!2 功能变化(用户管理):增加关联角色列;

* 功能变化(用户管理):增加关联角色列;
pull/3/head
xt12321 2021-03-27 20:26:55 +08:00 committed by 李强
parent 9c5a931e6d
commit 0384353ad9
1 changed files with 376 additions and 342 deletions

View File

@ -91,7 +91,8 @@
size="mini"
@click="handleAdd"
v-hasPermi="['permission:user:post']"
>新增</el-button>
>新增
</el-button>
</el-col>
<el-col :span="1.5">
<el-button
@ -102,7 +103,8 @@
:disabled="single"
@click="handleUpdate"
v-hasPermi="['permission:user:{id}:put']"
>修改</el-button>
>修改
</el-button>
</el-col>
<el-col :span="1.5">
<el-button
@ -113,7 +115,8 @@
:disabled="multiple"
@click="handleDelete"
v-hasPermi="['permission:user:{id}:delete']"
>删除</el-button>
>删除
</el-button>
</el-col>
<el-col :span="1.5">
<el-button
@ -123,7 +126,8 @@
size="mini"
@click="handleImport"
v-hasPermi="['permission:user:import:post']"
>导入</el-button>
>导入
</el-button>
</el-col>
<el-col :span="1.5">
<el-button
@ -133,19 +137,42 @@
size="mini"
@click="handleExport"
v-hasPermi="['permission:user:export:get']"
>导出</el-button>
>导出
</el-button>
</el-col>
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList" :columns="columns"></right-toolbar>
</el-row>
<el-table v-loading="loading" :data="userList" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="50" align="center" />
<el-table-column label="用户编号" align="center" key="id" prop="id" v-if="columns[0].visible" />
<el-table-column label="用户名称" align="center" key="username" prop="username" v-if="columns[1].visible" :show-overflow-tooltip="true" />
<el-table-column label="用户昵称" align="center" key="name" prop="name" v-if="columns[2].visible" :show-overflow-tooltip="true" />
<el-table-column label="部门" align="center" key="deptName" prop="dept.deptName" v-if="columns[3].visible" :show-overflow-tooltip="true" />
<el-table-column label="手机号码" align="center" key="mobile" prop="mobile" v-if="columns[4].visible" width="120" />
<el-table-column label="状态" align="center" key="is_active" v-if="columns[5].visible">
<el-table-column type="selection" width="50" align="center"/>
<el-table-column label="用户编号" align="center" key="id" prop="id" v-if="columns[0].visible"/>
<el-table-column label="用户名称" align="center" key="username" prop="username" v-if="columns[1].visible"
:show-overflow-tooltip="true"/>
<el-table-column label="用户昵称" align="center" key="name" prop="name" v-if="columns[2].visible"
:show-overflow-tooltip="true"/>
<el-table-column label="部门" align="center" key="deptName" prop="dept.deptName" v-if="columns[3].visible"
:show-overflow-tooltip="true"/>
<el-table-column label="关联角色" align="center" key="role" prop="dept.role" v-if="columns[4].visible"
:show-overflow-tooltip="true">
<template slot-scope="scope">
<template v-if="scope.row.role.length > 0">
<el-dropdown>
<span class="el-dropdown-link">{{scope.row.role[0].roleName}}
<i class="el-icon-arrow-down el-icon--right"></i>
</span>
<el-dropdown-menu slot="dropdown">
<el-dropdown-item v-for="role in scope.row.role">{{role.roleName}}</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
</template>
<template v-else>
<span>暂无关联角色</span>
</template>
</template>
</el-table-column>
<el-table-column label="手机号码" align="center" key="mobile" prop="mobile" v-if="columns[5].visible"
width="120"/>
<el-table-column label="状态" align="center" key="is_active" v-if="columns[6].visible">
<template slot-scope="scope">
<el-switch
v-model="scope.row.is_active"
@ -154,7 +181,7 @@
></el-switch>
</template>
</el-table-column>
<el-table-column label="创建时间" align="center" prop="create_datetime" v-if="columns[6].visible" width="160">
<el-table-column label="创建时间" align="center" prop="create_datetime" v-if="columns[7].visible" width="160">
<template slot-scope="scope">
<span>{{ parseTime(scope.row.create_datetime) }}</span>
</template>
@ -173,7 +200,8 @@
icon="el-icon-edit"
@click="handleUpdate(scope.row)"
v-hasPermi="['permission:user:{id}:put']"
>修改</el-button>
>修改
</el-button>
<el-button
v-if="scope.row.id !== 1"
size="mini"
@ -181,14 +209,16 @@
icon="el-icon-delete"
@click="handleDelete(scope.row)"
v-hasPermi="['permission:user:{id}:delete']"
>删除</el-button>
>删除
</el-button>
<el-button
size="mini"
type="text"
icon="el-icon-key"
@click="handleResetPwd(scope.row)"
v-hasPermi="['permission:user:resetpwd:put']"
>重置</el-button>
>重置
</el-button>
</template>
</el-table-column>
</el-table>
@ -209,36 +239,36 @@
<el-row>
<el-col :span="12">
<el-form-item label="用户昵称" prop="name">
<el-input v-model="form.name" placeholder="请输入用户昵称" />
<el-input v-model="form.name" placeholder="请输入用户昵称"/>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="归属部门" prop="deptId">
<treeselect v-model="form.deptId" :options="deptOptions" :show-count="true" placeholder="请选择归属部门" />
<treeselect v-model="form.deptId" :options="deptOptions" :show-count="true" placeholder="请选择归属部门"/>
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col :span="12">
<el-form-item label="手机号码" prop="mobile">
<el-input v-model="form.mobile" placeholder="请输入手机号码" maxlength="11" />
<el-input v-model="form.mobile" placeholder="请输入手机号码" maxlength="11"/>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="邮箱" prop="email">
<el-input v-model="form.email" placeholder="请输入邮箱" maxlength="50" />
<el-input v-model="form.email" placeholder="请输入邮箱" maxlength="50"/>
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col :span="12">
<el-form-item v-if="form.id == undefined" label="用户名称" prop="username">
<el-input v-model="form.username" placeholder="请输入用户名称" />
<el-input v-model="form.username" placeholder="请输入用户名称"/>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item v-if="form.id == undefined" label="用户密码" prop="password">
<el-input v-model="form.password" placeholder="请输入用户密码" type="password" />
<el-input v-model="form.password" placeholder="请输入用户密码" type="password"/>
</el-form-item>
</el-col>
</el-row>
@ -262,7 +292,8 @@
v-for="dict in statusOptions"
:key="dict.dictValue"
:label="dict.dictValue"
>{{dict.dictLabel}}</el-radio>
>{{dict.dictLabel}}
</el-radio>
</el-radio-group>
</el-form-item>
</el-col>
@ -329,7 +360,8 @@
<em>点击上传</em>
</div>
<div class="el-upload__tip" slot="tip">
<el-checkbox v-model="upload.updateSupport" />是否更新已经存在的用户数据
<el-checkbox v-model="upload.updateSupport"/>
是否更新已经存在的用户数据
<el-link type="info" style="font-size:12px" @click="importTemplate"></el-link>
</div>
<div class="el-upload__tip" style="color:red" slot="tip">提示仅允许导入xlsxlsx格式文件</div>
@ -354,338 +386,340 @@
listUser,
resetUserPwd,
updateUser
} from "@/api/vadmin/permission/user";
import {getToken} from "@/utils/auth";
import {treeselect} from "@/api/vadmin/permission/dept";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
} from '@/api/vadmin/permission/user'
import { getToken } from '@/utils/auth'
import { treeselect } from '@/api/vadmin/permission/dept'
import Treeselect from '@riophae/vue-treeselect'
import '@riophae/vue-treeselect/dist/vue-treeselect.css'
export default {
name: "User",
components: { Treeselect },
data() {
return {
//
loading: true,
//
ids: [],
//
single: true,
//
multiple: true,
//
showSearch: true,
//
total: 0,
//
userList: null,
//
title: "",
//
deptOptions: undefined,
//
open: false,
//
deptName: undefined,
//
initPassword: undefined,
//
dateRange: [],
//
statusOptions: [{dictLabel: '正常', dictValue: true,}, {dictLabel: '停用', dictValue: false,}],
//
sexOptions: [],
//
postOptions: [],
//
roleOptions: [],
//
form: {},
defaultProps: {
children: "children",
label: "label"
},
//
upload: {
//
name: 'User',
components: { Treeselect },
data() {
return {
//
loading: true,
//
ids: [],
//
single: true,
//
multiple: true,
//
showSearch: true,
//
total: 0,
//
userList: null,
//
title: '',
//
deptOptions: undefined,
//
open: false,
//
title: "",
//
isUploading: false,
//
updateSupport: 0,
//
headers: { Authorization: "Bearer " + getToken() },
//
url: process.env.VUE_APP_BASE_API + "/admin/system/savefile/"
},
//
queryParams: {
pageNum: 1,
pageSize: 10,
username: undefined,
mobile: undefined,
is_active: undefined,
deptId: undefined
},
//
columns: [
{ key: 0, label: `用户编号`, visible: true },
{ key: 1, label: `用户名称`, visible: true },
{ key: 2, label: `用户昵称`, visible: true },
{ key: 3, label: `部门`, visible: true },
{ key: 4, label: `手机号码`, visible: true },
{ key: 5, label: `状态`, visible: true },
{ key: 6, label: `创建时间`, visible: true }
],
//
rules: {
username: [
{ required: true, message: "用户名称不能为空", trigger: "blur" }
//
deptName: undefined,
//
initPassword: undefined,
//
dateRange: [],
//
statusOptions: [{ dictLabel: '正常', dictValue: true }, { dictLabel: '停用', dictValue: false }],
//
sexOptions: [],
//
postOptions: [],
//
roleOptions: [],
//
form: {},
defaultProps: {
children: 'children',
label: 'label'
},
//
upload: {
//
open: false,
//
title: '',
//
isUploading: false,
//
updateSupport: 0,
//
headers: { Authorization: 'Bearer ' + getToken() },
//
url: process.env.VUE_APP_BASE_API + '/admin/system/savefile/'
},
//
queryParams: {
pageNum: 1,
pageSize: 10,
username: undefined,
mobile: undefined,
is_active: undefined,
deptId: undefined
},
//
columns: [
{ key: 0, label: `用户编号`, visible: true },
{ key: 1, label: `用户名称`, visible: true },
{ key: 2, label: `用户昵称`, visible: true },
{ key: 3, label: `部门`, visible: true },
{ key: 4, label: `关联角色`, visible: true },
{ key: 5, label: `手机号码`, visible: true },
{ key: 6, label: `状态`, visible: true },
{ key: 7, label: `创建时间`, visible: true }
],
name: [
{ required: true, message: "用户昵称不能为空", trigger: "blur" }
],
password: [
{ required: true, message: "用户密码不能为空", trigger: "blur" }
],
email: [
{
type: "email",
message: "'请输入正确的邮箱地址",
trigger: ["blur", "change"]
}
],
mobile: [
{
pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
message: "请输入正确的手机号码",
trigger: "blur"
}
]
//
rules: {
username: [
{ required: true, message: '用户名称不能为空', trigger: 'blur' }
],
name: [
{ required: true, message: '用户昵称不能为空', trigger: 'blur' }
],
password: [
{ required: true, message: '用户密码不能为空', trigger: 'blur' }
],
email: [
{
type: 'email',
message: '\'请输入正确的邮箱地址',
trigger: ['blur', 'change']
}
],
mobile: [
{
pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
message: '请输入正确的手机号码',
trigger: 'blur'
}
]
}
}
};
},
watch: {
//
deptName(val) {
this.$refs.tree.filter(val);
}
},
created() {
this.getList();
this.getTreeselect();
// this.getDicts("sys_normal_disable").then(response => {
// this.statusOptions = response.data;
// });
this.getDicts("sys_user_sex").then(response => {
this.sexOptions = response.data;
});
this.getConfigKey("sys.user.initPassword").then(response => {
this.initPassword = response.msg;
});
},
methods: {
/** 查询用户列表 */
getList() {
this.loading = true;
listUser(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
this.userList = response.data.results;
this.total = response.data.count;
this.loading = false;
}
);
},
/** 查询部门下拉树结构 */
getTreeselect() {
treeselect().then(response => {
this.deptOptions = this.handleTree(response.data,'id');
});
watch: {
//
deptName(val) {
this.$refs.tree.filter(val)
}
},
//
filterNode(value, data) {
if (!value) return true;
return data.label.indexOf(value) !== -1;
created() {
this.getList()
this.getTreeselect()
// this.getDicts("sys_normal_disable").then(response => {
// this.statusOptions = response.data;
// });
this.getDicts('sys_user_sex').then(response => {
this.sexOptions = response.data
})
this.getConfigKey('sys.user.initPassword').then(response => {
this.initPassword = response.msg
})
},
//
handleNodeClick(data) {
this.queryParams.deptId = data.id;
this.getList();
},
//
handleStatusChange(row) {
let text = row.is_active === true ? "启用" : "停用";
this.$confirm('确认要"' + text + '""' + row.username + '"用户吗?', "警告", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning"
}).then(function() {
return changeUserStatus(row.id, row.is_active);
}).then(() => {
this.msgSuccess(text + "成功");
}).catch(function() {
row.is_active = row.is_active === false ? true : false;
});
},
//
cancel() {
this.open = false;
this.reset();
},
//
reset() {
this.form = {
id: undefined,
deptId: undefined,
username: undefined,
name: undefined,
password: undefined,
mobile: undefined,
email: undefined,
gender: undefined,
is_active: false,
remark: undefined,
postIds: [],
roleIds: []
};
this.resetForm("form");
},
/** 搜索按钮操作 */
handleQuery() {
this.queryParams.page = 1;
this.getList();
},
/** 重置按钮操作 */
resetQuery() {
this.dateRange = [];
this.queryParams.deptId = ''
this.resetForm("queryForm");
this.handleQuery();
},
//
handleSelectionChange(selection) {
this.ids = selection.map(item => item.id);
this.single = selection.length != 1;
this.multiple = !selection.length;
},
/** 新增按钮操作 */
handleAdd() {
this.reset();
this.getTreeselect();
getUser().then(response => {
this.postOptions = response.data.posts;
this.roleOptions = response.data.roles;
this.open = true;
this.title = "添加用户";
this.form.password = this.initPassword;
});
},
/** 修改按钮操作 */
handleUpdate(row) {
this.reset();
this.getTreeselect();
const id = row.id || this.ids;
getUser(id).then(response => {
let data = response.data.data
data['postIds'] = response.data.postIds
data['roleIds'] = response.data.roleIds
this.form = data;
this.postOptions = response.data.posts;
this.roleOptions = response.data.roles;
this.open = true;
this.title = "修改用户";
this.form.password = "";
});
},
/** 重置密码按钮操作 */
handleResetPwd(row) {
this.$prompt('请输入"' + row.username + '"的新密码', "提示", {
confirmButtonText: "确定",
cancelButtonText: "取消"
}).then(({ value }) => {
resetUserPwd(row.id, value).then(response => {
this.msgSuccess("修改成功,新密码是:" + value);
});
}).catch(() => {});
},
/** 提交按钮 */
submitForm: function() {
this.$refs["form"].validate(valid => {
if (valid) {
if (this.form.id != undefined) {
updateUser(this.form).then(response => {
this.msgSuccess("修改成功");
this.open = false;
this.getList();
});
} else {
addUser(this.form).then(response => {
this.msgSuccess("新增成功");
this.open = false;
this.getList();
});
methods: {
/** 查询用户列表 */
getList() {
this.loading = true
listUser(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
this.userList = response.data.results
this.total = response.data.count
this.loading = false
}
}
});
},
/** 删除按钮操作 */
handleDelete(row) {
const userIds = row.id || this.ids;
this.$confirm('是否确认删除用户编号为"' + userIds + '"的数据项?', "警告", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning"
)
},
/** 查询部门下拉树结构 */
getTreeselect() {
treeselect().then(response => {
this.deptOptions = this.handleTree(response.data, 'id')
})
},
//
filterNode(value, data) {
if (!value) return true
return data.label.indexOf(value) !== -1
},
//
handleNodeClick(data) {
this.queryParams.deptId = data.id
this.getList()
},
//
handleStatusChange(row) {
let text = row.is_active === true ? '启用' : '停用'
this.$confirm('确认要"' + text + '""' + row.username + '"用户吗?', '警告', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(function() {
return delUser(userIds);
return changeUserStatus(row.id, row.is_active)
}).then(() => {
this.getList();
this.msgSuccess("删除成功");
this.msgSuccess(text + '成功')
}).catch(function() {
row.is_active = row.is_active === false ? true : false
})
},
/** 导出按钮操作 */
handleExport() {
const queryParams = this.queryParams;
this.$confirm('是否确认导出所有用户数据项?', "警告", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning"
},
//
cancel() {
this.open = false
this.reset()
},
//
reset() {
this.form = {
id: undefined,
deptId: undefined,
username: undefined,
name: undefined,
password: undefined,
mobile: undefined,
email: undefined,
gender: undefined,
is_active: false,
remark: undefined,
postIds: [],
roleIds: []
}
this.resetForm('form')
},
/** 搜索按钮操作 */
handleQuery() {
this.queryParams.page = 1
this.getList()
},
/** 重置按钮操作 */
resetQuery() {
this.dateRange = []
this.queryParams.deptId = ''
this.resetForm('queryForm')
this.handleQuery()
},
//
handleSelectionChange(selection) {
this.ids = selection.map(item => item.id)
this.single = selection.length != 1
this.multiple = !selection.length
},
/** 新增按钮操作 */
handleAdd() {
this.reset()
this.getTreeselect()
getUser().then(response => {
this.postOptions = response.data.posts
this.roleOptions = response.data.roles
this.open = true
this.title = '添加用户'
this.form.password = this.initPassword
})
},
/** 修改按钮操作 */
handleUpdate(row) {
this.reset()
this.getTreeselect()
const id = row.id || this.ids
getUser(id).then(response => {
let data = response.data.data
data['postIds'] = response.data.postIds
data['roleIds'] = response.data.roleIds
this.form = data
this.postOptions = response.data.posts
this.roleOptions = response.data.roles
this.open = true
this.title = '修改用户'
this.form.password = ''
})
},
/** 重置密码按钮操作 */
handleResetPwd(row) {
this.$prompt('请输入"' + row.username + '"的新密码', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消'
}).then(({ value }) => {
resetUserPwd(row.id, value).then(response => {
this.msgSuccess('修改成功,新密码是:' + value)
})
}).catch(() => {
})
},
/** 提交按钮 */
submitForm: function() {
this.$refs['form'].validate(valid => {
if (valid) {
if (this.form.id != undefined) {
updateUser(this.form).then(response => {
this.msgSuccess('修改成功')
this.open = false
this.getList()
})
} else {
addUser(this.form).then(response => {
this.msgSuccess('新增成功')
this.open = false
this.getList()
})
}
}
})
},
/** 删除按钮操作 */
handleDelete(row) {
const userIds = row.id || this.ids
this.$confirm('是否确认删除用户编号为"' + userIds + '"的数据项?', '警告', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(function() {
return exportUser(queryParams);
}).then(response => {
this.download(response.data.file_url,response.data.name);
return delUser(userIds)
}).then(() => {
this.getList()
this.msgSuccess('删除成功')
})
},
/** 导入按钮操作 */
handleImport() {
this.upload.title = "用户导入";
this.upload.open = true;
},
/** 下载模板操作 */
importTemplate() {
importTemplate().then(response => {
this.download(response.data.file_url,response.data.name);
});
},
//
handleFileUploadProgress(event, file, fileList) {
this.upload.isUploading = true;
},
//
handleFileSuccess(response, file, fileList) {
this.upload.open = false;
this.upload.isUploading = false;
this.$refs.upload.clearFiles();
//
importsUser({file_url: response.data.file_url,updateSupport:this.upload.updateSupport}).then(response => {
this.$alert('导入成功!', "导入结果", { dangerouslyUseHTMLString: true });
this.getList();
});
},
//
submitFileForm() {
this.$refs.upload.submit();
},
/** 导出按钮操作 */
handleExport() {
const queryParams = this.queryParams
this.$confirm('是否确认导出所有用户数据项?', '警告', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(function() {
return exportUser(queryParams)
}).then(response => {
this.download(response.data.file_url, response.data.name)
})
},
/** 导入按钮操作 */
handleImport() {
this.upload.title = '用户导入'
this.upload.open = true
},
/** 下载模板操作 */
importTemplate() {
importTemplate().then(response => {
this.download(response.data.file_url, response.data.name)
})
},
//
handleFileUploadProgress(event, file, fileList) {
this.upload.isUploading = true
},
//
handleFileSuccess(response, file, fileList) {
this.upload.open = false
this.upload.isUploading = false
this.$refs.upload.clearFiles()
//
importsUser({ file_url: response.data.file_url, updateSupport: this.upload.updateSupport }).then(response => {
this.$alert('导入成功!', '导入结果', { dangerouslyUseHTMLString: true })
this.getList()
})
},
//
submitFileForm() {
this.$refs.upload.submit()
}
}
}
};
</script>