From 8bd8ad3a394566bc5580f0a8490fd0a087f6e5c6 Mon Sep 17 00:00:00 2001 From: wangshuaiswim Date: Fri, 13 Jan 2023 11:02:14 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E8=AE=BE=E5=A4=87?= =?UTF-8?q?=E5=92=8C=E4=BA=A7=E5=93=81=E6=8E=A5=E5=8F=A3=EF=BC=8C=E6=96=B0?= =?UTF-8?q?=E5=A2=9EproductStore=EF=BC=8C=E6=96=B0=E5=A2=9Eutils.ts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/device/instance.ts | 10 +++++++++- src/api/device/product.ts | 17 +++++++++++++++-- src/store/instance.ts | 9 +++++++-- src/store/product.ts | 14 ++++++++++++++ src/utils/utils.ts | 21 +++++++++++++++++++++ 5 files changed, 66 insertions(+), 5 deletions(-) create mode 100644 src/store/product.ts create mode 100644 src/utils/utils.ts diff --git a/src/api/device/instance.ts b/src/api/device/instance.ts index dd91bf13..8c3c964f 100644 --- a/src/api/device/instance.ts +++ b/src/api/device/instance.ts @@ -1,4 +1,5 @@ import server from '@/utils/request' +import { DeviceInstance } from '@/views/device/instance/typings' /** * 删除设备物模型 @@ -13,4 +14,11 @@ export const deleteMetadata = (deviceId: string) => server.remove(`/device-insta * @param data 物模型 * @returns */ -export const saveMetadata = (id: string, data: string) => server.put(`/device/instance/${id}/metadata`, data) \ No newline at end of file +export const saveMetadata = (id: string, data: string) => server.put(`/device/instance/${id}/metadata`, data) + +/** + * 根据设备ID获取设备详情 + * @param id 设备ID + * @returns 设备详情 + */ +export const detail = (id: string) => server.get(`/device-instance/${id}/detail`) \ No newline at end of file diff --git a/src/api/device/product.ts b/src/api/device/product.ts index 53183eb3..68f8b787 100644 --- a/src/api/device/product.ts +++ b/src/api/device/product.ts @@ -1,5 +1,5 @@ import server from '@/utils/request' -import type { DeviceMetadata } from '@/views/device/Product/typings' +import { DeviceMetadata, ProductItem } from '@/views/device/Product/typings' /** * 根据条件查询产品(不带翻页) @@ -23,4 +23,17 @@ export const convertMetadata = (direction: 'from' | 'to', type: string, data: an * @param data 产品数据 * @returns */ -export const modify = (id: string, data: any) => server.put(`/device-product/${id}`, data) \ No newline at end of file +export const modify = (id: string, data: any) => server.put(`/device-product/${id}`, data) + +/** + * + * @returns + */ +export const getCodecs = () => server.get<{id: string, name: string}>('/device/product/metadata/codecs') + +/** + * 根据产品ID获取产品详情 + * @param id 产品ID + * @returns + */ +export const detail = (id: string) => server.get(`/device-product/${id}`) \ No newline at end of file diff --git a/src/store/instance.ts b/src/store/instance.ts index a97a247e..f4d6e145 100644 --- a/src/store/instance.ts +++ b/src/store/instance.ts @@ -1,7 +1,12 @@ -import { InstanceModel } from "@/views/device/instance/typings"; +import { DeviceInstance, InstanceModel } from "@/views/device/instance/typings"; import { defineStore } from "pinia"; export const useInstanceStore = defineStore({ id: 'device', state: () => ({} as InstanceModel), -}); \ No newline at end of file + actions: { + setCurrent(current: Partial) { + this.current = current + } + } +}) \ No newline at end of file diff --git a/src/store/product.ts b/src/store/product.ts new file mode 100644 index 00000000..32ee205d --- /dev/null +++ b/src/store/product.ts @@ -0,0 +1,14 @@ +import { ProductItem } from "@/views/device/Product/typings"; +import { defineStore } from "pinia"; + +export const useProductStore = defineStore({ + id: 'product', + state: () => ({ + current: {} as ProductItem | undefined + }), + actions: { + setCurrent(current: ProductItem) { + this.current = current + } + } +}) \ No newline at end of file diff --git a/src/utils/utils.ts b/src/utils/utils.ts new file mode 100644 index 00000000..a238c5cc --- /dev/null +++ b/src/utils/utils.ts @@ -0,0 +1,21 @@ +/** + * 把数据下载成JSON + * @param record + * @param fileName + */ +export const downloadObject = (record: Record, fileName: string, format?: string) => { + // 创建隐藏的可下载链接 + const ghostLink = document.createElement('a'); + ghostLink.download = `${fileName ? '' : record?.name}${fileName}_${moment(new Date()).format( + format || 'YYYY_MM_DD', + )}.json`; + ghostLink.style.display = 'none'; + //字符串内容转成Blob地址 + const blob = new Blob([JSON.stringify(record)]); + ghostLink.href = URL.createObjectURL(blob); + //触发点击 + document.body.appendChild(ghostLink); + ghostLink.click(); + //移除 + document.body.removeChild(ghostLink); +}; \ No newline at end of file