|
@@ -22,7 +22,6 @@ export const mini_env = function (cb) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
// 获取用户信息
|
|
|
export const getUserInfo = () => {
|
|
|
return new Promise((resolve, reject) => {
|
|
@@ -48,17 +47,17 @@ export async function redirection() {
|
|
|
'/packageMaterial/pages/stock/index',
|
|
|
'/packageMaterial/pages/sale/index',
|
|
|
'/packageMaterial/pages/sale/index'
|
|
|
- ];
|
|
|
+ ]
|
|
|
const goMycon = [
|
|
|
'/packageMine/pages/collection',
|
|
|
'/packageMine/pages/profit/list',
|
|
|
'/packageMine/pages/salesProfit/index',
|
|
|
'/packageMine/pages/ranking/list',
|
|
|
- '/packageMine/pages/myWebsit',
|
|
|
- ];
|
|
|
+ '/packageMine/pages/myWebsit'
|
|
|
+ ]
|
|
|
var userInfo = await getUserInfo()
|
|
|
if (userInfo) {
|
|
|
- if (userInfo.type === "GENERAL") {
|
|
|
+ if (userInfo.type === 'GENERAL') {
|
|
|
if (goHome.find(url => !!~window.location.href.split('?')[0].indexOf(url))) {
|
|
|
uni.showModal({
|
|
|
title: '提示',
|
|
@@ -66,11 +65,11 @@ export async function redirection() {
|
|
|
showCancel: false,
|
|
|
success: function (res) {
|
|
|
if (res.confirm) {
|
|
|
- window.history.go(-(window.history.length - 1));
|
|
|
- window.location.href = `${process.env.VUE_APP_HREF}/pages/index/index?appid=${appid}`;
|
|
|
+ window.history.go(-(window.history.length - 1))
|
|
|
+ window.location.href = `${process.env.VUE_APP_HREF}/pages/index/index?appid=${appid}`
|
|
|
}
|
|
|
}
|
|
|
- });
|
|
|
+ })
|
|
|
return
|
|
|
}
|
|
|
if (goMycon.find(url => !!~window.location.href.split('?')[0].indexOf(url))) {
|
|
@@ -80,17 +79,15 @@ export async function redirection() {
|
|
|
showCancel: false,
|
|
|
success: function (res) {
|
|
|
if (res.confirm) {
|
|
|
- window.history.go(-(window.history.length - 1));
|
|
|
- window.location.href = `${process.env.VUE_APP_HREF}/pages/mine/index?appid=${appid}`;
|
|
|
+ window.history.go(-(window.history.length - 1))
|
|
|
+ window.location.href = `${process.env.VUE_APP_HREF}/pages/mine/index?appid=${appid}`
|
|
|
}
|
|
|
}
|
|
|
- });
|
|
|
+ })
|
|
|
return
|
|
|
}
|
|
|
} else if (userInfo.type === 'SERVICE') {
|
|
|
-
|
|
|
} else if (userInfo.type === 'WORKER') {
|
|
|
-
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -110,7 +107,7 @@ export const getQueryVariable = variable => {
|
|
|
var pair = vars[i].split('=')
|
|
|
// 如果第一个元素等于 传进来的参的话 就输出第二个元素
|
|
|
if (pair[0] == variable) {
|
|
|
- return pair[1] || ""
|
|
|
+ return pair[1] || ''
|
|
|
}
|
|
|
}
|
|
|
return undefined
|
|
@@ -118,27 +115,27 @@ export const getQueryVariable = variable => {
|
|
|
|
|
|
export function compareUrls(url1, url2) {
|
|
|
// 创建 URL 对象来解析地址
|
|
|
- const parsedUrl1 = new URL(url1);
|
|
|
- const parsedUrl2 = new URL(url2);
|
|
|
+ const parsedUrl1 = new URL(url1)
|
|
|
+ const parsedUrl2 = new URL(url2)
|
|
|
|
|
|
// 比较主要部分(不包括查询参数)
|
|
|
- const mainPartUrl1 = parsedUrl1.origin + parsedUrl1.pathname;
|
|
|
- const mainPartUrl2 = parsedUrl2.origin + parsedUrl2.pathname;
|
|
|
+ const mainPartUrl1 = parsedUrl1.origin + parsedUrl1.pathname
|
|
|
+ const mainPartUrl2 = parsedUrl2.origin + parsedUrl2.pathname
|
|
|
|
|
|
- return mainPartUrl1 === mainPartUrl2;
|
|
|
+ return mainPartUrl1 === mainPartUrl2
|
|
|
}
|
|
|
|
|
|
export function removePreviousHistory() {
|
|
|
// 获取当前页面的url
|
|
|
- const currentUrl = window.location.href;
|
|
|
- if (compareUrls(getStorage("CurrentHrefUrlAddress") || "", currentUrl)) {
|
|
|
- removeStorage("CurrentHrefUrlAddress")
|
|
|
+ const currentUrl = window.location.href
|
|
|
+ if (compareUrls(getStorage('CurrentHrefUrlAddress') || '', currentUrl)) {
|
|
|
+ removeStorage('CurrentHrefUrlAddress')
|
|
|
// 使用 history 对象的 go 方法跳转到上一个历史记录
|
|
|
- window.history.go(-1);
|
|
|
+ window.history.go(-1)
|
|
|
// 使用 history.replaceState
|
|
|
- window.history.replaceState(null, '', currentUrl);
|
|
|
+ window.history.replaceState(null, '', currentUrl)
|
|
|
// 刷新页面
|
|
|
- window.location.reload();
|
|
|
+ window.location.reload()
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -161,18 +158,18 @@ function setStore(data = {}) {
|
|
|
}
|
|
|
|
|
|
export function truePath() {
|
|
|
- var currentURL = window.location.href;
|
|
|
- var url = new URL(currentURL);
|
|
|
- var path = url.pathname;
|
|
|
+ var currentURL = window.location.href
|
|
|
+ var url = new URL(currentURL)
|
|
|
+ var path = url.pathname
|
|
|
var partToRemove = (function () {
|
|
|
- var hrefUrl = new URL(process.env.VUE_APP_HREF);
|
|
|
- if (hrefUrl.pathname && hrefUrl.pathname === "/") {
|
|
|
- return ""
|
|
|
+ var hrefUrl = new URL(process.env.VUE_APP_HREF)
|
|
|
+ if (hrefUrl.pathname && hrefUrl.pathname === '/') {
|
|
|
+ return ''
|
|
|
}
|
|
|
return url.pathname
|
|
|
- })();
|
|
|
+ })()
|
|
|
if (path.startsWith(partToRemove)) {
|
|
|
- path = path.slice(partToRemove.length);
|
|
|
+ path = path.slice(partToRemove.length)
|
|
|
}
|
|
|
|
|
|
return path
|
|
@@ -180,9 +177,9 @@ export function truePath() {
|
|
|
|
|
|
export function rompamUrl() {
|
|
|
// 获取当前页面的 URL
|
|
|
- var currentURL = window.location.href;
|
|
|
+ var currentURL = window.location.href
|
|
|
// 创建 URL 对象
|
|
|
- var url = new URL(currentURL);
|
|
|
+ var url = new URL(currentURL)
|
|
|
return url.origin + url.pathname
|
|
|
}
|
|
|
|
|
@@ -204,38 +201,42 @@ export function webLogin(bool = false) {
|
|
|
// 获取当前地址
|
|
|
var url = location.href
|
|
|
// 获取记录的时间
|
|
|
- const isAuthorizationTime = getStorage("isAuthorizationTime")
|
|
|
+ const isAuthorizationTime = getStorage('isAuthorizationTime')
|
|
|
// 获取历史code
|
|
|
- const previousCode = getStorage("previousCode")
|
|
|
+ const previousCode = getStorage('previousCode')
|
|
|
if (code) {
|
|
|
- url = removeUrlParams("code")
|
|
|
- url = removeUrlParams("state")
|
|
|
+ url = removeUrlParams('code')
|
|
|
+ url = removeUrlParams('state')
|
|
|
}
|
|
|
// 是否强制授权
|
|
|
- if (isAuthorization && (!isAuthorizationTime || (isAuthorizationTime < new Date().getTime()))) {
|
|
|
+ if (isAuthorization && (!isAuthorizationTime || isAuthorizationTime < new Date().getTime())) {
|
|
|
// 设置时间
|
|
|
- setStorage("isAuthorizationTime", new Date().getTime() + 2 * 60 * 60 * 1000)
|
|
|
+ setStorage('isAuthorizationTime', new Date().getTime() + 2 * 60 * 60 * 1000)
|
|
|
// 删除本地缓存
|
|
|
setStore()
|
|
|
- url = removeUrlParams("x-token")
|
|
|
+ url = removeUrlParams('x-token')
|
|
|
// 去获取授权
|
|
|
setTimeout(function () {
|
|
|
- window.location.href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${isEncoded(url)}&response_type=code&scope=snsapi_userinfo#wechat_redirect`
|
|
|
+ window.location.href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${isEncoded(
|
|
|
+ url
|
|
|
+ )}&response_type=code&scope=snsapi_userinfo#wechat_redirect`
|
|
|
}, 50)
|
|
|
} else if (bool) {
|
|
|
// 删除本地缓存
|
|
|
setStore()
|
|
|
// url = `${rompamUrl()}?appid=${appid}`
|
|
|
- url = removeUrlParams("x-token")
|
|
|
+ url = removeUrlParams('x-token')
|
|
|
// 去获取授权
|
|
|
setTimeout(function () {
|
|
|
- window.location.href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${isEncoded(url)}&response_type=code&scope=snsapi_userinfo#wechat_redirect`
|
|
|
+ window.location.href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${isEncoded(
|
|
|
+ url
|
|
|
+ )}&response_type=code&scope=snsapi_userinfo#wechat_redirect`
|
|
|
}, 50)
|
|
|
}
|
|
|
// 判断是否有token有则不需要授权执行
|
|
|
else if (code && code !== previousCode) {
|
|
|
// 设置时间
|
|
|
- setStorage("previousCode", code)
|
|
|
+ setStorage('previousCode', code)
|
|
|
// 有token表示授权回来则执行code静默登入
|
|
|
api
|
|
|
.post('/user/auth2', {
|
|
@@ -244,7 +245,8 @@ export function webLogin(bool = false) {
|
|
|
.then(async res => {
|
|
|
setStore(res.data)
|
|
|
resolve({})
|
|
|
- }).catch(reject)
|
|
|
+ })
|
|
|
+ .catch(reject)
|
|
|
} else {
|
|
|
resolve({})
|
|
|
}
|
|
@@ -785,80 +787,91 @@ export const selectionChange = async function () {
|
|
|
} catch (err) {
|
|
|
var doc = document.getElementsByClassName('uni-tabbar-bottom')
|
|
|
if (doc && doc.length) {
|
|
|
- if(!appModuleJsonGuding){
|
|
|
+ if (!appModuleJsonGuding) {
|
|
|
try {
|
|
|
- doc[0].innerHTML = ""
|
|
|
- var { appModuleJson } = await getUserInfo() || {}
|
|
|
- if(appModuleJson){
|
|
|
+ doc[0].innerHTML = ''
|
|
|
+ var { appModuleJson } = (await getUserInfo()) || {}
|
|
|
+ if (appModuleJson) {
|
|
|
appModuleJsonGuding = JSON.parse(appModuleJson)
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
appModuleJsonGuding = [
|
|
|
- {type:"home", name:"首页", sort:0,},
|
|
|
- {type:"order", name:"工单", sort:1,},
|
|
|
- {type:"shop", name:"商城", sort:2,},
|
|
|
- {type:"my", name:"我的", sort:3,}
|
|
|
+ { type: 'home', name: '首页', sort: 0 },
|
|
|
+ { type: 'order', name: '工单', sort: 1 },
|
|
|
+ { type: 'shop', name: '商城', sort: 2 },
|
|
|
+ { type: 'my', name: '我的', sort: 3 }
|
|
|
]
|
|
|
}
|
|
|
} catch (error) {
|
|
|
console.log(error)
|
|
|
}
|
|
|
}
|
|
|
- doc[0].innerHTML = (function(){
|
|
|
+ doc[0].innerHTML = (function () {
|
|
|
var tabs = {
|
|
|
- home(item){
|
|
|
+ home(item) {
|
|
|
return `<div class="uni-tabbar__item" onclick="(function(){navToPage({url: '/pages/index/index'+window.location.search})})()">
|
|
|
<div class="uni-tabbar__bd" style="height: 50px;">
|
|
|
<div class="uni-tabbar__icon" style="width: 24px; height: 24px;">
|
|
|
<img src="${process.env.VUE_APP_BASE_PATH}static/tabBar/icon_1${index == 0 ? '_cur' : ''}.png">
|
|
|
</div>
|
|
|
- <div class="uni-tabbar__label" style="color: ${index == 0 ? 'rgb(61, 143, 253)' : 'rgb(122, 126, 131)'}; font-size: 10px; line-height: normal; margin-top: 3px;">
|
|
|
- ${item.name}
|
|
|
+ <div class="uni-tabbar__label" style="color: ${
|
|
|
+ index == 0 ? 'rgb(61, 143, 253)' : 'rgb(122, 126, 131)'
|
|
|
+ }; font-size: 10px; line-height: normal; margin-top: 3px;">
|
|
|
+ ${item.name}
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>`
|
|
|
},
|
|
|
- order(item){
|
|
|
+ order(item) {
|
|
|
return `<div class="uni-tabbar__item" onclick="(function(){navToPage({url: '/pages/workorder/index'+window.location.search+'&type=0&isWb=0'})})()">
|
|
|
<div class="uni-tabbar__bd" style="height: 50px;">
|
|
|
<div class="uni-tabbar__icon" style="width: 24px; height: 24px;">
|
|
|
<img src="${process.env.VUE_APP_BASE_PATH}static/tabBar/icon_2${index == 1 ? '_cur' : ''}.png">
|
|
|
</div>
|
|
|
- <div class="uni-tabbar__label" style="color: ${index == 1 ? 'rgb(61, 143, 253)' : 'rgb(122, 126, 131)'}; font-size: 10px; line-height: normal; margin-top: 3px;">
|
|
|
- ${item.name}
|
|
|
+ <div class="uni-tabbar__label" style="color: ${
|
|
|
+ index == 1 ? 'rgb(61, 143, 253)' : 'rgb(122, 126, 131)'
|
|
|
+ }; font-size: 10px; line-height: normal; margin-top: 3px;">
|
|
|
+ ${item.name}
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>`
|
|
|
},
|
|
|
- shop(item){
|
|
|
+ shop(item) {
|
|
|
return `<div class="uni-tabbar__item" onclick="(function(){navToPage({url: '/pages/goods/index'+window.location.search})})()">
|
|
|
<div class="uni-tabbar__bd" style="height: 50px;">
|
|
|
<div class="uni-tabbar__icon" style="width: 24px; height: 24px;">
|
|
|
<img src="${process.env.VUE_APP_BASE_PATH}static/tabBar/icon_3${index == 2 ? '_cur' : ''}.png">
|
|
|
</div>
|
|
|
- <div class="uni-tabbar__label" style="color: ${index == 2 ? 'rgb(61, 143, 253)' : 'rgb(122, 126, 131)'}; font-size: 10px; line-height: normal; margin-top: 3px;">
|
|
|
- ${item.name}
|
|
|
+ <div class="uni-tabbar__label" style="color: ${
|
|
|
+ index == 2 ? 'rgb(61, 143, 253)' : 'rgb(122, 126, 131)'
|
|
|
+ }; font-size: 10px; line-height: normal; margin-top: 3px;">
|
|
|
+ ${item.name}
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>`
|
|
|
},
|
|
|
- my(item){
|
|
|
+ my(item) {
|
|
|
return `<div class="uni-tabbar__item" onclick="(function(){navToPage({url: '/pages/mine/index'+window.location.search})})()">
|
|
|
<div class="uni-tabbar__bd" style="height: 50px;">
|
|
|
<div class="uni-tabbar__icon" style="width: 24px; height: 24px;">
|
|
|
<img src="${process.env.VUE_APP_BASE_PATH}static/tabBar/icon_4${index == 3 ? '_cur' : ''}.png">
|
|
|
</div>
|
|
|
- <div class="uni-tabbar__label" style="color: ${index == 3 ? 'rgb(61, 143, 253)' : 'rgb(122, 126, 131)'}; font-size: 10px; line-height: normal; margin-top: 3px;">
|
|
|
- ${item.name}
|
|
|
+ <div class="uni-tabbar__label" style="color: ${
|
|
|
+ index == 3 ? 'rgb(61, 143, 253)' : 'rgb(122, 126, 131)'
|
|
|
+ }; font-size: 10px; line-height: normal; margin-top: 3px;">
|
|
|
+ ${item.name}
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>`
|
|
|
}
|
|
|
- };
|
|
|
+ }
|
|
|
return `<div class="uni-tabbar" style="background-color: rgb(255, 255, 255); backdrop-filter: none;">
|
|
|
<div class="uni-tabbar-border" style="background-color: rgba(0, 0, 0, 0.33);"></div>
|
|
|
- ${((appModuleJsonGuding||[]).sort((a, b) => a.sort - b.sort)).map(item=>{
|
|
|
- return tabs?.[item.type](item) || ""
|
|
|
- }).join('')}
|
|
|
+ ${(appModuleJsonGuding || [])
|
|
|
+ .sort((a, b) => a.sort - b.sort)
|
|
|
+ .map(item => {
|
|
|
+ return tabs?.[item.type](item) || ''
|
|
|
+ })
|
|
|
+ .join('')}
|
|
|
</div>
|
|
|
<div class="uni-placeholder" style="height: 50px;"></div>`
|
|
|
})()
|
|
@@ -991,10 +1004,10 @@ export const wxScanCode = function (scanType = ['barCode']) {
|
|
|
needResult: 1, // 默认为0,扫描结果由微信处理,1则直接返回扫描结果,
|
|
|
scanType,
|
|
|
success: res => {
|
|
|
- var result = res.resultStr // 当 needResult 为 1 时,扫码返回的结果
|
|
|
- var resultArr = result.split(',') // 扫描结果以逗号分割数组
|
|
|
- var codeVal = resultArr[resultArr.length - 1] // 获取数组最后一个元素,也就是最终的内容
|
|
|
- resolve(codeVal)
|
|
|
+ // var result = res.result // 当 needResult 为 1 时,扫码返回的结果
|
|
|
+ // var resultArr = result.split(',') // 扫描结果以逗号分割数组
|
|
|
+ // var codeVal = resultArr[resultArr.length - 1] // 获取数组最后一个元素,也就是最终的内容
|
|
|
+ resolve(res.result)
|
|
|
},
|
|
|
fail: res => {
|
|
|
reject('')
|
|
@@ -1012,7 +1025,9 @@ export const wxShare = function (options = {}) {
|
|
|
wx.updateAppMessageShareData({
|
|
|
title: title || `${userInfo.nickName}向你推荐了「${configInfo.minAppName}」`, // 分享标题
|
|
|
desc: desc || '点击查看', // 分享描述
|
|
|
- link: link || `${process.env.VUE_APP_HREF}/pages/index/index?appid=${appid}&serviceId=${userInfo.userId}&isAuthorization=1`, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
|
|
|
+ link:
|
|
|
+ link ||
|
|
|
+ `${process.env.VUE_APP_HREF}/pages/index/index?appid=${appid}&serviceId=${userInfo.userId}&isAuthorization=1`, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
|
|
|
imgUrl: imgUrl || `${configInfo.minLogo3}`, // 分享图标
|
|
|
success: function () {
|
|
|
// 设置成功
|
|
@@ -1024,7 +1039,9 @@ export const wxShare = function (options = {}) {
|
|
|
wx.updateTimelineShareData({
|
|
|
title: title || `${userInfo.nickName}向你推荐了「${configInfo.minAppName}」`, // 分享标题
|
|
|
desc: desc || '点击查看', // 分享描述
|
|
|
- link: link || `${process.env.VUE_APP_HREF}/pages/index/index?appid=${appid}&serviceId=${userInfo.userId}&isAuthorization=1`, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
|
|
|
+ link:
|
|
|
+ link ||
|
|
|
+ `${process.env.VUE_APP_HREF}/pages/index/index?appid=${appid}&serviceId=${userInfo.userId}&isAuthorization=1`, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
|
|
|
imgUrl: imgUrl || `${configInfo.minLogo3}`, // 分享图标
|
|
|
success: function () {
|
|
|
// 设置成功
|