Ver Fonte

新增删除配置项

zhangjie há 2 anos atrás
pai
commit
b0bcbba724

+ 3 - 0
src/modules/admin/api.js

@@ -116,6 +116,9 @@ export const appConfigList = datas => {
 export const appConfigItemUpdate = datas => {
   return $postParam("/api/admin/property/item/update", datas);
 };
+export const appConfigItemDelete = datas => {
+  return $postParam("/api/admin/property/item/delete", datas);
+};
 // app-nginx
 export const appNginxConfig = datas => {
   return $postParam("/api/admin/nginx/find", datas);

+ 37 - 8
src/modules/admin/components/AppConfigManage.vue

@@ -146,6 +146,13 @@
                     @click="toEdit(item)"
                     >编辑</el-button
                   >
+                  <el-button
+                    v-if="!item.isFromBaseline && group.name !== 'custom'"
+                    class="btn-danger cont-edit"
+                    type="text"
+                    @click="toDelete(item)"
+                    >删除</el-button
+                  >
                 </div>
               </div>
             </div>
@@ -173,7 +180,7 @@
       ref="ModifyAppConfigItem"
       :instance="curConfigItem"
       :group="curGroupForAdd"
-      @modified="search"
+      @modified="resetSearch"
     ></modify-app-config-item>
   </div>
 </template>
@@ -184,7 +191,8 @@ import {
   appConfigModes,
   appConfigGroups,
   appEnvList,
-  appConfigList
+  appConfigList,
+  appConfigItemDelete
 } from "../api";
 import UpdateAppBaseline from "../components/UpdateAppBaseline.vue";
 import ModifyAppBaselineItem from "../components/ModifyAppBaselineItem.vue";
@@ -369,14 +377,17 @@ export default {
 
       this.searchFilter = { ...this.filter };
 
-      if (this.filter.envId) {
+      await this.resetSearch();
+      this.$refs.ConfigTableBody.scrollTop = 0;
+    },
+    async resetSearch() {
+      if (this.searchFilter.envId) {
         await this.getConfigList();
         this.buildGroupConfigList(this.configList);
       } else {
         await this.getBaselineList();
         this.buildGroupConfigList(this.baselineList);
       }
-      this.$refs.ConfigTableBody.scrollTop = 0;
     },
     getCacheBaselineList() {
       const k = [
@@ -410,17 +421,18 @@ export default {
       const data = await appConfigList(this.searchFilter);
 
       let configList = this.baselineList.map(item => {
-        let nitem = { ...item };
+        let nitem = { ...item, isFromBaseline: true };
         if (item.mode === "OVERRIDE") nitem.value = null;
         nitem.refVal = item.value;
         return nitem;
       });
+      // 只有配置项位于group分组内,不是应用自定义,且基线不包含此配置项时才能删除
       data.forEach(item => {
         let bIndex = configList.findIndex(citem => citem.key === item.key);
         if (bIndex !== -1) {
           configList[bIndex].value = item.value;
         } else {
-          configList.push({ ...item });
+          configList.push({ ...item, isFromBaseline: false });
         }
       });
       this.configList = configList;
@@ -547,11 +559,28 @@ export default {
     },
     baselineItemModified() {
       this.setCacheBaselineList([]);
-      this.search();
+      this.resetSearch();
     },
     baselineModified(data) {
       this.setCacheBaselineList(data);
-      this.search();
+      this.resetSearch();
+    },
+    async toDelete(item) {
+      const confirm = await this.$confirm(
+        `确定要删除配置项【${item.key}】吗?`,
+        "提示",
+        {
+          type: "warning"
+        }
+      ).catch(() => {});
+      if (confirm !== "confirm") return;
+      const res = await appConfigItemDelete({
+        ...this.filter,
+        key: item.key
+      }).catch(() => {});
+      if (!res) return;
+      this.$message.success("删除成功!");
+      this.resetSearch();
     },
     scrollTo(group) {
       this.$refs.ConfigTableBody.scrollTop =