|
@@ -11,16 +11,16 @@ export function getMobileOperatingSystem() {
|
|
|
const userAgent = navigator.userAgent || navigator.vendor || window.opera;
|
|
|
|
|
|
// Windows Phone must come first because its UA also contains "Android"
|
|
|
- if (/windows phone/i.test(userAgent)) {
|
|
|
+ if ( /windows phone/i.test(userAgent) ) {
|
|
|
return 'Windows Phone';
|
|
|
}
|
|
|
|
|
|
- if (/android/i.test(userAgent)) {
|
|
|
+ if ( /android/i.test(userAgent) ) {
|
|
|
return 'Android';
|
|
|
}
|
|
|
|
|
|
// iOS detection from: http://stackoverflow.com/a/9039885/177710
|
|
|
- if (/iPad|iPhone|iPod/.test(userAgent) && !window.MSStream) {
|
|
|
+ if ( /iPad|iPhone|iPod/.test(userAgent) && !window.MSStream ) {
|
|
|
return 'iOS';
|
|
|
}
|
|
|
|
|
@@ -38,13 +38,13 @@ export function getQueryParam() {
|
|
|
query = location.search
|
|
|
.slice(1)
|
|
|
.split('&')
|
|
|
- .map((p) => p.split('='))
|
|
|
+ .map(( p ) => p.split('='))
|
|
|
// .reduce((obj: Record<string, string>, pair) => {
|
|
|
- .reduce((obj, pair) => {
|
|
|
- const [key, value] = pair.map(decodeURIComponent);
|
|
|
+ .reduce(( obj,pair ) => {
|
|
|
+ const [key,value] = pair.map(decodeURIComponent);
|
|
|
obj[key] = value;
|
|
|
return obj;
|
|
|
- }, {});
|
|
|
+ },{});
|
|
|
return query;
|
|
|
}
|
|
|
|
|
@@ -59,11 +59,11 @@ export function isInWeixinH5() {
|
|
|
export function getPlatform() {
|
|
|
const userAgent = navigator.userAgent.toLowerCase();
|
|
|
// 微信小程序
|
|
|
- if (/miniprogram/g.test(userAgent)) {
|
|
|
+ if ( /miniprogram/g.test(userAgent) ) {
|
|
|
return 'miniprogram';
|
|
|
}
|
|
|
// 微信公众号
|
|
|
- if (/micromessenger/g.test(userAgent)) {
|
|
|
+ if ( /micromessenger/g.test(userAgent) ) {
|
|
|
return 'micromessenger';
|
|
|
}
|
|
|
return 'miniprogram'; // TODO: 上线前改为其他
|
|
@@ -82,20 +82,20 @@ export function getIsWxh5() {
|
|
|
}
|
|
|
|
|
|
// 获取appid
|
|
|
-export function getAppIdByGroupIdAndMallId({ groupId, mallId, type }) {
|
|
|
+export function getAppIdByGroupIdAndMallId( {groupId,mallId,type} ) {
|
|
|
const platform = getPlatform();
|
|
|
- if (platform === 'miniprogram') {
|
|
|
+ if ( platform === 'miniprogram' ) {
|
|
|
return 'wx92c3e55fbef6b2af';
|
|
|
}
|
|
|
- if (platform === 'micromessenger') {
|
|
|
+ if ( platform === 'micromessenger' ) {
|
|
|
// 后期在其他公众号上线H5应用,appid需要根据地址栏的 project 动态处理, 已预留入口
|
|
|
// console.log(89);
|
|
|
const env = window.env === 'qa' ? 'qa' : 'prod';
|
|
|
let appInfo = {};
|
|
|
- Object.keys(lbsDictionary).forEach((lbsId) => {
|
|
|
+ Object.keys(lbsDictionary).forEach(( lbsId ) => {
|
|
|
const elm = lbsDictionary[lbsId];
|
|
|
// console.log(92, env, elm[env].groupId, groupId, elm[env].mallId, mallId);
|
|
|
- if (elm[env].groupId === groupId && elm[env].mallId === mallId) {
|
|
|
+ if ( elm[env].groupId === groupId && elm[env].mallId === mallId ) {
|
|
|
appInfo = {
|
|
|
appid: elm[env].appid,
|
|
|
// secret: elm[env].secret,
|
|
@@ -104,14 +104,14 @@ export function getAppIdByGroupIdAndMallId({ groupId, mallId, type }) {
|
|
|
}
|
|
|
});
|
|
|
// console.log(101, appInfo);
|
|
|
- if (JSON.stringify(appInfo) === '{}') {
|
|
|
+ if ( JSON.stringify(appInfo) === '{}' ) {
|
|
|
// groupId, mallId 错误
|
|
|
return;
|
|
|
}
|
|
|
- if (type === 'appid') {
|
|
|
+ if ( type === 'appid' ) {
|
|
|
return appInfo.appid;
|
|
|
}
|
|
|
- if (type === 'all') {
|
|
|
+ if ( type === 'all' ) {
|
|
|
return appInfo;
|
|
|
}
|
|
|
return 'wx907c27f16841a919';
|
|
@@ -119,28 +119,28 @@ export function getAppIdByGroupIdAndMallId({ groupId, mallId, type }) {
|
|
|
return '';
|
|
|
}
|
|
|
|
|
|
-export function getUrlParams(url = window.location.href) {
|
|
|
- const str = `${url}`.split('?')[1];
|
|
|
- if (!str) return {};
|
|
|
+export function getUrlParams( url = window.location.href ) {
|
|
|
+ const str = `${ url }`.split('?')[1];
|
|
|
+ if ( !str ) return {};
|
|
|
return qs.parse(str);
|
|
|
}
|
|
|
|
|
|
// 根据不同环境和lsbid返回 groupId 和 mallId
|
|
|
-export function getGroupIdAndMallIdByLsbId(lbsId) {
|
|
|
- console.log(125, lbsId);
|
|
|
+export function getGroupIdAndMallIdByLsbId( lbsId ) {
|
|
|
+ console.log(125,lbsId);
|
|
|
const lbsObj = lbsDictionary[lbsId];
|
|
|
- if (window.env === 'prod') {
|
|
|
+ if ( window.env === 'prod' ) {
|
|
|
return lbsObj['prod'];
|
|
|
}
|
|
|
return lbsObj['qa'];
|
|
|
}
|
|
|
|
|
|
// 微信小程序端登录之后的回调
|
|
|
-export function wxToLoginCallback(path, callback) {
|
|
|
+export function wxToLoginCallback( path,callback ) {
|
|
|
const oldPath = uni.getStorageSync('oldPath');
|
|
|
// 如果是在微信小程序内部运行的话
|
|
|
- if (getIsMin() && oldPath !== path) {
|
|
|
- uni.setStorageSync('oldPath', path);
|
|
|
+ if ( getIsMin() && oldPath !== path ) {
|
|
|
+ uni.setStorageSync('oldPath',path);
|
|
|
// 前往登录
|
|
|
window.toWXSendMsg({
|
|
|
type: 'toLogin',
|
|
@@ -148,9 +148,9 @@ export function wxToLoginCallback(path, callback) {
|
|
|
path: path,
|
|
|
},
|
|
|
});
|
|
|
- window.subscribe('callback', (options) => {
|
|
|
- console.log('登录页面的回调', JSON.stringify(options));
|
|
|
- if (options.isReload) {
|
|
|
+ window.subscribe('callback',( options ) => {
|
|
|
+ console.log('登录页面的回调',JSON.stringify(options));
|
|
|
+ if ( options.isReload ) {
|
|
|
console.log('刷新页面');
|
|
|
window.location.reload();
|
|
|
} else {
|
|
@@ -168,23 +168,26 @@ export function wxToLoginCallback(path, callback) {
|
|
|
|
|
|
export function initEnv() {
|
|
|
const href = window.location.href;
|
|
|
- console.log('当前页面的url地址 ', href);
|
|
|
- if (/dev-|8080/.test(href)) {
|
|
|
- window.env = 'qa';
|
|
|
- window.profileApi = 'https://qa-apim.kerryplus.com/c/api';
|
|
|
- window.api = 'qaApi';
|
|
|
- /* window.env = 'dev';
|
|
|
+ console.log('当前页面的url地址 ',href);
|
|
|
+ if ( /dev-|8080/.test(href) ) {
|
|
|
+ /*window.env = 'qa';
|
|
|
+ window.profileApi = 'https://qa-apim.kerryplus.com/c/api';
|
|
|
+ window.api = 'qaApi';*/
|
|
|
+ window.env = 'dev';
|
|
|
window.profileApi = 'https://dev-gateway-kip.kerryonvip.com/api';
|
|
|
- window.api = 'devApi'; */
|
|
|
+ window.api = 'devApi';
|
|
|
+ // window.env = 'prod';
|
|
|
+ // window.profileApi = 'https://sl-apim.kerryplus.com/c/api';
|
|
|
+ // window.api = 'api';
|
|
|
return;
|
|
|
}
|
|
|
- if (/qa-/.test(href)) {
|
|
|
+ if ( /qa-/.test(href) ) {
|
|
|
window.env = 'qa';
|
|
|
window.api = 'qaApi';
|
|
|
window.profileApi = 'https://qa-apim.kerryplus.com/c/api';
|
|
|
return;
|
|
|
}
|
|
|
- if (/sl-/.test(href)) {
|
|
|
+ if ( /sl-/.test(href) ) {
|
|
|
window.env = 'prod';
|
|
|
window.profileApi = 'https://sl-apim.kerryplus.com/c/api';
|
|
|
window.api = 'api';
|
|
@@ -213,11 +216,11 @@ export function requestInit() {
|
|
|
export function getUrl() {
|
|
|
// return `https://crm.kerryplus.com/xcrm-api`; // TODO: 临时更改websocket域名为prod
|
|
|
// 如果 kerry+ 这边的访问环境是 sl 或者 lt,需要把 wss 指向 qa 环境。
|
|
|
- const href = `${window.location.href}`;
|
|
|
- if (/dev-|8080/.test(href)) {
|
|
|
+ const href = `${ window.location.href }`;
|
|
|
+ if ( /dev-|8080/.test(href) ) {
|
|
|
return 'https://qa-crm-kpl.kerryprops.com.cn/xcrm-api';
|
|
|
}
|
|
|
- if (/qa-/.test(href)) {
|
|
|
+ if ( /qa-/.test(href) ) {
|
|
|
return 'https://qa-crm-kpl.kerryprops.com.cn/xcrm-api';
|
|
|
}
|
|
|
// return 'https://qa-crm-kpl.kerryprops.com.cn/xcrm-api';
|
|
@@ -226,11 +229,11 @@ export function getUrl() {
|
|
|
|
|
|
export function windowSendInit() {
|
|
|
const token = window.token;
|
|
|
- window.toWXSendMsg = function ({ type = '', funcName = '', options = {} }) {
|
|
|
+ window.toWXSendMsg = function ( {type = '',funcName = '',options = {}} ) {
|
|
|
/**
|
|
|
* 向小程序端发送消息
|
|
|
*/
|
|
|
- if (!type) return;
|
|
|
+ if ( !type ) return;
|
|
|
window.stompClient.send(
|
|
|
'/sendToWechat',
|
|
|
{},
|
|
@@ -248,29 +251,29 @@ export function windowSendInit() {
|
|
|
};
|
|
|
|
|
|
// 主动订阅事件回调
|
|
|
- window.subscribe = function (type, callback) {
|
|
|
- const subscribeId = window.stompClient.subscribe('/user/' + token + '/toH5', function (response) {
|
|
|
+ window.subscribe = function ( type,callback ) {
|
|
|
+ const subscribeId = window.stompClient.subscribe('/user/' + token + '/toH5',function ( response ) {
|
|
|
try {
|
|
|
let res = {
|
|
|
token: '', // 微信小程序端 页面的传递过来的token
|
|
|
data: '', // 微信小程序端 页面的传递过来的信息(已加密)
|
|
|
};
|
|
|
- if (response.body) {
|
|
|
+ if ( response.body ) {
|
|
|
res = JSON.parse(response.body);
|
|
|
}
|
|
|
// 检查 微信小程序端 发送过来的信息和token是否与当前页面的 token一致。并且 res.data 携带信息,在解密之后是 json 格式
|
|
|
- if (res.token && res.token === token && res.data) {
|
|
|
+ if ( res.token && res.token === token && res.data ) {
|
|
|
const msgJson = JSON.parse(Decrypt(res.data));
|
|
|
const reg = new RegExp(type);
|
|
|
// 获取 projectId
|
|
|
- if (reg.test(msgJson.type)) {
|
|
|
- callback(msgJson.options, subscribeId);
|
|
|
+ if ( reg.test(msgJson.type) ) {
|
|
|
+ callback(msgJson.options,subscribeId);
|
|
|
subscribeId.unsubscribe();
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
- } catch (err) {
|
|
|
- console.log('stomp error', err);
|
|
|
+ } catch ( err ) {
|
|
|
+ console.log('stomp error',err);
|
|
|
}
|
|
|
});
|
|
|
};
|
|
@@ -278,23 +281,23 @@ export function windowSendInit() {
|
|
|
|
|
|
|
|
|
export function wssInit() {
|
|
|
- return new Promise((resolve, reject) => {
|
|
|
+ return new Promise(( resolve,reject ) => {
|
|
|
try {
|
|
|
- const socket = new SockJS(`${getUrl()}/hafengWebsocket?token=${window.token}`);
|
|
|
+ const socket = new SockJS(`${ getUrl() }/hafengWebsocket?token=${ window.token }`);
|
|
|
window.stompClient = Stomp.over(socket);
|
|
|
window.stompClient.debug = null;
|
|
|
windowSendInit();
|
|
|
- window.stompClient.connect({}, (frame) => {
|
|
|
+ window.stompClient.connect({},( frame ) => {
|
|
|
// 请求 projectId
|
|
|
window.toWXSendMsg({
|
|
|
type: 'getProjectId',
|
|
|
options: {},
|
|
|
});
|
|
|
- window.subscribe('projectId', (options) => {
|
|
|
+ window.subscribe('projectId',( options ) => {
|
|
|
resolve(options);
|
|
|
});
|
|
|
});
|
|
|
- } catch (err) {
|
|
|
+ } catch ( err ) {
|
|
|
reject(err);
|
|
|
}
|
|
|
});
|