Commit d460e8cf by 钟乾明

u: 优化开发环境配置

parent 61a0da9d
......@@ -4,8 +4,39 @@
<meta charset='utf-8'>
<meta name='viewport' content='initial-scale=1.0, maximum-scale=1.0, user-scalable=0'>
<title>简历</title>
<script src='miniapp://common/js/qing/qing.js'></script>
<!-- <script src='miniapp://common/js/qing/qing.js'></script>-->
<!-- <script src='https://staging.jffctest.com/public/js/qing/latest/qing.js'></script>-->
<script>
console.log('开始引入库>>');
const ua = window.navigator.userAgent.toLocaleLowerCase();
if (ua.indexOf('qing') > -1) {
console.log('ua qing>>')
if (ua.indexOf('miniapp') > -1) {
console.log('ua 云之家小程序>>')
document.write('<scr' + 'ipt src="miniapp://common/js/qing/qing.js"></scr' + 'ipt>');
sessionStorage.setItem('runClientEnv', 'miniapp');
} else {
console.log('轻应用>>');
const testFlags = ['test', 'localhost', '192.168'];// 测试环境的url标志
if (testFlags.some(flag => location.origin.includes(flag))) {
sessionStorage.setItem('env', 'test');
} else {
sessionStorage.setItem('env', 'prod');
}
const qingUrl = sessionStorage.getItem('env') === 'test' ? 'https://staging.jffctest.com/public/js/qing/latest/qing.js' : 'https://portal.cndrealty.com/public/js/qing/latest/qing.js';
document.write('<scr' + 'ipt src="'+qingUrl+'"></scr' + 'ipt>');
// 轻应用从url上取ticket
let urlParamStr = location.href.split('?')[ 1 ] || '';
urlParamStr = urlParamStr.split('/')[ 0 ] || ''; // 截止/。用于去除尾部 /
urlParamStr = urlParamStr.split('#')[ 0 ] || ''; // 截止#。用于去除尾部 #
const urlParams = new URLSearchParams(((location.href.split('?')[ 1 ] || '').split('/')[ 0 ] || '').split('#')[ 0 ]);
// 从url上取ticket 存至全局
sessionStorage.setItem('ticket', urlParams.get('ticket') || '');
sessionStorage.setItem('runClientEnv', 'qing');
}
}
</script>
</head>
<body>
<div class='header'>
......
......@@ -71,6 +71,17 @@ let config = {
note: ['jobstarttime', 'jobendtime'],
},
},
mVoList: {
name: '干部考核',
type: RENDER_TYPE.G,
img: 'cadre',
list: {
title: 'year',
note: 'result',
chilkey: ['attachmentName', 'attachmentFile'],
children: 'attachmentArray',
},
},
cadreEvaluationVoList: {
name: '干部考核',
type: RENDER_TYPE.G,
......
......@@ -62,7 +62,7 @@ const config = {
loginuserid: '46000011',
appkey: 'd504275e',
uid: 'hqhuang@cndrealty.com',
token:'yzj_6082c32a80f913acd16a0e8e9364914d',
token:'yzj_199aa82fe0a735a740f446f4d1929e03',
baseUrl: 'https://staging.jffctest.com/',
};
......
......@@ -33,8 +33,7 @@ window.customEvt = {
var customEvt = window.customEvt
var qing = window.qing
console.log('qing---1');
qing.ready(function () {
qing&&qing.ready(function () {
// 重写左侧返回按钮
qing.call('defback', {
success: function () {
......
import axios from 'axios';
var originAdapter = axios.defaults.adapter;
console.log('r process.env.PACK_ENV>>', process.env.PACK_ENV);
axios.defaults.adapter = function(config) {
if (!/^https?/.test(config.url)) {
// 区分美信云cordova环境、云之家qing环境
if (!process.env.PACK_ENV||process.env.PACK_ENV === 'dev') {
return originAdapter(config);
} else {
if (sessionStorage.getItem('runClientEnv') === 'qing') {
console.log('轻应用request config>>', config);
return request(config);
}
if (!/^https?/.test(config.url)) {
console.log('is https>>');
return originAdapter(config);
}
return request(config);
}
return request(config);
};
function isObject(value) {
......@@ -33,15 +45,12 @@ function params2object(url) {
if (typeof url === 'object') {
return url;
} else if (typeof url === 'string') {
url
.replace(/^.*\?|#.*$/g, '')
.split('&')
.forEach((n) => {
n = n.split('=');
if (n.length === 2) {
params[ n[ 0 ] ] = decodeURIComponent(n[ 1 ]);
}
});
url.replace(/^.*\?|#.*$/g, '').split('&').forEach((n) => {
n = n.split('=');
if (n.length === 2) {
params[ n[ 0 ] ] = decodeURIComponent(n[ 1 ]);
}
});
}
return params;
}
......@@ -67,18 +76,16 @@ function request(opt) {
opt.url =
opt.url.split('?')[ 0 ] +
'?' +
Object.keys(urlParams)
.map((key) => {
var val = urlParams[ key ];
if (isObject(val)) {
val = JSON.stringify(val);
val = encodeURIComponent(val);
} else if (/[^\x00-\xff]/.test(val)) {
val = encodeURIComponent(val);
}
return key + '=' + val;
})
.join('&');
Object.keys(urlParams).map((key) => {
var val = urlParams[ key ];
if (isObject(val)) {
val = JSON.stringify(val);
val = encodeURIComponent(val);
} else if (/[^\x00-\xff]/.test(val)) {
val = encodeURIComponent(val);
}
return key + '=' + val;
}).join('&');
// post非json即是form。
if (opt.method.toLowerCase() === 'post') {
......@@ -107,21 +114,20 @@ function request(opt) {
opt.headers = opt.headers || {};
const headers = {};
// headers字段值必须是字符串型
Object.keys(opt.headers)
.forEach(function(key) {
var val = opt.headers[ key ];
if (val) {
var type = typeof val;
if (type !== 'string') {
val = val + '';
}
// 因content-type可能存在大小写不规范,这里先过滤掉,后面根据serializer统一添加
var _key = key.toLowerCase();
if (_key !== 'content-type') {
headers[ _key ] = val;
}
Object.keys(opt.headers).forEach(function(key) {
var val = opt.headers[ key ];
if (val) {
var type = typeof val;
if (type !== 'string') {
val = val + '';
}
});
// 因content-type可能存在大小写不规范,这里先过滤掉,后面根据serializer统一添加
var _key = key.toLowerCase();
if (_key !== 'content-type') {
headers[ _key ] = val;
}
}
});
// 根据serializer统一添加content-type
headers[ 'content-type' ] = serializer === 'json' ? 'application/json' : 'application/x-www-form-urlencoded';
opt.headers = headers;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment