setting.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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 {
  8. getDeviceConfigs,
  9. getDeviceConfigDetail,
  10. getDeviceConfigDetailQuery,
  11. removeConfig,
  12. saveDeviceConfig,
  13. resetDeviceConfig,
  14. updateSysConfigs,
  15. getSysConfig,
  16. getDeviceTabs,
  17. updateLeftRightConfig,
  18. updateTabName
  19. } = require('../api/setting');
  20. const errData = {
  21. msg :'请求失败,请联系管理员',
  22. code:999
  23. }
  24. /**
  25. * 设置控制器
  26. * @class
  27. */
  28. class SettingController extends Controller {
  29. constructor(ctx) {
  30. super(ctx);
  31. this.configPath = path.join(__dirname, '..', 'config', 'app.config.json');
  32. }
  33. /**
  34. * 获取设备配置列表
  35. */
  36. async getDeviceConfigList(args) {
  37. try {
  38. const result = await getDeviceConfigs(args);
  39. if(result.data) return result.data
  40. return errData;
  41. } catch (error) {
  42. Log.error('获取设备配置列表失败:', error);
  43. return errData;
  44. }
  45. }
  46. /**
  47. * 获取二级 设备配置列表
  48. */
  49. async getDeviceTabs(args) {
  50. try {
  51. const result = await getDeviceTabs(args);
  52. if(result.data) return result.data
  53. return errData;
  54. } catch (error) {
  55. Log.error('获取设备配置二级列表失败:', error);
  56. return errData;
  57. }
  58. }
  59. /**
  60. * 获取设备配置详情
  61. * @param {Object} args - 配置ID
  62. */
  63. async getDeviceConfigDetail(args) {
  64. try {
  65. let fun = getDeviceConfigDetail
  66. if(!args.id) {
  67. fun = getDeviceConfigDetailQuery
  68. }
  69. const result = await fun(args);
  70. if(result.data) return result.data
  71. return errData;
  72. } catch (error) {
  73. return errData;
  74. }
  75. }
  76. /**
  77. * 删除设备配置
  78. * @param {Object} args - 配置ID
  79. */
  80. async removeDeviceConfig(args) {
  81. try {
  82. const result = await removeConfig(args)
  83. if(result.data) return result.data
  84. return errData;
  85. } catch (error) {
  86. Log.error('删除设备配置失败:', error);
  87. return errData;
  88. }
  89. }
  90. /**
  91. * 保存设备配置
  92. * @param {Object} args - 配置内容
  93. */
  94. async saveDeviceConfig(args) {
  95. try {
  96. const result = await saveDeviceConfig(args);
  97. if(result.data) return result.data
  98. return errData;
  99. } catch (error) {
  100. Log.error('保存设备配置失败:', error);
  101. return errData;
  102. }
  103. }
  104. async updateLeftRightConfig(args) {
  105. try {
  106. const result = await updateLeftRightConfig(args);
  107. if(result.data) return result.data
  108. return errData;
  109. } catch (error) {
  110. Log.error('更新左右脚失败:', error);
  111. return errData;
  112. }
  113. }
  114. /**
  115. * 重置设备配置
  116. * @param {Object} args - 配置ID
  117. */
  118. async resetDeviceConfig(args) {
  119. try {
  120. const result = await resetDeviceConfig(args);
  121. if(result.data) return result.data
  122. return errData;
  123. } catch (error) {
  124. Log.error('重置设备配置失败:', error);
  125. return errData;
  126. }
  127. }
  128. async updateTabName(args) {
  129. try {
  130. const result = await updateTabName(args);
  131. if(result.data) return result.data
  132. return errData;
  133. } catch (error) {
  134. Log.error('重命名配置失败:', error);
  135. return errData;
  136. }
  137. }
  138. /**
  139. * 读取配置
  140. * @param {Object} args - 配置ID
  141. */
  142. async getSysConfig(args) {
  143. try {
  144. const result = await getSysConfig(args);
  145. if(result.data) return result.data
  146. return errData;
  147. } catch (error) {
  148. Log.error('重置设备配置失败:', error);
  149. return errData;
  150. }
  151. }
  152. /**
  153. * 保存配置
  154. * @param {Object} args - 配置ID
  155. */
  156. async updateSysConfigs(args) {
  157. try {
  158. const result = await updateSysConfigs(args);
  159. if(result.data) return result.data
  160. return errData;
  161. } catch (error) {
  162. Log.error('保存配置:', error);
  163. return errData;
  164. }
  165. }
  166. }
  167. SettingController.toString = () => '[class SettingController]';
  168. module.exports = SettingController;