87 门诊医生站-》增加医生常用语权限管理
This commit is contained in:
@@ -268,14 +268,15 @@ const validatePhraseName = (phraseName, excludeId = null) => {
|
||||
// 所有数据(用于客户端分页处理)
|
||||
const allData = ref([])
|
||||
|
||||
// 获取医生常用语列表数据
|
||||
// 获取医生常用语列表数据
|
||||
const fetchDoctorPhraseList = async () => {
|
||||
try {
|
||||
const response = await getDoctorPhraseList()
|
||||
// 处理后端返回的数据结构:data.data
|
||||
if (response.code === 200 && response.data && response.data.data) {
|
||||
// 【关键修改】去掉 response.data.data,直接取 response.data
|
||||
if (response.code === 200 && response.data) {
|
||||
// 按照sortNo由小到大排序,保证列表顺序正确
|
||||
allData.value = response.data.data.sort((a, b) => a.sortNo - b.sortNo)
|
||||
allData.value = response.data.sort((a, b) => a.sortNo - b.sortNo)
|
||||
total.value = allData.value.length
|
||||
// 执行客户端分页逻辑
|
||||
applyPagination()
|
||||
@@ -285,7 +286,7 @@ const fetchDoctorPhraseList = async () => {
|
||||
total.value = 0
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取列表失败:', error) // 增加控制台日志便于调试
|
||||
console.error('获取列表失败:', error)
|
||||
ElMessage.error('获取数据失败: 网络请求错误')
|
||||
allData.value = []
|
||||
total.value = 0
|
||||
@@ -322,19 +323,18 @@ const handleCurrentChange = (val) => {
|
||||
applyPagination()
|
||||
}
|
||||
|
||||
// 搜索功能核心方法
|
||||
// 搜索功能核心方法
|
||||
const handleSearch = async () => {
|
||||
try {
|
||||
// searchScope可能是null(未选择)、1=个人,2=科室,3=全院
|
||||
const phraseType = searchScope.value === null ? undefined : searchScope.value
|
||||
// 调用搜索接口:phraseName, phraseType
|
||||
const response = await searchDoctorPhraseList(searchKeyword.value, phraseType)
|
||||
if (response.code === 200 && response.data && response.data.data) {
|
||||
// 按照sortNo由小到大排序
|
||||
allData.value = response.data.data.sort((a, b) => a.sortNo - b.sortNo)
|
||||
// 【关键修改】去掉 response.data.data,直接取 response.data
|
||||
if (response.code === 200 && response.data) {
|
||||
allData.value = response.data.sort((a, b) => a.sortNo - b.sortNo)
|
||||
total.value = allData.value.length
|
||||
currentPage.value = 1 // 搜索后重置到第一页
|
||||
applyPagination() // 应用分页
|
||||
currentPage.value = 1
|
||||
applyPagination()
|
||||
} else {
|
||||
ElMessage.error('搜索失败: ' + (response.msg || '未知错误'))
|
||||
allData.value = []
|
||||
@@ -349,20 +349,30 @@ const handleSearch = async () => {
|
||||
}
|
||||
|
||||
// 打开新增模态框方法
|
||||
// index.vue
|
||||
|
||||
const showAddDialog = () => {
|
||||
// 重置表单数据
|
||||
// 1. 算出当前最大的排序号
|
||||
// 如果列表是空的,就从 1 开始;如果不空,取第一条(因为我们排过序了)或遍历找最大值
|
||||
let maxSortNo = 0
|
||||
if (allData.value && allData.value.length > 0) {
|
||||
// 既然 allData 已经按 sortNo 排序了,那最后一个就是最大的?
|
||||
// 或者保险起见,用 Math.max 算一下
|
||||
maxSortNo = Math.max(...allData.value.map(item => item.sortNo || 0))
|
||||
}
|
||||
|
||||
// 2. 重置表单,并将排序号设为 最大值 + 1
|
||||
addForm.value = {
|
||||
phraseName: '',
|
||||
phraseContent: '',
|
||||
sortNo: 1,
|
||||
sortNo: maxSortNo + 1, // <--- 这样每次打开就是 2, 3, 4...
|
||||
phraseType: 1,
|
||||
phraseCategory: ''
|
||||
}
|
||||
// 重置表单验证状态
|
||||
|
||||
if (addFormRef.value) {
|
||||
addFormRef.value.clearValidate()
|
||||
}
|
||||
// 打开模态框
|
||||
addDialogVisible.value = true
|
||||
}
|
||||
|
||||
@@ -434,7 +444,6 @@ const handleDelete = async (row) => {
|
||||
// 用户取消删除时不提示错误
|
||||
if (error !== 'cancel') {
|
||||
console.error('删除失败:', error)
|
||||
ElMessage.error('删除操作失败: 网络异常或权限不足')
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -455,39 +464,41 @@ const showEditDialog = (row) => {
|
||||
}
|
||||
|
||||
// 编辑表单提交保存方法
|
||||
// 修改 index.vue 中的 handleEditSave 方法
|
||||
const handleEditSave = async () => {
|
||||
try {
|
||||
// 先执行表单验证
|
||||
// 1. 表单校验
|
||||
const validateResult = await editFormRef.value.validate()
|
||||
if (!validateResult) return
|
||||
|
||||
// 名称唯一性校验(排除当前编辑的这条记录ID)
|
||||
// 2. 名称唯一性校验
|
||||
const nameValidation = validatePhraseName(editForm.value.phraseName, editForm.value.id)
|
||||
if (!nameValidation.valid) {
|
||||
ElMessage.error(nameValidation.message)
|
||||
return
|
||||
}
|
||||
|
||||
// 准备更新数据,修复时间格式为ISO字符串,适配后端LocalDateTime
|
||||
// 3. 准备数据
|
||||
const updateData = {
|
||||
...editForm.value,
|
||||
enableFlag: 1,
|
||||
updateTime: new Date().toISOString() // 前端临时赋值,后端最终以自己的为准
|
||||
updateTime: new Date().toISOString()
|
||||
}
|
||||
|
||||
// 调用更新接口
|
||||
// 4. 调用接口
|
||||
const response = await updateDoctorPhrase(updateData)
|
||||
|
||||
// 【核心修改】直接判断 code === 200 即可
|
||||
// 因为后端现在失败会返回 R.fail (code!=200),所以只要是 200 就是成功
|
||||
if (response.code === 200) {
|
||||
ElMessage.success('更新成功')
|
||||
ElMessage.success(response.msg || '更新成功') // 优先显示后端返回的消息
|
||||
editDialogVisible.value = false
|
||||
// 重新拉取数据,保证列表数据最新
|
||||
fetchDoctorPhraseList()
|
||||
} else {
|
||||
ElMessage.error('更新失败: ' + (response.msg || '未知错误'))
|
||||
ElMessage.error(response.msg || '更新失败')
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('更新失败:', error)
|
||||
ElMessage.error('更新操作失败: 网络请求错误')
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user