feat: 新增设备和产品接口,新增productStore,新增utils.ts
This commit is contained in:
parent
3ed04a35ff
commit
8bd8ad3a39
|
@ -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)
|
||||
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<DeviceInstance>(`/device-instance/${id}/detail`)
|
|
@ -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)
|
||||
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<ProductItem>(`/device-product/${id}`)
|
|
@ -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),
|
||||
});
|
||||
actions: {
|
||||
setCurrent(current: Partial<DeviceInstance>) {
|
||||
this.current = current
|
||||
}
|
||||
}
|
||||
})
|
|
@ -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
|
||||
}
|
||||
}
|
||||
})
|
|
@ -0,0 +1,21 @@
|
|||
/**
|
||||
* 把数据下载成JSON
|
||||
* @param record
|
||||
* @param fileName
|
||||
*/
|
||||
export const downloadObject = (record: Record<string, any>, 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);
|
||||
};
|
Loading…
Reference in New Issue