setting.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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. Log.error('获取设备配置详情失败:', error);
  74. return errData;
  75. }
  76. }
  77. /**
  78. * 删除设备配置
  79. * @param {Object} args - 配置ID
  80. */
  81. async removeDeviceConfig(args) {
  82. try {
  83. const result = await removeConfig(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. * 保存设备配置
  93. * @param {Object} args - 配置内容
  94. */
  95. async saveDeviceConfig(args) {
  96. try {
  97. const result = await saveDeviceConfig(args);
  98. if(result.data) return result.data
  99. return errData;
  100. } catch (error) {
  101. Log.error('保存设备配置失败:', error);
  102. return errData;
  103. }
  104. }
  105. async updateLeftRightConfig(args) {
  106. try {
  107. const result = await updateLeftRightConfig(args);
  108. if(result.data) return result.data
  109. return errData;
  110. } catch (error) {
  111. Log.error('更新左右脚失败:', error);
  112. return errData;
  113. }
  114. }
  115. /**
  116. * 重置设备配置
  117. * @param {Object} args - 配置ID
  118. */
  119. async resetDeviceConfig(args) {
  120. try {
  121. const result = await resetDeviceConfig(args);
  122. if(result.data) return result.data
  123. return errData;
  124. } catch (error) {
  125. Log.error('重置设备配置失败:', error);
  126. return errData;
  127. }
  128. }
  129. async updateTabName(args) {
  130. try {
  131. const result = await updateTabName(args);
  132. if(result.data) return result.data
  133. return errData;
  134. } catch (error) {
  135. Log.error('重命名配置失败:', error);
  136. return errData;
  137. }
  138. }
  139. /**
  140. * 读取配置
  141. * @param {Object} args - 配置ID
  142. */
  143. async getSysConfig(args) {
  144. try {
  145. const result = await getSysConfig(args);
  146. if(result.data) return result.data
  147. return errData;
  148. } catch (error) {
  149. Log.error('重置设备配置失败:', error);
  150. return errData;
  151. }
  152. }
  153. /**
  154. * 保存配置
  155. * @param {Object} args - 配置ID
  156. */
  157. async updateSysConfigs(args) {
  158. try {
  159. const result = await updateSysConfigs(args);
  160. if(result.data) return result.data
  161. return errData;
  162. } catch (error) {
  163. Log.error('保存配置:', error);
  164. return errData;
  165. }
  166. }
  167. }
  168. SettingController.toString = () => '[class SettingController]';
  169. module.exports = SettingController;