bugfix: 编辑时无法回显用户邮箱

This commit is contained in:
2026-01-07 15:06:25 +08:00
parent b4ea8907d7
commit 45af83d0b2
2 changed files with 46 additions and 5 deletions

View File

@@ -18,7 +18,7 @@
</template>
<script setup lang="ts">
import { computed, ref, reactive } from 'vue'
import { computed, ref, reactive ,defineExpose} from 'vue'
import { debounce } from 'lodash-es'
import { Https } from '@/tool/https'
import { useStore } from '@/store'
@@ -94,6 +94,21 @@ const doFetch = async (reset = false) => {
})
const data = res?.data
pager.hasMore = res?.hasMore
if (tempItem.value.value) {
const exists = data.find(
it =>
(props.valueKey ? it[props.valueKey] : it.value) ===
(props.valueKey ? tempItem.value[props.valueKey] : tempItem.value.value)
)
if (!!exists) {
// 如果存在,用data中的新数据覆盖internalList中的旧数据
const index = internalList.value.indexOf(tempItem.value)
const existsIndex = data.indexOf(exists)
internalList.value[index] = { ...exists }
data.splice(existsIndex, 1)
tempItem.value = {}
}
}
if (pager.page === 1) internalList.value = data
else internalList.value = internalList.value.concat(data)
pager.page += 1
@@ -129,6 +144,24 @@ const handleFocus = () => {
const onChange = (val: any) => {
emit('change', val)
}
// 解决回显时没有加载对应选项的问题
const tempItem = ref({})
const patchList = item => {
const exists = internalList.value.find(
it =>
(props.valueKey ? it[props.valueKey] : it.value) ===
(props.valueKey ? item[props.valueKey] : item.value)
)
if (!exists) {
internalList.value.unshift({ ...item, temp: true })
tempItem.value = item
}
}
defineExpose({
patchList
})
</script>
<style lang="less" scoped></style>