1.接口调用优化,减少接口调用次数
parent
99b974ab87
commit
c4057ac69b
|
|
@ -132,6 +132,7 @@ const get_auto_data_list = async () => {
|
||||||
article_is_cover: is_cover,
|
article_is_cover: is_cover,
|
||||||
};
|
};
|
||||||
const res = await ArticleAPI.getAutoList(new_data);
|
const res = await ArticleAPI.getAutoList(new_data);
|
||||||
|
new_content.value.data_auto_list = [];
|
||||||
if (!isEmpty(res.data)) {
|
if (!isEmpty(res.data)) {
|
||||||
data_list.value = [];
|
data_list.value = [];
|
||||||
res.data.forEach((child: any) => {
|
res.data.forEach((child: any) => {
|
||||||
|
|
@ -141,6 +142,12 @@ const get_auto_data_list = async () => {
|
||||||
new_cover: [],
|
new_cover: [],
|
||||||
data: child,
|
data: child,
|
||||||
});
|
});
|
||||||
|
new_content.value.data_auto_list.push({
|
||||||
|
id: get_math(),
|
||||||
|
new_title: '',
|
||||||
|
new_cover: [],
|
||||||
|
data: child,
|
||||||
|
});
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
data_list.value = Array(4).fill(default_data_list);
|
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_content = computed(() => props.value?.content || {});
|
||||||
const new_style = computed(() => props.value?.style || {});
|
const new_style = computed(() => props.value?.style || {});
|
||||||
watchEffect(() => {
|
onMounted(() => {
|
||||||
if (new_content.value.data_type == '0') {
|
if (!isEmpty(new_content.value.data_list) && new_content.value.data_type == '0') {
|
||||||
if (!isEmpty(new_content.value.data_list)) {
|
data_list.value = new_content.value.data_list;
|
||||||
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 = cloneDeep(new_content.value.data_list);
|
data_list.value = new_content.value.data_auto_list;
|
||||||
} else {
|
|
||||||
data_list.value = Array(4).fill(default_data_list);
|
|
||||||
}
|
|
||||||
} else {
|
} 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 multicolumn_columns_width = computed(() => {
|
||||||
const { carousel_col } = toRefs(new_content.value);
|
const { carousel_col } = toRefs(new_content.value);
|
||||||
|
|
|
||||||
|
|
@ -172,6 +172,15 @@ const content_title = computed(() => {
|
||||||
const content_desc = computed(() => {
|
const content_desc = computed(() => {
|
||||||
return form.value.desc;
|
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 get_coupon = () => {
|
||||||
const { number, type } = form.value;
|
const { number, type } = form.value;
|
||||||
const params = {
|
const params = {
|
||||||
|
|
@ -180,6 +189,7 @@ const get_coupon = () => {
|
||||||
};
|
};
|
||||||
// 获取商品列表
|
// 获取商品列表
|
||||||
CouponAPI.getCoupon(params).then((res: any) => {
|
CouponAPI.getCoupon(params).then((res: any) => {
|
||||||
|
form.value.data_auto_list = res.data;
|
||||||
if (!isEmpty(res.data)) {
|
if (!isEmpty(res.data)) {
|
||||||
data_list.value = res.data;
|
data_list.value = res.data;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -187,17 +197,25 @@ const get_coupon = () => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
watchEffect(() => {
|
const data_list_computer = computed(() => {
|
||||||
if (form.value.data_type == '0') {
|
const { data_type, type, number } = form.value;
|
||||||
if (!isEmpty(form.value.data_list)) {
|
return { data_type, type, number };
|
||||||
data_list.value = cloneDeep(form.value.data_list);
|
|
||||||
} else {
|
|
||||||
data_list.value = Array(4).fill(default_list);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
get_coupon();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
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 = computed(() => props.value?.content?.theme);
|
||||||
const theme_style = computed(() => {
|
const theme_style = computed(() => {
|
||||||
const new_background = gradient_computer({ color_list: props.value?.style?.background, direction: props.value?.style?.direction }, false);
|
const new_background = gradient_computer({ color_list: props.value?.style?.background, direction: props.value?.style?.direction }, false);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue