dataease-dm/frontend/src/views/system/role/index.vue

273 lines
8.1 KiB
Vue
Raw Normal View History

2021-03-03 15:06:52 +08:00
<template>
<layout-content v-loading="$store.getters.loadingMap[$store.getters.currentPath]">
<!-- <div v-loading="result.loading" style="height: 100%"> -->
<el-container style="width: 100%; height: 100%;">
<el-aside width="70%">
<complex-table
highlight-current-row
:data="tableData"
:columns="columns"
:search-config="searchConfig"
:pagination-config="paginationConfig"
@search="search"
@row-click="rowClick"
>
<template #toolbar>
2021-05-06 10:40:08 +08:00
<el-button v-permission="['role:add']" icon="el-icon-circle-plus-outline" @click="create">{{ $t('role.add') }}</el-button>
2021-03-03 15:06:52 +08:00
</template>
2021-05-14 18:51:35 +08:00
<el-table-column prop="name" :label="$t('commons.name')" />
<el-table-column :show-overflow-tooltip="true" prop="createTime" :label="$t('commons.create_time')">
<template v-slot:default="scope">
<span>{{ scope.row.createTime | timestampFormatDate }}</span>
</template>
</el-table-column>
2021-05-14 18:51:35 +08:00
<fu-table-operations :buttons="buttons" :label="$t('commons.operating')" fix />
</complex-table>
2021-03-03 15:06:52 +08:00
</el-aside>
<el-main style="padding: 8px 20px;">
2021-03-03 15:06:52 +08:00
<el-tabs v-model="activeName" @tab-click="handleClick">
2021-05-14 18:51:35 +08:00
<el-tab-pane :label="$t('role.menu_authorization')" name="first">
2021-03-03 15:06:52 +08:00
<el-tree
ref="menu"
lazy
:data="menus"
:default-checked-keys="menuIds"
:load="getMenuDatas"
:props="defaultProps"
check-strictly
show-checkbox
node-key="id"
@check="menuChange"
/>
</el-tab-pane>
2021-05-14 18:51:35 +08:00
<el-tab-pane :label="$t('role.data_authorization')" name="second">玩命开发中...</el-tab-pane>
2021-03-03 15:06:52 +08:00
</el-tabs>
</el-main>
</el-container>
<el-dialog
:close-on-click-modal="false"
:title="formType=='add' ? $t('role.add') : $t('role.modify')"
:visible.sync="dialogVisible"
width="580px"
:destroy-on-close="true"
@closed="closeFunc"
>
<el-form ref="roleForm" inline :model="form" :rules="rule" size="small" label-width="80px">
<el-form-item label="角色名称" prop="name">
<el-input v-model="form.name" style="width: 380px;" />
</el-form-item>
<!-- <el-form-item label="角色代码" prop="code">
2021-03-05 17:20:45 +08:00
<el-input v-model="form.code" style="width: 380px;" />
</el-form-item> -->
2021-03-05 17:20:45 +08:00
2021-03-03 15:06:52 +08:00
<el-form-item label="描述信息" prop="description">
<el-input v-model="form.description" style="width: 380px;" rows="5" type="textarea" />
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="text" @click="dialogVisible = false">{{ $t('commons.cancel') }}</el-button>
2021-05-14 18:51:35 +08:00
<el-button type="primary" @click="saveRole('roleForm')">{{ $t('commons.confirm') }}</el-button>
</div>
2021-03-03 15:06:52 +08:00
</el-dialog>
</layout-content>
2021-03-03 15:06:52 +08:00
</template>
<script>
import LayoutContent from '@/components/business/LayoutContent'
import ComplexTable from '@/components/business/complex-table'
2021-05-19 17:25:07 +08:00
import { formatCondition, formatQuickCondition } from '@/utils/index'
2021-03-05 17:20:45 +08:00
import { addRole, editRole, delRole, roleGrid, addRoleMenus, menuIds } from '@/api/system/role'
2021-03-03 15:06:52 +08:00
import { getMenusTree, getChild } from '@/api/system/menu'
export default {
name: 'Role',
components: {
LayoutContent,
ComplexTable
2021-03-03 15:06:52 +08:00
},
data() {
return {
2021-03-03 15:06:52 +08:00
tableData: [],
menus: [],
menuIds: [],
defaultProps: { children: 'children', label: 'label', isLeaf: 'isLeaf' },
activeName: 'first',
dialogVisible: false,
formType: 'add',
form: {},
rule: {
name: [
2021-05-17 15:36:11 +08:00
{ required: true, message: this.$t('role.pls_input_name'), trigger: 'blur' }
2021-04-28 12:16:52 +08:00
],
code: [{ required: true, message: '请输入代码', trigger: 'blur' }]
2021-03-03 15:06:52 +08:00
},
2021-03-05 16:07:44 +08:00
currentRow: null,
permission: {
add: ['role:add'],
edit: ['role:edit'],
del: ['role:del']
},
header: '',
columns: [],
buttons: [
{
label: this.$t('commons.edit'), icon: 'el-icon-edit', type: 'primary', click: this.edit
}, {
label: this.$t('commons.delete'), icon: 'el-icon-delete', type: 'danger', click: this.handleDelete
}
],
searchConfig: {
2021-05-19 17:25:07 +08:00
useQuickSearch: true,
2021-05-17 15:36:11 +08:00
quickPlaceholder: this.$t('role.search_by_name'),
components: [
2021-05-17 15:36:11 +08:00
{ field: 'name', label: this.$t('role.role_name'), component: 'FuComplexInput' }
]
},
paginationConfig: {
currentPage: 1,
pageSize: 10,
total: 0
2021-03-05 16:07:44 +08:00
}
2021-03-03 15:06:52 +08:00
}
},
watch: {
currentRow: 'currentRowChange'
},
mounted() {
2021-03-03 15:06:52 +08:00
this.search()
},
methods: {
handleClick(tab, event) {
console.log(tab, event)
},
create() {
2021-05-19 10:30:51 +08:00
this.$router.push({ name: 'system-role-form' })
2021-03-03 15:06:52 +08:00
},
2021-03-11 22:58:05 +08:00
search(condition) {
2021-05-19 17:25:07 +08:00
condition = formatQuickCondition(condition, 'name')
2021-03-11 22:58:05 +08:00
const temp = formatCondition(condition)
const param = temp || {}
roleGrid(this.paginationConfig.currentPage, this.paginationConfig.pageSize, param).then(response => {
2021-03-03 18:20:59 +08:00
const data = response.data
2021-03-03 15:06:52 +08:00
this.total = data.itemCount
this.tableData = data.listObject
})
},
edit(row) {
2021-05-19 10:30:51 +08:00
this.$router.push({ name: 'system-role-form', params: row })
2021-03-03 15:06:52 +08:00
},
saveRole(roleForm) {
this.$refs[roleForm].validate(valid => {
if (valid) {
const method = this.formType === 'add' ? addRole : editRole
method(this.form).then(res => {
this.$success(this.$t('commons.save_success'))
this.search()
this.dialogVisible = false
})
} else {
return false
}
})
},
closeFunc() {
this.dialogVisible = false
},
getMenuDatas(node, resolve) {
const pid = node.data.id ? node.data.id : '0'
getMenusTree(pid).then(res => {
2021-03-03 18:20:59 +08:00
const datas = res.data
2021-03-03 15:06:52 +08:00
const nodes = datas.map(data => this.formatNode(data))
resolve && resolve(nodes)
})
},
formatNode(node) {
const result = {
id: node.menuId,
label: node.title,
isLeaf: !node.hasChildren,
children: node.children
}
return result
},
menuChange(menu) {
getChild(menu.id).then(res => {
2021-03-03 18:20:59 +08:00
const childIds = res.data
2021-03-03 15:06:52 +08:00
if (this.menuIds.indexOf(menu.id) !== -1) {
for (let i = 0; i < childIds.length; i++) {
const index = this.menuIds.indexOf(childIds[i])
if (index !== -1) {
this.menuIds.splice(index, 1)
}
}
} else {
for (let i = 0; i < childIds.length; i++) {
const index = this.menuIds.indexOf(childIds[i])
if (index === -1) {
this.menuIds.push(childIds[i])
}
}
}
this.$refs.menu.setCheckedKeys(this.menuIds)
this.saveMenus()
})
},
saveMenus() {
if (!this.currentRow) {
return
}
const param = { roleId: this.currentRow.roleId, menuIds: this.menuIds }
addRoleMenus(param).then(res => {
this.search()
})
},
rowClick(row, column, event) {
2021-03-05 17:20:45 +08:00
menuIds(row.roleId).then(res => {
const menuIds = res.data
row.menuIds = menuIds
this.currentRow = row
})
2021-03-03 15:06:52 +08:00
},
currentRowChange(newVal, oldVal) {
if (newVal === oldVal) {
return
}
if (!newVal) {
this.menuIds = []
return
}
this.menuIds = newVal.menuIds
this.$refs.menu.setCheckedKeys(this.menuIds)
},
handleDelete(row) {
this.$confirm(this.$t('role.confirm_delete') + ': ' + row.name + '', this.$t('role.tips'), {
2021-05-17 15:36:11 +08:00
confirmButtonText: this.$t('commons.confirm'),
2021-05-19 10:30:51 +08:00
cancelButtonText: this.$t('commons.cancel'),
2021-03-03 15:06:52 +08:00
type: 'warning'
}).then(() => {
delRole(row.roleId).then(res => {
this.$success(this.$t('commons.delete_success'))
2021-03-03 15:06:52 +08:00
this.search()
})
}).catch(() => {
})
}
}
}
</script>
<style scoped>
</style>