import { getDetailList } from '@/api/management/dictionary'; function loadDictionary() { function queryData(code, that, field) { return new Promise((resolve, reject) => { if (that[field].length) { resolve(that[field]); } getDetailList(code).then(response => { that[field] = response.data; resolve(that[field]); }).catch(error => { console.log('获取字典失败:' + error.message); reject(error); }); }); } function Dictionary() { } Dictionary.prototype = { _TrainingType: [], _SectionType: [], _SectionSepType: [], _SignalPotLampType: [], _SignalLampPostType: [], _SignalLampPositionType: [], _SignalDirectionType: [], _SignalPositionType: [], _SignalUseType: [], _DoorLocationType: [], _WhetherType: [], // 是/否 _EffectiveType: [], // 生效/失效 _RouteNatureType: [], _RouteAutoType: [], _SwitchLocateType: [], _BizType: [], _OrderType: [], _PayType: [], _PayStatus: [], _LogicalViewType: {}, _PhysicalViewType: [], _PermissionType: [], _ProductPostType: [], _ProductType: [], _TimeStyle: [], _RunDirectionType: [], _TrainPositionType: [], _CityType: [], _LineType: [], _TaskList: [], // 任务类型列表 _TaskStatus: [], // 任务状态 _StationControl: [], // 控制权操作类型 _SignalOperation: [], // 信号灯操作类型 _SwitchOperation: [], // 道岔操作类型 _SectionOperation: [], // 区段操作类型 _StationStandOperation: [], // 站台操作类型 _TrainPlanOperation: [], // 行车计划操作类型 _TrainOperation: [], // 列车操作类型 _RegionTypeList: [], // 区间类型列表 _LimitOperation: [], regionTypeList: function () { return queryData('region_type_list', this, '_RegionTypeList'); }, limitOperation: function () { return queryData('limit_operation', this, '_LimitOperation'); }, stationControl: function () { return queryData('station_control', this, '_StationControl'); }, signalOperation: function () { return queryData('signal_operation', this, '_SignalOperation'); }, switchOperation: function () { return queryData('switch_operation', this, '_SwitchOperation'); }, sectionOperation: function () { return queryData('section_operation', this, '_SectionOperation'); }, stationStandOperation: function () { return queryData('station_stand_operation', this, '_StationStandOperation'); }, trainPlanOperation: function () { return queryData('train_plan_operation', this, '_TrainPlanOperation'); }, trainOperation: function () { return queryData('train_operation', this, '_TrainOperation'); }, taskList: function () { return queryData('task_type', this, '_TaskList'); }, taskStatus: function () { return queryData('task_status', this, '_TaskStatus'); }, trainingType: function () { return queryData('training_type', this, '_TrainingType'); }, sectionType: function () { return queryData('section_type', this, '_SectionType'); }, sectionSepType: function () { return queryData('section_sep_type', this, '_SectionSepType'); }, signalPotLampType: function () { return queryData('signal_pot_lamp_type', this, '_SignalPotLampType'); }, signalLampPostType: function () { return queryData('signal_lamp_post_type', this, '_SignalLampPostType'); }, signalLampPositionType: function () { return queryData('signal_lamp_position_type', this, '_SignalLampPositionType'); }, signalDirectionType: function () { return queryData('signal_direction_type', this, '_SignalDirectionType'); }, signalPositionType: function () { return queryData('signal_position_type', this, '_SignalPositionType'); }, signalUseType: function () { return queryData('signal_use_type', this, '_SignalUseType'); }, doorLocationType: function () { return queryData('door_location_type', this, '_DoorLocationType'); }, whetherType: function () { return queryData('whether_type', this, '_WhetherType'); }, effectiveType: function () { return queryData('effective_type', this, '_EffectiveType'); }, routeNatureType: function () { return queryData('route_nature_type', this, '_RouteNatureType'); }, routeAutoType: function () { return queryData('route_auto_type', this, '_RouteAutoType'); }, switchLocateType: function () { return queryData('switch_locate_type', this, '_SwitchLocateType'); }, productPostType: function () { return queryData('product_post_type', this, '_ProductPostType'); }, bizType: function () { return queryData('biz_type', this, '_BizType'); }, orderType: function () { return queryData('order_type', this, '_OrderType'); }, payType: function () { return queryData('pay_type', this, '_PayType'); }, payStatus: function () { return queryData('pay_status', this, '_PayStatus'); }, permissionType: function () { return queryData('permission_type', this, '_PermissionType'); }, productType: function () { return queryData('product_type', this, '_ProductType'); }, timeStyleType: function () { return queryData('time_style', this, '_TimeStyle'); }, runDirectionType: function () { return queryData('run_direction_type', this, '_RunDirectionType'); }, logicalViewType: function () { return queryData('logical_view_Type', this, '_LogicalViewType'); }, physicalViewType: function () { return queryData('physical_view_Type', this, '_PhysicalViewType'); }, trainPositionType: function () { return queryData('train_position_type', this, '_TrainPositionType'); }, cityType: function () { return queryData('city_type', this, '_CityType'); }, lineType: function () { return queryData('line_type', this, '_LineType'); }, translate: function (value, dic) { return new Promise((resolve, reject) => { if (this[dic] instanceof Function) { this[dic]().then(list => { if (list && list.length) { const obj = list.filter(function (item) { return item.value === value; })[0]; const label = obj && obj.label; resolve(label); } else { console.warn('字典列表为空:"' + dic + '"'); resolve(''); } }).catch(error => { console.error('字典翻译异常:' + error.message); reject(error); }); } else { const error = new Error('"' + dic + '" 对象不存在'); console.error('字典翻译异常:' + error.message); reject(error); } }); } }; return new Dictionary(); } // export function addCityNodeByTree(cityList, tree) { // let cityNode = { // children: [], // id: "6", // name: '', // type: 'city', // }; // } export default loadDictionary();