Browse Source

接口调试

zhangjie 2 years ago
parent
commit
04b1929320

+ 5 - 1
src/assets/styles/home.scss

@@ -627,9 +627,13 @@
   .privilege-group {
     margin-bottom: 20px;
     &-title {
-      font-weight: 600;
       line-height: 1;
       padding-bottom: 10px;
+
+      .el-checkbox__label {
+        font-weight: 600;
+        color: $--color-text-dark-1 !important;
+      }
     }
 
     .privilege-item {

+ 75 - 29
src/constants/privilege.js

@@ -3,15 +3,15 @@ export const privilegeConfig = [
     title: "用户",
     options: [
       {
-        code: "USER_VIEW",
+        permission: "USER_VIEW",
         name: "用户管理",
       },
       {
-        code: "USER_INSERT",
+        permission: "USER_INSERT",
         name: "用户新增",
       },
       {
-        code: "USER_EDIT",
+        permission: "USER_EDIT",
         name: "用户修改",
       },
     ],
@@ -20,15 +20,15 @@ export const privilegeConfig = [
     title: "微信小程序",
     options: [
       {
-        code: "WXAPP_VIEW",
+        permission: "WXAPP_VIEW",
         name: "微信小程序管理",
       },
       {
-        code: "WXAPP_INSERT",
+        permission: "WXAPP_INSERT",
         name: "微信小程序新增",
       },
       {
-        code: "WXAPP_EDIT",
+        permission: "WXAPP_EDIT",
         name: "微信小程序修改",
       },
     ],
@@ -37,15 +37,15 @@ export const privilegeConfig = [
     title: "机构",
     options: [
       {
-        code: "ORG_VIEW",
+        permission: "ORG_VIEW",
         name: "机构管理",
       },
       {
-        code: "ORG_INSERT",
+        permission: "ORG_INSERT",
         name: "机构新增",
       },
       {
-        code: "ORG_EDIT",
+        permission: "ORG_EDIT",
         name: "机构修改",
       },
     ],
@@ -54,11 +54,11 @@ export const privilegeConfig = [
     title: "应用",
     options: [
       {
-        code: "APP_INSERT",
+        permission: "APP_INSERT",
         name: "应用新增",
       },
       {
-        code: "APP_EDIT",
+        permission: "APP_EDIT",
         name: "应用修改",
       },
     ],
@@ -67,11 +67,11 @@ export const privilegeConfig = [
     title: "模块",
     options: [
       {
-        code: "MODULE_INSERT",
+        permission: "MODULE_INSERT",
         name: "模块新增",
       },
       {
-        code: "MODULE_EDIT",
+        permission: "MODULE_EDIT",
         name: "模块修改",
       },
     ],
@@ -80,11 +80,11 @@ export const privilegeConfig = [
     title: "环境",
     options: [
       {
-        code: "ENV_INSERT",
+        permission: "ENV_INSERT",
         name: "环境新增",
       },
       {
-        code: "ENV_EDIT",
+        permission: "ENV_EDIT",
         name: "环境修改",
       },
     ],
@@ -93,12 +93,12 @@ export const privilegeConfig = [
     title: "版本",
     options: [
       {
-        code: "VERSION_INSERT",
+        permission: "VERSION_INSERT",
         name: "版本新增",
         dataPrivilege: "app.id",
       },
       {
-        code: "VERSION_EDIT",
+        permission: "VERSION_EDIT",
         name: "版本修改",
         dataPrivilege: "app.id",
       },
@@ -108,14 +108,14 @@ export const privilegeConfig = [
     title: "程序配置",
     options: [
       {
-        code: "PROPERTY_BASELINE_EDIT",
+        permission: "PROPERTY_BASELINE_EDIT",
         name: "基线配置修改",
         dataPrivilege: "app.id",
       },
       {
-        code: "PROPERTY_EDIT",
+        permission: "PROPERTY_EDIT",
         name: "程序配置修改",
-        dataPrivilege: "app.id",
+        dataPrivilege: "env.id",
       },
     ],
   },
@@ -123,14 +123,14 @@ export const privilegeConfig = [
     title: "Nginx配置",
     options: [
       {
-        code: "NGINX_BASELINE_EDIT",
+        permission: "NGINX_BASELINE_EDIT",
         name: "Nginx基线修改",
         dataPrivilege: "app.id",
       },
       {
-        code: "NGINX_EDIT",
+        permission: "NGINX_EDIT",
         name: "Nginx配置修改",
-        dataPrivilege: "app.id",
+        dataPrivilege: "env.id",
       },
     ],
   },
@@ -138,34 +138,80 @@ export const privilegeConfig = [
     title: "部署",
     options: [
       {
-        code: "DEPLOY_INSERT",
+        permission: "DEPLOY_INSERT",
         name: "部署新增",
       },
       {
-        code: "DEPLOY_EDIT",
+        permission: "DEPLOY_EDIT",
         name: "部署修改",
         dataPrivilege: "deploy.id",
       },
       {
-        code: "DEPLOY_ORG_EDIT",
+        permission: "DEPLOY_ORG_EDIT",
         name: "部署绑定机构修改",
         dataPrivilege: "deploy.id",
       },
       {
-        code: "DEPLOY_DEVICE_EDIT",
+        permission: "DEPLOY_DEVICE_EDIT",
         name: "部署绑定设备修改",
         dataPrivilege: "deploy.id",
       },
       {
-        code: "DEPLOY_SECRET_VIEW",
+        permission: "DEPLOY_SECRET_VIEW",
         name: "部署密钥查看",
         dataPrivilege: "deploy.id",
       },
       {
-        code: "DEPLOY_LICENSE_DOWNLOAD",
+        permission: "DEPLOY_LICENSE_DOWNLOAD",
         name: "部署证书下载",
         dataPrivilege: "deploy.id",
       },
     ],
   },
 ];
+
+export const permission = [
+  {
+    permission: "USER_VIEW",
+    scope: "*",
+  },
+  {
+    permission: "USER_INSERT",
+    scope: "*",
+  },
+  {
+    permission: "USER_EDIT",
+    scope: "*",
+  },
+  {
+    permission: "WXAPP_VIEW",
+    scope: "*",
+  },
+  {
+    permission: "WXAPP_INSERT",
+    scope: "*",
+  },
+  {
+    permission: "WXAPP_EDIT",
+    scope: "*",
+  },
+  {
+    permission: "ORG_VIEW",
+    scope: "*",
+  },
+  {
+    permission: "ORG_INSERT",
+    scope: "*",
+  },
+  {
+    permission: "ORG_EDIT",
+    scope: "*",
+  },
+];
+
+let privilegeMap = {};
+permission.forEach((item) => {
+  privilegeMap[item.permission] = item.scope;
+});
+
+export { privilegeMap };

+ 3 - 8
src/modules/admin/app-config/AppConfigManage.vue

@@ -267,9 +267,6 @@ export default {
     IS_BASELINE() {
       return this.filter.envId === null;
     },
-    IS_MAINTAINER() {
-      return this.curEnv.user && this.curEnv.user.id === this.user.id;
-    },
   },
   created() {
     this.user = this.$ls.get("user", {});
@@ -309,18 +306,16 @@ export default {
       this.groupConfigList = [];
     },
     checkAddPrivilege(group) {
-      const privilege =
-        this.checkPrivilege("PROPERTY_EDIT", this.app.id) || this.IS_MAINTAINER;
+      const privilege = this.checkPrivilege("PROPERTY_EDIT", this.filter.envId);
       return group.name !== "custom" && !this.IS_BASELINE && privilege;
     },
     checkEditPrivilege(item) {
-      const privilege = this.checkPrivilege("PROPERTY_EDIT", this.app.id);
+      const privilege = this.checkPrivilege("PROPERTY_EDIT", this.filter.envId);
 
       return (
         (item.mode !== "READONLY" && privilege) ||
         (this.checkPrivilege("PROPERTY_BASELINE_EDIT", this.appa.id) &&
-          this.IS_BASELINE) ||
-        (!this.IS_BASELINE && this.IS_MAINTAINER)
+          this.IS_BASELINE)
       );
     },
     cancel() {

+ 0 - 5
src/modules/admin/app-deploy/AppDeployManage.vue

@@ -91,9 +91,6 @@
 
     <!-- ModifyAppDeploy -->
     <modify-app-deploy
-      v-if="
-        checkPrivilege('DEPLOY_INSERT') || checkPrivilege('app_deploy_edit')
-      "
       ref="ModifyAppDeploy"
       :instance="curRow"
       :deploy-modes="deployModes"
@@ -101,13 +98,11 @@
     ></modify-app-deploy>
     <!-- AppDeployBindOrg -->
     <app-deploy-bind-org
-      v-if="checkPrivilege('DEPLOY_ORG_EDIT', scope.row.id)"
       ref="AppDeployBindOrg"
       :instance="curRow"
     ></app-deploy-bind-org>
     <!-- AppDeployBindDevice -->
     <app-deploy-bind-device
-      v-if="checkPrivilege('DEPLOY_DEVICE_EDIT', scope.row.id)"
       ref="AppDeployBindDevice"
       :instance="curRow"
     ></app-deploy-bind-device>

+ 0 - 14
src/modules/admin/app-env/AppEnvManage.vue

@@ -40,18 +40,6 @@
           <el-table-column prop="code" label="编码"> </el-table-column>
           <el-table-column prop="typeName" label="分类" width="100">
           </el-table-column>
-          <el-table-column prop="userName" label="维护人" width="120">
-          </el-table-column>
-          <!-- <el-table-column prop="createTime" label="创建时间" width="160">
-            <span slot-scope="scope">{{
-              scope.row.createTime | timestampFilter
-            }}</span>
-          </el-table-column>
-          <el-table-column prop="updateTime" label="修改时间" width="160">
-            <span slot-scope="scope">{{
-              scope.row.updateTime | timestampFilter
-            }}</span>
-          </el-table-column> -->
           <el-table-column
             v-if="checkPrivilege('ENV_EDIT')"
             label="操作"
@@ -144,8 +132,6 @@ export default {
       const data = await appEnvList(datas);
       this.dataList = data.map((item) => {
         item.typeName = this.envTypeMap[item.type];
-        item.userId = item.user && item.user.id;
-        item.userName = item.user && item.user.name;
         return item;
       });
     },

+ 1 - 1
src/modules/admin/app-module/AppModuleManage.vue

@@ -146,7 +146,7 @@ export default {
   },
   methods: {
     async visibleChange() {
-      await this.moduleTypes();
+      await this.getModuleTypes();
       await this.getList();
     },
     cancel() {

+ 4 - 1
src/modules/admin/app-nginx/AppNginxManage.vue

@@ -91,7 +91,10 @@ export default {
     },
   },
   created() {
-    this.hasBaselinePrivilege = this.checkPrivilege("app_nginx_baseline");
+    this.hasBaselinePrivilege = this.checkPrivilege(
+      "NGINX_BASELINE_EDIT",
+      this.app.id
+    );
   },
   methods: {
     async visibleChange(visible) {

+ 3 - 8
src/modules/admin/app-nginx/EditNginxContent.vue

@@ -71,11 +71,6 @@ export default {
       user: {},
     };
   },
-  computed: {
-    IS_MAINTAINER() {
-      return this.curEnv.user && this.curEnv.user.id === this.user.id;
-    },
-  },
   created() {
     this.user = this.$ls.get("user", {});
     this.initData();
@@ -103,12 +98,12 @@ export default {
     },
     checkEditPrivilege() {
       const privilege =
-        (this.checkPrivilege("NGINX_EDIT", this.filter.appId) &&
+        (this.checkPrivilege("NGINX_EDIT", this.curEnv.id) &&
           !this.isBaseline) ||
-        (this.checkPrivilege("NGINX_BASELINE_EDIT", this.filter.appId) &&
+        (this.checkPrivilege("NGINX_BASELINE_EDIT", this.filterData.appId) &&
           this.isBaseline);
 
-      return privilege || (!this.isBaseline && this.IS_MAINTAINER);
+      return privilege;
     },
     async search() {
       if (!this.isBaseline && !this.curEnv.id) {

+ 1 - 1
src/modules/admin/app-version/AppVersionManage.vue

@@ -167,7 +167,7 @@ export default {
   },
   methods: {
     visibleChange() {
-      this.curMasterVersionId = this.app.masterVersionId;
+      this.curMasterVersionId = this.app.latestVersionId;
       this.toPage(1);
     },
     cancel() {

+ 2 - 2
src/modules/admin/app/AppManage.vue

@@ -31,7 +31,7 @@
         <el-table-column prop="id" label="ID" width="80"></el-table-column>
         <el-table-column prop="name" label="名称"> </el-table-column>
         <el-table-column prop="code" label="编码"> </el-table-column>
-        <el-table-column prop="masterVersionName" label="主干版本" width="120">
+        <el-table-column prop="latestVersionName" label="主干版本" width="120">
         </el-table-column>
         <el-table-column
           v-if="checkPrivilege('APP_EDIT')"
@@ -144,7 +144,7 @@ import AppUserManage from "../app-user/AppUserManage.vue";
 import AppDeployManage from "../app-deploy/AppDeployManage.vue";
 import AppModuleManage from "../app-module/AppModuleManage.vue";
 import AppVersionManage from "../app-version/AppVersionManage.vue";
-import AppEnvManage from "../app-version/AppVersionManage.vue";
+import AppEnvManage from "../app-env/AppEnvManage.vue";
 import AppConfigManage from "../app-config/AppConfigManage.vue";
 import AppNginxManage from "../app-nginx/AppNginxManage.vue";
 

+ 23 - 11
src/modules/admin/user/ModifyPrivilege.vue

@@ -30,12 +30,16 @@
       <div class="part-box part-box-pad">
         <div v-for="item in dataList" :key="item.id" class="privilege-group">
           <div class="privilege-group-title">
-            <h3>{{ item.title }}</h3>
+            <el-checkbox
+              v-model="item.selected"
+              @change="groupCheckChange(item)"
+              >{{ item.title }}</el-checkbox
+            >
           </div>
           <div class="privilege-group-body">
             <div
               v-for="option in item.options"
-              :key="option.code"
+              :key="option.permission"
               :class="[
                 'privilege-item',
                 { 'privilege-item-scope': option.dataPrivilege },
@@ -128,7 +132,7 @@ export default {
       data.forEach((item) => {
         if (!groups[item.appCode]) {
           groups[item.appCode] = {
-            id: groupId++,
+            id: `app-${groupId++}`,
             name: item.appName,
             code: item.appCode,
             children: [],
@@ -156,18 +160,23 @@ export default {
       let userPrivilege = {};
       const privilegeData = res || [];
       privilegeData.forEach((item) => {
-        userPrivilege[item.code] = item.scope;
+        userPrivilege[item.permission] = item.scope;
       });
 
       let dataList = privilegeConfig.map((item) => {
-        let nitem = { id: this.$randomCode(), title: item.title };
+        let nitem = {
+          id: this.$randomCode(),
+          title: item.title,
+          selected: false,
+        };
         nitem.options = item.options.map((option) => {
           return {
             ...option,
-            selected: !!userPrivilege[option.code],
-            scope: userPrivilege[option.code] || "*",
+            selected: !!userPrivilege[option.permission],
+            scope: userPrivilege[option.permission] || "*",
           };
         });
+        nitem.selected = !nitem.options.some((option) => !option.selected);
         return nitem;
       });
       this.dataList = dataList;
@@ -177,11 +186,14 @@ export default {
       this.dataList.forEach((item) => {
         item.options.forEach((option) => {
           if (!option.selected) return;
-          data.push({ code: option.code, scope: option.scope });
+          data.push({ permission: option.permission, scope: option.scope });
         });
       });
       return data;
     },
+    groupCheckChange(group) {
+      group.options.forEach((option) => (option.selected = group.selected));
+    },
     async submit() {
       const data = this.getData();
       if (!data.length) {
@@ -193,13 +205,13 @@ export default {
       this.isSubmit = true;
       const res = await userPermissionSave({
         userId: this.user.id,
-        permission: data,
+        permissions: data,
       }).catch(() => {});
       this.isSubmit = false;
       if (!res) return;
       this.$message.success("设置成功!");
-      this.$emit("modified");
-      this.cancel;
+      // this.$emit("modified");
+      this.cancel();
     },
   },
 };

+ 15 - 15
src/modules/admin/user/PrivilegeScopeEdit.vue

@@ -3,7 +3,7 @@
     <span class="scope-edit-label">数据范围:</span>
     <div class="scope-edit-content">
       <div>
-        <span class="mr-2" v-if="!selectedScopes.length">无限制</span>
+        <span class="mr-2" v-if="!selectedSources.length">无限制</span>
         <el-button
           class="btn-primary cont-edit"
           size="medium"
@@ -14,7 +14,7 @@
       </div>
 
       <el-tag
-        v-for="item in selectedScopes"
+        v-for="item in selectedSources"
         :key="item.id"
         effect="dark"
         type="primary"
@@ -25,7 +25,7 @@
     <!-- SelectScopeDialog -->
     <select-scope-dialog
       ref="SelectScopeDialog"
-      :selected="selectedScopeIds"
+      :selected="selectedSourceIds"
       :source-list="sourceList"
       @modified="scopeChange"
     ></select-scope-dialog>
@@ -55,31 +55,31 @@ export default {
       immediate: true,
       handler(val) {
         if (!val || val === "*") {
-          this.selectedScopeIds = [];
-          this.selectedScopes = [];
+          this.selectedSourceIds = [];
+          this.selectedSources = [];
         } else {
-          this.selectedScopeIds = val.split(",").map((item) => item * 1);
-          this.getSelectedScopes(this.selectedScopeIds);
+          this.selectedSourceIds = val.split(",").map((item) => item * 1);
+          this.getSelectedScopes(this.selectedSourceIds);
         }
       },
     },
   },
   data() {
     return {
-      selectedScopes: [],
-      selectedScopeIds: [],
+      selectedSources: [],
+      selectedSourceIds: [],
     };
   },
   methods: {
     toSelect() {
       this.$refs.SelectScopeDialog.open();
     },
-    getSelectedScopes(selectedScopeIds) {
-      let selectedScopes = [];
+    getSelectedScopes(selectedSourceIds) {
+      let selectedSources = [];
       const search = (dataList) => {
         dataList.forEach((item) => {
-          if (selectedScopeIds.includes(item.id)) {
-            selectedScopes.push({ id: item.id, name: item.name });
+          if (selectedSourceIds.includes(item.id)) {
+            selectedSources.push({ id: item.id, name: item.name });
           }
           if (item.children && item.children.length) {
             search(item.children);
@@ -87,11 +87,11 @@ export default {
         });
       };
       search(this.sourceList);
-      this.selectedSources = selectedScopes;
+      this.selectedSources = selectedSources;
     },
     scopeChange(selectedSources) {
       this.selectedSources = selectedSources;
-      const scope = this.selectedScopes.map((item) => item.id).join();
+      const scope = this.selectedSources.map((item) => item.id).join();
       this.$emit("input", scope || "*");
       this.$emit("change", scope || "*");
     },

+ 31 - 15
src/modules/admin/user/SelectScopeDialog.vue

@@ -12,6 +12,7 @@
   >
     <el-row type="flex" :gutter="10">
       <el-col :span="12">
+        <div class="select-part-title">数据范围</div>
         <div class="select-search">
           <el-input
             v-model="filterLabel"
@@ -27,8 +28,11 @@
             ref="DataTree"
             :data="dataList"
             node-key="id"
-            :default-checked-keys="selectedSourceIds"
+            show-checkbox
+            check-on-click-node
             :props="defaultProps"
+            :filter-node-method="filterNode"
+            @check-change="checkChange"
           >
           </el-tree>
         </div>
@@ -48,7 +52,7 @@
               class="select-delete"
               type="text"
               icon="el-icon-remove"
-              @click="toDelete(user)"
+              @click="toDelete(item)"
             ></el-button>
           </div>
         </div>
@@ -98,15 +102,8 @@ export default {
       this.dataList = deepCopy(this.sourceList);
       this.filterLabel = "";
 
-      this.$refs.DataTree.setCheckedKeys(this.selectedSourceIds);
-      const selectedData = this.$refs.DataTree.getCheckedNodes(true);
-      this.selectedSources = selectedData.map((item) => {
-        return {
-          id: item.id,
-          name: item.name,
-        };
-      });
-      this.selectedSourceIds = this.selectedData.map((item) => item.id);
+      this.$refs.DataTree.setCheckedKeys(this.selected, true);
+      this.checkChange();
     },
     cancel() {
       this.modalIsShow = false;
@@ -116,13 +113,32 @@ export default {
     },
     labelChange() {
       this.$refs.DataTree.filter(this.filterLabel);
-      this.$refs.DataTree.setCheckedKeys(this.selectedSourceIds);
+      this.$refs.DataTree.setCheckedKeys(this.selectedSourceIds, true);
+    },
+    filterNode(value, data) {
+      if (!value) return true;
+
+      const escapeRegexpString = (val = "") =>
+        String(val).replace(/[|\\{}()[\]^$+*?.]/g, "\\$&");
+      const reg = new RegExp(escapeRegexpString(value), "i");
+      return reg.test(data.name);
+    },
+    checkChange() {
+      const selectedData = this.$refs.DataTree.getCheckedNodes(true);
+      this.selectedSources = selectedData.map((item) => {
+        return {
+          id: item.id,
+          name: item.name,
+        };
+      });
+      this.selectedSourceIds = selectedData.map((item) => item.id);
     },
     toDelete(data) {
-      const pos = this.selectedSources.findIndex((item) => item.id === data.id);
-      this.selectedSources.splice(pos, 1);
+      this.selectedSources = this.selectedSources.filter(
+        (item) => item.id !== data.id
+      );
       this.selectedSourceIds = this.selectedSources.map((item) => item.id);
-      this.$refs.DataTree.setCheckedKeys(this.selectedSourceIds);
+      this.$refs.DataTree.setCheckedKeys(this.selectedSourceIds, true);
     },
     submit() {
       this.$emit("modified", this.selectedSources);

+ 1 - 1
src/modules/login/views/Login.vue

@@ -119,7 +119,7 @@ export default {
       const permissions = data.permissions || [];
       let privilegeMap = {};
       permissions.forEach((item) => {
-        privilegeMap[item.code] = item.scope;
+        privilegeMap[item.permission] = item.scope;
       });
       this.$store.commit("setPrivilegeMap", privilegeMap);
       this.$ls.set("privilegeMap", privilegeMap);

+ 1 - 0
src/store.js

@@ -5,6 +5,7 @@ Vue.use(Vuex);
 
 const privilegeMapData = window.sessionStorage.getItem("vs_privilegeMap");
 const privilegeMap = privilegeMapData ? JSON.parse(privilegeMapData).value : {};
+// import { privilegeMap } from "@/constants/privilege";
 
 export default new Vuex.Store({
   state: {

+ 19 - 0
src/views/Home.vue

@@ -116,6 +116,7 @@ export default {
   methods: {
     initData() {
       this.menus = this.getMenu();
+      this.privileges = this.getPrivileges();
 
       if (this.$route.name === "Home") {
         // console.log(this.getMenuFirstRouter());
@@ -176,6 +177,24 @@ export default {
       // console.log(JSON.stringify(menus));
       return menus;
     },
+    getPrivileges() {
+      let privileges = [];
+      const listTree = (dataList) => {
+        dataList.forEach((item) => {
+          privileges.push({
+            id: item.id,
+            name: item.name,
+            parentId: item.parentId,
+            url: item.url,
+          });
+          if (item.children && item.children.length) {
+            listTree(item.children);
+          }
+        });
+      };
+      listTree(this.menus);
+      return privileges;
+    },
     updateBreadcrumbs() {
       this.curRouteName = this.$route.name;
       let breadcrumbs = [];