| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- 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 useInitConfigs() {
- const configs = ref<Config[]>([]);
- const isOriginal = computed(() => {
- return configs.value.some((c) => {
- return c.showStyle.version === 'original';
- });
- });
- function fetchConfigs() {
- cfgList({}).then(({ records }) => {
- configs.value = records;
- });
- }
- return {
- fetchConfigs,
- configs,
- isOriginal,
- };
- }
- 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,
- };
- }
|