From a09a342f58c282a89df6b5bc274cf8f37f8bf6f3 Mon Sep 17 00:00:00 2001
From: fungleo <web@fengcms.com>
Date: 星期二, 21 七月 2020 10:22:07 +0800
Subject: [PATCH] 优化 uitls/ruoyi.js 中 selectDictLabel 方法,数组迭代器换为 some 提高性能

---
 ruoyi-ui/src/views/system/role/index.vue |  142 +++++++++++++++++++++++++++++++++++------------
 1 files changed, 106 insertions(+), 36 deletions(-)

diff --git a/ruoyi-ui/src/views/system/role/index.vue b/ruoyi-ui/src/views/system/role/index.vue
index 7f0feb9..1739f0a 100644
--- a/ruoyi-ui/src/views/system/role/index.vue
+++ b/ruoyi-ui/src/views/system/role/index.vue
@@ -1,7 +1,7 @@
 <template>
   <div class="app-container">
-    <el-form :inline="true">
-      <el-form-item label="瑙掕壊鍚嶇О">
+    <el-form :model="queryParams" ref="queryForm" :inline="true">
+      <el-form-item label="瑙掕壊鍚嶇О" prop="roleName">
         <el-input
           v-model="queryParams.roleName"
           placeholder="璇疯緭鍏ヨ鑹插悕绉�"
@@ -11,7 +11,7 @@
           @keyup.enter.native="handleQuery"
         />
       </el-form-item>
-      <el-form-item label="鏉冮檺瀛楃">
+      <el-form-item label="鏉冮檺瀛楃" prop="roleKey">
         <el-input
           v-model="queryParams.roleKey"
           placeholder="璇疯緭鍏ユ潈闄愬瓧绗�"
@@ -21,7 +21,7 @@
           @keyup.enter.native="handleQuery"
         />
       </el-form-item>
-      <el-form-item label="鐘舵��">
+      <el-form-item label="鐘舵��" prop="status">
         <el-select
           v-model="queryParams.status"
           placeholder="瑙掕壊鐘舵��"
@@ -51,6 +51,12 @@
       </el-form-item>
       <el-form-item>
         <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">鎼滅储</el-button>
+        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">閲嶇疆</el-button>
+      </el-form-item>
+    </el-form>
+
+    <el-row :gutter="10" class="mb8">
+      <el-col :span="1.5">
         <el-button
           type="primary"
           icon="el-icon-plus"
@@ -58,15 +64,45 @@
           @click="handleAdd"
           v-hasPermi="['system:role:add']"
         >鏂板</el-button>
-      </el-form-item>
-    </el-form>
+      </el-col>
+      <el-col :span="1.5">
+        <el-button
+          type="success"
+          icon="el-icon-edit"
+          size="mini"
+          :disabled="single"
+          @click="handleUpdate"
+          v-hasPermi="['system:role:edit']"
+        >淇敼</el-button>
+      </el-col>
+      <el-col :span="1.5">
+        <el-button
+          type="danger"
+          icon="el-icon-delete"
+          size="mini"
+          :disabled="multiple"
+          @click="handleDelete"
+          v-hasPermi="['system:role:remove']"
+        >鍒犻櫎</el-button>
+      </el-col>
+      <el-col :span="1.5">
+        <el-button
+          type="warning"
+          icon="el-icon-download"
+          size="mini"
+          @click="handleExport"
+          v-hasPermi="['system:post:export']"
+        >瀵煎嚭</el-button>
+      </el-col>
+    </el-row>
 
-    <el-table v-loading="loading" :data="roleList">
+    <el-table v-loading="loading" :data="roleList" @selection-change="handleSelectionChange">
+      <el-table-column type="selection" width="55" align="center" />
       <el-table-column label="瑙掕壊缂栧彿" prop="roleId" width="120" />
       <el-table-column label="瑙掕壊鍚嶇О" prop="roleName" :show-overflow-tooltip="true" width="150" />
