Compare commits

..

No commits in common. "789a16e958a2c28f43dd0c3fe8b78c012a509df4" and "d241a1a6b9d650f969bf0968314816f9c4065098" have entirely different histories.

3 changed files with 34 additions and 143 deletions

View File

@ -2,7 +2,7 @@
import type { VbenFormProps } from '#/adapter/form';
import type { VxeGridProps } from '#/adapter/vxe-table';
import { computed, h, ref, watch } from 'vue';
import { computed, h, ref } from 'vue';
import { useRouter } from 'vue-router';
import { Page, useVbenModal } from '@vben/common-ui';
@ -18,10 +18,9 @@ import {
import { useVbenForm } from '#/adapter/form';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import {
postAggregationDeviceBatchCreateAsync,
postAggregationDeviceCreateAsync,
postAggregationDeviceDeleteAsync,
postAggregationDeviceRepushDeviceInfoToIoTplatform,
postAggregationDeviceBatchCreateAsync,
postDeviceInfoCacheDeviceDataToRedis,
postDeviceInfoPage,
} from '#/api-client';
@ -83,7 +82,6 @@ const [Grid, gridApi] = useVbenVxeGrid({ formOptions, gridOptions });
const editRow: Record<string, any> = ref({});
const cacheRefreshLoading = ref(false);
const pageLoading = ref(false);
const loadingTip = ref('缓存刷新中...');
const commandRow: Record<string, any> = ref({});
const [UserModal, userModalApi] = useVbenModal({
draggable: true,
@ -169,22 +167,16 @@ const [BatchAddForm, batchAddFormApi] = useVbenForm({
showCollapseButton: false,
showDefaultActions: false,
wrapperClass: 'grid-cols-2',
//
autoSubmitOnEnter: false,
});
const [BatchAddModal, batchAddModalApi] = useVbenModal({
draggable: true,
onConfirm: submitBatchAdd,
onBeforeClose: () => {
batchAddFormApi.resetForm();
return true;
},
});
//
const batchAddModalState = batchAddModalApi.useStore();
//
async function submit() {
const isEdit = !!editRow.value.id;
@ -339,28 +331,6 @@ const toTelemetryLog = (row: Record<string, any>) => {
},
});
};
// IoT
const repushDeviceInfo = async (row: Record<string, any>) => {
try {
pageLoading.value = true;
loadingTip.value = '重推设备信息中...';
const result = await postAggregationDeviceRepushDeviceInfoToIoTplatform({
body: { id: row.id },
});
if (result.data) {
Message.success('重推设备信息成功');
gridApi.reload();
} else {
Message.error('重推设备信息失败');
}
} catch (error) {
Message.error('重推设备信息失败');
} finally {
pageLoading.value = false;
loadingTip.value = '缓存刷新中...';
}
};
const openAddModal = async () => {
editRow.value = {};
userModalApi.open();
@ -415,9 +385,7 @@ async function submitBatchAdd() {
}
//
const invalidAddresses = addressList.filter(
(address: string) => !address || address.length < 3,
);
const invalidAddresses = addressList.filter((address: string) => !address || address.length < 3);
if (invalidAddresses.length > 0) {
Message.error(`以下设备地址格式不正确: ${invalidAddresses.join(', ')}`);
return;
@ -467,58 +435,15 @@ async function submitBatchAdd() {
//
const openBatchAddModal = () => {
console.log('打开批量添加模态框');
batchAddFormApi.resetForm();
batchAddModalApi.open();
};
//
const addressLines = ref(0);
//
const getAddressLines = () => {
try {
const formValues = batchAddFormApi.getValues();
const addressList = formValues?.addressList;
if (!addressList || typeof addressList !== 'string') {
addressLines.value = 0;
return 0;
}
const lines = addressList.split('\n').filter((line: string) => line.trim());
addressLines.value = lines.length;
return lines.length;
} catch {
addressLines.value = 0;
return 0;
}
};
// 使
const computedAddressLines = computed(() => {
try {
const formValues = batchAddFormApi.getValues();
const addressList = formValues?.addressList;
if (!addressList || typeof addressList !== 'string') {
return 0;
}
const lines = addressList.split('\n').filter((line: string) => line.trim());
return lines.length;
} catch {
return 0;
}
});
// addressLines
watch(computedAddressLines, (newValue) => {
addressLines.value = newValue;
}, { immediate: true });
//
const handleCacheRefresh = async () => {
try {
cacheRefreshLoading.value = true;
pageLoading.value = true;
loadingTip.value = '缓存刷新中...';
const result = await postDeviceInfoCacheDeviceDataToRedis();
if (result.data) {
Message.success('缓存刷新成功');
@ -532,7 +457,6 @@ const handleCacheRefresh = async () => {
} finally {
cacheRefreshLoading.value = false;
pageLoading.value = false;
loadingTip.value = '缓存刷新中...';
}
};
@ -572,7 +496,7 @@ const toolbarActions = computed(() => [
<template>
<Page auto-content-height>
<Loading :loading="pageLoading" :tip="loadingTip" />
<Loading :loading="pageLoading" tip="缓存刷新中..." />
<Grid>
<template #toolbar-actions>
<TableAction :actions="toolbarActions" />
@ -644,10 +568,6 @@ const toolbarActions = computed(() => [
style=" padding: 4px 8px;text-align: left">
{{ $t('abp.IoTDBBase.TelemetryLog') }}
</Button>
<Button type="text" size="small" @click="repushDeviceInfo.bind(null, row)()"
style="padding: 4px 8px; text-align: left">
重推设备信息
</Button>
<Button type="text" size="small" @click="onDel.bind(null, row)()"
style=" padding: 4px 8px; color: #ff4d4f;text-align: left">
{{ $t('common.delete') }}
@ -671,23 +591,6 @@ const toolbarActions = computed(() => [
</CommandModal>
<BatchAddModal title="批量添加设备" class="w-[800px]">
<BatchAddForm />
<template #footer>
<div class="flex w-full items-center justify-between">
<div class="text-sm text-gray-500">
<span v-if="addressLines > 0">
{{ addressLines }} 行设备地址
</span>
</div>
<div class="flex gap-2">
<Button @click="batchAddModalApi.close()">
{{ $t('common.cancel') }}
</Button>
<Button type="primary" :loading="batchAddModalState?.confirmLoading" @click="submitBatchAdd">
{{ $t('common.confirm') }}
</Button>
</div>
</div>
</template>
</BatchAddModal>
</Page>
</template>

View File

@ -89,14 +89,6 @@ export const tableSchema: any = computed((): VxeGridProps['columns'] => [
]);
export const addDeviceFormSchema: any = computed(() => [
{
component: 'Input',
fieldName: 'deviceAddress',
label: $t('abp.deviceInfos.deviceAddress'),
rules: z.string().min(1, {
message: `${$t('common.pleaseInput')}${$t('abp.deviceInfos.deviceAddress')}`,
}),
},
{
component: 'ApiSelect',
fieldName: 'ioTPlatform',
@ -369,6 +361,14 @@ export const addDeviceFormSchema: any = computed(() => [
},
rules: z.string().optional(),
},
{
component: 'Input',
fieldName: 'deviceAddress',
label: $t('abp.deviceInfos.deviceAddress'),
rules: z.string().min(1, {
message: `${$t('common.pleaseInput')}${$t('abp.deviceInfos.deviceAddress')}`,
}),
},
]);
export const editDeviceFormSchemaEdit: any = computed(() => [
@ -667,25 +667,6 @@ export const commandFormSchema: any = computed(() => [
]);
export const batchAddDeviceFormSchema: any = computed(() => [
{
component: 'Textarea',
fieldName: 'addressList',
label: $t('abp.deviceInfos.deviceAddress'),
componentProps: {
rows: 4,
placeholder: $t('common.pleaseInput') + $t('abp.deviceInfos.deviceAddress') + ',每行一个设备地址',
showCount: true,
maxLength: 2000,
style: {
resize: 'vertical',
minHeight: '32px',
maxHeight: '200px',
},
},
rules: z.string().min(1, {
message: `${$t('common.pleaseInput')}${$t('abp.deviceInfos.deviceAddress')}`,
}),
},
{
component: 'ApiSelect',
fieldName: 'ioTPlatform',
@ -958,4 +939,18 @@ export const batchAddDeviceFormSchema: any = computed(() => [
},
rules: z.string().optional(),
},
{
component: 'Textarea',
fieldName: 'addressList',
label: $t('abp.deviceInfos.deviceAddress'),
componentProps: {
rows: 8,
placeholder: $t('common.pleaseInput') + $t('abp.deviceInfos.deviceAddress') + ',每行一个设备地址',
showCount: true,
maxLength: 2000,
},
rules: z.string().min(1, {
message: `${$t('common.pleaseInput')}${$t('abp.deviceInfos.deviceAddress')}`,
}),
},
]);

View File

@ -8,7 +8,8 @@ import { useRoute } from 'vue-router';
import { Page } from '@vben/common-ui';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import { postDeviceInfoPage, postTableModelCtWingLogInfo } from '#/api-client';
import { postDeviceInfoPage } from '#/api-client';
import { postTableModelCtWingLogInfo } from '#/api-client';
import DeviceSelect from '../deviceData/DeviceSelect.vue';
import { querySchema, tableSchema } from './schema';
@ -52,17 +53,11 @@ const fetchDeviceOptions = async () => {
//
const getDeviceInfoByAddress = (deviceAddress: string) => {
if (
!deviceAddress ||
!deviceOptions.value ||
deviceOptions.value.length === 0
) {
if (!deviceAddress || !deviceOptions.value || deviceOptions.value.length === 0) {
return null;
}
const device = deviceOptions.value.find(
(device) => device.deviceAddress === deviceAddress,
);
const device = deviceOptions.value.find((device) => device.deviceAddress === deviceAddress);
return device;
};
@ -194,9 +189,7 @@ const gridOptions: VxeGridProps<any> = {
ajax: {
query: async ({ page }, formValues) => {
// API
const currentFormValues = gridApi?.formApi
? await gridApi.formApi.getValues()
: {};
const currentFormValues = gridApi?.formApi ? await gridApi.formApi.getValues() : {};
// DeviceAddress使
if (!currentFormValues.DeviceAddress && DeviceAddress) {