app.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  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. <script src="./lang/en-US.js"></script>
  81. <script src="./lang/zh-CN.js"></script>
  82. <script>
  83. (function () {
  84. let amis = amisRequire('amis/embed');
  85. const match = amisRequire('path-to-regexp').match;
  86. // 引入语言包内容
  87. let enUSLocale = enUs()
  88. let zhCNLocale = zhCn()
  89. //多语言映射
  90. const languageMap = {
  91. "en-US": {
  92. register: enUSLocale.register,
  93. replaceText: enUSLocale.replaceText,
  94. langReplaceTextIgnoreKeys: enUSLocale.langReplaceTextIgnoreKeys
  95. },
  96. "zh-CN": {
  97. register: zhCNLocale.register,
  98. replaceText: zhCNLocale.replaceText,
  99. langReplaceTextIgnoreKeys: zhCNLocale.langReplaceTextIgnoreKeys
  100. }
  101. }
  102. // 缓存中设置的语言
  103. let lang = localStorage.getItem('language')
  104. //内置组件的翻译信息
  105. let langRegister = {}
  106. //json配置的全文翻译信息
  107. let langReplaceText = {}
  108. //需要忽略json配置的全文替换key
  109. let langReplaceTextIgnoreKeys = {}
  110. if (undefined !== languageMap[lang]) {
  111. langRegister = languageMap[lang].register
  112. langReplaceText = languageMap[lang].replaceText
  113. langReplaceTextIgnoreKeys = languageMap[lang].langReplaceTextIgnoreKeys
  114. } else {
  115. lang = 'zh-CN'
  116. }
  117. if (undefined !== langReplaceText && Object.keys(langReplaceText).length !== 0) {
  118. } else {
  119. langReplaceText = {}
  120. }
  121. if (undefined !== langReplaceTextIgnoreKeys && Object.keys(langReplaceTextIgnoreKeys).length !== 0) {
  122. } else {
  123. langReplaceTextIgnoreKeys = {}
  124. }
  125. // 如果想用 browserHistory 请切换下这处代码, 其他不用变
  126. // const history = History.createBrowserHistory();
  127. const history = History.createHashHistory();
  128. const header = {
  129. "type": "page",
  130. "initApi": "/api/sys_user_info",
  131. "body": [
  132. {
  133. "type": "flex",
  134. "justify": "flex-end",
  135. "items": [
  136. {
  137. "type": "dropdown-button",
  138. "label": "",
  139. "className": "header-menu",
  140. "buttons": [
  141. {
  142. "type": "button",
  143. "label": "中文",
  144. "id": "u:6911502c8fcc",
  145. "onEvent": {
  146. "click": {
  147. "actions": [
  148. {
  149. "script": "localStorage.setItem('language', 'zh-CN')\nlocation.reload()",
  150. "actionType": "custom",
  151. "args": {
  152. }
  153. }
  154. ],
  155. "weight": 0
  156. }
  157. }
  158. },
  159. {
  160. "type": "button",
  161. "label": "English",
  162. "id": "u:e702685a7a45",
  163. "onEvent": {
  164. "click": {
  165. "actions": [
  166. {
  167. "script": "localStorage.setItem('language', 'en-US')\r\nlocation.reload()",
  168. "actionType": "custom"
  169. }
  170. ],
  171. "weight": 0
  172. }
  173. },
  174. "actionType": "",
  175. "link": "/view/user_info"
  176. }
  177. ],
  178. "id": "u:4fedf7a987bf",
  179. "size": "md",
  180. "level": "default",
  181. "align": "right",
  182. "block": false,
  183. "hideCaret": true,
  184. "trigger": "hover",
  185. "icon": "./public/static/icon/language-change.png",
  186. "btnClassName": "no-border"
  187. },
  188. {
  189. "type": "dropdown-button",
  190. "label": "名字e",
  191. "className": "header-menu",
  192. "buttons": [
  193. {
  194. "type": "button",
  195. "label": "个人信息",
  196. "actionType": "link",
  197. "link": "/view/user_info",
  198. "id": "u:57cf3ed9c568"
  199. },
  200. {
  201. "type": "button",
  202. "actionType": "url",
  203. "url": "/login/out",
  204. "blank": false,
  205. "confirmText": "确定要退出吗",
  206. "label": "退出登录",
  207. "id": "u:88d8afc464b5"
  208. }
  209. ],
  210. "id": "u:d324269526b9",
  211. "size": "md",
  212. "level": "default",
  213. "align": "right",
  214. "block": true,
  215. "trigger": "hover"
  216. }
  217. ],
  218. "id": "u:e7752d0c1dbe"
  219. }
  220. ],
  221. "id": "u:d16525b6aae6"
  222. }
  223. const app = {
  224. type: 'app',
  225. brandName: 'ROMA',
  226. // logo: './public/static/images/logo.jpg',
  227. // footer: '<div class="p-2 text-center bg-light">底部区域</div>',
  228. // asideBefore: '<div class="p-2 text-center">菜单前面区域</div>',
  229. // asideAfter: '<div class="p-2 text-center">菜单后面区域</div>',
  230. // // api: '/pages/site.json'
  231. header,
  232. api: 'http://172.20.118.83:8051/demomenu'
  233. };
  234. function normalizeLink(to, location = history.location) {
  235. to = to || '';
  236. if (to && to[0] === '#') {
  237. to = location.pathname + location.search + to;
  238. } else if (to && to[0] === '?') {
  239. to = location.pathname + to;
  240. }
  241. const idx = to.indexOf('?');
  242. const idx2 = to.indexOf('#');
  243. let pathname = ~idx
  244. ? to.substring(0, idx)
  245. : ~idx2
  246. ? to.substring(0, idx2)
  247. : to;
  248. let search = ~idx ? to.substring(idx, ~idx2 ? idx2 : undefined) : '';
  249. let hash = ~idx2 ? to.substring(idx2) : location.hash;
  250. if (!pathname) {
  251. pathname = location.pathname;
  252. } else if (pathname[0] != '/' && !/^https?\:\/\//.test(pathname)) {
  253. let relativeBase = location.pathname;
  254. const paths = relativeBase.split('/');
  255. paths.pop();
  256. let m;
  257. while ((m = /^\.\.?\//.exec(pathname))) {
  258. if (m[0] === '../') {
  259. paths.pop();
  260. }
  261. pathname = pathname.substring(m[0].length);
  262. }
  263. pathname = paths.concat(pathname).join('/');
  264. }
  265. return pathname + search + hash;
  266. }
  267. function isCurrentUrl(to, ctx) {
  268. if (!to) {
  269. return false;
  270. }
  271. const pathname = history.location.pathname;
  272. const link = normalizeLink(to, {
  273. ...location,
  274. pathname,
  275. hash: ''
  276. });
  277. if (!~link.indexOf('http') && ~link.indexOf(':')) {
  278. let strict = ctx && ctx.strict;
  279. return match(link, {
  280. decode: decodeURIComponent,
  281. strict: typeof strict !== 'undefined' ? strict : true
  282. })(pathname);
  283. }
  284. return decodeURI(pathname) === link;
  285. }
  286. let amisInstance = amis.embed(
  287. '#root',
  288. app,
  289. {
  290. location: history.location,
  291. locale: lang
  292. },
  293. {
  294. replaceText: langReplaceText,
  295. langReplaceTextIgnoreKeys: langReplaceTextIgnoreKeys,
  296. // watchRouteChange: fn => {
  297. // return history.listen(fn);
  298. // },
  299. updateLocation: (location, replace) => {
  300. location = normalizeLink(location);
  301. if (location === 'goBack') {
  302. return history.goBack();
  303. } else if (
  304. (!/^https?\:\/\//.test(location) &&
  305. location ===
  306. history.location.pathname + history.location.search) ||
  307. location === history.location.href
  308. ) {
  309. // 目标地址和当前地址一样,不处理,免得重复刷新
  310. return;
  311. } else if (/^https?\:\/\//.test(location) || !history) {
  312. return (window.location.href = location);
  313. }
  314. history[replace ? 'replace' : 'push'](location);
  315. },
  316. jumpTo: (to, action) => {
  317. if (to === 'goBack') {
  318. return history.goBack();
  319. }
  320. to = normalizeLink(to);
  321. if (isCurrentUrl(to)) {
  322. return;
  323. }
  324. if (action && action.actionType === 'url') {
  325. action.blank === false
  326. ? (window.location.href = to)
  327. : window.open(to, '_blank');
  328. return;
  329. } else if (action && action.blank) {
  330. window.open(to, '_blank');
  331. return;
  332. }
  333. if (/^https?:\/\//.test(to)) {
  334. window.location.href = to;
  335. } else if (
  336. (!/^https?\:\/\//.test(to) &&
  337. to === history.pathname + history.location.search) ||
  338. to === history.location.href
  339. ) {
  340. // do nothing
  341. } else {
  342. history.push(to);
  343. }
  344. },
  345. isCurrentUrl: isCurrentUrl,
  346. theme: 'cxd'
  347. }
  348. );
  349. history.listen(state => {
  350. amisInstance.updateProps({
  351. location: state.location || state
  352. });
  353. });
  354. })();
  355. </script>
  356. </body>
  357. </html>