| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242 |
- <!DOCTYPE html>
- <html lang="zh">
- <head>
- <meta charset="UTF-8" />
- <title>ROMA</title>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <link rel="icon" type="image/x-ico" href=""/>
- <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
- <meta http-equiv="X-UA-Compatible" content="IE=Edge" />
- <link rel="stylesheet" href="./public/static/amis-sdk/helper.css">
- <link rel="stylesheet" href="./public/static/amis-sdk/sdk.css">
- <link rel="stylesheet" href="./public/static/amis-sdk/iconfont.css">
- <link rel="stylesheet" href="./public/static/fonts/remixicon.css">
- <!-- 引入自定义样式 -->
- <link rel="stylesheet" href="./public/static/css/app.css">
- </head>
- <body>
- <div id="root" class="app-wrapper"></div>
- <script type='text/javascript' src='./public/static/amis-sdk/sdk.js'></script>
- <script type='text/javascript' src='./public/static/amis-static/history.js'></script>
- <!-- 引入语言包 -->
- <script src="./lang/en-US.js"></script>
- <script src="./lang/zh-CN.js"></script>
- <!-- 引入多语言js处理文件,必须先引入语言包 -->
- <script src="./public/static/tools/common.js"></script>
- <!-- 引入header的JSON -->
- <script src="./pages/app/header-json.js"></script>
- <script>
- (function () {
- var systemUri = getSystemIp();
- let amis = amisRequire('amis/embed');
- const match = amisRequire('path-to-regexp').match;
- // 如果想用 browserHistory 请切换下这处代码, 其他不用变
- // const history = History.createBrowserHistory();
- const history = History.createHashHistory();
- const header = getHeaderJson()
- const app = {
- type: 'app',
- brandName: 'ROMA',
- // logo: './public/static/images/logo.jpg',
- // footer: '<div class="p-2 text-center bg-light">底部区域</div>',
- // asideBefore: '<div class="p-2 text-center">菜单前面区域</div>',
- // asideAfter: '<div class="p-2 text-center">菜单后面区域</div>',
- // // api: '/pages/site.json'
- breadcrumb:false,
- header,
- api: {
- "url": '/page/menu'
- }
- };
- function normalizeLink(to, location = history.location) {
- to = to || '';
- if (to && to[0] === '#') {
- to = location.pathname + location.search + to;
- } else if (to && to[0] === '?') {
- to = location.pathname + to;
- }
- const idx = to.indexOf('?');
- const idx2 = to.indexOf('#');
- let pathname = ~idx
- ? to.substring(0, idx)
- : ~idx2
- ? to.substring(0, idx2)
- : to;
- let search = ~idx ? to.substring(idx, ~idx2 ? idx2 : undefined) : '';
- let hash = ~idx2 ? to.substring(idx2) : location.hash;
- if (!pathname) {
- pathname = location.pathname;
- } else if (pathname[0] != '/' && !/^https?\:\/\//.test(pathname)) {
- let relativeBase = location.pathname;
- const paths = relativeBase.split('/');
- paths.pop();
- let m;
- while ((m = /^\.\.?\//.exec(pathname))) {
- if (m[0] === '../') {
- paths.pop();
- }
- pathname = pathname.substring(m[0].length);
- }
- pathname = paths.concat(pathname).join('/');
- }
- return pathname + search + hash;
- }
- function isCurrentUrl(to, ctx) {
- if (!to) {
- return false;
- }
- const pathname = history.location.pathname;
- const link = normalizeLink(to, {
- ...location,
- pathname,
- hash: ''
- });
- if (!~link.indexOf('http') && ~link.indexOf(':')) {
- let strict = ctx && ctx.strict;
- return match(link, {
- decode: decodeURIComponent,
- strict: typeof strict !== 'undefined' ? strict : true
- })(pathname);
- }
- return decodeURI(pathname) === link;
- }
- let languageInfo = getLanguageInfo();//获取语言包内容
- let amisInstance = amis.embed(
- '#root',
- app,
- {
- location: history.location,
- locale: languageInfo.lang
- },
- {
- replaceText: languageInfo.langReplaceText,
- langReplaceTextIgnoreKeys: languageInfo.langReplaceTextIgnoreKeys,
- // watchRouteChange: fn => {
- // return history.listen(fn);
- // },
- fetcher: (params) => {
- var systemUri = getSystemIp();
- var method = params.method;
- var data = params.data;
- var body = params.body;
- var url = systemUri + params.url;
- var form = new FormData();
- form = JSON.stringify(params.data);
- var ContentType = 'application/x-www-form-urlencoded';
- // var ContentType = 'application/json';
- let header = {
- "Content-Type": ContentType,
- "Authorization":'Bearer ' + getToken(),
- }
-
- let isFormData = (typeof FormData !== 'undefined') && (params['data'] instanceof FormData);
-
- // if (isFormData) {
- // delete header['Content-Type'];
- // form = data;
- // }
- let headers = new Headers(header);
- return new Promise(function (resolve, reject) {
- fetch(url,{
- method: method,
- body: params.data,
- headers: headers
- }).then(function (response) {
- return response.json();
- }).then(function (res) {
- if(res.status == "50000") {
- localStorage.removeItem("apiToken");
- window.location.href="./login.html";
- }
- // if (isFormData) {
- // data['data'] = res.data;
- // }
- resolve({ "data": res });
- });
- });
- },
- updateLocation: (location, replace) => {
- location = normalizeLink(location);
- if (location === 'goBack') {
- return history.goBack();
- } else if (
- (!/^https?\:\/\//.test(location) &&
- location ===
- history.location.pathname + history.location.search) ||
- location === history.location.href
- ) {
- // 目标地址和当前地址一样,不处理,免得重复刷新
- return;
- } else if (/^https?\:\/\//.test(location) || !history) {
- return (window.location.href = location);
- }
- history[replace ? 'replace' : 'push'](location);
- },
- jumpTo: (to, action) => {
- if (to === 'goBack') {
- return history.goBack();
- }
- to = normalizeLink(to);
- if (isCurrentUrl(to)) {
- return;
- }
- if (action && action.actionType === 'url') {
- action.blank === false
- ? (window.location.href = to)
- : window.open(to, '_blank');
- return;
- } else if (action && action.blank) {
- window.open(to, '_blank');
- return;
- }
- if (/^https?:\/\//.test(to)) {
- window.location.href = to;
- } else if (
- (!/^https?\:\/\//.test(to) &&
- to === history.pathname + history.location.search) ||
- to === history.location.href
- ) {
- // do nothing
- } else {
- history.push(to);
- }
- },
- isCurrentUrl: isCurrentUrl,
- theme: 'cxd'
- }
- );
- history.listen(state => {
- amisInstance.updateProps({
- location: state.location || state
- });
- });
- })();
- // 获取登录的token-登录请求不需要登录token
- function getToken() {
- return localStorage.getItem("apiToken");
- }
- </script>
- </body>
- </html>
|