app.html 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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: 'http://172.20.118.83:8051/demomenu'
  46. };
  47. function normalizeLink(to, location = history.location) {
  48. to = to || '';
  49. if (to && to[0] === '#') {
  50. to = location.pathname + location.search + to;
  51. } else if (to && to[0] === '?') {
  52. to = location.pathname + to;
  53. }
  54. const idx = to.indexOf('?');
  55. const idx2 = to.indexOf('#');
  56. let pathname = ~idx
  57. ? to.substring(0, idx)
  58. : ~idx2
  59. ? to.substring(0, idx2)
  60. : to;
  61. let search = ~idx ? to.substring(idx, ~idx2 ? idx2 : undefined) : '';
  62. let hash = ~idx2 ? to.substring(idx2) : location.hash;
  63. if (!pathname) {
  64. pathname = location.pathname;
  65. } else if (pathname[0] != '/' && !/^https?\:\/\//.test(pathname)) {
  66. let relativeBase = location.pathname;
  67. const paths = relativeBase.split('/');
  68. paths.pop();
  69. let m;
  70. while ((m = /^\.\.?\//.exec(pathname))) {
  71. if (m[0] === '../') {
  72. paths.pop();
  73. }
  74. pathname = pathname.substring(m[0].length);
  75. }
  76. pathname = paths.concat(pathname).join('/');
  77. }
  78. return pathname + search + hash;
  79. }
  80. function isCurrentUrl(to, ctx) {
  81. if (!to) {
  82. return false;
  83. }
  84. const pathname = history.location.pathname;
  85. const link = normalizeLink(to, {
  86. ...location,
  87. pathname,
  88. hash: ''
  89. });
  90. if (!~link.indexOf('http') && ~link.indexOf(':')) {
  91. let strict = ctx && ctx.strict;
  92. return match(link, {
  93. decode: decodeURIComponent,
  94. strict: typeof strict !== 'undefined' ? strict : true
  95. })(pathname);
  96. }
  97. return decodeURI(pathname) === link;
  98. }
  99. let languageInfo = getLanguageInfo();//获取语言包内容
  100. let amisInstance = amis.embed(
  101. '#root',
  102. app,
  103. {
  104. location: history.location,
  105. locale: languageInfo.lang
  106. },
  107. {
  108. replaceText: languageInfo.langReplaceText,
  109. langReplaceTextIgnoreKeys: languageInfo.langReplaceTextIgnoreKeys,
  110. // watchRouteChange: fn => {
  111. // return history.listen(fn);
  112. // },
  113. updateLocation: (location, replace) => {
  114. location = normalizeLink(location);
  115. if (location === 'goBack') {
  116. return history.goBack();
  117. } else if (
  118. (!/^https?\:\/\//.test(location) &&
  119. location ===
  120. history.location.pathname + history.location.search) ||
  121. location === history.location.href
  122. ) {
  123. // 目标地址和当前地址一样,不处理,免得重复刷新
  124. return;
  125. } else if (/^https?\:\/\//.test(location) || !history) {
  126. return (window.location.href = location);
  127. }
  128. history[replace ? 'replace' : 'push'](location);
  129. },
  130. jumpTo: (to, action) => {
  131. if (to === 'goBack') {
  132. return history.goBack();
  133. }
  134. to = normalizeLink(to);
  135. if (isCurrentUrl(to)) {
  136. return;
  137. }
  138. if (action && action.actionType === 'url') {
  139. action.blank === false
  140. ? (window.location.href = to)
  141. : window.open(to, '_blank');
  142. return;
  143. } else if (action && action.blank) {
  144. window.open(to, '_blank');
  145. return;
  146. }
  147. if (/^https?:\/\//.test(to)) {
  148. window.location.href = to;
  149. } else if (
  150. (!/^https?\:\/\//.test(to) &&
  151. to === history.pathname + history.location.search) ||
  152. to === history.location.href
  153. ) {
  154. // do nothing
  155. } else {
  156. history.push(to);
  157. }
  158. },
  159. isCurrentUrl: isCurrentUrl,
  160. theme: 'cxd'
  161. }
  162. );
  163. history.listen(state => {
  164. amisInstance.updateProps({
  165. location: state.location || state
  166. });
  167. });
  168. })();
  169. </script>
  170. </body>
  171. </html>