Files
wms_base/wms_pro/qd/src/views/system/role/index.vue

295 lines
9.4 KiB
Vue
Raw Normal View History

2022-06-27 19:25:41 +08:00
<template>
<div class="app-container">
<!--工具栏-->
<div class="head-container">
<div v-if="crud.props.searchToggle">
<!-- 搜索 -->
<el-input
v-model="query.blurry"
2023-03-14 15:31:36 +08:00
size="mini"
2022-06-27 19:25:41 +08:00
clearable
:placeholder="$t('role.table_title.input_name')"
2022-06-27 19:25:41 +08:00
style="width: 200px;"
class="filter-item"
@keyup.enter.native="crud.toQuery"
/>
2023-05-05 16:35:38 +08:00
<rrOperation />
2022-06-27 19:25:41 +08:00
</div>
2023-05-05 16:35:38 +08:00
<crudOperation :permission="permission" />
2022-06-27 19:25:41 +08:00
</div>
<!-- 表单渲染 -->
<el-dialog
append-to-body
:close-on-click-modal="false"
:before-close="crud.cancelCU"
:visible.sync="crud.status.cu > 0"
:title="crud.status.title"
width="520px"
>
2023-03-14 15:31:36 +08:00
<el-form ref="form" :inline="true" :model="form" :rules="rules" size="mini" label-width="80px">
<el-form-item :label="$t('role.table_value.Name')" prop="name">
2023-05-05 16:35:38 +08:00
<el-input v-model="form.name" style="width: 380px;" />
2022-06-27 19:25:41 +08:00
</el-form-item>
<el-form-item :label="$t('role.table_value.Name')" prop="description">
2023-05-05 16:35:38 +08:00
<el-input v-model="form.remark" style="width: 380px;" rows="2" type="textarea" />
2022-06-27 19:25:41 +08:00
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="text" @click="crud.cancelCU">{{ $t('task.select.Cancel') }}</el-button>
<el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">{{ $t('task.select.Confirm') }}</el-button>
2022-06-27 19:25:41 +08:00
</div>
</el-dialog>
<el-row :gutter="15">
<!--角色管理-->
2023-03-14 15:31:36 +08:00
<el-col :span="12" style="margin-bottom: 10px">
2022-06-27 19:25:41 +08:00
<el-card class="box-card" shadow="never">
<div slot="header" class="clearfix">
<span class="role-span">{{ $t('role.table_value.roleList') }}</span>
2022-06-27 19:25:41 +08:00
</div>
<el-table
ref="table"
v-loading="crud.loading"
highlight-current-row
style="width: 100%;"
:data="crud.data"
@selection-change="crud.selectionChangeHandler"
@current-change="handleCurrentChange"
>
2023-05-05 16:35:38 +08:00
<el-table-column type="selection" width="55" />
<el-table-column prop="name" :label="$t('role.table_value.Name')" :min-width="flexWidth('name',crud.data,$t('role.table_value.Name'))" show-overflow-tooltip />
<el-table-column show-overflow-tooltip prop="remark" :label="$t('role.table_value.Description')" :min-width="flexWidth('remark',crud.data,$t('role.table_value.Description'))" />
<el-table-column show-overflow-tooltip :min-width="flexWidth('create_time',crud.data,$t('role.table_value.CreateDate'))" prop="create_time" :label="$t('role.table_value.CreateDate')">
2022-06-27 19:25:41 +08:00
<template slot-scope="scope">
<span>{{ parseTime(scope.row.create_time) }}</span>
2022-06-27 19:25:41 +08:00
</template>
</el-table-column>
<el-table-column
v-permission="['admin','roles:edit','roles:del']"
:label="$t('role.table_value.Operate')"
2022-06-27 19:25:41 +08:00
width="130px"
align="center"
fixed="right"
>
<template slot-scope="scope">
<udOperation
:data="scope.row"
:permission="permission"
/>
</template>
</el-table-column>
</el-table>
<!--分页组件-->
2023-05-05 16:35:38 +08:00
<pagination />
2022-06-27 19:25:41 +08:00
</el-card>
</el-col>
<!-- 菜单授权 -->
2023-03-14 15:31:36 +08:00
<el-col :span="12">
2022-06-27 19:25:41 +08:00
<el-card class="box-card" shadow="never">
<div slot="header" class="clearfix">
<el-tooltip class="item" effect="dark" content="选择指定角色分配菜单" placement="top">
<span class="role-span">{{ $t('role.other.Menu_assignments') }}</span>
2022-06-27 19:25:41 +08:00
</el-tooltip>
<el-button
v-permission="['admin','roles:edit']"
:disabled="!showButton"
:loading="menuLoading"
icon="el-icon-check"
size="mini"
2023-03-14 15:31:36 +08:00
style="float: right; padding: 6px 10px"
2022-06-27 19:25:41 +08:00
type="primary"
@click="saveMenu"
>{{ $t('role.other.Save') }}
2022-06-27 19:25:41 +08:00
</el-button>
</div>
2023-03-14 15:31:36 +08:00
2022-06-27 19:25:41 +08:00
<el-tree
ref="menu"
lazy
:data="menus"
2023-05-05 16:35:38 +08:00
:default-checked-keys="menu_ids"
2022-06-27 19:25:41 +08:00
:load="getMenuDatas"
:props="defaultProps"
check-strictly
accordion
show-checkbox
2023-05-05 16:35:38 +08:00
node-key="menu_id"
2022-06-27 19:25:41 +08:00
@check="menuChange"
/>
</el-card>
</el-col>
</el-row>
</div>
</template>
<script>
2023-03-14 15:31:36 +08:00
import crudRoles from './role'
2023-05-05 16:35:38 +08:00
import crudMenu from '@/views/system/menu/menu'
2023-03-14 15:31:36 +08:00
import { getChild, getMenusTree } from '@/views/system/menu/menu'
2022-06-27 19:25:41 +08:00
import CRUD, { crud, form, header, presenter } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'
import i18n from '@/i18n'
2022-06-27 19:25:41 +08:00
2023-05-09 13:54:35 +08:00
const defaultForm = { role_id: null, name: null, remark: null }
2022-06-27 19:25:41 +08:00
export default {
name: 'Role',
components: { pagination, crudOperation, rrOperation, udOperation },
2022-06-27 19:25:41 +08:00
cruds() {
return CRUD({ idField: 'role_id', title: i18n.t('role.table_value.Role'), url: 'api/sysRole', crudMethod: { ...crudRoles }})
2022-06-27 19:25:41 +08:00
},
mixins: [presenter(), header(), form(defaultForm), crud()],
data() {
return {
2023-03-14 15:31:36 +08:00
defaultProps: { children: 'children', label: 'title', isLeaf: 'leaf' },
2022-06-27 19:25:41 +08:00
currentId: 0, menuLoading: false, showButton: false,
2023-05-05 16:35:38 +08:00
menus: [], menu_ids: [], // 多选时使用
2022-06-27 19:25:41 +08:00
permission: {
add: ['admin', 'roles:add'],
edit: ['admin', 'roles:edit'],
del: ['admin', 'roles:del']
},
rules: {
name: [
{ required: true, message: '请输入名称', trigger: 'blur' }
],
permission: [
{ required: true, message: '请输入权限', trigger: 'blur' }
]
}
}
},
created() {
},
methods: {
getMenuDatas(node, resolve) {
setTimeout(() => {
2023-05-05 16:35:38 +08:00
getMenusTree(node.data.menu_id ? node.data.menu_id : 0).then(res => {
2022-06-27 19:25:41 +08:00
resolve(res)
})
}, 100)
},
2023-03-14 15:31:36 +08:00
getMenusByRole(val) {
if (this.currentId && val[0] && val[1]) {
const param = {
role_id: this.currentId,
system_type: val[0],
category: val[1]
}
const _this = this
crudMenu.getMenusByRole(param).then(res => {
_this.menus = res
// 初始化默认选中的key
2023-05-05 16:35:38 +08:00
_this.menu_ids = []
2023-03-14 15:31:36 +08:00
_this.menus.forEach(function(data) {
2023-05-05 16:35:38 +08:00
_this.menu_ids.push(data)
2023-03-14 15:31:36 +08:00
})
})
}
},
2022-06-27 19:25:41 +08:00
[CRUD.HOOK.afterRefresh]() {
this.$refs.menu.setCheckedKeys([])
},
// 提交前做的操作
[CRUD.HOOK.afterValidateCU](crud) {
return true
},
// 触发单选
handleCurrentChange(val) {
if (val) {
const _this = this
// 清空菜单的选中
this.$refs.menu.setCheckedKeys([])
// 保存当前的角色id
2023-05-09 13:54:35 +08:00
this.currentId = val.role_id
2022-06-27 19:25:41 +08:00
// 初始化默认选中的key
2023-05-05 16:35:38 +08:00
this.menu_ids = []
2022-06-27 19:25:41 +08:00
val.menus.forEach(function(data) {
2023-05-05 16:35:38 +08:00
_this.menu_ids.push(data)
2022-06-27 19:25:41 +08:00
})
this.showButton = true
}
},
menuChange(menu) {
// 获取该节点的所有子节点id 包含自身
2023-05-05 16:35:38 +08:00
getChild(menu.menu_id).then(childIds => {
// 判断是否在 menu_ids 中,如果存在则删除,否则添加
if (this.menu_ids.indexOf(menu.menu_id) !== -1) {
2022-06-27 19:25:41 +08:00
for (let i = 0; i < childIds.length; i++) {
2023-05-05 16:35:38 +08:00
const index = this.menu_ids.indexOf(childIds[i])
2022-06-27 19:25:41 +08:00
if (index !== -1) {
2023-05-05 16:35:38 +08:00
this.menu_ids.splice(index, 1)
2022-06-27 19:25:41 +08:00
}
}
} else {
for (let i = 0; i < childIds.length; i++) {
2023-05-05 16:35:38 +08:00
const index = this.menu_ids.indexOf(childIds[i])
2022-06-27 19:25:41 +08:00
if (index === -1) {
2023-05-05 16:35:38 +08:00
this.menu_ids.push(childIds[i])
2022-06-27 19:25:41 +08:00
}
}
}
2023-05-05 16:35:38 +08:00
this.$refs.menu.setCheckedKeys(this.menu_ids)
2022-06-27 19:25:41 +08:00
})
},
// 保存菜单
saveMenu() {
this.menuLoading = true
2023-05-09 13:54:35 +08:00
const role = { role_id: this.currentId, menus: [] }
2022-06-27 19:25:41 +08:00
// 得到已选中的 key 值
2023-05-05 16:35:38 +08:00
this.menu_ids.forEach(function(menu_id) {
const menu = { menu_id: menu_id }
2022-06-27 19:25:41 +08:00
role.menus.push(menu)
})
crudRoles.editMenu(role).then(() => {
this.crud.notify('保存成功', CRUD.NOTIFICATION_TYPE.SUCCESS)
this.menuLoading = false
2023-03-14 15:31:36 +08:00
this.crud.toQuery()
// this.update()
2022-06-27 19:25:41 +08:00
}).catch(err => {
this.menuLoading = false
console.log(err.response.data.message)
})
},
// 改变数据
update() {
// 无刷新更新 表格数据
crudRoles.get(this.currentId).then(res => {
for (let i = 0; i < this.crud.data.length; i++) {
2023-05-05 16:35:38 +08:00
if (res.menu_id === this.crud.data[i].menu_id) {
2022-06-27 19:25:41 +08:00
this.crud.data[i] = res
break
}
}
})
}
}
}
</script>
<style rel="stylesheet/scss" lang="scss">
.role-span {
font-weight: bold;
color: #303133;
font-size: 15px;
}
</style>
<style rel="stylesheet/scss" lang="scss" scoped>
::v-deep .el-input-number .el-input__inner {
text-align: left;
}
2023-03-14 15:31:36 +08:00
::v-deep .el-card__header {
padding: 5px 0 5px 10px;
background-color: #f8f8f9;
2022-06-27 19:25:41 +08:00
}
2023-03-14 15:31:36 +08:00
::v-deep .el-card__body {
padding: 10px 0 10px 0;
2022-06-27 19:25:41 +08:00
}
</style>