setting.js 4.7 KB

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