From c4057ac69b14948d2d305a46e5dcd05bb527ac2b Mon Sep 17 00:00:00 2001 From: sws <1141121512@qq.com> Date: Mon, 9 Sep 2024 11:44:28 +0800 Subject: [PATCH] =?UTF-8?q?1.=E6=8E=A5=E5=8F=A3=E8=B0=83=E7=94=A8=E4=BC=98?= =?UTF-8?q?=E5=8C=96=EF=BC=8C=E5=87=8F=E5=B0=91=E6=8E=A5=E5=8F=A3=E8=B0=83?= =?UTF-8?q?=E7=94=A8=E6=AC=A1=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/model-article-list/index.vue | 41 ++++++++++++++++----- src/components/model-coupon/index.vue | 38 ++++++++++++++----- 2 files changed, 60 insertions(+), 19 deletions(-) diff --git a/src/components/model-article-list/index.vue b/src/components/model-article-list/index.vue index eb4e75c4..c89a09b1 100644 --- a/src/components/model-article-list/index.vue +++ b/src/components/model-article-list/index.vue @@ -132,6 +132,7 @@ const get_auto_data_list = async () => { article_is_cover: is_cover, }; const res = await ArticleAPI.getAutoList(new_data); + new_content.value.data_auto_list = []; if (!isEmpty(res.data)) { data_list.value = []; res.data.forEach((child: any) => { @@ -141,6 +142,12 @@ const get_auto_data_list = async () => { new_cover: [], data: child, }); + new_content.value.data_auto_list.push({ + id: get_math(), + new_title: '', + new_cover: [], + data: child, + }); }); } else { data_list.value = Array(4).fill(default_data_list); @@ -149,18 +156,34 @@ const get_auto_data_list = async () => { const new_content = computed(() => props.value?.content || {}); const new_style = computed(() => props.value?.style || {}); -watchEffect(() => { - if (new_content.value.data_type == '0') { - if (!isEmpty(new_content.value.data_list)) { - data_list.value = new_content.value.data_list; - data_list.value = cloneDeep(new_content.value.data_list); - } else { - data_list.value = Array(4).fill(default_data_list); - } +onMounted(() => { + if (!isEmpty(new_content.value.data_list) && new_content.value.data_type == '0') { + data_list.value = new_content.value.data_list; + } else if (!isEmpty(new_content.value.data_auto_list) && new_content.value.data_type == '1') { + data_list.value = new_content.value.data_auto_list; } else { - get_auto_data_list(); + data_list.value = Array(4).fill(default_data_list); } }); +const data_list_computer = computed(() => { + const { data_type, category, number, sort, sort_rules, is_cover } = new_content.value; + return { data_type, category, number, sort, sort_rules, is_cover }; +}); +watch( + () => data_list_computer.value, + (new_value) => { + if (new_value.data_type == '1') { + get_auto_data_list(); + } else { + if (!isEmpty(new_content.value.data_list)) { + data_list.value = cloneDeep(new_content.value.data_list); + } else { + data_list.value = Array(4).fill(default_data_list); + } + } + }, + { deep: true } +); // 轮播宽度 const multicolumn_columns_width = computed(() => { const { carousel_col } = toRefs(new_content.value); diff --git a/src/components/model-coupon/index.vue b/src/components/model-coupon/index.vue index 07acf88d..42d54213 100644 --- a/src/components/model-coupon/index.vue +++ b/src/components/model-coupon/index.vue @@ -172,6 +172,15 @@ const content_title = computed(() => { const content_desc = computed(() => { return form.value.desc; }); +onMounted(() => { + if (!isEmpty(form.value.data_list) && form.value.data_type == '0') { + data_list.value = form.value.data_list; + } else if (!isEmpty(form.value.data_auto_list) && form.value.data_type == '1') { + data_list.value = form.value.data_auto_list; + } else { + data_list.value = Array(4).fill(default_list); + } +}); const get_coupon = () => { const { number, type } = form.value; const params = { @@ -180,6 +189,7 @@ const get_coupon = () => { }; // 获取商品列表 CouponAPI.getCoupon(params).then((res: any) => { + form.value.data_auto_list = res.data; if (!isEmpty(res.data)) { data_list.value = res.data; } else { @@ -187,17 +197,25 @@ const get_coupon = () => { } }); }; -watchEffect(() => { - if (form.value.data_type == '0') { - if (!isEmpty(form.value.data_list)) { - data_list.value = cloneDeep(form.value.data_list); - } else { - data_list.value = Array(4).fill(default_list); - } - } else { - get_coupon(); - } +const data_list_computer = computed(() => { + const { data_type, type, number } = form.value; + return { data_type, type, number }; }); +watch( + () => data_list_computer.value, + (new_value) => { + if (new_value.data_type == '1') { + get_coupon(); + } else { + if (!isEmpty(form.value.data_list)) { + data_list.value = cloneDeep(form.value.data_list); + } else { + data_list.value = Array(4).fill(default_list); + } + } + }, + { deep: true } +); const theme = computed(() => props.value?.content?.theme); const theme_style = computed(() => { const new_background = gradient_computer({ color_list: props.value?.style?.background, direction: props.value?.style?.direction }, false);