logswitch.js 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. function logswitchGenPage() {
  2. var page = '<div id="logswitch_page">\
  3. <div class="maintitle">\
  4. <div>硬件适配器日志记录管理</div>\
  5. <div class="page_description_text">本地临时打开硬件适配器日志记录,方便及时排查硬件问题。有改动更新需重启应用方能生效。\
  6. </div>\
  7. </div>\
  8. <div id="logswitchContent" class="hide" style="display: block;">\
  9. </div>\
  10. </div>';
  11. $("#rightpagearea").prepend(page);
  12. if (typeof logswitchRenderPage == "function") {
  13. beforeRenderPage("logswitch");
  14. logswitchRenderPage();
  15. afterRenderPage("logswitch");
  16. }
  17. }
  18. var logswitchController = (function() {
  19. var devSectionPlaceHolder = '<div id="log_switch_{{devName}}_section" class="wps_connect_way_title " style="margin-top: 40px; padding-top: 40px;">{{devSectionName}}</div>\
  20. <div id="log_switch_{{devName}}_section_description" class="three_way_instruction maintitle" style="padding-bottom: 0px !important;" >&nbsp;</div>\
  21. <div id="log_switch_{{devName}}_switch_div" class="clearboth" style="padding-top: 15px;">\
  22. <div class="control-label" style="margin-top:3px;">\
  23. <span>日志开关</span>\
  24. </div>\
  25. <div class="controls">\
  26. <div id="log_switch_{{devName}}_switch" onclick="SwitchEx(this, RVC.VendorLogSwitchController.LogSwitch)" class="switch_on"></div>\
  27. </div>\
  28. </div>\
  29. <div id="log_switch_{{devName}}_level" class="clearboth" style="padding-top: 15px;">\
  30. <div class="control-label" style="margin-top:3px;">\
  31. <span>日志等级</span>\
  32. </div>\
  33. <div class="controls">\
  34. <div id="log_switch_{{devName}}_log_level_select_all">\
  35. <div id="log_switch_{{devName}}_log_level_select" class="select_on_normal" value="0" onclick="SelectItem(this)"></div>\
  36. <div id="log_switch_{{devName}}_log_level_select_list" class="select_list hide" style="display: none;">\
  37. <div id="log_switch_{{devName}}_log_level_select_list_item_fatal" option="1" class="select_medium" onclick=\"RVC.VendorLogSwitchController.LogLevelChange(this, \'1\')\">Fatal</div>\
  38. <div id="log_switch_{{devName}}_log_level_select_list_item_error" option="2" class="select_medium" onclick=\"RVC.VendorLogSwitchController.LogLevelChange(this, \'2\')\">Error</div>\
  39. <div id="log_switch_{{devName}}_log_level_select_list_item_warn" option="3" class="select_medium" onclick=\"RVC.VendorLogSwitchController.LogLevelChange(this, \'3\')\">Warn</div>\
  40. <div id="log_switch_{{devName}}_log_level_select_list_item_info" option="4" class="select_medium" onclick=\"RVC.VendorLogSwitchController.LogLevelChange(this, \'4\')\">Info</div>\
  41. <div id="log_switch_{{devName}}_log_level_select_list_item_trace" option="5" class="select_medium" onclick=\"RVC.VendorLogSwitchController.LogLevelChange(this, \'5\')\">Trace</div>\
  42. </div>\
  43. </div>\
  44. </div>\
  45. </div>';
  46. var hardwares = [];
  47. function SwithDevAdapterLogRecord(adapterName, record_on, record_level, failCallback)
  48. {
  49. let req = new Request();
  50. req.configType = 7; //GlobalCache
  51. req.section = 'AdapterLogSwith';
  52. req.option = true; //Write
  53. req.key = adapterName;
  54. req.reserved1 = 0;
  55. req.reserved2 = 0;
  56. if(record_on) {
  57. req.reserved3 = '1,' + record_level;
  58. } else {
  59. req.reserved3 = '0,' + record_level;
  60. }
  61. req.reserved4 = '';
  62. RVC.DeviceControlEntityCtrl.ReadConfigValue(req, function(ret) {
  63. if (ret.errorCode === 0) {
  64. utilShowToast('设置成功!');
  65. } else {
  66. utilStartAlertDialog("设置失败! ErrorCode: " + ErrorCodeStringfy(ret.errorCode), function(){
  67. if(failCallback) {
  68. failCallback();
  69. }
  70. });
  71. }
  72. });
  73. }
  74. RVC.VendorLogSwitchController = RVC.ObjController.extend({
  75. LogLevelChange: function(widget, value) {
  76. var thatWidget = widget;
  77. var hardwareName = '';
  78. for(var i=0; i<hardwares.length; ++i) {
  79. if(-1 !== widget.id.indexOf(hardwares[i])) {
  80. hardwareName = hardwares[i];
  81. console.log(widget.id + " " + widget.className + ' ' + hardwareName);
  82. break;
  83. }
  84. }
  85. if(hardwareName === '') {
  86. return;
  87. }
  88. var switchon = true;
  89. var switch_id = 'log_switch_' + hardwareName + '_switch';
  90. var classlist = $('#' + switch_id).attr('class');
  91. if (classlist.indexOf('switch_on') < 0) {
  92. switchon = false;
  93. }
  94. var recordLevel = value;
  95. SwithDevAdapterLogRecord(hardwareName, switchon, recordLevel);
  96. },
  97. LogSwitch: function(widget) {
  98. var thatWidget = widget;
  99. var switchon = false;
  100. var hardwareName = '';
  101. for(var i=0; i<hardwares.length; ++i) {
  102. if(-1 !== widget.id.indexOf(hardwares[i])) {
  103. hardwareName = hardwares[i];
  104. console.log(widget.id + " " + widget.className + ' ' + hardwareName);
  105. break;
  106. }
  107. }
  108. if(hardwareName === '') {
  109. return;
  110. }
  111. var classlist = $(widget).attr('class');
  112. if (classlist.indexOf('switch_on') >= 0) {
  113. switchon = true;
  114. }
  115. var select_id = 'log_switch_' + hardwareName + '_log_level_select';
  116. setSelectWidgetEnableState(select_id, switchon);
  117. var recordLevel = $('#' + select_id).attr('value');
  118. SwithDevAdapterLogRecord(hardwareName, switchon, recordLevel, function() {
  119. setSelectWidgetEnableState(select_id, !switchon);
  120. Switch(thatWidget);
  121. });
  122. }
  123. });
  124. function initEachDevLogStatus(index) {
  125. if(index >= hardwares.length) {
  126. return;
  127. }
  128. const adapterName = hardwares[index];
  129. var switch_id = 'log_switch_' + adapterName + '_switch';
  130. var select_id = 'log_switch_' + adapterName + '_log_level_select';
  131. console.log('adapterName: ' + adapterName + ' ' + switch_id + ' ' + select_id);
  132. let req = new Request();
  133. req.configType = 7; //GlobalCache
  134. req.section = 'AdapterLogSwith';
  135. req.option = false;
  136. req.key = adapterName;
  137. req.reserved1 = 0;
  138. req.reserved2 = 0;
  139. req.reserved3 = '';
  140. req.reserved4 = '';
  141. RVC.DeviceControlEntityCtrl.ReadConfigValue(req, function(ret) {
  142. if (ret.errorCode === 0) {
  143. var recordOn = false;
  144. var recordLevel = '2';
  145. let result = JSON.parse(ret[RVC.EntityController.sigResponseUUID])
  146. console.log(adapterName + ': ' + result.value);
  147. if(result.value !== '') {
  148. var values = result.value.split(',');
  149. if(values.length >= 1 && parseInt(values[0]) > 0) {
  150. recordOn = true;
  151. }
  152. if(values.length >= 2) {
  153. recordLevel = (values[1]);
  154. }
  155. }
  156. setSwitchState(switch_id, recordOn);
  157. showSelectedValue(select_id, recordLevel);
  158. setSelectWidgetEnableState(select_id, recordOn);
  159. //setSwitchEnableState(switch_id, true);
  160. //setSelectWidgetEnableState(select_id, true);
  161. } else {
  162. setSwitchEnableState(switch_id, false);
  163. setSelectWidgetEnableState(select_id, false);
  164. }
  165. initEachDevLogStatus(index+1);
  166. });
  167. }
  168. function initPage() {
  169. for (var i = 0; i < gMenu.length; i++) {
  170. var menuitems = gMenu[i];
  171. var hash = menuitems.pagename;
  172. if(hash === 'hardwareconfig') {
  173. if (menuitems.submenus) {
  174. var subitems = menuitems.submenus;
  175. for(var j = 0; j < subitems.length; j++) {
  176. hash = subitems[j].pagename;
  177. if(hash === 'adapters') {
  178. if (typeof subitems[j].submenus !== 'undefined') {
  179. var thrditems = subitems[j].submenus;
  180. for(var k = 0; k <thrditems.length; ++k) {
  181. hash = subitems[j].submenus[k].pagename;
  182. hardwares.push(hash);
  183. }
  184. }
  185. }
  186. }
  187. }
  188. }
  189. }
  190. for(var i=0; i<hardwares.length; ++i) {
  191. console.log('hash1: ' + hardwares[i]);
  192. var templateData = {
  193. devName: hardwares[i],
  194. devSectionName: gMenuDisplayName[hardwares[i]]
  195. };
  196. $('#logswitchContent').secureAppend(devSectionPlaceHolder, templateData);
  197. }
  198. setTimeout(function () {
  199. // for(var i=0; i<hardwares.length; ++i) {
  200. // const adapterName = hardwares[i];
  201. // var switch_id = 'log_switch_' + adapterName + '_switch';
  202. // var select_id = 'log_switch_' + adapterName + '_log_level_select';
  203. // setSwitchEnableState(switch_id, false);
  204. // setSelectWidgetEnableState(select_id, false);
  205. // }
  206. initEachDevLogStatus(0);
  207. }, 500);
  208. }
  209. var fistTime = true;
  210. function init() {
  211. if (fistTime) {
  212. fistTime = false;
  213. }
  214. initPage();
  215. }
  216. return { init: init };
  217. }());
  218. window.logswitchRenderPage = function () {
  219. logswitchController.init();
  220. };