business.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  1. function businessGenPage() {
  2. var page = '<div id="business_page" style="display: block;">\
  3. <div class="maintitle">\
  4. <div>业务中台切换</div>\
  5. <div class="page_description_text">用于开发测试环境<strong>灵活</strong>切换业务中台链接。将替代集中配置中的业务链接,设置永久有效<br/>\
  6. 信息有变更时需重启Chromium实体或者重启应用方能生效。\
  7. </div>\
  8. </div>\
  9. <div id="businessContent">\
  10. <div class="clearboth" id="apn_list" style="padding-top:70px;">\
  11. <div class="table_top">\
  12. <div class="table_list_title">自定义业务链接\
  13. </div>\
  14. <div class="pull-right">\
  15. <div id="web_new" class="btn_new pull-left" >\
  16. &nbsp;\
  17. </div>\
  18. </div>\
  19. </div>\
  20. <div class="border_left border_right color_Darkgray" style="width:678px;padding-top:-1px;">\
  21. <div id="web_lists" class="clearboth" style="width:100%;overflow:hidden;">\
  22. </div>\
  23. </div>\
  24. <div class="table_bottom">\
  25. </div>\
  26. </div>\
  27. <div id="add_web_item_win" class="out_win_content submit_background hide">\
  28. <div class="table_top">\
  29. <div style="border-bottom: #E9E9E9 solid 1px;font-size: 16px;text-align:center;line-height: 65px;">\
  30. 业务链接设置</div>\
  31. </div>\
  32. <div class="border_left border_right margin_bottom_box2 color_background_white"\
  33. style="padding-top: 40px;">\
  34. <div id="add_web_item_win_scroll" style="max-height:300px;">\
  35. <div id="web_env_type_div" class="clearboth">\
  36. <div class="control-label-win"><span>环境</span></div>\
  37. <div class="controls-win">\
  38. <div id="web_env" class="select_on_normal"\
  39. onclick="SelectItem(this)"></div>\
  40. <div id="web_env_list" class="select_list hide"\
  41. style="display: none;">\
  42. <div id="web_env_list_item_dev" option="1"\
  43. class="select_medium"">DEV</div>\
  44. <div id="web_env_list_item_st" option="2"\
  45. class="select_medium">ST</div>\
  46. <div id="web_env_list_item_uat" option="3"\
  47. class="select_medium">UAT</div>\
  48. <div id="web_env_list_item_all" option="0"\
  49. class="select_medium">Unclassfied</div>\
  50. </div>\
  51. </div>\
  52. </div>\
  53. <input style="display:none;" id="web_url_profile_index" type="text">\
  54. <div id="web_main_url" class="clearboth" style="padding-top:29px;">\
  55. <div class="control-label-win"><span>业务URL(主屏)</span></div>\
  56. <div class="controls-win input_normal"><input id="web_main_url_text"\
  57. onfocus="showInputBorder(this)" onblur="hideInputBorder(this)"\
  58. type="text" maxlength="128"></div> \
  59. </div>\
  60. <div id="web_ad_url" class="clearboth" style="padding-top:29px;">\
  61. <div class="control-label-win"><span>广告URL(上屏)</span></div>\
  62. <div class="controls-win input_normal"><input id="web_ad_url_text" placeholder="(目前该值没应用,将使用默认的)"\
  63. onfocus="showInputBorder(this)" onblur="hideInputBorder(this)"\
  64. type="text" maxlength="128" disabled></div>\
  65. </div>\
  66. <div id="remark" class="clearboth" style="padding-top:29px;">\
  67. <div class="control-label-win"><span">备注</span></div>\
  68. <div class="controls-win input_normal"><input id="input_remark" placeholder="(可不填)"\
  69. onfocus="showInputBorder(this)" onblur="hideInputBorder(this)"\
  70. type="text" maxlength="63"></div>\
  71. </div>\
  72. <div id="web_list_input_set_default_div" class="clearboth" style="padding-top: 27px;">\
  73. <div class="control-label-win pull-left">\
  74. <span>设置为当前使用链接</span>\
  75. </div>\
  76. <div id="web_list_input_set_default" class="check_off controls-win pull-right" style="margin-top:8px;">\
  77. </div>\
  78. </div>\
  79. <div id="web_select_blank" style="height: 145px; display: none;" class="hide"></div>\
  80. <div class="clearboth"></div>\
  81. </div>\
  82. <div style="padding-top:50px;padding-bottom:8px;" align="center">\
  83. <button id="web_item_cancel" class="btn_normal_short" >取消</button>\
  84. <button id="web_item_save" class="btn_normal_short btn_disabled margin-left-20">保存</button>\
  85. </div>\
  86. </div>\
  87. <div class="table_bottom"></div>\
  88. </div>\
  89. </div>\
  90. </div>';
  91. $("#rightpagearea").prepend(page);
  92. if (typeof businessRenderPage == "function") {
  93. beforeRenderPage("business");
  94. businessRenderPage();
  95. afterRenderPage("business");
  96. }
  97. }
  98. var businessController = (function() {
  99. var CONST = {
  100. SWITCH_ON: '1',
  101. PROFILE_MAX_NUM: 100
  102. };
  103. var weblistCount = 0;
  104. var isNewWebConfig = true;
  105. var modifyIndex = -1;
  106. var profilesArray = [];
  107. var modifyProfile = {};
  108. function loadData(flag) {
  109. let req = new Request();
  110. req.filter1 = 0;
  111. req.filter2 = 0;
  112. req.filter3 = 0;
  113. req.filter4 = '';
  114. profilesArray = [];
  115. weblistCount = 0;
  116. if(typeof flag === 'undefined') {
  117. utilStartSubmitDialog();
  118. }
  119. RVC.CenterSettingEntity.GetWebUrlList(req, function(ret) {
  120. if(typeof flag === 'undefined'){
  121. utilStopSubmitDialog();
  122. }
  123. console.log('result: ' + ret.errorCode);
  124. if (ret.errorCode === 0) {
  125. let result = JSON.parse(ret[RVC.CenterSettingEntity.sigResponseUUID])
  126. console.log('count: ' + result.index.length + ' ' + result);
  127. if (result.index.length === 0) {
  128. $('#web_lists').css('height', 0);
  129. $('#web_lists').hide();
  130. return;
  131. } else if (result.index.length <= 8) {
  132. $('#web_lists').css('height', (result.index.length * 70 - 12) + result.index.length + 'px');
  133. } else {
  134. $('#web_lists').css('height', '561px');
  135. }
  136. $('#web_lists').show();
  137. $('#web_lists').empty();
  138. RVC.Scroll.initScroll('#web_lists');
  139. for (var n = 0; n < result.index.length; n++)
  140. {
  141. var templateData = {
  142. profileItemIndex: result.index[n],
  143. profileItemName: result.remark[n],
  144. profileItemMainUrl: result.futureUrl[n],
  145. profileItemAdUrl: result.adUrl[n],
  146. profileItemEnvType: result.env[n],
  147. profileItemFromType: result.type[n],
  148. profileItemStatus: result.status[n]
  149. };
  150. profilesArray.push(templateData);
  151. var profileHtml;
  152. if (n === result.index.length - 1) {
  153. profileHtml = '<div id="web_list_{{profileItemIndex}}" style="height:59px;cursor:pointer;" class="list_item_hover">';
  154. profileHtml += '<div id="web_list_name_{{profileItemIndex}}" class="pull-left padding-left-20" style="height:45px;padding-top:14px;width:600px;" onclick="RVC.WebUrlController.ShowWebUrlInfo({{profileItemIndex}})">';
  155. } else {
  156. profileHtml = '<div id="web_list_{{profileItemIndex}}" class="border_bottom list_item_hover" style="height:70px;cursor:pointer;">';
  157. profileHtml += '<div id="web_list_name_{{profileItemIndex}}" class="pull-left padding-left-20" style="height:56px;padding-top:14px;width:600px;" onclick="RVC.WebUrlController.ShowWebUrlInfo({{profileItemIndex}})">';
  158. }
  159. if (templateData.profileItemStatus === 1) {
  160. profileHtml += '<pre class="web_profile_name_{{profileItemIndex}}" style="font-size:16px;margin-top:0px;"><span class="web_profile_itemname pull-left" style="line-height:21px;" title="{{profileItemName}}">{{profileItemName}}</span><span class="pull-left" style="line-height:21px;">(当前采用)</span><div class="clearboth"></div></pre>';
  161. } else {
  162. profileHtml += '<pre class="web_profile_name_{{profileItemIndex}}" style="font-size:16px;margin-top:0px;"><span class="web_profile_itemname" title="{{profileItemName}}">{{profileItemName}}</span></pre>';
  163. }
  164. profileHtml += '<div class="web_web_name_{{profileItemIndex}} color_descroption_gray web_profile_itemapnname" style="margin-top:-10px;font-size:14px;" title="{{profileItemMainUrl}}">{{profileItemMainUrl}}</div></div>';
  165. if (templateData.profileItemFromType === 0 || templateData.profileItemStatus === 1 || templateData.profileItemStatus === 2) {
  166. profileHtml += '<div class="pull-right"></div></div>';
  167. } else {
  168. if (n === 0) {
  169. profileHtml += '<div class="pull-right"><div class="btn_delete mobileconnet_btn_delete" onclick="RVC.WebUrlController.RemoveWebUrlProfile({{profileItemIndex}})" >&nbsp;</div></div></div>';
  170. } else {
  171. profileHtml += '<div class="pull-right"><div class="btn_delete mobileconnet_btn_delete" onclick="RVC.WebUrlController.RemoveWebUrlProfile({{profileItemIndex}})" >&nbsp;</div></div></div>';
  172. }
  173. }
  174. $('#web_lists .scroll_text').secureAppend(profileHtml, templateData);
  175. }
  176. weblistCount = result.index.length;
  177. } else if(typeof flag === 'undefined') {
  178. RVC.CenterSettingEntity.commErrorCallback(ret);
  179. }
  180. });
  181. }
  182. function preShowWebList()
  183. {
  184. $('#web_lists').show();
  185. $('#web_lists').empty();
  186. RVC.Scroll.initScroll('#web_lists');
  187. }
  188. function webProfileCancel() {
  189. $('#add_web_item_win').hide();
  190. $('#submit_fade').hide();
  191. }
  192. function saveProfileData(newConfig)
  193. {
  194. if (!isButtonEnable('web_item_save')) {
  195. return;
  196. }
  197. var mainUrl = $('#web_main_url_text').val();
  198. var adUrl = $('#web_ad_url_text').val();
  199. var remark = $('#input_remark').val();
  200. var isSetDefault = $('#web_list_input_set_default').hasClass('check_on') ? true : false;
  201. var envType = parseInt($('#web_env').val());
  202. var index = parseInt($('#web_url_profile_index').val());
  203. if(mainUrl === '') {
  204. utilStartAlertDialog('请输入业务链接地址!');
  205. return;
  206. }
  207. let req = new Request();
  208. if(newConfig) {
  209. req.operation = 1;
  210. req.index = 0;
  211. } else {
  212. req.operation = 3;
  213. req.index = index;
  214. }
  215. req.futureUrl = mainUrl;
  216. req.adUrl = adUrl;
  217. req.remark = remark;
  218. req.env = envType;
  219. req.setDefault = isSetDefault;
  220. utilStartSubmitDialog();
  221. RVC.CenterSettingEntity.EditWebUrl(req, function(ret) {
  222. utilStopSubmitDialog();
  223. if (ret.errorCode === 0) {
  224. let result = JSON.parse(ret[RVC.CenterSettingEntity.sigResponseUUID])
  225. webProfileCancel();
  226. utilStartAlertDialog('操作成功!点击确认将重启Chromium实体以让设置生效(该页面由Chromium实体控制,如果出现突然消失属正常现象)', function(){
  227. RVC.HealthmanagerEntityCtrl.StartEntity('Chromium', function() {
  228. utilShowToast('Chromium实体重启时会断开与此页面的通讯连接,如果长时间此提示或当前页面未消失,请转到后台管理窗口查看告警或自行重启!', 30000);
  229. });
  230. });
  231. } else {
  232. RVC.CenterSettingEntity.commErrorCallback(ret);
  233. }
  234. });
  235. }
  236. function checkboxDisabled(id) {
  237. var checkElement = $('#' + id);
  238. if (checkElement.hasClass('check_on') && checkElement.hasClass('disabled')) {
  239. checkElement.removeClass('check_on').addClass('check_on_disable').addClass('check_on');
  240. } else {
  241. checkElement.removeClass('check_on_disable');
  242. }
  243. if (checkElement.hasClass('check_off') && checkElement.hasClass('disabled')) {
  244. checkElement.removeClass('check_off').addClass('check_off_disable').addClass('check_off');
  245. } else {
  246. checkElement.removeClass('check_off_disable');
  247. }
  248. }
  249. function showWebBox() {
  250. clearAllErrorMsg();
  251. $('#web_item_save').addClass('btn_disabled');
  252. var outwin = $('#add_web_item_win');
  253. checkboxDisabled('web_list_input_set_default');
  254. var heightest = $(document).height();
  255. $('#submit_fade').css('height', heightest + 'px');
  256. $('#submit_fade').show();
  257. outwin.show();
  258. }
  259. function setDefaultWebUrlSwitch() {
  260. if ($('#web_list_input_set_default').hasClass('disabled')) {
  261. return;
  262. }
  263. $('#web_item_save').removeClass('btn_disabled');
  264. if ($('#web_list_input_set_default').hasClass('check_on')) {
  265. $('#web_list_input_set_default').removeClass('check_on').addClass('check_off');
  266. } else {
  267. $('#web_list_input_set_default').removeClass('check_off').addClass('check_on');
  268. }
  269. if ($('#web_list_input_set_default').hasClass('check_off')) {
  270. $('#web_item_save').addClass('btn_disabled');
  271. }
  272. }
  273. function ResetWebUrlInfoShowDialog()
  274. {
  275. $('#web_url_profile_index').val('');
  276. $('#add_web_item_win input').val('');
  277. $('#add_web_item_win input').removeAttr('disabled');
  278. $('#add_web_item_win .select_on_normal').removeClass('disabled');
  279. }
  280. RVC.WebUrlController = RVC.ObjController.extend({
  281. ShowWebUrlInfo: function(index) {
  282. modifyIndex = index;
  283. var webUrlShowItem = {};
  284. for (var i = 0; i < profilesArray.length; i++) {
  285. if (profilesArray[i].profileItemIndex === index) {
  286. webUrlShowItem = profilesArray[i];
  287. break;
  288. }
  289. }
  290. /**
  291. * profileItemIndex: result.index[n],
  292. profileItemName: result.remark[n],
  293. profileItemMainUrl: result.futureUrl[n],
  294. profileItemAdUrl: result.adUrl[n],
  295. profileItemEnvType: result.env[n],
  296. profileItemFromType: result.type[n],
  297. profileItemStatus: result.status[n]
  298. */
  299. ResetWebUrlInfoShowDialog();
  300. modifyProfile = webUrlShowItem;
  301. $('#web_url_profile_index').val(webUrlShowItem.profileItemIndex.toString());
  302. $('#web_main_url_text').val(webUrlShowItem.profileItemMainUrl);
  303. $('#web_ad_url_text').val(webUrlShowItem.profileItemAdUrl);
  304. $('#input_remark').val(webUrlShowItem.profileItemName);
  305. if (webUrlShowItem.profileItemStatus === 1) { //默认配置
  306. $('#web_list_input_set_default').removeClass('check_off').addClass('check_on');
  307. $('#web_list_input_set_default').addClass('disabled');
  308. } else {
  309. $('#web_list_input_set_default').removeClass('check_on').addClass('check_off');
  310. $('#web_list_input_set_default').removeClass('disabled');
  311. }
  312. showSelectedValue('web_env', webUrlShowItem.profileItemEnvType.toString());
  313. $(document).off('click', '#web_item_save');
  314. $(document).on('click', '#web_item_save', function () {
  315. saveProfileData(false);
  316. });
  317. if(webUrlShowItem.profileItemFromType === 0) { //集中配置文件不让修改
  318. $('#add_web_item_win input').attr('disabled', true);
  319. $('#add_web_item_win .select_on_normal').addClass('disabled');
  320. console.log(webUrlShowItem.profileItemName);
  321. }
  322. showWebBox();
  323. },
  324. RemoveWebUrlProfile: function(index)
  325. {
  326. utilStartConfirmDialog("确定要移除该配置吗?", function() {
  327. let req = new Request();
  328. req.operation = 2; //删除
  329. req.index = parseInt(index);
  330. req.futureUrl = '';
  331. req.adUrl = '';
  332. req.remark = '';
  333. req.env = 0;
  334. req.setDefault = false;
  335. utilStartSubmitDialog();
  336. RVC.CenterSettingEntity.EditWebUrl(req, function(ret) {
  337. utilStopSubmitDialog();
  338. if (ret.errorCode === 0) {
  339. let result = JSON.parse(ret[RVC.CenterSettingEntity.sigResponseUUID])
  340. preShowWebList();
  341. loadData();
  342. } else {
  343. RVC.CenterSettingEntity.commErrorCallback(ret);
  344. }
  345. });
  346. });
  347. }
  348. });
  349. function bindEvents() {
  350. $('#web_new').click(function () {
  351. $('#web_select_blank').hide();
  352. if (weblistCount === CONST.PROFILE_MAX_NUM) {
  353. utilStartCommonDialog('配置数量超过上限(' + CONST.PROFILE_MAX_NUM + '),请删除再新建!');
  354. setTimeout(function () {
  355. utilStopCommonDialog();
  356. }, 3000);
  357. return;
  358. }
  359. modifyIndex = -1;
  360. ResetWebUrlInfoShowDialog();
  361. $('#web_list_input_set_default').removeClass('check_off').addClass('check_on');
  362. $('#web_list_input_set_default').addClass('disabled');
  363. showSelectedValue('web_env', '1');
  364. isNewWebConfig = true;
  365. showWebBox();
  366. $(document).off('click', '#web_item_save');
  367. $(document).on('click', '#web_item_save', function () {
  368. saveProfileData(true);
  369. });
  370. $('#web_main_url_text').focus();
  371. });
  372. $('#web_item_cancel').click(webProfileCancel);
  373. $(document).on('click keyup change', '#add_web_item_win input', function () {
  374. $('#web_item_save').removeClass('btn_disabled');
  375. });
  376. $(document).on('change click', '#add_web_item_win .select_on_normal', function () {
  377. $('#web_item_save').removeClass('btn_disabled');
  378. });
  379. $('#web_list_input_set_default').click(setDefaultWebUrlSwitch);
  380. $('#web_env').click(function () {
  381. //RVC.Scroll.setTop('#add_web_item_win_scroll', 200);
  382. });
  383. }
  384. function initPage()
  385. {
  386. preShowWebList();
  387. loadData(true);
  388. }
  389. var fistTime = true;
  390. function init() {
  391. initPage();
  392. if (fistTime) {
  393. fistTime = false;
  394. bindEvents();
  395. RVC.Scroll.initScroll('#add_web_item_win_scroll');
  396. }
  397. }
  398. function destory() {
  399. clearAllErrorMsg();
  400. }
  401. return { init: init, destory: destory };
  402. }());
  403. window.businessRenderPage = function () {
  404. businessController.init();
  405. };