123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 |
- <template>
- <div class="subPage">
- <div class="system-table-search">
- <div class="flex-h">
- <div class="flex-item flex-h">
- <el-button size="mini" type="success" @click='addRole'>新增角色</el-button>
- </div>
- <tableSearch value='角色名称' @exportSearchKey="searchList"></tableSearch>
- </div>
- <div class="moreFilter"></div>
- </div>
- <div class="system-table-box">
- <el-table :data="roles.list" stripe style="width: 100%">
- <el-table-column prop="RoleName" label="角色名">
- </el-table-column>
- <el-table-column label="创建时间" width="300">
- <template slot-scope="scope">
- <label>{{FormatDate(scope.row.CreateDate)}}</label>
- </template>
- </el-table-column>
- <el-table-column fixed='right' label="操作" width="300">
- <template slot-scope="scope">
- <el-button size="mini" type="warning" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
- <el-button size="mini" type="danger" @click="handleDelete(scope.$index, scope.row)">删除</el-button>
- <el-button size="mini" type="success" @click="handlePermission(scope.$index, scope.row)">分配权限</el-button>
- </template>
- </el-table-column>
- </el-table>
- </div>
- <el-pagination
- @size-change="handleSizeChange"
- @current-change="handleCurrentChange"
- :current-page.sync="currentPage"
- :page-size="10"
- layout="prev, pager, next, jumper"
- :total="roles.pagenum">
- </el-pagination>
- <el-dialog title="请选择菜单" :visible.sync="dialogTableVisible">
- <el-tree
- v-if="dialogTableVisible"
- class="flxe-h"
- :data="menus"
- :default-expand-all="true"
- :expand-on-click-node="false"
- :default-checked-keys="defaultChecked"
- ref="tree"
- show-checkbox
- @node-click="handleNodeClick"></el-tree>
- <div class="flex-h" style="justify-content: flex-end;margin-top: 1rem">
- <el-button type='success' @click="getCheckedNodes">确定</el-button>
- </div>
- </el-dialog>
- </div>
- </template>
-
- <script>
- import { createNamespacedHelpers, mapState } from 'vuex'
- import tableSearch from '@/components/tableSearch/index'
-
- const { mapState: mapRoleState, mapActions: mapRoleActions } = createNamespacedHelpers('role')
-
- export default {
- name: '',
- data () {
- return {
- currentPage: 0, // 当前页码
- key: '',
- selid: '',
- dialogTableVisible: false,
- }
- },
- computed: {
- ...mapRoleState({
- roles: x => x.roleList,
- selmenus: x => x.roleMenus,
- }),
- ...mapState({
- menus: x => x.app.menus
- }),
- defaultChecked: {
- get () {
- console.log(this.selmenus)
- // const sels = (this.selmenus || []).map(x => x.MenuId)
- return []
- },
- },
- },
- components: {
- tableSearch
- },
- methods: {
- ...mapRoleActions([
- 'GetRolesList',
- 'DelRole',
- 'SaveRoleMenus',
- 'GetRoleMenu',
- ]),
- FormatDate (date) {
- console.log()
- return this.toolClass.dateFormat(date)
- },
- handleSizeChange (val) {
- console.log(`每页 ${val} 条`)
- },
- handleCurrentChange (val) {
- console.log(`当前页: ${val}`)
- },
- handleEdit (index, row) {
- // 编辑
- this.$router.push({ name: 'editRole', query: { id: row.RoleId } })
- },
- handleDelete (index, row) {
- // 删除
- console.log(index, row)
- this.$confirm('确认删除此角色?', '提示', {
- confirmButtonText: '确定',
- cancelButtonText: '取消',
- type: 'warning'
- })
- .then(() => {
- this.DelRole({id: row.RoleId, callback: this.delCallBack})
- })
- .catch(() => {
- this.$message({
- type: 'info',
- message: '已取消删除'
- })
- })
- },
- delCallBack () {
- this.$message({
- type: 'success',
- message: '删除成功!'
- })
- this.GetRolesList({name: this.key})
- },
- handlePermission (index, row) {
- this.selid = row.RoleId
- this.GetRoleMenu(this.selid)
- this.dialogTableVisible = true
- console.log(index)
- },
- handleNodeClick (node) {
- console.log(node)
- },
- searchList (key) {
- this.key = key
- this.GetRolesList({name: this.key})
- },
- addRole () {
- this.$router.push({ name: 'editRole' })
- },
- getCheckedNodes () { // 获取选中的节点
- const menuids = this.$refs.tree.getCheckedNodes().map(x => x.id).join(',')
- this.SaveRoleMenus({
- id: this.selid,
- menuids: menuids,
- callback: this.hideDialog,
- })
- },
- hideDialog () {
- this.$message({
- type: 'success',
- message: '操作成功!'
- })
- this.dialogTableVisible = false
- },
- },
- beforeMount () {
- this.GetRolesList()
- },
- }
- </script>
-
- <!-- Add "scoped" attribute to limit CSS to this component only -->
- <style lang="scss" scoped>
- </style>
|