Commit 26c03b64 by 史雅文

处理采集项bug

parent c4924f07
...@@ -6,13 +6,13 @@ VITE_PUBLIC_PATH=/ ...@@ -6,13 +6,13 @@ VITE_PUBLIC_PATH=/
# 本地开发代理(解决跨域) # 本地开发代理(解决跨域)
# 所有匹配前缀的请求将被代理到目标服务器 # 所有匹配前缀的请求将被代理到目标服务器
VITE_PROXY=[["/system","http://localhost:8080"],["/language","http://localhost:8080"],["/api","http://localhost:8080"]] VITE_PROXY=[["/system","http://192.168.8.136:8080"],["/language","http://192.168.8.136:8080"],["/api","http://192.168.8.136:8080"]]
# 是否删除Console.log # 是否删除Console.log
VITE_DROP_CONSOLE=false VITE_DROP_CONSOLE=false
# 接口地址(用于代码中生成 baseURL) # 接口地址(用于代码中生成 baseURL)
VITE_GLOB_API_URL=http://localhost:8080 VITE_GLOB_API_URL=http://192.168.8.136:8080
# 文件上传接口 # 文件上传接口
VITE_GLOB_UPLOAD_URL=/system/oss/upload VITE_GLOB_UPLOAD_URL=/system/oss/upload
......
...@@ -29,21 +29,6 @@ export async function getMesCollectionItemPage(params: MesCollectionItemPagePara ...@@ -29,21 +29,6 @@ export async function getMesCollectionItemPage(params: MesCollectionItemPagePara
} }
/** /**
* @description: 查询MesCollectionItem列表(不分页)
*/
export async function getMesCollectionItemList(params?: MesCollectionItemPageParams, mode: ErrorMessageMode = 'modal') {
return defHttp.get<MesCollectionItemPageModel[]>(
{
url: Api.List,
params,
},
{
errorMessageMode: mode,
},
);
}
/**
* @description: 获取MesCollectionItem信息 * @description: 获取MesCollectionItem信息
*/ */
export async function getMesCollectionItem(id: String, mode: ErrorMessageMode = 'modal') { export async function getMesCollectionItem(id: String, mode: ErrorMessageMode = 'modal') {
......
...@@ -1667,21 +1667,12 @@ ...@@ -1667,21 +1667,12 @@
localStorage.setItem('tableColumnShowSetting', JSON.stringify(obj)); localStorage.setItem('tableColumnShowSetting', JSON.stringify(obj));
} }
// 获取采集项表单API(用于采集方案页面)
const collectionItemFormApi = inject('collectionItemFormApi', null);
function customClick(executeButton, record?, index?) { function customClick(executeButton, record?, index?) {
curRecord.value = index; curRecord.value = index;
curButtonModalConfig.value = executeButton.modal; curButtonModalConfig.value = executeButton.modal;
// 特殊处理:如果是选择采集项按钮,直接调用provide的方法
if (executeButton.key === 'selectCollectionItem' && collectionItemFormApi) {
if (collectionItemFormApi.openCollectionItemSelect) {
collectionItemFormApi.openCollectionItemSelect();
}
return;
}
let obj = { let obj = {
selectedRows: selectedRowsData.value, selectedRows: selectedRowsData.value,
tableDatas: data.value, tableDatas: data.value,
......
<template>
<BasicModal
v-bind="$attrs"
@register="registerModal"
title="选择采集项"
width="800"
@ok="handleSubmit"
@cancel="handleCancel"
:destroyOnClose="true"
>
<BasicTable @register="registerTable" />
</BasicModal>
</template>
<script lang="ts" setup>
import { ref, nextTick } from 'vue';
import { BasicModal, useModalInner } from '/@/components/Modal';
import { BasicTable, useTable } from '/@/components/Table';
import { getMesCollectionItemPage } from '/@/api/jcsj/cjx';
import { columns } from './collectionItemColumns';
import { useMessage } from '/@/hooks/web/useMessage';
const emit = defineEmits(['success']);
const { createMessage } = useMessage();
const contentType = ref<string>('');
const getExistingItemIds = ref<(() => string[]) | null>(null); // 获取已存在的采集项ID列表的函数
// 表格配置:不再维护外部 selection 状态
const [registerTable, {
reload,
clearSelectedRowKeys,
getSelectRows,
getDataSource,
setTableData
}] = useTable({
title: '采集项列表',
rowSelection: {
type: 'checkbox',
},
api: async (params) => {
if (!contentType.value) {
createMessage.warning('请先选择采集内容');
return { list: [], total: 0 };
}
const ctParam = String(contentType.value || '');
if (!ctParam) return { list: [], total: 0 };
const queryParams = {
...params,
contentType: ctParam,
size: Math.min(params.pageSize || 50, 100),
};
try {
const result = await getMesCollectionItemPage(queryParams);
// 兼容多种返回格式
if (Array.isArray(result)) {
return { list: result, total: result.length };
}
if (result?.list) {
return { list: result.list, total: result.total ?? result.list.length };
}
if (result?.records) {
return { list: result.records, total: result.total ?? result.records.length };
}
// 泛型兼容:找第一个数组字段
for (const key in result) {
if (Array.isArray(result[key])) {
return { list: result[key], total: result.total ?? result[key].length };
}
}
} catch (error: any) {
console.error('获取采集项失败:', error);
createMessage.error(error?.message || '请求失败');
}
return { list: [], total: 0 };
},
columns,
pagination: { pageSize: 50 },
rowKey: 'id',
canResize: false,
showIndexColumn: false,
useSearchForm: false,
});
// 弹窗注册
const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
// 先重置所有状态,确保按钮可用
setModalProps({
confirmLoading: false,
destroyOnClose: true,
});
// 提取 contentType
let ctValue = data?.contentType;
if (Array.isArray(ctValue)) ctValue = ctValue[0];
contentType.value = ctValue ? String(ctValue) : '';
// 保存获取已存在采集项ID列表的函数
getExistingItemIds.value = typeof data?.getExistingItemIds === 'function'
? data.getExistingItemIds
: null;
if (!contentType.value) {
createMessage.warning('请先选择采集内容');
closeModal();
return;
}
// 等待 DOM 更新
await nextTick();
// 清除可能遗留的选中状态和数据
if (clearSelectedRowKeys) {
clearSelectedRowKeys();
}
if (setTableData) {
setTableData([]);
}
// 重新加载对应类型的数据
await reload();
// 再次确保选中已清空
await nextTick();
if (clearSelectedRowKeys) {
clearSelectedRowKeys();
}
// 确保按钮状态正确
setModalProps({
confirmLoading: false,
});
});
// 提交处理:直接从表格获取选中行
async function handleSubmit() {
try {
// 设置加载状态,防止重复点击
setModalProps({ confirmLoading: true });
const selectedRows = getSelectRows();
console.log('handleSubmit - selectedRows:', selectedRows);
if (!selectedRows || selectedRows.length === 0) {
createMessage.warning('请至少选择一个采集项');
setModalProps({ confirmLoading: false });
return;
}
// 在提交时实时获取最新的采集项列表,检查是否重复
let currentExistingItemIds: string[] = [];
if (getExistingItemIds.value) {
try {
const ids = getExistingItemIds.value();
currentExistingItemIds = Array.isArray(ids)
? ids.map(id => String(id)).filter(Boolean)
: [];
} catch (error) {
console.error('获取已存在的采集项列表失败:', error);
}
}
// 检查是否与已存在的采集项重复
const duplicateItems: any[] = [];
selectedRows.forEach((item: any) => {
const itemId = String(item.id || '');
if (currentExistingItemIds.includes(itemId)) {
duplicateItems.push(item);
}
});
if (duplicateItems.length > 0) {
const names = duplicateItems.map(item => item.name || item.code || item.id).join('、');
createMessage.warning(`以下采集项已存在,不可重复选择:${names}`);
setModalProps({ confirmLoading: false });
return;
}
// 触发成功事件
emit('success', selectedRows);
// 重置加载状态
setModalProps({ confirmLoading: false });
// 清空所有数据和状态(这些操作即使失败也不应该影响成功流程)
try {
if (clearSelectedRowKeys) {
clearSelectedRowKeys();
}
if (setTableData) {
setTableData([]);
}
} catch (cleanupError) {
console.warn('清空数据时出错(不影响提交):', cleanupError);
}
// 使用 nextTick 确保状态更新后再关闭
await nextTick();
closeModal();
} catch (error) {
console.error('提交失败:', error);
createMessage.error('提交失败,请重试');
setModalProps({ confirmLoading: false });
}
}
// 取消处理
function handleCancel() {
// 确保按钮状态正确
setModalProps({ confirmLoading: false });
// 清空所有数据和状态
if (clearSelectedRowKeys) {
clearSelectedRowKeys();
}
if (setTableData) {
setTableData([]);
}
closeModal();
}
</script>
<template>
<BasicModal
v-bind="$attrs"
@register="registerModal"
title="选择采集项"
@ok="handleSubmit"
@visible-change="handleVisibleChange"
@cancel="handleCancel"
width="800px"
:height="600"
>
<BasicTable @register="registerTable" />
</BasicModal>
</template>
<script lang="ts" setup>
import { ref } from 'vue';
import { BasicModal, useModalInner } from '/@/components/Modal';
import { BasicTable, useTable } from '/@/components/Table';
import { FormSchema } from '/@/components/Form';
import { BasicColumn } from '/@/components/Table';
import { getMesCollectionItemPage } from '/@/api/jcsj/cjx';
import { useI18n } from '/@/hooks/web/useI18n';
const { t } = useI18n();
const emit = defineEmits(['success', 'register']);
const contentType = ref<string>('');
const searchFormSchema: FormSchema[] = [
{
field: 'code',
label: '编码',
component: 'Input',
colProps: { span: 8 },
},
{
field: 'name',
label: '名称',
component: 'Input',
colProps: { span: 8 },
},
];
const columns: BasicColumn[] = [
{
title: '编码',
dataIndex: 'code',
width: 150,
},
{
title: '名称',
dataIndex: 'name',
width: 200,
},
{
title: '采集内容',
dataIndex: 'contentType',
width: 150,
},
{
title: '备注',
dataIndex: 'note',
width: 200,
},
];
const [registerTable, { getSelectRows, reload, clearSelectedRowKeys, getForm }] = useTable({
title: '采集项列表',
api: getMesCollectionItemPage,
rowKey: 'id',
columns,
formConfig: {
labelWidth: 70,
schemas: searchFormSchema,
},
rowSelection: {
type: 'checkbox',
},
useSearchForm: true,
showTableSetting: false,
bordered: true,
pagination: {
pageSize: 10,
},
beforeFetch: (params) => {
// 根据选择的采集内容过滤
if (contentType.value) {
params.contentType = contentType.value;
}
return params;
},
});
const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
contentType.value = data?.contentType || '';
setModalProps({ confirmLoading: false });
await reload();
});
// 清空弹窗内的操作
function clearModalOperations() {
// 清空表格选中项
clearSelectedRowKeys();
// 重置搜索表单
const form = getForm();
if (form) {
form.resetFields();
}
}
// 处理弹窗可见性变化
function handleVisibleChange(visible: boolean) {
// 当弹窗关闭时,清空操作
if (!visible) {
clearModalOperations();
}
}
// 处理取消事件
function handleCancel() {
clearModalOperations();
}
const handleSubmit = () => {
const selectedRows = getSelectRows();
if (selectedRows.length === 0) {
return;
}
emit('success', selectedRows);
closeModal();
};
</script>
import { BasicColumn } from '/@/components/Table';
export const columns: BasicColumn[] = [
{
title: '编码',
dataIndex: 'code',
width: 150,
},
{
title: '名称',
dataIndex: 'name',
width: 200,
},
{
title: '数据类型',
dataIndex: 'dataType',
width: 120,
},
{
title: '备注',
dataIndex: 'note',
width: 200,
},
];
...@@ -409,7 +409,7 @@ export const formProps: FormProps = { ...@@ -409,7 +409,7 @@ export const formProps: FormProps = {
suffix: '', suffix: '',
addonBefore: '', addonBefore: '',
addonAfter: '', addonAfter: '',
disabled: (record: any) => record?._isFromSelect === true, disabled: true,
allowClear: false, allowClear: false,
showLabel: true, showLabel: true,
required: false, required: false,
...@@ -440,7 +440,7 @@ export const formProps: FormProps = { ...@@ -440,7 +440,7 @@ export const formProps: FormProps = {
suffix: '', suffix: '',
addonBefore: '', addonBefore: '',
addonAfter: '', addonAfter: '',
disabled: (record: any) => record?._isFromSelect === true, disabled: true,
allowClear: false, allowClear: false,
showLabel: true, showLabel: true,
required: false, required: false,
...@@ -468,7 +468,7 @@ export const formProps: FormProps = { ...@@ -468,7 +468,7 @@ export const formProps: FormProps = {
showSearch: false, showSearch: false,
isMultiple: false, isMultiple: false,
clearable: false, clearable: false,
disabled: (record: any) => record?._isFromSelect === true, disabled: true,
staticOptions: [ staticOptions: [
{ key: 1, label: 'Option 1', value: 'Option 1' }, { key: 1, label: 'Option 1', value: 'Option 1' },
{ key: 2, label: 'Option 2', value: 'Option 2' }, { key: 2, label: 'Option 2', value: 'Option 2' },
...@@ -510,7 +510,7 @@ export const formProps: FormProps = { ...@@ -510,7 +510,7 @@ export const formProps: FormProps = {
suffix: '', suffix: '',
addonBefore: '', addonBefore: '',
addonAfter: '', addonAfter: '',
disabled: (record: any) => record?._isFromSelect === true, disabled: true,
allowClear: false, allowClear: false,
showLabel: true, showLabel: true,
required: false, required: false,
...@@ -567,7 +567,7 @@ export const formProps: FormProps = { ...@@ -567,7 +567,7 @@ export const formProps: FormProps = {
buttonName: '选择数据', buttonName: '选择数据',
showLabel: true, showLabel: true,
showComponentBorder: true, showComponentBorder: true,
showBorder: true, showBorder: false,
bordercolor: '#f0f0f0', bordercolor: '#f0f0f0',
bordershowtype: [true, true, true, true], bordershowtype: [true, true, true, true],
borderwidth: 1, borderwidth: 1,
...@@ -603,20 +603,12 @@ export const formProps: FormProps = { ...@@ -603,20 +603,12 @@ export const formProps: FormProps = {
checked: false, checked: false,
}, },
], ],
isShowAdd: false, isShowAdd: true,
isShowDelete: true, isShowDelete: true,
hasCheckedCol: true, hasCheckedCol: true,
events: {}, events: {},
showPagenation: true, showPagenation: true,
showColunmSet: false, showColunmSet: false,
topButtonList: [
{
key: 'selectCollectionItem',
label: '新增',
style: 'primary',
icon: 'ant-design:plus-outlined',
},
],
}, },
}, },
], ],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment