From 064d703f2907b931085c5f565269289e9fa81012 Mon Sep 17 00:00:00 2001
From: doum <doum>
Date: 星期五, 17 十月 2025 15:53:55 +0800
Subject: [PATCH] 最新版本541200007

---
 admin/src/views/system/permission.vue |  229 ++++++++++++++++++++++++++++++++++++++++-----------------
 1 files changed, 161 insertions(+), 68 deletions(-)

diff --git a/admin/src/views/system/permission.vue b/admin/src/views/system/permission.vue
index d4e56f4..ec2fe7d 100644
--- a/admin/src/views/system/permission.vue
+++ b/admin/src/views/system/permission.vue
@@ -1,97 +1,190 @@
 <template>
   <TableLayout :permissions="['system:permission:query']">
-    <!-- 鎼滅储琛ㄥ崟 -->
-    <el-form ref="searchForm" slot="search-form" :model="searchForm" label-width="100px" inline>
-      <el-form-item label="鏉冮檺缂栫爜" prop="code">
-        <el-input v-model="searchForm.code" v-trim placeholder="璇疯緭鍏ユ潈闄愮紪鐮�" @keypress.enter.native="search"/>
-      </el-form-item>
-      <el-form-item label="鏉冮檺鍚嶇О" prop="name">
-        <el-input v-model="searchForm.name" v-trim placeholder="璇疯緭鍏ユ潈闄愬悕绉�" @keypress.enter.native="search"/>
-      </el-form-item>
-      <section>
-        <el-button type="primary" @click="search">鎼滅储</el-button>
-        <el-button @click="reset">閲嶇疆</el-button>
-      </section>
-    </el-form>
     <!-- 琛ㄦ牸鍜屽垎椤� -->
     <template v-slot:table-wrap>
