医生常用语维护->名称字数限制、前端名称唯一性校验等

This commit is contained in:
2025-12-30 14:26:14 +08:00
parent 1b2c248fa2
commit 91cb465962
2 changed files with 72 additions and 26 deletions

View File

@@ -13,11 +13,11 @@ export function getDoctorPhraseList() {
/**
* 搜索医生常用语
*/
export function searchDoctorPhraseList(phraseName, phraseType, phraseCategory) {
export function searchDoctorPhraseList(phraseName, phraseType) {
return request({
url: '/Doctor-phrase/search',
method: 'get',
params: { phraseName, phraseType, phraseCategory }
params: { phraseName, phraseType }
})
}

View File

@@ -3,9 +3,9 @@
<!-- 搜索栏 -->
<div class="search-bar">
<el-select v-model="searchScope" placeholder="范围" style="width: 120px;">
<el-option label="个人" value="1"></el-option>
<el-option label="科室" value="2"></el-option>
<el-option label="全院" value="3"></el-option>
<el-option label="个人" :value="1"></el-option>
<el-option label="科室" :value="2"></el-option>
<el-option label="全院" :value="3"></el-option>
</el-select>
<el-input
v-model="searchKeyword"
@@ -14,6 +14,7 @@
@keyup.enter="handleSearch"
></el-input>
<el-button style="margin-left: 10px;" @click="handleSearch"><el-icon><Search /></el-icon> 查询</el-button>
<el-button style="margin-left: 10px;" @click="handleReset"><el-icon><Refresh /></el-icon> 重置</el-button>
<el-button type="primary" style="margin-left: 10px;" @click="showAddDialog"><el-icon><Plus /></el-icon> 增加</el-button>
</div>
@@ -36,7 +37,9 @@
<el-input
v-if="editingId === scope.row.id"
v-model="editForm.phraseName"
placeholder="请输入名称"
placeholder="请输入名称(不超过50字)"
maxlength="50"
show-word-limit
style="width: 100%"
/>
<span v-else>{{ scope.row.phraseName }}</span>
@@ -137,7 +140,7 @@
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
:current-page="currentPage"
:page-sizes="[10, 20, 50, 100]"
:page-sizes="[15, 30, 50]"
:page-size="pageSize"
layout="total, prev, pager, next, jumper, sizes"
:total="total"
@@ -153,7 +156,7 @@
>
<el-form ref="addFormRef" :model="addForm" :rules="rules" label-width="100px" class="add-form">
<el-form-item label="名称" prop="phraseName" required>
<el-input v-model="addForm.phraseName" placeholder="请输入常用语名称" style="width: 100%;"></el-input>
<el-input v-model="addForm.phraseName" placeholder="请输入常用语名称(不超过50字)" maxlength="50" show-word-limit style="width: 100%;"></el-input>
</el-form-item>
<el-form-item label="内容" prop="phraseContent" required>
<el-input
@@ -200,21 +203,21 @@
<script setup>
import { ref, onMounted } from 'vue'
import { Search, Plus, Check, Close } from '@element-plus/icons-vue'
import { Search, Plus, Check, Close, Refresh } from '@element-plus/icons-vue'
import { getDoctorPhraseList, searchDoctorPhraseList, addDoctorPhrase, deleteDoctorPhrase, updateDoctorPhrase } from './api'
import { ElMessage, ElMessageBox } from 'element-plus'
import { useDict } from '@/utils/dict'
// 搜索条件
const searchScope = ref('个人')
const searchKeyword = ref('')
const searchScope = ref(null) // null表示未选择数字类型1=个人2=科室3=全院
const searchKeyword = ref('')
// 表格数据
const tableData = ref([])
// 分页
const currentPage = ref(1)
const pageSize = ref(10)
const pageSize = ref(15)
const total = ref(0)
// 新增模态框相关
@@ -276,6 +279,33 @@ const getScopeName = (scope) => {
return scopeMap[scope] || '未知范围'
}
// 名称唯一性校验函数
const validatePhraseName = (phraseName, excludeId = null) => {
if (!phraseName || !phraseName.trim()) {
return { valid: false, message: '请输入常用语名称' }
}
// 检查字数限制
if (phraseName.trim().length > 50) {
return { valid: false, message: '常用语名称不能超过50字' }
}
// 检查名称是否已存在
const existingPhrase = allData.value.find(item => {
// 排除自身(更新时)
if (excludeId && item.id === excludeId) {
return false
}
return item.phraseName === phraseName.trim()
})
if (existingPhrase) {
return { valid: false, message: '常用语名称已存在,请输入不同的名称' }
}
return { valid: true, message: '' }
}
// 所有数据(用于客户端分页)
const allData = ref([])
@@ -302,6 +332,16 @@ const fetchDoctorPhraseList = async () => {
}
}
// 重置功能
const handleReset = () => {
// 重置搜索条件
searchScope.value = null
searchKeyword.value = ''
// 重新加载所有数据
fetchDoctorPhraseList()
}
// 客户端分页处理
const applyPagination = () => {
const start = (currentPage.value - 1) * pageSize.value
@@ -323,21 +363,13 @@ const handleCurrentChange = (val) => {
// 搜索功能
const handleSearch = async () => {
try {
// 根据搜索范围确定phraseType
// 这里需要根据实际业务逻辑映射,暂时使用默认值
const phraseType = 1
// searchScope可能是null未选择、1=个人2=科室3=全院
const searchScopeValue = searchScope.value
const phraseType = searchScopeValue === null ? undefined : searchScopeValue
// 如果需要使用searchScope进行搜索需要将字符串转换为对应的数字
const scopeMap = {
'个人': 1,
'科室': 2,
'全院': 3
}
const searchScopeValue = scopeMap[searchScope.value] || 1
// 调用搜索接口
// 注意根据后端API要求这里的参数顺序可能需要调整
const response = await searchDoctorPhraseList(searchKeyword.value, searchScopeValue, phraseType)
// 调用搜索接口phraseName, phraseType
// 如果phraseType为undefined则后端不会按范围过滤查询所有数据
const response = await searchDoctorPhraseList(searchKeyword.value, phraseType)
// 处理后端返回的数据结构data.data
if (response.code === 200 && response.data && response.data.data) {
@@ -378,6 +410,13 @@ const handleAdd = async () => {
// 验证表单
await addFormRef.value.validate()
// 名称唯一性校验
const nameValidation = validatePhraseName(addForm.value.phraseName)
if (!nameValidation.valid) {
ElMessage.error(nameValidation.message)
return
}
// 添加数据库要求的必填默认字段
const formData = {
...addForm.value,
@@ -484,6 +523,13 @@ const handleSave = async () => {
return
}
// 名称唯一性校验(排除当前记录)
const nameValidation = validatePhraseName(editForm.value.phraseName, editingId.value)
if (!nameValidation.valid) {
ElMessage.error(nameValidation.message)
return
}
// 准备更新数据
const updateData = {
...editForm.value,