123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579 |
- <template>
- <div class="sy-content">
- <el-row>
- <el-col>
- <!-- 搜索信息 -->
- <el-form
- v-show="showSearch"
- ref="queryForm"
- :model="queryParams"
- size="small"
- :inline="true"
- label-width="68px"
- >
- <el-form-item
- label="用户名称"
- prop="userName"
- >
- <el-input
- v-model="queryParams.userName"
- placeholder="请输入用户名称"
- clearable
- style="width: 150px"
- @keyup.enter.native="handleQuery"
- />
- </el-form-item>
- <el-form-item
- label="用户状态"
- prop="state"
- >
- <el-select
- v-model="queryParams.state"
- placeholder="用户状态"
- clearable
- style="width: 150px"
- >
- <el-option
- v-for="status in userStatus"
- :key="status.value"
- :label="status.name"
- :value="status.value"
- />
- </el-select>
- </el-form-item>
- <el-form-item
- label="用户类型"
- prop="userType"
- >
- <el-select
- v-model="queryParams.userType"
- placeholder="用户类型"
- clearable
- style="width: 150px"
- >
- <el-option
- v-for="type in userType"
- :key="type.value"
- :label="type.name"
- :value="type.value"
- />
- </el-select>
- </el-form-item>
- <el-form-item>
- <el-button
- type="primary"
- icon="el-icon-search"
- size="mini"
- @click="handleQuery"
- >搜索</el-button>
- <el-button
- icon="el-icon-refresh"
- size="mini"
- @click="resetQuery"
- >重置</el-button>
- </el-form-item>
- </el-form>
- <!-- 操作按钮 -->
- <el-row>
- <el-col :span="1.5">
- <el-button
- type="primary"
- plain
- icon="el-icon-plus"
- size="mini"
- @click="handleAdd"
- >新增</el-button>
- </el-col>
- <el-col
- :span="1.5"
- style="margin-left: 15px;"
- >
- <el-button
- type="danger"
- plain
- icon="el-icon-delete"
- size="mini"
- :disabled="multiple"
- @click="handleDelete"
- >
- 删除</el-button>
- </el-col>
- </el-row>
- <!-- 表格数据信息 -->
- <el-table
- v-loading="loading"
- :data="userList"
- @selection-change="handleSelectionChange"
- >
- <el-table-column
- type="selection"
- width="50"
- align="center"
- />
- <el-table-column
- v-if="false"
- key="userId"
- label="用户编号"
- align="center"
- prop="userId"
- />
- <el-table-column
- key="userName"
- label="用户名称"
- align="center"
- prop="userName"
- :show-overflow-tooltip="true"
- />
- <el-table-column
- key="state"
- label="用户状态"
- align="center"
- prop="state"
- :show-overflow-tooltip="true"
- >
- <template slot-scope="scope">
- <span>{{ convertUserStatus(scope.row.state) }}</span>
- </template>
- </el-table-column>
- <el-table-column
- key="userType"
- label="用户类型"
- align="center"
- prop="userType"
- :show-overflow-tooltip="true"
- >
- <template slot-scope="scope">
- <span>{{ convertUserType(scope.row.userType) }}</span>
- </template>
- </el-table-column>
- <el-table-column
- key="lastLoginTime"
- label="最后登录时间"
- align="center"
- prop="lastLoginTime"
- width="160"
- />
- <el-table-column
- label="创建时间"
- align="center"
- prop="createTime"
- width="160"
- />
- <el-table-column
- label="操作"
- align="center"
- width="250"
- class-name="small-padding fixed-width"
- >
- <template
- v-if="scope.row.userId !== 1"
- slot-scope="scope"
- >
- <el-button
- size="mini"
- type="text"
- icon="el-icon-edit"
- @click="handleUpdate(scope.row)"
- >修改</el-button>
- <el-button
- size="mini"
- type="text"
- icon="el-icon-delete"
- @click="handleDelete(scope.row)"
- >删除</el-button>
- <el-button
- size="mini"
- type="text"
- icon="el-icon-key"
- @click="handleResetPwd(scope.row)"
- >重置密码</el-button>
- </template>
- </el-table-column>
- </el-table>
- <!-- 分页信息 -->
- <pagination
- v-show="total > 0"
- :total="total"
- :page.sync="queryParams.page"
- :limit.sync="queryParams.limit"
- align="right"
- @pagination="getUserList"
- />
- </el-col>
- </el-row>
- <!-- 添加或修改用户配置对话框 -->
- <el-dialog
- :title="title"
- :visible.sync="open"
- width="600px"
- append-to-body
- :close-on-click-modal="false"
- >
- <el-form
- ref="form"
- :model="form"
- :rules="rules"
- label-width="80px"
- >
- <el-row>
- <el-col :span="12">
- <el-form-item
- label="用户名称"
- prop="userName"
- >
- <el-input
- v-if="form.userId == undefined"
- v-model="form.userName"
- placeholder="请输入用户名称"
- maxlength="30"
- />
- <el-input
- v-else
- v-model="form.userName"
- placeholder="请输入用户名称"
- maxlength="30"
- readonly
- />
- </el-form-item>
- </el-col>
- <el-col :span="12">
- <el-form-item
- v-if="form.userId == undefined"
- label="用户密码"
- prop="password"
- >
- <el-input
- v-model="form.password"
- placeholder="请输入用户密码"
- type="password"
- maxlength="20"
- show-password
- auto-complete="new-password"
- />
- </el-form-item>
- </el-col>
- </el-row>
- <el-row>
- <el-col :span="12">
- <el-form-item label="用户类型">
- <el-select
- v-model="form.userType"
- placeholder="请选择用户类型"
- >
- <el-option
- v-for="dict in userType"
- :key="dict.value"
- :label="dict.name"
- :value="dict.value"
- />
- </el-select>
- </el-form-item>
- </el-col>
- <el-col :span="12">
- <el-form-item
- v-if="form.userId != undefined"
- label="用户状态"
- >
- <el-radio-group v-model="form.state">
- <el-radio
- v-for="dict in userStatus"
- :key="dict.value"
- :label="dict.value"
- >{{ dict.name }}</el-radio>
- </el-radio-group>
- </el-form-item>
- </el-col>
- </el-row>
- </el-form>
- <div
- slot="footer"
- class="dialog-footer"
- >
- <el-button
- type="primary"
- @click="submitForm"
- >确 定</el-button>
- <el-button @click="cancel">取 消</el-button>
- </div>
- </el-dialog>
- </div>
- </template>
- <script>
- import { addUserInfo, getUserList, updateUserInfo, delUserById } from '@/api/system/user'
- import { getPubKey } from '@/utils/auth'
- import { encrypt } from '@/utils/jsencrypt'
- export default {
- name: 'Index',
- data() {
- return {
- // 遮罩层
- loading: true,
- // 显示搜索条件
- showSearch: true,
- // 非多个禁用
- multiple: true,
- // 查询参数
- queryParams: {
- page: 1,
- limit: 10,
- userName: undefined,
- userType: undefined,
- state: undefined
- },
- // 总条数
- total: 0,
- // 用户表格数据
- userList: null,
- // 弹出层标题
- title: '',
- // 是否显示弹出层
- open: false,
- // 表单参数
- form: {},
- // 管理员默认ID
- defaultAdminId: '1',
- // 用户状态
- userStatus: this.$store.getters.userStatus,
- // 用户类型
- userType: this.$store.getters.userType,
- // 表单校验
- rules: {
- userName: [
- { required: true, message: '用户名称不能为空', trigger: 'blur' },
- { min: 2, max: 20, message: '用户名称长度必须介于 2 和 20 之间', trigger: 'blur' }
- ],
- password: [
- { required: true, message: '用户密码不能为空', trigger: 'blur' },
- { min: 5, max: 20, message: '用户密码长度必须介于 5 和 20 之间', trigger: 'blur' }
- ]
- }
- }
- },
- created() {
- this.getUserList()
- },
- methods: {
- /** 搜索按钮操作 */
- handleQuery() {
- this.queryParams.page = 1
- this.getUserList()
- },
- /** 重置按钮操作 */
- resetQuery() {
- this.$refs['queryForm'].resetFields()
- this.handleQuery()
- },
- /** 多选框选中数据 */
- handleSelectionChange(selection) {
- this.ids = selection.map(item => item.userId)
- this.multiple = !selection.length
- },
- /** 用户状态转换 */
- convertUserStatus(val) {
- let result = ''
- this.userStatus.forEach((e) => {
- if (e.value === val) {
- result = e.name
- }
- })
- return result
- },
- /** 用户类型转换 */
- convertUserType(val) {
- let result = ''
- // this.userType.forEach((e) => {
- // if (e.value === val) {
- // result = e.name
- // }
- // })
- val === 0 ? result = '客户端用户' : result = '管理用户'
- return result
- },
- /** 查询用户列表 */
- getUserList() {
- this.loading = true
- getUserList(this.queryParams).then(response => {
- const data = response.data
- this.userList = data.userList
- this.total = data.count
- this.loading = false
- })
- },
- /** 删除按钮操作 */
- handleDelete(row) {
- const userId = row.userId
- if (!userId) {
- const userIdList = this.ids
- if (!userIdList || userIdList.length === 0) {
- this.$message({
- message: '请选择您要删除的用户',
- type: 'warning'
- })
- return
- }
- this.$confirm('您确定要删除选中的用户吗?', '提示', {
- confirmButtonText: '确定',
- cancelButtonText: '取消',
- cancelButtonClass: 'btn_custom_cancel',
- closeOnClickModal: false,
- type: 'warning'
- }).then(() => {
- for (const i in userIdList) {
- const id = userIdList[i]
- if (id === this.defaultAdminId) {
- continue
- }
- delUserById({
- 'userId': id
- }).then(response => {
- this.getUserList()
- })
- }
- }).catch(() => {
- })
- return
- }
- if (userId === this.defaultAdminId) {
- this.$message({
- message: '系统管理员帐号无法进行删除操作',
- type: 'warning'
- })
- return
- }
- this.$confirm('您确定要删除用户【' + row.userName + '】吗?', '提示', {
- confirmButtonText: '确定',
- cancelButtonText: '取消',
- cancelButtonClass: 'btn_custom_cancel',
- closeOnClickModal: false,
- type: 'warning'
- }).then(() => {
- delUserById({
- userId
- }).then(response => {
- this.$message({
- message: '删除成功',
- type: 'success'
- })
- this.getUserList()
- })
- }).catch(() => {
- })
- },
- /** 重置密码按钮操作 */
- handleResetPwd(row) {
- if (row.userId === this.defaultAdminId) {
- this.$message({
- message: '系统管理员帐号无法进行密码重置操作',
- type: 'warning'
- })
- return
- }
- this.$confirm('是否重置密码?', '提示', {
- confirmButtonText: '确定',
- cancelButtonText: '取消',
- cancelButtonClass: 'btn_custom_cancel',
- closeOnClickModal: false,
- type: 'warning'
- }).then(() => {
- const data = this.$store.dispatch('user/ResetPassword', {
- userId: row.userId,
- newPassword: 'cy123456'
- })
- data.then(res => {
- if (res.code === 200) {
- this.$message({
- type: 'success',
- message: '修改成功'
- })
- }
- })
- }).catch(() => {
- this.$message({
- type: 'info',
- message: '已取消重置'
- })
- })
- },
- /** 修改按钮操作 */
- handleUpdate(row) {
- if (row.userId === this.defaultAdminId) {
- this.$message({
- message: '系统管理员帐号无法进行修改操作',
- type: 'warning'
- })
- return
- }
- this.reset()
- this.form = {
- userId: row.userId,
- userName: row.userName,
- password: '',
- userType: row.userType,
- state: row.state
- }
- this.open = true
- this.title = '修改用户'
- this.form.password = ''
- },
- /** 新增按钮操作 */
- handleAdd() {
- this.reset()
- this.form.userType = this.userType[0].value
- this.open = true
- this.title = '添加用户'
- },
- /** 表单提交 */
- submitForm() {
- this.$refs['form'].validate(valid => {
- if (valid) {
- if (this.form.userId !== undefined) {
- updateUserInfo(this.form).then(response => {
- this.$message({
- message: '修改成功',
- type: 'success'
- })
- this.open = false
- this.getUserList()
- })
- } else {
- const publicKey = getPubKey()
- this.form.password = encrypt(this.form.password, publicKey)
- addUserInfo(this.form).then(response => {
- this.$message({
- message: '新增成功',
- type: 'success'
- })
- this.open = false
- this.getUserList()
- })
- }
- }
- })
- },
- /** 表单重置 */
- cancel() {
- this.open = false
- this.reset()
- },
- /** 表单重置 */
- reset() {
- this.form = {
- userId: undefined,
- userName: undefined,
- password: undefined,
- userType: '0',
- state: '0'
- }
- if (this.$refs['form']) {
- this.$refs['form'].resetFields()
- }
- }
- }
- }
- </script>
- <style rel="stylesheet/scss" lang="scss">
- </style>
|