-      <ul class="toolbar" v-permissions="['system:permission:create', 'system:permission:delete']">
-        <li><el-button type="primary" @click="$refs.operaPermissionWindow.open('鏂板缓绯荤粺鏉冮檺')" icon="el-icon-plus" v-permissions="['system:permission:create']">鏂板缓</el-button></li>
-        <li><el-button @click="deleteByIdInBatch" icon="el-icon-delete" v-permissions="['system:permission:delete']">鍒犻櫎</el-button></li>
-      </ul>
-      <el-table
-          :height="tableHeightNew"
-        v-loading="isWorking.search"
-        :data="tableData.list"
-        :default-sort = "{prop: 'createTime', order: 'descending'}"
-        stripe
-        @selection-change="handleSelectionChange"
-        @sort-change="handleSortChange"
-      >
-        <el-table-column type="selection" fixed="left" width="55"></el-table-column>
-        <el-table-column prop="code" label="鏉冮檺缂栫爜" fixed="left" min-width="240px"></el-table-column>
-        <el-table-column prop="name" label="鏉冮檺鍚嶇О" fixed="left" min-width="200px"></el-table-column>
-        <el-table-column prop="remark" label="鏉冮檺澶囨敞" min-width="200px"></el-table-column>
-        <el-table-column prop="createUser" label="鍒涘缓浜�" min-width="100px">
-          <template slot-scope="{row}">{{row.createUserInfo == null ? '' : row.createUserInfo.username}}</template>
-        </el-table-column>
-        <el-table-column prop="createTime" label="鍒涘缓鏃堕棿" min-width="140px" sortable="custom" sort-by="perm.CREATE_TIME"></el-table-column>
-        <el-table-column prop="updateUser" label="鏇存柊浜�" min-width="100px">
-          <template slot-scope="{row}">{{row.updateUserInfo == null ? '' : row.updateUserInfo.username}}</template>
-        </el-table-column>
-        <el-table-column prop="updateTime" label="鏇存柊鏃堕棿" min-width="140px"></el-table-column>
-        <el-table-column
-          v-if="containPermissions(['system:permission:update', 'system:permission:delete'])"
-          label="鎿嶄綔"
-          min-width="130"
-          fixed="right"
-        >
-          <template slot-scope="{row}">
-            <el-button v-if="!row.fixed" type="text" @click="$refs.operaPermissionWindow.open('缂栬緫绯荤粺鏉冮檺', row)" icon="el-icon-edit" v-permissions="['system:permission:update']">缂栬緫</el-button>
-            <el-button v-if="!row.fixed" type="text" @click="deleteById(row)" icon="el-icon-delete" v-permissions="['system:permission:delete']">鍒犻櫎</el-button>
-          </template>
-        </el-table-column>
-      </el-table>
-      <pagination
-        @size-change="handleSizeChange"
-        @current-change="handlePageChange"
-        :pagination="tableData.pagination"
-      ></pagination>
+      <el-tabs v-model="currentTab" v-loading="isWorking.search">
+        <el-tab-pane :name="'module'+module.id" :label="module.name" v-for="module in tableData.list" :key="module.id">
+          <ul class="toolbar" v-permissions="['system:permission:create', 'system:permission:delete']">
+            <li><el-button type="primary" @click="$refs.operaPermissionWindow.open('鏂板缓绯荤粺鏉冮檺', module)" icon="el-icon-plus" v-permissions="['system:permission:create']">鏂板缓</el-button></li>
+            <li><el-button @click="deleteByIdInBatch" icon="el-icon-delete" v-permissions="['system:permission:delete']">鍒犻櫎</el-button></li>
+          </ul>
+          <el-table
+              :height="tableHeightNew"
+            :data="module.children"
+            :ref="'module' + module.id"
+            row-key="id"
+            stripe
+            default-expand-all
+            @selection-change="handleSelectionChange"
+          >
+            <el-table-column type="selection" fixed="left" width="55"></el-table-column>
+            <el-table-column prop="name" label="鏉冮檺鍚嶇О" fixed="left" min-width="200px"></el-table-column>
+            <el-table-column prop="code" label="鏉冮檺缂栫爜" min-width="200px"></el-table-column>
+            <el-table-column prop="remark" label="鏉冮檺澶囨敞" min-width="120px"></el-table-column>
+            <el-table-column prop="createUser" label="鍒涘缓浜�" min-width="100px">
+              <template slot-scope="{row}">{{row.createUserInfo == null ? '' : row.createUserInfo.username}}</template>
+            </el-table-column>
+            <el-table-column prop="createTime" label="鍒涘缓鏃堕棿" min-width="140px"></el-table-column>
+            <el-table-column prop="updateUser" label="鏇存柊浜�" min-width="100px">
+              <template slot-scope="{row}">{{row.updateUserInfo == null ? '' : row.updateUserInfo.username}}</template>
+            </el-table-column>
+            <el-table-column prop="updateTime" label="鏇存柊鏃堕棿" min-width="140px"></el-table-column>
+            <el-table-column
+              v-if="containPermissions(['system:permission:update', 'system:permission:delete'])"
+              label="鎿嶄綔"
+              min-width="150"
+              fixed="right"
+            >
+              <template slot-scope="{row}">
+                <!-- 妯″潡缂栬緫&鍒犻櫎 -->
+                <template v-if="row.type === 'module'">
+                  <el-button type="text" @click="$refs.operaModuleWindow.open('缂栬緫妯″潡', row)" icon="el-icon-edit" v-permissions="['system:permission:update']">缂栬緫</el-button>
+                  <el-button type="text" @click="$refs.operaPermissionWindow.open('鏂板缓绯荤粺鏉冮檺', row)" icon="el-icon-edit" v-permissions="['system:permission:update']">娣诲姞鏉冮檺</el-button>
+                  <el-button v-if="!row.fixed" type="text" @click="deletePermission(row)" icon="el-icon-delete" v-permissions="['system:permission:delete']">鍒犻櫎</el-button>
+                </template>
+                <!-- 鏉冮檺缂栬緫&鍒犻櫎 -->
+                <template v-else>
+                  <el-button v-if="!row.fixed" type="text" @click="$refs.operaPermissionWindow.open('缂栬緫绯荤粺鏉冮檺', row)" icon="el-icon-edit" v-permissions="['system:permission:update']">缂栬緫</el-button>
+                  <el-button v-if="!row.fixed" type="text" @click="deletePermission(row)" icon="el-icon-delete" v-permissions="['system:permission:delete']">鍒犻櫎</el-button>
+                </template>
+              </template>
+            </el-table-column>
+          </el-table>
+        </el-tab-pane>
+      </el-tabs>
     </template>
     <!-- 鏂板缓/淇敼 -->
-    <OperaPermissionWindow ref="operaPermissionWindow" @success="handlePageChange"/>
+    <OperaPermissionWindow ref="operaPermissionWindow" @success="search"/>
+    <!-- 缂栬緫鏉冮檺妯″潡 -->
+    <OperaModuleWindow ref="operaModuleWindow" @success="handlePageChange"/>
   </TableLayout>
 </template>
 
 <script>
-import Pagination from '@/components/common/Pagination'
 import TableLayout from '@/layouts/TableLayout'
 import BaseTable from '@/components/base/BaseTable'
 import OperaPermissionWindow from '@/components/system/permission/OperaPermissionWindow'
