From 732292c01e6c9ccf4760d32a5e403b7546e48299 Mon Sep 17 00:00:00 2001 From: fuyunfeng <1069035666@qq.com> Date: Tue, 19 Mar 2024 15:51:49 +0800 Subject: [PATCH 01/10] =?UTF-8?q?OTA=E5=8D=87=E7=BA=A7=20=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E5=92=8C=E8=AF=A6=E6=83=85=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/things/otaPackage.ts | 74 +++++++ src/locales/lang/en/things.ts | 1 + src/locales/lang/zh-CN/things.ts | 1 + src/router/routes/modules/things.ts | 14 +- src/utils/index.ts | 7 + src/views/things/desktop/sysadmin/index.vue | 8 +- src/views/things/otaPackage/detail.vue | 182 ++++++++++++++++ src/views/things/otaPackage/form.vue | 3 + src/views/things/otaPackage/list.vue | 229 ++++++++++++++++++++ 9 files changed, 512 insertions(+), 7 deletions(-) create mode 100644 src/api/things/otaPackage.ts create mode 100644 src/views/things/otaPackage/detail.vue create mode 100644 src/views/things/otaPackage/form.vue create mode 100644 src/views/things/otaPackage/list.vue diff --git a/src/api/things/otaPackage.ts b/src/api/things/otaPackage.ts new file mode 100644 index 0000000..979b0ae --- /dev/null +++ b/src/api/things/otaPackage.ts @@ -0,0 +1,74 @@ +import { BasicModel, BasicQuery, Page } from "../model/baseModel"; +import { EntityId } from "/#/store"; +import { EntityType } from "/@/enums/entityTypeEnum"; +import { defHttp } from "/@/utils/http/axios"; + +export interface OtaPackageInfo extends BasicModel { + tenantId: EntityId; + deviceProfileId: EntityId; + title?: string; + type?: 'FIRMWARE' | 'SOFTWARE'; + version?: string; + tag?: string; + url?: string; + hasData?: boolean; + fileName?: string; + contentType?: string; + checksum?: string; + dataSize?: number; + checksumAlgorithm?: 'MD5' | 'SHA256' | 'SHA384' | 'SHA512' | 'CRC32' | 'MURMUR3_32' | 'MURMUR3_128'; +} + +export interface otaPackage extends OtaPackageInfo { + data?: Recordable; +} + +export function getOtaPackageInfoById(otaPackageId: string) { + return defHttp.get({ + url: `/api/otaPackage/info/${otaPackageId}`, + }) +} + +export function getOtaPackageById(otaPackageId: string) { + return defHttp.get({ + url: `/api/otaPackage/${otaPackageId}`, + }) +} + +export function saveOtaPackageInfo(data: { otaPackageInfo: OtaPackageInfo, usesUrl: boolean } | any) { + return defHttp.postJson({ + url: '/api/otaPackage', + data + }) +} + +export function saveOtaPackageData(otaPackageId: string, checksum: string, checksumAlgorithmStr: string, file: any) { + return defHttp.post({ + url: `/api/otaPackage/${otaPackageId}`, + data: { + checksum: checksum, + checksumAlgorithmStr: checksumAlgorithmStr, + file: file, + } + }) +} + +export function getOtaPackageList(params: BasicQuery) { + return defHttp.get>({ + url: '/api/otaPackages', + params, + }); +} + +export function getOtaPackageListByDeviceProfile(deviceProfileId: string, type: string, params: BasicQuery) { + return defHttp.get>({ + url: `/api/otaPackages/${deviceProfileId}/${type}`, + params, + }); +} + +export function deleteOtaPackage(otaPackageId: string) { + return defHttp.delete({ + url: `/api/otaPackage/${otaPackageId}`, + }); +} \ No newline at end of file diff --git a/src/locales/lang/en/things.ts b/src/locales/lang/en/things.ts index c04a789..dbef3ee 100644 --- a/src/locales/lang/en/things.ts +++ b/src/locales/lang/en/things.ts @@ -27,4 +27,5 @@ export default { entity: 'Entity', asset: 'Asset', entityView: 'Entity View', + ota: 'OTA Update', } \ No newline at end of file diff --git a/src/locales/lang/zh-CN/things.ts b/src/locales/lang/zh-CN/things.ts index 9bd154c..944c98e 100644 --- a/src/locales/lang/zh-CN/things.ts +++ b/src/locales/lang/zh-CN/things.ts @@ -27,4 +27,5 @@ export default { entity: '实体', asset: '资产', entityView: '实体视图', + ota: 'OTA升级', } \ No newline at end of file diff --git a/src/router/routes/modules/things.ts b/src/router/routes/modules/things.ts index 73a5b98..742d545 100644 --- a/src/router/routes/modules/things.ts +++ b/src/router/routes/modules/things.ts @@ -229,7 +229,7 @@ const things: AppRouteModule = { component: LAYOUT, redirect: '/rule-chain/list', meta: { - orderNo: 130, + orderNo: 120, icon: 'ant-design:subnode-outlined', tabIcon: 'ant-design:subnode-outlined', title: t('things.ruleChain'), @@ -262,6 +262,18 @@ const things: AppRouteModule = { }, ] }, + { + path: '/otaPackage/list', + name: 'OtaPackage', + component: () => import('/@/views/things/otaPackage/list.vue'), + meta: { + orderNo: 130, + icon: 'ant-design:paper-clip-outlined', + tabIcon: 'ant-design:paper-clip-outlined', + title: t('things.ota'), + useAuthority: [Authority.TENANT_ADMIN] + }, + }, { path: 'resources', name: 'Resource', diff --git a/src/utils/index.ts b/src/utils/index.ts index 2a553d7..cf0c83a 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -113,3 +113,10 @@ export function copyToClipboard(value: string, msg: string | undefined = '复制 export const sleep = (time: number) => { return new Promise(resolve => setTimeout(resolve, time)); } + +export function convertBytesToSize(bytes: number) { + const sizes = ['b', 'Kb', 'Mb', 'Gb', 'Tb']; // 存储单位的数组 + if (bytes === 0) { return '0 b' }; + const i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024))); + return Number(bytes / Math.pow(1024, i)).toFixed(2) + ' ' + sizes[i]; +} diff --git a/src/views/things/desktop/sysadmin/index.vue b/src/views/things/desktop/sysadmin/index.vue index 192582a..f42e441 100644 --- a/src/views/things/desktop/sysadmin/index.vue +++ b/src/views/things/desktop/sysadmin/index.vue @@ -150,6 +150,7 @@ import CpuStateLine from '../components/chart/CpuStateLine.vue'; import { ref, onMounted, onBeforeUnmount } from 'vue'; import { EntityType } from '/@/enums/entityTypeEnum'; import { isArray } from 'lodash'; +import { convertBytesToSize } from '/@/utils'; const go = useGo(); const { getAndIncrementCmdId, send, unsubscribe } = useWebsocketStore(); @@ -331,12 +332,7 @@ function initCmdId() { CPU_STATUS_CMD_ID.value = getAndIncrementCmdId(); } -function convertBytesToSize(bytes: number) { - const sizes = ['b', 'Kb', 'Mb', 'Gb', 'Tb']; // 存储单位的数组 - if (bytes === 0) { return '0 b' }; - const i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024))); - return Number(bytes / Math.pow(1024, i)).toFixed(2) + ' ' + sizes[i]; -} + onBeforeUnmount(() => { unsubscribeEntityCount(); diff --git a/src/views/things/otaPackage/detail.vue b/src/views/things/otaPackage/detail.vue new file mode 100644 index 0000000..79087b9 --- /dev/null +++ b/src/views/things/otaPackage/detail.vue @@ -0,0 +1,182 @@ +