diff --git a/src/components/common/custom-module/model-icon/index.vue b/src/components/common/custom-module/model-icon/index.vue index bb9a6e5d..b67d9074 100644 --- a/src/components/common/custom-module/model-icon/index.vue +++ b/src/components/common/custom-module/model-icon/index.vue @@ -49,7 +49,9 @@ const icon_class = computed(() => { let icon = props.sourceList[form.data_source_id]; // 如果是商品,品牌,文章的图片, 其他的切换为从data中取数据 if (['goods', 'article', 'brand'].includes(props.sourceType)) { - icon = props.sourceList.data[form.data_source_id]; + if (!isEmpty(props.sourceList.data)) { + icon = props.sourceList.data[form.data_source_id]; + } } return icon; } else { diff --git a/src/components/common/custom-module/model-image/index.vue b/src/components/common/custom-module/model-image/index.vue index e01914e4..e11e4318 100644 --- a/src/components/common/custom-module/model-image/index.vue +++ b/src/components/common/custom-module/model-image/index.vue @@ -51,10 +51,12 @@ const img = computed(() => { let image_url = props.sourceList[form.data_source_id]; // 如果是商品,品牌,文章的图片, 其他的切换为从data中取数据 if (['goods', 'article', 'brand'].includes(props.sourceType)) { - if (form.data_source_id == keyMap[props.sourceType]) { - image_url = !isEmpty(props.sourceList.new_cover)? props.sourceList.new_cover[0]?.url || '' : props.sourceList.data[keyMap[props.sourceType]]; - } else { - image_url = props.sourceList.data[form.data_source_id]; + if (!isEmpty(props.sourceList.data)) { + if (form.data_source_id == keyMap[props.sourceType]) { + image_url = !isEmpty(props.sourceList.new_cover)? props.sourceList.new_cover[0]?.url || '' : props.sourceList.data[keyMap[props.sourceType]]; + } else { + image_url = props.sourceList.data[form.data_source_id]; + } } } return image_url; diff --git a/src/components/common/custom-module/model-text/index.vue b/src/components/common/custom-module/model-text/index.vue index b3c6f60e..a95613ee 100644 --- a/src/components/common/custom-module/model-text/index.vue +++ b/src/components/common/custom-module/model-text/index.vue @@ -53,11 +53,13 @@ const text_title = computed(() => { let text_title = props.sourceList[form.data_source_id]; // 如果是商品的标题或者是品牌的名称,需要判断是否有新的标题,没有的话就取原来的标题 if (['goods', 'article', 'brand'].includes(props.sourceType)) { - // 其他的切换为从data中取数据 - if (form.data_source_id == keyMap[props.sourceType]) { - text_title = !isEmpty(props.sourceList.new_title) ? props.sourceList.new_title : props.sourceList.data[keyMap[props.sourceType]]; - } else { - text_title = props.sourceList.data[form.data_source_id]; + if (!isEmpty(props.sourceList.data)) { + // 其他的切换为从data中取数据 + if (form.data_source_id == keyMap[props.sourceType]) { + text_title = !isEmpty(props.sourceList.new_title) ? props.sourceList.new_title : props.sourceList.data[keyMap[props.sourceType]]; + } else { + text_title = props.sourceList.data[form.data_source_id]; + } } } if (!isEmpty(form.text_title)) { diff --git a/src/components/model-custom/index.vue b/src/components/model-custom/index.vue index 8fb3cf48..e92018d2 100644 --- a/src/components/model-custom/index.vue +++ b/src/components/model-custom/index.vue @@ -90,7 +90,12 @@ let data_source_content_list = computed(() => { if (form.value.data_source_content.data_type == '0') { return form.value.data_source_content.data_list; } else { - return form.value.data_source_content.data_auto_list; + return form.value.data_source_content.data_auto_list.map((item: any) => ({ + id: Math.random(), + new_cover: [], + new_title: '', + data: item, + })); } } else { return form.value.data_source_content.data_list; diff --git a/src/components/model-custom/model-custom-content.vue b/src/components/model-custom/model-custom-content.vue index 7afe9043..01877764 100644 --- a/src/components/model-custom/model-custom-content.vue +++ b/src/components/model-custom/model-custom-content.vue @@ -112,8 +112,16 @@ const getCustominit = () => { onBeforeMount(() => { // 不包含新创建的数组时,将历史数据放到手动添加数组中 if (!Object.keys(form.data_source_content).includes('data_auto_list') && !Object.keys(form.data_source_content).includes('data_list')) { - form.data_source_content = cloneDeep(source_list[form.data_source as keyof typeof source_list]); - form.data_source_content.data_list = [ form.data_source_content ]; + const data = cloneDeep(form.data_source_content); + const new_list = cloneDeep(source_list[form.data_source as keyof typeof source_list]); + if (!isEmpty(new_list)) { + form.data_source_content = new_list; + } else { + form.data_source_content = cloneDeep(source_list['common']); + } + if (!isEmpty(data)) { + form.data_source_content.data_list = [ data ]; + } } if (!data_source_store.is_data_source_api) { data_source_store.set_is_data_source_api(true); @@ -244,6 +252,14 @@ const source_list = { order_by_type: '0', // 排序规则 order_by_rule: '0', + }, + common: { + // 存放手动输入的id + data_ids: [], + // 手动输入 + data_list: [], + // 自动 + data_auto_list: [], } }; const changeDataSource = (key: string) => { @@ -396,14 +412,7 @@ const get_products = () => { // 清空历史数据 form.data_source_content.data_auto_list = []; if (!isEmpty(res.data)) { - res.data.forEach((child: any) => { - form.data_source_content.data_auto_list.push({ - id: get_math(), - new_title: '', - new_cover: [], - data: child, - }); - }); + form.data_source_content.data_auto_list = res.data; } }); }; @@ -422,14 +431,7 @@ const get_article = async () => { // 清空历史数据 form.data_source_content.data_auto_list = []; if (!isEmpty(res.data)) { - res.data.forEach((child: any) => { - form.data_source_content.data_auto_list.push({ - id: get_math(), - new_title: '', - new_cover: [], - data: child, - }); - }); + form.data_source_content.data_auto_list = res.data; } }; const get_brand = () => {