123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291 |
- <template>
- <a-card size="small" :bordered="false">
- <a-spin :spinning="spinning" tip="Loading...">
- <div class="table-page-search-wrapper">
- <a-form layout="inline">
- <a-row :gutter="48">
- <a-col :md="6" :sm="24">
- <a-form-item label="角色名称">
- <a-input
- allowClear
- v-model.trim="queryParam.name"
- placeholder="请输入角色名称"
- :maxLength="30"
- id="roleList-name"
- @pressEnter="$refs.table.refresh(true)" />
- </a-form-item>
- </a-col>
- <a-col :md="6" :sm="24">
- <a-form-item label="状态">
- <v-select code="ENABLE_FLAG" v-model="queryParam.isEnable" allowClear placeholder="请选择状态" id="roleList-isEnable"></v-select>
- </a-form-item>
- </a-col>
- <a-col :md="6" :sm="24">
- <a-button type="primary" @click="$refs.table.refresh(true)" id="roleList-handSubmit" style="margin-right: 10px;">查询</a-button>
- <a-button type="" @click="reset" id="roleList-reset">重置</a-button>
- </a-col>
- </a-row>
- </a-form>
- </div>
- <div class="table-operator">
- <!-- <a-button v-if="$hasPermissions('B_powerMD_role_add')" type="primary" class="button-error" @click="openModal" id="roleList-openModal">新增</a-button> -->
- <a-button type="primary" v-if="$hasPermissions('B_power_role_add')" class="button-error" @click="openModal" id="roleList-openModal">新增</a-button>
- </div>
- <s-table
- ref="table"
- size="default"
- rowKey="id"
- :columns="columns"
- :data="loadData"
- style="word-break: break-all;"
- bordered>
- <!-- 启用禁用 -->
- <span slot="status" slot-scope="text, record">
- <!-- <a-switch
- v-if="$hasPermissions('B_powerMD_role_enable')"
- checkedChildren="启用"
- unCheckedChildren="禁用"
- id="roleList-isEnable"
- v-model="record.isEnable"
- @change="changeFlagHandle(text, record)" />
- <span v-else>{{ record.isEnable==1?'已启用':'已禁用' }}</span> -->
- <a-switch
- checkedChildren="启用"
- unCheckedChildren="禁用"
- id="roleList-isEnable"
- v-model="record.isEnable"
- v-if="$hasPermissions('B_power_role_enable')"
- @change="changeFlagHandle(text, record)" />
- <span v-else>--</span>
- </span>
- <!-- 角色描述 -->
- <template slot="remarks" slot-scope="text, record">
- <span class="text-overflows" :title="record.remarks">{{ record.remarks ?record.remarks : '--' }}</span>
- </template>
- <!-- 操作 -->
- <span slot="action" slot-scope="text, record">
- <!-- <a-icon v-if="$hasPermissions('M_powerMD_role_menu')" type="setting" title="菜单权限" :style="{ fontSize: '20px', color: '#e29e14', padding: '0 10px' }" @click="openMenuModal(record)" />
- <a-icon v-if="$hasPermissions('B_powerMD_role_edit')" type="edit" title="编辑" :style="{fontSize: '20px',color:' #1890FF',padding:' 0 10px'}" @click="handleEdit(record)" />
- <a-icon
- type="delete"
- title="删除"
- :style="{fontSize: '20px',color: '#f00',padding: '0 10px'}"
- v-if="!record.isEnable && $hasPermissions('B_powerMD_role_del')"
- @click="delect(record)" /> -->
- <a-icon type="setting" title="菜单权限" v-if="$hasPermissions('M_power_role_menu')" :style="{ fontSize: '20px', color: '#e29e14', padding: '0 10px' }" @click="openMenuModal(record)" />
- <a-icon type="edit" title="编辑" v-if="$hasPermissions('B_power_role_edit')" :style="{fontSize: '20px',color:' #1890FF',padding:' 0 10px'}" @click="handleEdit(record)" />
- <a-icon
- type="delete"
- title="删除"
- :style="{fontSize: '20px',color: '#f00',padding: '0 10px'}"
- v-if="!record.isEnable && $hasPermissions('B_power_role_del')"
- @click="delect(record)" />
- <span v-if="!$hasPermissions('M_power_role_menu') && !$hasPermissions('B_power_role_edit') && (record.isEnable && !$hasPermissions('B_power_role_del'))">--</span>
- </span>
- </s-table>
- </a-spin>
- <roleModal :visible="showModal" :data="itemData" @refresh="refreshTable" @close="showModal = false"></roleModal>
- <menuModal :visible="showMenuModal" :data="menuData" @close="showMenuModal = false"></menuModal>
- </a-card>
- </template>
- <script>
- import {
- STable,
- VSelect
- } from '@/components'
- import roleModal from './roleModal.vue'
- import menuModal from './menuModal.vue'
- import {
- getPowerRoleList,
- updateEnableStatus,
- delectRolePower,
- getMenuList
- } from '@/api/power-role.js'
- export default {
- name: 'RoleList',
- components: {
- STable,
- VSelect,
- roleModal,
- menuModal
- },
- data () {
- return {
- spinning: false,
- // 查询参数
- queryParam: {
- name: '',
- isEnable: ''
- },
- showModal: false,
- showMenuModal: false,
- itemData: {}, // 编辑行数据
- menuData: {},
- // 表头
- columns: [{
- title: '序号',
- dataIndex: 'no',
- width: 60,
- align: 'center'
- },
- {
- title: '创建时间',
- dataIndex: 'createDate',
- width: 150,
- align: 'center'
- },
- {
- title: '角色名称',
- dataIndex: 'name',
- width: 150,
- align: 'center'
- },
- {
- title: '角色描述',
- dataIndex: 'remarks',
- width: 200,
- align: 'center',
- scopedSlots: {
- customRender: 'remarks'
- }
- },
- {
- title: '状态',
- width: 150,
- align: 'center',
- scopedSlots: {
- customRender: 'status'
- }
- },
- {
- title: '操作',
- width: 150,
- align: 'center',
- scopedSlots: {
- customRender: 'action'
- }
- }
- ],
- // 加载数据方法 必须为 Promise 对象
- loadData: parameter => {
- console.log(parameter, 'parameter')
- return getPowerRoleList(Object.assign(parameter, this.queryParam)).then(res => {
- const no = (res.data.pageNo - 1) * res.data.pageSize
- for (let i = 0; i < res.data.list.length; i++) {
- const _item = res.data.list[i]
- _item.no = no + i + 1
- _item.isEnable = _item.isEnable + '' === '1'
- }
- return res.data
- })
- },
- optionAlertShow: false
- }
- },
- beforeRouteEnter (to, from, next) {
- next(vm => {
- // vm.$refs.table.refresh()
- })
- },
- methods: {
- // 刷新列表
- refreshTable () {
- this.$refs.table.refresh(true)
- },
- // 重置
- reset () {
- this.queryParam.name = ''
- this.queryParam.isEnable = ''
- this.refreshTable()
- },
- // 新增
- openModal () {
- this.showModal = true
- this.itemData = {}
- },
- // 打开分配权限弹窗
- openMenuModal (row) {
- this.getMenuList(row.id)
- },
- // 获取菜单树列表
- getMenuList (id) {
- const _this = this
- getMenuList({
- id: id
- }).then(res => {
- if (res.status == 200) {
- _this.menuData = res.data
- this.showMenuModal = true
- console.log(res.data, 'this.itemData')
- }
- })
- },
- // 删除
- delect (row) {
- const _this = this
- this.$confirm({
- title: '警告',
- content: '删除后无法恢复,确认删除?',
- centered: true,
- onOk () {
- _this.spinning = true
- delectRolePower({
- id: row.id
- }).then(res => {
- if (res.status == 200) {
- _this.$message.success(res.message)
- _this.$refs.table.refresh()
- _this.spinning = false
- } else {
- _this.spinning = false
- }
- })
- }
- })
- },
- handleEdit (row) {
- this.showModal = true
- this.itemData = row
- },
- // 修改状态
- changeFlagHandle (text, record) {
- const _data = {
- id: record.id,
- flag: record.isEnable ? '1' : '0'
- }
- this.spinning = true
- updateEnableStatus(_data).then(res => {
- if (res.status == 200) {
- this.$message.success(res.message)
- this.$refs.table.refresh()
- this.spinning = false
- } else {
- this.$refs.table.refresh()
- this.spinning = false
- }
- })
- }
- }
- }
- </script>
- <style scoped>
- .action-button {
- line-height: 40px;
- white-space: nowrap;
- padding: 5px 10px;
- background-color: #1890ff;
- border-radius: 4px;
- color: #fff;
- margin-right: 5px;
- }
- .red-text {
- background-color: red;
- }
- .menu-text {
- background-color: #f90;
- }
- </style>
|