app.html 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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. console.log('----------------'+url)
  124. var form = new FormData();
  125. form = JSON.stringify(params.data);
  126. var ContentType = 'application/x-www-form-urlencoded';
  127. // var ContentType = 'application/json';
  128. let header = {
  129. "Content-Type": ContentType,
  130. "Authorization":'Bearer ' + getToken(),
  131. }
  132. let isFormData = (typeof FormData !== 'undefined') && (params['data'] instanceof FormData);
  133. // if (isFormData) {
  134. // delete header['Content-Type'];
  135. // form = data;
  136. // }
  137. let headers = new Headers(header);
  138. return new Promise(function (resolve, reject) {
  139. fetch(url,{
  140. method: method,
  141. body: params.data,
  142. headers: headers
  143. }).then(function (response) {
  144. return response.json();
  145. }).then(function (res) {
  146. // if (isFormData) {
  147. // data['data'] = res.data;
  148. // }
  149. resolve({ "data": res });
  150. });
  151. });
  152. },
  153. updateLocation: (location, replace) => {
  154. location = normalizeLink(location);
  155. if (location === 'goBack') {
  156. return history.goBack();
  157. } else if (
  158. (!/^https?\:\/\//.test(location) &&
  159. location ===
  160. history.location.pathname + history.location.search) ||
  161. location === history.location.href
  162. ) {
  163. // 目标地址和当前地址一样,不处理,免得重复刷新
  164. return;
  165. } else if (/^https?\:\/\//.test(location) || !history) {
  166. return (window.location.href = location);
  167. }
  168. history[replace ? 'replace' : 'push'](location);
  169. },
  170. jumpTo: (to, action) => {
  171. if (to === 'goBack') {
  172. return history.goBack();
  173. }
  174. to = normalizeLink(to);
  175. if (isCurrentUrl(to)) {
  176. return;
  177. }
  178. if (action && action.actionType === 'url') {
  179. action.blank === false
  180. ? (window.location.href = to)
  181. : window.open(to, '_blank');
  182. return;
  183. } else if (action && action.blank) {
  184. window.open(to, '_blank');
  185. return;
  186. }
  187. if (/^https?:\/\//.test(to)) {
  188. window.location.href = to;
  189. } else if (
  190. (!/^https?\:\/\//.test(to) &&
  191. to === history.pathname + history.location.search) ||
  192. to === history.location.href
  193. ) {
  194. // do nothing
  195. } else {
  196. history.push(to);
  197. }
  198. },
  199. isCurrentUrl: isCurrentUrl,
  200. theme: 'cxd'
  201. }
  202. );
  203. history.listen(state => {
  204. amisInstance.updateProps({
  205. location: state.location || state
  206. });
  207. });
  208. })();
  209. // 获取登录的token-登录请求不需要登录token
  210. function getToken() {
  211. return localStorage.getItem("apiToken");
  212. }
  213. </script>
  214. </body>
  215. </html>