diff --git a/src/api/system/user.js b/src/api/system/user.js index 2ffd545..55310c8 100644 --- a/src/api/system/user.js +++ b/src/api/system/user.js @@ -69,5 +69,16 @@ export function resetpassword(data) { }) } -export default { add, edit, del, resetpassword } +export function FetchEditUserState(data) { + return request({ + url: 'api/users/editUserState', + method: 'post', + headers: { + Authorization: getToken() + }, + data + }) +} + +export default { add, edit, del, resetpassword, FetchEditUserState } diff --git a/src/views/system/dept/index.vue b/src/views/system/dept/index.vue index cd38f2b..e8f26a9 100644 --- a/src/views/system/dept/index.vue +++ b/src/views/system/dept/index.vue @@ -121,7 +121,6 @@ > - @@ -484,27 +483,32 @@ export default { }, toDelete(datas) { this.deleteData = datas - this.$confirm('此操作将删除当前所选' + this.crud.title + '你是否还要继续?', '提示', { - confirmButtonText: '继续', - cancelButtonText: '取消', - type: 'warning', - dangerouslyUseHTMLString: true - }).then(() => { - this.crud.delAllLoading = true - const ids = [] - this.deleteData.forEach(val => { - ids.push(val.deptsId) - }) - crudDept.del(ids).then(() => { - this.crud.notify('删除成功', CRUD.NOTIFICATION_TYPE.SUCCESS) - this.crud.delAllLoading = false - this.crud.refresh() - }).catch(err => { - this.crud.delAllLoading = false - console.log(err) + const bool = this.deleteData.every(item => item.deptsTotalPeoNum !== 0) + if (!bool) { + this.$confirm('此操作将删除当前所选' + this.crud.title + '你是否还要继续?', '提示', { + confirmButtonText: '继续', + cancelButtonText: '取消', + type: 'warning', + dangerouslyUseHTMLString: true + }).then(() => { + this.crud.delAllLoading = true + const ids = [] + this.deleteData.forEach(val => { + ids.push(val.deptsId) + }) + crudDept.del(ids).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(() => { }) - }).catch(() => { - }) + } else { + this.crud.notify('当前选择条目中有用户存在不可直接操作删除', CRUD.NOTIFICATION_TYPE.ERROR) + } }, // 改变状态 changeStatus(data, val) { diff --git a/src/views/system/user/index.vue b/src/views/system/user/index.vue index e250954..c9ea0eb 100644 --- a/src/views/system/user/index.vue +++ b/src/views/system/user/index.vue @@ -29,7 +29,9 @@ - + + 搜索 + 重置 - 密码重置 +
@@ -46,12 +54,10 @@ -
- + @@ -64,7 +70,7 @@ - +
{{ getAutoNameUnknown(node.label) }}
@@ -108,7 +115,7 @@
- +
@@ -118,19 +125,6 @@
- -
@@ -163,11 +157,6 @@
{{ scope.row.createTime | parseTime }}
- @@ -187,7 +176,7 @@ import { FetchFondsAll } from '@/api/system/fonds' 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' +// import rrOperation from '@crud/RR.operation' import crudOperation from '@crud/CRUD.operation' // import udOperation from '@crud/UD.operation' import pagination from '@crud/Pagination' @@ -197,19 +186,21 @@ import { mapGetters } from 'vuex' import '@riophae/vue-treeselect/dist/vue-treeselect.css' import { LOAD_CHILDREN_OPTIONS } from '@riophae/vue-treeselect' import Vue from 'vue' +import { exportFile } from '@/utils/index' +import qs from 'qs' let userRoles = [] 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 }, + components: { Treeselect, crudOperation, pagination, DateRangePicker }, cruds() { - return CRUD({ title: '用户', url: 'api/users/initUserList', sort: '', crudMethod: { ...crudUser }, optShow: { + return CRUD({ title: '用户', idField: 'userId', url: 'api/users/initUserList', sort: [], crudMethod: { ...crudUser }, optShow: { add: true, edit: true, del: false, reset: true, - download: true, + download: false, group: false }}) }, @@ -248,16 +239,17 @@ export default { blurryTime: null, btnLoading: false, resetVisible: false, - height: document.documentElement.clientHeight - 180 + 'px;', - deptName: '', depts: [], deptDatas: [], postsOptions: [], level: 3, roles: [], + deptName: '', depts: [], deptDatas: [], posts: [], level: 3, roles: [], postDatas: [], roleDatas: [], // 多选时使用 fondsDatas: [], fondsOptions: [], + lastValue: '', leftFondsId: '', leftDeptsId: '', filterText: '', defaultExpandedKeys: [], defaultProps: { children: 'children', label: 'fondsName' }, + levelNumber: 0, permission: { add: ['admin', 'user:add'], edit: ['admin', 'user:edit'], @@ -307,7 +299,8 @@ export default { }, computed: { ...mapGetters([ - 'user' + 'user', + 'baseApi' ]) }, watch: { @@ -319,12 +312,9 @@ export default { this.crud.msg.add = '新增成功,默认密码:123456' }, mounted: function() { - const that = this - window.onresize = function temp() { - that.height = document.documentElement.clientHeight - 180 + 'px;' - } - console.log(this.user) this.getFondsDatas() + this.getRoles() + this.getPosts() }, methods: { getAutoNameUnknown(name) { @@ -334,36 +324,27 @@ export default { return name } }, + resetQuery() { + this.crud.query.blurry = '' + this.blurryTime = null + this.crud.query.startTime = null + this.crud.query.endTime = null + this.crud.query.userStatus = null + this.crud.toQuery() + }, [CRUD.HOOK.beforeRefresh]() { if (this.blurryTime) { this.crud.query.startTime = this.blurryTime[0] this.crud.query.endTime = this.blurryTime[1] + } else { + this.crud.query.startTime = null + this.crud.query.endTime = null } }, // 新增与编辑前做的操作 [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]() { @@ -372,8 +353,51 @@ export default { }, // 初始化编辑时候的角色与岗位 [CRUD.HOOK.beforeToEdit](crud, form) { - console.log('beforeToEdit', crud) - console.log('beforeToEditform.roles', form.roles) + this.lastValue = '' + this.levelNumber = 0 + form.roles = [] + form.posts = [] + + if (this.leftFondsId) { + form.fonds.id = this.leftFondsId + form.dept.id = this.leftDeptsId + this.changeFondsValue(this.leftFondsId) + this.levelNumber = 4 + } + + if (form.roleIds.includes(',')) { + const arr = form.roleIds.split(',') + this.roles.map((role) => { + arr.forEach(item => { + if (item === String(role.id)) { + return form.roles.push(role) + } + }) + }) + } else { + this.roles.map((role) => { + if (form.roleIds === String(role.id)) { + return form.roles.push(role) + } + }) + } + if (form.postIds.includes(',')) { + const arr = form.postIds.split(',') + this.posts.map((post) => { + arr.forEach(item => { + if (item === String(post.id)) { + return form.posts.push(post) + } + }) + }) + } else { + this.posts.map((post) => { + if (form.postIds === String(post.id)) { + return form.posts.push(post) + } + }) + } + this.postDatas = [] this.roleDatas = [] userRoles = [] @@ -384,22 +408,14 @@ export default { 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) - } + form.posts.forEach(function(job, index) { + _this.postDatas.push(job.id) + const data = { id: job.id } + userPosts.push(data) + }) }, // 提交前做的操作 [CRUD.HOOK.afterValidateCU](crud) { - console.log(crud) - console.log(crud.form) if (!crud.form.fonds.id) { this.$message({ message: '全宗不能为空', @@ -425,13 +441,22 @@ export default { }) return false } - crud.form.id = crud.form.userId + + if (crud.form.userId) { + crud.form.id = crud.form.userId + } else { + crud.form.id = null + } crud.form.roles = userRoles crud.form.posts = userPosts delete crud.form.deptsId + delete crud.form.fondsId + delete crud.form.deptId + delete crud.form.postIds + delete crud.form.roleIds delete crud.form.deptsName delete crud.form.job - return false + return true }, clickRowHandler(row) { this.$refs.table.clearSelection() @@ -443,7 +468,7 @@ export default { }, // 重置密码 pwdReset(data) { - const params = data.map(item => { return item.userName }) + const params = data.map(item => { return item.username }) this.btnLoading = true resetpassword(params).then(res => { if (res === 'SUCCESS') { @@ -453,6 +478,7 @@ export default { }) this.resetVisible = false this.btnLoading = false + this.crud.toQuery() } else { this.$message.error('重置密码失败') this.btnLoading = false @@ -473,31 +499,6 @@ export default { }) }, 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 } @@ -511,14 +512,22 @@ export default { } }) }, + // 获取弹窗内角色数据 + getRoles() { + getAll().then(res => { + this.roles = res + }).catch(() => { }) + }, + // 获取弹窗内岗位数据 + getPosts() { + getAllJob().then(res => { + this.posts = res.content + }).catch(() => { }) + }, // 切换部门 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 @@ -562,11 +571,16 @@ export default { }, changeFondsValue(value) { this.depts = [] + console.log(this.lastValue) + if (this.lastValue) { + if (value !== this.lastValue) { + this.form.dept.id = null + } + } var obj = {} obj = this.fondsOptions.find(function(item) { return item.id === value }) - this.form.deptsId = null const params = { 'fondsId': obj.id, 'fondsName': obj.fondsName, @@ -643,8 +657,12 @@ export default { type: 'warning', dangerouslyUseHTMLString: true }).then(() => { - crudUser.edit(data).then(res => { - this.crud.notify(this.dict.label.user_status[val] + '成功', CRUD.NOTIFICATION_TYPE.SUCCESS) + const params = { + 'id': data.userId, + 'enabled': !!data.enabled + } + crudUser.FetchEditUserState(params).then(res => { + this.crud.notify('修改成功', CRUD.NOTIFICATION_TYPE.SUCCESS) this.crud.refresh() }).catch(() => { data.enabled = !data.enabled @@ -654,17 +672,25 @@ export default { data.enabled = data.enabled ? 0 : 1 }) }, - // 获取弹窗内角色数据 - getRoles() { - getAll().then(res => { - this.roles = res - }).catch(() => { }) - }, - // 获取弹窗内岗位数据 - getPosts() { - getAllJob().then(res => { - this.postsOptions = res.content - }).catch(() => { }) + doExport(data) { + console.log(data) + crud.downloadLoading = true + this.$confirm('此操作将导出所选数据' + '你是否还要继续?', '提示', { + confirmButtonText: '继续', + cancelButtonText: '取消', + type: 'warning', + dangerouslyUseHTMLString: true + }).then(() => { + const ids = [] + data.forEach(val => { + ids.push(val.userId) + }) + const params = { + 'deptsIds': ids + } + exportFile(this.baseApi + '/api/users/download?' + qs.stringify(params, { indices: false })) + }).catch(() => { + }) }, checkboxT(row, rowIndex) { return row.userId !== this.user.id