app.html 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. <!DOCTYPE html>
  2. <html lang="zh">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <title>ROMA</title>
  6. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  7. <link rel="icon" type="image/x-ico" href=""/>
  8. <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
  9. <meta http-equiv="X-UA-Compatible" content="IE=Edge" />
  10. <link rel="stylesheet" href="./public/static/amis-sdk/helper.css">
  11. <link rel="stylesheet" href="./public/static/amis-sdk/sdk.css">
  12. <link rel="stylesheet" href="./public/static/amis-sdk/iconfont.css">
  13. <link rel="stylesheet" href="./public/static/fonts/remixicon.css">
  14. <!-- 引入自定义样式 -->
  15. <link rel="stylesheet" href="./public/static/css/app.css">
  16. </head>
  17. <body>
  18. <div id="root" class="app-wrapper"></div>
  19. <script type='text/javascript' src='./public/static/amis-sdk/sdk.js'></script>
  20. <script type='text/javascript' src='./public/static/amis-static/history.js'></script>
  21. <!-- 引入语言包 -->
  22. <script src="./lang/en-US.js"></script>
  23. <script src="./lang/zh-CN.js"></script>
  24. <!-- 引入多语言js处理文件,必须先引入语言包 -->
  25. <script src="./public/static/tools/common.js"></script>
  26. <!-- 引入header的JSON -->
  27. <script src="./pages/app/header-json.js"></script>
  28. <script>
  29. (function () {
  30. let amis = amisRequire('amis/embed');
  31. const match = amisRequire('path-to-regexp').match;
  32. // 如果想用 browserHistory 请切换下这处代码, 其他不用变
  33. // const history = History.createBrowserHistory();
  34. const history = History.createHashHistory();
  35. const header = getHeaderJson()
  36. const app = {
  37. type: 'app',
  38. brandName: 'ROMA',
  39. // logo: './public/static/images/logo.jpg',
  40. // footer: '<div class="p-2 text-center bg-light">底部区域</div>',
  41. // asideBefore: '<div class="p-2 text-center">菜单前面区域</div>',
  42. // asideAfter: '<div class="p-2 text-center">菜单后面区域</div>',
  43. // // api: '/pages/site.json'
  44. header,
  45. api: {
  46. "url": 'http://localhost:8081/page/menu',
  47. "dataType":"form",
  48. "method":"post",
  49. "headers": {
  50. "Authorization": 'Bearer ' + getToken()
  51. },
  52. }
  53. };
  54. function normalizeLink(to, location = history.location) {
  55. to = to || '';
  56. if (to && to[0] === '#') {
  57. to = location.pathname + location.search + to;
  58. } else if (to && to[0] === '?') {
  59. to = location.pathname + to;
  60. }
  61. const idx = to.indexOf('?');
  62. const idx2 = to.indexOf('#');
  63. let pathname = ~idx
  64. ? to.substring(0, idx)
  65. : ~idx2
  66. ? to.substring(0, idx2)
  67. : to;
  68. let search = ~idx ? to.substring(idx, ~idx2 ? idx2 : undefined) : '';
  69. let hash = ~idx2 ? to.substring(idx2) : location.hash;
  70. if (!pathname) {
  71. pathname = location.pathname;
  72. } else if (pathname[0] != '/' && !/^https?\:\/\//.test(pathname)) {
  73. let relativeBase = location.pathname;
  74. const paths = relativeBase.split('/');
  75. paths.pop();
  76. let m;
  77. while ((m = /^\.\.?\//.exec(pathname))) {
  78. if (m[0] === '../') {
  79. paths.pop();
  80. }
  81. pathname = pathname.substring(m[0].length);
  82. }
  83. pathname = paths.concat(pathname).join('/');
  84. }
  85. return pathname + search + hash;
  86. }
  87. function isCurrentUrl(to, ctx) {
  88. if (!to) {
  89. return false;
  90. }
  91. const pathname = history.location.pathname;
  92. const link = normalizeLink(to, {
  93. ...location,
  94. pathname,
  95. hash: ''
  96. });
  97. if (!~link.indexOf('http') && ~link.indexOf(':')) {
  98. let strict = ctx && ctx.strict;
  99. return match(link, {
  100. decode: decodeURIComponent,
  101. strict: typeof strict !== 'undefined' ? strict : true
  102. })(pathname);
  103. }
  104. return decodeURI(pathname) === link;
  105. }
  106. let languageInfo = getLanguageInfo();//获取语言包内容
  107. let amisInstance = amis.embed(
  108. '#root',
  109. app,
  110. {
  111. location: history.location,
  112. locale: languageInfo.lang
  113. },
  114. {
  115. replaceText: languageInfo.langReplaceText,
  116. langReplaceTextIgnoreKeys: languageInfo.langReplaceTextIgnoreKeys,
  117. // watchRouteChange: fn => {
  118. // return history.listen(fn);
  119. // },
  120. updateLocation: (location, replace) => {
  121. location = normalizeLink(location);
  122. if (location === 'goBack') {
  123. return history.goBack();
  124. } else if (
  125. (!/^https?\:\/\//.test(location) &&
  126. location ===
  127. history.location.pathname + history.location.search) ||
  128. location === history.location.href
  129. ) {
  130. // 目标地址和当前地址一样,不处理,免得重复刷新
  131. return;
  132. } else if (/^https?\:\/\//.test(location) || !history) {
  133. return (window.location.href = location);
  134. }
  135. history[replace ? 'replace' : 'push'](location);
  136. },
  137. jumpTo: (to, action) => {
  138. if (to === 'goBack') {
  139. return history.goBack();
  140. }
  141. to = normalizeLink(to);
  142. if (isCurrentUrl(to)) {
  143. return;
  144. }
  145. if (action && action.actionType === 'url') {
  146. action.blank === false
  147. ? (window.location.href = to)
  148. : window.open(to, '_blank');
  149. return;
  150. } else if (action && action.blank) {
  151. window.open(to, '_blank');
  152. return;
  153. }
  154. if (/^https?:\/\//.test(to)) {
  155. window.location.href = to;
  156. } else if (
  157. (!/^https?\:\/\//.test(to) &&
  158. to === history.pathname + history.location.search) ||
  159. to === history.location.href
  160. ) {
  161. // do nothing
  162. } else {
  163. history.push(to);
  164. }
  165. },
  166. isCurrentUrl: isCurrentUrl,
  167. theme: 'cxd'
  168. }
  169. );
  170. history.listen(state => {
  171. amisInstance.updateProps({
  172. location: state.location || state
  173. });
  174. });
  175. })();
  176. // 获取登录的token-登录请求不需要登录token
  177. function getToken() {
  178. return localStorage.getItem("apiToken");
  179. }
  180. </script>
  181. </body>
  182. </html>