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