1.接口调用优化,减少接口调用次数
parent
99b974ab87
commit
c4057ac69b
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in New Issue