space.mobile.console.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. var spaceConsole = {};
  2. /**
  3. * 回收TOKEN
  4. * @param {Object} removeUrl url
  5. * @param {Object} param tokenList
  6. */
  7. spaceConsole.recycleToken = function (removeUrl, param) {
  8. $.ajax({
  9. type: "post",
  10. url: removeUrl,
  11. async: true,
  12. data: param
  13. });
  14. }
  15. /**
  16. * 业务程序组件
  17. */
  18. spaceConsole.appWindow = {
  19. // 显示
  20. show: function (setting) {
  21. if (!this.vaildation(setting)) {
  22. this.close();
  23. return;
  24. }
  25. this.hideBackBtn();
  26. this.winSetting = setting;
  27. space.plugin.loading.show();
  28. setting.position = space.utils.isNull(setting.position) ? "bottom" : setting.position;
  29. space.vue.$data.appWindow.position = setting.position;
  30. // 设置父窗口对象
  31. this.windowMap.set(space.vue.$data.appWindow.index, setting);
  32. // 解析 param
  33. if (setting.param) {
  34. var keys = Object.keys(setting.param);
  35. for (var i = 0; i < keys.length; i++) {
  36. setting.url += ("&" + keys[i] + "=" + setting.param[keys[i]]);
  37. }
  38. }
  39. space.vue.$data.appWindow.appWindowTitle = setting.title;
  40. space.vue.$data.appWindow.appWindowUrl = setting.url;
  41. space.vue.$data.appWindow.isShowAppWindow = true;
  42. },
  43. // 判断是否显示返回按钮
  44. autoControlBackBtn: function () {
  45. return false;
  46. // var appWin = this.getAppWindowObject();
  47. // if (!appWin) {
  48. // this.hideBackBtn();
  49. // return false;
  50. // }
  51. // try {
  52. // var laySize = appWin.space.plugin.layer.getLayCount();
  53. // if (laySize == 0) {
  54. // this.hideBackBtn();
  55. // }
  56. // else {
  57. // $("#appWindow-back").show();
  58. // }
  59. // } catch (error) {
  60. // this.hideBackBtn();
  61. // console.error(" autoControlBackBtn Error! " + error);
  62. // }
  63. },
  64. // 隐藏掉返回按钮
  65. hideBackBtn: function () {
  66. $("#appWindow-back").hide();
  67. },
  68. // 关闭 AppWindow 里面的弹出层
  69. closeAppWinLayer: function () {
  70. try {
  71. var appWin = this.getAppWindowObject();
  72. if (appWin) {
  73. appWin.space.plugin.layer.autoClose();
  74. }
  75. else {
  76. this.autoControlBackBtn();
  77. }
  78. } catch (error) {
  79. console.log(error);
  80. this.close({ type: 'cancel' });
  81. }
  82. },
  83. // 获取 APP Window Frame 对象
  84. getAppWindowObject: function () {
  85. var appWindowFrame = $("#appWindow-iframe");
  86. if (appWindowFrame.length == 0) {
  87. return undefined;
  88. }
  89. return $(appWindowFrame)[0].contentWindow;
  90. },
  91. // 获取父窗口对象
  92. getAppWinParentWin: function () {
  93. var winSetting = this.windowMap.get(space.vue.$data.appWindow.index);
  94. return winSetting == undefined ? undefined : winSetting.parentWin;
  95. },
  96. // 取消
  97. cancel: function () {
  98. try {
  99. var appWin = this.getAppWindowObject();
  100. if (!appWin) {
  101. return false;
  102. }
  103. // 逐一关闭 AppWin 的子页面,最后再关闭 AppWin 窗口
  104. var laySize = appWin.space.plugin.layer.getLayCount();
  105. if (laySize == 0) {
  106. this.close({ type: 'cancel' });
  107. } else {
  108. this.closeAppWinLayer();
  109. }
  110. } catch (error) {
  111. console.log(error);
  112. this.closeAppWinLayer();
  113. }
  114. },
  115. // 关闭,需清理掉 iframe 的 src
  116. close: function (params) {
  117. var contentWindow = $("#appWindow-iframe")[0].contentWindow;
  118. contentWindow.$("body").html("<div style='text-align: center;color: #999;margin-top: 49%'>加载中</div>");
  119. try {
  120. contentWindow.onunload(0);
  121. } catch (error) {
  122. console.error("contentWindow.onunload Error");
  123. }
  124. // 关闭回调,如果是右上角的关闭按钮则不进行回调
  125. var winSetting = this.windowMap.get(space.vue.$data.appWindow.index);
  126. if (!params || params.type != 'cancel') {
  127. if (winSetting && winSetting.close) {
  128. winSetting.close();
  129. }
  130. }
  131. // 关闭回调,百分百调用
  132. if (winSetting && winSetting.closeCallback) {
  133. winSetting.closeCallback();
  134. }
  135. // 删除父窗口对象
  136. this.windowMap.delete(space.vue.$data.appWindow.index);
  137. // 下标自增长
  138. space.vue.$data.appWindow.index++;
  139. space.vue.$data.appWindow.appWindowUrl = "javascript:false";
  140. space.vue.$nextTick(function () {
  141. space.vue.$data.appWindow.isShowAppWindow = false; // 关闭动画
  142. })
  143. this.autoControlBackBtn();
  144. },
  145. // 更新
  146. update: function (setting) {
  147. if (space.utils.isNull(setting)) {
  148. space.message.warning("AppWindow update setting is null");
  149. return false;
  150. }
  151. if (space.utils.isNull(setting.title)) {
  152. space.message.warning("AppWindow update setting.title is null");
  153. return false;
  154. }
  155. // 是弹出层调用,动画为:从右渐入
  156. var isLayerFlag = setting.target != undefined && setting.target == 'layer';
  157. if (isLayerFlag) {
  158. $("#appWinTitle").addClass("animate__animated animate__fadeIn");
  159. // $("#appWinTitle").addClass("animate__animated animate__fadeInRight");
  160. }
  161. else {
  162. $("#appWinTitle").addClass("animate__animated animate__fadeIn");
  163. }
  164. space.vue.$data.appWindow.appWindowTitle = setting.title;
  165. setTimeout(() => {
  166. $("#appWinTitle").removeAttr("class");
  167. }, 300);
  168. },
  169. // 窗口对象
  170. windowMap: new Map(),
  171. // 校验
  172. vaildation: function (setting) {
  173. if (space.utils.isNull(setting)) {
  174. space.message.warning("AppWindow setting is null");
  175. return false;
  176. }
  177. if (space.utils.isNull(setting.title)) {
  178. space.message.warning("AppWindow setting.title is null");
  179. return false;
  180. }
  181. if (space.utils.isNull(setting.url)) {
  182. space.message.warning("AppWindow setting.url is null");
  183. return false;
  184. }
  185. return true;
  186. }
  187. }
  188. spaceConsole.CMSSave = function (obj) {
  189. $.ajax({
  190. type: "post",
  191. url: cmsUrl,
  192. data: obj,
  193. async: true,
  194. cache: false
  195. });
  196. }