useInit.ts 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 useInitDevices(devicekind: string) {
  22. const devices = ref<Record<string, any>[]>([]);
  23. const options = ref<{ label: string; value: string }[]>([]);
  24. const selectedDeviceID = ref<string>('');
  25. const selectedDevice = computed(() => {
  26. return (
  27. devices.value.find((e) => {
  28. return e.deviceID === selectedDeviceID.value;
  29. }) || {}
  30. );
  31. });
  32. // 获取设备数据,赋值并以选项格式返回给 Header 消费
  33. function fetchDevices() {
  34. return getHomeData({}).then((result) => {
  35. if (!result[devicekind]) return;
  36. // 如果数据只有一条,转为数据
  37. const records: { strinstallpos?: string; deviceID: string; devicePos?: string }[] = result[devicekind];
  38. devices.value = records;
  39. selectedDeviceID.value = records[0]?.deviceID;
  40. options.value = records.map((e) => {
  41. return {
  42. label: e.strinstallpos || e.devicePos || '/',
  43. value: e.deviceID,
  44. };
  45. });
  46. });
  47. // return list({
  48. // // devicekind,
  49. // }).then(({ records }) => {
  50. // devices.value = records;
  51. // selectedDeviceID.value = records[0]?.id;
  52. // options.value = records.map((e) => {
  53. // return {
  54. // label: e.strinstallpos,
  55. // value: e.id,
  56. // };
  57. // });
  58. // });
  59. }
  60. return {
  61. fetchDevices,
  62. selectedDevice,
  63. selectedDeviceID,
  64. options,
  65. };
  66. }
  67. export function useInitScene(scenekind: string) {
  68. const scene = ref<Record<string, any>[]>([]);
  69. // 获取设备数据,赋值并以选项格式返回给 Header 消费
  70. function fetchScene() {
  71. return getHomeData({}).then((result) => {
  72. if (!result[scenekind]) return;
  73. // 如果数据只有一条,转为数据
  74. const records: { strinstallpos: string; deviceID: string }[] = result[scenekind];
  75. scene.value = records;
  76. });
  77. }
  78. return {
  79. fetchScene,
  80. scene,
  81. };
  82. }