소스 검색

数据权限接口对接

liujiejie 1 년 전
부모
커밋
c27a8e1376

+ 17 - 2
src/api/system.js

@@ -1,7 +1,7 @@
 /*
  * @Author: your name
  * @Date: 2024-05-20 09:36:55
- * @LastEditTime: 2024-05-22 09:13:09
+ * @LastEditTime: 2024-06-11 10:01:44
  * @LastEditors: bogon
  * @Description: In User Settings Edit
  * @FilePath: /performance-test/src/api/system.js
@@ -141,7 +141,6 @@ export function getDetailRoleAuth(data) {
   });
 }
 //更新角色菜单权限
-
 export function updateRolePermission(data) {
   return request({
     url: "/energy-manage-service/sysrole/updateRolePermission",
@@ -149,6 +148,22 @@ export function updateRolePermission(data) {
     data,
   });
 }
+//角色获取组织架构权限
+export function getRoleOrganization(data) {
+  return request({
+    url: "/energy-manage-service/sysrole/getRoleOrganization",
+    method: "post",
+    data,
+  });
+}
+//更新角色数据权限
+export function updateRoleOrganization(data) {
+  return request({
+    url: "/energy-manage-service/sysrole/updateRoleOrganization",
+    method: "post",
+    data,
+  });
+}
 
 //获取菜单列表
 export function getAllMenu(data) {

BIN
src/assets/upload.png


+ 64 - 19
src/components/Tinymce.vue

@@ -14,7 +14,6 @@ import { quillEditor } from "vue-quill-editor";
 import "quill/dist/quill.core.css";
 import "quill/dist/quill.snow.css";
 import "quill/dist/quill.bubble.css";
-import Quill from "quill";
 
 export default {
   components: {
@@ -37,12 +36,13 @@ export default {
                 { indent: "-1" },
                 { indent: "+1" },
               ],
-              ["link", "image", "video"],
+              ["link", "image", "video", "custom-file"], // 添加自定义文件图标
               ["clean"],
             ],
             handlers: {
-              image: this.imageHandler,
+              // image: this.imageHandler,
               video: this.videoHandler,
+              "custom-file": this.fileHandler, // 自定义文件处理函数
             },
           },
         },
@@ -51,7 +51,7 @@ export default {
   },
   methods: {
     onEditorReady(editor) {
-      // Any additional setup for the editor can be done here
+      console.log(editor, "editor");
     },
     imageHandler() {
       const input = document.createElement("input");
@@ -64,16 +64,18 @@ export default {
         if (file) {
           const formData = new FormData();
           formData.append("file", file);
-
-          try {
-            const response = await this.uploadImage(formData);
-            const url = response.data.url; // 根据你的实际响应数据结构
-            const quill = this.$refs.quillEditor.quill;
-            const range = quill.getSelection();
-            quill.insertEmbed(range.index, "image", url);
-          } catch (error) {
-            console.error("Image upload failed", error);
-          }
+          const quill = this.$refs.quillEditor.quill;
+          const range = quill.getSelection();
+          quill.insertEmbed(range.index, "image", formData);
+          // try {
+          //   const response = await this.uploadImage(formData);
+          //   const url = response.data.url; // 根据你的实际响应数据结构
+          //   const quill = this.$refs.quillEditor.quill;
+          //   const range = quill.getSelection();
+          //   quill.insertEmbed(range.index, "image", url);
+          // } catch (error) {
+          //   console.error("Image upload failed", error);
+          // }
         }
       };
     },
@@ -91,7 +93,7 @@ export default {
 
           try {
             const response = await this.uploadVideo(formData);
-            const url = response.data.url; // 根据你的实际响应数据结构
+            const url = response.data.url;
             const quill = this.$refs.quillEditor.quill;
             const range = quill.getSelection();
             quill.insertEmbed(range.index, "video", url);
@@ -101,9 +103,39 @@ export default {
         }
       };
     },
+    fileHandler() {
+      const input = document.createElement("input");
+      input.setAttribute("type", "file");
+      input.setAttribute("accept", ".doc,.docx,.pdf");
+      input.click();
+
+      input.onchange = async () => {
+        const file = input.files[0];
+        if (file) {
+          const formData = new FormData();
+          formData.append("file", file);
+          const quill = this.$refs.quillEditor.quill;
+          const range = quill.getSelection();
+          quill.insertText(
+            range.index,
+            `File uploaded: ${file.name} (URL: ${formData})`
+          );
+          // try {
+          //   const response = await this.uploadFile(formData);
+          //   const url = response.data.url;
+          //   const quill = this.$refs.quillEditor.quill;
+          //   const range = quill.getSelection();
+          //   quill.insertText(
+          //     range.index,
+          //     `File uploaded: ${file.name} (URL: ${url})`
+          //   );
+          // } catch (error) {
+          //   console.error("File upload failed", error);
+          // }
+        }
+      };
+    },
     async uploadImage(formData) {
-      // 在这里实现你的图片上传逻辑
-      // 示例:使用 axios 进行上传
       const response = await axios.post("/api/upload/image", formData, {
         headers: {
           "Content-Type": "multipart/form-data",
@@ -112,8 +144,6 @@ export default {
       return response;
     },
     async uploadVideo(formData) {
-      // 在这里实现你的视频上传逻辑
-      // 示例:使用 axios 进行上传
       const response = await axios.post("/api/upload/video", formData, {
         headers: {
           "Content-Type": "multipart/form-data",
@@ -121,10 +151,25 @@ export default {
       });
       return response;
     },
+    async uploadFile(formData) {
+      const response = await axios.post("/api/upload/file", formData, {
+        headers: {
+          "Content-Type": "multipart/form-data",
+        },
+      });
+      return response;
+    },
   },
 };
 </script>
 
 <style scoped>
 /* 添加你需要的样式 */
