useInit.ts 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 { ModuleData } from '@/views/vent/deviceManager/configurationTable/adapters';
  5. // import mapComponent from './components/3Dmap/index.vue';
  6. export function useInitConfig(deviceType: string) {
  7. function fetchConfig() {
  8. cfgList({
  9. deviceType,
  10. }).then(({ records }) => {
  11. configs.value = records[0]?.moduleData;
  12. });
  13. }
  14. const configs = ref<ModuleData>({});
  15. return {
  16. fetchConfig,
  17. configs,
  18. };
  19. }
  20. export function useInitDevices(devicekind: string) {
  21. const devices = ref<Record<string, any>[]>([]);
  22. const options = ref<{ label: string; value: string }[]>([]);
  23. const selectedDeviceID = ref<string>('');
  24. const selectedDevice = computed(() => {
  25. return (
  26. devices.value.find((e) => {
  27. return e.id === selectedDeviceID.value;
  28. }) || {}
  29. );
  30. });
  31. // 获取设备数据,赋值并以选项格式返回给 Header 消费
  32. function fetchDevices() {
  33. return list({
  34. devicekind,
  35. }).then(({ records }) => {
  36. devices.value = records;
  37. selectedDeviceID.value = records[0]?.id;
  38. options.value = records.map((e) => {
  39. return {
  40. label: e.strinstallpos,
  41. value: e.id,
  42. };
  43. });
  44. });
  45. }
  46. return {
  47. fetchDevices,
  48. selectedDevice,
  49. selectedDeviceID,
  50. options,
  51. };
  52. }