+import OperaModuleWindow from '@/components/system/permission/OperaModuleWindow'
+
 export default {
   name: 'SystemPermission',
   extends: BaseTable,
-  components: { OperaPermissionWindow, TableLayout, Pagination },
+  components: { OperaModuleWindow, OperaPermissionWindow, TableLayout },
   data () {
     return {
-      // 鎼滅储
-      searchForm: {
-        code: '',
-        name: '',
-        remark: ''
+      // 褰撳墠閫変腑鐨勬ā鍧�
+      currentTab: null
+    }
+  },
+  methods: {
+    /**
+     * 瑕嗙洊椤电爜鍙樻洿澶勭悊
+     */
+    handlePageChange () {
+      this.isWorking.search = true
+      this.api.fetchTree()
+        .then(data => {
+          this.tableData.list = data
+          this.currentTab = 'module' + this.tableData.list[0].id
+        })
+        .catch(e => {
+          this.$tip.apiFailed(e)
+        })
+        .finally(() => {
+          this.isWorking.search = false
+        })
+    },
+    /**
+     * 瑕嗙洊鍒犻櫎澶勭悊
+     */
+    deletePermission (row, childConfirm = true) {
+      this.__checkApi()
+      let message = `纭鍒犻櫎${this.module}銆�${row[this.configData['field.main']]}銆戝悧?`
+      if (childConfirm && row.children != null && row.children.length > 0) {
+        message = `纭鍒犻櫎${this.module}銆�${row[this.configData['field.main']]}銆戝強鍏跺瓙${this.module}鍚�?`
       }
+      this.$dialog.deleteConfirm(message)
+        .then(() => {
+          this.isWorking.delete = true
+          this.api.deletePermission({
+            id: row.type === 'module' ? null : row.id, // 妯″潡涓嶄紶ID
+            modulePrefix: row.type === 'module' ? row.modulePath : null // 鏉冮檺涓嶄紶妯″潡
+          })
+            .then(() => {
+              this.$tip.apiSuccess('鍒犻櫎鎴愬姛')
+              this.__afterDelete()
+            })
+            .catch(e => {
+              this.$tip.apiFailed(e)
+            })
+            .finally(() => {
+              this.isWorking.delete = false
+            })
+        })
+        .catch(() => {})
+    },
+    /**
+     * 瑕嗙洊鎵归噺鍒犻櫎澶勭悊
+     */
+    deleteByIdInBatch (childConfirm = true) {
+      this.__checkApi()
+      if (this.tableData.selectedRows.length === 0) {
+        this.$tip.warning('璇疯嚦灏戦�夋嫨涓�鏉℃暟鎹�')
+        return
+      }
+      let message = `纭鍒犻櫎宸查�変腑鐨� ${this.tableData.selectedRows.length} 鏉�${this.module}璁板綍鍚�?`
+      if (childConfirm) {
+        const containChildrenRows = []
+        for (const row of this.tableData.selectedRows) {
+          if (row.children != null && row.children.length > 0) {
+            containChildrenRows.push(row[this.configData['field.main']])
+          }
+        }
+        if (containChildrenRows.length > 0) {
+          message = `鏈灏嗗垹闄�${this.module}銆�${containChildrenRows.join('銆�')}銆戝強鍏跺瓙${this.module}璁板綍锛岀‘璁ゅ垹闄ゅ悧锛焋
+        }
+      }
+      this.$dialog.deleteConfirm(message)
+        .then(() => {
+          this.isWorking.delete = true
+          this.api.deletePermissionInBatch(this.tableData.selectedRows.map(row => {
+            return {
+              id: row.type === 'module' ? null : row.id, // 妯″潡涓嶄紶ID
+              modulePrefix: row.type === 'module' ? row.modulePath : null // 鏉冮檺涓嶄紶妯″潡
+            }
+          }))
+            .then(() => {
+              this.$tip.apiSuccess('鍒犻櫎鎴愬姛')
+              this.__afterDelete(this.tableData.selectedRows.length)
+            })
+            .catch(e => {
+              this.$tip.apiFailed(e)
+            })
+            .finally(() => {
+              this.isWorking.delete = false
+            })
+        })
+        .catch(() => {})
     }
   },
   created () {
     this.config({
       module: '鏉冮檺',
-      api: '/system/permission',
-      sorts: [{
-        property: 'perm.CREATE_TIME',
-        direction: 'DESC'
-      }]
+      api: '/system/permission'
     })
     this.search()
   }
 }
 </script>
+
+<style scoped lang="scss">
+/deep/ .table-content {
+  margin-top: 0;
+  .table-wrap {
+    padding-bottom: 16px;
+  }
+}
+/deep/ .el-tabs__nav-prev, /deep/ .el-tabs__nav-next {
+  line-height: 40px;
+}
+</style>

--
Gitblit v1.9.3