feat
This commit is contained in:
@@ -57,7 +57,7 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { PropType, reactive, watch } from 'vue'
|
||||
import { PropType, reactive, watch, ref } from 'vue'
|
||||
import type { FormItem } from './types'
|
||||
|
||||
const props = defineProps({
|
||||
@@ -91,6 +91,7 @@ const emit = defineEmits<{
|
||||
|
||||
// 使用本地响应式副本,避免直接修改 props
|
||||
const localModel = reactive<Record<string, any>>({})
|
||||
const isUpdating = ref(false)
|
||||
|
||||
// 初始化本地模型
|
||||
const initLocalModel = () => {
|
||||
@@ -98,10 +99,11 @@ const initLocalModel = () => {
|
||||
Object.assign(localModel, props.modelValue)
|
||||
}
|
||||
|
||||
// 监听外部值变化
|
||||
// 监听外部值变化(只在非本地更新时响应)
|
||||
watch(
|
||||
() => props.modelValue,
|
||||
(val) => {
|
||||
if (isUpdating.value) return
|
||||
Object.keys(localModel).forEach(key => delete localModel[key])
|
||||
Object.assign(localModel, val)
|
||||
},
|
||||
@@ -112,7 +114,12 @@ watch(
|
||||
watch(
|
||||
localModel,
|
||||
(val) => {
|
||||
isUpdating.value = true
|
||||
emit('update:modelValue', { ...val })
|
||||
// 使用 nextTick 避免循环更新
|
||||
setTimeout(() => {
|
||||
isUpdating.value = false
|
||||
}, 0)
|
||||
},
|
||||
{ deep: true }
|
||||
)
|
||||
|
||||
@@ -118,7 +118,7 @@ const props = defineProps({
|
||||
},
|
||||
showDownload: {
|
||||
type: Boolean,
|
||||
default: true,
|
||||
default: false,
|
||||
},
|
||||
showRefresh: {
|
||||
type: Boolean,
|
||||
@@ -166,6 +166,7 @@ const emit = defineEmits<{
|
||||
(e: 'column-change', columns: TableColumnData[]): void
|
||||
}>()
|
||||
|
||||
|
||||
// 计算需要插槽的列(动态插槽透传)
|
||||
const slotColumns = computed(() => {
|
||||
return props.columns.filter(col => col.slotName)
|
||||
|
||||
Reference in New Issue
Block a user