保存时的数据处理内容更新

v1.2.0
于肖磊 2025-02-06 17:15:03 +08:00
parent 790a59ebed
commit c7d110774a
1 changed files with 137 additions and 86 deletions

View File

@ -259,55 +259,13 @@ const save_formmat_form_data = (data: diy_data_item, close: boolean = false, is_
const new_array_6 = ['nav-group'];
clone_form.diy_data = clone_form.diy_data.map((item: any) => {
if (new_array_1.includes(item.key)) {
if (item.com_data.content.data_type == '0') {
item.com_data.content.data_ids = item.com_data.content.data_list.map((item: any) => item.data.id).join(',') || '';
item.com_data.content.data_list = item.com_data.content.data_list.map((item1: any) => {
return {
...item1,
data: [],
data_id: item1.data.id,
};
});
item.com_data.content.category_ids = defaultConfigSetting.category_ids;
item.com_data.content.number = defaultConfigSetting.page_size;
item.com_data.content.order_by_rule = defaultConfigSetting.order_by_rule;
item.com_data.content.order_by_type = defaultConfigSetting.order_by_type;
if (item.key == new_array_1[0]) {
item.com_data.content.brand_ids = defaultConfigSetting.brand_ids;
} else {
item.com_data.content.is_cover = defaultConfigSetting.is_cover;
}
} else {
item.com_data.content.data_ids = '';
item.com_data.content.data_list = [];
}
item.com_data.content.data_auto_list = [];
//
goods_or_article_data_processing(item.com_data.content, item.key == new_array_1[0]);
} else if (new_array_2.includes(item.key)) {
item.com_data.content.tabs_active_index = 0;
item.com_data.content.tabs_list.map((item0: any) => {
if (item0.data_type == '0') {
item0.data_ids = item0.data_list.map((item1: any) => item1.data.id).join(',') || '';
item0.data_list = item0.data_list.map((item2: any) => {
return {
...item2,
data: [],
data_id: item2.data.id,
};
});
item0.category_ids = defaultConfigSetting.category_ids;
item0.number = defaultConfigSetting.page_size;
item0.order_by_rule = defaultConfigSetting.order_by_rule;
item0.order_by_type = defaultConfigSetting.order_by_type;
if (item.key == new_array_1[0]) {
item0.brand_ids = defaultConfigSetting.brand_ids;
} else {
item0.is_cover = defaultConfigSetting.is_cover;
}
} else {
item0.data_ids = '';
item0.data_list = [];
}
item0.data_auto_list = [];
item.com_data.content.tabs_list.forEach((item0: any) => {
//
goods_or_article_data_processing(item0, item.key == new_array_1[0]);
});
} else if (new_array_3.includes(item.key)) {
item.com_data.content.data_ids = item.com_data.content.data_list.map((item: any) => item.id).join(',') || '';
@ -318,7 +276,7 @@ const save_formmat_form_data = (data: diy_data_item, close: boolean = false, is_
item.com_data.content.number = defaultConfigSetting.page_size;
}
} else if (new_array_4.includes(item.key)) {
item.com_data.content.data_magic_list.map((item1: any) => {
item.com_data.content.data_magic_list.forEach((item1: any) => {
if (item1.data_content.data_type == 'goods') {
item1.data_content.goods_ids = item1.data_content.goods_list.map((item2: any) => item2.data.id).join(',') || '';
item1.data_content.goods_list = item1.data_content.goods_list.map((item3: any) => {
@ -339,24 +297,8 @@ const save_formmat_form_data = (data: diy_data_item, close: boolean = false, is_
item1.data_content.data_source_content = { data_type: 0, data_ids: '', data_list: [], data_auto_list: []}
}
} else if (item1.data_content.data_type == 'custom') {
if (item1.data_content.is_custom_data == '1' && item1.data_content.data_source_content.data_type === 0) {
const data_list = cloneDeep(item1.data_content.data_source_content.data_list);
// ,id
item1.data_content.data_source_content.data_ids = data_list.map((item4: any) => item4.data[item1.data_content?.show_data.data_key || 'id']).join(',') || '';
// ,data
item1.data_content.data_source_content.data_list = data_list.map((item5: any) => {
return {
...item5,
data: [],
data_id: item5.data[item1.data_content?.show_data.data_key || 'id'],
};
});
} else {
item1.data_content.data_source_content.data_ids = [];
item1.data_content.data_source_content.data_list = [];
}
//
item1.data_content.data_source_content.data_auto_list = [];
//
custom_data_processing(item1.data_content);
//
item1.data_content.goods_ids = '';
item1.data_content.goods_list= [];
@ -379,28 +321,37 @@ const save_formmat_form_data = (data: diy_data_item, close: boolean = false, is_
} else if (new_array_5.includes(item.key)) {
// data_source_content_value
item.com_data.content = omit(cloneDeep(item.com_data.content), ['data_source_content_value']);
//
if (item.com_data.content.is_custom_data == '1' && item.com_data.content.data_source_content.data_type === 0) {
//
const data_list = cloneDeep(item.com_data.content.data_source_content.data_list);
// ,id
item.com_data.content.data_source_content.data_ids = data_list.map((list_item: any) => list_item.data[item.com_data.content?.show_data.data_key || 'id'] || '').join(',') || '';
// ,data
item.com_data.content.data_source_content.data_list = data_list.map((list_item: any) => {
return {
...list_item,
data: [],
data_id: list_item.data[item.data_content?.show_data.data_key || 'id'],
};
});
} else {
item.com_data.content.data_source_content.data_ids = [];
item.com_data.content.data_source_content.data_list = [];
}
//
item.com_data.content.data_source_content.data_auto_list = [];
//
custom_data_processing(item.com_data.content);
} else if (new_array_6.includes(item.key)) {
item.com_data.content.nav_content_list = item.com_data.content.nav_content_list.map((item0: any) => ({...omit(item0, 'tabs_name') }));
} else if (['data-tabs'].includes(item.key)) {
const new_tabs_list = item?.com_data?.content?.tabs_list || [];
new_tabs_list.forEach((item: any) => {
if (item.tabs_data_type == 'goods' || item.tabs_data_type == 'article') {
const new_com_data = item.tabs_data_type == 'goods' ? item.goods_config : item.article_config;
//
goods_or_article_data_processing(new_com_data.content, item.tabs_data_type == 'goods');
//
if (item.tabs_data_type == 'goods') {
goods_or_article_data_clear(item.article_config.content, false);
clear_custom_data(item.custom_config.content);
} else {
//
goods_or_article_data_clear(item.goods_config.content, true);
clear_custom_data(item.custom_config.content);
}
} else if (item.tabs_data_type == 'custom') {
const new_com_data = item.custom_config;
// data_source_content_value
new_com_data.content = omit(cloneDeep(new_com_data.content), ['data_source_content_value']);
//
custom_data_processing(new_com_data.content);
//
goods_or_article_data_clear(item.goods_config.content, true);
goods_or_article_data_clear(item.article_config.content, false);
}
});
}
return {
...item,
@ -445,7 +396,107 @@ const save_formmat_form_data = (data: diy_data_item, close: boolean = false, is_
save_disabled.value = false;
});
};
/**
* 商品或文章数据处理函数
* 该函数根据提供的数据类型和是否为商品的标志处理数据内容的结构
* 主要目的是为了标准化数据处理逻辑使得数据格式符合预期的要求
*
* @param new_com_data_content 传入的新数据内容对象包含需要处理的数据列表和其他相关信息
* @param is_goods 是否为商品的标志用于决定数据处理的具体方式
*/
const goods_or_article_data_processing = (new_com_data_content: any, is_goods: boolean) => {
// '0'
if (new_com_data_content.data_type == '0') {
// ID
new_com_data_content.data_ids = new_com_data_content.data_list.map((item: any) => item.data.id).join(',') || '';
//
new_com_data_content.data_list = new_com_data_content.data_list.map((item1: any) => {
return {
...item1,
data: [],
data_id: item1.data.id,
};
});
// ID
new_com_data_content.category_ids = defaultConfigSetting.category_ids;
new_com_data_content.number = defaultConfigSetting.page_size;
new_com_data_content.order_by_rule = defaultConfigSetting.order_by_rule;
new_com_data_content.order_by_type = defaultConfigSetting.order_by_type;
// ID
if (is_goods) {
new_com_data_content.brand_ids = defaultConfigSetting.brand_ids;
} else {
new_com_data_content.is_cover = defaultConfigSetting.is_cover;
}
} else {
// '0'ID
new_com_data_content.data_ids = '';
new_com_data_content.data_list = [];
}
//
new_com_data_content.data_auto_list = [];
};
//
const goods_or_article_data_clear = (new_com_data_content: any, is_goods: boolean) => {
new_com_data_content.data_ids = '';
new_com_data_content.data_list = [];
//
new_com_data_content.data_auto_list = [];
// ID
new_com_data_content.category_ids = defaultConfigSetting.category_ids;
new_com_data_content.number = defaultConfigSetting.page_size;
new_com_data_content.order_by_rule = defaultConfigSetting.order_by_rule;
new_com_data_content.order_by_type = defaultConfigSetting.order_by_type;
// ID
if (is_goods) {
new_com_data_content.brand_ids = defaultConfigSetting.brand_ids;
} else {
new_com_data_content.is_cover = defaultConfigSetting.is_cover;
}
}
const clear_custom_data = (new_com_data_content: any) => {
// 0
new_com_data_content.data_source_content.data_ids = [];
new_com_data_content.data_source_content.data_list = [];
//
new_com_data_content.data_source_content.data_auto_list = [];
}
/**
* 自定义数据处理函数
* 该函数用于处理新组件数据内容根据数据是否为自定义以及数据类型对数据进行相应的处理和格式化
* @param {any} new_com_data_content - 新组件的数据内容对象包含数据源和显示数据等信息
*/
const custom_data_processing = (new_com_data_content: any) => {
// 00
if (new_com_data_content.is_custom_data == '1' && new_com_data_content.data_source_content.data_type === 0) {
//
const data_list = cloneDeep(new_com_data_content.data_source_content.data_list);
// ,id
new_com_data_content.data_source_content.data_ids = data_list.map((list_item: any) => list_item.data[new_com_data_content?.show_data.data_key || 'id'] || '').join(',') || '';
// ,data
new_com_data_content.data_source_content.data_list = data_list.map((list_item: any) => {
return {
...list_item,
data: [],
data_id: list_item.data[new_com_data_content?.show_data.data_key || 'id'],
};
});
} else {
// 0
new_com_data_content.data_source_content.data_ids = [];
new_com_data_content.data_source_content.data_list = [];
}
//
new_com_data_content.data_source_content.data_auto_list = [];
};
//#endregion ---------------------end
//
const diy_data_transfor_form_data = (clone_form: diy_data_item) => {
return {