app.html 8.4 KB

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