用户管理

This commit is contained in:
yl 2023-03-07 22:34:07 +08:00 committed by yovinchen
parent d063d67d5a
commit 44ca241b0c
3 changed files with 73 additions and 126 deletions

View File

@ -1,21 +1,9 @@
import request from '@/utils/request' import request from '@/utils/request'
/**
* 用户管理相关的API请求函数
*
* @type {string}
*/
const api_name = '/admin/system/sysUser' const api_name = '/admin/system/sysUser'
export default { export default {
/**
* 用户条件分页查询
*
* @param page
* @param limit
* @param searchObj
* @returns {AxiosPromise}
*/
getPageList(page, limit, searchObj) { getPageList(page, limit, searchObj) {
return request({ return request({
url: `${api_name}/${page}/${limit}`, url: `${api_name}/${page}/${limit}`,
@ -23,24 +11,13 @@ export default {
params: searchObj // url查询字符串或表单键值对 params: searchObj // url查询字符串或表单键值对
}) })
}, },
/**
* 获取用户
*
* @param id
* @returns {AxiosPromise}
*/
getById(id) { getById(id) {
return request({ return request({
url: `${api_name}/get/${id}`, url: `${api_name}/get/${id}`,
method: 'get' method: 'get'
}) })
}, },
/**
* 保存用户
*
* @param role
* @returns {AxiosPromise}
*/
save(role) { save(role) {
return request({ return request({
url: `${api_name}/save`, url: `${api_name}/save`,
@ -48,12 +25,7 @@ export default {
data: role data: role
}) })
}, },
/**
* 更新用户
*
* @param role
* @returns {AxiosPromise}
*/
updateById(role) { updateById(role) {
return request({ return request({
url: `${api_name}/update`, url: `${api_name}/update`,
@ -61,29 +33,10 @@ export default {
data: role data: role
}) })
}, },
/**
* 删除用户
*
* @param id
* @returns {AxiosPromise}
*/
removeById(id) { removeById(id) {
return request({ return request({
url: `${api_name}/remove/${id}`, url: `${api_name}/remove/${id}`,
method: 'delete' method: 'delete'
}) })
},
/**
* 更新用户状态
*
* @param id
* @param status
* @returns {AxiosPromise}
*/
updateStatus(id, status) {
return request({
url: `${api_name}/updateStatus/${id}/${status}`,
method: 'get'
})
} }
} }

View File

@ -64,6 +64,15 @@ export const constantRoutes = [
}, },
alwaysShow: true, alwaysShow: true,
children: [ children: [
{
name: 'sysUser',
path: 'sysUser',
component: () => import('@/views/system/sysUser/list'),
meta: {
title: '用户管理',
icon: 'el-icon-s-custom'
},
},
{ {
path: 'sysRole', path: 'sysRole',
component: () => import('@/views/system/sysRole/list'), component: () => import('@/views/system/sysRole/list'),

View File

@ -6,59 +6,58 @@
<el-row> <el-row>
<el-col :span="8"> <el-col :span="8">
<el-form-item label="关 键 字"> <el-form-item label="关 键 字">
<el-input v-model="searchObj.keyword" placeholder="用户名/姓名/手机号码" style="width: 95%" /> <el-input style="width: 95%" v-model="searchObj.keyword" placeholder="用户名/姓名/手机号码"></el-input>
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col :span="8"> <el-col :span="8">
<el-form-item label="操作时间"> <el-form-item label="操作时间">
<el-date-picker <el-date-picker
v-model="createTimes" v-model="createTimes"
end-placeholder="结束时间" type="datetimerange"
range-separator="至" range-separator="至"
start-placeholder="开始时间" start-placeholder="开始时间"
style="margin-right: 10px;width: 100%;" end-placeholder="结束时间"
type="datetimerange"
value-format="yyyy-MM-dd HH:mm:ss" value-format="yyyy-MM-dd HH:mm:ss"
style="margin-right: 10px;width: 100%;"
/> />
</el-form-item> </el-form-item>
</el-col> </el-col>
</el-row> </el-row>
<el-row style="display:flex"> <el-row style="display:flex">
<el-button :loading="loading" icon="el-icon-search" size="mini" type="primary" @click="fetchData()">搜索 <el-button type="primary" icon="el-icon-search" size="mini" :loading="loading" @click="fetchData()">搜索</el-button>
</el-button>
<el-button icon="el-icon-refresh" size="mini" @click="resetData">重置</el-button> <el-button icon="el-icon-refresh" size="mini" @click="resetData">重置</el-button>
<!-- 工具条 --> <el-button type="success" icon="el-icon-plus" size="mini" @click="add"> </el-button>
<!-- <div class="tools-div">-->
<el-button icon="el-icon-plus" size="mini" type="success" @click="add"> </el-button>
<!-- </div>-->
</el-row> </el-row>
</el-form> </el-form>
</div> </div>
<!-- 工具条 -->
<!-- <div class="tools-div">-->
<!-- <el-button type="success" icon="el-icon-plus" size="mini" @click="add"> </el-button>-->
<!-- </div>-->
<!-- 列表 --> <!-- 列表 -->
<el-table <el-table
v-loading="listLoading" v-loading="listLoading"
:data="list" :data="list"
border
stripe stripe
style="width: 100%;margin-top: 10px;" border
> style="width: 100%;margin-top: 10px;">
<el-table-column <el-table-column
align="center"
label="序号" label="序号"
width="70" width="70"
> align="center">
<template slot-scope="scope"> <template slot-scope="scope">
{{ (page - 1) * limit + scope.$index + 1 }} {{ (page - 1) * limit + scope.$index + 1 }}
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="用户名" prop="username" width="100" /> <el-table-column prop="username" label="用户名" width="100"/>
<el-table-column label="姓名" prop="name" width="70" /> <el-table-column prop="name" label="姓名" width="70"/>
<el-table-column label="手机" prop="phone" width="120" /> <el-table-column prop="phone" label="手机" width="120"/>
<el-table-column label="岗位" prop="postName" width="100" /> <el-table-column prop="postName" label="岗位" width="100"/>
<el-table-column label="部门" prop="deptName" width="100" /> <el-table-column prop="deptName" label="部门" width="100"/>
<el-table-column label="所属角色" width="130"> <el-table-column label="所属角色" width="130">
<template slot-scope="scope"> <template slot-scope="scope">
<span v-for="item in scope.row.roleList" :key="item.id" style="margin-right: 10px;">{{ item.roleName }}</span> <span v-for="item in scope.row.roleList" :key="item.id" style="margin-right: 10px;">{{ item.roleName }}</span>
@ -68,29 +67,17 @@
<template slot-scope="scope"> <template slot-scope="scope">
<el-switch <el-switch
v-model="scope.row.status === 1" v-model="scope.row.status === 1"
@change="switchStatus(scope.row)" @change="switchStatus(scope.row)">
/> </el-switch>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="创建时间" prop="createTime" width="160" /> <el-table-column prop="createTime" label="创建时间" width="160"/>
<el-table-column align="center" fixed="right" label="操作" width="180"> <el-table-column label="操作" width="180" align="center" fixed="right">
<template slot-scope="scope"> <template slot-scope="scope">
<el-button icon="el-icon-edit" size="mini" title="修改" type="primary" @click="edit(scope.row.id)" /> <el-button type="primary" icon="el-icon-edit" size="mini" @click="edit(scope.row.id)" title="修改"/>
<el-button <el-button type="danger" icon="el-icon-delete" size="mini" @click="removeDataById(scope.row.id)" title="删除" />
icon="el-icon-delete" <el-button type="warning" icon="el-icon-baseball" size="mini" @click="showAssignRole(scope.row)" title="分配角色"/>
size="mini"
title="删除"
type="danger"
@click="removeDataById(scope.row.id)"
/>
<el-button
icon="el-icon-baseball"
size="mini"
title="分配角色"
type="warning"
@click="showAssignRole(scope.row)"
/>
</template> </template>
</el-table-column> </el-table-column>
</el-table> </el-table>
@ -98,54 +85,53 @@
<!-- 分页组件 --> <!-- 分页组件 -->
<el-pagination <el-pagination
:current-page="page" :current-page="page"
:total="total"
:page-size="limit" :page-size="limit"
:page-sizes="[5, 10, 20, 30, 40, 50, 100]" :page-sizes="[5, 10, 20, 30, 40, 50, 100]"
:total="total"
layout="sizes, prev, pager, next, jumper, ->, total, slot"
style="padding: 30px 0; text-align: center;" style="padding: 30px 0; text-align: center;"
layout="sizes, prev, pager, next, jumper, ->, total, slot"
@current-change="fetchData" @current-change="fetchData"
@size-change="changeSize" @size-change="changeSize"
/> />
<el-dialog :visible.sync="dialogVisible" title="添加/修改" width="40%"> <el-dialog title="添加/修改" :visible.sync="dialogVisible" width="40%" >
<el-form ref="dataForm" :model="sysUser" label-width="100px" size="small" style="padding-right: 40px;"> <el-form ref="dataForm" :model="sysUser" label-width="100px" size="small" style="padding-right: 40px;">
<el-form-item label="用户名" prop="username"> <el-form-item label="用户名" prop="username">
<el-input v-model="sysUser.username" /> <el-input v-model="sysUser.username"/>
</el-form-item> </el-form-item>
<el-form-item v-if="!sysUser.id" label="密码" prop="password"> <el-form-item v-if="!sysUser.id" label="密码" prop="password">
<el-input v-model="sysUser.password" type="password" /> <el-input v-model="sysUser.password" type="password"/>
</el-form-item> </el-form-item>
<el-form-item label="姓名" prop="name"> <el-form-item label="姓名" prop="name">
<el-input v-model="sysUser.name" /> <el-input v-model="sysUser.name"/>
</el-form-item> </el-form-item>
<el-form-item label="手机" prop="phone"> <el-form-item label="手机" prop="phone">
<el-input v-model="sysUser.phone" /> <el-input v-model="sysUser.phone"/>
</el-form-item> </el-form-item>
</el-form> </el-form>
<span slot="footer" class="dialog-footer"> <span slot="footer" class="dialog-footer">
<el-button icon="el-icon-refresh-right" size="small" @click="dialogVisible = false"> </el-button> <el-button @click="dialogVisible = false" size="small" icon="el-icon-refresh-right"> </el-button>
<el-button icon="el-icon-check" size="small" type="primary" @click="saveOrUpdate()"> </el-button> <el-button type="primary" icon="el-icon-check" @click="saveOrUpdate()" size="small"> </el-button>
</span> </span>
</el-dialog> </el-dialog>
<el-dialog :visible.sync="dialogRoleVisible" title="分配角色"> <el-dialog title="分配角色" :visible.sync="dialogRoleVisible">
<el-form label-width="80px"> <el-form label-width="80px">
<el-form-item label="用户名"> <el-form-item label="用户名">
<el-input :value="sysUser.username" disabled /> <el-input disabled :value="sysUser.username"></el-input>
</el-form-item> </el-form-item>
<el-form-item label="角色列表"> <el-form-item label="角色列表">
<el-checkbox v-model="checkAll" :indeterminate="isIndeterminate" @change="handleCheckAllChange">全选 <el-checkbox :indeterminate="isIndeterminate" v-model="checkAll" @change="handleCheckAllChange">全选</el-checkbox>
</el-checkbox> <div style="margin: 15px 0;"></div>
<div style="margin: 15px 0;" />
<el-checkbox-group v-model="userRoleIds" @change="handleCheckedChange"> <el-checkbox-group v-model="userRoleIds" @change="handleCheckedChange">
<el-checkbox v-for="role in allRoles" :key="role.id" :label="role.id">{{ role.roleName }}</el-checkbox> <el-checkbox v-for="role in allRoles" :key="role.id" :label="role.id">{{role.roleName}}</el-checkbox>
</el-checkbox-group> </el-checkbox-group>
</el-form-item> </el-form-item>
</el-form> </el-form>
<div slot="footer"> <div slot="footer">
<el-button size="small" type="primary" @click="assignRole">保存</el-button> <el-button type="primary" @click="assignRole" size="small">保存</el-button>
<el-button size="small" @click="dialogRoleVisible = false">取消</el-button> <el-button @click="dialogRoleVisible = false" size="small">取消</el-button>
</div> </div>
</el-dialog> </el-dialog>
</div> </div>
@ -154,7 +140,6 @@
<script> <script>
import api from '@/api/system/sysUser' import api from '@/api/system/sysUser'
import roleApi from '@/api/system/sysRole' import roleApi from '@/api/system/sysRole'
const defaultForm = { const defaultForm = {
id: '', id: '',
username: '', username: '',
@ -193,7 +178,7 @@ export default {
this.fetchData() this.fetchData()
roleApi.findAll().then(response => { roleApi.findAll().then(response => {
this.roleList = response.data this.roleList = response.data;
}) })
}, },
@ -212,18 +197,18 @@ export default {
// banner // banner
fetchData(page = 1) { fetchData(page = 1) {
// debugger debugger
this.page = page this.page = page
console.log('翻页。。。' + this.page) console.log('翻页。。。' + this.page)
if (this.createTimes && this.createTimes.length === 2) { if(this.createTimes && this.createTimes.length ==2) {
this.searchObj.createTimeBegin = this.createTimes[0] this.searchObj.createTimeBegin = this.createTimes[0]
this.searchObj.createTimeEnd = this.createTimes[1] this.searchObj.createTimeEnd = this.createTimes[1]
} }
api.getPageList(this.page, this.limit, this.searchObj).then( api.getPageList(this.page, this.limit, this.searchObj).then(
response => { response => {
// this.list = response.data.list //this.list = response.data.list
this.list = response.data.records this.list = response.data.records
this.total = response.data.total this.total = response.data.total
@ -252,7 +237,7 @@ export default {
// ajax // ajax
return api.removeById(id) return api.removeById(id)
}).then((response) => { }).then((response) => {
this.fetchData(this.page) this.fetchData()
this.$message.success(response.message || '删除成功') this.$message.success(response.message || '删除成功')
}).catch(() => { }).catch(() => {
this.$message.info('取消删除') this.$message.info('取消删除')
@ -260,7 +245,7 @@ export default {
}, },
// ------------- // -------------
add() { add(){
this.dialogVisible = true this.dialogVisible = true
this.sysUser = Object.assign({}, defaultForm) this.sysUser = Object.assign({}, defaultForm)
}, },
@ -307,26 +292,26 @@ export default {
}) })
}, },
showAssignRole(row) { showAssignRole (row) {
this.sysUser = row this.sysUser = row
this.dialogRoleVisible = true this.dialogRoleVisible = true
this.getRoles() this.getRoles()
}, },
getRoles() { getRoles () {
roleApi.getRoles(this.sysUser.id).then(response => { roleApi.getRoles(this.sysUser.id).then(response => {
const { allRolesList, assginRoleList } = response.data const {allRolesList, assginRoleList} = response.data
this.allRoles = allRolesList this.allRoles = allRolesList
this.userRoleIds = assginRoleList.map(item => item.id) this.userRoleIds = assginRoleList.map(item => item.id)
this.checkAll = allRolesList.length === assginRoleList.length this.checkAll = allRolesList.length===assginRoleList.length
this.isIndeterminate = assginRoleList.length > 0 && assginRoleList.length < allRolesList.length this.isIndeterminate = assginRoleList.length>0 && assginRoleList.length<allRolesList.length
}) })
}, },
/* /*
全选勾选状态发生改变的监听 全选勾选状态发生改变的监听
*/ */
handleCheckAllChange(value) { // value true/false handleCheckAllChange (value) {// value true/false
// , userRoleIdsid, // , userRoleIdsid,
this.userRoleIds = value ? this.allRoles.map(item => item.id) : [] this.userRoleIds = value ? this.allRoles.map(item => item.id) : []
// , false // , false
@ -336,14 +321,14 @@ export default {
/* /*
角色列表选中项发生改变的监听 角色列表选中项发生改变的监听
*/ */
handleCheckedChange(value) { handleCheckedChange (value) {
const { userRoleIds, allRoles } = this const {userRoleIds, allRoles} = this
this.checkAll = userRoleIds.length === allRoles.length && allRoles.length > 0 this.checkAll = userRoleIds.length === allRoles.length && allRoles.length>0
this.isIndeterminate = userRoleIds.length > 0 && userRoleIds.length < allRoles.length this.isIndeterminate = userRoleIds.length>0 && userRoleIds.length<allRoles.length
}, },
assignRole() { assignRole () {
const assginRoleVo = { let assginRoleVo = {
userId: this.sysUser.id, userId: this.sysUser.id,
roleIdList: this.userRoleIds roleIdList: this.userRoleIds
} }