前端迁移

This commit is contained in:
zhangzhiqiang
2022-12-07 09:20:30 +08:00
parent e01104696a
commit b2588d3010
10 changed files with 619 additions and 447 deletions

View File

@@ -8,6 +8,14 @@ export function getDepts(params) {
})
}
export function getDeptTree(params) {
return request({
url: '/api/dept/allTree',
method: 'get',
params
})
}
export function getDeptSuperior(ids) {
const data = ids.length || ids.length === 0 ? ids : Array.of(ids)
return request({
@@ -17,6 +25,14 @@ export function getDeptSuperior(ids) {
})
}
export function getDeptvo(params) {
return request({
url: 'api/dept/vo',
method: 'get',
params
})
}
export function add(data) {
return request({
url: 'api/dept',
@@ -41,4 +57,4 @@ export function edit(data) {
})
}
export default { add, edit, del, getDepts, getDeptSuperior }
export default { add, edit, del, getDepts, getDeptSuperior, getDeptvo, getDeptTree }

View File

@@ -15,8 +15,19 @@ export function getMenus(params) {
})
}
export function getMenusByRole(params) {
return request({
url: 'api/menus/getMenusByRole',
method: 'post',
data: params
})
}
export function getMenuSuperior(ids) {
const data = ids.length || ids.length === 0 ? ids : Array.of(ids)
// const data = ids.length || ids.length === 0 ? ids : Array.of(ids)
const data = {
'ids': ids
}
return request({
url: 'api/menus/superior',
method: 'post',
@@ -62,4 +73,4 @@ export function edit(data) {
})
}
export default { add, edit, del, getMenusTree, getMenuSuperior, getMenus, getChild }
export default { add, edit, del, getMenusTree, getMenuSuperior, getMenus, getChild, getMenusByRole }

View File

@@ -14,7 +14,7 @@
@keyup.enter.native="crud.toQuery"
/>
<el-select
v-model="query.enabled"
v-model="query.is_used"
clearable
size="mini"
placeholder="状态"
@@ -28,7 +28,6 @@
</div>
<crudOperation :permission="permission" />
</div>
<!--表单组件-->
<el-dialog
append-to-body
:close-on-click-modal="false"
@@ -39,14 +38,14 @@
>
<el-form ref="form" inline :model="form" :rules="rules" size="mini" label-width="80px">
<el-form-item label="部门编码" prop="code">
<el-input v-model="form.code" style="width: 370px;" />
<el-input v-model="form.code" :disabled="true" style="width: 370px;" />
</el-form-item>
<el-form-item label="部门名称" prop="name">
<el-input v-model="form.name" style="width: 370px;" />
</el-form-item>
<el-form-item label="部门排序" prop="deptSort">
<el-form-item label="部门排序" prop="dept_sort">
<el-input-number
v-model.number="form.deptSort"
v-model.number="form.dept_sort"
:min="0"
:max="999"
controls-position="right"
@@ -54,10 +53,7 @@
/>
</el-form-item>
<el-form-item label="外部标识" prop="extId">
<el-input v-model="form.extId" style="width: 370px;" />
</el-form-item>
<el-form-item label="版本ID" prop="versionId">
<el-input v-model="form.versionId" style="width: 370px;" />
<el-input v-model="form.ext_id" style="width: 370px;" />
</el-form-item>
<el-form-item label="顶级部门">
<el-radio-group v-model="form.isTop" style="width: 140px">
@@ -65,10 +61,14 @@
<el-radio label="0">否</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item label="状态" prop="enabled">
<el-radio v-for="item in dict.dept_status" :key="item.id" v-model="form.enabled" :label="item.value">
{{ item.label }}
</el-radio>
<el-form-item label="状态" prop="is_uesd">
<el-switch
v-model="form.is_used"
active-color="#409EFF"
inactive-color="#F56C6C"
active-value="1"
inactive-value="0"
/>
</el-form-item>
<el-form-item v-if="form.isTop === '0'" style="margin-bottom: 0;" label="上级部门" prop="pid">
<treeselect
@@ -76,7 +76,8 @@
:load-options="loadDepts"
:options="depts"
style="width: 370px;"
placeholder="选择上级类目"
:normalizer="normalizer"
placeholder="选择部门类目"
/>
</el-form-item>
</el-form>
@@ -85,7 +86,7 @@
<el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
</div>
</el-dialog>
<!--表格渲染-->
<!--表格渲染 :load="getDeptDatas" 点击事件 row-key需要指定唯一的数据id-->
<el-table
ref="table"
v-loading="crud.loading"
@@ -93,7 +94,7 @@
:load="getDeptDatas"
:tree-props="{children: 'children', hasChildren: 'hasChildren'}"
:data="crud.data"
row-key="id"
row-key="dept_id"
@select="crud.selectChange"
@select-all="crud.selectAllChange"
@selection-change="crud.selectionChangeHandler"
@@ -101,23 +102,21 @@
<el-table-column :selectable="checkboxT" type="selection" width="55" />
<!-- <el-table-column label="编码" prop="code" />-->
<el-table-column label="名称" prop="name" />
<el-table-column label="排序" prop="deptSort" />
<el-table-column label="状态" align="center" prop="enabled">
<el-table-column label="排序" prop="dept_sort" />
<el-table-column label="状态" align="center" prop="is_used">
<template slot-scope="scope">
<el-switch
v-model="scope.row.enabled"
v-model="scope.row.is_used"
:disabled="scope.row.id === 1"
active-color="#409EFF"
inactive-color="#F56C6C"
active-value="1"
inactive-value="0"
@change="changeEnabled(scope.row, scope.row.enabled,)"
/>
</template>
</el-table-column>
<el-table-column prop="createTime" label="创建日期">
<template slot-scope="scope">
<span>{{ parseTime(scope.row.createTime) }}</span>
</template>
</el-table-column>
<el-table-column prop="create_time" label="创建日期" />
<el-table-column
v-permission="['admin','dept:edit','dept:del']"
label="操作"
@@ -148,22 +147,20 @@ import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
const defaultForm = {
id: null,
code: null,
name: null,
isTop: '1',
subCount: 0,
sub_count: 0,
pid: null,
deptSort: 999,
enabled: 'true',
extId: null,
versionId: null
dept_sort: 999,
is_used: '1',
ext_id: null
}
export default {
name: 'Dept',
components: { Treeselect, crudOperation, rrOperation, udOperation },
cruds() {
return CRUD({ title: '部门', url: 'api/dept', crudMethod: { ...crudDept }})
return CRUD({ title: '部门', idField: 'dept_id', url: 'api/dept/vo', crudMethod: { ...crudDept }})
},
mixins: [presenter(), header(), form(defaultForm), crud()],
// 设置数据字典
@@ -172,13 +169,10 @@ export default {
return {
depts: [],
rules: {
code: [
{ required: true, message: '请输入编码', trigger: 'blur' }
],
name: [
{ required: true, message: '请输入名称', trigger: 'blur' }
],
deptSort: [
dept_sort: [
{ required: true, message: '请输入序号', trigger: 'blur', type: 'number' }
]
},
@@ -188,16 +182,16 @@ export default {
del: ['admin', 'dept:del']
},
enabledTypeOptions: [
{ key: 'true', display_name: '正常' },
{ key: 'false', display_name: '禁用' }
{ key: '1', display_name: '正常' },
{ key: '0', display_name: '禁用' }
]
}
},
methods: {
getDeptDatas(tree, treeNode, resolve) {
const params = { pid: tree.id }
const params = { pid: tree.dept_id }
setTimeout(() => {
crudDept.getDepts(params).then(res => {
crudDept.getDeptvo(params).then(res => {
resolve(res.content)
})
}, 100)
@@ -206,12 +200,12 @@ export default {
[CRUD.HOOK.afterToCU](crud, form) {
if (form.pid !== null) {
form.isTop = '0'
} else if (form.id !== null) {
} else {
form.isTop = '1'
}
form.enabled = `${form.enabled}`
if (form.id != null) {
this.getSupDepts(form.id)
form.is_used = `${form.is_used}`
if (form.pid != null) {
this.getSupDepts(form.pid)
} else {
this.getDepts()
}
@@ -234,7 +228,7 @@ export default {
})
},
getDepts() {
crudDept.getDepts({ enabled: true }).then(res => {
crudDept.getDeptvo({ is_used: '1' }).then(res => {
this.depts = res.content.map(function(obj) {
if (obj.hasChildren) {
obj.children = null
@@ -246,11 +240,9 @@ export default {
// 获取弹窗内部门数据
loadDepts({ action, parentNode, callback }) {
if (action === LOAD_CHILDREN_OPTIONS) {
crudDept.getDepts({ enabled: true, pid: parentNode.id }).then(res => {
crudDept.getDeptvo({ is_used: '1', pid: parentNode.dept_id }).then(res => {
parentNode.children = res.content.map(function(obj) {
if (obj.hasChildren) {
obj.children = null
}
obj.children = null
return obj
})
setTimeout(() => {
@@ -261,7 +253,7 @@ export default {
},
// 提交前的验证
[CRUD.HOOK.afterValidateCU]() {
if (this.form.pid !== null && this.form.pid === this.form.id) {
if (this.form.isTop !== '1' && this.form.pid == null) {
this.$message({
message: '上级部门不能为空',
type: 'warning'
@@ -292,6 +284,13 @@ export default {
},
checkboxT(row, rowIndex) {
return row.id !== 1
},
normalizer(node) {
return {
id: node.dept_id,
label: node.name,
children: node.children
}
}
}
}

View File

@@ -1,6 +1,6 @@
<template>
<div>
<div v-if="query.dictName === ''">
<div v-if="query.code === ''">
<div class="my-code">点击字典查看详情</div>
</div>
<div v-else>
@@ -8,12 +8,27 @@
<div class="head-container">
<div v-if="crud.props.searchToggle">
<!-- 搜索 -->
<el-input v-model="query.label" clearable size="mini" placeholder="输入字典标签查询" style="width: 200px;" class="filter-item" @keyup.enter.native="toQuery" />
<el-input
v-model="query.label"
clearable
size="mini"
placeholder="输入字典标签查询"
style="width: 200px;"
class="filter-item"
@keyup.enter.native="toQuery"
/>
<rrOperation />
</div>
</div>
<!--表单组件-->
<el-dialog append-to-body :close-on-click-modal="false" :before-close="crud.cancelCU" :visible="crud.status.cu > 0" :title="crud.status.title" width="500px">
<el-dialog
append-to-body
:close-on-click-modal="false"
:before-close="crud.cancelCU"
:visible="crud.status.cu > 0"
:title="crud.status.title"
width="500px"
>
<el-form ref="form" :model="form" :rules="rules" size="mini" label-width="80px">
<el-form-item label="字典标签" prop="label">
<el-input v-model="form.label" style="width: 370px;" />
@@ -21,8 +36,23 @@
<el-form-item label="字典值" prop="value">
<el-input v-model="form.value" style="width: 370px;" />
</el-form-item>
<el-form-item label="排序" prop="dictSort">
<el-input-number v-model.number="form.dictSort" :min="0" :max="999" controls-position="right" style="width: 370px;" />
<el-form-item label="排序" prop="dict_sort">
<el-input-number
v-model.number="form.dict_sort"
:min="0"
:max="999"
controls-position="right"
style="width: 370px;"
/>
</el-form-item>
<el-form-item label="参数1" prop="para1">
<el-input v-model="form.para1" style="width: 370px;" />
</el-form-item>
<el-form-item label="参数2" prop="para2">
<el-input v-model="form.para2" style="width: 370px;" />
</el-form-item>
<el-form-item label="参数3" prop="para3">
<el-input v-model="form.para3" style="width: 370px;" />
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
@@ -31,14 +61,30 @@
</div>
</el-dialog>
<!--表格渲染-->
<el-table ref="table" v-loading="crud.loading" :data="crud.data" highlight-current-row style="width: 100%;" @selection-change="crud.selectionChangeHandler">
<el-table-column label="所属字典" width="135">
{{ query.dictName }}
<el-table
ref="table"
v-loading="crud.loading"
:data="crud.data"
highlight-current-row
style="width: 100%;"
@selection-change="crud.selectionChangeHandler"
>
<el-table-column label="所属字典" min-width="150" show-overflow-tooltip>
{{ query.code }}
</el-table-column>
<el-table-column prop="label" label="字典标签" align="center" width="100" />
<el-table-column prop="label" label="字典标签" align="center" width="120" show-overflow-tooltip />
<el-table-column prop="value" label="字典值" align="center" width="60" />
<el-table-column prop="dictSort" label="排序" align="center" width="65" />
<el-table-column v-permission="['admin','dict:edit','dict:del']" label="操作" align="center" fixed="right">
<el-table-column prop="dict_sort" label="排序" align="center" width="65" />
<el-table-column prop="para1" label="参数1" align="center" width="65" />
<el-table-column prop="para2" label="参数2" align="center" width="65" />
<el-table-column prop="para3" label="参数3" align="center" width="65" />
<el-table-column
v-permission="['admin','dict:edit','dict:del']"
label="操作"
align="center"
width="115px"
fixed="right"
>
<template slot-scope="scope">
<udOperation
:data="scope.row"
@@ -55,18 +101,23 @@
<script>
import crudDictDetail from '@/api/system/dictDetail'
import CRUD, { presenter, header, form } from '@crud/crud'
import CRUD, { form, header, presenter } from '@crud/crud'
import pagination from '@crud/Pagination'
import rrOperation from '@crud/RR.operation'
import udOperation from '@crud/UD.operation'
const defaultForm = { id: null, label: null, value: null, dictSort: 999 }
const defaultForm = { dict_id: null, code: null, name: null, label: null, value: null, dict_sort: null, dict_type: null, para1: null, para2: null, para3: null, create_id: null, create_name: null, create_time: null, update_optid: null, update_optname: null, update_time: null }
export default {
components: { pagination, rrOperation, udOperation },
cruds() {
return [
CRUD({ title: '字典详情', url: 'api/dictDetail', query: { dictName: '' }, sort: ['dictSort,asc', 'id,desc'],
CRUD({
title: '字典详情',
url: 'api/dictDetail',
query: { code: '' },
idField: 'dict_id',
sort: ['dict_sort,asc', 'dict_id,desc'],
crudMethod: { ...crudDictDetail },
optShow: {
add: true,
@@ -82,11 +133,11 @@ export default {
presenter(),
header(),
form(function() {
return Object.assign({ dict: { id: this.dictId }}, defaultForm)
return Object.assign({ dict: { dict_id: this.dict_id }}, defaultForm)
})],
data() {
return {
dictId: null,
dict_id: null,
rules: {
label: [
{ required: true, message: '请输入字典标签', trigger: 'blur' }
@@ -94,7 +145,7 @@ export default {
value: [
{ required: true, message: '请输入字典值', trigger: 'blur' }
],
dictSort: [
dict_sort: [
{ required: true, message: '请输入序号', trigger: 'blur', type: 'number' }
]
},
@@ -109,7 +160,7 @@ export default {
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
::v-deep .el-input-number .el-input__inner {
text-align: left;
}
::v-deep .el-input-number .el-input__inner {
text-align: left;
}
</style>

View File

@@ -3,11 +3,11 @@
<!--表单组件-->
<el-dialog append-to-body :close-on-click-modal="false" :before-close="crud.cancelCU" :visible="crud.status.cu > 0" :title="crud.status.title" width="500px">
<el-form ref="form" :model="form" :rules="rules" size="mini" label-width="80px">
<el-form-item label="字典名称" prop="name">
<el-input v-model="form.name" style="width: 370px;" />
<el-form-item label="字典编码" prop="code">
<el-input v-model="form.code" style="width: 370px;" />
</el-form-item>
<el-form-item label="描述">
<el-input v-model="form.description" style="width: 370px;" />
<el-form-item label="名称">
<el-input v-model="form.name" style="width: 370px;" />
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
@@ -29,10 +29,17 @@
<crudOperation :permission="permission" />
</div>
<!--表格渲染-->
<el-table ref="table" v-loading="crud.loading" :data="crud.data" highlight-current-row style="width: 100%;" @selection-change="crud.selectionChangeHandler" @current-change="handleCurrentChange">
<el-table
ref="table"
v-loading="crud.loading"
:data="crud.data"
highlight-current-row
style="width: 100%;"
@selection-change="crud.selectionChangeHandler"
@current-change="handleCurrentChange">
<el-table-column type="selection" width="55" />
<el-table-column show-overflow-tooltip prop="code" label="编码" />
<el-table-column show-overflow-tooltip prop="name" label="名称" />
<el-table-column show-overflow-tooltip prop="description" label="描述" />
<el-table-column v-permission="['admin','dict:edit','dict:del']" label="操作" width="130px" align="center" fixed="right">
<template slot-scope="scope">
<udOperation
@@ -52,7 +59,7 @@
<div slot="header" class="clearfix">
<span>字典详情</span>
<el-button
v-if="checkPermission(['admin','dict:add']) && this.$refs.dictDetail && this.$refs.dictDetail.query.dictName"
v-if="checkPermission(['admin','dict:add']) && this.$refs.dictDetail && this.$refs.dictDetail.query.code"
class="filter-item"
size="mini"
style="float: right;padding: 4px 10px"
@@ -79,14 +86,14 @@ import pagination from '@crud/Pagination'
import rrOperation from '@crud/RR.operation'
import udOperation from '@crud/UD.operation'
const defaultForm = { id: null, name: null, description: null, dictDetails: [] }
const defaultForm = { dict_id: null, code: null, name: null, label: null, value: null, dict_sort: null, dict_type: null, para1: null, para2: null, para3: null, create_id: null, create_name: null, create_time: null, update_optid: null, update_optname: null, update_time: null }
export default {
name: 'Dict',
components: { crudOperation, pagination, rrOperation, udOperation, dictDetail },
cruds() {
return [
CRUD({ title: '字典', url: 'api/dict', crudMethod: { ...crudDict }})
CRUD({ title: '字典', url: 'api/dict', idField: 'dict_id', crudMethod: { ...crudDict }})
]
},
mixins: [presenter(), header(), form(defaultForm)],
@@ -97,8 +104,8 @@ export default {
{ key: 'description', display_name: '描述' }
],
rules: {
name: [
{ required: true, message: '请输入名称', trigger: 'blur' }
code: [
{ required: true, message: '请输入编码', trigger: 'blur' }
]
},
permission: {
@@ -113,15 +120,15 @@ export default {
// 获取数据前设置好接口地址
[CRUD.HOOK.beforeRefresh]() {
if (this.$refs.dictDetail) {
this.$refs.dictDetail.query.dictName = ''
this.$refs.dictDetail.query.code = ''
}
return true
},
// 选中字典后,设置字典详情数据
handleCurrentChange(val) {
if (val) {
this.$refs.dictDetail.query.dictName = val.name
this.$refs.dictDetail.dictId = val.id
this.$refs.dictDetail.query.code = val.code
this.$refs.dictDetail.form.dictCode = val.code
this.$refs.dictDetail.crud.toQuery()
}
}

View File

@@ -4,22 +4,38 @@
<div class="head-container">
<div v-if="crud.props.searchToggle">
<!-- 搜索 -->
<el-input v-model="query.blurry" clearable size="mini" placeholder="模糊搜索" style="width: 200px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
<el-input
v-model="query.blurry"
clearable
size="mini"
placeholder="模糊搜索"
style="width: 200px;"
class="filter-item"
@keyup.enter.native="crud.toQuery"
/>
<rrOperation />
</div>
<crudOperation :permission="permission" />
</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="580px">
<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="650px"
>
<el-form ref="form" :inline="true" :model="form" :rules="rules" size="mini" label-width="80px">
<el-form-item label="菜单类型" prop="type">
<el-radio-group v-model="form.type" size="mini" style="width: 178px">
<el-radio-button label="0">目录</el-radio-button>
<el-radio-button label="1">菜单</el-radio-button>
<el-radio-button label="2">按钮</el-radio-button>
<el-radio-group v-model="form.type" size="mini">
<el-radio-button label="1">系统</el-radio-button>
<el-radio-button label="2">目录</el-radio-button>
<el-radio-button label="3">菜单</el-radio-button>
<el-radio-button label="4">按钮</el-radio-button>
</el-radio-group>
</el-form-item>
<el-form-item v-show="form.type.toString() !== '2'" label="菜单图标" prop="icon">
<el-form-item v-show="form.type.toString() !== '1' && form.type.toString() !== '4' " label="菜单图标" prop="icon">
<el-popover
placement="bottom-start"
width="450"
@@ -28,61 +44,73 @@
>
<IconSelect ref="iconSelect" @selected="selected" />
<el-input slot="reference" v-model="form.icon" style="width: 450px;" placeholder="点击选择图标" readonly>
<svg-icon v-if="form.icon" slot="prefix" :icon-class="form.icon" class="el-input__icon" style="height: 32px;width: 16px;" />
<svg-icon
v-if="form.icon"
slot="prefix"
:icon-class="form.icon"
class="el-input__icon"
style="height: 32px;width: 16px;"
/>
<i v-else slot="prefix" class="el-icon-search el-input__icon" />
</el-input>
</el-popover>
</el-form-item>
<el-form-item v-show="form.type.toString() !== '2'" label="外链菜单" prop="iframe">
<el-radio-group v-model="form.iframe" size="mini">
<el-radio-button label="true">是</el-radio-button>
<el-radio-button label="false">否</el-radio-button>
<el-form-item v-show="form.type.toString() !== '2' && form.type.toString() !== '1'" label="外链菜单" prop="i_frame">
<el-radio-group v-model="form.i_frame" size="mini">
<el-radio-button label="1">是</el-radio-button>
<el-radio-button label="0">否</el-radio-button>
</el-radio-group>
</el-form-item>
<el-form-item v-show="form.type.toString() === '1'" label="菜单缓存" prop="cache">
<el-form-item v-show="form.type.toString() === '2'" label="菜单缓存" prop="cache">
<el-radio-group v-model="form.cache" size="mini">
<el-radio-button label="true">是</el-radio-button>
<el-radio-button label="false">否</el-radio-button>
<el-radio-button label="1">是</el-radio-button>
<el-radio-button label="0">否</el-radio-button>
</el-radio-group>
</el-form-item>
<el-form-item v-show="form.type.toString() !== '2'" label="菜单可见" prop="hidden">
<el-form-item v-show="form.type.toString() !== '2' && form.type.toString() !== '1' " label="菜单可见" prop="hidden">
<el-radio-group v-model="form.hidden" size="mini">
<el-radio-button label="false">是</el-radio-button>
<el-radio-button label="true">否</el-radio-button>
</el-radio-group>
</el-form-item>
<el-form-item v-show="form.type.toString() !== '2'" label="PC菜单" prop="hidden">
<el-radio-group v-model="form.isPc" size="mini">
<el-radio-button label="false">否</el-radio-button>
<el-radio-button label="true">是</el-radio-button>
<el-radio-button label="1">是</el-radio-button>
<el-radio-button label="0">否</el-radio-button>
</el-radio-group>
</el-form-item>
<el-form-item v-if="form.type.toString() !== '2'" label="菜单标题" prop="title">
<el-input v-model="form.title" :style=" form.type.toString() === '0' ? 'width: 450px' : 'width: 178px'" placeholder="菜单标题" />
<el-input
v-model="form.title"
:style=" form.type.toString() === '0' ? 'width: 450px' : 'width: 190px'"
placeholder="菜单标题"
/>
</el-form-item>
<el-form-item v-if="form.type.toString() === '2'" label="按钮名称" prop="title">
<el-input v-model="form.title" placeholder="按钮名称" style="width: 178px;" />
<el-input v-model="form.title" placeholder="按钮名称" style="width: 190px;" />
</el-form-item>
<el-form-item v-show="form.type.toString() !== '0'" label="权限标识" prop="permission">
<el-input v-model="form.permission" :disabled="form.iframe" placeholder="权限标识" style="width: 178px;" />
<el-form-item v-show="form.type.toString() !== '1' " label="权限标识" prop="permission">
<el-input v-model="form.permission" :disabled="form.i_frame=='1'" placeholder="权限标识" style="width: 190px;" />
</el-form-item>
<el-form-item v-if="form.type.toString() !== '2'" label="路由地址" prop="path">
<el-input v-model="form.path" placeholder="路由地址" style="width: 178px;" />
<el-form-item v-if="form.type.toString() !== '1' && form.type.toString() !== '2'" label="路由地址" prop="path">
<el-input v-model="form.path" placeholder="路由地址" style="width: 190px;" />
</el-form-item>
<el-form-item label="菜单排序" prop="menuSort">
<el-input-number v-model.number="form.menuSort" :min="0" :max="999" controls-position="right" style="width: 178px;" />
<el-input-number
v-model.number="form.menuSort"
:min="0"
:max="999"
controls-position="right"
style="width: 190px;"
/>
</el-form-item>
<el-form-item v-show="!form.iframe && form.type.toString() === '1'" label="组件名称" prop="componentName">
<el-input v-model="form.componentName" style="width: 178px;" placeholder="匹配组件内Name字段" />
<el-form-item v-show="!form.i_frame && form.type.toString() === '3' " label="组件名称" prop="componentName">
<el-input v-model="form.componentName" style="width: 190px;" placeholder="匹配组件内Name字段" />
</el-form-item>
<el-form-item v-show="!form.iframe && form.type.toString() === '1'" label="组件路径" prop="component">
<el-input v-model="form.component" style="width: 178px;" placeholder="组件路径" />
<el-form-item v-show="!form.i_frame && (form.type.toString() === '2' ||form.type.toString() === '3' ) " label="组件路径" prop="component">
<el-input v-model="form.component" style="width: 190px;" placeholder="组件路径" />
</el-form-item>
<el-form-item label="上级类目" prop="pid">
<!-- normalizer转换- loadMenus 点击扩展的时候会调用该方法-->
<treeselect
v-model="form.pid"
:options="menus"
:load-options="loadMenus"
:normalizer="normalizer"
style="width: 450px;"
placeholder="选择上级类目"
/>
@@ -99,57 +127,42 @@
v-loading="crud.loading"
lazy
:load="getMenus"
:auto-load-root-options="false"
:data="crud.data"
:tree-props="{children: 'children', hasChildren: 'hasChildren'}"
row-key="id"
row-key="menu_id"
@select="crud.selectChange"
@select-all="crud.selectAllChange"
@selection-change="crud.selectionChangeHandler"
>
<el-table-column type="selection" width="55" />
<el-table-column show-overflow-tooltip label="菜单标题" width="125px" prop="title" />
<el-table-column prop="icon" label="图标" align="center" width="60px">
<el-table-column label="菜单标题" prop="title" :min-width="flexWidth('title',crud.data,'菜单标题')" />
<el-table-column label="子系统" prop="system_type" :min-width="flexWidth('system_type',crud.data,'子系统')" />
<el-table-column prop="icon" label="图标" align="center" :min-width="flexWidth('icon',crud.data,'图标')">
<template slot-scope="scope">
<svg-icon :icon-class="scope.row.icon ? scope.row.icon : ''" />
</template>
</el-table-column>
<el-table-column prop="menuSort" align="center" label="排序">
<el-table-column prop="menuSort" align="center" label="排序" :min-width="flexWidth('menuSort',crud.data,'排序')">
<template slot-scope="scope">
{{ scope.row.menuSort }}
</template>
</el-table-column>
<el-table-column show-overflow-tooltip prop="permission" label="权限标识" />
<el-table-column show-overflow-tooltip prop="component" label="组件路径" />
<el-table-column prop="iframe" label="外链" width="75px">
<template slot-scope="scope">
<span v-if="scope.row.iframe">是</span>
<span v-else>否</span>
</template>
</el-table-column>
<el-table-column prop="cache" label="缓存" width="75px">
<template slot-scope="scope">
<span v-if="scope.row.cache">是</span>
<span v-else>否</span>
</template>
</el-table-column>
<el-table-column prop="hidden" label="可见" width="75px">
<template slot-scope="scope">
<span v-if="scope.row.hidden">否</span>
<span v-else>是</span>
</template>
</el-table-column>
<el-table-column prop="hidden" label="是否PC" width="75px">
<template slot-scope="scope">
<span v-if="scope.row.isPc">是</span>
<span v-else>否</span>
</template>
</el-table-column>
<el-table-column prop="createTime" label="创建日期" width="135px">
<template slot-scope="scope">
<span>{{ parseTime(scope.row.createTime) }}</span>
</template>
</el-table-column>
<el-table-column v-permission="['admin','menu:edit','menu:del']" label="操作" width="130px" align="center" fixed="right">
<el-table-column prop="permission" label="权限标识" :min-width="flexWidth('permission',crud.data,'权限标识')" />
<el-table-column prop="component" label="组件路径" min-width="120" />
<el-table-column prop="i_frame" label="外链" :formatter="crud.formatIsOrNot" :min-width="flexWidth('i_frame',crud.data,'外链')" />
<el-table-column prop="cache" label="缓存" :formatter="crud.formatIsOrNot" :min-width="flexWidth('cache',crud.data,'缓存')" />
<el-table-column prop="hidden" label="可见" :formatter="crud.formatIsOrNot" :min-width="flexWidth('hidden',crud.data,'可见')" />
<el-table-column prop="createTime" label="创建日期" :min-width="flexWidth('createTime',crud.data,'创建日期')" />
<el-table-column
v-permission="['admin','menu:edit','menu:del']"
label="操作"
width="130px"
align="center"
fixed="right"
>
<template slot-scope="scope">
<udOperation
:data="scope.row"
@@ -175,12 +188,29 @@ import udOperation from '@crud/UD.operation'
import DateRangePicker from '@/components/DateRangePicker'
// crud交由presenter持有
const defaultForm = { id: null, title: null, menuSort: 999, path: null, component: null, componentName: null, iframe: false, roles: [], pid: 0, icon: null, cache: false, hidden: false, type: 0, permission: null, isPc: true }
const defaultForm = {
menu_id: null,
title: null,
menuSort: 999,
path: null,
system_type: null,
category: null,
component: null,
componentName: null,
i_frame: 0,
roles: [],
pid: 0,
icon: null,
cache: 0,
hidden: 0,
type: 0,
permission: null
}
export default {
name: 'Menu',
components: { Treeselect, IconSelect, crudOperation, rrOperation, udOperation, DateRangePicker },
cruds() {
return CRUD({ title: '菜单', url: 'api/menus', crudMethod: { ...crudMenu }})
return CRUD({ title: '菜单', idField: 'menu_id', url: 'api/menus', crudMethod: { ...crudMenu }})
},
mixins: [presenter(), header(), form(defaultForm), crud()],
data() {
@@ -191,6 +221,13 @@ export default {
edit: ['admin', 'menu:edit'],
del: ['admin', 'menu:del']
},
normalizer(node) {
return {
id: node.menu_id,
label: node.title,
children: node.children
}
},
rules: {
title: [
{ required: true, message: '请输入标题', trigger: 'blur' }
@@ -205,37 +242,37 @@ export default {
// 新增与编辑前做的操作
[CRUD.HOOK.afterToCU](crud, form) {
this.menus = []
if (form.id != null) {
if (form.pid === null) {
if (form.menu_id) { // 修改
if (!form.pid) { // 一级菜单一级的父级菜单的pid为0.
form.pid = 0
}
this.getSupDepts(form.id)
} else {
this.menus.push({ id: 0, label: '顶级类目', children: null })
this.getSupDepts(form.menu_id)
} else { // 新增
this.menus.push({ menu_id: 0, title: '顶级类目', children: null })
}
},
getMenus(tree, treeNode, resolve) {
const params = { pid: tree.id }
const params = { pid: tree.menu_id }
setTimeout(() => {
crudMenu.getMenus(params).then(res => {
resolve(res.content)
})
}, 100)
},
getSupDepts(id) {
crudMenu.getMenuSuperior(id).then(res => {
getSupDepts(menu_id) {
crudMenu.getMenuSuperior(menu_id).then(res => {
const children = res.map(function(obj) {
if (!obj.leaf && !obj.children) {
obj.children = null
}
return obj
})
this.menus = [{ id: 0, label: '顶级类目', children: children }]
this.menus = [{ menu_id: 0, title: '顶级类目', children: children }]
})
},
loadMenus({ action, parentNode, callback }) {
if (action === LOAD_CHILDREN_OPTIONS) {
crudMenu.getMenusTree(parentNode.id).then(res => {
crudMenu.getMenusTree(parentNode.menu_id).then(res => {
parentNode.children = res.map(function(obj) {
if (!obj.leaf) {
obj.children = null
@@ -257,11 +294,12 @@ export default {
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
::v-deep .el-input-number .el-input__inner {
text-align: left;
}
::v-deep .vue-treeselect__control,::v-deep .vue-treeselect__placeholder,::v-deep .vue-treeselect__single-value {
height: 30px;
line-height: 30px;
}
::v-deep .el-input-number .el-input__inner {
text-align: left;
}
::v-deep .vue-treeselect__control, ::v-deep .vue-treeselect__placeholder, ::v-deep .vue-treeselect__single-value {
height: 30px;
line-height: 30px;
}
</style>

View File

@@ -8,14 +8,14 @@
v-model="query.blurry"
size="mini"
clearable
placeholder="输入名称或者描述搜索"
placeholder="输入名称"
style="width: 200px;"
class="filter-item"
@keyup.enter.native="crud.toQuery"
/>
<rrOperation />
<rrOperation/>
</div>
<crudOperation :permission="permission" />
<crudOperation :permission="permission"/>
</div>
<!-- 表单渲染 -->
<el-dialog
@@ -28,33 +28,10 @@
>
<el-form ref="form" :inline="true" :model="form" :rules="rules" size="mini" label-width="80px">
<el-form-item label="角色名称" prop="name">
<el-input v-model="form.name" style="width: 380px;" />
<el-input v-model="form.name" style="width: 380px;"/>
</el-form-item>
<el-form-item label="角色级别" prop="level">
<el-input-number v-model.number="form.level" :min="1" controls-position="right" style="width: 145px;" />
</el-form-item>
<el-form-item label="数据范围" prop="dataScope">
<el-select v-model="form.dataScope" style="width: 140px" placeholder="请选择数据范围" @change="changeScope">
<el-option
v-for="item in dateScopes"
:key="item"
:label="item"
:value="item"
/>
</el-select>
</el-form-item>
<el-form-item v-if="form.dataScope === '自定义'" label="数据权限" prop="depts">
<treeselect
v-model="deptDatas"
:load-options="loadDepts"
:options="depts"
multiple
style="width: 380px"
placeholder="请选择"
/>
</el-form-item>
<el-form-item label="描述信息" prop="description">
<el-input v-model="form.description" style="width: 380px;" rows="5" type="textarea" />
<el-form-item label="备注" prop="description">
<el-input v-model="form.description" style="width: 380px;" rows="2" type="textarea"/>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
@@ -64,7 +41,7 @@
</el-dialog>
<el-row :gutter="15">
<!--角色管理-->
<el-col :xs="24" :sm="24" :md="16" :lg="16" :xl="17" style="margin-bottom: 10px">
<el-col :span="12" style="margin-bottom: 10px">
<el-card class="box-card" shadow="never">
<div slot="header" class="clearfix">
<span class="role-span">角色列表</span>
@@ -78,11 +55,9 @@
@selection-change="crud.selectionChangeHandler"
@current-change="handleCurrentChange"
>
<el-table-column :selectable="checkboxT" type="selection" width="55" />
<el-table-column prop="name" label="名称" min-width="100" show-overflow-tooltip />
<el-table-column prop="dataScope" label="数据权限" />
<el-table-column prop="level" label="角色级别" />
<el-table-column show-overflow-tooltip prop="description" label="描述" />
<el-table-column type="selection" width="55"/>
<el-table-column prop="name" label="名称" min-width="100" show-overflow-tooltip/>
<el-table-column show-overflow-tooltip prop="description" label="描述"/>
<el-table-column show-overflow-tooltip width="135px" prop="createTime" label="创建日期">
<template slot-scope="scope">
<span>{{ parseTime(scope.row.createTime) }}</span>
@@ -97,7 +72,6 @@
>
<template slot-scope="scope">
<udOperation
v-if="scope.row.level >= level"
:data="scope.row"
:permission="permission"
/>
@@ -105,11 +79,11 @@
</el-table-column>
</el-table>
<!--分页组件-->
<pagination />
<pagination/>
</el-card>
</el-col>
<!-- 菜单授权 -->
<el-col :xs="24" :sm="24" :md="8" :lg="8" :xl="7">
<el-col :span="12">
<el-card class="box-card" shadow="never">
<div slot="header" class="clearfix">
<el-tooltip class="item" effect="dark" content="选择指定角色分配菜单" placement="top">
@@ -121,12 +95,13 @@
:loading="menuLoading"
icon="el-icon-check"
size="mini"
style="float: right; padding: 6px 9px"
style="float: right; padding: 6px 10px"
type="primary"
@click="saveMenu"
>保存
</el-button>
</div>
<el-tree
ref="menu"
lazy
@@ -137,7 +112,7 @@
check-strictly
accordion
show-checkbox
node-key="id"
node-key="menu_id"
@check="menuChange"
/>
</el-card>
@@ -148,31 +123,27 @@
<script>
import crudRoles from '@/api/system/role'
import { getDepts, getDeptSuperior } from '@/api/system/dept'
import crudMenu from '@/api/system/menu'
import { getChild, getMenusTree } from '@/api/system/menu'
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 Treeselect, { LOAD_CHILDREN_OPTIONS } from '@riophae/vue-treeselect'
import '@riophae/vue-treeselect/dist/vue-treeselect.css'
import DateRangePicker from '@/components/DateRangePicker'
const defaultForm = { id: null, name: null, depts: [], description: null, dataScope: '全部', level: 3 }
const defaultForm = { role_id: null, name: null, description: null }
export default {
name: 'Role',
components: { Treeselect, pagination, crudOperation, rrOperation, udOperation, DateRangePicker },
components: { pagination, crudOperation, rrOperation, udOperation, crudMenu },
cruds() {
return CRUD({ title: '角色', url: 'api/roles', sort: 'level,asc', crudMethod: { ...crudRoles }})
return CRUD({ idField: 'role_id', title: '角色', url: 'api/roles', crudMethod: { ...crudRoles } })
},
mixins: [presenter(), header(), form(defaultForm), crud()],
data() {
return {
defaultProps: { children: 'children', label: 'label', isLeaf: 'leaf' },
dateScopes: ['全部', '本级', '自定义'], level: 3,
defaultProps: { children: 'children', label: 'title', isLeaf: 'leaf' },
currentId: 0, menuLoading: false, showButton: false,
menus: [], menuIds: [], depts: [], deptDatas: [], // 多选时使用
menus: [], menuIds: [], // 多选时使用
permission: {
add: ['admin', 'roles:add'],
edit: ['admin', 'roles:edit'],
@@ -189,54 +160,40 @@ export default {
}
},
created() {
crudRoles.getLevel().then(data => {
this.level = data.level
})
},
methods: {
getMenuDatas(node, resolve) {
setTimeout(() => {
getMenusTree(node.data.id ? node.data.id : 0).then(res => {
getMenusTree(node.data.menu_id ? node.data.menu_id : 0).then(res => {
resolve(res)
})
}, 100)
},
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
_this.menuIds = []
_this.menus.forEach(function(data) {
_this.menuIds.push(data.menu_id)
})
})
}
},
[CRUD.HOOK.afterRefresh]() {
this.$refs.menu.setCheckedKeys([])
},
// 新增前初始化部门信息
[CRUD.HOOK.beforeToAdd]() {
this.deptDatas = []
},
// 编辑前初始化自定义数据权限的部门信息
[CRUD.HOOK.beforeToEdit](crud, form) {
this.deptDatas = []
if (form.dataScope === '自定义') {
this.getSupDepts(form.depts)
}
const _this = this
form.depts.forEach(function(dept) {
_this.deptDatas.push(dept.id)
})
},
// 提交前做的操作
[CRUD.HOOK.afterValidateCU](crud) {
if (crud.form.dataScope === '自定义' && this.deptDatas.length === 0) {
this.$message({
message: '自定义数据权限不能为空',
type: 'warning'
})
return false
} else if (crud.form.dataScope === '自定义') {
const depts = []
this.deptDatas.forEach(function(data) {
const dept = { id: data }
depts.push(dept)
})
crud.form.depts = depts
} else {
crud.form.depts = []
}
return true
},
// 触发单选
@@ -246,20 +203,20 @@ export default {
// 清空菜单的选中
this.$refs.menu.setCheckedKeys([])
// 保存当前的角色id
this.currentId = val.id
this.currentId = val.role_id
// 初始化默认选中的key
this.menuIds = []
val.menus.forEach(function(data) {
_this.menuIds.push(data.id)
_this.menuIds.push(data.menu_id)
})
this.showButton = true
}
},
menuChange(menu) {
// 获取该节点的所有子节点id 包含自身
getChild(menu.id).then(childIds => {
getChild(menu.menu_id).then(childIds => {
// 判断是否在 menuIds 中,如果存在则删除,否则添加
if (this.menuIds.indexOf(menu.id) !== -1) {
if (this.menuIds.indexOf(menu.menu_id) !== -1) {
for (let i = 0; i < childIds.length; i++) {
const index = this.menuIds.indexOf(childIds[i])
if (index !== -1) {
@@ -280,10 +237,10 @@ export default {
// 保存菜单
saveMenu() {
this.menuLoading = true
const role = { id: this.currentId, menus: [] }
const role = { role_id: this.currentId, menus: [] }
// 得到已选中的 key 值
this.menuIds.forEach(function(id) {
const menu = { id: id }
this.menuIds.forEach(function(menu_id) {
const menu = { menu_id: menu_id }
role.menus.push(menu)
})
crudRoles.editMenu(role).then(() => {
@@ -300,69 +257,12 @@ export default {
// 无刷新更新 表格数据
crudRoles.get(this.currentId).then(res => {
for (let i = 0; i < this.crud.data.length; i++) {
if (res.id === this.crud.data[i].id) {
if (res.menu_id === this.crud.data[i].menu_id) {
this.crud.data[i] = res
break
}
}
})
},
// 获取部门数据
getDepts() {
getDepts({ enabled: true }).then(res => {
this.depts = res.content.map(function(obj) {
if (obj.hasChildren) {
obj.children = null
}
return obj
})
})
},
getSupDepts(depts) {
const ids = []
depts.forEach(dept => {
ids.push(dept.id)
})
getDeptSuperior(ids).then(res => {
const date = res.content
this.buildDepts(date)
this.depts = date
})
},
buildDepts(depts) {
depts.forEach(data => {
if (data.children) {
this.buildDepts(data.children)
}
if (data.hasChildren && !data.children) {
data.children = null
}
})
},
// 获取弹窗内部门数据
loadDepts({ action, parentNode, callback }) {
if (action === LOAD_CHILDREN_OPTIONS) {
getDepts({ enabled: true, pid: parentNode.id }).then(res => {
parentNode.children = res.content.map(function(obj) {
if (obj.hasChildren) {
obj.children = null
}
return obj
})
setTimeout(() => {
callback()
}, 200)
})
}
},
// 如果数据权限为自定义则获取部门数据
changeScope() {
if (this.form.dataScope === '自定义') {
this.getDepts()
}
},
checkboxT(row) {
return row.level >= this.level
}
}
}
@@ -381,12 +281,12 @@ export default {
text-align: left;
}
::v-deep .vue-treeselect__multi-value {
margin-bottom: 0;
::v-deep .el-card__header {
padding: 5px 0 5px 10px;
background-color: #f8f8f9;
}
::v-deep .vue-treeselect__multi-value-item {
border: 0;
padding: 0;
::v-deep .el-card__body {
padding: 10px 0 10px 0;
}
</style>

View File

@@ -2,7 +2,7 @@
<div class="app-container">
<el-row :gutter="20">
<!--侧边部门数据-->
<el-col :xs="9" :sm="6" :md="5" :lg="5" :xl="4">
<el-col :span="4">
<div class="head-container">
<el-input
v-model="deptName"
@@ -16,15 +16,12 @@
</div>
<el-tree
:data="deptDatas"
:load="getDeptDatas"
:props="defaultProps"
:expand-on-click-node="false"
lazy
@node-click="handleNodeClick"
/>
</el-col>
<!--用户数据-->
<el-col :xs="15" :sm="18" :md="19" :lg="19" :xl="20">
<el-col :span="20">
<!--工具栏-->
<div class="head-container">
<div v-if="crud.props.searchToggle">
@@ -39,7 +36,7 @@
@keyup.enter.native="crud.toQuery"
/>
<el-select
v-model="query.enabled"
v-model="query.is_used"
clearable
size="mini"
placeholder="状态"
@@ -58,7 +55,7 @@
</div>
<crudOperation show="" :permission="permission" />
</div>
<!--表单渲染-->
<!--新增跟修改表单渲染-->
<el-dialog
append-to-body
:close-on-click-modal="false"
@@ -74,24 +71,27 @@
<el-form-item label="电话" prop="phone">
<el-input v-model.number="form.phone" style="width: 200px;" />
</el-form-item>
<el-form-item label="姓名" prop="nickName">
<el-input v-model="form.nickName" style="width: 200px;" />
<el-form-item label="姓名" prop="preson_name">
<el-input v-model="form.person_name" style="width: 200px;" />
</el-form-item>
<el-form-item label="邮箱" prop="email">
<el-input v-model="form.email" style="width: 200px;" />
</el-form-item>
<el-form-item label="部门" prop="dept.id" :rules="[{ required: true, message: '请选择部门', trigger: 'change' }]">
<el-form-item label="部门" prop="depts" :rules="[{ required: true, message: '请选择部门', trigger: 'change' }]">
<treeselect
v-model="form.dept.id"
:options="depts"
v-model="form.depts"
:load-options="loadDepts"
style="width: 200px"
placeholder="选择部门"
:options="deptDatas"
style="width: 370px;"
:multiple="true"
:flat="true"
:normalizer="normalizer"
placeholder="选择部门类目"
/>
</el-form-item>
<br v-if="!crud.status.add">
<el-form-item label="密码" prop="password" v-if="crud.status.add">
<el-input v-model="form.password" style="width: 200px;" show-password auto-complete="new-password"/>
<el-form-item v-if="crud.status.add" label="密码" prop="password">
<el-input v-model="form.password" style="width: 200px;" show-password auto-complete="new-password" />
</el-form-item>
<el-form-item label="性别">
<el-radio-group v-model="form.gender" style="width: 178px">
@@ -99,31 +99,32 @@
<el-radio label="">女</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item label="状态">
<el-radio-group v-model="form.enabled" :disabled="form.id === user.id">
<el-radio
v-for="item in dict.user_status"
:key="item.id"
:label="item.value"
>{{ item.label }}
</el-radio>
</el-radio-group>
<el-form-item label="状态" prop="is_uesd">
<el-switch
v-model="form.is_used"
active-color="#409EFF"
inactive-color="#F56C6C"
active-value="1"
inactive-value="0"
/>
</el-form-item>
<el-form-item style="margin-bottom: 0;" label="角色" prop="roles">
<el-select
v-model="roleDatas"
style="width: 512px"
multiple
active-value="1"
inactive-value="0"
placeholder="请选择"
@remove-tag="deleteTag"
@change="changeRole"
>
<!--:disabled="level !== 1 && item.level <= level"-->
<el-option
v-for="item in roles"
:key="item.name"
:disabled="level !== 1 && item.level <= level"
:key="item.role_id"
:label="item.name"
:value="item.id"
:value="item.role_id"
/>
</el-select>
</el-form-item>
@@ -142,55 +143,43 @@
@selection-change="crud.selectionChangeHandler"
>
<el-table-column :selectable="checkboxT" type="selection" width="55" />
<el-table-column show-overflow-tooltip prop="username" label="用户名" />
<el-table-column show-overflow-tooltip prop="nickName" label="姓名" />
<el-table-column prop="gender" label="性别" />
<el-table-column show-overflow-tooltip prop="phone" width="100" label="电话" />
<el-table-column show-overflow-tooltip width="135" prop="email" label="邮箱" />
<el-table-column show-overflow-tooltip prop="dept" label="部门">
<template slot-scope="scope">
<div>{{ scope.row.dept.name }}</div>
</template>
</el-table-column>
<el-table-column label="状态" align="center" prop="enabled">
<template slot-scope="scope">
<el-switch
v-model="scope.row.enabled"
:disabled="user.id === scope.row.id"
active-color="#409EFF"
inactive-color="#F56C6C"
@change="changeEnabled(scope.row, scope.row.enabled)"
/>
</template>
</el-table-column>
<el-table-column show-overflow-tooltip prop="createTime" width="135" label="创建日期">
<template slot-scope="scope">
<span>{{ parseTime(scope.row.createTime) }}</span>
</template>
</el-table-column>
<el-table-column prop="username" label="用户名" :min-width="flexWidth('username',crud.data,'用户名')" />
<el-table-column
v-permission="['admin','user:edit','user:del']"
label="操作"
width="200"
prop="person_name"
label="姓名"
:min-width="flexWidth('person_name',crud.data,'姓名')"
/>
<el-table-column prop="gender" label="性别" :min-width="flexWidth('person_name',crud.data,'性别')" />
<el-table-column prop="phone" label="电话" :min-width="flexWidth('phone',crud.data,'电话')" />
<el-table-column prop="email" label="邮箱" :min-width="flexWidth('email',crud.data,'邮箱')" />
<el-table-column show-overflow-tooltip prop="deptnames" label="部门" />
<el-table-column
label="启用"
align="center"
prop="is_used"
:formatter="crud.formatIsOrNot"
:min-width="flexWidth('is_used',crud.data,'启用')"
/>
<el-table-column prop="create_time" label="创建日期" :min-width="flexWidth('create_time',crud.data,'创建日期')" />
<el-table-column
label="操作"
fixed="right"
align="center"
width="200"
>
<template slot-scope="scope">
<udOperation
style="display: inline"
:data="scope.row"
:permission="permission"
:disabled-dle="scope.row.id === user.id"
/>
<el-button
v-permission="permission.edit"
type="text"
slot="left"
icon="el-icon-refresh-left"
@click="resetPassword(scope.row)"
>
重置密码
</el-button>
<template v-if="scope.row.userId !== 1" slot-scope="scope">
<el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)">修改</el-button>
<el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)">删除</el-button>
<el-dropdown v-hasPermi="['system:user:resetPwd', 'system:user:edit']" size="mini" @command="(command) => handleCommand(command, scope.row)">
<el-button size="mini" type="text" icon="el-icon-d-arrow-right">更多</el-button>
<el-dropdown-menu slot="dropdown">
<el-dropdown-item command="handleResetPwd" icon="el-icon-key">重置密码</el-dropdown-item>
<el-dropdown-item command="handleResetPwd" icon="el-icon-key">部门权限</el-dropdown-item>
<el-dropdown-item command="handleResetPwd" icon="el-icon-key">数据权限</el-dropdown-item>
<el-dropdown-item command="handleResetPwd" icon="el-icon-key">锁定账号</el-dropdown-item>
<el-dropdown-item command="handleAuthRole" icon="el-icon-circle-check">分配角色</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
</template>
</el-table-column>
</el-table>
@@ -203,36 +192,35 @@
<script>
import crudUser from '@/api/system/user'
import { getDepts, getDeptSuperior } from '@/api/system/dept'
import crudDept from '@/api/system/dept'
import { getAll, getLevel } from '@/api/system/role'
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 DateRangePicker from '@/components/DateRangePicker'
import Treeselect, { LOAD_CHILDREN_OPTIONS } from '@riophae/vue-treeselect'
import { mapGetters } from 'vuex'
import '@riophae/vue-treeselect/dist/vue-treeselect.css'
let userRoles = []
const defaultForm = {
id: null,
dept_id: null,
depts: [],
username: null,
nickName: null,
person_name: null,
gender: '男',
email: null,
enabled: 'true',
roles: [],
dept: { id: null },
phone: null,
password: null
}
export default {
name: 'User',
components: { Treeselect, crudOperation, rrOperation, udOperation, pagination, DateRangePicker },
components: { Treeselect, crudOperation, rrOperation, udOperation, pagination },
cruds() {
return CRUD({ title: '用户', url: 'api/users', crudMethod: { ...crudUser }})
return CRUD({ title: '用户', idField: 'user_id', url: 'api/users', crudMethod: { ...crudUser }})
},
mixins: [presenter(), header(), form(defaultForm), crud()],
// 数据字典
@@ -242,22 +230,22 @@ export default {
height: document.documentElement.clientHeight - 180 + 'px;',
deptName: '', depts: [], deptDatas: [], level: 3, roles: [],
roleDatas: [], // 多选时使用
defaultProps: { children: 'children', label: 'name', isLeaf: 'leaf' },
defaultProps: { children: 'children', label: 'name' },
permission: {
add: ['admin', 'user:add'],
edit: ['admin', 'user:edit'],
del: ['admin', 'user:del']
},
enabledTypeOptions: [
{ key: 'true', display_name: '激活' },
{ key: 'false', display_name: '锁定' }
{ key: '1', display_name: '激活' },
{ key: '0', display_name: '锁定' }
],
rules: {
username: [
{ required: true, message: '请输入用户名', trigger: 'blur' },
{ min: 2, max: 20, message: '长度在 2 到 20 个字符', trigger: 'blur' }
],
nickName: [
person_name: [
{ required: true, message: '请输入用户姓名', trigger: 'blur' },
{ min: 2, max: 20, message: '长度在 2 到 20 个字符', trigger: 'blur' }
]
@@ -269,6 +257,9 @@ export default {
'user'
])
},
beforeMount() {
this.deptTree()
},
created() {
this.crud.msg.add = '新增成功'
},
@@ -296,13 +287,13 @@ export default {
// 新增与编辑前做的操作
[CRUD.HOOK.afterToCU](crud, form) {
this.getRoles()
if (form.id == null) {
this.getDepts()
if (form.dept_id == null) {
crudDept.getDepts()
} else {
this.getSupDepts(form.dept.id)
this.getSupDepts(form.dept_id)
}
this.getRoleLevel()
form.enabled = form.enabled.toString()
form.is_used = form.enabled.toString()
},
// 新增前将多选的值设置为空
[CRUD.HOOK.beforeToAdd]() {
@@ -314,7 +305,8 @@ export default {
this.roleDatas = []
userRoles = []
const _this = this
form.roles.forEach(function(role, index) {
const arr = form.roles.split(',')
arr.forEach(function(role, index) {
_this.roleDatas.push(role.id)
const rol = { id: role.id }
userRoles.push(rol)
@@ -322,7 +314,7 @@ export default {
},
// 提交前做的操作
[CRUD.HOOK.afterValidateCU](crud) {
if (!crud.form.dept.id) {
if (!crud.form.depts) {
this.$message({
message: '部门不能为空',
type: 'warning'
@@ -335,25 +327,18 @@ export default {
})
return false
}
crud.form.roles = userRoles
const roles = []
userRoles.forEach(function(data, index) {
roles.push(data.id)
})
crud.form.roles = roles.toString()
crud.form.depts = crud.form.depts.toString()
return true
},
// 获取左侧部门数据
getDeptDatas(node, resolve) {
console.log('node', node)
console.log('resolve', resolve)
const sort = 'id,desc'
const params = { sort: sort }
if (typeof node !== 'object') {
if (node) {
params['name'] = node
}
} else if (node.level !== 0) {
params['pid'] = node.data.id
}
console.log('params', params)
setTimeout(() => {
getDepts(params).then(res => {
crudDept.getDeptTree({ name: node }).then(res => {
console.log('res', res)
if (resolve) {
resolve(res.content)
@@ -363,10 +348,19 @@ export default {
})
}, 100)
},
deptTree() {
setTimeout(() => {
crudDept.getDeptTree().then(res => {
this.deptDatas = res.content
})
}, 100)
},
getDepts() {
console.log('获取部门')
getDepts({ enabled: true }).then(res => {
crudDept.getDepts({ is_used: 1 }).then(res => {
console.log('获取的部门信息', res)
this.depts = res.content.map(function(obj) {
if (obj.hasChildren) {
obj.children = null
@@ -376,7 +370,7 @@ export default {
})
},
getSupDepts(deptId) {
getDeptSuperior(deptId).then(res => {
crudDept.getDeptSuperior(deptId).then(res => {
console.log('父部门', res)
const date = res.content
this.buildDepts(date)
@@ -396,26 +390,28 @@ export default {
// 获取弹窗内部门数据
loadDepts({ action, parentNode, callback }) {
if (action === LOAD_CHILDREN_OPTIONS) {
getDepts({ enabled: true, pid: parentNode.id }).then(res => {
crudDept.getDeptvo({ is_used: '1', pid: parentNode.dept_id }).then(res => {
parentNode.children = res.content.map(function(obj) {
if (obj.hasChildren) {
obj.children = null
}
obj.children = null
return obj
})
setTimeout(() => {
callback()
}, 200)
}, 100)
})
}
},
normalizer(node) {
return {
id: node.dept_id,
label: node.name,
children: node.children
}
},
// 切换部门
handleNodeClick(data) {
if (data.pid === 0) {
this.query.deptId = null
} else {
this.query.deptId = data.id
}
this.query.deptId = data.dept_id
this.query.needAll = true
this.crud.toQuery()
},
// 改变状态