diff --git a/src/views/system/user/index.vue b/src/views/system/user/index.vue index 9bf0480..e250954 100644 --- a/src/views/system/user/index.vue +++ b/src/views/system/user/index.vue @@ -4,18 +4,17 @@
- +
-
@@ -33,6 +32,12 @@ + 密码重置 @@ -45,8 +50,8 @@ -->
- - + + @@ -57,9 +62,9 @@ - + - + - + - - - + + + @@ -142,7 +147,7 @@ - + @@ -179,7 +184,7 @@ import crudUser, { resetpassword } from '@/api/system/user' import { isvalidPhone } from '@/utils/validate' import { getDepts, FetchSonDepts } from '@/api/system/dept' import { FetchFondsAll } from '@/api/system/fonds' -import { getAll, getLevel } from '@/api/system/role' +import { getAll } from '@/api/system/role' import { getAllJob } from '@/api/system/job' import CRUD, { presenter, header, form, crud } from '@crud/crud' import rrOperation from '@crud/RR.operation' @@ -193,13 +198,20 @@ import '@riophae/vue-treeselect/dist/vue-treeselect.css' import { LOAD_CHILDREN_OPTIONS } from '@riophae/vue-treeselect' import Vue from 'vue' let userRoles = [] -let userJobs = [] -const defaultForm = { id: null, userName: null, nickName: null, gender: '男', email: null, enabled: null, fondsId: null, roles: [], jobs: [], deptsId: null, phone: null } +let userPosts = [] +const defaultForm = { id: null, username: null, nickName: null, gender: '男', email: null, enabled: null, fonds: { id: null }, roles: [], posts: [], dept: { id: null }, phone: null } export default { name: 'User', components: { Treeselect, crudOperation, rrOperation, pagination, DateRangePicker }, cruds() { - return CRUD({ title: '用户', url: 'api/users/initUserList', sort: 'update_time,asc', crudMethod: { ...crudUser }}) + return CRUD({ title: '用户', url: 'api/users/initUserList', sort: '', crudMethod: { ...crudUser }, optShow: { + add: true, + edit: true, + del: false, + reset: true, + download: true, + group: false + }}) }, mixins: [presenter(), header(), form(defaultForm), crud()], // 数据字典 @@ -215,9 +227,15 @@ export default { callback() } } - var validateJob = (rule, value, callback) => { - console.log(value) - if (this.jobDatas.length > 0) { + const validateRole = (rule, value, callback) => { + if (this.roleDatas.length > 0) { + callback() + } else { + callback(new Error('请选择角色')) + } + } + const validatePost = (rule, value, callback) => { + if (this.postDatas.length > 0) { callback() } else { callback(new Error('请选择岗位')) @@ -230,13 +248,13 @@ export default { blurryTime: null, btnLoading: false, resetVisible: false, - // delVisible: false, - // deleteData: {}, height: document.documentElement.clientHeight - 180 + 'px;', - deptName: '', depts: [], deptDatas: [], jobs: [], level: 3, roles: [], - jobDatas: [], roleDatas: [], // 多选时使用 + deptName: '', depts: [], deptDatas: [], postsOptions: [], level: 3, roles: [], + postDatas: [], roleDatas: [], // 多选时使用 fondsDatas: [], fondsOptions: [], + leftFondsId: '', + leftDeptsId: '', filterText: '', defaultExpandedKeys: [], defaultProps: { children: 'children', label: 'fondsName' }, @@ -249,9 +267,9 @@ export default { { key: '1', display_name: '激活' }, { key: '0', display_name: '锁定' } ], - + deleteData: [], rules: { - userName: [ + username: [ { required: true, message: '请输入用户名', trigger: 'blur' }, { min: 2, max: 20, message: '长度在 2 到 20 个字符', trigger: 'blur' } ], @@ -266,17 +284,23 @@ export default { phone: [ { required: true, trigger: 'blur', validator: validPhone } ], - 'deptsId': [ + 'dept.id': [ { required: true, trigger: 'blur', message: '请选择部门' } ], + 'fonds.id': [ + { required: true, trigger: 'blur', message: '请选择全宗' } + ], gender: [ { required: true, trigger: 'change', message: '请选择性别' } ], enabled: [ { required: true, trigger: 'change', message: '请选择状态' } ], - jobs: [ - { trigger: 'blur', validator: validateJob } + roles: [ + { trigger: 'blur', validator: validateRole } + ], + posts: [ + { trigger: 'blur', validator: validatePost } ] } } @@ -316,10 +340,104 @@ export default { this.crud.query.endTime = this.blurryTime[1] } }, + // 新增与编辑前做的操作 + [CRUD.HOOK.afterToCU](crud, form) { + this.getRoles() + this.getPosts() + console.log('postsvvvv', this.postsOptions) + console.log('form', form) + console.log(this.crud.status.edit) + // if (this.crud.status.edit) { + // if (form.postIds.includes(',')) { + // const arr = form.postIds.split(',') + // console.log(arr) + // arr.forEach(item => { + // const json = {} + // json.id = item + // this.postDatas.push(json) + // this.posts.push({ + + // }) + // console.log(this.postDatas) + // }) + // } else { + // this.postDatas.push(form.postIds) + // } + // } + }, + // 新增前将多选的值设置为空 + [CRUD.HOOK.beforeToAdd]() { + this.postDatas = [] + this.roleDatas = [] + }, + // 初始化编辑时候的角色与岗位 + [CRUD.HOOK.beforeToEdit](crud, form) { + console.log('beforeToEdit', crud) + console.log('beforeToEditform.roles', form.roles) + this.postDatas = [] + this.roleDatas = [] + userRoles = [] + userPosts = [] + const _this = this + form.roles.forEach(function(role, index) { + _this.roleDatas.push(role.id) + const rol = { id: role.id } + userRoles.push(rol) + }) + if (form.postIds.includes(',')) { + const arr = form.postIds.split(',') + console.log(arr) + _this.postDatas = arr + arr.forEach(function(id, index) { + const data = { id: id } + userPosts.push(data) + form.posts.push(data) + }) + console.log('userPosts', userPosts) + } + }, + // 提交前做的操作 + [CRUD.HOOK.afterValidateCU](crud) { + console.log(crud) + console.log(crud.form) + if (!crud.form.fonds.id) { + this.$message({ + message: '全宗不能为空', + type: 'warning' + }) + return false + } else if (!crud.form.dept.id) { + this.$message({ + message: '部门不能为空', + type: 'warning' + }) + return false + } else if (this.postDatas.length === 0) { + this.$message({ + message: '岗位不能为空', + type: 'warning' + }) + return false + } else if (this.roleDatas.length === 0) { + this.$message({ + message: '角色不能为空', + type: 'warning' + }) + return false + } + crud.form.id = crud.form.userId + crud.form.roles = userRoles + crud.form.posts = userPosts + delete crud.form.deptsId + delete crud.form.deptsName + delete crud.form.job + return false + }, clickRowHandler(row) { this.$refs.table.clearSelection() this.$refs.table.toggleRowSelection(row) }, + // 重置密码 handlePwdReset() { this.resetVisible = true }, @@ -327,7 +445,6 @@ export default { pwdReset(data) { const params = data.map(item => { return item.userName }) this.btnLoading = true - console.log(params) resetpassword(params).then(res => { if (res === 'SUCCESS') { this.$message({ @@ -355,11 +472,36 @@ export default { userRoles.push(role) }) }, - changeJob(value) { - userJobs = [] - value.forEach(function(data, index) { - const job = { id: data } - userJobs.push(job) + changePost(val) { + // const allValues = [] + // // 保留所有值 + // for (const item of this.organOptions) { + // allValues.push(item.id) + // } + // // 用来储存上一次的值,可以进行对比 + // const oldVal = this.oldSearchClassify.length === 1 ? this.oldSearchClassify[0] : [] + // // 若是全部选择 + // if (val.includes('ALL_SELECT')) this.searchClassify = allValues + // // 取消全部选中 上次有 当前没有 表示取消全选 + // if (oldVal.includes('ALL_SELECT') && !val.includes('ALL_SELECT')) this.searchClassify = [] + // // 点击非全部选中 需要排除全部选中 以及 当前点击的选项 + // // 新老数据都有全部选中 + // if (oldVal.includes('ALL_SELECT') && val.includes('ALL_SELECT')) { + // const index = val.indexOf('ALL_SELECT') + // val.splice(index, 1) // 排除全选选项 + // this.searchClassify = val + // } + // // 全选未选 但是其他选项全部选上 则全选选上 上次和当前 都没有全选 + // if (!oldVal.includes('ALL_SELECT') && !val.includes('ALL_SELECT')) { + // if (val.length === allValues.length - 1) this.searchClassify = ['ALL_SELECT'].concat(val) + // } + // // 储存当前最后的结果 作为下次的老数据 + // this.oldSearchClassify[0] = this.searchClassify + + userPosts = [] + val.forEach(function(data, index) { + const post = { id: data } + userPosts.push(post) }) }, deleteTag(value) { @@ -369,6 +511,27 @@ export default { } }) }, + // 切换部门 + handleNodeClick(data) { + console.log('nodeiD', data.id) + console.log('nodeName', data.deptsName) + const selectedKey = this.$refs.tree.getCurrentNode() + console.log('selectedKey', selectedKey) + const selectedParentVal = this.$refs.tree.getNode(selectedKey).parent.data.id + console.log('selectedParentVal', selectedParentVal) + if (data.pid === 0) { + this.query.deptsId = null + this.query.deptsName = null + this.leftFondsId = null + this.leftDeptsId = null + } else { + this.query.deptsId = data.id + this.query.deptsName = data.deptsName + this.leftFondsId = selectedParentVal + this.leftDeptsId = data.id + } + this.crud.toQuery() + }, getFondsDatas() { const parent = {} parent.id = 0 @@ -380,24 +543,22 @@ export default { parent.children = res this.fondsDatas.push(parent) this.fondsOptions = res - // this.fondsOptions = JSON.parse(JSON.stringify(this.fondsDatas)) - // this.fondsOptions[0].children.map(item => { - // console.log(item) - // delete item.children - // }) this.$nextTick(() => { - Vue.set(this.defaultExpandedKeys, 0, this.fondsDatas[0].children[0].id) - this.$refs.tree.setCurrentKey(this.fondsDatas[0].children[0].id) - this.handleNodeClick(this.fondsDatas[0].children[0]) + Vue.set(this.defaultExpandedKeys, 0, this.fondsDatas[0].children[0].children[0].id) + this.$refs.tree.setCurrentKey(this.fondsDatas[0].children[0].children[0].id) + this.handleNodeClick(this.fondsDatas[0].children[0].children[0]) }) }) }, filterNode(value, data) { if (!value) return true - return data.fondsName.indexOf(value) !== -1 - }, - changeFonds(val) { - console.log('val', val) + if (data.deptsName) { + if (data.deptsName.includes(value)) { + return true + } else { + return false + } + } }, changeFondsValue(value) { this.depts = [] @@ -413,89 +574,6 @@ export default { } this.getDepts(params) }, - // 新增与编辑前做的操作 - [CRUD.HOOK.afterToCU](crud, form) { - console.log(form) - this.getRoles() - if (form.id == null) { - this.getDepts() - } else { - // this.getSupDepts(form.deptsId) - } - this.getRoleLevel() - this.getJobs() - form.enabled = form.enabled.toString() - }, - // 新增前将多选的值设置为空 - [CRUD.HOOK.beforeToAdd]() { - this.jobDatas = [] - this.roleDatas = [] - }, - // 初始化编辑时候的角色与岗位 - [CRUD.HOOK.beforeToEdit](crud, form) { - this.getJobs(this.form.deptsId) - this.jobDatas = [] - this.roleDatas = [] - userRoles = [] - userJobs = [] - const _this = this - form.roles.forEach(function(role, index) { - _this.roleDatas.push(role.id) - const rol = { id: role.id } - userRoles.push(rol) - }) - form.jobs.forEach(function(job, index) { - _this.jobDatas.push(job.id) - const data = { id: job.id } - userJobs.push(data) - }) - }, - // 提交前做的操作 - [CRUD.HOOK.afterValidateCU](crud) { - if (!crud.form.deptsId) { - this.$message({ - message: '部门不能为空', - type: 'warning' - }) - return false - } else if (this.jobDatas.length === 0) { - this.$message({ - message: '岗位不能为空', - type: 'warning' - }) - return false - } else if (this.roleDatas.length === 0) { - this.$message({ - message: '角色不能为空', - type: 'warning' - }) - return false - } - crud.form.roles = userRoles - crud.form.jobs = userJobs - return true - }, - // 获取左侧部门数据 - getDeptDatas(node, resolve) { - const sort = 'update_time,desc' - const params = { sort: sort } - if (typeof node !== 'object') { - if (node) { - params['name'] = node - } - } else if (node.level !== 0) { - params['pid'] = node.data.id - } - setTimeout(() => { - getDepts(params).then(res => { - if (resolve) { - resolve(res.content) - } else { - this.deptDatas = res.content - } - }) - }, 100) - }, getDepts(params) { getDepts(params).then(res => { this.depts = res.content.map(function(obj) { @@ -532,18 +610,33 @@ export default { }) } }, - // 切换部门 - handleNodeClick(data) { - if (data.pid === 0) { - this.query.deptId = null - } else { - this.query.deptId = data.id - } - this.crud.toQuery() + // 删除用户 + toDelete(datas) { + this.deleteData = datas + this.$confirm('此操作将删除当前所选' + this.crud.title + '你是否还要继续?', '提示', { + confirmButtonText: '继续', + cancelButtonText: '取消', + type: 'warning', + dangerouslyUseHTMLString: true + }).then(() => { + this.crud.delAllLoading = true + const userIds = [] + this.deleteData.forEach(val => { + userIds.push(val.userId) + }) + crudUser.del(userIds).then(() => { + this.crud.notify('删除成功', CRUD.NOTIFICATION_TYPE.SUCCESS) + this.crud.delAllLoading = false + this.crud.refresh() + }).catch(err => { + this.crud.delAllLoading = false + console.log(err) + }) + }).catch(() => { + }) }, // 改变状态 changeEnabled(data, val) { - // '此操作将 "' + this.dict.label.user_status[val] + '" ' + data.username + ', 你是否继续?', this.$confirm('此操作将禁用 / 启用用户 “' + data.username + '”' + '你是否还要继续?', '提示', { confirmButtonText: '继续', cancelButtonText: '取消', @@ -552,11 +645,13 @@ export default { }).then(() => { crudUser.edit(data).then(res => { this.crud.notify(this.dict.label.user_status[val] + '成功', CRUD.NOTIFICATION_TYPE.SUCCESS) + this.crud.refresh() }).catch(() => { data.enabled = !data.enabled }) }).catch(() => { - data.enabled = !data.enabled + this.crud.notify('已取消修改', CRUD.NOTIFICATION_TYPE.INFO) + data.enabled = data.enabled ? 0 : 1 }) }, // 获取弹窗内角色数据 @@ -566,15 +661,9 @@ export default { }).catch(() => { }) }, // 获取弹窗内岗位数据 - getJobs() { + getPosts() { getAllJob().then(res => { - this.jobs = res.content - }).catch(() => { }) - }, - // 获取权限级别 - getRoleLevel() { - getLevel().then(res => { - this.level = res.level + this.postsOptions = res.content }).catch(() => { }) }, checkboxT(row, rowIndex) { @@ -608,10 +697,12 @@ export default { ::v-deep .el-tree{ .el-tree-node__content{ font-size: 14px; + color: #545B65; } .top-level{ font-size: 16px; font-weight: 600; + color: #0C0E1E; } }