|
@@ -1,5 +1,5 @@
|
|
|
<template>
|
|
|
- <div class="xc-select-v2_main" @mousedown="stopLosingFocus($event)" ref="xcSelectV2Main">
|
|
|
+ <div class="xc-select-v2_main" style="width: 120px" @mousedown="stopLosingFocus($event)" ref="xcSelectV2Main">
|
|
|
<el-input ref="xcInput" @input="inputChange" v-model="label"
|
|
|
@blur="loseFocus"
|
|
|
:placeholder="placeholder"
|
|
@@ -83,17 +83,13 @@ const emit = defineEmits(['change'])
|
|
|
|
|
|
let label = $ref('')
|
|
|
let isGetFocus = $ref(false)
|
|
|
-let tempMap = new Map()
|
|
|
let selectItem = $ref(null)
|
|
|
let xcInput = $ref(null)
|
|
|
let top = $ref(22)
|
|
|
let selectedSubscript = $ref(0)
|
|
|
let dataLenght = $ref(0)
|
|
|
let isClearable = $ref(false)
|
|
|
-let inputStyle = $ref({
|
|
|
- top: 22,
|
|
|
- width: 120
|
|
|
-})
|
|
|
+let inputStyle = $ref({})
|
|
|
let xcSelectV2Main = $ref()
|
|
|
let whetherToSearchLocally = $ref(!props.remoteMethod)
|
|
|
|
|
@@ -148,7 +144,6 @@ const method = (val) => {
|
|
|
|
|
|
const change = async (data) => {
|
|
|
if (data) {
|
|
|
- tempMap[data.value] = data
|
|
|
props.modelValue[props.value] = data.value
|
|
|
props.modelValue[props.label] = data.label
|
|
|
label = data.label
|
|
@@ -179,7 +174,7 @@ const getFocus = async () => {
|
|
|
}
|
|
|
|
|
|
const loseFocus = async () => {
|
|
|
- label = props.modelValue[props.label]
|
|
|
+ label = props.modelValue[props.label] ? props.modelValue[props.label] : props.modelValue[props.value]
|
|
|
await sleep(100)
|
|
|
isShow = false
|
|
|
isGetFocus = false
|
|
@@ -199,24 +194,21 @@ const selectItemResetData = async () => {
|
|
|
try {
|
|
|
await selectItem.resetData()
|
|
|
} catch (e) {
|
|
|
- console.log(e)
|
|
|
+ // console.log(e)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-const selectItemEnableScrollBar = async () => {
|
|
|
+const selectItemDelectedDataSubscript = async () => {
|
|
|
try {
|
|
|
- await selectItem.enableScrollBar()
|
|
|
+ await selectItem.selectedDataSubscript(selectedSubscript)
|
|
|
} catch (e) {
|
|
|
// console.log(e)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
-const valueChange = async () => {
|
|
|
+const valueChange = async (whetherToChangeTheValue) => {
|
|
|
dataLenght = props.data.length
|
|
|
- await nextTick()
|
|
|
- await selectItemResetData()
|
|
|
- await selectItemEnableScrollBar()
|
|
|
if (isGetFocus) {
|
|
|
return;
|
|
|
}
|
|
@@ -243,19 +235,18 @@ const valueChange = async () => {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- if (!props.modelValue[props.label]) {
|
|
|
+
|
|
|
+ if (whetherToChangeTheValue) {
|
|
|
label = props.modelValue[props.value]
|
|
|
+ await method(props.modelValue[props.value])
|
|
|
}
|
|
|
- await method(props.modelValue[props.value])
|
|
|
- } else {
|
|
|
- label = props.modelValue[props.value]
|
|
|
}
|
|
|
}
|
|
|
|
|
|
watch(
|
|
|
() => props.modelValue[props.value],
|
|
|
(newValue, oldValue) => {
|
|
|
- valueChange()
|
|
|
+ valueChange(true)
|
|
|
},
|
|
|
{immediate: true, deep: true}
|
|
|
)
|
|
@@ -263,7 +254,10 @@ watch(
|
|
|
watch(
|
|
|
() => props.data,
|
|
|
async () => {
|
|
|
- valueChange()
|
|
|
+ await valueChange(false)
|
|
|
+ await nextTick()
|
|
|
+ await selectItemResetData()
|
|
|
+ selectedSubscript = 0
|
|
|
},
|
|
|
{immediate: true, deep: true}
|
|
|
)
|
|
@@ -274,22 +268,18 @@ watch(
|
|
|
() => {
|
|
|
if (isShow && dataLenght > 0) {
|
|
|
nextTick(() => {
|
|
|
- if (!props.data[selectedSubscript].value === props.modelValue[props.value]) {
|
|
|
+ if (props.data[selectedSubscript].value !== props.modelValue[props.value]) {
|
|
|
for (let i = 0; i < dataLenght; i++) {
|
|
|
let data = props.data[i];
|
|
|
- if (data.value === props.data[selectedSubscript].value) {
|
|
|
+ if (data.value === props.modelValue[props.value]) {
|
|
|
selectedSubscript = i
|
|
|
- try {
|
|
|
- selectItem.selectedDataSubscript(i)
|
|
|
- } catch (e) {
|
|
|
- }
|
|
|
- return;
|
|
|
+ break
|
|
|
}
|
|
|
}
|
|
|
- } else {
|
|
|
- selectItem.selectedDataSubscript(selectedSubscript)
|
|
|
}
|
|
|
- let docInput = xcInput.input
|
|
|
+ selectItemDelectedDataSubscript()
|
|
|
+
|
|
|
+ let docInput = xcInput.input;
|
|
|
let inputTop = docInput.getBoundingClientRect().top
|
|
|
let inputLeft = docInput.getBoundingClientRect().left
|
|
|
let selectBox = selectItem.$el
|
|
@@ -313,8 +303,8 @@ onMounted(() => {
|
|
|
let docInput = xcInput.input
|
|
|
inputStyle = {
|
|
|
top: docInput.scrollHeight + 5 + 'px',
|
|
|
- minWidth: docInput.scrollWidth + 15 + 'px',
|
|
|
- minHeight: '40px'
|
|
|
+ minWidth: xcSelectV2Main.scrollWidth + 'px',
|
|
|
+ minHeight: '40px',
|
|
|
}
|
|
|
})
|
|
|
})
|