| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- import { computed, ref } from 'vue';
- import { list as cfgList } from '@/views/vent/deviceManager/configurationTable/configuration.api';
- // import { list } from '@/views/vent/deviceManager/deviceTable/device.api';
- import { Config } from '@/views/vent/deviceManager/configurationTable/types';
- import { getHomeData } from '../configurable.api';
- // import mapComponent from './components/3Dmap/index.vue';
- export function useInitConfig(deviceType: string) {
- function fetchConfig() {
- cfgList({
- deviceType,
- }).then(({ records }) => {
- config.value = records[0];
- });
- }
- const config = ref<Partial<Config>>({});
- return {
- fetchConfig,
- config,
- };
- }
- export function useInitDevices(devicekind: string) {
- const devices = ref<Record<string, any>[]>([]);
- const options = ref<{ label: string; value: string }[]>([]);
- const selectedDeviceID = ref<string>('');
- const selectedDevice = computed(() => {
- return (
- devices.value.find((e) => {
- return e.deviceID === selectedDeviceID.value;
- }) || {}
- );
- });
- // 获取设备数据,赋值并以选项格式返回给 Header 消费
- function fetchDevices() {
- return getHomeData({}).then((result) => {
- if (!result[devicekind]) return;
- // 如果数据只有一条,转为数据
- const records: { strinstallpos?: string; deviceID: string; devicePos?: string }[] = result[devicekind];
- devices.value = records;
- selectedDeviceID.value = records[0]?.deviceID;
- options.value = records.map((e) => {
- return {
- label: e.strinstallpos || e.devicePos || '/',
- value: e.deviceID,
- };
- });
- });
- // return list({
- // // devicekind,
- // }).then(({ records }) => {
- // devices.value = records;
- // selectedDeviceID.value = records[0]?.id;
- // options.value = records.map((e) => {
- // return {
- // label: e.strinstallpos,
- // value: e.id,
- // };
- // });
- // });
- }
- return {
- fetchDevices,
- selectedDevice,
- selectedDeviceID,
- options,
- };
- }
- export function useInitScene(scenekind: string) {
- const scene = ref<Record<string, any>[]>([]);
- // 获取设备数据,赋值并以选项格式返回给 Header 消费
- function fetchScene() {
- return getHomeData({}).then((result) => {
- if (!result[scenekind]) return;
- // 如果数据只有一条,转为数据
- const records: { strinstallpos: string; deviceID: string }[] = result[scenekind];
- scene.value = records;
- });
- }
- return {
- fetchScene,
- scene,
- };
- }
|