setting.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. 'use strict';
  2. const { Controller } = require('ee-core');
  3. const Log = require('ee-core/log');
  4. const Services = require('ee-core/services');
  5. const path = require('path');
  6. const fs = require('fs');
  7. const { getDeviceConfigs, getDeviceConfigDetail, removeConfig, saveDeviceConfig, resetDeviceConfig } = require('../api/setting');
  8. const errData = {
  9. msg :'请求失败,请联系管理员',
  10. code:999
  11. }
  12. /**
  13. * 设置控制器
  14. * @class
  15. */
  16. class SettingController extends Controller {
  17. constructor(ctx) {
  18. super(ctx);
  19. this.configPath = path.join(__dirname, '..', 'config', 'app.config.json');
  20. }
  21. /**
  22. * 获取设备配置列表
  23. */
  24. async getDeviceConfigList(args) {
  25. try {
  26. const result = await getDeviceConfigs(args);
  27. if(result.data) return result.data
  28. return errData;
  29. } catch (error) {
  30. Log.error('获取设备配置列表失败:', error);
  31. return errData;
  32. }
  33. }
  34. /**
  35. * 获取设备配置详情
  36. * @param {Object} args - 配置ID
  37. */
  38. async getDeviceConfigDetail(args) {
  39. try {
  40. const result = await getDeviceConfigDetail(args);
  41. if(result.data) return result.data
  42. return errData;
  43. } catch (error) {
  44. return errData;
  45. }
  46. }
  47. /**
  48. * 删除设备配置
  49. * @param {Object} args - 配置ID
  50. */
  51. async removeDeviceConfig(args) {
  52. try {
  53. console.log('1111');
  54. const result = await removeConfig(args);
  55. console.log(result);
  56. if(result.data) return result.data
  57. return errData;
  58. } catch (error) {
  59. Log.error('删除设备配置失败:', error);
  60. return errData;
  61. }
  62. }
  63. /**
  64. * 保存设备配置
  65. * @param {Object} args - 配置内容
  66. */
  67. async saveDeviceConfig(args) {
  68. try {
  69. const result = await saveDeviceConfig(args);
  70. if(result.data) return result.data
  71. return errData;
  72. } catch (error) {
  73. Log.error('保存设备配置失败:', error);
  74. return errData;
  75. }
  76. }
  77. /**
  78. * 重置设备配置
  79. * @param {Object} args - 配置ID
  80. */
  81. async resetDeviceConfig(args) {
  82. try {
  83. const result = await resetDeviceConfig(args);
  84. if(result.data) return result.data
  85. return errData;
  86. } catch (error) {
  87. Log.error('重置设备配置失败:', error);
  88. return errData;
  89. }
  90. }
  91. }
  92. SettingController.toString = () => '[class SettingController]';
  93. module.exports = SettingController;