-      <el-table-column label="鏉冮檺瀛楃" prop="roleKey" :show-overflow-tooltip="true" width="180" />
-      <el-table-column label="鏄剧ず椤哄簭" prop="roleSort" width="120" />
-      <el-table-column label="鐘舵��" align="center" width="120">
+      <el-table-column label="鏉冮檺瀛楃" prop="roleKey" :show-overflow-tooltip="true" width="150" />
+      <el-table-column label="鏄剧ず椤哄簭" prop="roleSort" width="100" />
+      <el-table-column label="鐘舵��" align="center" width="100">
         <template slot-scope="scope">
           <el-switch
             v-model="scope.row.status"
@@ -117,7 +153,7 @@
     />
 
     <!-- 娣诲姞鎴栦慨鏀硅鑹查厤缃璇濇 -->
-    <el-dialog :title="title" :visible.sync="open" width="500px">
+    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
       <el-form ref="form" :model="form" :rules="rules" label-width="80px">
         <el-form-item label="瑙掕壊鍚嶇О" prop="roleName">
           <el-input v-model="form.roleName" placeholder="璇疯緭鍏ヨ鑹插悕绉�" />
@@ -158,7 +194,7 @@
     </el-dialog>
 
     <!-- 鍒嗛厤瑙掕壊鏁版嵁鏉冮檺瀵硅瘽妗� -->
-    <el-dialog :title="title" :visible.sync="openDataScope" width="500px">
+    <el-dialog :title="title" :visible.sync="openDataScope" width="500px" append-to-body>
       <el-form :model="form" label-width="80px">
         <el-form-item label="瑙掕壊鍚嶇О">
           <el-input v-model="form.roleName" :disabled="true" />
@@ -197,15 +233,22 @@
 </template>
 
 <script>
