riku
2024-12-23 329bc53486678ea26b1b63c69299509c01677aeb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// 监测因子复选框默认选项
import { defineProps, ref, watch } from 'vue';
import { checkboxOptions } from '@/constant/checkbox-options';
import { TYPE0 } from '@/constant/device-type';
 
export function useDefaultFactorType() {
  const props = defineProps({
    deviceType: {
      type: String,
      // type0: 车载或无人机; type1:无人船
      default: TYPE0
    }
  });
 
  // 根据当前数据对应的设备类型, 获取默认选中的监测因子id集合
  function defaultFactorTypes() {
    const list = checkboxOptions(props.deviceType);
    if (list.length > 3) {
      return list.slice(0, 3).map((v) => v.value);
    } else {
      return list.map((v) => v.value);
    }
  }
 
  const selectFactorType = ref(defaultFactorTypes());
 
  watch(props.deviceType, (nV, oV) => {
    if (nV != oV) {
      selectFactorType.value = defaultFactorTypes();
    }
  });
 
  return { selectFactorType, props };
}