// 监测因子复选框默认选项 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 }; }