diff --git a/src/views/layout/index.vue b/src/views/layout/index.vue index 49f272aa..9bb8755d 100644 --- a/src/views/layout/index.vue +++ b/src/views/layout/index.vue @@ -23,7 +23,7 @@ import { Settings, AppMain } from './components/index'; import defaultSettings from './components/main/index'; import defaultConfigSetting from '@/config/setting'; import defaultConfigConst from '@/config/const/index'; -import { cloneDeep, isEmpty, omit } from 'lodash'; +import { clone, cloneDeep, isEmpty, omit } from 'lodash'; import DiyAPI, { diyData, headerAndFooter, diyConfig } from '@/api/diy'; import CommonAPI from '@/api/common'; import { commonStore } from '@/store'; @@ -277,8 +277,9 @@ const save_formmat_form_data = (data: diy_data_item, close: boolean = false, is_ // 获取所有组件名称 const all_type = ['hot_zone', 'custom', 'img_magic', 'goods_magic', 'goods_list', 'article_list', 'nav_group', 'video', 'carousel']; // 将数据信息合并起来 - const new_data_list = [item.com_data.content.home_data, ...item.com_data.content.tabs_list]; + const new_data_list = cloneDeep([item.com_data.content.home_data, ...item.com_data.content.tabs_list]); // 对整个数据进行处理 + let clone_data_list: any = []; new_data_list.forEach((item1: any) => { if (['goods-list', 'article-list'].includes(item1.magic_type)) { // 处理商品或者文章的数据 @@ -287,16 +288,18 @@ const save_formmat_form_data = (data: diy_data_item, close: boolean = false, is_ // 自定义数据处理 custom_data_processing(item1[item1.magic_type].content); } - item1 = Object.keys(item1) - .filter(key => !all_type.filter((item2: string) => item2 !== item1.magic_type).includes(key)) - .reduce((acc: Record, key: string) => { - acc[key] = item1[key]; - return acc; - }, {}); + clone_data_list.push( + Object.keys(item1) + .filter(key => !(all_type.filter((item2: string) => !isEmpty(item1.magic_type) ? (item2 !== item1.magic_type) : item2).includes(key))) + .reduce((acc: Record, key: string) => { + acc[key] = item1[key]; + return acc; + }, {}) + ); }); // 处理完成之后拆分开 - item.com_data.content.home_data = new_data_list.length > 0 ? new_data_list[0] : null; - item.com_data.content.tabs_list = new_data_list.slice(1, new_data_list.length); + item.com_data.content.home_data = clone_data_list.length > 0 ? clone_data_list[0] : null; + item.com_data.content.tabs_list = clone_data_list.slice(1, clone_data_list.length); } return { ...item,