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