Files
wer-admin/src/views/biz/device/constants.ts
2026-10-30 14:16:09 +08:00

48 lines
2.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { toRefs, type Ref } from 'vue';
import { useDict } from '@/utils/dict';
/**
* 设备模块字典:设备类型走后端字典管理(ur_device_type,字典项只有电表/水表),
* 控制状态后端字典尚未建立,先用本地兜底选项;列表页与详情页共用这里的定义。
*/
export const DEVICE_TYPE_DICT = 'ur_device_type';
/** 设备类型字典(字典未加载时为空数组,类型列会回显原始值) */
export const useDeviceTypeDict = () => {
return toRefs<any>(useDict(DEVICE_TYPE_DICT))[DEVICE_TYPE_DICT] as Ref<DictDataOption[]>;
};
/** 控制状态(0正常,1强制拉闸,2欠费拉闸,3离线) */
export const switchStatusOptions: DictDataOption[] = [
{ label: '正常', value: '0', elTagType: 'success' },
{ label: '强制拉闸', value: '1', elTagType: 'danger' },
{ label: '欠费拉闸', value: '2', elTagType: 'warning' },
{ label: '离线', value: '3', elTagType: 'info' }
];
/** 只有电表、水表支持清零/抄表/拉闸 */
export const METER_TYPES = ['0', '1'];
/** 已拉闸的状态:强制拉闸、欠费拉闸 */
export const CUT_OFF_STATUS = ['1', '2'];
/** 是否水表:deviceType 为 1 表示水表,0 为电表 */
export const isWaterMeter = (deviceType?: string) => String(deviceType) === '1';
/** 恢复文案:水表叫恢复供水,电表叫恢复供电(拉闸动作水电统一叫拉闸) */
export const getRestoreLabel = (deviceType?: string) => (isWaterMeter(deviceType) ? '恢复供水' : '恢复供电');
/** 设备类型文案:字典里找不到时回显原始值 */
export const getDeviceTypeLabel = (options: DictDataOption[], value?: string) => {
return options.find(item => item.value === String(value))?.label || (value ? String(value) : '—');
};
/** 控制状态选项 */
export const getSwitchStatusOption = (value?: string) => switchStatusOptions.find(item => item.value === String(value));
/** 控制状态文案 */
export const getSwitchStatusLabel = (value?: string) => getSwitchStatusOption(value)?.label || '—';
/** 控制状态配色 */
export const getSwitchStatusClass = (value?: string) => `switch-status--${getSwitchStatusOption(value)?.elTagType || 'info'}`;