|
@@ -5,248 +5,34 @@ import { lbsDictionary } from '@/common/js/BaseDictionary';
|
|
|
import uni from './uniHooks';
|
|
|
import {Dialog} from "vant";
|
|
|
import kipTheme from "@/kui/theme/theme";
|
|
|
+import { devInit, qaInit,slInit,ltInit,prodInit } from '@/environment';
|
|
|
// import Vue from 'vue';
|
|
|
|
|
|
-export function getMobileOperatingSystem() {
|
|
|
- // #ifdef H5
|
|
|
- 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) ) {
|
|
|
- return 'Windows Phone';
|
|
|
- }
|
|
|
-
|
|
|
- if ( /android/i.test(userAgent) ) {
|
|
|
- return 'Android';
|
|
|
- }
|
|
|
-
|
|
|
- // iOS detection from: http://stackoverflow.com/a/9039885/177710
|
|
|
- if ( /iPad|iPhone|iPod/.test(userAgent) && !window.MSStream ) {
|
|
|
- return 'iOS';
|
|
|
- }
|
|
|
-
|
|
|
- return 'unknown';
|
|
|
- // #endif
|
|
|
-
|
|
|
- // #ifndef H5
|
|
|
- return 'unknown';
|
|
|
- // #endif
|
|
|
-}
|
|
|
-
|
|
|
-export function getQueryParam() {
|
|
|
- // let query: Record<string, string> = {};
|
|
|
- let query = {};
|
|
|
- query = location.search
|
|
|
- .slice(1)
|
|
|
- .split('&')
|
|
|
- .map(( p ) => p.split('='))
|
|
|
- // .reduce((obj: Record<string, string>, pair) => {
|
|
|
- .reduce(( obj,pair ) => {
|
|
|
- const [key,value] = pair.map(decodeURIComponent);
|
|
|
- obj[key] = value;
|
|
|
- return obj;
|
|
|
- },{});
|
|
|
- return query;
|
|
|
-}
|
|
|
-
|
|
|
-//
|
|
|
-export function isInWeixinH5() {
|
|
|
- // TODO: 发布前取消注释
|
|
|
- return navigator.userAgent.toLowerCase().indexOf('micromessenger') !== -1;
|
|
|
- // return true;
|
|
|
-}
|
|
|
-
|
|
|
-// 判断当前运行平台
|
|
|
-export function getPlatform() {
|
|
|
- const userAgent = navigator.userAgent.toLowerCase();
|
|
|
- // 微信小程序
|
|
|
- if ( /miniprogram/g.test(userAgent) ) {
|
|
|
- return 'miniprogram';
|
|
|
- }
|
|
|
- // 微信公众号
|
|
|
- if ( /micromessenger/g.test(userAgent) ) {
|
|
|
- return 'micromessenger';
|
|
|
- }
|
|
|
- return 'miniprogram'; // TODO: 上线前改为其他
|
|
|
-}
|
|
|
-
|
|
|
-// 是否是支付宝
|
|
|
-export function isAlipay() {
|
|
|
- const userAgent = navigator.userAgent.toLowerCase();
|
|
|
- return /alipayclient/g.test(userAgent)
|
|
|
-}
|
|
|
-// 是否在微信小程序中运行
|
|
|
-export function getIsMin() {
|
|
|
- const platform = getPlatform();
|
|
|
- // console.log('platform====>80', platform);
|
|
|
- return platform === 'miniprogram';
|
|
|
-}
|
|
|
-
|
|
|
-// 是否在微信公众号中运行
|
|
|
-export function getIsWxh5() {
|
|
|
- const platform = getPlatform();
|
|
|
- return platform === 'micromessenger';
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-// 获取appid
|
|
|
-export function getAppIdByGroupIdAndMallId( {groupId,mallId,type} ) {
|
|
|
- const platform = getPlatform();
|
|
|
- if ( platform === 'miniprogram' ) {
|
|
|
- return 'wx92c3e55fbef6b2af';
|
|
|
- }
|
|
|
- if ( platform === 'micromessenger' ) {
|
|
|
- // 后期在其他公众号上线H5应用,appid需要根据地址栏的 project 动态处理, 已预留入口
|
|
|
- // console.log(89);
|
|
|
- const env = window.env === 'qa' ? 'qa' : 'prod';
|
|
|
- let appInfo = {};
|
|
|
- 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 ) {
|
|
|
- appInfo = {
|
|
|
- appid: elm[env].appid,
|
|
|
- // secret: elm[env].secret,
|
|
|
- projectId: elm[env].projectId,
|
|
|
- };
|
|
|
- }
|
|
|
- });
|
|
|
- // console.log(101, appInfo);
|
|
|
- if ( JSON.stringify(appInfo) === '{}' ) {
|
|
|
- // groupId, mallId 错误
|
|
|
- return;
|
|
|
- }
|
|
|
- if ( type === 'appid' ) {
|
|
|
- return appInfo.appid;
|
|
|
- }
|
|
|
- if ( type === 'all' ) {
|
|
|
- return appInfo;
|
|
|
- }
|
|
|
- return 'wx907c27f16841a919';
|
|
|
- }
|
|
|
- return '';
|
|
|
-}
|
|
|
-
|
|
|
-export function getUrlParams( url = window.location.href ) {
|
|
|
- console.log(131, url)
|
|
|
- const str = `${ url }`.split('?')[1];
|
|
|
- if ( !str ) return {};
|
|
|
- return qs.parse(str);
|
|
|
-}
|
|
|
-
|
|
|
-// 根据不同环境和lsbid返回 groupId 和 mallId
|
|
|
-export function getGroupIdAndMallIdByLsbId( lbsId ) {
|
|
|
- // console.log(125,lbsId);
|
|
|
- const lbsObj = lbsDictionary[lbsId];
|
|
|
- if ( window.env === 'prod' ) {
|
|
|
- return lbsObj['prod'];
|
|
|
- }
|
|
|
- if ( window.env === 'dev' ) {
|
|
|
- return lbsObj['dev'];
|
|
|
- }
|
|
|
- return lbsObj['qa'];
|
|
|
-}
|
|
|
-
|
|
|
-// 微信小程序端登录之后的回调
|
|
|
-export function wxToLoginCallback( path,callback ) {
|
|
|
- const oldPath = uni.getStorageSync('oldPath');
|
|
|
- // 如果是在微信小程序内部运行的话
|
|
|
- if ( getIsMin() && oldPath !== path ) {
|
|
|
- uni.setStorageSync('oldPath',path);
|
|
|
- // 前往登录
|
|
|
- window.toWXSendMsg({
|
|
|
- type: 'toLogin',
|
|
|
- options: {
|
|
|
- path: path,
|
|
|
- },
|
|
|
- });
|
|
|
- window.subscribe('callback',( options ) => {
|
|
|
- // console.log('登录页面的回调',JSON.stringify(options));
|
|
|
- if ( options.isReload || window.isAlipayClient && options?.options?.isReload) {
|
|
|
- // console.log('刷新页面');
|
|
|
- window.location.reload();
|
|
|
- } else {
|
|
|
- // console.log('刷新页面:callback');
|
|
|
- callback && callback(options);
|
|
|
- uni.setStorageSync('oldPath','');
|
|
|
- }
|
|
|
- });
|
|
|
- return;
|
|
|
- }
|
|
|
- // 如果是在微信公众号环境运行的话
|
|
|
- /*if ( getIsWxh5() ) {
|
|
|
- return
|
|
|
- }*/
|
|
|
-}
|
|
|
-
|
|
|
export function initEnv() {
|
|
|
const origin = window.location.origin;
|
|
|
console.log('当前页面的url地址 ',origin);
|
|
|
if (origin.indexOf('http://127.0.0.1') > -1 || origin.indexOf('http://localhost:') > -1) {
|
|
|
- window.env = 'qa';
|
|
|
- window.profileApi = 'https://qa-apim.kerryplus.com/c/api';
|
|
|
- window.cmrApi = 'https://qa-crm.kerryplus.com/xcrm-api/api';
|
|
|
- window.api = 'qaApi';
|
|
|
- window.QR_CODE_BASE_URL = 'https://p.kerryplus.com';
|
|
|
- window.QUESTIONNAIRE_BASE_URL = 'https://qa-questionnaire.kerryplus.com';
|
|
|
- // window.env = 'dev';
|
|
|
- // window.profileApi = 'https://dev-gateway-kip.kerryonvip.com/api';
|
|
|
- // window.cmrApi = 'https://dev-crm.kerryplus.com/xcrm-api/api';
|
|
|
- // window.api = 'devApi';
|
|
|
- // window.env = 'prod';
|
|
|
- // window.profileApi = 'https://sl-apim.kerryplus.com/c/api';
|
|
|
- // window.cmrApi = 'https://sl-crm.kerryplus.com/xcrm-api/api';
|
|
|
- // window.api = 'api';
|
|
|
- window.wechatOfficialAccountId = 'wxb81a622ed6d60adf'
|
|
|
+ // devInit, qaInit,slInit,ltInit,prodInit
|
|
|
+ qaInit()
|
|
|
return;
|
|
|
}
|
|
|
if ( origin.indexOf('https://dev-') > -1) {
|
|
|
- window.env = 'dev';
|
|
|
- window.profileApi = 'https://dev-gateway-kip.kerryonvip.com/api';
|
|
|
- window.cmrApi = 'https://dev-crm.kerryplus.com/xcrm-api/api';
|
|
|
- window.api = 'devApi';
|
|
|
- window.wechatOfficialAccountId = 'wxb81a622ed6d60adf';
|
|
|
- window.QR_CODE_BASE_URL = 'https://pd.kerryplus.com';
|
|
|
- window.QUESTIONNAIRE_BASE_URL = 'https://dev-questionnaire.kerryonvip.com';
|
|
|
+ devInit()
|
|
|
return;
|
|
|
}
|
|
|
if ( origin.indexOf('https://qa-') > -1 ) {
|
|
|
- window.env = 'qa';
|
|
|
- window.api = 'qaApi';
|
|
|
- window.profileApi = 'https://qa-apim.kerryplus.com/c/api';
|
|
|
- window.cmrApi = 'https://qa-crm.kerryplus.com/xcrm-api/api';
|
|
|
- window.wechatOfficialAccountId = 'wxb81a622ed6d60adf';
|
|
|
- window.QR_CODE_BASE_URL = 'https://pq.kerryplus.com';
|
|
|
- window.QUESTIONNAIRE_BASE_URL = 'https://qa-questionnaire.kerryplus.com';
|
|
|
+ qaInit()
|
|
|
return;
|
|
|
}
|
|
|
if ( origin.indexOf('https://sl-') > -1 ) {
|
|
|
- window.env = 'prod';
|
|
|
- window.profileApi = 'https://sl-apim.kerryplus.com/c/api';
|
|
|
- window.cmrApi = 'https://sl-crm.kerryplus.com/xcrm-api/api';
|
|
|
- window.api = 'api';
|
|
|
- window.wechatOfficialAccountId = 'wxb150c7d193e8662d'
|
|
|
- window.QR_CODE_BASE_URL = 'https://p.kerryplus.com';
|
|
|
- window.QUESTIONNAIRE_BASE_URL = 'https://sl-questionnaire.kerryplus.com';
|
|
|
+ slInit()
|
|
|
return;
|
|
|
}
|
|
|
if ( origin.indexOf('https://lt-') > -1 ) {
|
|
|
- window.env = 'lt';
|
|
|
- window.profileApi = 'https://lt-gateway-kip-internal.kerryplus.com/api';
|
|
|
- window.cmrApi = 'https://lt-crm.kerryplus.com/xcrm-api/api';
|
|
|
- window.api = 'api';
|
|
|
- window.wechatOfficialAccountId = 'wx2bd99ca94d6acd7e';
|
|
|
- window.QR_CODE_BASE_URL = 'https://p.kerryplus.com';
|
|
|
- window.QUESTIONNAIRE_BASE_URL = 'https://lt-questionnaire.kerryplus.com';
|
|
|
+ ltInit()
|
|
|
return;
|
|
|
}
|
|
|
- window.env = 'prod';
|
|
|
- window.profileApi = 'https://apim.kerryplus.com/c/api';
|
|
|
- window.cmrApi = 'https://crm.kerryplus.com/xcrm-api/api';
|
|
|
- window.api = 'api';
|
|
|
- window.wechatOfficialAccountId = 'wxb150c7d193e8662d';
|
|
|
- window.QR_CODE_BASE_URL = 'https://p.kerryplus.com';
|
|
|
- window.QUESTIONNAIRE_BASE_URL = 'https://questionnaire.kerryplus.com';
|
|
|
+ prodInit()
|
|
|
}
|
|
|
|
|
|
export function requestInit() {
|
|
@@ -278,154 +64,10 @@ export function getUrl() {
|
|
|
return `https://crm.kerryplus.com/xcrm-api`;
|
|
|
}
|
|
|
|
|
|
-export function windowSendInit() {
|
|
|
- const token = window.token;
|
|
|
- window.toWXSendMsg = function ( {type = '',funcName = '',options = {}} ) {
|
|
|
- if(window.isAlipayClient) {
|
|
|
- my.postMessage({
|
|
|
- name:'h5',
|
|
|
- body: {
|
|
|
- token,
|
|
|
- data: {
|
|
|
- type: type,
|
|
|
- funcName,
|
|
|
- options,
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 向小程序端发送消息
|
|
|
- */
|
|
|
- if ( !type ) return;
|
|
|
- window.stompClient.send(
|
|
|
- '/sendToWechat',
|
|
|
- {},
|
|
|
- JSON.stringify({
|
|
|
- token,
|
|
|
- data: Encrypt(
|
|
|
- JSON.stringify({
|
|
|
- type: type,
|
|
|
- funcName,
|
|
|
- options,
|
|
|
- })
|
|
|
- ),
|
|
|
- })
|
|
|
- );
|
|
|
- };
|
|
|
-
|
|
|
- // 主动订阅事件回调
|
|
|
- window.subscribe = function ( type,callback ) {
|
|
|
- if(window.isAlipayClient) {
|
|
|
- my.onMessage = function (response) {
|
|
|
- console.log('293my.onMessage', response)
|
|
|
- callback(response.body.data);
|
|
|
- }
|
|
|
- return
|
|
|
- }
|
|
|
- const subscribeId = window.stompClient.subscribe('/user/' + token + '/toH5',function ( response ) {
|
|
|
- try {
|
|
|
- let res = {
|
|
|
- token: '', // 微信小程序端 页面的传递过来的token
|
|
|
- data: '', // 微信小程序端 页面的传递过来的信息(已加密)
|
|
|
- };
|
|
|
- if ( response.body ) {
|
|
|
- res = JSON.parse(response.body);
|
|
|
- }
|
|
|
- // 检查 微信小程序端 发送过来的信息和token是否与当前页面的 token一致。并且 res.data 携带信息,在解密之后是 json 格式
|
|
|
- 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);
|
|
|
- subscribeId.unsubscribe();
|
|
|
- return;
|
|
|
- }
|
|
|
- }
|
|
|
- } catch ( err ) {
|
|
|
- console.log('stomp error',err);
|
|
|
- }
|
|
|
- });
|
|
|
- };
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
|
|
|
-// 获取当前的主题
|
|
|
-export function getsTheCurrentTopic() {
|
|
|
- let theme = 'theme-mall'
|
|
|
- let componentName = ''
|
|
|
- const source = uni.getStorageSync('source')
|
|
|
- const custTypeId = uni.getStorageSync('custTypeId')
|
|
|
- const com = ['purpleCom', 'blueCom', 'greenCom', 'officeBlueCom', 'purpleCom'];
|
|
|
- if (custTypeId < 3 || !custTypeId) {
|
|
|
- componentName = 'baseParkingFeeCom';
|
|
|
- theme = 'theme-mall'
|
|
|
- } else {
|
|
|
- componentName = com[custTypeId];
|
|
|
- theme = 'theme-office'
|
|
|
- }
|
|
|
- if (source === 'KIP') {
|
|
|
- theme = 'theme-office'
|
|
|
- }
|
|
|
- if (source === 'PUDONG') {
|
|
|
- theme = 'theme-pudong'
|
|
|
- }
|
|
|
- if (source === 'JINGAN') {
|
|
|
- theme = 'theme-jingan'
|
|
|
- }
|
|
|
- return { theme, componentName }
|
|
|
-}
|
|
|
-
|
|
|
-export function setToken() {
|
|
|
- window.token = `${window.location.href}`.replace(/.*wx\/(.*)\/.*/g, '$1');
|
|
|
-}
|
|
|
-
|
|
|
-// 如果用户的 vipcode 或者 userid 不存在提示用户返回首页重新进入
|
|
|
-export function backLbsHome() {
|
|
|
- const { theme } = getsTheCurrentTopic();
|
|
|
- const source = uni.getStorageSync('source')
|
|
|
- const dialog = Dialog.alert({
|
|
|
- title: '温馨提示',
|
|
|
- message: source === 'KIP' ? '当前网络异常,请返回首页重试' : '登录异常,请重新登录',
|
|
|
- confirmButtonColor: kipTheme[theme].primaryColor,
|
|
|
- beforeClose: async (action, done) => {
|
|
|
- try {
|
|
|
- if(window?.__wxjs_environment === 'miniprogram') {
|
|
|
- wx?.miniProgram?.reLaunch({
|
|
|
- url: source === 'KIP' ? '/pages/tabbar/home/home' : "/pages/package-parkingFee/parkingFeeWebViewLogin?needLogin=1" // 去 login 页面
|
|
|
- })
|
|
|
- }
|
|
|
- if (window.isAlipayClient) {
|
|
|
- my?.reLaunch({
|
|
|
- url: "/pages/package-parkingFee/parkingFeeWebViewLogin?needLogin=1" // 去 login 页面 1 去登录
|
|
|
- })
|
|
|
- }
|
|
|
- } catch (e) {
|
|
|
- console.log(e)
|
|
|
- }
|
|
|
- done()
|
|
|
- }
|
|
|
- });
|
|
|
-}
|
|
|
-
|
|
|
-export function toLogin() {
|
|
|
- if (window.__wxjs_environment === 'miniprogram') {
|
|
|
- wx.miniProgram.redirectTo({
|
|
|
- "url": source === 'KIP' ? "/pages/package-login/select?from=parkingFeeWebView" : "/pages/package-parkingFee/parkingFeeWebViewLogin?needLogin=1" // 去 login 页面 1 去登录
|
|
|
- })
|
|
|
- }
|
|
|
- if (window.isAlipayClient) {
|
|
|
- my?.reLaunch({
|
|
|
- url: "/pages/package-parkingFee/parkingFeeWebViewLogin?needLogin=1" // 去 login 页面 1 去登录
|
|
|
- })
|
|
|
- }
|
|
|
-}
|
|
|
export * from './common/localStorage.js'
|
|
|
export * from './common/function.js'
|
|
|
export * from './common/lbsIdCommon.js'
|
|
|
+export * from './common/contactManage.js'
|
|
|
+export * from './common/CrossPlatformManage.js'
|
|
|
export * from './alipayClient/index.js'
|