Commit 50457910 by cwq0219

修改

1 parent ac6df49e
<template>
<el-dialog
:title="title"
:before-close="handleClose"
:visible.sync="dialogVisible"
width="720px"
custom-class="edit-role-dialog"
:close-on-click-modal="false"
v-if="dialogVisible"
>
<el-form
ref="roleForm"
:model="roleForm"
label-width="120px"
class="edit-dialog-form"
:rules="rules"
>
<el-form-item label="角色名:" prop="roleName">
<el-input v-model="roleForm.roleName" requred maxlength="10" :show-word-limit="true" clearable placeholder="请输入角色名" :disabled="!!roleForm.roleId"></el-input>
</el-form-item>
<el-form-item label="描述:">
<el-input
type="textarea"
:rows="2"
placeholder="角色描述"
clearable
maxlength="50"
:show-word-limit="true"
v-model="roleForm.description">
</el-input>
</el-form-item>
</el-form>
<el-divider content-position="left">权限设置</el-divider>
<RoleTree :resources="resources" :authIds="authIds" ref="roleTree" :close="dialogVisible"></RoleTree>
<div slot="footer">
<el-button @click="submit" type="primary" :loading="$store.state.d2admin.loading.value" class="button-submit">保存</el-button>
<el-button @click="handleClose" type="plain" class="button-submit">取消</el-button>
</div>
</el-dialog>
</template>
<script>
import { RoleReg, RoleModify } from '@/api/sys.account'
import notice from '@/common/notice'
import RoleTree from './roleTree'
import { localRoutes } from '@/router/routes'
import util from '@/libs/util.js'
export default {
name: 'editDialog',
props: {
isVisible: {
type: Boolean,
default: false
},
editData: {
type: Object,
default: null
}
},
components: {
RoleTree
},
watch: {
editData: {
handler: function(value) {
this.title = value && value.roleId ? '编辑角色' : '创建角色'
Object.assign(this.roleForm, value)
this.authIds = this.roleForm.authes || []
delete this.roleForm.authes
},
immediate: true
}
},
computed: {
dialogVisible() {
if (!this.isVisible) {
util.resetForm.call(this, 'roleForm')
}
return this.isVisible
},
resources() {
const clone = util.deepClone(Object.values(localRoutes))
const { menus } = util.permision.packMenusBtns(clone)
const all = util.permision.flatten(clone)
menus.find(o => o.authId === '101').disabled = true
return { menus, all }
}
},
data() {
return {
authIds: [],
title: '',
roleForm: {
roleName: '',
description: ''
},
rules: Object.freeze({
roleName: [
{ required: true, message: '角色名不能为空', trigger: ['blur'] }
]
})
}
},
methods: {
handleClose(done) {
this.emitClose(false)
},
emitClose(reload) {
this.$event.$emit('e-role-dialog-close', reload)
reload && this.$refs.roleForm.resetFields()
},
submit() {
this.$refs.roleForm.validate(vaild => {
if (vaild) {
const authIds = this.$refs.roleTree.getCheckedNodes()
var __p = { ...this.roleForm, authIds }
const fMethod = __p.roleId ? RoleModify : RoleReg
fMethod(__p).then(res => {
const { operateStatus } = res
if (operateStatus) {
notice.okTips(`${this.title}成功!`)
this.emitClose(true)
} else {
notice.errorTips(`${this.title}失败!`)
}
})
}
})
}
},
mounted() {
}
}
</script>
<style lang="scss">
.edit-role-dialog {
.el-divider--horizontal{
margin: 30px 0px 20px;
}
.role-tree{
height: 443px;overflow-y: auto;
}
}
</style>
<!-- 权限管理 -->
<template>
<d2-container class="role">
<d2-table-header title="角色列表"><auth-button category="action" label="创建角色"></auth-button></d2-table-header>
<d2-table
ref="roleTable"
:tableParams="tableParams"
:pagination="pagination"
:getListApi="getListApi"
>
<auth-button
slot="auth-button"
slot-scope="scope"
:data="scope.scope"
></auth-button>
</d2-table>
<edit-dialog
:isVisible="editVisible"
:editData="editData"
></edit-dialog>
</d2-container>
</template>
<script>
import { RoleList, RoleDetail } from '@/api/sys.account'
// import notice from '@/common/notice'
import { mapActions } from 'vuex'
import { BaseData } from '@/common/constants'
export default {
name: 'FimsRoles',
components: {
'EditDialog': () => import('./editDialog')
},
data() {
return {
getListApi: RoleList,
// 新增/编辑弹窗
editVisible: false,
// 表格
pagination: false,
// 表格参数
tableParams: {
btnId: new Date().getTime() + parseInt(Math.random() * 1000),
listName: 'roles',
tableOption: true,
tableColumns: Object.freeze([
{
label: '角色名称',
prop: 'roleName'
},
{
label: '描述',
prop: 'description'
},
{
label: '创建时间',
prop: 'createTime'
}
])
}
}
},
mounted() {
// this.fetchData()
this.$event.$on('e-role-dialog-close', async isReload => {
if (isReload) {
const { roles } = await RoleList()
this.set({ name: BaseData.ROLE.KEY, value: roles })
this.$refs.roleTable.refreshTable()
}
this.editVisible = false
})
},
methods: {
...mapActions('d2admin/base', ['set']),
async handleEdit(row) {
// this.editData = row && await RoleDetail({ roleId: row.roleId })
this.editData = row && Object.assign(row, await RoleDetail({ roleId: row.roleId }))
this.editVisible = true
}
}
}
</script>
<style scoped>
</style>
<template>
<div class="role-tree">
<el-tree
:data="resources.menus"
show-checkbox
ref="tree"
node-key="authId"
:default-expand-all="true"
:check-strictly="true"
@check-change="treeCheckChange"
:expand-on-click-node="true"
>
<span class="role-tree-node" slot-scope="{ node, data }">
<p v-text="node.label"></p>
<div class="role-tree-auth">
<template v-if="data.auth">
<el-checkbox-group size="mini" v-model="checked">
<el-checkbox
v-for="(btn,index) in data.auth"
:key="index"
:label="btn.authId"
@change="(sta)=>btnChange(node,btn,sta)"
><p v-text="btn.label"></p>
</el-checkbox>
</el-checkbox-group>
</template>
</div>
</span>
</el-tree>
</div>
</template>
<script>
export default {
data() {
return { checked: [] }
},
props: {
resources: {
type: Object,
default: null
},
authIds: [],
close: Boolean
},
watch: {
close(value) {
// !value && this.reset();
},
authIds: {
handler(value) {
if (!value) return
const chk = []
const treeChk = ['101']
this.$nextTick(() => {
value.forEach(v => {
v.authId += ''
const node = this.find(v.authId)
if (!node) return true
const check = node.hasOwnProperty('label') ? chk : treeChk
check.push(v.authId)
})
this.$refs.tree.setCheckedKeys(treeChk)
this.checked = chk
})
},
immediate: true
}
},
methods: {
treeCheckChange(node, checked, childChecked) {
// if(node.parentId ==='0') return
// this.checked=checked?[...this.resources.all.filter(res=> res.parentId === node.authId),...this.checked]:this.checked.filter(obj=>obj.parentId!==node.authId)
// !checked && (this.checked = this.checked.filter(obj=>this.resources.all.find( res => res.authId === obj).parentId!==node.authId))
// this.setCheckedNodes()
},
btnChange(node, data, sta) {
const checked = sta // || this.checked.some(child => child.parentId === node.key && child.authId !== data.authId);
checked && this.$refs.tree.setChecked(node.key, checked, true)
// this.setCheckedNodes()
},
getCheckedNodes() {
const { getCheckedKeys, getHalfCheckedKeys } = this.$refs.tree
let checkedIds = [
...getCheckedKeys(),
...getHalfCheckedKeys(),
...this.checked
]
checkedIds = checkedIds.map(node => {
const { authId, parentId } = this.resources.all.find(
res => res.authId === node
)
return { authId, parentId }
})
return checkedIds
// this.$emit('update:authIds', checkedIds)
},
reset() {
this.checked = []
this.$refs.tree.setCheckedKeys([])
// this.$emit('update:authIds', [])
},
find(authId) {
return this.resources.all.find(res => res.authId === authId)
}
}
}
</script>
<style lang="scss">
.role-tree {
padding-left: 30px;
.role-tree-node {
flex: 1;
display: flex;
align-items: center;
justify-content: space-between;
font-size: 14px;
padding: 8px;
}
.el-tree-node__content {
height: 34px;
.el-checkbox {
margin-right: 5px;
.el-checkbox__label {
padding: 0;
}
}
}
&-auth {
word-break: break-all;
word-wrap: break-word;
white-space: normal;
position: absolute;
left: 200px;
padding: 5px 0;
}
}
</style>
<template>
<el-dialog
:title="title"
:visible.sync="dialogVisible"
:before-close="handleClose"
width="720px"
custom-class="reg-dialog-admin"
:close-on-click-modal="false"
v-if="dialogVisible"
:append-to-body="true"
:lock-scroll="false"
>
<el-form
ref="regForm"
:model="regForm"
label-width="120px"
class="reg-dialog-form"
:rules="rules"
>
<el-form-item label="用户名:" prop="loginName">
<el-input
v-model="regForm.loginName"
:disabled="!!regForm.userId"
requred
maxlength="10"
placeholder="请输入用户名"
clearable
:show-word-limit="true"
></el-input>
</el-form-item>
<el-row>
<el-col :span="12">
<el-form-item label="姓名:" prop="userName">
<el-input
v-model="regForm.userName"
placeholder="请输入姓名"
maxlength="8"
:show-word-limit="true"
clearable
></el-input>
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col :span="12">
<el-form-item label="角色:" prop="roleId">
<el-select v-model="regForm.roleId" placeholder="请选择">
<el-option
:label="role.roleName"
:value="role.roleId"
v-for="(role,index) in baseData.roles"
:key="index"
></el-option>
</el-select>
</el-form-item>
</el-col>
</el-row>
</el-form>
<div slot="footer">
<el-button @click="submit" type="primary" :loading="$store.state.d2admin.loading.value" class="button-submit">提交</el-button>
<el-button @click="handleClose" type="plain" class="button-submit">取消</el-button>
</div>
</el-dialog>
</template>
<script>
import notice from '@/common/notice'
import util from '@/libs/util'
export default {
name: 'DialogReg',
props: {
isVisible: {
type: Boolean,
default: false
},
editData: {
type: Object,
default: null
},
verify: {
type: Function,
default: null
}
},
watch: {
editData: {
handler: function(value) {
if (!value || !value.data) return
const { data } = value
const { title, submit } = data
this.title = title
this.submitFunction = submit
delete value.data
Object.assign(this.regForm, value)
},
immediate: true
}
},
computed: {
dialogVisible() {
if (!this.isVisible) {
util.resetForm.call(this, 'regForm')
}
return this.isVisible
}
},
data() {
return {
regForm: {
loginName: '',
userName: '',
roleId: ''
},
title: '',
submitFunction: null,
rules: Object.freeze({
loginName: [
{ required: true, message: '用户名不能为空', trigger: ['blur'] }
],
userName: [
{ required: true, message: '姓名不能为空', trigger: ['blur'] }
],
roleId: [{ required: true, message: '角色不能为空', trigger: ['blur'] }]
})
}
},
methods: {
handleClose(done) {
this.$event.$emit('e-reg-dialog-close', false)
},
// 提交注册或审核数据
submit() {
this.$refs.regForm.validate(vaild => {
if (vaild) {
var __p = this.regForm
this.submitFunction(__p).then(res => {
const { operateStatus } = res
if (operateStatus) {
notice.okTips(`${this.title}成功!`)
this.$refs.regForm.resetFields()
this.$event.$emit('e-reg-dialog-close', true)
} else {
notice.errorTips(`${this.title}失败!`)
}
})
}
})
}
},
mounted() {
}
}
</script>
<!-- 用户管理 -->
<template>
<d2-container class="user">
<el-form :inline="true" :model="searchForm" label-width="85px" slot="header">
<el-form-item label="用户:">
<el-input v-model="searchForm.userName" placeholder="请输入用户名/姓名/联系电话" clearable></el-input>
</el-form-item>
<!-- <el-form-item label="角色:">
<el-select v-model="searchForm.roleId" clearable placeholder="请选择">
<el-option
v-for="(role,index) in baseData.roles"
:label="role.roleName"
:value="role.roleId"
:key="index"
></el-option>
</el-select>
</el-form-item> -->
<el-form-item label="注册时间:">
<el-date-picker
v-model="searchTimes"
type="daterange"
range-separator="至"
start-placeholder="开始日期"
end-placeholder="结束日期"
value-format="yyyy-MM-dd"
></el-date-picker>
</el-form-item>
<el-form-item>
<el-button type="primary" icon="el-icon-search" :id="tableParams.btnId">查询</el-button>
</el-form-item>
</el-form>
<d2-table-header title="用户列表"><auth-button category="action" label="创建用户"></auth-button></d2-table-header>
<d2-table
ref="userTable"
:searchForm="searchForm"
:tableParams="tableParams"
:getListApi="getListApi"
>
<auth-button
slot="auth-button"
slot-scope="scope"
:data="scope.scope"
:mapping="mapping"
></auth-button>
</d2-table>
<dialog-reg :isVisible="registerDialogVisible" :editData="editData" :key="key"/>
</d2-container>
</template>
<script>
import {
UserList,
PassWordReset,
AccountModify,
AccountIncrease,
AccountForbidden,
AccountValidate,
AccountActived,
Reg
} from '@/api/sys.account'
import notice from '@/common/notice'
import { mapActions } from 'vuex'
import util from '@/libs/util'
export default {
name: 'FimsUsers',
components: {
DialogReg: () => import('./dialogReg')
},
data() {
return {
getListApi: UserList,
key: new Date(),
mapping: Object.freeze({
field: 'status',
'1': ['重置密码', '编辑', '延期', '禁用'],
'2': ['重置密码', '编辑', '激活'],
'3': ['重置密码', '编辑', '激活'],
'4': ['审核']
}),
apiMapping: Object.freeze({
'重置密码': PassWordReset,
'延期': AccountIncrease,
'禁用': AccountForbidden,
'激活': AccountActived
}),
// 新增/编辑弹窗
registerDialogVisible: false,
editData: {},
// 搜索
searchForm: {
userName: '',
status: '',
stationCode: '',
postCode: '',
startTime: '',
endTime: ''
},
searchTimes: [],
// 表格
// 表格参数
tableParams: {
btnId: new Date().getTime() + parseInt(Math.random() * 1000),
listName: 'userList',
tag: Object.freeze({
type: ['', 'success', 'info', 'danger', 'warning'],
label: ['未知', '正常', '已过期', '禁用', '待审核']
}),
tableOption: true,
tableColumns: [{
label: '用户名',
prop: 'loginName',
width: '200'
}, {
label: '角色',
prop: 'roleName',
width: '140'
}, {
label: '注册时间',
prop: 'registerTime',
minWidth: '200'
}, {
label: '有效期',
prop: 'validTime',
minWidth: '200'
}, {
label: '状态',
prop: 'status',
width: '120',
tagLabel: true
}, {
label: '姓名',
prop: 'userName',
width: '120'
}]
}
/* -----------------------基础数据---------------------- */
// baseData: {
// // 所属站点
// stations: [],
// // 职务
// posts: [],
// // 角色
// roles: []
// }
}
},
watch: {
'searchTimes'(value) {
Object.assign(this.searchForm, util.formatTime(this.searchTimes))
}
// '$store.state.d2admin.base.role'(value) {
// this.baseData.roles = value
// this.key = new Date()
// }
},
mounted() {
// this.fetchData()
this.$event.$on('e-reg-dialog-close', isReload => {
isReload && this.$refs.userTable.refreshTable()
this.registerDialogVisible = false
})
},
methods: {
...mapActions('d2admin/base', ['load']),
// 加载业务所需所有数据
// fetchData() {
// this.loadBaseData()
// },
// async loadBaseData() {
// const { role, station, post } = await this.load()
// this.baseData.posts = post
// this.baseData.stations = station
// this.baseData.roles = role.roles
// Object.freeze(this.baseData)
// },
/* 接口请求-start */
filterTag(value, row) {
return row.status === value
},
handleRegister() {
const row = {
data: {
title: '用户创建',
submit: Reg
}
}
this.openDialog(row)
},
handleEdit(row) {
row = util.deepClone(row)
row.data = {
title: '用户编辑',
submit: AccountModify
}
this.openDialog(row)
},
openDialog(row) {
this.registerDialogVisible = true
this.editData = row
},
handleVerify(row) {
row = util.deepClone(row)
row.data = {
title: '用户审核',
submit: AccountValidate
}
this.openDialog(row)
},
// ------------
// 列表各种操作
async handleOperation(row, e) {
const _actionText = e.target.innerText
const res = await this.apiMapping[_actionText]({ userId: row.userId })
const { operateStatus } = res
if (operateStatus) {
notice.okTips(`${_actionText}成功!`)
this.$refs.userTable.refreshTable()
} else {
notice.errorTips(`${_actionText}失败!`)
}
}
}
}
</script>
<style scoped>
</style>
......@@ -27,11 +27,11 @@ const cdn = {
`${CDN_DOMAIN}/nprogress/0.2.0/nprogress.min.js`,
`${CDN_DOMAIN}/echarts/4.3.0-rc.1/echarts.min.js`,
`${CDN_DOMAIN}/lodash.js/4.17.15/lodash.min.js`,
`${CDN_DOMAIN}/qs/6.8.0/qs.min.js`,
`${CDN_DOMAIN}/qs/6.8.0/qs.min.js`
// `${CDN_DOMAIN}/core-js/2.6.9/core.min.js`,
// `${CDN_DOMAIN}/vue-i18n/8.14.0/vue-i18n.esm.js`,
// `${CDN_DOMAIN}/UAParser.js/0.7.20/ua-parser.min.js`,
'https://unpkg.com/better-scroll@1.15.2/dist/bscroll.min.js'
// 'https://unpkg.com/better-scroll@1.15.2/dist/bscroll.min.js'
]
}
module.exports = {
......@@ -61,7 +61,7 @@ module.exports = {
'lodash': '_',
// 'vue-i18n':'vue-i18n',
// 'ua-parser-js': 'UAParser',
'better-scroll': 'BScroll',
// 'better-scroll': 'BScroll',
'qs': 'Qs'
// 'core-js': 'core-js'
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!