|
@@ -5,6 +5,12 @@
|
|
|
<m-button type="primary" icon="el-icon-plus" @click="onAdd">
|
|
|
新增
|
|
|
</m-button>
|
|
|
+ <m-button type="primary" icon="el-icon-upload2">
|
|
|
+ 批量导入
|
|
|
+ </m-button>
|
|
|
+ <m-button type="primary" icon="el-icon-download">
|
|
|
+ 模板下载
|
|
|
+ </m-button>
|
|
|
</template>
|
|
|
</m-search>
|
|
|
<MTable
|
|
@@ -13,54 +19,111 @@
|
|
|
:headers="headers"
|
|
|
:page-size="pageInfo.size"
|
|
|
:page-current="pageInfo.current"
|
|
|
- :total="pageInfo.total"
|
|
|
+ :total="total"
|
|
|
@page-change="handlePageChange"
|
|
|
>
|
|
|
- <template #createTime="scope">
|
|
|
- {{ dateFormat(scope.row.createTime) }}
|
|
|
+ <template #createdTime="scope">
|
|
|
+ {{ dateFormat(scope.row.createdTime) }}
|
|
|
+ </template>
|
|
|
+ <template #state="scope">
|
|
|
+ <el-tag size="small" :type="scope.row.state ? 'default' : 'success'">{{ scope.row.state ? '未启用' : '已启用' }}</el-tag>
|
|
|
+ </template>
|
|
|
+ <template #role="scope">
|
|
|
+ <template v-if="scope.row.companyInfo?.homeUserId === scope.row.id">
|
|
|
+ <el-tag size="small" type="danger">超级管理员</el-tag>
|
|
|
+ </template>
|
|
|
+ <template v-if="scope.row.role && scope.row.role.length">
|
|
|
+ <el-tag
|
|
|
+ v-for="item in scope.row.role"
|
|
|
+ :key="item.id"
|
|
|
+ size="small"
|
|
|
+ >{{ item.roleName }}</el-tag>
|
|
|
+ </template>
|
|
|
</template>
|
|
|
<template #actions="scope">
|
|
|
- <m-button type="primary" text @click="onEdit(scope.row)">编辑</m-button>
|
|
|
- <m-button type="warning" text @click="onMenu(scope.row)">重置密码</m-button>
|
|
|
- <m-button type="danger" text @click="onDelete(scope.row)">删除</m-button>
|
|
|
+ <template v-if="scope.row.companyInfo?.homeUserId !== scope.row.id">
|
|
|
+ <m-button
|
|
|
+ :type="scope.row.state ? 'success' : 'danger'"
|
|
|
+ class="pa-0"
|
|
|
+ text
|
|
|
+ @click="onStatus(scope.row)"
|
|
|
+ >
|
|
|
+ {{ scope.row.state ? '启用' : '禁用' }}
|
|
|
+ </m-button>
|
|
|
+ <m-button type="primary" class="pa-0" text @click="onEdit(scope.row)">编辑</m-button>
|
|
|
+ <m-button type="primary" class="pa-0" text @click="onSetRole(scope.row)">角色分配</m-button>
|
|
|
+ <m-button type="warning" class="pa-0" text @click="onReset(scope.row)">重置密码</m-button>
|
|
|
+ <m-button type="danger" class="pa-0" text @click="onDelete(scope.row)">删除</m-button>
|
|
|
+ </template>
|
|
|
</template>
|
|
|
</MTable>
|
|
|
+ <MDialog ref="dialog" :title="itemData.id ? '编辑用户' : '新增用户'" @sure="handleSave">
|
|
|
+ <MForm ref="userForm" :items="userFormItems" v-model="userFormValue"></MForm>
|
|
|
+ </MDialog>
|
|
|
+ <MDialog ref="role" title="角色分配" @sure="handleSaveRole">
|
|
|
+ <MForm ref="roleForm" :items="roleFormItems" v-model="roleFormValue">
|
|
|
+ <template #username>
|
|
|
+ <el-tag>{{ itemData.username }}</el-tag>
|
|
|
+ </template>
|
|
|
+ <template #name>
|
|
|
+ <el-tag>{{ itemData.name }}</el-tag>
|
|
|
+ </template>
|
|
|
+ </MForm>
|
|
|
+ </MDialog>
|
|
|
+ <MDialog ref="password" title="重置密码" @sure="handleSavePassword">
|
|
|
+ <MForm ref="passwordForm" :items="passwordFormItems" v-model="passwordFormValue"></MForm>
|
|
|
+ </MDialog>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
import util from '@/utils/base64ToFile'
|
|
|
-import { getUserList, saveUser, deleteUser, resetPassword, downloadUserTemplate, userExcelExport } from '@/api/user'
|
|
|
+import {
|
|
|
+ getUserList,
|
|
|
+ saveUser,
|
|
|
+ deleteUser,
|
|
|
+ resetPassword,
|
|
|
+ downloadUserTemplate,
|
|
|
+ userExcelExport,
|
|
|
+ blockUser
|
|
|
+} from '@/api/user'
|
|
|
import { getRoleList } from '@/api/menu'
|
|
|
-import { currentTime } from '@/utils/date'
|
|
|
+import { dateFormat } from '@/utils/date'
|
|
|
export default {
|
|
|
name: 'user-list',
|
|
|
- components: { },
|
|
|
data () {
|
|
|
return {
|
|
|
searchItems: [
|
|
|
{
|
|
|
- label: '用户名称',
|
|
|
- prop: 'username',
|
|
|
+ label: '用户查找',
|
|
|
+ option: {
|
|
|
+ placeholder: '请输入用户昵称 / 账号'
|
|
|
+ },
|
|
|
+ prop: 'searchKey',
|
|
|
type: 'input'
|
|
|
}
|
|
|
],
|
|
|
- query: {
|
|
|
- name: null,
|
|
|
- username: null
|
|
|
+ searchValues: {
|
|
|
+ searchKey: null
|
|
|
+ },
|
|
|
+ roleFormValue: {
|
|
|
+ roleId: null
|
|
|
+ },
|
|
|
+ userFormValue: {
|
|
|
+ type: 1
|
|
|
+ },
|
|
|
+ passwordFormValue: {
|
|
|
+ newPwd: null
|
|
|
},
|
|
|
- showReset: false,
|
|
|
headers: [
|
|
|
- { text: '用户昵称', align: 'start', value: 'name' },
|
|
|
- { text: '账号', align: 'start', value: 'username' },
|
|
|
- { text: '人员编码', value: 'employeeCode' },
|
|
|
- { text: '电话', align: 'start', value: 'phone' },
|
|
|
- { text: '角色', align: 'start', value: 'role' },
|
|
|
- { text: '状态', align: 'start', value: 'state' },
|
|
|
- { text: '登陆时间', align: 'start', value: 'loginTime' },
|
|
|
- { text: '上次登录时间', align: 'start', value: 'lastLoginTime' },
|
|
|
- { text: '创建时间', align: 'start', value: 'createdTime' },
|
|
|
- { text: '操作', align: 'start', value: 'actions' }
|
|
|
+ { label: '用户昵称', prop: 'name', width: 200 },
|
|
|
+ { label: '账号', prop: 'username', width: 200 },
|
|
|
+ { label: '人员编码', prop: 'employeeCode' },
|
|
|
+ { label: '角色', prop: 'role' },
|
|
|
+ { label: '状态', prop: 'state' },
|
|
|
+ { label: '上次登录时间', prop: 'lastLoginTime', width: 150 },
|
|
|
+ { label: '创建时间', prop: 'createdTime', width: 200 },
|
|
|
+ { label: '操作', prop: 'actions', fixed: 'right', width: 300 }
|
|
|
],
|
|
|
items: [],
|
|
|
total: 0,
|
|
@@ -69,41 +132,145 @@ export default {
|
|
|
size: 10
|
|
|
},
|
|
|
loading: false,
|
|
|
- isEdit: false,
|
|
|
+ itemData: {},
|
|
|
+ showReset: false,
|
|
|
show: false,
|
|
|
- title: '新增',
|
|
|
roleList: [],
|
|
|
- itemData: {},
|
|
|
uploadLoading: false
|
|
|
}
|
|
|
},
|
|
|
+ computed: {
|
|
|
+ passwordFormItems () {
|
|
|
+ return [
|
|
|
+ {
|
|
|
+ label: '新密码',
|
|
|
+ prop: 'newPwd',
|
|
|
+ type: 'input',
|
|
|
+ options: {
|
|
|
+ showPassword: true,
|
|
|
+ placeholder: '请输入新密码'
|
|
|
+ },
|
|
|
+ rules: [
|
|
|
+ { required: true, message: '请输入密码', trigger: 'change' }
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ roleFormItems () {
|
|
|
+ return [
|
|
|
+ {
|
|
|
+ label: '用户名称',
|
|
|
+ prop: 'username'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ label: '用户昵称',
|
|
|
+ prop: 'name'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ label: '角色',
|
|
|
+ prop: 'roleId',
|
|
|
+ type: 'select',
|
|
|
+ options: {
|
|
|
+ multiple: true,
|
|
|
+ items: this.roleList.map(e => {
|
|
|
+ return {
|
|
|
+ label: e.roleName,
|
|
|
+ value: e.id
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ rules: [
|
|
|
+ { required: true, message: '请选择角色', trigger: 'change' }
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ userFormItems () {
|
|
|
+ const hidden = this.userFormValue.type === 2
|
|
|
+ return [
|
|
|
+ {
|
|
|
+ label: '账户类型',
|
|
|
+ prop: 'type',
|
|
|
+ type: 'radioGroup',
|
|
|
+ options: {
|
|
|
+ items: [
|
|
|
+ { text: '统一认证号用户', label: 1 },
|
|
|
+ { text: '系统普通用户', label: 2 }
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ rules: [
|
|
|
+ { required: true, message: '请选择账户类型', trigger: 'blur' }
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ label: !hidden ? '统一认证号' : '用户账号',
|
|
|
+ prop: 'username',
|
|
|
+ type: 'input',
|
|
|
+ options: {
|
|
|
+ placeholder: '请输入' + (!hidden ? '统一认证号' : '用户账号')
|
|
|
+ },
|
|
|
+ rules: [
|
|
|
+ { required: true, message: `请输入${!hidden ? '统一认证号' : '用户账号'}`, trigger: 'blur' }
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ label: '用户昵称',
|
|
|
+ prop: 'name',
|
|
|
+ type: 'input',
|
|
|
+ options: {
|
|
|
+ placeholder: '请输入用户昵称'
|
|
|
+ },
|
|
|
+ rules: [
|
|
|
+ { required: true, message: '请输入用户昵称', trigger: 'blur' }
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ label: '用户密码',
|
|
|
+ prop: 'password',
|
|
|
+ type: 'input',
|
|
|
+ options: {
|
|
|
+ showPassword: true,
|
|
|
+ placeholder: '请输入用户密码'
|
|
|
+ },
|
|
|
+ hidden: !hidden || this.itemData.id,
|
|
|
+ rules: [
|
|
|
+ { required: true, message: '请输入用户密码', trigger: 'blur' }
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ label: '用户邮箱',
|
|
|
+ prop: 'email',
|
|
|
+ type: 'input',
|
|
|
+ options: {
|
|
|
+ placeholder: '请输入用户邮箱'
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ },
|
|
|
async created () {
|
|
|
await this.initDice()
|
|
|
await this.init()
|
|
|
},
|
|
|
methods: {
|
|
|
- formatToTime (str) {
|
|
|
- return currentTime(str)
|
|
|
+ dateFormat (str) {
|
|
|
+ const date = new Date(+str * 1000)
|
|
|
+ return dateFormat('YYYY-mm-dd HH:MM:SS', date)
|
|
|
},
|
|
|
async init () {
|
|
|
try {
|
|
|
this.loading = true
|
|
|
- const { data } = await getUserList({ ...this.pageInfo, ...this.query })
|
|
|
- this.items = data.records.map(e => {
|
|
|
- // e.roleName = e.role.map(_m => _m.roleName).toString()
|
|
|
- return e
|
|
|
- })
|
|
|
+ const { data } = await getUserList({ ...this.pageInfo, ...this.searchValues })
|
|
|
+ this.items = data.records
|
|
|
this.total = data.total
|
|
|
} catch (error) {
|
|
|
- this.$snackbar.error(error)
|
|
|
+ this.$message.error(error)
|
|
|
} finally {
|
|
|
this.loading = false
|
|
|
}
|
|
|
},
|
|
|
- handleSearch (val) {
|
|
|
- // console.log(val)
|
|
|
+ search (val) {
|
|
|
this.pageInfo.current = 1
|
|
|
- Object.assign(this.query, val)
|
|
|
this.init()
|
|
|
},
|
|
|
async initDice () {
|
|
@@ -111,71 +278,131 @@ export default {
|
|
|
const { data } = await getRoleList({ size: 999 })
|
|
|
this.roleList = data.records
|
|
|
} catch (error) {
|
|
|
- this.$snackbar.error(error)
|
|
|
+ this.$message.error(error)
|
|
|
}
|
|
|
},
|
|
|
- handleEdit (item) {
|
|
|
- this.title = '编辑用户'
|
|
|
- this.itemData = item
|
|
|
- this.isEdit = true
|
|
|
- this.show = true
|
|
|
- },
|
|
|
- handleAdd () {
|
|
|
- this.title = '新增用户'
|
|
|
- this.isEdit = false
|
|
|
- this.show = true
|
|
|
+ async onSave (query) {
|
|
|
+ try {
|
|
|
+ await saveUser({
|
|
|
+ id: this.itemData?.id,
|
|
|
+ tenantCode: this.itemData.tenantCode,
|
|
|
+ ...query
|
|
|
+ })
|
|
|
+ this.$message.success('保存成功')
|
|
|
+ this.init()
|
|
|
+ return true
|
|
|
+ } catch (error) {
|
|
|
+ this.$message.error(error)
|
|
|
+ }
|
|
|
},
|
|
|
- async handleSave () {
|
|
|
- if (!this.$refs.user.validate()) return
|
|
|
- const param = this.$refs.user.getValue()
|
|
|
- if (this.isEdit) param.id = this.itemData.id
|
|
|
- param.roleId = param.roleId.toString()
|
|
|
+ async onStatus (item) {
|
|
|
+ const state = item.state ? 1 : 0
|
|
|
try {
|
|
|
- await saveUser(param)
|
|
|
- this.$snackbar.success('保存成功')
|
|
|
- this.show = false
|
|
|
+ await blockUser({
|
|
|
+ userId: item.id,
|
|
|
+ state: 1 ^ state
|
|
|
+ })
|
|
|
+ this.$message.success('保存成功')
|
|
|
this.init()
|
|
|
} catch (error) {
|
|
|
- this.$snackbar.error(error)
|
|
|
+ this.$message.error(error)
|
|
|
}
|
|
|
},
|
|
|
- handleDelete (userId) {
|
|
|
- if (Array.isArray(userId)) return
|
|
|
- this.$confirm('提示', '是否确定删除该选项')
|
|
|
+ onEdit (item) {
|
|
|
+ this.itemData = item
|
|
|
+ this.userFormValue = {
|
|
|
+ type: item.password ? 2 : 1,
|
|
|
+ username: item.username,
|
|
|
+ name: item.name,
|
|
|
+ email: item.email
|
|
|
+ }
|
|
|
+ this.$refs.dialog.open()
|
|
|
+ },
|
|
|
+ onAdd () {
|
|
|
+ this.itemData = {}
|
|
|
+ this.userFormValue = {
|
|
|
+ type: 1
|
|
|
+ }
|
|
|
+ this.$refs.dialog.open()
|
|
|
+ },
|
|
|
+ onSetRole (item) {
|
|
|
+ this.itemData = item
|
|
|
+ console.log(item.roleId.length)
|
|
|
+ this.roleFormValue = {
|
|
|
+ roleId: item.roleId ? item.roleId.split(',').map(e => +e) : []
|
|
|
+ }
|
|
|
+ this.$refs.role.open()
|
|
|
+ },
|
|
|
+ onReset (item) {
|
|
|
+ this.itemData = item
|
|
|
+ this.passwordFormValue.newPwd = null
|
|
|
+ this.$refs.password.open()
|
|
|
+ },
|
|
|
+ onDelete (item) {
|
|
|
+ this.$confirm('是否确定删除该选项', '提示', {
|
|
|
+ confirmButtonText: '确定',
|
|
|
+ cancelButtonText: '取消',
|
|
|
+ type: 'warning'
|
|
|
+ })
|
|
|
.then(async () => {
|
|
|
try {
|
|
|
- await deleteUser({ userId })
|
|
|
- this.$snackbar.success('删除成功')
|
|
|
+ await deleteUser({ userId: item.id })
|
|
|
+ this.$message.success('删除成功')
|
|
|
this.init()
|
|
|
} catch (error) {
|
|
|
- this.$snackbar.error(error)
|
|
|
+ this.$message.error(error)
|
|
|
}
|
|
|
})
|
|
|
+ .catch(_ => {})
|
|
|
},
|
|
|
- handleReset (item) {
|
|
|
- this.itemData = item
|
|
|
- this.showReset = true
|
|
|
- },
|
|
|
- async handleSaveReset () {
|
|
|
- if (!this.$refs.password.validate()) return
|
|
|
- const obj = this.$refs.password.getValue()
|
|
|
- const companyCode = this.itemData.companyInfo.companyCode
|
|
|
- const userId = this.itemData.id
|
|
|
- const param = {
|
|
|
- type: 1,
|
|
|
- userId,
|
|
|
- companyCode
|
|
|
- }
|
|
|
- Object.assign(param, obj)
|
|
|
- try {
|
|
|
- await resetPassword(param)
|
|
|
- this.showReset = false
|
|
|
- this.$snackbar.success('修改成功')
|
|
|
- } catch (error) {
|
|
|
- this.$snackbar.error(error)
|
|
|
- }
|
|
|
+ async handleSave () {
|
|
|
+ this.$refs.userForm.validate(async valid => {
|
|
|
+ if (!valid) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ const { type, ...obj } = this.userFormValue
|
|
|
+ const check = await this.onSave({
|
|
|
+ ...obj,
|
|
|
+ state: 0,
|
|
|
+ roleId: ''
|
|
|
+ })
|
|
|
+ check && this.$refs.dialog.close()
|
|
|
+ })
|
|
|
+ },
|
|
|
+ async handleSaveRole () {
|
|
|
+ this.$refs.roleForm.validate(async valid => {
|
|
|
+ if (!valid) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ const check = await this.onSave({
|
|
|
+ roleId: this.roleFormValue.roleId.toString()
|
|
|
+ })
|
|
|
+ check && this.$refs.role.close()
|
|
|
+ })
|
|
|
+ },
|
|
|
+ async handleSavePassword () {
|
|
|
+ this.$refs.passwordForm.validate(async valid => {
|
|
|
+ if (!valid) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ const companyCode = this.itemData.companyInfo?.companyCode
|
|
|
+ const userId = this.itemData.id
|
|
|
+ const param = {
|
|
|
+ type: 1,
|
|
|
+ userId,
|
|
|
+ companyCode,
|
|
|
+ ...this.passwordFormValue
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ await resetPassword(param)
|
|
|
+ this.$refs.password.close()
|
|
|
+ this.$message.success('修改成功')
|
|
|
+ } catch (error) {
|
|
|
+ this.$message.error(error)
|
|
|
+ }
|
|
|
+ })
|
|
|
},
|
|
|
- pageHandleChange (page) {
|
|
|
+ handlePageChange (page) {
|
|
|
this.pageInfo.current = page
|
|
|
this.init()
|
|
|
},
|
|
@@ -185,7 +412,7 @@ export default {
|
|
|
const { data } = await downloadUserTemplate()
|
|
|
util.downloadFileByByte(data, '批量上传文件模板.xls')
|
|
|
} catch (error) {
|
|
|
- this.$snackbar.error(error)
|
|
|
+ this.$message.error(error)
|
|
|
}
|
|
|
},
|
|
|
// 批量上传用户
|
|
@@ -195,10 +422,10 @@ export default {
|
|
|
this.uploadLoading = true
|
|
|
try {
|
|
|
await userExcelExport(formData)
|
|
|
- this.$snackbar.success('上传成功')
|
|
|
+ this.$message.success('上传成功')
|
|
|
this.init()
|
|
|
} catch (error) {
|
|
|
- this.$snackbar.error(error)
|
|
|
+ this.$message.error(error)
|
|
|
} finally {
|
|
|
this.uploadLoading = false
|
|
|
}
|