app.html 12 KB

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