This commit is contained in:
ygx
2026-03-15 23:16:00 +08:00
parent 18072d75a4
commit 2835695d78
36 changed files with 6902 additions and 17 deletions

View File

@@ -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 }
)

View File

@@ -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)