| ¶Ô±ÈÐÂÎļþ | 
|  |  |  | 
|---|
|  |  |  | <template> | 
|---|
|  |  |  | <TableLayout class="menu-layout" :permissions="['system:menu:query']"> | 
|---|
|  |  |  | <!-- è¡¨æ ¼åå页 --> | 
|---|
|  |  |  | <template v-slot:table-wrap> | 
|---|
|  |  |  | <ul class="toolbar" v-permissions="['system:menu:create', 'system:menu:delete', 'system:menu:sort']"> | 
|---|
|  |  |  | <li><el-button type="primary" @click="$refs.operaMenuWindow.open('æ°å»ºä¸çº§èå')" icon="el-icon-plus" v-permissions="['system:menu:create']">æ°å»º</el-button></li> | 
|---|
|  |  |  | <li><el-button @click="deleteByIdInBatch" icon="el-icon-delete" v-permissions="['system:menu:delete']">å é¤</el-button></li> | 
|---|
|  |  |  | <li><el-button @click="sort('top')" :loading="isWorking.sort" icon="el-icon-sort-up" v-permissions="['system:menu:sort']">ä¸ç§»</el-button></li> | 
|---|
|  |  |  | <li><el-button @click="sort('bottom')" :loading="isWorking.sort" icon="el-icon-sort-down" v-permissions="['system:menu:sort']">ä¸ç§»</el-button></li> | 
|---|
|  |  |  | </ul> | 
|---|
|  |  |  | <el-table | 
|---|
|  |  |  | :height="tableHeightNew" | 
|---|
|  |  |  | ref="table" | 
|---|
|  |  |  | v-loading="isWorking.search" | 
|---|
|  |  |  | :data="tableData.list" | 
|---|
|  |  |  | row-key="id" | 
|---|
|  |  |  | stripe | 
|---|
|  |  |  | default-expand-all | 
|---|
|  |  |  | @selection-change="handleSelectionChange" | 
|---|
|  |  |  | > | 
|---|
|  |  |  | <el-table-column type="selection" width="55" fixed="left"></el-table-column> | 
|---|
|  |  |  | <el-table-column prop="name" label="èååç§°" fixed="left" min-width="160px"></el-table-column> | 
|---|
|  |  |  | <el-table-column prop="icon" label="徿 " min-width="80px" class-name="table-column-icon"> | 
|---|
|  |  |  | <template slot-scope="{row}"> | 
|---|
|  |  |  | <i v-if="row.icon != null && row.icon !== ''" :class="{[row.icon]: true}"></i> | 
|---|
|  |  |  | <template v-else>æªè®¾ç½®</template> | 
|---|
|  |  |  | </template> | 
|---|
|  |  |  | </el-table-column> | 
|---|
|  |  |  | <el-table-column prop="path" label="访é®è·¯å¾" min-width="140px"></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 prop="disabled" label="æ¯å¦å¯ç¨" min-width="80px"> | 
|---|
|  |  |  | <template slot-scope="{row}"> | 
|---|
|  |  |  | <el-switch v-model="row.disabled" :active-value="false" :inactive-value="true" @change="switchDisabled(row)"/> | 
|---|
|  |  |  | </template> | 
|---|
|  |  |  | </el-table-column> | 
|---|
|  |  |  | <el-table-column | 
|---|
|  |  |  | v-if="containPermissions(['system:menu:update', 'system:menu:create', 'system:menu:delete'])" | 
|---|
|  |  |  | label="æä½" | 
|---|
|  |  |  | min-width="220" | 
|---|
|  |  |  | fixed="right" | 
|---|
|  |  |  | > | 
|---|
|  |  |  | <template slot-scope="{row}"> | 
|---|
|  |  |  | <el-button type="text" icon="el-icon-edit" @click="$refs.operaMenuWindow.open('ç¼è¾èå', row)" v-permissions="['system:menu:update']">ç¼è¾</el-button> | 
|---|
|  |  |  | <el-button type="text" icon="el-icon-plus" @click="$refs.operaMenuWindow.open('æ°å»ºåèå', null, row)" v-permissions="['system:menu:create']">æ°å»ºåèå</el-button> | 
|---|
|  |  |  | <el-button v-if="!row.fixed" type="text" icon="el-icon-delete" @click="deleteById(row)" v-permissions="['system:menu:delete']">å é¤</el-button> | 
|---|
|  |  |  | </template> | 
|---|
|  |  |  | </el-table-column> | 
|---|
|  |  |  | </el-table> | 
|---|
|  |  |  | </template> | 
|---|
|  |  |  | <!-- æ°å»º/修湠--> | 
|---|
|  |  |  | <OperaMenuWindow ref="operaMenuWindow" @success="handlePageChange(tableData.pagination.pageIndex)"/> | 
|---|
|  |  |  | </TableLayout> | 
|---|
|  |  |  | </template> | 
|---|
|  |  |  |  | 
|---|
|  |  |  | <script> | 
|---|
|  |  |  | import TableLayout from '@/layouts/TableLayout' | 
|---|
|  |  |  | import BaseTable from '@/components/base/BaseTable' | 
|---|
|  |  |  | import OperaMenuWindow from '@/components/system/menu/OperaMenuWindow' | 
|---|
|  |  |  | import { fetchTree, updateStatus, sort } from '@/api/system/menu' | 
|---|
|  |  |  | export default { | 
|---|
|  |  |  | name: 'SystemMenu', | 
|---|
|  |  |  | extends: BaseTable, | 
|---|
|  |  |  | components: { OperaMenuWindow, TableLayout }, | 
|---|
|  |  |  | data () { | 
|---|
|  |  |  | return { | 
|---|
|  |  |  | // æ¯å¦æ£å¨å¤çä¸ | 
|---|
|  |  |  | isWorking: { | 
|---|
|  |  |  | sort: false | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }, | 
|---|
|  |  |  | methods: { | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * è¦ç页ç åæ´å¤ç | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | handlePageChange () { | 
|---|
|  |  |  | this.isWorking.search = true | 
|---|
|  |  |  | fetchTree() | 
|---|
|  |  |  | .then(records => { | 
|---|
|  |  |  | this.tableData.list = records | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | .catch(e => { | 
|---|
|  |  |  | this.$tip.apiFailed(e) | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | .finally(() => { | 
|---|
|  |  |  | this.isWorking.search = false | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | }, | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * æåº | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param direction æ¹åï¼åå¼[top:ä¸ç§», bottom:ä¸ç§»] | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | sort (direction) { | 
|---|
|  |  |  | if (this.isWorking.sort) { | 
|---|
|  |  |  | return | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (this.tableData.selectedRows.length === 0) { | 
|---|
|  |  |  | this.$tip.warning('è¯·éæ©ä¸æ¡æ°æ®') | 
|---|
|  |  |  | return | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (this.tableData.selectedRows.length > 1) { | 
|---|
|  |  |  | this.$tip.warning('æåºæ¶ä»
å
è®¸éæ©ä¸æ¡æ°æ®') | 
|---|
|  |  |  | return | 
|---|
|  |  |  | } | 
|---|
|  |  |  | const menuId = this.tableData.selectedRows[0].id | 
|---|
|  |  |  | // æ¾å°èåèå´ | 
|---|
|  |  |  | let menuPool | 
|---|
|  |  |  | for (const rootMenu of this.tableData.list) { | 
|---|
|  |  |  | const parent = this.__findParent(menuId, rootMenu) | 
|---|
|  |  |  | if (parent != null) { | 
|---|
|  |  |  | menuPool = parent.children | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | menuPool = menuPool || this.tableData.list | 
|---|
|  |  |  | const menuIndex = menuPool.findIndex(menu => menu.id === menuId) | 
|---|
|  |  |  | // ä¸ç§»æ ¡éª | 
|---|
|  |  |  | if (direction === 'top' && menuIndex === 0) { | 
|---|
|  |  |  | this.$tip.warning('èåå·²å°é¡¶é¨') | 
|---|
|  |  |  | return | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // ä¸ç§»æ ¡éª | 
|---|
|  |  |  | if (direction === 'bottom' && menuIndex === menuPool.length - 1) { | 
|---|
|  |  |  | this.$tip.warning('èåå·²å°åºé¨') | 
|---|
|  |  |  | return | 
|---|
|  |  |  | } | 
|---|
|  |  |  | this.isWorking.sort = true | 
|---|
|  |  |  | sort({ | 
|---|
|  |  |  | id: this.tableData.selectedRows[0].id, | 
|---|
|  |  |  | direction | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | .then(() => { | 
|---|
|  |  |  | if (direction === 'top') { | 
|---|
|  |  |  | menuPool.splice(menuIndex, 0, menuPool.splice(menuIndex - 1, 1)[0]) | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | menuPool.splice(menuIndex, 0, menuPool.splice(menuIndex + 1, 1)[0]) | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | .catch(e => { | 
|---|
|  |  |  | this.$tip.apiFailed(e) | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | .finally(() => { | 
|---|
|  |  |  | this.isWorking.sort = false | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | }, | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * å¯ç¨/ç¦ç¨ | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param row è¡å¯¹è±¡ | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | switchDisabled (row) { | 
|---|
|  |  |  | const newValue = row.disabled | 
|---|
|  |  |  | row.disabled = !row.disabled | 
|---|
|  |  |  | // å¼å¯ | 
|---|
|  |  |  | if (!newValue) { | 
|---|
|  |  |  | this.__updateMenuStatus(row, newValue) | 
|---|
|  |  |  | return | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // ç¦ç¨ | 
|---|
|  |  |  | this.$dialog.disableConfirm(`确认ç¦ç¨ ${row.name} èååï¼`) | 
|---|
|  |  |  | .then(() => { | 
|---|
|  |  |  | this.__updateMenuStatus(row, newValue) | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | .catch(() => { | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | }, | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * æ¥è¯¢ç¶èç¹ | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param id èç¹ID | 
|---|
|  |  |  | * @param parent å¨åªä¸ªç¶èç¹ä¸è¿è¡æ¥æ¾ | 
|---|
|  |  |  | * @returns {null|{children}|*|*|undefined|null} | 
|---|
|  |  |  | * @private | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | __findParent (id, parent) { | 
|---|
|  |  |  | if (parent.children == null || parent.children.length === 0) { | 
|---|
|  |  |  | return | 
|---|
|  |  |  | } | 
|---|
|  |  |  | for (const row of parent.children) { | 
|---|
|  |  |  | if (row.id === id) { | 
|---|
|  |  |  | return parent | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (row.children.length > 0) { | 
|---|
|  |  |  | const target = this.__findParent(id, row) | 
|---|
|  |  |  | if (target != null) { | 
|---|
|  |  |  | return target | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return null | 
|---|
|  |  |  | }, | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * ä¿®æ¹èåç¶æ | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param row è¡å¯¹è±¡ | 
|---|
|  |  |  | * @param newValue æ°å¼ | 
|---|
|  |  |  | * @private | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | __updateMenuStatus (row, newValue) { | 
|---|
|  |  |  | updateStatus({ | 
|---|
|  |  |  | id: row.id, | 
|---|
|  |  |  | parentId: row.parentId, | 
|---|
|  |  |  | disabled: newValue | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | .then(() => { | 
|---|
|  |  |  | row.disabled = newValue | 
|---|
|  |  |  | this.$tip.apiSuccess('ä¿®æ¹æå') | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | .catch(e => { | 
|---|
|  |  |  | this.$tip.apiFailed(e) | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }, | 
|---|
|  |  |  | created () { | 
|---|
|  |  |  | this.config({ | 
|---|
|  |  |  | module: 'èå', | 
|---|
|  |  |  | api: '/system/menu' | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | this.search() | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | </script> | 
|---|
|  |  |  |  | 
|---|
|  |  |  | <style lang="scss" scoped> | 
|---|
|  |  |  | @import "@/assets/style/variables.scss"; | 
|---|
|  |  |  | .menu-layout { | 
|---|
|  |  |  | /deep/ .table-content { | 
|---|
|  |  |  | margin-top: 0; | 
|---|
|  |  |  | .table-wrap { | 
|---|
|  |  |  | padding-bottom: 16px; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // å¾æ å | 
|---|
|  |  |  | .table-column-icon { | 
|---|
|  |  |  | // element-ui徿  | 
|---|
|  |  |  | i { | 
|---|
|  |  |  | background-color: $primary-color; | 
|---|
|  |  |  | opacity: 0.72; | 
|---|
|  |  |  | font-size: 20px; | 
|---|
|  |  |  | color: #fff; | 
|---|
|  |  |  | padding: 4px; | 
|---|
|  |  |  | border-radius: 50%; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // èªå®ä¹å¾æ  | 
|---|
|  |  |  | [class^="eva-icon-"] { | 
|---|
|  |  |  | width: 20px; | 
|---|
|  |  |  | height: 20px; | 
|---|
|  |  |  | background-size: 16px; | 
|---|
|  |  |  | vertical-align: middle; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | </style> | 
|---|