| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189 |
- 'use strict';
- const { Controller } = require('ee-core');
- const Log = require('ee-core/log');
- const Services = require('ee-core/services');
- const path = require('path');
- const fs = require('fs');
- const {
- getDeviceConfigs,
- getDeviceConfigDetail,
- getDeviceConfigDetailQuery,
- removeConfig,
- saveDeviceConfig,
- resetDeviceConfig,
- updateSysConfigs,
- getSysConfig,
- getDeviceTabs,
- updateLeftRightConfig,
- updateTabName
- } = require('../api/setting');
- const errData = {
- msg :'请求失败,请联系管理员',
- code:999
- }
- /**
- * 设置控制器
- * @class
- */
- class SettingController extends Controller {
- constructor(ctx) {
- super(ctx);
- this.configPath = path.join(__dirname, '..', 'config', 'app.config.json');
- }
- /**
- * 获取设备配置列表
- */
- async getDeviceConfigList(args) {
- try {
- const result = await getDeviceConfigs(args);
- if(result.data) return result.data
- return errData;
- } catch (error) {
- Log.error('获取设备配置列表失败:', error);
- return errData;
- }
- }
- /**
- * 获取二级 设备配置列表
- */
- async getDeviceTabs(args) {
- try {
- const result = await getDeviceTabs(args);
- if(result.data) return result.data
- return errData;
- } catch (error) {
- Log.error('获取设备配置二级列表失败:', error);
- return errData;
- }
- }
- /**
- * 获取设备配置详情
- * @param {Object} args - 配置ID
- */
- async getDeviceConfigDetail(args) {
- try {
- let fun = getDeviceConfigDetail
- if(!args.id) {
- fun = getDeviceConfigDetailQuery
- }
- const result = await fun(args);
- if(result.data) return result.data
- return errData;
- } catch (error) {
- Log.error('获取设备配置详情失败:', error);
- return errData;
- }
- }
- /**
- * 删除设备配置
- * @param {Object} args - 配置ID
- */
- async removeDeviceConfig(args) {
- try {
- const result = await removeConfig(args)
- if(result.data) return result.data
- return errData;
- } catch (error) {
- Log.error('删除设备配置失败:', error);
- return errData;
- }
- }
- /**
- * 保存设备配置
- * @param {Object} args - 配置内容
- */
- async saveDeviceConfig(args) {
- try {
- const result = await saveDeviceConfig(args);
- if(result.data) return result.data
- return errData;
- } catch (error) {
- Log.error('保存设备配置失败:', error);
- return errData;
- }
- }
- async updateLeftRightConfig(args) {
- try {
- const result = await updateLeftRightConfig(args);
- if(result.data) return result.data
- return errData;
- } catch (error) {
- Log.error('更新左右脚失败:', error);
- return errData;
- }
- }
- /**
- * 重置设备配置
- * @param {Object} args - 配置ID
- */
- async resetDeviceConfig(args) {
- try {
- const result = await resetDeviceConfig(args);
- if(result.data) return result.data
- return errData;
- } catch (error) {
- Log.error('重置设备配置失败:', error);
- return errData;
- }
- }
- async updateTabName(args) {
- try {
- const result = await updateTabName(args);
- if(result.data) return result.data
- return errData;
- } catch (error) {
- Log.error('重命名配置失败:', error);
- return errData;
- }
- }
- /**
- * 读取配置
- * @param {Object} args - 配置ID
- */
- async getSysConfig(args) {
- try {
- const result = await getSysConfig(args);
- if(result.data) return result.data
- return errData;
- } catch (error) {
- Log.error('重置设备配置失败:', error);
- return errData;
- }
- }
- /**
- * 保存配置
- * @param {Object} args - 配置ID
- */
- async updateSysConfigs(args) {
- try {
- const result = await updateSysConfigs(args);
- if(result.data) return result.data
- return errData;
- } catch (error) {
- Log.error('保存配置:', error);
- return errData;
- }
- }
- }
- SettingController.toString = () => '[class SettingController]';
- module.exports = SettingController;
|