Compare commits

..

No commits in common. "4d7ee72d246bb62ab9411ac3c69ed1b99655417b" and "9a9420f423c9709a2b2a134ff92199b827e32026" have entirely different histories.

9 changed files with 155 additions and 508 deletions

View File

@ -2071,39 +2071,6 @@ export const FileLoadBalancerOptionsSchema = {
additionalProperties: false
} as const;
export const FileObjectDtoSchema = {
type: 'object',
properties: {
id: {
type: 'string',
description: '主键Id',
format: 'uuid'
},
creationTime: {
type: 'string',
description: '创建时间',
format: 'date-time'
},
fileSize: {
type: 'integer',
description: '文件大小',
format: 'int64'
},
contentType: {
type: 'string',
description: '文件名称',
nullable: true
},
fileName: {
type: 'string',
description: '文件名称',
nullable: true
}
},
additionalProperties: false,
description: '文件'
} as const;
export const FileQoSOptionsSchema = {
type: 'object',
properties: {
@ -3395,11 +3362,11 @@ export const IoTDBDynamicObjectPagedResultDtoSchema = {
} as const;
export const IoTPlatformTypeEnumSchema = {
enum: [1, 2],
enum: [0, 1, 2],
type: 'integer',
description: '物联网平台类型枚举',
format: 'int32',
'说明:': '电信CTWing=1,移动OneNET=2'
'说明:': '无=0,电信CTWing=1,移动OneNET=2'
} as const;
export const LanguageInfoSchema = {
@ -4462,11 +4429,6 @@ export const OneNETProductInfoDtoSchema = {
description: 'OneNET账户Id',
nullable: true
},
oneNETAccountName: {
type: 'string',
description: 'OneNET账户',
nullable: true
},
ioTPlatformProductId: {
type: 'string',
description: '物联网平台对应的产品Id',
@ -4482,15 +4444,14 @@ export const OneNETProductInfoDtoSchema = {
description: '产品访问密钥',
nullable: true
},
deviceThingModelFileId: {
deviceThingModelUrl: {
type: 'string',
description: '设备物模型文件Id',
description: '设备物模型文件管理地址',
nullable: true
},
deviceThingModelFileName: {
type: 'string',
description: '设备物模型文件名称',
nullable: true
isEncrypted: {
type: 'boolean',
description: '通信是否加密'
},
isEnabled: {
type: 'boolean',
@ -4694,38 +4655,32 @@ export const OneNetAccountModifyInputSchema = {
} as const;
export const OneNetProductInfoInsertInputSchema = {
required: ['communicationAddress', 'ioTPlatformProductId', 'oneNETAccountId', 'productAccesskey'],
type: 'object',
properties: {
oneNETAccountId: {
minLength: 1,
type: 'string',
description: 'OneNET 账号ID'
description: 'OneNET 账号ID',
nullable: true
},
ioTPlatformProductId: {
minLength: 1,
type: 'string',
description: '物联网平台对应的产品Id'
description: '物联网平台对应的产品Id',
nullable: true
},
productAccesskey: {
minLength: 1,
type: 'string',
description: '产品访问密钥'
description: '产品访问密钥',
nullable: true
},
communicationAddress: {
minLength: 1,
type: 'string',
description: '通讯服务地址'
description: '通讯服务地址',
nullable: true
},
communicationAddressTLS: {
type: 'string',
description: 'TLS通讯服务地址',
nullable: true
},
deviceThingModelUrl: {
type: 'string',
description: '物模型文件链接',
nullable: true
}
},
additionalProperties: false
@ -4778,48 +4733,11 @@ export const OneNetProductInfoListInputSchema = {
} as const;
export const OneNetProductInfoModifyInputSchema = {
required: ['communicationAddress', 'ioTPlatformProductId', 'oneNETAccountId', 'productAccesskey'],
type: 'object',
properties: {
id: {
type: 'string',
description: '产品数据ID',
format: 'uuid'
},
oneNETAccountId: {
minLength: 1,
type: 'string',
description: 'OneNET 账号ID'
},
ioTPlatformProductId: {
minLength: 1,
type: 'string',
description: '物联网平台对应的产品Id'
},
productAccesskey: {
minLength: 1,
type: 'string',
description: '产品访问密钥'
},
communicationAddress: {
minLength: 1,
type: 'string',
description: '通讯服务地址'
},
communicationAddressTLS: {
type: 'string',
description: 'TLS通讯服务地址',
nullable: true
},
deviceThingModelFileId: {
type: 'string',
description: '设备物模型文件Id',
nullable: true
},
deviceThingModelFileName: {
type: 'string',
description: '设备物模型文件名称',
nullable: true
}
},
additionalProperties: false,

View File

@ -917,32 +917,6 @@ export type FileLoadBalancerOptions = {
expiry?: number;
};
/**
*
*/
export type FileObjectDto = {
/**
* Id
*/
id?: string;
/**
*
*/
creationTime?: string;
/**
*
*/
fileSize?: number;
/**
*
*/
contentType?: (string) | null;
/**
*
*/
fileName?: (string) | null;
};
export type FileQoSOptions = {
exceptionsAllowedBeforeBreaking?: number;
durationOfBreak?: number;
@ -1406,7 +1380,7 @@ export type IoTDBDynamicObjectPagedResultDto = {
/**
*
*/
export type IoTPlatformTypeEnum = 1 | 2;
export type IoTPlatformTypeEnum = 0 | 1 | 2;
export type IStringValueType = {
readonly name?: (string) | null;
@ -2133,10 +2107,6 @@ export type OneNETProductInfoDto = {
* OneNET账户Id
*/
oneNETAccountId?: (string) | null;
/**
* OneNET账户
*/
oneNETAccountName?: (string) | null;
/**
* Id
*/
@ -2150,13 +2120,13 @@ export type OneNETProductInfoDto = {
*/
productAccesskey?: (string) | null;
/**
* Id
*
*/
deviceThingModelFileId?: (string) | null;
deviceThingModelUrl?: (string) | null;
/**
*
*
*/
deviceThingModelFileName?: (string) | null;
isEncrypted?: boolean;
/**
*
*/
@ -2230,27 +2200,23 @@ export type OneNetProductInfoInsertInput = {
/**
* OneNET ID
*/
oneNETAccountId: string;
oneNETAccountId?: (string) | null;
/**
* Id
*/
ioTPlatformProductId: string;
ioTPlatformProductId?: (string) | null;
/**
* 访
*/
productAccesskey: string;
productAccesskey?: (string) | null;
/**
*
*/
communicationAddress: string;
communicationAddress?: (string) | null;
/**
* TLS通讯服务地址
*/
communicationAddressTLS?: (string) | null;
/**
*
*/
deviceThingModelUrl?: (string) | null;
};
export type OneNetProductInfoListInput = {
@ -2291,38 +2257,7 @@ export type OneNetProductInfoListInput = {
* OneNET产品
*/
export type OneNetProductInfoModifyInput = {
/**
* ID
*/
id?: string;
/**
* OneNET ID
*/
oneNETAccountId: string;
/**
* Id
*/
ioTPlatformProductId: string;
/**
* 访
*/
productAccesskey: string;
/**
*
*/
communicationAddress: string;
/**
* TLS通讯服务地址
*/
communicationAddressTLS?: (string) | null;
/**
* Id
*/
deviceThingModelFileId?: (string) | null;
/**
*
*/
deviceThingModelFileName?: (string) | null;
};
/**
@ -4594,7 +4529,7 @@ export type PostFilesUploadData = {
};
};
export type PostFilesUploadResponse = (Array<FileObjectDto>);
export type PostFilesUploadResponse = (unknown);
export type PostFilesUploadError = (RemoteServiceErrorResponse);

View File

@ -269,13 +269,12 @@
"ProductCount": "ProductCount",
"OneNETAccountId": "OneNETAccountId",
"OneNETProductId": "OneNETProductId",
"ProductKey": "ProductKey",
"ProductSecret": "ProductSecret",
"IoTPlatformProductId": "IoTPlatformProductId",
"ProductName": "ProductName",
"ProductAccesskey": "ProductAccesskey",
"IsEncrypted": "IsEncrypted",
"BelongingProductName": "Belonging ProductName",
"CommunicationAddress": "Communication Address",
"CommunicationAddressTLS": "TLS Communication Address",
"DeviceThingModelFileName": "DeviceThingModelFileName"
"BelongingProductName": "BelongingProductName"
}
}

View File

@ -271,13 +271,12 @@
"ProductCount": "产品数量",
"OneNETAccountId": "OneNET账户Id",
"OneNETProductId": "OneNET产品Id",
"ProductKey": "产品密钥",
"ProductSecret": "产品密钥",
"IoTPlatformProductId": "物联网平台对应的产品Id",
"ProductName": "产品名称",
"ProductAccesskey": "产品密钥",
"ProductAccesskey": "产品访问密钥",
"IsEncrypted": "是否加密",
"BelongingProductName": "所属产品",
"CommunicationAddress": "通讯地址",
"CommunicationAddressTLS": "TLS通讯地址",
"DeviceThingModelFileName": "物模型文件"
"BelongingProductName": "所属产品"
}
}

View File

@ -2,7 +2,7 @@
import type { VbenFormProps } from '#/adapter/form';
import type { VxeGridProps } from '#/adapter/vxe-table';
import { h, ref, nextTick } from 'vue';
import { h, ref } from 'vue';
import { useRouter } from 'vue-router';
import { Page, useVbenModal } from '@vben/common-ui';
@ -16,8 +16,6 @@ import {
postOneNetProductDeleteAsync,
postOneNetProductListAsync,
postOneNetProductModifyAsync,
postFilesUpload,
postFilesDownload,
} from '#/api-client';
import { TableAction } from '#/components/table-action';
import { $t } from '#/locales';
@ -27,7 +25,6 @@ import {
editProductFormSchemaEdit,
querySchema,
tableSchema,
setFileSelectedCallback,
} from './schema';
defineOptions({
@ -72,41 +69,13 @@ const gridOptions: VxeGridProps<any> = {
const [Grid, gridApi] = useVbenVxeGrid({ formOptions, gridOptions });
const editRow: Record<string, any> = ref({});
//
let selectedFile: File | null = null;
//
setFileSelectedCallback((file) => {
selectedFile = file;
});
const [UserModal, userModalApi] = useVbenModal({
draggable: true,
footer: true,
showCancelButton: true,
showConfirmButton: true,
onConfirm: submit,
onBeforeClose: () => {
//
return true;
},
onOpen: () => {
//
selectedFile = null;
},
onOpenChange: (isOpen: boolean) => {
if (isOpen && editRow.value.id) {
//
nextTick(() => {
editFormApi.setValues({ ...editRow.value });
});
}
},
onCancel: () => {
//
selectedFile = null;
//
userModalApi.close();
},
});
const [AddForm, addFormApi] = useVbenForm({
@ -153,45 +122,6 @@ async function submit() {
if (!valid) return;
const formValues = await formApi.getValues();
//
if (!formValues.deviceThingModelFileName) {
Message.error('请选择设备模型文件');
return;
}
//
if (selectedFile) {
try {
userModalApi.setState({ loading: true, confirmLoading: true });
const result = await postFilesUpload({ body: { files: [selectedFile] } });
if (result.status === 204 || result.status === 200) {
const fileInfo = result.data?.[0];
if (fileInfo && fileInfo.id) {
formValues.deviceThingModelFileId = fileInfo.id;
//
} else {
Message.error('文件上传成功但未获取到文件ID');
userModalApi.setState({ loading: false, confirmLoading: false });
return;
}
} else {
Message.error('文件上传失败');
userModalApi.setState({ loading: false, confirmLoading: false });
return;
}
} catch (error) {
Message.error('文件上传失败');
userModalApi.setState({ loading: false, confirmLoading: false });
return;
}
}
//
selectedFile = null;
//
const fetchParams: any = isEdit
? {
id: editRow.value.id,
@ -202,6 +132,7 @@ async function submit() {
};
try {
userModalApi.setState({ loading: true, confirmLoading: true });
const resp = await api({ body: fetchParams });
if (resp.data) {
Message.success(
@ -223,15 +154,12 @@ async function submit() {
async function onEdit(record: any) {
editRow.value = record;
userModalApi.open();
//
selectedFile = null;
editFormApi.setValues({ ...record });
}
const openAddModal = async () => {
editRow.value = {};
userModalApi.open();
//
selectedFile = null;
};
//
@ -240,8 +168,6 @@ async function onDel(record: any) {
const resp = await postOneNetProductDeleteAsync({ body: { id: record.id } });
if (resp.data) {
Message.success($t('common.deleteSuccess'));
//
selectedFile = null;
gridApi.reload();
} else {
Message.error($t('common.deleteFail'));
@ -250,32 +176,6 @@ async function onDel(record: any) {
Message.error($t('common.deleteFail'));
}
}
//
async function onDownloadFile(record: any) {
if (!record.deviceThingModelFileId) {
Message.error('文件ID不存在无法下载');
return;
}
try {
const { data } = await postFilesDownload({
body: { id: record.deviceThingModelFileId },
responseType: 'blob',
});
const url = window.URL.createObjectURL(new Blob([data as Blob]));
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', record.deviceThingModelFileName || 'device-model-file');
document.body.append(link);
link.click();
link.remove();
window.URL.revokeObjectURL(url);
Message.success('文件下载成功');
} catch (error) {
Message.error('文件下载失败');
}
}
</script>
<template>
@ -305,17 +205,6 @@ async function onDownloadFile(record: any) {
/>
</template>
<template #deviceThingModelFileName="{ row }">
<a
v-if="row.deviceThingModelFileName && row.deviceThingModelFileId"
@click="onDownloadFile(row)"
style="color: #1890ff; cursor: pointer; text-decoration: underline;"
>
{{ row.deviceThingModelFileName }}
</a>
<span v-else>{{ row.deviceThingModelFileName || '-' }}</span>
</template>
<template #action="{ row }">
<TableAction
:actions="[

View File

@ -1,11 +1,11 @@
import type { VxeGridProps } from '#/adapter/vxe-table';
import { computed, h } from 'vue';
import { computed } from 'vue';
import { z } from '@vben/common-ui';
import { postOneNetAccountListAsync, postFilesUpload } from '#/api-client';
import { $t } from '#/locales';
import { postOneNetAccountListAsync } from '#/api-client';
export const querySchema = computed(() => [
{
@ -18,12 +18,7 @@ export const querySchema = computed(() => [
export const tableSchema: any = computed((): VxeGridProps['columns'] => [
{ title: $t('common.seq'), type: 'seq', width: 50 },
{
field: 'oneNETAccountName',
title: $t('abp.OneNETManagement.BelongingAccountName'),
minWidth: '150',
},
{
field: 'ioTPlatformProductId',
field: 'oneNETProductId',
title: $t('abp.OneNETManagement.OneNETProductId'),
minWidth: '150',
},
@ -33,28 +28,22 @@ export const tableSchema: any = computed((): VxeGridProps['columns'] => [
minWidth: '150',
},
{
field: 'productAccesskey',
title: $t('abp.OneNETManagement.ProductAccesskey'),
field: 'productKey',
title: $t('abp.OneNETManagement.ProductKey'),
minWidth: '150',
},
{
field: 'communicationAddress',
title: $t('abp.OneNETManagement.CommunicationAddress'),
field: 'productSecret',
title: $t('abp.OneNETManagement.ProductSecret'),
minWidth: '150',
},
{
field: 'communicationAddressTLS',
title: $t('abp.OneNETManagement.CommunicationAddressTLS'),
field: 'accountName',
title: $t('abp.OneNETManagement.AccountName'),
minWidth: '150',
},
{
field: 'deviceThingModelFileName',
title: $t('abp.OneNETManagement.DeviceThingModelFileName'),
minWidth: '150',
slots: { default: 'deviceThingModelFileName' },
},
{
field: 'isEnabled',
field: 'enabled',
title: $t('common.isEnable'),
minWidth: '150',
slots: { default: 'isEnable' },
@ -68,16 +57,6 @@ export const tableSchema: any = computed((): VxeGridProps['columns'] => [
},
]);
// 全局变量存储选择的文件
export let selectedFile: File | null = null;
// 文件选择回调函数
let _onFileSelected: ((file: File) => void) | null = null;
export function setFileSelectedCallback(callback: (file: File) => void) {
_onFileSelected = callback;
}
export const addProductFormSchema: any = computed(() => [
{
component: 'ApiSelect',
@ -95,25 +74,32 @@ export const addProductFormSchema: any = computed(() => [
valueField: 'oneNETAccountId',
immediate: true,
afterFetch: (res: any) => {
console.log('ApiSelect afterFetch res:', res);
// 如果是 Axios 响应对象,提取 data
if (res && res.data) {
console.log('提取 res.data:', res.data);
const data = res.data;
// 确保返回的是数组格式
if (Array.isArray(data)) {
console.log('返回数组,长度:', data.length);
return data;
}
// 如果是包装在 items 中的,提取出来
if (data && Array.isArray(data.items)) {
console.log('返回items数组长度:', data.items.length);
return data.items;
}
// 如果是包装在 data 中的,提取出来
if (data && Array.isArray(data.data)) {
console.log('返回data数组长度:', data.data.length);
return data.data;
}
}
// 如果都不是,返回空数组
console.log('没有找到数组数据,返回空数组');
return [];
},
placeholder: `${$t('common.pleaseSelect')}${$t('abp.OneNETManagement.BelongingAccountName')}`,
@ -124,7 +110,7 @@ export const addProductFormSchema: any = computed(() => [
},
{
component: 'Input',
fieldName: 'ioTPlatformProductId',
fieldName: 'oneNETProductId',
label: $t('abp.OneNETManagement.OneNETProductId'),
rules: z.string().min(1, {
message: `${$t('common.pleaseInput')}${$t('common.info')}${$t('abp.OneNETManagement.OneNETProductId')}`,
@ -132,86 +118,73 @@ export const addProductFormSchema: any = computed(() => [
},
{
component: 'Input',
fieldName: 'productAccesskey',
label: $t('abp.OneNETManagement.ProductAccesskey'),
fieldName: 'productName',
label: $t('abp.OneNETManagement.ProductName'),
rules: z.string().min(1, {
message: `${$t('common.pleaseInput')}${$t('common.info')}${$t('abp.OneNETManagement.ProductAccesskey')}`,
message: `${$t('common.pleaseInput')}${$t('common.info')}${$t('abp.OneNETManagement.ProductName')}`,
}),
},
{
component: 'Input',
fieldName: 'communicationAddress',
label: $t('abp.OneNETManagement.CommunicationAddress'),
fieldName: 'productKey',
label: $t('abp.OneNETManagement.ProductKey'),
rules: z.string().min(1, {
message: `${$t('common.pleaseInput')}${$t('common.info')}${$t('abp.OneNETManagement.CommunicationAddress')}`,
message: `${$t('common.pleaseInput')}${$t('common.info')}${$t('abp.OneNETManagement.ProductKey')}`,
}),
},
{
component: 'Input',
fieldName: 'communicationAddressTLS',
label: $t('abp.OneNETManagement.CommunicationAddressTLS'),
fieldName: 'productSecret',
label: $t('abp.OneNETManagement.ProductSecret'),
rules: z.string().min(1, {
message: `${$t('common.pleaseInput')}${$t('common.info')}${$t('abp.OneNETManagement.CommunicationAddressTLS')}`,
message: `${$t('common.pleaseInput')}${$t('common.info')}${$t('abp.OneNETManagement.ProductSecret')}`,
}),
},
{
component: 'Input',
fieldName: 'deviceThingModelFileName',
label: $t('abp.OneNETManagement.DeviceThingModelFileName'),
component: 'Switch',
componentProps: {
placeholder: '请选择文件',
readonly: true,
addonAfter: h('button', {
type: 'button',
style: 'border: none; background: #1890ff; color: white; padding: 4px 8px; border-radius: 4px; cursor: pointer;',
onClick: () => {
const input = document.createElement('input');
input.type = 'file';
input.accept = '.json,.xlsx,.xls';
input.onchange = (e: any) => {
const file = e.target.files[0];
if (file) {
// 只显示文件名,不上传
const currentInput = document.querySelector('input[placeholder="请选择文件"]') as HTMLInputElement;
if (currentInput) {
currentInput.value = file.name;
// 触发change事件
currentInput.dispatchEvent(new Event('input', { bubbles: true }));
currentInput.dispatchEvent(new Event('change', { bubbles: true }));
// 存储文件对象到全局变量,用于后续上传
selectedFile = file;
// 调用回调函数
if (_onFileSelected) {
_onFileSelected(file);
}
}
console.log('文件已选择:', file.name, '大小:', file.size, '字节');
}
};
input.click();
}
}, '选择文件'),
},
rules: z.string().min(1, {
message: `${$t('common.pleaseSelect')}${$t('abp.OneNETManagement.DeviceThingModelFileName')}`,
}),
},
{
component: 'Input',
fieldName: 'deviceThingModelFileId',
label: '',
componentProps: {
type: 'hidden',
class: 'w-auto',
},
fieldName: 'enabled',
label: $t('common.isEnable'),
},
]);
export const editProductFormSchemaEdit: any = computed(() => [
{
component: 'Input',
fieldName: 'oneNETProductId',
label: $t('abp.OneNETManagement.OneNETProductId'),
disabled: true,
},
{
component: 'Input',
fieldName: 'productName',
label: $t('abp.OneNETManagement.ProductName'),
rules: z.string().min(1, {
message: `${$t('common.pleaseInput')}${$t('common.info')}${$t('abp.OneNETManagement.ProductName')}`,
}),
},
{
component: 'Input',
fieldName: 'productKey',
label: $t('abp.OneNETManagement.ProductKey'),
rules: z.string().min(1, {
message: `${$t('common.pleaseInput')}${$t('common.info')}${$t('abp.OneNETManagement.ProductKey')}`,
}),
},
{
component: 'Input',
fieldName: 'productSecret',
label: $t('abp.OneNETManagement.ProductSecret'),
rules: z.string().min(1, {
message: `${$t('common.pleaseInput')}${$t('common.info')}${$t('abp.OneNETManagement.ProductSecret')}`,
}),
},
{
component: 'ApiSelect',
fieldName: 'oneNETAccountId',
label: $t('abp.OneNETManagement.BelongingAccountName'),
fieldName: 'accountName',
label: $t('abp.OneNETManagement.AccountName'),
componentProps: {
api: postOneNetAccountListAsync,
params: {
@ -223,124 +196,47 @@ export const editProductFormSchemaEdit: any = computed(() => [
labelField: 'accountName',
valueField: 'oneNETAccountId',
immediate: true,
disabled: true, // 编辑时禁用
afterFetch: (res: any) => {
console.log('ApiSelect afterFetch res:', res);
// 如果是 Axios 响应对象,提取 data
if (res && res.data) {
console.log('提取 res.data:', res.data);
const data = res.data;
// 确保返回的是数组格式
if (Array.isArray(data)) {
console.log('返回数组,长度:', data.length);
return data;
}
// 如果是包装在 items 中的,提取出来
if (data && Array.isArray(data.items)) {
console.log('返回items数组长度:', data.items.length);
return data.items;
}
// 如果是包装在 data 中的,提取出来
if (data && Array.isArray(data.data)) {
console.log('返回data数组长度:', data.data.length);
return data.data;
}
}
// 如果都不是,返回空数组
console.log('没有找到数组数据,返回空数组');
return [];
},
placeholder: `${$t('common.pleaseSelect')}${$t('abp.OneNETManagement.BelongingAccountName')}`,
placeholder: `${$t('common.pleaseSelect')}${$t('abp.OneNETManagement.AccountName')}`,
},
rules: z.string().min(1, {
message: `${$t('common.pleaseSelect')}${$t('abp.OneNETManagement.BelongingAccountName')}`,
message: `${$t('common.pleaseSelect')}${$t('abp.OneNETManagement.AccountName')}`,
}),
},
{
component: 'Input',
fieldName: 'ioTPlatformProductId',
label: $t('abp.OneNETManagement.OneNETProductId'),
disabled: true,
component: 'Switch',
componentProps: {
readonly: true, // 编辑时只读
},
rules: z.string().min(1, {
message: `${$t('common.pleaseInput')}${$t('common.info')}${$t('abp.OneNETManagement.OneNETProductId')}`,
}),
},
{
component: 'Input',
fieldName: 'productAccesskey',
label: $t('abp.OneNETManagement.ProductAccesskey'),
disabled: true,
componentProps: {
readonly: true, // 编辑时只读
},
rules: z.string().min(1, {
message: `${$t('common.pleaseInput')}${$t('common.info')}${$t('abp.OneNETManagement.ProductAccesskey')}`,
}),
},
{
component: 'Input',
fieldName: 'communicationAddress',
label: $t('abp.OneNETManagement.CommunicationAddress'),
rules: z.string().min(1, {
message: `${$t('common.pleaseInput')}${$t('common.info')}${$t('abp.OneNETManagement.CommunicationAddress')}`,
}),
},
{
component: 'Input',
fieldName: 'communicationAddressTLS',
label: $t('abp.OneNETManagement.CommunicationAddressTLS'),
rules: z.string().min(1, {
message: `${$t('common.pleaseInput')}${$t('common.info')}${$t('abp.OneNETManagement.CommunicationAddressTLS')}`,
}),
},
{
component: 'Input',
fieldName: 'deviceThingModelFileName',
label: $t('abp.OneNETManagement.DeviceThingModelFileName'),
componentProps: {
placeholder: '请选择文件',
readonly: true,
addonAfter: h('button', {
type: 'button',
style: 'border: none; background: #1890ff; color: white; padding: 4px 8px; border-radius: 4px; cursor: pointer;',
onClick: () => {
const input = document.createElement('input');
input.type = 'file';
input.accept = '.json,.xlsx,.xls';
input.onchange = (e: any) => {
const file = e.target.files[0];
if (file) {
// 只显示文件名,不上传
const currentInput = document.querySelector('input[placeholder="请选择文件"]') as HTMLInputElement;
if (currentInput) {
currentInput.value = file.name;
// 触发change事件
currentInput.dispatchEvent(new Event('input', { bubbles: true }));
currentInput.dispatchEvent(new Event('change', { bubbles: true }));
// 存储文件对象到全局变量,用于后续上传
selectedFile = file;
// 调用回调函数
if (_onFileSelected) {
_onFileSelected(file);
}
}
console.log('文件已选择:', file.name, '大小:', file.size, '字节');
}
};
input.click();
}
}, '选择文件'),
},
rules: z.string().min(1, {
message: `${$t('common.pleaseSelect')}${$t('abp.OneNETManagement.DeviceThingModelFileName')}`,
}),
},
{
component: 'Input',
fieldName: 'deviceThingModelFileId',
label: '',
componentProps: {
type: 'hidden',
class: 'w-auto',
},
fieldName: 'enabled',
label: $t('common.isEnable'),
},
]);

View File

@ -9,12 +9,9 @@ import { $t } from '#/locales';
import { addFormSchema } from './schema';
import { postFilesUpload } from '#/api-client/index';
import { useUserStore } from '@vben/stores';
const emit = defineEmits(['reload']);
const userStore = useUserStore();
//
const UploadIcon = createIconifyIcon('mdi:upload');
const FolderIcon = createIconifyIcon('mdi:folder');
@ -147,40 +144,51 @@ const handleUpload = async () => {
uploading.value = true;
try {
//
const formValues = await formApi.getValues();
console.log('Form values:', formValues);
console.log('File list:', fileList.value);
//
const files = fileList.value
.map(fileInfo => fileInfo.originFileObj)
.filter(file => file !== null && file !== undefined);
// FormData
const uploadFormData = new FormData();
console.log('Extracted files:', files);
// FormData
fileList.value.forEach((fileInfo, index) => {
if (fileInfo.originFileObj) {
console.log(`Adding file ${index}:`, fileInfo.name, fileInfo.originFileObj);
uploadFormData.append('files', fileInfo.originFileObj);
}
});
// - 使API
console.log('Sending request to /Files/Upload...');
//
if (formValues) {
Object.keys(formValues).forEach(key => {
if (formValues[key] !== undefined && formValues[key] !== null) {
console.log(`Adding form field ${key}:`, formValues[key]);
uploadFormData.append(key, formValues[key]);
}
});
}
// FormData
for (let [key, value] of uploadFormData.entries()) {
console.log(`FormData entry: ${key} =`, value);
}
//
const result = await postFilesUpload({
body: {
files: files
},
headers: {
'Authorization': `Bearer ${userStore.userInfo?.token}`,
},
body: uploadFormData as any,
});
console.log('Upload result:', result);
console.log('Response status:', result.status);
console.log('Response data:', result.data);
console.log('Response headers:', result.headers);
//
if (result.status === 204 || result.status === 200) {
message.success(`文件上传成功!共上传 ${fileList.value.length} 个文件`);
fileList.value = [];
console.log('Emitting reload event...');
emit('reload');
modalApi.close();
} else {
message.error(`文件上传失败,状态码: ${result.status}`);
message.error('文件上传失败,请重试');
}
} catch (error) {
console.error('Upload error:', error);

View File

@ -73,11 +73,6 @@ const [AddVbenModal, addModalApi] = useVbenModal({
connectedComponent: AddModal,
});
const handleReload = () => {
console.log('Reloading file list...');
gridApi.reload();
};
const handleAdd = () => {
addModalApi.open();
};
@ -149,7 +144,7 @@ const handleDown = async (row: any) => {
/>
</template>
</Grid>
<AddVbenModal @reload="handleReload" />
<AddVbenModal @reload="gridApi.reload" />
</Page>
</template>
<style scoped></style>

View File

@ -69,5 +69,13 @@ export const tableSchema: any = computed((): VxeGridProps['columns'] => [
]);
export const addFormSchema = computed(() => [
// 文件上传现在在AddModal中处理不需要表单字段
// 文件上传现在在AddModal中处理
{
component: 'Input',
fieldName: 'note',
label: $t('common.note'),
componentProps: {
placeholder: '请输入备注信息',
},
},
]);