|
|
@ -119,7 +119,6 @@ export const replaceLogin = (msg) => { |
|
|
|
}); |
|
|
|
}); |
|
|
|
// 这里代表已经失去登录状态以及401强制推出登录了
|
|
|
|
// 这里代表已经失去登录状态以及401强制推出登录了
|
|
|
|
store.commit('LOGOUT') |
|
|
|
store.commit('LOGOUT') |
|
|
|
console.log(uni, 989) |
|
|
|
|
|
|
|
if (Vue.prototype.$deviceType == 'weixin') { |
|
|
|
if (Vue.prototype.$deviceType == 'weixin') { |
|
|
|
// 如果是微信小程序,跳转到授权页
|
|
|
|
// 如果是微信小程序,跳转到授权页
|
|
|
|
login({ |
|
|
|
login({ |
|
|
@ -152,7 +151,6 @@ export const getProvider = () => { |
|
|
|
uni.getProvider({ |
|
|
|
uni.getProvider({ |
|
|
|
service: 'oauth', |
|
|
|
service: 'oauth', |
|
|
|
success: function (res) { |
|
|
|
success: function (res) { |
|
|
|
console.log(`当前环境的服务商为 | ${res.provider}`) |
|
|
|
|
|
|
|
// 此处可以排除h5
|
|
|
|
// 此处可以排除h5
|
|
|
|
if (res.provider) { |
|
|
|
if (res.provider) { |
|
|
|
resolve(res.provider[0]) |
|
|
|
resolve(res.provider[0]) |
|
|
@ -185,7 +183,6 @@ export const authorize = (authorizeStr) => { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export const login = (option) => { |
|
|
|
export const login = (option) => { |
|
|
|
console.log('调用登录') |
|
|
|
|
|
|
|
return new Promise((resolve, reject) => { |
|
|
|
return new Promise((resolve, reject) => { |
|
|
|
getProvider().then(provider => { |
|
|
|
getProvider().then(provider => { |
|
|
|
// 调用登录接口
|
|
|
|
// 调用登录接口
|
|
|
@ -193,16 +190,12 @@ export const login = (option) => { |
|
|
|
provider: provider, |
|
|
|
provider: provider, |
|
|
|
success: function (loginRes) { |
|
|
|
success: function (loginRes) { |
|
|
|
// 微信登录
|
|
|
|
// 微信登录
|
|
|
|
console.log(`获取code | ${loginRes.code}`) |
|
|
|
|
|
|
|
let code = loginRes.code; |
|
|
|
let code = loginRes.code; |
|
|
|
// 检查授权, 检查用户信息授权
|
|
|
|
// 检查授权, 检查用户信息授权
|
|
|
|
authorize('userInfo').then(() => { |
|
|
|
authorize('userInfo').then(() => { |
|
|
|
uni.getUserInfo({ |
|
|
|
uni.getUserInfo({ |
|
|
|
provider: provider, |
|
|
|
provider: provider, |
|
|
|
success: function (user) { |
|
|
|
success: function (user) { |
|
|
|
console.log(user) |
|
|
|
|
|
|
|
console.log(`用户昵称为 | ${user.userInfo.nickName}`); |
|
|
|
|
|
|
|
console.log(`当前的环境 | ${Vue.prototype.$deviceType}`) |
|
|
|
|
|
|
|
if (Vue.prototype.$deviceType == 'weixin') { |
|
|
|
if (Vue.prototype.$deviceType == 'weixin') { |
|
|
|
wxappAuth({ |
|
|
|
wxappAuth({ |
|
|
|
encryptedData: user.encryptedData, |
|
|
|
encryptedData: user.encryptedData, |
|
|
@ -212,23 +205,14 @@ export const login = (option) => { |
|
|
|
}).then(({ |
|
|
|
}).then(({ |
|
|
|
data |
|
|
|
data |
|
|
|
}) => { |
|
|
|
}) => { |
|
|
|
console.log('登录成功') |
|
|
|
|
|
|
|
console.log(data) |
|
|
|
|
|
|
|
console.log('登录成功1') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
resolve(data) |
|
|
|
resolve(data) |
|
|
|
console.log('登录成功3') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uni.hideLoading(); |
|
|
|
uni.hideLoading(); |
|
|
|
console.log('登录成功4') |
|
|
|
|
|
|
|
store.commit("LOGIN", data.token, dayjs(data.expires_time)); |
|
|
|
store.commit("LOGIN", data.token, dayjs(data.expires_time)); |
|
|
|
console.log('登录成功5') |
|
|
|
|
|
|
|
console.log(store) |
|
|
|
console.log(store) |
|
|
|
handleGetUserInfo() |
|
|
|
handleGetUserInfo() |
|
|
|
|
|
|
|
|
|
|
|
}).catch(error => { |
|
|
|
}).catch(error => { |
|
|
|
reject() |
|
|
|
reject() |
|
|
|
console.log('微信登录失败') |
|
|
|
|
|
|
|
console.log(error) |
|
|
|
console.log(error) |
|
|
|
handleFail(option, '微信登录失败') |
|
|
|
handleFail(option, '微信登录失败') |
|
|
|
}); |
|
|
|
}); |
|
|
@ -264,19 +248,13 @@ export const login = (option) => { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export const handleGetUserInfo = () => { |
|
|
|
export const handleGetUserInfo = () => { |
|
|
|
console.log('登录后请求用户信息') |
|
|
|
|
|
|
|
getUser().then(res => { |
|
|
|
getUser().then(res => { |
|
|
|
console.log(res.data, '登录后的样式') |
|
|
|
|
|
|
|
store.dispatch('setUserInfo', res.data) |
|
|
|
store.dispatch('setUserInfo', res.data) |
|
|
|
console.log('登录成功6') |
|
|
|
|
|
|
|
var pages = getCurrentPages() //获取加载的页面
|
|
|
|
var pages = getCurrentPages() //获取加载的页面
|
|
|
|
console.log('登录成功7') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var currentPage = pages[pages.length - 1] //获取当前页面的对象
|
|
|
|
var currentPage = pages[pages.length - 1] //获取当前页面的对象
|
|
|
|
let url = "/pages/home/index" |
|
|
|
let url = "/pages/home/index" |
|
|
|
let query = {} |
|
|
|
let query = {} |
|
|
|
console.log('登录成功8') |
|
|
|
|
|
|
|
console.log(currentPage) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (currentPage) { |
|
|
|
if (currentPage) { |
|
|
|
// 获取到最后一个页面
|
|
|
|
// 获取到最后一个页面
|
|
|
@ -297,11 +275,6 @@ export const handleGetUserInfo = () => { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
console.log('登录成功9') |
|
|
|
|
|
|
|
console.log({ |
|
|
|
|
|
|
|
path: url, |
|
|
|
|
|
|
|
query |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
if (url == '/pages/home/index' || url == '/pages/shop/GoodsClass/index' || url == '/pages/shop/ShoppingCart/index' || url == '/pages/user/User/index') { |
|
|
|
if (url == '/pages/home/index' || url == '/pages/shop/GoodsClass/index' || url == '/pages/shop/ShoppingCart/index' || url == '/pages/user/User/index') { |
|
|
|
switchTab({ |
|
|
|
switchTab({ |
|
|
|
path: `${url}`, |
|
|
|
path: `${url}`, |
|
|
@ -363,7 +336,6 @@ export function auth() { |
|
|
|
* userInfo只是用来限时用户信息,作用并不是很大 |
|
|
|
* userInfo只是用来限时用户信息,作用并不是很大 |
|
|
|
* ps:只需要判断 token 是否存在即可 |
|
|
|
* ps:只需要判断 token 是否存在即可 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
console.log(cookie.get('login_status'), 'token') |
|
|
|
|
|
|
|
if (cookie.get('login_status')) { |
|
|
|
if (cookie.get('login_status')) { |
|
|
|
return true |
|
|
|
return true |
|
|
|
} |
|
|
|
} |
|
|
@ -372,7 +344,6 @@ export function auth() { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const handleLoginStatus = (location, complete, fail, success) => { |
|
|
|
export const handleLoginStatus = (location, complete, fail, success) => { |
|
|
|
console.log(location, '开始检验权限') |
|
|
|
|
|
|
|
// 不登录可访问的页面
|
|
|
|
// 不登录可访问的页面
|
|
|
|
let page = [{ |
|
|
|
let page = [{ |
|
|
|
path: '/pages/Loading/index', |
|
|
|
path: '/pages/Loading/index', |
|
|
@ -405,7 +376,6 @@ export const handleLoginStatus = (location, complete, fail, success) => { |
|
|
|
|
|
|
|
|
|
|
|
if (!auth()) { |
|
|
|
if (!auth()) { |
|
|
|
page.map((item) => { |
|
|
|
page.map((item) => { |
|
|
|
console.log(item.path == path) |
|
|
|
|
|
|
|
if (item.path == path) { |
|
|
|
if (item.path == path) { |
|
|
|
isAuth = true |
|
|
|
isAuth = true |
|
|
|
} |
|
|
|
} |
|
|
@ -416,14 +386,7 @@ export const handleLoginStatus = (location, complete, fail, success) => { |
|
|
|
|
|
|
|
|
|
|
|
return new Promise((resolve, reject) => { |
|
|
|
return new Promise((resolve, reject) => { |
|
|
|
if (isAuth) { |
|
|
|
if (isAuth) { |
|
|
|
console.log('有权限') |
|
|
|
|
|
|
|
// 登录了有权限
|
|
|
|
// 登录了有权限
|
|
|
|
console.log({ |
|
|
|
|
|
|
|
url: parseUrl(location), |
|
|
|
|
|
|
|
complete, |
|
|
|
|
|
|
|
fail, |
|
|
|
|
|
|
|
success |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
resolve({ |
|
|
|
resolve({ |
|
|
|
url: parseUrl(location), |
|
|
|
url: parseUrl(location), |
|
|
|
complete, |
|
|
|
complete, |
|
|
@ -431,7 +394,6 @@ export const handleLoginStatus = (location, complete, fail, success) => { |
|
|
|
success |
|
|
|
success |
|
|
|
}) |
|
|
|
}) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
console.log('无权限') |
|
|
|
|
|
|
|
// 未登录没有权限
|
|
|
|
// 未登录没有权限
|
|
|
|
replaceLogin() |
|
|
|
replaceLogin() |
|
|
|
reject() |
|
|
|
reject() |
|
|
@ -443,7 +405,6 @@ export const handleLoginStatus = (location, complete, fail, success) => { |
|
|
|
|
|
|
|
|
|
|
|
export function push(location, complete, fail, success) { |
|
|
|
export function push(location, complete, fail, success) { |
|
|
|
handleLoginStatus(location, complete, fail, success).then(params => { |
|
|
|
handleLoginStatus(location, complete, fail, success).then(params => { |
|
|
|
console.log(params) |
|
|
|
|
|
|
|
uni.navigateTo(params) |
|
|
|
uni.navigateTo(params) |
|
|
|
}).catch(error => { |
|
|
|
}).catch(error => { |
|
|
|
// 没有权限
|
|
|
|
// 没有权限
|
|
|
@ -453,7 +414,6 @@ export function push(location, complete, fail, success) { |
|
|
|
|
|
|
|
|
|
|
|
export function replace(location, complete, fail, success) { |
|
|
|
export function replace(location, complete, fail, success) { |
|
|
|
handleLoginStatus(location, complete, fail, success).then(params => { |
|
|
|
handleLoginStatus(location, complete, fail, success).then(params => { |
|
|
|
console.log(params) |
|
|
|
|
|
|
|
uni.redirectTo(params) |
|
|
|
uni.redirectTo(params) |
|
|
|
}).catch(error => { |
|
|
|
}).catch(error => { |
|
|
|
// 没有权限
|
|
|
|
// 没有权限
|
|
|
@ -476,9 +436,7 @@ export function back() { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function switchTab(location, complete, fail, success) { |
|
|
|
export function switchTab(location, complete, fail, success) { |
|
|
|
console.log(location) |
|
|
|
|
|
|
|
handleLoginStatus(location, complete, fail, success).then(params => { |
|
|
|
handleLoginStatus(location, complete, fail, success).then(params => { |
|
|
|
console.log(params) |
|
|
|
|
|
|
|
uni.switchTab(params) |
|
|
|
uni.switchTab(params) |
|
|
|
}).catch(error => { |
|
|
|
}).catch(error => { |
|
|
|
// 没有权限
|
|
|
|
// 没有权限
|
|
|
@ -529,14 +487,12 @@ const getImageInfo = (images) => { |
|
|
|
src: item, |
|
|
|
src: item, |
|
|
|
fail: function (res) { |
|
|
|
fail: function (res) { |
|
|
|
imageAry[index] = null |
|
|
|
imageAry[index] = null |
|
|
|
console.log(res) |
|
|
|
|
|
|
|
if (imageAry.length == images.length) { |
|
|
|
if (imageAry.length == images.length) { |
|
|
|
resolve(imageAry) |
|
|
|
resolve(imageAry) |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
success: function (res) { |
|
|
|
success: function (res) { |
|
|
|
imageAry[index] = res |
|
|
|
imageAry[index] = res |
|
|
|
console.log(res) |
|
|
|
|
|
|
|
if (Object.keys(imageAry).length == images.length) { |
|
|
|
if (Object.keys(imageAry).length == images.length) { |
|
|
|
resolve(imageAry) |
|
|
|
resolve(imageAry) |
|
|
|
} |
|
|
|
} |
|
|
@ -562,7 +518,6 @@ export const PosterCanvas = (store, successCallBack) => { |
|
|
|
mask: true |
|
|
|
mask: true |
|
|
|
}); |
|
|
|
}); |
|
|
|
getImageInfo([store.image, store.code]).then(res => { |
|
|
|
getImageInfo([store.image, store.code]).then(res => { |
|
|
|
console.log(res) |
|
|
|
|
|
|
|
let contentHh = 48 * 1.3 |
|
|
|
let contentHh = 48 * 1.3 |
|
|
|
const ctx = uni.createCanvasContext('myCanvas') |
|
|
|
const ctx = uni.createCanvasContext('myCanvas') |
|
|
|
ctx.clearRect(0, 0, 0, 0); |
|
|
|
ctx.clearRect(0, 0, 0, 0); |
|
|
@ -591,7 +546,6 @@ export const PosterCanvas = (store, successCallBack) => { |
|
|
|
ctx.setTextAlign('center') |
|
|
|
ctx.setTextAlign('center') |
|
|
|
ctx.setFontSize(22); |
|
|
|
ctx.setFontSize(22); |
|
|
|
ctx.setFillStyle('#333333'); |
|
|
|
ctx.setFillStyle('#333333'); |
|
|
|
console.log('长按识别二维码立即购买') |
|
|
|
|
|
|
|
ctx.fillText('长按识别二维码立即购买', WIDTH / 2, 1167); |
|
|
|
ctx.fillText('长按识别二维码立即购买', WIDTH / 2, 1167); |
|
|
|
ctx.save(); |
|
|
|
ctx.save(); |
|
|
|
ctx.draw(true, () => { |
|
|
|
ctx.draw(true, () => { |
|
|
|