81 lines
1.7 KiB
TypeScript
81 lines
1.7 KiB
TypeScript
import type { Recordable } from '@vben/types';
|
|
|
|
import { sha256 } from 'js-sha256';
|
|
|
|
import { pyRequestClient } from '#/api/request';
|
|
|
|
export namespace SystemDeviceApi {
|
|
export interface SystemDevice {
|
|
[key: string]: any;
|
|
id: string;
|
|
remark?: string;
|
|
name: string;
|
|
roles: string[];
|
|
status: 0 | 1;
|
|
is_superuser: 0 | 1;
|
|
dept_id?: string;
|
|
dept_name?: string;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 获取设备列表数据
|
|
*/
|
|
async function getDeviceList(params: Recordable<any>) {
|
|
return pyRequestClient.get<Array<SystemDeviceApi.SystemDevice>>(
|
|
'/iot/common/device/list',
|
|
{ params },
|
|
);
|
|
}
|
|
|
|
/**
|
|
* 创建设备
|
|
* @param data 设备数据
|
|
*/
|
|
async function createDevice(data: Omit<SystemDeviceApi.SystemDevice, 'id'>) {
|
|
data.password_hash = sha256(data.password?.toString() || '');
|
|
delete data.password;
|
|
return pyRequestClient.post('/iot/common/device', data);
|
|
}
|
|
|
|
/**
|
|
* 更新设备
|
|
*
|
|
* @param id 设备 ID
|
|
* @param data 设备数据
|
|
*/
|
|
async function updateDevice(
|
|
id: string,
|
|
data: Omit<SystemDeviceApi.SystemDevice, 'id'>,
|
|
) {
|
|
return pyRequestClient.put(`/iot/common/device/${id}`, data);
|
|
}
|
|
/**
|
|
* 更新设备(部分更新)
|
|
*
|
|
* @param id 设备 ID
|
|
* @param data 需要更新的字段(部分字段即可)
|
|
*/
|
|
async function updateDevicePatch(
|
|
id: string,
|
|
data: Partial<Omit<SystemDeviceApi.SystemDevice, 'id'>>,
|
|
) {
|
|
return pyRequestClient.patch(`/iot/common/device/${id}`, data);
|
|
}
|
|
|
|
/**
|
|
* 删除设备
|
|
* @param id 设备 ID
|
|
*/
|
|
async function deleteDevice(id: string) {
|
|
return pyRequestClient.delete(`/iot/common/device/${id}`);
|
|
}
|
|
|
|
export {
|
|
createDevice,
|
|
deleteDevice,
|
|
getDeviceList,
|
|
updateDevice,
|
|
updateDevicePatch,
|
|
};
|