2020-08-13 08:12:57 +00:00
|
|
|
|
import { spread } from "@/api/user";
|
|
|
|
|
import Cache from "@/utils/cache";
|
|
|
|
|
|
|
|
|
|
/**
|
2020-09-15 08:13:25 +00:00
|
|
|
|
* 静默授权绑定上下级,使用在已经登录后扫描了别人的推广二维码
|
2020-08-13 08:12:57 +00:00
|
|
|
|
* @param {Object} puid
|
|
|
|
|
*/
|
2021-03-19 10:26:43 +00:00
|
|
|
|
export function silenceBindingSpread() {
|
|
|
|
|
|
|
|
|
|
|
2020-08-13 08:12:57 +00:00
|
|
|
|
//#ifdef H5
|
|
|
|
|
let puid = Cache.get('spread');
|
|
|
|
|
//#endif
|
2021-03-19 10:26:43 +00:00
|
|
|
|
|
2020-08-13 08:12:57 +00:00
|
|
|
|
//#ifdef MP
|
|
|
|
|
let puid = getApp().globalData.spid;
|
|
|
|
|
//#endif
|
2021-03-19 10:26:43 +00:00
|
|
|
|
|
2020-08-13 08:12:57 +00:00
|
|
|
|
puid = parseInt(puid);
|
2021-03-19 10:26:43 +00:00
|
|
|
|
if (Number.isNaN(puid)) {
|
2020-08-13 08:12:57 +00:00
|
|
|
|
puid = 0;
|
|
|
|
|
}
|
2021-03-19 10:26:43 +00:00
|
|
|
|
if (puid) {
|
|
|
|
|
spread(puid).then(res => {}).catch(res => {});
|
2020-09-15 08:13:25 +00:00
|
|
|
|
//#ifdef H5
|
2021-03-19 10:26:43 +00:00
|
|
|
|
Cache.clear('spread');
|
2020-09-15 08:13:25 +00:00
|
|
|
|
//#endif
|
2021-03-19 10:26:43 +00:00
|
|
|
|
|
2020-09-15 08:13:25 +00:00
|
|
|
|
//#ifdef MP
|
2021-03-19 10:26:43 +00:00
|
|
|
|
getApp().globalData.spid = 0;
|
|
|
|
|
getApp().globalData.code = 0;
|
2020-09-15 08:13:25 +00:00
|
|
|
|
//#endif
|
2021-03-19 10:26:43 +00:00
|
|
|
|
} else {
|
|
|
|
|
Cache.set('spread', 0);
|
2020-08-13 08:12:57 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function isWeixin() {
|
2021-03-19 10:26:43 +00:00
|
|
|
|
return navigator.userAgent.toLowerCase().indexOf("micromessenger") !== -1;
|
2020-08-13 08:12:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function parseQuery() {
|
2021-03-19 10:26:43 +00:00
|
|
|
|
const res = {};
|
|
|
|
|
|
|
|
|
|
const query = (location.href.split("?")[1] || "")
|
|
|
|
|
.trim()
|
|
|
|
|
.replace(/^(\?|#|&)/, "");
|
|
|
|
|
|
|
|
|
|
if (!query) {
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
query.split("&").forEach(param => {
|
|
|
|
|
const parts = param.replace(/\+/g, " ").split("=");
|
|
|
|
|
const key = decodeURIComponent(parts.shift());
|
|
|
|
|
const val = parts.length > 0 ? decodeURIComponent(parts.join("=")) : null;
|
|
|
|
|
|
|
|
|
|
if (res[key] === undefined) {
|
|
|
|
|
res[key] = val;
|
|
|
|
|
} else if (Array.isArray(res[key])) {
|
|
|
|
|
res[key].push(val);
|
|
|
|
|
} else {
|
|
|
|
|
res[key] = [res[key], val];
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return res;
|
2020-08-13 08:12:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// #ifdef H5
|
2021-03-19 10:26:43 +00:00
|
|
|
|
const VUE_APP_WS_URL = process.env.VUE_APP_WS_URL || `ws://${location.hostname}:20001`;
|
|
|
|
|
export {
|
|
|
|
|
VUE_APP_WS_URL
|
|
|
|
|
}
|
2020-08-13 08:12:57 +00:00
|
|
|
|
// #endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-03-19 10:26:43 +00:00
|
|
|
|
export default parseQuery;
|