diff --git a/src/views/site/drawer.vue b/src/views/site/drawer.vue
index 408b35a..2f5ceae 100644
--- a/src/views/site/drawer.vue
+++ b/src/views/site/drawer.vue
@@ -169,7 +169,7 @@ function countNovelInfoUrl(array) {
}
const templateList = ref();
-// 获取分组ID列表
+// 获取模板列表
getAllList().then(res => {
templateList.value = res.data.items;
});
@@ -523,9 +523,15 @@ const acceptParams = (params: DrawerProps) => {
// }
};
const handleSelectChange = value => {
+ // 获取选择的 模板
const matchedTemplate = templateList.value.find(item => item.t_id === value);
+
+ // 这里我想 同步下原有模板的值 数据到 新模板
+
+ // 将站点原有的模板 替换成 选择的模板
drawerProps.value.row.t_cfg = matchedTemplate.t_cfg_template;
};
+
const handleSelectChangeUrl = value => {
var strKey = "模板";
var temp = drawerProps.value.row.t_cfg;
diff --git a/src/views/site/index.vue b/src/views/site/index.vue
index 45c8bb8..5ec13de 100644
--- a/src/views/site/index.vue
+++ b/src/views/site/index.vue
@@ -12,6 +12,7 @@
新增
批量添加
缓存清理
+ 模板重置
import { reactive, ref } from "vue";
+import { ElMessage, FormInstance } from "element-plus";
import { SiteList } from "@/api/interface/site/list";
import { useHandleData } from "@/hooks/useHandleData";
import ProTable from "@/components/ProTable/index.vue";
-import { Delete, EditPen, CirclePlus,Upload, Refresh } from "@element-plus/icons-vue";
+import { Delete, EditPen, CirclePlus, Upload, Refresh } from "@element-plus/icons-vue";
import { ProTableInstance, ColumnProps } from "@/components/ProTable/interface";
-import { getList, saveData, uploadExcel, cacheFlush ,deleteItem, buildItem, landingItem } from "@/api/modules/site/list";
+import { getList, saveData, uploadExcel, cacheFlush, deleteItem, buildItem, landingItem } from "@/api/modules/site/list";
import { getAllList } from "@/api/modules/site/template";
import Drawer from "./drawer.vue";
import { arrColorType } from "@/utils/serviceDict";
@@ -89,13 +91,13 @@ const proTable = ref();
const importRef = ref();
const batchAdd = () => {
- let params = {
- title: "站点",
- tempApi: '',
- importApi: uploadExcel,
- getTableList: proTable.value?.getTableList
- };
- importRef.value.acceptParams(params);
+ let params = {
+ title: "站点",
+ tempApi: "",
+ importApi: uploadExcel,
+ getTableList: proTable.value?.getTableList
+ };
+ importRef.value.acceptParams(params);
};
const initParam = reactive({
@@ -103,9 +105,12 @@ const initParam = reactive({
page: 1
});
+let arrSiteData = [];
+
const dataCallback = (data: any) => {
// 转换为数组
const arr = data.items;
+ arrSiteData = arr;
return {
items: arr,
total: data.total,
@@ -125,7 +130,6 @@ const getTableList = (params: any) => {
// 分组
const getTempLateList = ref([] as any);
getAllList().then(res => {
-
getTempLateList.value = res.data.items;
});
@@ -212,7 +216,7 @@ const columns = reactive[]>([
enum: [
{ label: "否", value: 0 },
{ label: "是", value: 1 }
- ],
+ ]
},
{
prop: "d_logo_type",
@@ -221,7 +225,7 @@ const columns = reactive[]>([
enum: [
{ label: "文字", value: 0 },
{ label: "图片", value: 1 }
- ],
+ ]
},
{
prop: "d_img_logo",
@@ -246,8 +250,7 @@ const columns = reactive[]>([
}
}
},
-
-
+
{
prop: "d_statis",
width: 170,
@@ -269,6 +272,99 @@ const clearCache = async (params: SiteList.ResList) => {
proTable.value?.getTableList();
};
+const resetTmp = async (params: SiteList.ResList) => {
+ await useHandleData(resetTmpFun, {}, "模板重置");
+ proTable.value?.getTableList();
+};
+
+const resetTmpFun = async (params: SiteList.ResList) => {
+ console.log("模板重置");
+ // 所有站点
+ console.log(arrSiteData);
+ // 所有模板
+ console.log(getTempLateList.value);
+
+ // 检查是否存在新增配置的函数
+ const hasNewConfig = (target: any, source: any): boolean => {
+ for (const key in source) {
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
+ if (!(key in target)) {
+ return true; // 发现新增键
+ }
+ // 如果是对象,递归检查子对象
+ if (
+ typeof source[key] === "object" &&
+ source[key] !== null &&
+ !Array.isArray(source[key]) &&
+ typeof target[key] === "object" &&
+ target[key] !== null &&
+ !Array.isArray(target[key])
+ ) {
+ if (hasNewConfig(target[key], source[key])) {
+ return true; // 子对象中有新增键
+ }
+ }
+ }
+ }
+ return false; // 没有新增配置
+ };
+
+ // 深度合并函数,优先保留原有数据,补充新模板的配置
+ const deepMerge = (target: any, source: any): any => {
+ const output = { ...target }; // 复制目标对象(站点模板)
+ for (const key in source) {
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
+ // 如果目标对象没有这个键,直接添加新模板的配置
+ if (!(key in target)) {
+ output[key] = source[key];
+ }
+ // 如果目标对象有这个键,且两者都是对象,递归合并
+ else if (
+ typeof source[key] === "object" &&
+ source[key] !== null &&
+ !Array.isArray(source[key]) &&
+ typeof target[key] === "object" &&
+ target[key] !== null &&
+ !Array.isArray(target[key])
+ ) {
+ output[key] = deepMerge(target[key], source[key]);
+ }
+ // 其他情况(基本类型、数组等),保留目标对象的值,不覆盖
+ }
+ }
+ return output;
+ };
+
+ // 遍历所有站点
+ arrSiteData.forEach((site: any) => {
+ // 根据站点的 t_id 查找对应模板
+ const matchedTemplate = getTempLateList.value.find((template: any) => template.t_id === site.t_id);
+
+ if (matchedTemplate) {
+ // 检查是否有新增配置
+ if (hasNewConfig(site.t_cfg || {}, matchedTemplate.t_cfg_template)) {
+ // 合并站点模板和基础模板,保留站点原有数据
+ site.t_cfg = deepMerge(
+ site.t_cfg || {}, // 确保站点模板存在
+ matchedTemplate.t_cfg_template
+ );
+ // 保存数据并提交
+ saveData(site);
+ ElMessage.success({ message: `${site.d_name}重置成功!` });
+ console.log(`站点 ${site.d_name} 重置成功!`);
+ } else {
+ ElMessage.success({ message: `站点${site.d_name} 无新增配置,跳过更新` });
+ console.log(`站点 ${site.d_name} 无新增配置,跳过更新`);
+ }
+ } else {
+ console.warn(`未找到站点 ${site.t_id} 对应的模板`);
+ }
+ });
+
+ // 刷新表格数据
+ // await useHandleData(cacheFlush, {}, "模板重置");
+ proTable.value?.getTableList();
+};
// 批量删除站点信息
const batchDelete = async (id: any[]) => {
const ids = id.map((item: SiteList.ResList) => item.si_id);