2025-10-22 15:09:56 +08:00
|
|
|
|
<script setup lang="ts">
|
|
|
|
|
|
import type { VbenFormProps } from '#/adapter/form';
|
|
|
|
|
|
import type { VxeGridProps } from '#/adapter/vxe-table';
|
|
|
|
|
|
|
2025-12-17 11:19:31 +08:00
|
|
|
|
import { h, nextTick, onMounted, ref, watch } from 'vue';
|
|
|
|
|
|
import { useRoute } from 'vue-router';
|
2025-10-22 15:09:56 +08:00
|
|
|
|
|
2025-12-17 11:19:31 +08:00
|
|
|
|
import { Page, useVbenModal } from '@vben/common-ui';
|
2025-10-22 15:09:56 +08:00
|
|
|
|
|
2025-12-17 11:19:31 +08:00
|
|
|
|
import { message as Message, Tag } from 'ant-design-vue';
|
2025-10-22 15:09:56 +08:00
|
|
|
|
|
|
|
|
|
|
import { useVbenForm } from '#/adapter/form';
|
|
|
|
|
|
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
|
|
|
|
|
import {
|
2025-12-17 15:51:26 +08:00
|
|
|
|
postCtWingProductListAsync,
|
2025-12-01 16:31:57 +08:00
|
|
|
|
postIoTplatformThingModelInfoCopyAnotherThingModelAsync,
|
|
|
|
|
|
postIoTplatformThingModelInfoCopyStandardThingModel,
|
|
|
|
|
|
postIoTplatformThingModelInfoCreateAsync,
|
|
|
|
|
|
postIoTplatformThingModelInfoDeleteAsync,
|
|
|
|
|
|
postIoTplatformThingModelInfoPageAsync,
|
|
|
|
|
|
postIoTplatformThingModelInfoUpdateAsync,
|
2025-12-17 15:51:26 +08:00
|
|
|
|
postOneNetProductListAsync,
|
2025-10-22 15:09:56 +08:00
|
|
|
|
} from '#/api-client';
|
|
|
|
|
|
import { TableAction } from '#/components/table-action';
|
|
|
|
|
|
import { $t } from '#/locales';
|
|
|
|
|
|
|
|
|
|
|
|
import {
|
|
|
|
|
|
addThingModelFormSchema,
|
2025-10-23 11:48:10 +08:00
|
|
|
|
copyThingModelFormSchema,
|
2025-10-22 15:09:56 +08:00
|
|
|
|
editThingModelFormSchema,
|
|
|
|
|
|
querySchema,
|
|
|
|
|
|
tableSchema,
|
|
|
|
|
|
} from './schema';
|
|
|
|
|
|
|
|
|
|
|
|
defineOptions({
|
2025-12-17 11:19:31 +08:00
|
|
|
|
name: 'IoTPlatformThingModelInfo',
|
2025-10-22 15:09:56 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
2025-12-17 11:19:31 +08:00
|
|
|
|
const route = useRoute();
|
2025-10-22 15:09:56 +08:00
|
|
|
|
|
2025-12-17 11:19:31 +08:00
|
|
|
|
// 从路由参数获取产品信息
|
|
|
|
|
|
const productId = ref<string>((route.query.productId as string) || '');
|
|
|
|
|
|
const productName = ref<string>((route.query.productName as string) || '');
|
|
|
|
|
|
const ioTPlatform = ref<string>((route.query.ioTPlatform as string) || '2');
|
2025-10-23 09:37:23 +08:00
|
|
|
|
|
2025-10-22 15:09:56 +08:00
|
|
|
|
const formOptions: VbenFormProps = {
|
|
|
|
|
|
schema: querySchema.value,
|
2025-12-17 15:51:26 +08:00
|
|
|
|
initialValues: {
|
|
|
|
|
|
ioTPlatform: route.query.ioTPlatform ? String(route.query.ioTPlatform) : undefined,
|
|
|
|
|
|
ioTPlatformProductId: route.query.productId ? String(route.query.productId) : undefined,
|
|
|
|
|
|
},
|
|
|
|
|
|
submitOnChange: false,
|
|
|
|
|
|
handleValuesChange: async (values, changedFields) => {
|
|
|
|
|
|
// 当平台类型变化时,清空产品ID
|
|
|
|
|
|
if (changedFields.includes('ioTPlatform')) {
|
|
|
|
|
|
if (values.ioTPlatform) {
|
|
|
|
|
|
ioTPlatform.value = String(values.ioTPlatform);
|
|
|
|
|
|
// 清空产品ID,因为平台变化了
|
|
|
|
|
|
if (gridApi?.formApi) {
|
|
|
|
|
|
await gridApi.formApi.setValues({
|
|
|
|
|
|
ioTPlatformProductId: undefined,
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
productId.value = '';
|
|
|
|
|
|
productName.value = '';
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 当产品ID变化时,更新响应式变量并重新加载数据
|
|
|
|
|
|
if (changedFields.includes('ioTPlatformProductId')) {
|
|
|
|
|
|
if (values.ioTPlatformProductId) {
|
|
|
|
|
|
productId.value = String(values.ioTPlatformProductId);
|
|
|
|
|
|
// 从产品列表中获取产品名称
|
|
|
|
|
|
const platform = values.ioTPlatform;
|
|
|
|
|
|
if (platform) {
|
|
|
|
|
|
try {
|
|
|
|
|
|
const api = platform === 2 || platform === '2'
|
|
|
|
|
|
? postOneNetProductListAsync
|
|
|
|
|
|
: platform === 1 || platform === '1'
|
|
|
|
|
|
? postCtWingProductListAsync
|
|
|
|
|
|
: null;
|
|
|
|
|
|
if (api) {
|
|
|
|
|
|
const { data } = await api({
|
|
|
|
|
|
body: {
|
|
|
|
|
|
pageIndex: 1,
|
|
|
|
|
|
pageSize: 1000,
|
|
|
|
|
|
},
|
|
|
|
|
|
});
|
|
|
|
|
|
const items = data?.items || [];
|
|
|
|
|
|
const selectedProduct = items.find((item: any) =>
|
|
|
|
|
|
String(item.ioTPlatformProductId) === String(values.ioTPlatformProductId)
|
|
|
|
|
|
);
|
|
|
|
|
|
if (selectedProduct) {
|
|
|
|
|
|
productName.value = selectedProduct.productName || '';
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
console.error('获取产品名称失败:', error);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
productId.value = '';
|
|
|
|
|
|
productName.value = '';
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 延迟重新加载数据,确保表单值已更新
|
|
|
|
|
|
setTimeout(async () => {
|
|
|
|
|
|
if (gridApi && gridApi.reload) {
|
|
|
|
|
|
try {
|
|
|
|
|
|
await gridApi.reload();
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
console.error('重新加载数据时出错:', error);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}, 100);
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
2025-10-22 15:09:56 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const gridOptions: VxeGridProps<any> = {
|
|
|
|
|
|
checkboxConfig: {
|
|
|
|
|
|
highlight: true,
|
|
|
|
|
|
labelField: 'thingModelName',
|
|
|
|
|
|
},
|
|
|
|
|
|
columns: tableSchema.value,
|
|
|
|
|
|
height: 'auto',
|
|
|
|
|
|
keepSource: true,
|
|
|
|
|
|
pagerConfig: {},
|
|
|
|
|
|
toolbarConfig: {
|
|
|
|
|
|
custom: true,
|
|
|
|
|
|
},
|
|
|
|
|
|
customConfig: {
|
|
|
|
|
|
storage: true,
|
|
|
|
|
|
},
|
|
|
|
|
|
proxyConfig: {
|
|
|
|
|
|
ajax: {
|
|
|
|
|
|
query: async ({ page }, formValues) => {
|
2025-12-17 15:51:26 +08:00
|
|
|
|
// 优先使用表单值,如果没有则使用响应式变量
|
|
|
|
|
|
const currentPlatform = formValues?.ioTPlatform || ioTPlatform.value;
|
|
|
|
|
|
const currentProductId = formValues?.ioTPlatformProductId || productId.value;
|
|
|
|
|
|
|
2025-12-17 11:19:31 +08:00
|
|
|
|
// 如果没有产品ID,直接返回空数据,让表格正常显示空白状态
|
2025-12-17 15:51:26 +08:00
|
|
|
|
if (!currentProductId || !currentPlatform) {
|
2025-12-17 11:19:31 +08:00
|
|
|
|
hasData.value = false;
|
|
|
|
|
|
return {
|
|
|
|
|
|
items: [],
|
|
|
|
|
|
totalCount: 0,
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
const { data } = await postIoTplatformThingModelInfoPageAsync({
|
2025-12-17 15:51:26 +08:00
|
|
|
|
body: {
|
|
|
|
|
|
pageIndex: page.currentPage,
|
|
|
|
|
|
pageSize: page.pageSize,
|
|
|
|
|
|
ioTPlatform: Number.parseInt(String(currentPlatform)) as 1 | 2,
|
|
|
|
|
|
ioTPlatformProductId: String(currentProductId),
|
|
|
|
|
|
...(formValues?.SearchKeyWords && { searchKeyWords: formValues.SearchKeyWords }),
|
2025-12-01 16:31:57 +08:00
|
|
|
|
},
|
2025-12-17 11:19:31 +08:00
|
|
|
|
});
|
|
|
|
|
|
// 更新数据状态,检查是否有数据
|
|
|
|
|
|
hasData.value = data?.items && data.items.length > 0;
|
|
|
|
|
|
return data || { items: [], totalCount: 0 };
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
console.error('查询物模型信息失败:', error);
|
|
|
|
|
|
hasData.value = false;
|
|
|
|
|
|
return {
|
|
|
|
|
|
items: [],
|
|
|
|
|
|
totalCount: 0,
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
2025-10-22 15:09:56 +08:00
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const [Grid, gridApi] = useVbenVxeGrid({ formOptions, gridOptions });
|
|
|
|
|
|
|
|
|
|
|
|
const editRow: Record<string, any> = ref({});
|
|
|
|
|
|
|
2025-10-23 11:48:10 +08:00
|
|
|
|
// 跟踪数据状态,用于控制按钮显示
|
|
|
|
|
|
const hasData = ref(true);
|
|
|
|
|
|
|
2025-10-22 15:09:56 +08:00
|
|
|
|
const [ThingModelModal, thingModelModalApi] = useVbenModal({
|
|
|
|
|
|
draggable: true,
|
|
|
|
|
|
footer: true,
|
|
|
|
|
|
showCancelButton: true,
|
|
|
|
|
|
showConfirmButton: true,
|
|
|
|
|
|
onConfirm: submit,
|
|
|
|
|
|
onBeforeClose: () => {
|
|
|
|
|
|
return true;
|
|
|
|
|
|
},
|
|
|
|
|
|
onOpenChange: (isOpen: boolean) => {
|
|
|
|
|
|
if (isOpen && editRow.value.id) {
|
|
|
|
|
|
// 编辑模式下,模态框打开后设置表单值
|
|
|
|
|
|
nextTick(() => {
|
|
|
|
|
|
editFormApi.setValues({ ...editRow.value });
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
onCancel: () => {
|
|
|
|
|
|
thingModelModalApi.close();
|
|
|
|
|
|
},
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2025-10-23 11:48:10 +08:00
|
|
|
|
const [CopyModal, copyModalApi] = useVbenModal({
|
|
|
|
|
|
draggable: true,
|
|
|
|
|
|
footer: true,
|
|
|
|
|
|
showCancelButton: true,
|
|
|
|
|
|
showConfirmButton: true,
|
|
|
|
|
|
onConfirm: submitCopy,
|
|
|
|
|
|
onBeforeClose: () => {
|
|
|
|
|
|
return true;
|
|
|
|
|
|
},
|
|
|
|
|
|
onCancel: () => {
|
|
|
|
|
|
copyModalApi.close();
|
|
|
|
|
|
},
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2025-10-22 15:09:56 +08:00
|
|
|
|
const [AddForm, addFormApi] = useVbenForm({
|
|
|
|
|
|
collapsed: false,
|
|
|
|
|
|
commonConfig: {
|
|
|
|
|
|
labelWidth: 110,
|
|
|
|
|
|
componentProps: {
|
|
|
|
|
|
class: 'w-4/5',
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
layout: 'horizontal',
|
|
|
|
|
|
schema: addThingModelFormSchema.value,
|
|
|
|
|
|
showCollapseButton: false,
|
|
|
|
|
|
showDefaultActions: false,
|
|
|
|
|
|
wrapperClass: 'grid-cols-2',
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
const [EditForm, editFormApi] = useVbenForm({
|
|
|
|
|
|
collapsed: false,
|
|
|
|
|
|
commonConfig: {
|
|
|
|
|
|
labelWidth: 110,
|
|
|
|
|
|
componentProps: {
|
|
|
|
|
|
class: 'w-4/5',
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
layout: 'horizontal',
|
|
|
|
|
|
schema: editThingModelFormSchema.value,
|
|
|
|
|
|
showCollapseButton: false,
|
|
|
|
|
|
showDefaultActions: false,
|
|
|
|
|
|
wrapperClass: 'grid-cols-2',
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2025-10-23 11:48:10 +08:00
|
|
|
|
const [CopyForm, copyFormApi] = useVbenForm({
|
|
|
|
|
|
collapsed: false,
|
|
|
|
|
|
commonConfig: {
|
|
|
|
|
|
labelWidth: 110,
|
|
|
|
|
|
componentProps: {
|
|
|
|
|
|
class: 'w-4/5',
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
layout: 'horizontal',
|
|
|
|
|
|
schema: copyThingModelFormSchema.value,
|
|
|
|
|
|
showCollapseButton: false,
|
|
|
|
|
|
showDefaultActions: false,
|
|
|
|
|
|
wrapperClass: 'grid-cols-2',
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2025-12-17 11:19:31 +08:00
|
|
|
|
// 监听路由参数变化,自动加载数据
|
2025-10-22 15:09:56 +08:00
|
|
|
|
watch(
|
2025-12-17 11:19:31 +08:00
|
|
|
|
() => [route.query.productId, route.query.ioTPlatform],
|
|
|
|
|
|
async ([newProductId, newIoTPlatform]) => {
|
|
|
|
|
|
if (newProductId) {
|
|
|
|
|
|
productId.value = newProductId as string;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (newIoTPlatform) {
|
|
|
|
|
|
ioTPlatform.value = newIoTPlatform as string;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (route.query.productName) {
|
|
|
|
|
|
productName.value = route.query.productName as string;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 延迟执行,确保组件完全初始化
|
|
|
|
|
|
if (gridApi) {
|
2025-10-22 15:09:56 +08:00
|
|
|
|
setTimeout(async () => {
|
|
|
|
|
|
try {
|
2025-12-01 16:31:57 +08:00
|
|
|
|
await gridApi.reload();
|
2025-10-22 15:09:56 +08:00
|
|
|
|
} catch (error) {
|
2025-12-17 11:19:31 +08:00
|
|
|
|
console.error('加载数据时出错:', error);
|
2025-10-22 15:09:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
}, 100);
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
2025-12-17 11:19:31 +08:00
|
|
|
|
{ immediate: false },
|
2025-10-22 15:09:56 +08:00
|
|
|
|
);
|
|
|
|
|
|
|
2025-12-17 11:19:31 +08:00
|
|
|
|
// 页面初始化时加载数据
|
|
|
|
|
|
onMounted(async () => {
|
|
|
|
|
|
// 从路由参数初始化
|
|
|
|
|
|
if (route.query.productId) {
|
|
|
|
|
|
productId.value = route.query.productId as string;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (route.query.productName) {
|
|
|
|
|
|
productName.value = route.query.productName as string;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (route.query.ioTPlatform) {
|
|
|
|
|
|
ioTPlatform.value = route.query.ioTPlatform as string;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 延迟加载数据,确保表格已初始化
|
|
|
|
|
|
// 即使没有 productId,也要触发一次查询,让表格显示空白状态
|
|
|
|
|
|
await nextTick();
|
|
|
|
|
|
setTimeout(async () => {
|
|
|
|
|
|
if (gridApi && gridApi.reload) {
|
|
|
|
|
|
try {
|
2025-12-17 15:51:26 +08:00
|
|
|
|
// 如果表单中有值,确保表单值已设置
|
|
|
|
|
|
if (route.query.ioTPlatform || route.query.productId) {
|
|
|
|
|
|
const formValues = await gridApi.formApi.getValues();
|
|
|
|
|
|
if (route.query.ioTPlatform && !formValues.ioTPlatform) {
|
|
|
|
|
|
await gridApi.formApi.setValues({
|
|
|
|
|
|
ioTPlatform: route.query.ioTPlatform,
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
if (route.query.productId && !formValues.ioTPlatformProductId) {
|
|
|
|
|
|
await gridApi.formApi.setValues({
|
|
|
|
|
|
ioTPlatformProductId: route.query.productId,
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
await nextTick();
|
|
|
|
|
|
}
|
2025-12-17 11:19:31 +08:00
|
|
|
|
await gridApi.reload();
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
console.error('初始化加载数据时出错:', error);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}, 300);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2025-10-22 15:09:56 +08:00
|
|
|
|
// 新增和编辑提交的逻辑
|
|
|
|
|
|
async function submit() {
|
2025-12-17 11:19:31 +08:00
|
|
|
|
// 检查是否有产品ID
|
|
|
|
|
|
if (!productId.value) {
|
|
|
|
|
|
Message.error('产品ID不存在,无法保存物模型信息');
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-22 15:09:56 +08:00
|
|
|
|
const isEdit = !!editRow.value.id;
|
|
|
|
|
|
const formApi = isEdit ? editFormApi : addFormApi;
|
|
|
|
|
|
const api = isEdit
|
2025-12-01 16:31:57 +08:00
|
|
|
|
? postIoTplatformThingModelInfoUpdateAsync
|
|
|
|
|
|
: postIoTplatformThingModelInfoCreateAsync;
|
2025-10-22 15:09:56 +08:00
|
|
|
|
const { valid } = await formApi.validate();
|
|
|
|
|
|
if (!valid) return;
|
|
|
|
|
|
|
2025-10-28 13:59:55 +08:00
|
|
|
|
const formValues = await formApi.getValues();
|
2025-10-22 15:09:56 +08:00
|
|
|
|
const fetchParams: any = {
|
2025-10-23 09:37:23 +08:00
|
|
|
|
...formValues,
|
|
|
|
|
|
// 自动添加平台和产品信息
|
2025-12-17 11:19:31 +08:00
|
|
|
|
ioTPlatform: Number.parseInt(ioTPlatform.value) as 1 | 2,
|
|
|
|
|
|
ioTPlatformProductId: productId.value,
|
2025-10-23 09:37:23 +08:00
|
|
|
|
// 编辑时需要添加ID
|
|
|
|
|
|
...(isEdit && { id: editRow.value.id }),
|
2025-10-22 15:09:56 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
2025-12-17 15:51:26 +08:00
|
|
|
|
const resp = await api({ body: fetchParams });
|
2025-10-22 15:09:56 +08:00
|
|
|
|
if (resp.data) {
|
|
|
|
|
|
Message.success(
|
|
|
|
|
|
editRow.value.id ? $t('common.editSuccess') : $t('common.addSuccess'),
|
|
|
|
|
|
);
|
|
|
|
|
|
thingModelModalApi.close();
|
|
|
|
|
|
editRow.value = {};
|
|
|
|
|
|
gridApi.reload();
|
|
|
|
|
|
} else {
|
|
|
|
|
|
Message.error(
|
|
|
|
|
|
editRow.value.id ? $t('common.editFail') : $t('common.addFail'),
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
console.error('提交失败:', error);
|
|
|
|
|
|
Message.error(
|
|
|
|
|
|
editRow.value.id ? $t('common.editFail') : $t('common.addFail'),
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async function onEdit(record: any) {
|
|
|
|
|
|
editRow.value = record;
|
|
|
|
|
|
thingModelModalApi.open();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const openAddModal = async () => {
|
|
|
|
|
|
editRow.value = {};
|
|
|
|
|
|
thingModelModalApi.open();
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-10-23 11:48:10 +08:00
|
|
|
|
// 打开复制已有模型模态框
|
|
|
|
|
|
const openCopyAnotherThingModelModal = async () => {
|
2025-12-17 11:19:31 +08:00
|
|
|
|
console.log('打开复制模态框,当前参数:', {
|
|
|
|
|
|
productId: productId.value,
|
|
|
|
|
|
productName: productName.value,
|
|
|
|
|
|
ioTPlatform: ioTPlatform.value,
|
2025-10-23 13:54:19 +08:00
|
|
|
|
});
|
2025-10-23 11:48:10 +08:00
|
|
|
|
copyModalApi.open();
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// 复制提交逻辑
|
|
|
|
|
|
async function submitCopy() {
|
2025-12-17 11:19:31 +08:00
|
|
|
|
// 检查是否有产品ID
|
|
|
|
|
|
if (!productId.value) {
|
|
|
|
|
|
Message.error('产品ID不存在,无法复制物模型信息');
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-23 11:48:10 +08:00
|
|
|
|
const { valid } = await copyFormApi.validate();
|
|
|
|
|
|
if (!valid) return;
|
|
|
|
|
|
|
|
|
|
|
|
const formValues = await copyFormApi.getValues();
|
2025-10-23 14:31:42 +08:00
|
|
|
|
|
2025-10-23 13:54:19 +08:00
|
|
|
|
console.log('复制提交参数:', {
|
|
|
|
|
|
formValues,
|
2025-12-17 11:19:31 +08:00
|
|
|
|
params: {
|
|
|
|
|
|
productId: productId.value,
|
|
|
|
|
|
productName: productName.value,
|
|
|
|
|
|
ioTPlatform: ioTPlatform.value,
|
2025-10-23 14:31:42 +08:00
|
|
|
|
},
|
2025-10-23 13:54:19 +08:00
|
|
|
|
});
|
2025-10-23 11:48:10 +08:00
|
|
|
|
|
|
|
|
|
|
try {
|
2025-12-01 16:31:57 +08:00
|
|
|
|
const resp = await postIoTplatformThingModelInfoCopyAnotherThingModelAsync({
|
2025-12-17 15:51:26 +08:00
|
|
|
|
body: {
|
|
|
|
|
|
ioTPlatform: Number.parseInt(ioTPlatform.value) as 1 | 2,
|
|
|
|
|
|
ioTPlatformProductId: productId.value,
|
|
|
|
|
|
sourceProductId: formValues.ioTPlatformProductId,
|
2025-10-23 11:48:10 +08:00
|
|
|
|
},
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
if (resp.data) {
|
|
|
|
|
|
Message.success('复制模型成功');
|
|
|
|
|
|
copyModalApi.close();
|
|
|
|
|
|
gridApi.reload();
|
|
|
|
|
|
} else {
|
|
|
|
|
|
Message.error('复制模型失败');
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
console.error('复制模型失败:', error);
|
|
|
|
|
|
Message.error('复制模型失败');
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-22 15:09:56 +08:00
|
|
|
|
// 删除函数
|
|
|
|
|
|
async function onDel(record: any) {
|
|
|
|
|
|
try {
|
2025-12-01 16:31:57 +08:00
|
|
|
|
const resp = await postIoTplatformThingModelInfoDeleteAsync({
|
2025-12-17 15:51:26 +08:00
|
|
|
|
body: { id: record.id },
|
2025-10-22 15:09:56 +08:00
|
|
|
|
});
|
|
|
|
|
|
if (resp.data) {
|
|
|
|
|
|
Message.success($t('common.deleteSuccess'));
|
|
|
|
|
|
gridApi.reload();
|
|
|
|
|
|
} else {
|
|
|
|
|
|
Message.error($t('common.deleteFail'));
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
console.error('删除失败:', error);
|
|
|
|
|
|
Message.error($t('common.deleteFail'));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 复制标准模型函数
|
|
|
|
|
|
async function copyStandardThingModel() {
|
2025-12-17 11:19:31 +08:00
|
|
|
|
// 检查是否有产品ID
|
|
|
|
|
|
if (!productId.value) {
|
|
|
|
|
|
Message.error('产品ID不存在,无法复制标准模型');
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-22 15:09:56 +08:00
|
|
|
|
try {
|
2025-12-01 16:31:57 +08:00
|
|
|
|
const resp = await postIoTplatformThingModelInfoCopyStandardThingModel({
|
2025-12-17 15:51:26 +08:00
|
|
|
|
body: {
|
|
|
|
|
|
ioTPlatform: Number.parseInt(ioTPlatform.value) as 1 | 2,
|
|
|
|
|
|
ioTPlatformProductId: productId.value,
|
2025-10-22 15:09:56 +08:00
|
|
|
|
},
|
|
|
|
|
|
});
|
|
|
|
|
|
if (resp.data) {
|
|
|
|
|
|
Message.success('复制标准模型成功');
|
|
|
|
|
|
gridApi.reload();
|
|
|
|
|
|
} else {
|
|
|
|
|
|
Message.error('复制标准模型失败');
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
console.error('复制标准模型失败:', error);
|
|
|
|
|
|
Message.error('复制标准模型失败');
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<template>
|
2025-12-17 11:19:31 +08:00
|
|
|
|
<Page auto-content-height>
|
|
|
|
|
|
<Grid>
|
|
|
|
|
|
<template #toolbar-actions>
|
|
|
|
|
|
<TableAction :actions="[
|
|
|
|
|
|
{
|
|
|
|
|
|
label: $t('common.add'),
|
|
|
|
|
|
type: 'primary',
|
|
|
|
|
|
icon: 'ant-design:plus-outlined',
|
|
|
|
|
|
onClick: openAddModal.bind(null),
|
|
|
|
|
|
auth: ['AbpIdentity.Users.Create'],
|
|
|
|
|
|
disabled: !productId,
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
label: $t('abp.thingModelInfos.copyStandardThingModel'),
|
|
|
|
|
|
type: 'default',
|
|
|
|
|
|
icon: 'ant-design:copy-outlined',
|
|
|
|
|
|
onClick: copyStandardThingModel,
|
|
|
|
|
|
auth: ['AbpIdentity.Users.Create'],
|
|
|
|
|
|
disabled: !productId,
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
label: $t('abp.thingModelInfos.copyAnotherThingModelModal'),
|
|
|
|
|
|
type: 'default',
|
|
|
|
|
|
icon: 'ant-design:copy-outlined',
|
|
|
|
|
|
onClick: openCopyAnotherThingModelModal,
|
|
|
|
|
|
auth: ['AbpIdentity.Users.Create'],
|
|
|
|
|
|
ifShow: !hasData,
|
|
|
|
|
|
disabled: !productId,
|
|
|
|
|
|
},
|
|
|
|
|
|
]" />
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<template #isValueNeedConvert="{ row }">
|
|
|
|
|
|
<component :is="h(
|
|
|
|
|
|
Tag,
|
|
|
|
|
|
{ color: row.isValueNeedConvert ? 'blue' : 'default' },
|
|
|
|
|
|
() => (row.isValueNeedConvert ? '是' : '否'),
|
|
|
|
|
|
)
|
|
|
|
|
|
" />
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<template #action="{ row }">
|
|
|
|
|
|
<TableAction :actions="[
|
|
|
|
|
|
{
|
|
|
|
|
|
label: $t('common.edit'),
|
|
|
|
|
|
type: 'link',
|
|
|
|
|
|
size: 'small',
|
|
|
|
|
|
auth: ['AbpIdentity.Users.Update'],
|
|
|
|
|
|
onClick: onEdit.bind(null, row),
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
label: $t('common.delete'),
|
|
|
|
|
|
icon: 'ant-design:delete-outlined',
|
|
|
|
|
|
type: 'link',
|
|
|
|
|
|
size: 'small',
|
|
|
|
|
|
auth: ['AbpIdentity.Users.Delete'],
|
|
|
|
|
|
popConfirm: {
|
|
|
|
|
|
title: $t('common.askConfirmDelete'),
|
|
|
|
|
|
confirm: onDel.bind(null, row),
|
2025-10-22 15:09:56 +08:00
|
|
|
|
},
|
2025-12-17 11:19:31 +08:00
|
|
|
|
},
|
|
|
|
|
|
]" />
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</Grid>
|
2025-10-22 15:09:56 +08:00
|
|
|
|
<ThingModelModal :title="editRow.id ? $t('common.edit') : $t('common.add')" class="w-[800px]">
|
|
|
|
|
|
<component :is="editRow.id ? EditForm : AddForm" />
|
|
|
|
|
|
</ThingModelModal>
|
2025-10-23 14:31:42 +08:00
|
|
|
|
|
2025-10-23 13:54:19 +08:00
|
|
|
|
<!-- 复制已有模型模态框 -->
|
|
|
|
|
|
<CopyModal title="复制已有模型" class="w-[600px]">
|
|
|
|
|
|
<CopyForm />
|
|
|
|
|
|
</CopyModal>
|
2025-12-17 11:19:31 +08:00
|
|
|
|
</Page>
|
2025-10-22 15:09:56 +08:00
|
|
|
|
</template>
|