app.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  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. <style>
  15. html,
  16. body,
  17. .app-wrapper {
  18. position: relative;
  19. width: 100%;
  20. height: 100%;
  21. margin: 0;
  22. padding: 0;
  23. touch-action: pan-y;
  24. }
  25. :root {
  26. --Form-item-gap: 1.3rem;
  27. --InputGroup-height: 2.5rem;
  28. --Button-height: 2.5rem;
  29. --InputGroup-paddingX: .6rem;
  30. --InputGroup-addOn-bg: var(--Form-input-bg);
  31. /* --fontSizeBase: .9rem; */
  32. }
  33. .app-wrapper {
  34. position: relative;
  35. width: 100%;
  36. height: 100%;
  37. margin: 0;
  38. padding: 0;
  39. }
  40. .amis-scope .cxd-Layout--headerFixed .cxd-Layout-header .cxd-Page {
  41. background: none;
  42. }
  43. .amis-scope .cxd-Page-body .cxd-DropDown--alignRight .cxd-DropDown-menu {
  44. text-align: center;
  45. }
  46. /* .amis-scope .cxd-DropDown button .m-r-xs {
  47. width: 100%;
  48. height: 100%;
  49. } */
  50. .amis-scope .cxd-Button--default {
  51. border: none;
  52. outline: none;
  53. }
  54. .amis-scope .cxd-Button--default:not(:disabled):not(.is-disabled):hover {
  55. color: none;
  56. background: none;
  57. border-color: none;
  58. border-width: none;
  59. border-style: none;
  60. box-shadow: none;
  61. border: none;
  62. outline: none;
  63. }
  64. .amis-scope .m-r-xs {
  65. margin-top:-5px;
  66. width: 30px;
  67. height: 30px;
  68. }
  69. @media (min-width: 768px) {
  70. .amis-scope .cxd-Layout--asideFixed.cxd-Layout--folded .cxd-Layout-aside {
  71. z-index: 2000;
  72. }
  73. }
  74. </style>
  75. </head>
  76. <body>
  77. <div id="root" class="app-wrapper"></div>
  78. <script type='text/javascript' src='./public/static/amis-sdk/sdk.js'></script>
  79. <script type='text/javascript' src='./public/static/amis-static/history.js'></script>
  80. <!-- 引入语言包 -->
  81. <script src="./lang/en-US.js"></script>
  82. <script src="./lang/zh-CN.js"></script>
  83. <!-- 引入多语言js处理文件,必须先引入语言包 -->
  84. <script src="./public/static/tools/common.js"></script>
  85. <script>
  86. (function () {
  87. let amis = amisRequire('amis/embed');
  88. const match = amisRequire('path-to-regexp').match;
  89. // 如果想用 browserHistory 请切换下这处代码, 其他不用变
  90. // const history = History.createBrowserHistory();
  91. const history = History.createHashHistory();
  92. const header = {
  93. "type": "page",
  94. "initApi": "/api/sys_user_info",
  95. "body": [
  96. {
  97. "type": "flex",
  98. "justify": "flex-end",
  99. "items": [
  100. {
  101. "type": "dropdown-button",
  102. "label": "",
  103. "className": "header-menu",
  104. "buttons": [
  105. {
  106. "type": "button",
  107. "label": "中文",
  108. "id": "u:6911502c8fcc",
  109. "onEvent": {
  110. "click": {
  111. "actions": [
  112. {
  113. "script": "localStorage.setItem('language', 'zh-CN')\nlocation.reload()",
  114. "actionType": "custom",
  115. "args": {
  116. }
  117. }
  118. ],
  119. "weight": 0
  120. }
  121. }
  122. },
  123. {
  124. "type": "button",
  125. "label": "English",
  126. "id": "u:e702685a7a45",
  127. "onEvent": {
  128. "click": {
  129. "actions": [
  130. {
  131. "script": "localStorage.setItem('language', 'en-US')\r\nlocation.reload()",
  132. "actionType": "custom"
  133. }
  134. ],
  135. "weight": 0
  136. }
  137. },
  138. "actionType": "",
  139. "link": "/view/user_info"
  140. }
  141. ],
  142. "id": "u:4fedf7a987bf",
  143. "size": "md",
  144. "level": "default",
  145. "align": "right",
  146. "block": false,
  147. "hideCaret": true,
  148. "trigger": "hover",
  149. "icon": "./public/static/icon/language-change.png",
  150. "btnClassName": "no-border"
  151. },
  152. {
  153. "type": "dropdown-button",
  154. "label": "名字e",
  155. "className": "header-menu",
  156. "buttons": [
  157. {
  158. "type": "button",
  159. "label": "个人信息",
  160. "actionType": "link",
  161. "link": "/view/user_info",
  162. "id": "u:57cf3ed9c568"
  163. },
  164. {
  165. "type": "button",
  166. "actionType": "url",
  167. "url": "/login/out",
  168. "blank": false,
  169. "confirmText": "确定要退出吗",
  170. "label": "退出登录",
  171. "id": "u:88d8afc464b5"
  172. }
  173. ],
  174. "id": "u:d324269526b9",
  175. "size": "md",
  176. "level": "default",
  177. "align": "right",
  178. "block": true,
  179. "trigger": "hover"
  180. }
  181. ],
  182. "id": "u:e7752d0c1dbe"
  183. }
  184. ],
  185. "id": "u:d16525b6aae6"
  186. }
  187. const app = {
  188. type: 'app',
  189. brandName: 'ROMA',
  190. // logo: './public/static/images/logo.jpg',
  191. // footer: '<div class="p-2 text-center bg-light">底部区域</div>',
  192. // asideBefore: '<div class="p-2 text-center">菜单前面区域</div>',
  193. // asideAfter: '<div class="p-2 text-center">菜单后面区域</div>',
  194. // // api: '/pages/site.json'
  195. header,
  196. api: 'http://172.20.118.83:8051/demomenu'
  197. };
  198. function normalizeLink(to, location = history.location) {
  199. to = to || '';
  200. if (to && to[0] === '#') {
  201. to = location.pathname + location.search + to;
  202. } else if (to && to[0] === '?') {
  203. to = location.pathname + to;
  204. }
  205. const idx = to.indexOf('?');
  206. const idx2 = to.indexOf('#');
  207. let pathname = ~idx
  208. ? to.substring(0, idx)
  209. : ~idx2
  210. ? to.substring(0, idx2)
  211. : to;
  212. let search = ~idx ? to.substring(idx, ~idx2 ? idx2 : undefined) : '';
  213. let hash = ~idx2 ? to.substring(idx2) : location.hash;
  214. if (!pathname) {
  215. pathname = location.pathname;
  216. } else if (pathname[0] != '/' && !/^https?\:\/\//.test(pathname)) {
  217. let relativeBase = location.pathname;
  218. const paths = relativeBase.split('/');
  219. paths.pop();
  220. let m;
  221. while ((m = /^\.\.?\//.exec(pathname))) {
  222. if (m[0] === '../') {
  223. paths.pop();
  224. }
  225. pathname = pathname.substring(m[0].length);
  226. }
  227. pathname = paths.concat(pathname).join('/');
  228. }
  229. return pathname + search + hash;
  230. }
  231. function isCurrentUrl(to, ctx) {
  232. if (!to) {
  233. return false;
  234. }
  235. const pathname = history.location.pathname;
  236. const link = normalizeLink(to, {
  237. ...location,
  238. pathname,
  239. hash: ''
  240. });
  241. if (!~link.indexOf('http') && ~link.indexOf(':')) {
  242. let strict = ctx && ctx.strict;
  243. return match(link, {
  244. decode: decodeURIComponent,
  245. strict: typeof strict !== 'undefined' ? strict : true
  246. })(pathname);
  247. }
  248. return decodeURI(pathname) === link;
  249. }
  250. let languageInfo = getLanguageInfo();
  251. let amisInstance = amis.embed(
  252. '#root',
  253. app,
  254. {
  255. location: history.location,
  256. locale: languageInfo.lang
  257. },
  258. {
  259. replaceText: languageInfo.langReplaceText,
  260. langReplaceTextIgnoreKeys: languageInfo.langReplaceTextIgnoreKeys,
  261. // watchRouteChange: fn => {
  262. // return history.listen(fn);
  263. // },
  264. updateLocation: (location, replace) => {
  265. location = normalizeLink(location);
  266. if (location === 'goBack') {
  267. return history.goBack();
  268. } else if (
  269. (!/^https?\:\/\//.test(location) &&
  270. location ===
  271. history.location.pathname + history.location.search) ||
  272. location === history.location.href
  273. ) {
  274. // 目标地址和当前地址一样,不处理,免得重复刷新
  275. return;
  276. } else if (/^https?\:\/\//.test(location) || !history) {
  277. return (window.location.href = location);
  278. }
  279. history[replace ? 'replace' : 'push'](location);
  280. },
  281. jumpTo: (to, action) => {
  282. if (to === 'goBack') {
  283. return history.goBack();
  284. }
  285. to = normalizeLink(to);
  286. if (isCurrentUrl(to)) {
  287. return;
  288. }
  289. if (action && action.actionType === 'url') {
  290. action.blank === false
  291. ? (window.location.href = to)
  292. : window.open(to, '_blank');
  293. return;
  294. } else if (action && action.blank) {
  295. window.open(to, '_blank');
  296. return;
  297. }
  298. if (/^https?:\/\//.test(to)) {
  299. window.location.href = to;
  300. } else if (
  301. (!/^https?\:\/\//.test(to) &&
  302. to === history.pathname + history.location.search) ||
  303. to === history.location.href
  304. ) {
  305. // do nothing
  306. } else {
  307. history.push(to);
  308. }
  309. },
  310. isCurrentUrl: isCurrentUrl,
  311. theme: 'cxd'
  312. }
  313. );
  314. history.listen(state => {
  315. amisInstance.updateProps({
  316. location: state.location || state
  317. });
  318. });
  319. })();
  320. </script>
  321. </body>
  322. </html>