+::v-deep .ql-snow.ql-toolbar .ql-custom-file {
+  background: url("../assets/upload.png");
+  background-size: 16px 16px;
+  background-position: center center;
+  background-repeat: no-repeat;
+  /*background: red;*/
+}
 </style>

+ 46 - 2
src/utils/getMenu.js

@@ -1,11 +1,12 @@
 /*
  * @Author: your name
  * @Date: 2024-05-21 14:21:20
- * @LastEditTime: 2024-05-21 17:36:17
+ * @LastEditTime: 2024-06-11 14:20:54
  * @LastEditors: bogon
  * @Description: In User Settings Edit
  * @FilePath: /performance-test/src/utils/getMenu.js
  */
+//角色菜单权限筛选
 export const checkListFn = (data) => {
   let list = [];
   recursiveFind(data);
@@ -24,7 +25,8 @@ export const checkListFn = (data) => {
 };
 
 // data 是一个树形数组结构数据,checkIdList是一个一维数组
-// 需求:递归循环data,data.permissionId在checkIdList这个数组中,父级节点和祖先节点的permissionId也需要push到新的一维数组,这个方法如何改?
+// 需求:递归循环data,data.permissionId在checkIdList这个数组中,父级节点和祖先节点的permissionId也需要push到新的一维数组。
+//角色菜单权限筛选
 export const getcheckListFn = (checkIdList, data) => {
   let list = [];
   console.log(checkIdList, "checkIdList");
@@ -52,3 +54,45 @@ export const getcheckListFn = (checkIdList, data) => {
 
   return list;
 };
+//角色数据权限筛选
+export const checkDataAuthTreeFn = (data) => {
+  let list = [];
+  recursiveFind(data);
+  function recursiveFind(data) {
+    data.forEach((item) => {
+      if (item.checked === 1) {
+        list.push(item.codeNumber);
+      }
+      if (item.children && item.children.length > 0) {
+        recursiveFind(item.children); // 递归遍历子节点
+      }
+    });
+  }
+  return list;
+};
+//角色数据权限筛选
+export const getCheckDataAuthTreeFn = (checkIdList, data) => {
+  let list = [];
+  function recursiveFind(node, ancestors = []) {
+    if (checkIdList.includes(node.codeNumber)) {
+      // 将当前节点的 codeNumber 加入到列表中
+      list.push({ codeNumber: node.codeNumber, codeType: node.type });
+      // 将当前节点的祖先节点的 codeNumber 加入到列表中
+      ancestors.forEach((ancestor) => {
+        list.push({ codeNumber: ancestor.codeNumber, codeType: node.type });
+      });
+    }
+    // 递归遍历子节点
+    if (node.children && node.children.length > 0) {
+      node.children.forEach((child) => {
+        recursiveFind(child, [...ancestors, node]);
+      });
+    }
+  }
+  // 从根节点开始递归遍历
+  data.forEach((root) => {
+    recursiveFind(root);
+  });
+
+  return list;
+};

+ 17 - 8
src/views/performance/assetssDetail.vue

@@ -1,7 +1,7 @@
 <!--
  * @Author: your name
  * @Date: 2024-05-27 09:25:45
- * @LastEditTime: 2024-06-11 09:14:15
+ * @LastEditTime: 2024-06-12 09:23:05
  * @LastEditors: bogon
  * @Description: In User Settings Edit
  * @FilePath: /performance-test/src/views/performance/assetssDetail.vue
@@ -10,9 +10,9 @@
   <div class="global-variable">
     <h2 style="text-align: center">分析历史记录总览</h2>
     <el-form
-      :model="ruleForm"
+      :model="formInfo"
       :rules="rules"
-      ref="ruleForm"
+      ref="formInfo"
       label-width="100px"
       class="demo-ruleForm"
     >
@@ -37,7 +37,6 @@
         </el-select>
       </el-form-item>
     </el-form>
-
     <el-button type="primary" @click="() => $router.go(-1)">返回</el-button>
     <h4>分析时间:2020-04-20 10:10:10{{}}</h4>
     <el-card class="box-card analysisType">
@@ -58,37 +57,47 @@
   </div>
 </template>
 <script>
-import { analysisDetail } from "@/api/performance";
+import { analysisDetail, analysisEditQuery } from "@/api/performance";
 export default {
   data() {
     return {
       analysisTypeList: [],
       windEngineGroupList: [],
       detailInfo: {},
+      formInfo: {
+        fieldEngineCode: null,
+        analysisTypeCode: null,
+      },
+      rules: {},
     };
   },
   created() {
     //获取分析 分析类型、机组编号 列表
     this.getWindCodeList();
     //获取详情信息
-    this.getDetailInfo();
+    // this.getDetailInfo();
   },
   methods: {
     async getDetailInfo() {
       try {
         const response = await analysisDetail({
           batchCode: this.$route.query.batchCode,
+          analysisTypeCode: this.formInfo.analysisTypeCode,
+          fieldEngineCode: this.formInfo.fieldEngineCode,
         });
         this.detailInfo = response.data;
       } catch (error) {
         console.error(error);
       }
     },
-    async getWindCodeList(batchCode) {
+    async getWindCodeList() {
       try {
-        const response = await analysisEditQuery({ batchCode });
+        const response = await analysisEditQuery({
+          batchCode: this.$route.query.batchCode,
+        });
         this.analysisTypeList = response.data.analysisTypeList;
         this.windEngineGroupList = response.data.windEngineGroupList;
+        this.getDetailInfo();
       } catch (error) {
         console.error(error);
       }

+ 86 - 0
src/views/system/roleMag/components/dataAuth.vue

@@ -0,0 +1,86 @@
+<!--
+ * @Author: your name
+ * @Date: 2024-06-11 09:36:36
+ * @LastEditTime: 2024-06-11 14:18:11
+ * @LastEditors: bogon
+ * @Description: In User Settings Edit
+ * @FilePath: /dashengmag/performance-test/src/views/system/roleMag/components/dataAuth.vue
+-->
+<template>
+  <div>
+    <el-tree
+      :data="menuList"
+      show-checkbox
+      default-expand-all
+      node-key="codeNumber"
+      ref="tree"
+      highlight-current
+      :props="defaultProps"
+    >
+    </el-tree>
+  </div>
+</template>
+
+<script>
+import { getRoleOrganization } from "@/api/system.js";
+import {
+  checkDataAuthTreeFn,
+  getCheckDataAuthTreeFn,
+} from "@/utils/getMenu.js";
+
+export default {
+  props: {
+    treeObj: {
+      type: Object,
+      required: true,
+    },
+  },
+  data() {
+    return {
+      menuList: [],
+      defaultProps: {
+        children: "children",
+        label: "codeName",
+      },
+    };
+  },
+  watch: {
+    treeObj: {
+      handler() {
+        this.getMenuList();
+      },
+      deep: true,
+      immediate: true,
+    },
+  },
+  created() {
+    // this.getMenuList();
+  },
+  methods: {
+    getMenuList() {
+      getRoleOrganization({ roleId: this.treeObj.roleId }).then((res) => {
+        this.menuList = res.data;
+        this.updateTreeCheckState(this.menuList);
+      });
+    },
+    getCheckTreeKey() {
+      const result = getCheckDataAuthTreeFn(
+        this.$refs.tree.getCheckedKeys(),
+        this.menuList
+      );
+      return {
+        organizationCodes: result,
+        roleIdAuth: this.treeObj.roleId,
+      };
+    },
+    updateTreeCheckState(checkList) {
+      console.log("回显数据权限内容");
+      if (this.$refs.tree) {
+        this.$refs.tree.setCheckedKeys(checkDataAuthTreeFn(checkList));
+      }
+    },
+  },
+};
+</script>
+
+<style scoped lang="scss"></style>

+ 53 - 23
src/views/system/roleMag/index.vue

@@ -244,11 +244,13 @@
             ></el-input>
           </el-form-item>
         </el-form>
-        <el-tabs type="border-card" class="tabs">
-          <el-tab-pane label="功能权限"
+        <el-tabs v-model="activeName" type="border-card" class="tabs">
+          <el-tab-pane label="功能权限" name="1"
             ><MenuTree ref="menuTreeRef" :treeObj="treeObj"></MenuTree
           ></el-tab-pane>
-          <el-tab-pane label="数据权限">数据权限</el-tab-pane>
+          <el-tab-pane label="数据权限" name="2"
+            ><DataAuthTree ref="dataAuthRef" :treeObj="treeObj"></DataAuthTree
+          ></el-tab-pane>
         </el-tabs>
         <span slot="footer" class="dialog-footer">
           <el-button
@@ -276,6 +278,7 @@
 
 <script>
 import MenuTree from "./components/menuTree.vue";
+import DataAuthTree from "./components/dataAuth.vue";
 import {
   getRoleTableList,
   updateRoleAvailable,
@@ -284,12 +287,14 @@ import {
   editRole,
   deleteRoleInfo,
   updateRolePermission,
+  updateRoleOrganization,
   getDetailRoleAuth,
 } from "@/api/system.js";
 import { dictType } from "@/api/dict.js";
 export default {
   components: {
     MenuTree,
+    DataAuthTree,
   },
   data() {
     return {
@@ -297,6 +302,7 @@ export default {
         roleId: null,
         checkList: [],
       },
+      activeName: "1",
       loadingView: false,
       //角色类型
       stateOPtions: [],
@@ -358,26 +364,50 @@ export default {
     editAuthMenu(formName) {
       this.$refs[formName].validate((valid) => {
         if (valid) {
-          const { permissionIds, roleId } =
-            this.$refs.menuTreeRef.getCheckTreeKey();
-          if (!permissionIds) {
-            this.$message({
-              message: "至少要选择一个菜单",
-              type: "warning",
-            });
+          if (this.activeName === "1") {
+            const { permissionIds, roleId } =
+              this.$refs.menuTreeRef.getCheckTreeKey();
+            if (!permissionIds) {
+              this.$message({
+                message: "至少要选择一个菜单权限",
+                type: "warning",
+              });
+            } else {
+              this.loadingView = true;
+              updateRolePermission({ permissionIds, roleId })
+                .then((res) => {
+                  this.$message({
+                    message: "菜单权限修改成功",
+                    type: "success",
+                  });
+                  this.getTableList();
+                  this.loadingView = false;
+                  this.unusualdialog = false;
+                })
+                .catch(() => {});
+            }
           } else {
-            this.loadingView = true;
-            updateRolePermission({ permissionIds, roleId })
-              .then((res) => {
-                this.$message({
-                  message: "权限修改成功",
-                  type: "success",
-                });
-                this.getTableList();
-                this.loadingView = false;
-                this.unusualdialog = false;
-              })
-              .catch(() => {});
+            const { organizationCodes, roleIdAuth } =
+              this.$refs.dataAuthRef.getCheckTreeKey();
+            if (organizationCodes.length === 0) {
+              this.$message({
+                message: "至少要选择一个数据权限",
+                type: "warning",
+              });
+            } else {
+              this.loadingView = true;
+              updateRoleOrganization({ organizationCodes, roleId: roleIdAuth })
+                .then((res) => {
+                  this.$message({
+                    message: "数据权限修改成功",
+                    type: "success",
+                  });
+                  this.getTableList();
+                  this.loadingView = false;
+                  this.unusualdialog = false;
+                })
+                .catch(() => {});
+            }
           }
         } else {
           return false;
@@ -420,7 +450,6 @@ export default {
         });
       }
     },
-
     rowStyle() {
       return "text-align:center";
     },
@@ -531,6 +560,7 @@ export default {
     },
     //权限修改按钮
     editAuth(row) {
+      this.activeName = "1";
       this.editRoleAuth.roleCode = row.roleCode;
       this.editRoleAuth.roleName = row.roleDescription;
       getDetailRoleAuth({ roleId: row.id })

+ 2 - 2
vue.config.js

@@ -66,8 +66,8 @@ module.exports = {
       "/api": {
         // target: "http://192.168.5.4:16200", // 石月
         // target: "http://192.168.50.235:16200", //内网
-        // target: "http://192.168.5.15:16200",
-        target: "http://106.120.102.238:16600", //外网
+        target: "http://192.168.5.15:16200",
+        // target: "http://106.120.102.238:16600", //外网
         changeOrigin: true,
         pathRewrite: {
           "^/api": "", // 需要rewrite重写的,