Browse Source

api-部门用户

master
xuhuajiao 2 years ago
parent
commit
79a1aabb0b
  1. 13
      src/api/system/user.js
  2. 6
      src/views/system/dept/index.vue
  3. 256
      src/views/system/user/index.vue

13
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 }

6
src/views/system/dept/index.vue

@ -121,7 +121,6 @@
>
<el-table-column type="selection" align="center" width="55" />
<el-table-column label="部门名称" prop="deptsName" />
<el-table-column label="部门22" prop="hasChildren" />
<el-table-column label="部门编码" prop="deptsCode" />
<el-table-column label="部门人数" prop="deptsTotalPeoNum" />
<el-table-column label="排序" prop="deptsOrders" />
@ -484,6 +483,8 @@ export default {
},
toDelete(datas) {
this.deleteData = datas
const bool = this.deleteData.every(item => item.deptsTotalPeoNum !== 0)
if (!bool) {
this.$confirm('此操作将删除当前所选' + this.crud.title + '<span>你是否还要继续?</span>', '提示', {
confirmButtonText: '继续',
cancelButtonText: '取消',
@ -505,6 +506,9 @@ export default {
})
}).catch(() => {
})
} else {
this.crud.notify('当前选择条目中有用户存在不可直接操作删除', CRUD.NOTIFICATION_TYPE.ERROR)
}
},
//
changeStatus(data, val) {

256
src/views/system/user/index.vue

@ -29,7 +29,9 @@
<i slot="prefix" class="iconfont icon-zhuangtai" />
<el-option v-for="item in enabledTypeOptions" :key="item.key" :label="item.display_name" :value="item.key" />
</el-select>
<rrOperation />
<!-- <rrOperation /> -->
<el-button class="filter-item filter-search" size="mini" type="success" icon="el-icon-search" @click="crud.toQuery">搜索</el-button>
<el-button v-if="crud.optShow.reset" class="filter-item filter-refresh" size="mini" type="warning" icon="el-icon-refresh-left" @click="resetQuery()">重置</el-button>
</div>
<crudOperation :permission="permission">
<template v-slot:middle>
@ -38,7 +40,13 @@
删除
</el-button>
</template>
<el-button slot="right" icon="el-icon-refresh-left" size="mini" :disabled="crud.selections.length !== 1" @click="handlePwdReset(crud.selections)">密码重置</el-button>
<template v-slot:right>
<el-button :loading="crud.downloadLoading" size="mini" :disabled="crud.selections.length === 0" @click="doExport(crud.selections)">
<i class="iconfont icon-daochu" />
导出
</el-button>
<el-button icon="el-icon-refresh-left" size="mini" :disabled="crud.selections.length !== 1" @click="handlePwdReset(crud.selections)">密码重置</el-button>
</template>
</crudOperation>
</div>
<div class="container-right">
@ -46,12 +54,10 @@
<span class="left-bottom-line" />
<!--表单渲染-->
<el-dialog append-to-body :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title">
<!-- <span class="dialog-right-top" />
<span class="dialog-left-bottom" /> -->
<div class="setting-dialog">
<el-form ref="form" :inline="true" :model="form" :rules="rules" label-width="90px">
<el-form-item label="账号" prop="username">
<el-input v-model="form.username" @keydown.native="keydown($event)" />
<el-input v-model="form.username" :disabled="crud.status.edit === 1" @keydown.native="keydown($event)" />
</el-form-item>
<el-form-item label="电话" prop="phone">
<el-input v-model.number="form.phone" />
@ -64,7 +70,7 @@
</el-form-item>
<el-form-item label="所属全宗" prop="fonds.id">
<!-- <treeselect v-model="form.fondsId" :options="fondsOptions" placeholder="选择全宗" :normalizer="fondsNormalizer" @input="changeFonds" /> -->
<el-select v-model="form.fonds.id" placeholder="请选择" style="width: 225px;" @change="changeFondsValue($event)">
<el-select ref="myFondsSelect" v-model="form.fonds.id" placeholder="请选择" style="width: 225px;" @click.native="lastValue = form.fonds.id" @change="changeFondsValue($event)">
<el-option
v-for="(item,index) in fondsOptions"
:key="index"
@ -81,6 +87,7 @@
:load-options="loadDepts"
placeholder="选择部门"
:normalizer="normalizer"
:default-expand-level="levelNumber"
>
<div slot="value-label" slot-scope="{ node }">{{ getAutoNameUnknown(node.label) }}</div>
</treeselect>
@ -108,7 +115,7 @@
</el-form-item>
<el-form-item style="margin-bottom: 0;" label="岗位" prop="posts" class="is-required">
<el-select ref="paramsSelect" v-model="postDatas" style="width: 584px" multiple placeholder="请选择" @remove-tag="deleteTag" @change="changePost">
<el-option v-for="item in postsOptions" :key="item.id" :label="item.postName" :value="item.id" />
<el-option v-for="item in posts" :key="item.postName" :label="item.postName" :value="item.id" />
</el-select>
</el-form-item>
</el-form>
@ -118,19 +125,6 @@
</div>
</div>
</el-dialog>
<!-- 删除dialog -->
<!-- <el-dialog class="tip-dialog" :visible.sync="delVisible" :modal-append-to-body="false" :close-on-click-modal="false" title="提示">
<div class="setting-dialog">
<div class="tip-content">
<p class="tipMsg">此操作将删除当前所选用户</p>
<span>你是否还要继续?</span>
</div>
<div slot="footer" class="dialog-footer">
<el-button type="text" @click="delVisible = false">取消</el-button>
<el-button type="primary" @click="handleDelConfirm">继续</el-button>
</div>
</div>
</el-dialog> -->
<!-- 密码重置dialog -->
<el-dialog class="tip-dialog" :visible.sync="resetVisible" :modal-append-to-body="false" :close-on-click-modal="false" title="提示">
<div class="setting-dialog">
@ -163,11 +157,6 @@
<div>{{ scope.row.createTime | parseTime }}</div>
</template>
</el-table-column>
<!-- <el-table-column v-if="checkPer(['admin','user:edit','user:del'])" label="操作" width="120" align="center" fixed="right">
<template slot-scope="scope">
<udOperation :data="scope.row" :permission="permission" :disabled-dle="scope.row.id === user.id" />
</template>
</el-table-column> -->
</el-table>
<!--分页组件-->
<pagination />
@ -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 }
form.posts.forEach(function(job, index) {
_this.postDatas.push(job.id)
const data = { id: job.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: '全宗不能为空',
@ -425,13 +441,22 @@ export default {
})
return false
}
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('此操作将导出所选数据' + '<span>你是否还要继续?</span>', '提示', {
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

Loading…
Cancel
Save