app.html 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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. var systemUri = getSystemIp();
  31. let amis = amisRequire('amis/embed');
  32. const match = amisRequire('path-to-regexp').match;
  33. // 如果想用 browserHistory 请切换下这处代码, 其他不用变
  34. // const history = History.createBrowserHistory();
  35. const history = History.createHashHistory();
  36. const header = getHeaderJson()
  37. const app = {
  38. type: 'app',
  39. brandName: 'ROMA',
  40. // logo: './public/static/images/logo.jpg',
  41. // footer: '<div class="p-2 text-center bg-light">底部区域</div>',
  42. // asideBefore: '<div class="p-2 text-center">菜单前面区域</div>',
  43. // asideAfter: '<div class="p-2 text-center">菜单后面区域</div>',
  44. // // api: '/pages/site.json'
  45. breadcrumb:false,
  46. header,
  47. api: {
  48. "url": '/page/menu'
  49. }
  50. };
  51. function normalizeLink(to, location = history.location) {
  52. to = to || '';
  53. if (to && to[0] === '#') {
  54. to = location.pathname + location.search + to;
  55. } else if (to && to[0] === '?') {
  56. to = location.pathname + to;
  57. }
  58. const idx = to.indexOf('?');
  59. const idx2 = to.indexOf('#');
  60. let pathname = ~idx
  61. ? to.substring(0, idx)
  62. : ~idx2
  63. ? to.substring(0, idx2)
  64. : to;
  65. let search = ~idx ? to.substring(idx, ~idx2 ? idx2 : undefined) : '';
  66. let hash = ~idx2 ? to.substring(idx2) : location.hash;
  67. if (!pathname) {
  68. pathname = location.pathname;
  69. } else if (pathname[0] != '/' && !/^https?\:\/\//.test(pathname)) {
  70. let relativeBase = location.pathname;
  71. const paths = relativeBase.split('/');
  72. paths.pop();
  73. let m;
  74. while ((m = /^\.\.?\//.exec(pathname))) {
  75. if (m[0] === '../') {
  76. paths.pop();
  77. }
  78. pathname = pathname.substring(m[0].length);
  79. }
  80. pathname = paths.concat(pathname).join('/');
  81. }
  82. return pathname + search + hash;
  83. }
  84. function isCurrentUrl(to, ctx) {
  85. if (!to) {
  86. return false;
  87. }
  88. const pathname = history.location.pathname;
  89. const link = normalizeLink(to, {
  90. ...location,
  91. pathname,
  92. hash: ''
  93. });
  94. if (!~link.indexOf('http') && ~link.indexOf(':')) {
  95. let strict = ctx && ctx.strict;
  96. return match(link, {
  97. decode: decodeURIComponent,
  98. strict: typeof strict !== 'undefined' ? strict : true
  99. })(pathname);
  100. }
  101. return decodeURI(pathname) === link;
  102. }
  103. let languageInfo = getLanguageInfo();//获取语言包内容
  104. let amisInstance = amis.embed(
  105. '#root',
  106. app,
  107. {
  108. location: history.location,
  109. locale: languageInfo.lang
  110. },
  111. {
  112. replaceText: languageInfo.langReplaceText,
  113. langReplaceTextIgnoreKeys: languageInfo.langReplaceTextIgnoreKeys,
  114. // watchRouteChange: fn => {
  115. // return history.listen(fn);
  116. // },
  117. fetcher: (params) => {
  118. var systemUri = getSystemIp();
  119. var method = params.method;
  120. var data = params.data;
  121. var body = params.body;
  122. var url = systemUri + params.url;
  123. var form = new FormData();
  124. form = JSON.stringify(params.data);
  125. var ContentType = 'application/x-www-form-urlencoded';
  126. // var ContentType = 'application/json';
  127. let header = {
  128. "Content-Type": ContentType,
  129. "Authorization":'Bearer ' + getToken(),
  130. }
  131. let isFormData = (typeof FormData !== 'undefined') && (params['data'] instanceof FormData);
  132. // if (isFormData) {
  133. // delete header['Content-Type'];
  134. // form = data;
  135. // }
  136. let headers = new Headers(header);
  137. return new Promise(function (resolve, reject) {
  138. fetch(url,{
  139. method: method,
  140. body: params.data,
  141. headers: headers
  142. }).then(function (response) {
  143. return response.json();
  144. }).then(function (res) {
  145. if(res.status == "50000") {
  146. localStorage.removeItem("apiToken");
  147. window.location.href="./login.html";
  148. }
  149. // if (isFormData) {
  150. // data['data'] = res.data;
  151. // }
  152. resolve({ "data": res });
  153. });
  154. });
  155. },
  156. updateLocation: (location, replace) => {
  157. location = normalizeLink(location);
  158. if (location === 'goBack') {
  159. return history.goBack();
  160. } else if (
  161. (!/^https?\:\/\//.test(location) &&
  162. location ===
  163. history.location.pathname + history.location.search) ||
  164. location === history.location.href
  165. ) {
  166. // 目标地址和当前地址一样,不处理,免得重复刷新
  167. return;
  168. } else if (/^https?\:\/\//.test(location) || !history) {
  169. return (window.location.href = location);
  170. }
  171. history[replace ? 'replace' : 'push'](location);
  172. },
  173. jumpTo: (to, action) => {
  174. if (to === 'goBack') {
  175. return history.goBack();
  176. }
  177. to = normalizeLink(to);
  178. if (isCurrentUrl(to)) {
  179. return;
  180. }
  181. if (action && action.actionType === 'url') {
  182. action.blank === false
  183. ? (window.location.href = to)
  184. : window.open(to, '_blank');
  185. return;
  186. } else if (action && action.blank) {
  187. window.open(to, '_blank');
  188. return;
  189. }
  190. if (/^https?:\/\//.test(to)) {
  191. window.location.href = to;
  192. } else if (
  193. (!/^https?\:\/\//.test(to) &&
  194. to === history.pathname + history.location.search) ||
  195. to === history.location.href
  196. ) {
  197. // do nothing
  198. } else {
  199. history.push(to);
  200. }
  201. },
  202. isCurrentUrl: isCurrentUrl,
  203. theme: 'cxd'
  204. }
  205. );
  206. history.listen(state => {
  207. amisInstance.updateProps({
  208. location: state.location || state
  209. });
  210. });
  211. })();
  212. // 获取登录的token-登录请求不需要登录token
  213. function getToken() {
  214. return localStorage.getItem("apiToken");
  215. }
  216. </script>
  217. </body>
  218. </html>