修改bug
This commit is contained in:
@ -9,7 +9,7 @@
|
||||
<el-select v-if="item.showType === 'select'" v-model="searchObj[item.prop]" :multiple="item.multiple"
|
||||
:clearable="item.clearable" :filterable="item.filterable" :placeholder="item.placeholder" collapse-tags
|
||||
collapse-tags-tooltip class="control-select">
|
||||
<el-option v-for="obj in getOptions[item.prop]" :key="obj.value" :label="obj.label || obj.lable"
|
||||
<el-option v-for="obj in (getOptions[item.prop] || [])" :key="obj.value" :label="obj.label || obj.lable"
|
||||
:value="obj.value" />
|
||||
</el-select>
|
||||
<!-- input -->
|
||||
@ -412,12 +412,12 @@ const cascaderLazyProps = reactive({
|
||||
}
|
||||
});
|
||||
// 获取到传过来的参数
|
||||
let getArr = reactive([]);
|
||||
let getArr = ref([]);
|
||||
const submit = () => {
|
||||
emit("submit", searchObj);
|
||||
};
|
||||
const reset = () => {
|
||||
getArr.forEach((item) => {
|
||||
getArr.value.forEach((item) => {
|
||||
searchObj[item.prop] = item.defaultVal;
|
||||
});
|
||||
emit("reset", true);
|
||||
@ -430,63 +430,63 @@ defineExpose({
|
||||
submit,
|
||||
reset
|
||||
});
|
||||
// 优化 watchEffect 为 watch,避免因 reactive 内部状态变化导致频繁重新执行
|
||||
// 监听 searchArr 变化,同时监听内部 options 的异步更新
|
||||
watch(() => props.searchArr, (newArr) => {
|
||||
loadingPage.value = true;
|
||||
// 使用 try-catch 防止解析失败导致崩溃
|
||||
try {
|
||||
let arr = JSON.parse(JSON.stringify(newArr));
|
||||
getArr = arr.map((item) => {
|
||||
switch (item.showType) {
|
||||
// 不再深拷贝,保留响应式引用
|
||||
getArr.value = newArr.map((item) => {
|
||||
const itemCopy = { ...item }; // 浅拷贝即可
|
||||
switch (itemCopy.showType) {
|
||||
case "select":
|
||||
item = { ...selectDefault, ...item };
|
||||
item.options = reactive(item.options);
|
||||
getOptions[item.prop] = item.options;
|
||||
Object.assign(itemCopy, { ...selectDefault, ...itemCopy });
|
||||
// 直接引用原 options,保持响应式
|
||||
getOptions[itemCopy.prop] = itemCopy.options || [];
|
||||
break;
|
||||
case "input":
|
||||
item = { ...inputDefault, ...item };
|
||||
Object.assign(itemCopy, { ...inputDefault, ...itemCopy });
|
||||
break;
|
||||
case "daterange":
|
||||
item = { ...daterangeDefault, ...item };
|
||||
if (item.defaultShortcuts) item.shortcuts = shortcuts;
|
||||
Object.assign(itemCopy, { ...daterangeDefault, ...itemCopy });
|
||||
if (itemCopy.defaultShortcuts) itemCopy.shortcuts = shortcuts;
|
||||
break;
|
||||
case "date":
|
||||
item = { ...defaultDate, ...item };
|
||||
if (item.defaultShortcuts) {
|
||||
item.shortcuts = dateShortcuts;
|
||||
Object.assign(itemCopy, { ...defaultDate, ...itemCopy });
|
||||
if (itemCopy.defaultShortcuts) {
|
||||
itemCopy.shortcuts = dateShortcuts;
|
||||
}
|
||||
break;
|
||||
case "checkbox":
|
||||
item = reactive({ ...defaultCheckbox, ...item });
|
||||
item.checkboxValueArr = item.options.map((obj) => {
|
||||
Object.assign(itemCopy, { ...defaultCheckbox, ...itemCopy });
|
||||
itemCopy.checkboxValueArr = (itemCopy.options || []).map((obj) => {
|
||||
return obj.value;
|
||||
});
|
||||
break;
|
||||
case "cascader":
|
||||
item = { ...defaultCascader, ...item };
|
||||
if (item.lazy) {
|
||||
cascaderLazyProps.checkStrictly = item.checkStrictly;
|
||||
item.props = { ...cascaderLazyProps, ...(item.props || {}) };
|
||||
delete item.options;
|
||||
Object.assign(itemCopy, { ...defaultCascader, ...itemCopy });
|
||||
if (itemCopy.lazy) {
|
||||
cascaderLazyProps.checkStrictly = itemCopy.checkStrictly;
|
||||
itemCopy.props = { ...cascaderLazyProps, ...(itemCopy.props || {}) };
|
||||
delete itemCopy.options;
|
||||
} else {
|
||||
item.props = {
|
||||
itemCopy.props = {
|
||||
...defaultCascader.props,
|
||||
...(item.props || {}),
|
||||
...{ checkStrictly: item.checkStrictly }
|
||||
...(itemCopy.props || {}),
|
||||
...{ checkStrictly: itemCopy.checkStrictly }
|
||||
};
|
||||
getOptions[item.prop] = reactive(item.options);
|
||||
getOptions[itemCopy.prop] = itemCopy.options || [];
|
||||
}
|
||||
break;
|
||||
}
|
||||
loadingPage.value = false;
|
||||
searchObj[item.prop] = item.defaultVal;
|
||||
return item;
|
||||
searchObj[itemCopy.prop] = itemCopy.defaultVal;
|
||||
return itemCopy;
|
||||
});
|
||||
} catch (e) {
|
||||
console.error('Search组件初始化失败:', e);
|
||||
console.error('Search组件解析searchArr失败:', e);
|
||||
} finally {
|
||||
loadingPage.value = false;
|
||||
}
|
||||
}, { immediate: true, deep: false });
|
||||
}, { immediate: true, deep: true }); // 开启深度监听,检测 options 变化
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
|
||||
Reference in New Issue
Block a user