testapp.html 10 KB

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