| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- '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, removeConfig, saveDeviceConfig, resetDeviceConfig } = 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;
- }
- }
- /**
- * 获取设备配置详情
- * @param {Object} args - 配置ID
- */
- async getDeviceConfigDetail(args) {
- try {
- const result = await getDeviceConfigDetail(args);
- if(result.data) return result.data
- return errData;
- } catch (error) {
- return errData;
- }
- }
- /**
- * 删除设备配置
- * @param {Object} args - 配置ID
- */
- async removeDeviceConfig(args) {
- try {
- console.log('1111');
- const result = await removeConfig(args);
- console.log(result);
- 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;
- }
- }
- /**
- * 重置设备配置
- * @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;
- }
- }
- }
- SettingController.toString = () => '[class SettingController]';
- module.exports = SettingController;
|