useInit.ts 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. import { computed, ref } from 'vue';
  2. import { list as cfgList } from '@/views/vent/deviceManager/configurationTable/configuration.api';
  3. // import { list } from '@/views/vent/deviceManager/deviceTable/device.api';
  4. import { Config } from '@/views/vent/deviceManager/configurationTable/types';
  5. import { getHomeData } from '../configurable.api';
  6. // import mapComponent from './components/3Dmap/index.vue';
  7. // export function useInitConfig(deviceType: string) {
  8. // function fetchConfig() {
  9. // cfgList({
  10. // deviceType,
  11. // }).then(({ records }) => {
  12. // config.value = records[0];
  13. // });
  14. // }
  15. // const config = ref<Partial<Config>>({});
  16. // return {
  17. // fetchConfig,
  18. // config,
  19. // };
  20. // }
  21. export function useInitConfigs() {
  22. const configs = ref<Config[]>([]);
  23. const isOriginal = computed(() => {
  24. return configs.value.some((c) => {
  25. return c.showStyle.version === 'original';
  26. });
  27. });
  28. function fetchConfigs() {
  29. cfgList({}).then(({ records }) => {
  30. configs.value = records;
  31. });
  32. }
  33. return {
  34. fetchConfigs,
  35. configs,
  36. isOriginal,
  37. };
  38. }
  39. export function useInitDevices(devicekind: string) {
  40. const devices = ref<Record<string, any>[]>([]);
  41. const options = ref<{ label: string; value: string }[]>([]);
  42. const selectedDeviceID = ref<string>('');
  43. const selectedDevice = computed(() => {
  44. return (
  45. devices.value.find((e) => {
  46. return e.deviceID === selectedDeviceID.value;
  47. }) || {}
  48. );
  49. });
  50. // 获取设备数据,赋值并以选项格式返回给 Header 消费
  51. function fetchDevices() {
  52. return getHomeData({}).then((result) => {
  53. if (!result[devicekind]) return;
  54. // 如果数据只有一条,转为数据
  55. const records: { strinstallpos?: string; deviceID: string; devicePos?: string }[] = result[devicekind];
  56. devices.value = records;
  57. selectedDeviceID.value = records[0]?.deviceID;
  58. options.value = records.map((e) => {
  59. return {
  60. label: e.strinstallpos || e.devicePos || '/',
  61. value: e.deviceID,
  62. };
  63. });
  64. });
  65. // return list({
  66. // // devicekind,
  67. // }).then(({ records }) => {
  68. // devices.value = records;
  69. // selectedDeviceID.value = records[0]?.id;
  70. // options.value = records.map((e) => {
  71. // return {
  72. // label: e.strinstallpos,
  73. // value: e.id,
  74. // };
  75. // });
  76. // });
  77. }
  78. return {
  79. fetchDevices,
  80. selectedDevice,
  81. selectedDeviceID,
  82. options,
  83. };
  84. }
  85. export function useInitScene(scenekind: string) {
  86. const scene = ref<Record<string, any>[]>([]);
  87. // 获取设备数据,赋值并以选项格式返回给 Header 消费
  88. function fetchScene() {
  89. return getHomeData({}).then((result) => {
  90. if (!result[scenekind]) return;
  91. // 如果数据只有一条,转为数据
  92. const records: { strinstallpos: string; deviceID: string }[] = result[scenekind];
  93. scene.value = records;
  94. });
  95. }
  96. return {
  97. fetchScene,
  98. scene,
  99. };
  100. }