Преглед на файлове

perf(components): 优化“选择标准参数”组件逻辑

1. 新增参数时多选,变更参数时单选
2. 支持变更参数
wangcong преди 2 месеца
родител
ревизия
203d6be9af
променени са 3 файла, в които са добавени 38 реда и са изтрити 11 реда
  1. 7 0
      src/api/index.ts
  2. 1 0
      src/i18n/locales/zh.json
  3. 30 11
      src/views/setup-protocol/SelectStandardParams.vue

+ 7 - 0
src/api/index.ts

@@ -640,6 +640,13 @@ export const addProtocolParam = async (params: Partial<ProtocolParamInfo>) => {
   });
 };
 
+export const updateProtocolParam = async (params: Partial<ProtocolParamInfo>) => {
+  await request(apiBiz('/protocolParamInfo/update'), {
+    method: 'POST',
+    body: JSON.stringify(params),
+  });
+};
+
 export const getProtocolParamList = async (params: ProtocolParamSearchParams) => {
   const data = await request<ProtocolParamData>(apiBiz('/protocolParamInfo/getPageList'), {
     method: 'POST',

+ 1 - 0
src/i18n/locales/zh.json

@@ -412,6 +412,7 @@
     "selectedParams": "已选",
     "setupProtocol": "配置协议",
     "stopBit": "停止位",
+    "updateStandardParamsSuccessful": "变更标准参数成功",
     "uploadFile": "上传文件",
     "uploadFileFormat": "支持扩展名:.xls,xlsx",
     "uploadFileTip": "单击或拖动文件到此区域以上传",

+ 30 - 11
src/views/setup-protocol/SelectStandardParams.vue

@@ -1,5 +1,5 @@
 <script setup lang="ts">
-import { ref, watch } from 'vue';
+import { computed, ref, watch } from 'vue';
 import { message } from 'ant-design-vue';
 import { debounce } from 'lodash-es';
 
@@ -7,13 +7,14 @@ import SvgIcon from '@/components/SvgIcon.vue';
 import { useRequest } from '@/hooks/request';
 import { useViewVisible } from '@/hooks/view-visible';
 import { t } from '@/i18n';
-import { addProtocolParam, getProtocolStandardParamList } from '@/api';
+import { addProtocolParam, getProtocolStandardParamList, updateProtocolParam } from '@/api';
 
-import type { Key } from 'ant-design-vue/es/table/interface';
+import type { Key, RowSelectionType } from 'ant-design-vue/es/table/interface';
 import type { PageParams, ProtocolStandardParam } from '@/types';
 
 interface Props {
   protocolId?: number;
+  paramId?: number;
 }
 
 const props = defineProps<Props>();
@@ -22,6 +23,7 @@ const emit = defineEmits<{
   refreshList: [];
 }>();
 
+const isAddParams = ref(true);
 const paramList = ref<ProtocolStandardParam[]>([]);
 const paramTotal = ref(0);
 const paramNameOrCode = ref('');
@@ -38,6 +40,10 @@ const pageParams = ref<PageParams>({
 
 const { isLoading, handleRequest } = useRequest();
 
+const setIsAddParams = (isAdd: boolean) => {
+  isAddParams.value = isAdd;
+};
+
 const getStandardParams = () => {
   handleRequest(async () => {
     const { records, total } = await getProtocolStandardParamList({
@@ -73,6 +79,10 @@ const handlePageChange = (page: number, pageSize: number) => {
 const selectedParamIds = ref<number[]>([]);
 const selectedParams = ref<ProtocolStandardParam[]>([]);
 
+const selectionType = computed<RowSelectionType>(() => {
+  return isAddParams.value ? 'checkbox' : 'radio';
+});
+
 const handleParamSelectChange = (selectedRowKeys: Key[], selectedRows: ProtocolStandardParam[]) => {
   selectedParamIds.value = selectedRowKeys as number[];
   selectedParams.value = selectedRows;
@@ -97,17 +107,24 @@ const handleOk = () => {
   }
 
   handleAddParamRequest(async () => {
-    for (const item of selectedParams.value) {
-      await addProtocolParam({
-        baseInfoId: props.protocolId,
-        paramCode: item.platformParamCode,
-        paramName: item.platformParamName,
-        unit: item.unit,
-        module: item.module,
+    if (isAddParams.value) {
+      for (const item of selectedParams.value) {
+        await addProtocolParam({
+          baseInfoId: props.protocolId,
+          ...item,
+        });
+      }
+
+      message.success(t('setupProtocol.addStandardParamsSuccessful'));
+    } else {
+      await updateProtocolParam({
+        ...selectedParams.value[0],
+        id: props.paramId,
       });
+
+      message.success(t('setupProtocol.updateStandardParamsSuccessful'));
     }
 
-    message.success(t('setupProtocol.addStandardParamsSuccessful'));
     hideView();
     emit('refreshList');
   });
@@ -125,6 +142,7 @@ const handleClose = () => {
 defineExpose({
   showView,
   hideView,
+  setIsAddParams,
 });
 </script>
 
@@ -158,6 +176,7 @@ defineExpose({
           :data-source="paramList"
           row-key="id"
           :row-selection="{
+            type: selectionType,
             selectedRowKeys: selectedParamIds,
             preserveSelectedRowKeys: true,
             onChange: handleParamSelectChange,