|
|
@@ -117,6 +117,7 @@
|
|
|
<script setup>
|
|
|
import { ref, computed, watch, onMounted, nextTick, onUnmounted } from 'vue'
|
|
|
import { useI18n } from 'vue-i18n'
|
|
|
+import { isRouteOnTop } from '@/utils/pageActive'
|
|
|
|
|
|
const { t } = useI18n()
|
|
|
|
|
|
@@ -313,6 +314,27 @@ const nonDateField = computed(() => {
|
|
|
const clonePlain = (val) => JSON.parse(JSON.stringify(val ?? {}))
|
|
|
const isEqual = (a, b) => JSON.stringify(a ?? {}) === JSON.stringify(b ?? {})
|
|
|
|
|
|
+/** 所属页面 route,离开栈顶后不再 emit search */
|
|
|
+const ownerPageRoute = ref('')
|
|
|
+
|
|
|
+/** 仅字段结构变化时重新初始化(语言切换改 label 不触发) */
|
|
|
+const getFieldsSignature = (fields) => {
|
|
|
+ if (!fields?.length) return ''
|
|
|
+ return JSON.stringify(
|
|
|
+ fields.filter(Boolean).map((field) => ({
|
|
|
+ key: field.key,
|
|
|
+ type: field.type,
|
|
|
+ defaultValue: field.defaultValue,
|
|
|
+ optionsLength: Array.isArray(field.options) ? field.options.length : 0,
|
|
|
+ optionValues: Array.isArray(field.options)
|
|
|
+ ? field.options.map((o) => o?.value ?? o?.text ?? o)
|
|
|
+ : undefined,
|
|
|
+ }))
|
|
|
+ )
|
|
|
+}
|
|
|
+
|
|
|
+let fieldsSignature = ''
|
|
|
+
|
|
|
// 监听外部 modelValue 变化
|
|
|
watch(() => props.modelValue, (newVal) => {
|
|
|
if (!newVal) return
|
|
|
@@ -374,6 +396,7 @@ const resetForm = () => {
|
|
|
}
|
|
|
// 触发查询
|
|
|
const handleSearch = () => {
|
|
|
+ if (!isRouteOnTop(ownerPageRoute.value)) return
|
|
|
emit('search', { ...formData.value })
|
|
|
}
|
|
|
|
|
|
@@ -430,13 +453,22 @@ const applyFilter = () => {
|
|
|
handleSearch()
|
|
|
}
|
|
|
|
|
|
-// 监听fields变化,重新初始化
|
|
|
-watch(() => props.fields, () => {
|
|
|
- initFormData()
|
|
|
-}, { deep: true, immediate: false })
|
|
|
+// 仅 fields 结构变化时重新初始化
|
|
|
+watch(
|
|
|
+ () => props.fields,
|
|
|
+ (fields) => {
|
|
|
+ const nextSig = getFieldsSignature(fields)
|
|
|
+ if (nextSig === fieldsSignature) return
|
|
|
+ fieldsSignature = nextSig
|
|
|
+ initFormData()
|
|
|
+ },
|
|
|
+ { deep: false }
|
|
|
+)
|
|
|
|
|
|
onMounted(() => {
|
|
|
- // 初始化表单数据
|
|
|
+ const pages = getCurrentPages()
|
|
|
+ ownerPageRoute.value = pages[pages.length - 1]?.route || ''
|
|
|
+ fieldsSignature = getFieldsSignature(props.fields)
|
|
|
initFormData()
|
|
|
})
|
|
|
|