2023-12-17 16:05:38 +08:00
|
|
|
|
<template>
|
2024-04-10 19:07:22 +08:00
|
|
|
|
<div class="table-page">
|
|
|
|
|
<div class="search-part" v-show="isSearch">
|
|
|
|
|
<div class="search-cell">
|
|
|
|
|
<span class="label">用户名</span>
|
|
|
|
|
<el-input v-model="queryParams.userName" placeholder="请输入用户名"></el-input>
|
|
|
|
|
</div>
|
2024-04-11 17:55:47 +08:00
|
|
|
|
<el-button type="primary" icon="Search" @click="searchData()">查询</el-button>
|
|
|
|
|
<el-button icon="Refresh" @click="resetSearch()">重置</el-button>
|
2024-04-10 19:07:22 +08:00
|
|
|
|
</div>
|
|
|
|
|
<div class="button-part" style="justify-content: space-between;">
|
|
|
|
|
<div>
|
|
|
|
|
<el-button type="primary" icon="FirstAidKit" @click="addData">新增</el-button>
|
|
|
|
|
<el-button icon="FirstAidKit" @click="importData">导入</el-button>
|
|
|
|
|
<el-button icon="Delete" @click="removeData()">删除</el-button>
|
|
|
|
|
</div>
|
2024-04-11 17:55:47 +08:00
|
|
|
|
<TableAbility @searchBtn="isSearch = !isSearch" @refreshBtn="updateData()"
|
2024-04-10 19:07:22 +08:00
|
|
|
|
@downloadBtn="exportData('医生数据', tableData)"></TableAbility>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="table-part">
|
|
|
|
|
<el-table ref="tableRef" v-loading="loading" :data="tableData" height="100%" border show-overflow-tooltip
|
|
|
|
|
:row-class-name="({ row }: any) => row.lockFlag == 1 && 'disable'" @row-click="tableRowClick">
|
|
|
|
|
<el-table-column type="selection" width="55"/>
|
|
|
|
|
<el-table-column type="index" label="#" width="55" align="center"/>
|
|
|
|
|
<el-table-column property="name" label="姓名" width="120" align="center"/>
|
|
|
|
|
<el-table-column label="手机号" width="220" align="center">
|
|
|
|
|
<template #default="scope">{{
|
|
|
|
|
scope.row.phone.slice(0, 3) + '****' + scope.row.phone.slice(7)
|
|
|
|
|
}}
|
|
|
|
|
</template>
|
|
|
|
|
</el-table-column>
|
|
|
|
|
<el-table-column label="角色" width="220" align="center">
|
|
|
|
|
<template #default="scope">
|
|
|
|
|
<span v-for="(item, index) in scope.row.roleList" :key="index">
|
|
|
|
|
{{ item.roleName }} {{ (scope.row.roleList.length - 1) == index ? '' : ',' }}
|
|
|
|
|
</span>
|
|
|
|
|
</template>
|
|
|
|
|
</el-table-column>
|
|
|
|
|
<el-table-column label="锁定" width="120" align="center">
|
|
|
|
|
<template #default="scope">
|
2024-04-11 17:55:47 +08:00
|
|
|
|
<span><el-switch v-model="scope.row.lockFlag" @click="enableChange(scope.row)"/></span>
|
2024-04-10 19:07:22 +08:00
|
|
|
|
</template>
|
|
|
|
|
</el-table-column>
|
|
|
|
|
<el-table-column label="操作" align="center">
|
|
|
|
|
<template #default="scope">
|
2023-12-18 17:16:47 +08:00
|
|
|
|
<span @click.stop>
|
2023-12-27 16:49:37 +08:00
|
|
|
|
<el-button link icon="RefreshLeft" @click="resetPassword(scope.row)"
|
2024-04-11 17:55:47 +08:00
|
|
|
|
:disabled="scope.row.lockFlag == 1">密码</el-button>
|
2023-12-27 16:49:37 +08:00
|
|
|
|
<el-button link icon="EditPen" @click="editData(scope.row)"
|
2024-04-11 17:55:47 +08:00
|
|
|
|
:disabled="scope.row.lockFlag == 1">修改</el-button>
|
2024-04-17 15:19:06 +08:00
|
|
|
|
<el-button link icon="Delete" @click="removeData([scope.row])"
|
|
|
|
|
:disabled="scope.row.lockFlag == 1">删除</el-button>
|
2023-12-18 17:16:47 +08:00
|
|
|
|
</span>
|
2024-04-10 19:07:22 +08:00
|
|
|
|
</template>
|
|
|
|
|
</el-table-column>
|
|
|
|
|
</el-table>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="pagination-part">
|
|
|
|
|
<CommonPagination :total="total" @paginationChange="paginationChange"/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<el-dialog v-model="isFormDialog" :title="formDialogTitle" width="750px">
|
|
|
|
|
<DoctorForm ref="doctorFormRef" :type="formDialogTitle === '添加' ? 'add' : 'edit'" @close="isFormDialog = false"
|
|
|
|
|
@save="doctorFormSave"/>
|
|
|
|
|
</el-dialog>
|
2024-04-11 17:55:47 +08:00
|
|
|
|
<ImportDialog ref="importDialogRef" title="用户导入"
|
2024-04-28 18:08:16 +08:00
|
|
|
|
templateUrl="/admin/sys-file/local/file/user.xlsx"
|
|
|
|
|
importUrl="/admin/user/import"/>
|
2023-12-17 16:05:38 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script lang='ts' setup>
|
2024-04-11 17:55:47 +08:00
|
|
|
|
import {ref} from 'vue'
|
2024-04-10 19:07:22 +08:00
|
|
|
|
import {ElMessage, ElMessageBox} from 'element-plus'
|
2024-04-11 17:55:47 +08:00
|
|
|
|
import {exportData, tableRemoveRow} from '@/utils/table-util'
|
2023-12-17 16:05:38 +08:00
|
|
|
|
import CommonPagination from '@/components/common-pagination.vue'
|
2023-12-18 14:29:28 +08:00
|
|
|
|
import DoctorForm from './form/doctor-form.vue'
|
|
|
|
|
import ImportDialog from '@/components/import-dialog.vue'
|
2024-04-17 15:19:06 +08:00
|
|
|
|
import {deleteU, modifyPw, updateUserInfo, userPage} from "@/api/user";
|
2023-12-17 16:05:38 +08:00
|
|
|
|
|
2023-12-18 14:29:28 +08:00
|
|
|
|
const tableRef = ref()
|
|
|
|
|
const doctorFormRef = ref()
|
2023-12-18 17:16:47 +08:00
|
|
|
|
const importDialogRef = ref()
|
2023-12-27 16:49:37 +08:00
|
|
|
|
const isSearch = ref(true)
|
|
|
|
|
const loading = ref(true)
|
2023-12-18 14:29:28 +08:00
|
|
|
|
const isFormDialog = ref(false)
|
|
|
|
|
const formDialogTitle = ref('')
|
2023-12-17 16:05:38 +08:00
|
|
|
|
const queryParams = ref({
|
2024-04-10 19:07:22 +08:00
|
|
|
|
userName: ''
|
2023-12-18 14:29:28 +08:00
|
|
|
|
} as any)
|
2023-12-17 16:05:38 +08:00
|
|
|
|
const tableData = ref([] as any)
|
2024-04-10 19:07:22 +08:00
|
|
|
|
let current = 0
|
|
|
|
|
let size = 10
|
|
|
|
|
const total = ref(0)
|
2023-12-17 16:05:38 +08:00
|
|
|
|
|
2023-12-28 14:48:45 +08:00
|
|
|
|
queryData()
|
2023-12-17 16:05:38 +08:00
|
|
|
|
|
2024-04-11 17:55:47 +08:00
|
|
|
|
function searchData() {
|
|
|
|
|
updateData()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function resetSearch() {
|
|
|
|
|
queryParams.value.userName = ""
|
|
|
|
|
updateData()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function queryData() {
|
2024-04-10 19:07:22 +08:00
|
|
|
|
loading.value = true
|
|
|
|
|
userPage({
|
|
|
|
|
current,
|
|
|
|
|
size,
|
|
|
|
|
name: queryParams.value.userName
|
|
|
|
|
}).then((res: any) => {
|
|
|
|
|
loading.value = false
|
|
|
|
|
total.value = res.data.total
|
|
|
|
|
tableData.value = res.data.records
|
|
|
|
|
}).catch(error => {
|
|
|
|
|
loading.value = false
|
|
|
|
|
})
|
2023-12-18 14:29:28 +08:00
|
|
|
|
}
|
2024-04-10 19:07:22 +08:00
|
|
|
|
|
2024-04-11 17:55:47 +08:00
|
|
|
|
function updateData() {
|
|
|
|
|
current = 0
|
|
|
|
|
total.value = 0
|
|
|
|
|
tableData.value = []
|
|
|
|
|
queryData()
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-18 14:29:28 +08:00
|
|
|
|
const addData = () => {
|
2024-04-10 19:07:22 +08:00
|
|
|
|
isFormDialog.value = true
|
|
|
|
|
formDialogTitle.value = '添加'
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
doctorFormRef.value.resetData()
|
|
|
|
|
}, 0)
|
2023-12-18 14:29:28 +08:00
|
|
|
|
}
|
|
|
|
|
const importData = () => {
|
2024-04-10 19:07:22 +08:00
|
|
|
|
setTimeout(() => {
|
|
|
|
|
importDialogRef.value.open()
|
|
|
|
|
}, 0);
|
2023-12-18 14:29:28 +08:00
|
|
|
|
}
|
|
|
|
|
const removeData = (e?: any) => {
|
2024-04-10 19:07:22 +08:00
|
|
|
|
const selectRow = e || tableRef.value.getSelectionRows()
|
2024-04-17 15:19:06 +08:00
|
|
|
|
|
2024-04-10 19:07:22 +08:00
|
|
|
|
tableRemoveRow({data: selectRow}, (res: boolean) => {
|
|
|
|
|
if (res) {
|
|
|
|
|
const index = tableData.value.findIndex((item: any) => item === selectRow)
|
|
|
|
|
tableData.value.splice(index, 1)
|
2024-04-17 15:19:06 +08:00
|
|
|
|
const ids: any = [];
|
|
|
|
|
selectRow.forEach((row: any) => {
|
|
|
|
|
ids.push(row.userId)
|
|
|
|
|
})
|
|
|
|
|
deleteU(ids).then(res => {
|
|
|
|
|
ElMessage.success("删除成功")
|
|
|
|
|
}).catch(() => {
|
|
|
|
|
ElMessage.error("删除失败")
|
|
|
|
|
})
|
2024-04-10 19:07:22 +08:00
|
|
|
|
}
|
|
|
|
|
})
|
2023-12-18 14:29:28 +08:00
|
|
|
|
}
|
|
|
|
|
const enableChange = (e: any) => {
|
2024-04-11 17:55:47 +08:00
|
|
|
|
updateUserInfo({
|
|
|
|
|
username: e.username,
|
|
|
|
|
lockFlag: e.lockFlag ? '1' : '0'
|
|
|
|
|
}).then((res: any) => {
|
|
|
|
|
if (res.code == 0) {
|
|
|
|
|
ElMessage.success(e.lockFlag ? '锁定成功' : '解锁成功')
|
|
|
|
|
}
|
|
|
|
|
})
|
2023-12-18 14:29:28 +08:00
|
|
|
|
}
|
|
|
|
|
const resetPassword = (e: any) => {
|
2024-04-11 17:55:47 +08:00
|
|
|
|
ElMessageBox.prompt('是否确定要重置密码?', '系统提醒', {
|
|
|
|
|
type: 'warning',
|
|
|
|
|
draggable: true,
|
|
|
|
|
inputPattern: /^(?=.*\d)(?=.*[a-zA-Z])(?=.*[^\da-zA-Z\s]).{9,15}$/,
|
|
|
|
|
inputErrorMessage: "密码至少包含字母、数字、特殊字符,不少于9位,最多15位"
|
|
|
|
|
}).then((inputVal) => {
|
|
|
|
|
modifyPw({
|
|
|
|
|
username: e.username,
|
|
|
|
|
password: inputVal.value
|
|
|
|
|
}).then((res: any) => {
|
|
|
|
|
if (res.code == 0) {
|
|
|
|
|
ElMessage.success('重置成功!')
|
|
|
|
|
} else {
|
|
|
|
|
ElMessage.error(res.msg)
|
|
|
|
|
}
|
|
|
|
|
})
|
2024-04-10 19:07:22 +08:00
|
|
|
|
})
|
2023-12-18 14:29:28 +08:00
|
|
|
|
}
|
|
|
|
|
const editData = (e: any) => {
|
2024-04-10 19:07:22 +08:00
|
|
|
|
isFormDialog.value = true
|
|
|
|
|
formDialogTitle.value = '修改'
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
doctorFormRef.value.resetData()
|
2024-04-11 17:55:47 +08:00
|
|
|
|
const val = JSON.parse(JSON.stringify(e));
|
|
|
|
|
val.role = []
|
|
|
|
|
val.roleList.forEach((role: any) => {
|
|
|
|
|
val.role.push(role.roleId)
|
|
|
|
|
})
|
|
|
|
|
doctorFormRef.value.formData = val
|
2024-04-10 19:07:22 +08:00
|
|
|
|
}, 0)
|
2023-12-18 14:29:28 +08:00
|
|
|
|
}
|
|
|
|
|
const tableRowClick = (row: any) => {
|
2024-04-10 19:07:22 +08:00
|
|
|
|
tableRef.value.toggleRowSelection(row)
|
2023-12-18 14:29:28 +08:00
|
|
|
|
}
|
2023-12-28 14:27:47 +08:00
|
|
|
|
const doctorFormSave = (data: any, type: string) => {
|
2024-04-11 17:55:47 +08:00
|
|
|
|
updateData()
|
2023-12-28 14:27:47 +08:00
|
|
|
|
}
|
2024-04-11 17:55:47 +08:00
|
|
|
|
const paginationChange = (page: number, s: number) => {
|
|
|
|
|
current = page
|
|
|
|
|
size = s
|
|
|
|
|
queryData()
|
2023-12-17 16:05:38 +08:00
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
2023-12-27 16:49:37 +08:00
|
|
|
|
<style lang='scss' scoped></style>
|