修改自定义动态数据更新

v1.1.0
于肖磊 2024-11-14 17:04:57 +08:00
parent d561cca47d
commit 5167c6abe8
1 changed files with 38 additions and 36 deletions

View File

@ -83,8 +83,12 @@ const props = defineProps({
const dialog = ref<expose | null>(null);
const draglist = ref<diy_data | null>(null);
const form = reactive(props.value);
const form = ref(props.value);
const center_width = ref(props.magicWidth);
watchEffect(() => {
form.value = props.value;
center_width.value = props.magicWidth;
})
//
let custom_list = reactive([]);
const center_height = ref(0);
@ -107,7 +111,7 @@ const getCustominit = () => {
options.value = data_source;
data_source_store.set_data_source(data_source);
//
processing_data(form.data_source);
processing_data(form.value.data_source);
});
};
@ -118,7 +122,7 @@ onBeforeMount(() => {
} else {
options.value = data_source_store.data_source_list;
//
processing_data(form.data_source);
processing_data(form.value.data_source);
}
});
//
@ -157,17 +161,17 @@ const custom_edit = () => {
if (!dialog.value) return;
dialog.value.dialogVisible = true;
dragkey.value = Math.random().toString(36).substring(2);
custom_list = cloneDeep(form.custom_list);
center_height.value = cloneDeep(form.height);
custom_list = cloneDeep(form.value.custom_list);
center_height.value = cloneDeep(form.value.height);
};
//
const accomplish = () => {
if (!draglist.value) {
return;
} else {
form.custom_list = draglist.value.diy_data;
form.value.custom_list = draglist.value.diy_data;
}
form.height = center_height.value;
form.value.height = center_height.value;
};
//#endregion
//#region
@ -177,7 +181,7 @@ const changeDataSource = (key: string) => {
const type_data = options.value.filter((item) => item.type == key);
processing_data(key);
if (type_data.length > 0 && !isEmpty(type_data[0].appoint_data)) {
form.data_source_content = {
form.value.data_source_content = {
// id
data_ids: [],
data_list: [ type_data[0].appoint_data ],
@ -185,7 +189,7 @@ const changeDataSource = (key: string) => {
data_auto_list: [],
}
} else {
form.data_source_content = {
form.value.data_source_content = {
// id
data_ids: [],
//
@ -194,7 +198,7 @@ const changeDataSource = (key: string) => {
data_auto_list: [],
};
if (!isEmpty(key) && key in source_list) {
form.data_source_content = cloneDeep(source_list[key as keyof typeof source_list]);
form.value.data_source_content = cloneDeep(source_list[key as keyof typeof source_list]);
}
}
};
@ -276,21 +280,21 @@ const add = () => {
};
//
const data_list_sort = (new_list: any) => {
form.data_source_content.data_list = new_list;
form.value.data_source_content.data_list = new_list;
};
const data_list_remove = (index: number) => {
form.data_source_content.data_list.splice(index, 1);
form.value.data_source_content.data_list.splice(index, 1);
};
//
const url_value_dialog_call_back = (item: any[]) => {
if (form.data_source == 'brand') {
if (form.value.data_source == 'brand') {
item.forEach((item: any) => {
item.title = item.name;
});
}
if (url_value_multiple_bool.value) {
item.forEach((item: any) => {
form.data_source_content.data_list.push({
form.value.data_source_content.data_list.push({
id: get_math(),
new_cover: [],
new_title: '',
@ -298,7 +302,7 @@ const url_value_dialog_call_back = (item: any[]) => {
});
});
} else {
form.data_source_content.data_list[data_list_replace_index.value] = {
form.value.data_source_content.data_list[data_list_replace_index.value] = {
id: get_math(),
new_cover: [],
new_title: '',
@ -308,19 +312,19 @@ const url_value_dialog_call_back = (item: any[]) => {
};
//
let data_source_content_list = computed(() => {
if (['goods', 'article', 'brand'].includes(form.data_source)) {
if (form.data_source_content.data_type == '0') {
return form.data_source_content.data_list;
if (['goods', 'article', 'brand'].includes(form.value.data_source)) {
if (form.value.data_source_content.data_type == '0') {
return form.value.data_source_content.data_list;
} else {
return form.data_source_content.data_auto_list;
return form.value.data_source_content.data_auto_list;
}
} else {
return form.data_source_content.data_list;
return form.value.data_source_content.data_list;
}
})
//
const get_products = () => {
const { category_ids, brand_ids, number, order_by_type, order_by_rule, keyword } = form.data_source_content;
const { category_ids, brand_ids, number, order_by_type, order_by_rule, keyword } = form.value.data_source_content;
const params = {
goods_keywords: keyword,
goods_category_ids: category_ids,
@ -332,15 +336,15 @@ const get_products = () => {
//
ShopAPI.getShopLists(params).then((res: any) => {
//
form.data_source_content.data_auto_list = [];
form.value.data_source_content.data_auto_list = [];
if (!isEmpty(res.data)) {
form.data_source_content.data_auto_list = res.data;
form.value.data_source_content.data_auto_list = res.data;
}
});
};
//
const get_article = async () => {
const { category_ids, number, order_by_type, order_by_rule, is_cover, keyword } = form.data_source_content;
const { category_ids, number, order_by_type, order_by_rule, is_cover, keyword } = form.value.data_source_content;
const new_data = {
article_keywords: keyword,
article_category_ids: category_ids.join(','),
@ -351,15 +355,14 @@ const get_article = async () => {
};
const res = await ArticleAPI.getAutoList(new_data);
//
form.data_source_content.data_auto_list = [];
form.value.data_source_content.data_auto_list = [];
if (!isEmpty(res.data)) {
form.data_source_content.data_auto_list = res.data;
form.value.data_source_content.data_auto_list = res.data;
}
};
//
const get_brand = () => {
const { category_ids, number, order_by_type, order_by_rule, keyword } = form.data_source_content;
console.log(form.data_source_content);
const { category_ids, number, order_by_type, order_by_rule, keyword } = form.value.data_source_content;
const params = {
brand_keywords: keyword,
brand_category_ids: category_ids,
@ -370,27 +373,26 @@ const get_brand = () => {
//
BrandAPI.getBrandLists(params).then((res: any) => {
//
form.data_source_content.data_auto_list = [];
form.value.data_source_content.data_auto_list = [];
if (!isEmpty(res.data)) {
form.data_source_content.data_auto_list = res.data;
form.value.data_source_content.data_auto_list = res.data;
}
});
console.log('品牌分类数据');
form.data_source_content.data_auto_list = [];
form.value.data_source_content.data_auto_list = [];
}
const data_source_content_value = computed(() => {
const { category_ids, brand_ids, number, order_by_type, order_by_rule, data_type, is_cover, keyword } = form.data_source_content;
const { category_ids, brand_ids, number, order_by_type, order_by_rule, data_type, is_cover, keyword } = form.value.data_source_content;
return { category_ids: category_ids, brand_ids: brand_ids, number: number, order_by_type: order_by_type, order_by_rule: order_by_rule, data_type: data_type, is_cover: is_cover, keyword: keyword };
})
watch(() => data_source_content_value.value, (new_val) => {
//
if (new_val.data_type != '0') {
if (form.data_source == 'goods') {
if (form.value.data_source == 'goods') {
get_products();
} else if (form.data_source == 'article') {
} else if (form.value.data_source == 'article') {
get_article();
} else if (form.data_source == 'brand') {
} else if (form.value.data_source == 'brand') {
get_brand();
}
}