diff --git a/src/api/system/user.ts b/src/api/system/user.ts index 7bc6464a..309a51bd 100644 --- a/src/api/system/user.ts +++ b/src/api/system/user.ts @@ -2,7 +2,7 @@ import request from "@utils/request"; export const listUser = (queryParams:any)=> { return request({ - url: '/youlai-admin/api/v1/users', + url: '/youlai-admin/api/v2/users', method: 'get', params: queryParams }) @@ -23,7 +23,7 @@ export const addUser = (data:any) => { }) } -export const updateUser = (id, data)=> { +export const updateUser = (id:number, data:any)=> { return request({ url: '/youlai-admin/api/v1/users/' + id, method: 'put', @@ -31,7 +31,7 @@ export const updateUser = (id, data)=> { }) } -export const patch = (id, data) => { +export const patch = (id:number, data:any) => { return request({ url: '/youlai-admin/api/v1/users/' + id, method: 'patch', @@ -39,7 +39,7 @@ export const patch = (id, data) => { }) } -export const delUser = (ids) =>{ +export const delUser =(ids:number) =>{ return request({ url: '/youlai-admin/api/v1/users/'+ids, method: 'delete', diff --git a/src/store/modules/user.ts b/src/store/modules/user.ts index 8ef73c46..b03b401e 100644 --- a/src/store/modules/user.ts +++ b/src/store/modules/user.ts @@ -85,6 +85,7 @@ const userModule: Module = { if (!data) { return reject('Verification failed, please Login again.') } + console.log(data) const {nickname, avatar, roles, perms} = data if (!roles || roles.length <= 0) { reject('getUserInfo: roles must be a non-null array!') diff --git a/src/views/system/user/index.vue b/src/views/system/user/index.vue index 0173cce8..54264442 100644 --- a/src/views/system/user/index.vue +++ b/src/views/system/user/index.vue @@ -3,7 +3,7 @@
@@ -30,7 +30,7 @@ - - - - - - 搜索 @@ -136,7 +111,7 @@ @@ -147,7 +122,7 @@ - - - + @@ -246,40 +216,41 @@ label="创建时间" align="center" prop="gmtCreate" - width="120" + width="180" > @@ -313,10 +284,10 @@ @@ -332,8 +303,6 @@ placeholder="请选择归属部门" :originOptions="originOptions" :defalut="formVal.deptId" - :accordion="isAccordion" - @getValue="getParentValue($event)" :user="true" @callBack="getDeptId" /> @@ -344,10 +313,10 @@ @@ -374,14 +343,14 @@ prop="userName" > @@ -397,14 +366,14 @@ @@ -424,23 +393,6 @@ - - - - - - - @@ -497,7 +449,8 @@ import { listUser, getUser, delUser, addUser, updateUser,patch } from '@/api/sys import {getDeptSelectList} from '@/api/system/dept' import Treeselect from '@/components/TreeSelect/Index.vue' - +import {listRoles} from '@/api/system/role' +import {Search, Plus, Edit, Refresh, Delete} from '@element-plus/icons' import {defineComponent, reactive, toRefs, ref, unref, onMounted, watchEffect, getCurrentInstance} from 'vue' import { ElMessage, ElMessageBox, ElTree, ElUpload } from 'element-plus' @@ -544,7 +497,7 @@ export default defineComponent({ // 部门名称 deptName: '', // 默认密码 - initPassword: '', + initPassword: '123456', // 日期范围 dateRange: [], // 状态数据字典 @@ -560,25 +513,22 @@ export default defineComponent({ ], // 性别状态字典 sexOptions: [], - // 岗位选项 - postOptions: [], // 角色选项 roleOptions: [], // 表单参数 formVal: { - userId: undefined, + id: undefined, deptId: '', - userName: undefined, - nickName: undefined, + username: undefined, + nickname: undefined, password: '', - phonenumber: undefined, + mobile: undefined, email: undefined, - sex: undefined, - status: '1', + gender: undefined, + status: 1, remark: undefined, postIds: [], roleIds: [] - }, defaultProps: { children: 'children', @@ -588,8 +538,8 @@ export default defineComponent({ queryParams: { page: 1, limit: 10, - userName: undefined, - phonenumber: undefined, + keywords: undefined, + mobile: undefined, status: undefined, deptId: undefined }, @@ -660,7 +610,7 @@ export default defineComponent({ return result } /** 查询部门下拉树结构 */ - const getTreeselect = () => { + const loadDeptOptions = () => { getDeptSelectList().then(response => { dataMap.deptOptions = response.data dataMap.originOptions = flatten(response?.data) as any @@ -679,9 +629,7 @@ export default defineComponent({ } // 用户状态修改 const handleStatusChange = (row: {[key: string]: any}) => { - console.log(row.status) - if (!dataMap.tigger) { - console.log(row.status) + if (dataMap.tigger) { const text = row.status === '1' ? '启用' : '停用' ElMessageBox.confirm('确认要"' + text +'""'+ row.username + '"用户吗?', '警告', { confirmButtonText: '确定', @@ -709,10 +657,9 @@ export default defineComponent({ handleQuery() } - // 多选框选中数据 const handleSelectionChange = (selection: any) => { - dataMap.ids = selection.map((item: any) => item.userId) + dataMap.ids = selection.map((item: any) => item.id) dataMap.single = selection.length !== 1 dataMap.multiple = !selection.length } @@ -720,63 +667,40 @@ export default defineComponent({ const handleAdd = () => { console.log(dataMap.formVal) dataMap.addformFlag = true - dataMap.formVal = { - userId: undefined, - deptId: '103', - userName: undefined, - nickName: undefined, - password: '', - phonenumber: undefined, - email: undefined, - sex: undefined, - status: '1', - remark: undefined, - postIds: [], - roleIds: [] - } + resetForm() dataMap.originOptions = [] - getTreeselect() - getUser().then(response => { - dataMap.postOptions = response.posts - dataMap.roleOptions = response.roles - dataMap.open = true - dataMap.title = '添加用户' - dataMap.formVal.password = dataMap.initPassword - }) + // loadDeptOptions() + dataMap.open = true + dataMap.title = '添加用户' + dataMap.formVal.password = "123456" } // 表单重置 const resetForm = ()=> { - dataMap.formVal= { - userId: undefined, - deptId: '', - userName: undefined, - nickName: undefined, - password: '', - phonenumber: undefined, - email: undefined, - sex: undefined, - status: '1', - remark: undefined, - postIds: [], - roleIds: [] - - } - if (this.$refs['form']) { - this.$refs['form'].resetFields() + dataMap.formVal= { + id: undefined, + deptId: '', + username: undefined, + nickname: undefined, + password: '', + mobile: undefined, + email: undefined, + gender: undefined, + status: 1, + remark: undefined, + postIds: [], + roleIds: [] } } /** 修改按钮操作 */ const handleUpdate = (row: {[key: string]: any}) => { - this.resetForm() - const userId = row.userId || dataMap.ids + resetForm() + const userId = row.id || dataMap.ids getUser(userId).then(response => { dataMap.formVal = response.data - dataMap.postOptions = response.posts - dataMap.roleOptions = response.roles - dataMap.formVal.postIds = response.postIds - dataMap.formVal.roleIds = response.roleIds + // dataMap.formVal.postIds = response.postIds + // dataMap.formVal.roleIds = response.roleIds dataMap.open = true dataMap.title = '修改用户' dataMap.formVal.password = '' @@ -799,14 +723,14 @@ export default defineComponent({ }).then(() => { ElMessage.success('修改成功,新密码是:' + value) }) - }).catch((err) => console.log(err)) + }).catch((err) => {}) } /** 提交按钮 */ const submitForm = () => { (queryForm.value as any).validate((valid: any) => { if (valid) { - if (dataMap.formVal.userId !== undefined) { - updateUser(dataMap.formVal).then(() => { + if (dataMap.formVal.id !== undefined) { + updateUser(dataMap.formVal.id,dataMap.formVal).then(() => { ElMessage.success('修改成功') dataMap.open = false getList() @@ -823,7 +747,7 @@ export default defineComponent({ } /** 删除按钮操作 */ const handleDelete = (row: {[key: string]: any}) => { - const userIds = row.userId || dataMap.ids.join(',') + const userIds = row.id || dataMap.ids.join(',') ElMessageBox.confirm('是否确认删除用户编号为"' + userIds + '"的数据项?', '警告', { confirmButtonText: '确定', cancelButtonText: '取消', @@ -837,13 +761,11 @@ export default defineComponent({ ElMessage.info('已取消删除') ) } - - -// 取消按钮 + // 取消按钮 function cancel() { - dataMap.loading = true dataMap.tigger = true - this.resetForm() + dataMap.open = false + resetForm() } const getParentValue = (event: any) => { @@ -860,28 +782,27 @@ export default defineComponent({ tree.filter(dataMap.deptName) } }) + const loadRoleOptions = async ()=> { + listRoles({}).then(response => { + dataMap.roleOptions = response.data + console.log(response.data) + }) + } + onMounted(() => { getList() - getTreeselect() - // const {proxy}: any = getCurrentInstance(); - // proxy.$getDictItemsByCode('gender').then((response: any) => { - // console.log('性别字典数据', response.data) - // }) - // getDicts('sys_normal_disable').then(response => { - // dataMap.statusOptions = response?.data - // }) - // getDicts('sys_user_sex').then(response => { - // dataMap.sexOptions = response?.data - // }) - // getConfigKey('sys.user.initPassword').then(response => { - // dataMap.initPassword = String(response?.msg) - // }) + loadDeptOptions() + loadRoleOptions() + const {proxy}: any = getCurrentInstance(); + proxy.$getDictItemsByCode('gender').then((response: any) => { + dataMap.sexOptions = response?.data + }) }) const showDialog = () => { - getTreeselect() + loadDeptOptions() } - return { ...toRefs(dataMap), uploadRef, getDeptId, getParentValue, resetForm, addForm, showDialog, flatten, queryForm, treeRef, handleQuery, handleStatusChange, handleNodeClick, filterNode, getTreeselect, getList, resetQuery, handleAdd, handleSelectionChange, handleUpdate, handleResetPwd, submitForm, handleDelete,cancel } + return { ...toRefs(dataMap), uploadRef, getDeptId, getParentValue, resetForm, addForm, showDialog, flatten, queryForm, treeRef, handleQuery, handleStatusChange, handleNodeClick, filterNode, loadDeptOptions, getList, resetQuery, handleAdd, handleSelectionChange, handleUpdate, handleResetPwd, submitForm, handleDelete,cancel,Search, Plus, Edit, Refresh, Delete } } })