123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- 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 { getFormattedText } from '../../../deviceManager/configurationTable/adapters';
- // 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 === '原版';
- });
- });
- const isCommon = computed(() => {
- return configs.value.some((c) => {
- return c.showStyle.version === '普通版';
- });
- });
- const isBD = computed(() => {
- return configs.value.some((c) => {
- return c.showStyle.version === '保德';
- });
- });
- function fetchConfigs(pageType?: string) {
- return cfgList({ pageType }).then(({ records }) => {
- configs.value = records;
- });
- }
- return {
- fetchConfigs,
- configs,
- isOriginal,
- isCommon,
- isBD,
- };
- }
- /** 初始化设备信息,包含了适配了 header config 的下拉框选项、已选择设备的各个详细子项等,如果模块不需要展示 header 那么会将全部信息提供给已选择设备以供消费 */
- export function useInitDevices(devicekind: string, config: Config['moduleData']) {
- const { header, mock } = config;
- 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.id === selectedDeviceID.value;
- }) || {}
- );
- });
- const selectedDeviceLabel = computed(() => {
- const res = options.value.find((e) => {
- return e.value === selectedDeviceID.value;
- });
- return res ? res.label : '';
- });
- const selectedDeviceSlot = computed(() => {
- return getFormattedText(selectedDevice.value, header.slot.value);
- });
- // 获取设备数据,赋值并以选项格式返回给 Header 消费
- function fetchDevices() {
- const { value } = header.selector;
- const promise = mock ? Promise.resolve(mock) : getHomeData({});
- return promise.then((result) => {
- if (header.show && header.showSelector && result[devicekind]) {
- // 如果配置里指明需要 header,检验后初始化设备信息
- const records: Record<string, any>[] = result[devicekind];
- devices.value = records.map((e, i) => {
- return {
- id: i,
- ...e,
- };
- });
- options.value = devices.value.map((e) => {
- return {
- label: getFormattedText(e, value),
- value: e.id,
- };
- });
- selectedDeviceID.value = options.value[0]?.value;
- } else {
- // 没有的话按默认的,将返回结果直接作为一整个设备信息供模块使用
- const record = {
- ...result,
- id: '00000000',
- };
- devices.value = [record];
- selectedDeviceID.value = record.id;
- }
- });
- }
- return {
- fetchDevices,
- selectedDevice,
- selectedDeviceID,
- selectedDeviceSlot,
- selectedDeviceLabel,
- 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; id: string }[] = result[scenekind];
- scene.value = records;
- });
- }
- return {
- fetchScene,
- scene,
- };
- }
|