-import { listRole, getRole, delRole, addRole, updateRole, dataScope, changeRoleStatus } from "@/api/system/role";
+import { listRole, getRole, delRole, addRole, updateRole, exportRole, dataScope, changeRoleStatus } from "@/api/system/role";
 import { treeselect as menuTreeselect, roleMenuTreeselect } from "@/api/system/menu";
 import { treeselect as deptTreeselect, roleDeptTreeselect } from "@/api/system/dept";
 
 export default {
+  name: "Role",
   data() {
     return {
       // 閬僵灞�
       loading: true,
+      // 閫変腑鏁扮粍
+      ids: [],
+      // 闈炲崟涓鐢�
+      single: true,
+      // 闈炲涓鐢�
+      multiple: true,
       // 鎬绘潯鏁�
       total: 0,
       // 瑙掕壊琛ㄦ牸鏁版嵁
@@ -325,16 +368,16 @@
     },
     /** 鏍规嵁瑙掕壊ID鏌ヨ鑿滃崟鏍戠粨鏋� */
     getRoleMenuTreeselect(roleId) {
-      roleMenuTreeselect(roleId).then(response => {
-        this.getMenuTreeselect();
-        this.$refs.menu.setCheckedKeys(response.data);
+      return roleMenuTreeselect(roleId).then(response => {
+        this.menuOptions = response.menus;
+        return response;
       });
     },
     /** 鏍规嵁瑙掕壊ID鏌ヨ閮ㄩ棬鏍戠粨鏋� */
     getRoleDeptTreeselect(roleId) {
-      roleDeptTreeselect(roleId).then(response => {
-        this.getDeptTreeselect();
-        this.$refs.dept.setCheckedKeys(response.data);
+      return roleDeptTreeselect(roleId).then(response => {
+        this.deptOptions = response.depts;
+        return response;
       });
     },
     // 瑙掕壊鐘舵�佷慨鏀�
@@ -364,8 +407,8 @@
     },
     // 琛ㄥ崟閲嶇疆
     reset() {
-      if (this.$refs.tree != undefined) {
-        this.$refs.tree.setCheckedKeys([]);
+      if (this.$refs.menu != undefined) {
+        this.$refs.menu.setCheckedKeys([]);
       }
       this.form = {
         roleId: undefined,
@@ -384,6 +427,18 @@
       this.queryParams.pageNum = 1;
       this.getList();
     },
+    /** 閲嶇疆鎸夐挳鎿嶄綔 */
+    resetQuery() {
+      this.dateRange = [];
+      this.resetForm("queryForm");
+      this.handleQuery();
+    },
+    // 澶氶�夋閫変腑鏁版嵁
+    handleSelectionChange(selection) {
+      this.ids = selection.map(item => item.roleId)
+      this.single = selection.length!=1
+      this.multiple = !selection.length
+    },
     /** 鏂板鎸夐挳鎿嶄綔 */
     handleAdd() {
       this.reset();
@@ -394,24 +449,31 @@
     /** 淇敼鎸夐挳鎿嶄綔 */
     handleUpdate(row) {
       this.reset();
-      this.$nextTick(() => {
-        this.getRoleMenuTreeselect(row.roleId);
-      });
-      getRole(row.roleId).then(response => {
+      const roleId = row.roleId || this.ids
+      const roleMenu = this.getRoleMenuTreeselect(roleId);
+      getRole(roleId).then(response => {
         this.form = response.data;
         this.open = true;
+        this.$nextTick(() => {
+          roleMenu.then(res => {
+            this.$refs.menu.setCheckedKeys(res.checkedKeys);
+          });
+        });
         this.title = "淇敼瑙掕壊";
       });
     },
     /** 鍒嗛厤鏁版嵁鏉冮檺鎿嶄綔 */
     handleDataScope(row) {
       this.reset();
-      this.$nextTick(() => {
-        this.getRoleDeptTreeselect(row.roleId);
-      });
+      const roleDeptTreeselect = this.getRoleDeptTreeselect(row.roleId);
       getRole(row.roleId).then(response => {
         this.form = response.data;
         this.openDataScope = true;
+        this.$nextTick(() => {
+          roleDeptTreeselect.then(res => {
+            this.$refs.dept.setCheckedKeys(res.checkedKeys);
+          });
+        });
         this.title = "鍒嗛厤鏁版嵁鏉冮檺";
       });
     },
@@ -426,8 +488,6 @@
                 this.msgSuccess("淇敼鎴愬姛");
                 this.open = false;
                 this.getList();
-              } else {
-                this.msgError(response.msg);
               }
             });
           } else {
@@ -437,8 +497,6 @@
                 this.msgSuccess("鏂板鎴愬姛");
                 this.open = false;
                 this.getList();
-              } else {
-                this.msgError(response.msg);
               }
             });
           }
@@ -454,24 +512,36 @@
             this.msgSuccess("淇敼鎴愬姛");
             this.openDataScope = false;
             this.getList();
-          } else {
-            this.msgError(response.msg);
           }
         });
       }
     },
     /** 鍒犻櫎鎸夐挳鎿嶄綔 */
     handleDelete(row) {
-      this.$confirm('鏄惁纭鍒犻櫎鍚嶇О涓�"' + row.roleName + '"鐨勬暟鎹」?', "璀﹀憡", {
+      const roleIds = row.roleId || this.ids;
+      this.$confirm('鏄惁纭鍒犻櫎瑙掕壊缂栧彿涓�"' + roleIds + '"鐨勬暟鎹」?', "璀﹀憡", {
           confirmButtonText: "纭畾",
           cancelButtonText: "鍙栨秷",
           type: "warning"
         }).then(function() {
-          return delRole(row.roleId);
+          return delRole(roleIds);
         }).then(() => {
           this.getList();
           this.msgSuccess("鍒犻櫎鎴愬姛");
         }).catch(function() {});
+    },
+    /** 瀵煎嚭鎸夐挳鎿嶄綔 */
+    handleExport() {
+      const queryParams = this.queryParams;
+      this.$confirm('鏄惁纭瀵煎嚭鎵�鏈夎鑹叉暟鎹」?', "璀﹀憡", {
+          confirmButtonText: "纭畾",
+          cancelButtonText: "鍙栨秷",
+          type: "warning"
+        }).then(function() {
+          return exportRole(queryParams);
+        }).then(response => {
+          this.download(response.msg);
+        }).catch(function() {});
     }
   }
 };

--
Gitblit v1.9.3