diff --git a/components/Footer.vue b/components/Footer.vue
index cbb32ed..dc0d9c3 100644
--- a/components/Footer.vue
+++ b/components/Footer.vue
@@ -1,10 +1,8 @@
-
-
+
diff --git a/pages/user/PersonalData/index.vue b/pages/user/PersonalData/index.vue
index 71bcfd2..548259d 100644
--- a/pages/user/PersonalData/index.vue
+++ b/pages/user/PersonalData/index.vue
@@ -121,11 +121,6 @@ export default {
userIndex: 0
};
},
- watch: {
- $yroute(n) {
- if (n.name === "PersonalData") this.$store.dispatch("USERINFO", true);
- }
- },
computed: mapGetters(["userInfo"]),
mounted: function() {
this.avatar = this.userInfo.avatar;
diff --git a/pages/user/Recharge/index.vue b/pages/user/Recharge/index.vue
index 25406fa..9347f5c 100644
--- a/pages/user/Recharge/index.vue
+++ b/pages/user/Recharge/index.vue
@@ -63,14 +63,14 @@ export default {
icon: "none",
duration: 2000
});
- return
+ return;
} else if (price < 0.01) {
uni.showToast({
title: "转入金额不能低于0.01",
icon: "none",
duration: 2000
});
- return
+ return;
}
uni.showModal({
diff --git a/pages/user/User/index.vue b/pages/user/User/index.vue
index 38aa0ef..11396bf 100644
--- a/pages/user/User/index.vue
+++ b/pages/user/User/index.vue
@@ -1,157 +1,161 @@
-
diff --git a/pages/user/promotion/Poster/index.vue b/pages/user/promotion/Poster/index.vue
index 3ae20e3..fa702bb 100644
--- a/pages/user/promotion/Poster/index.vue
+++ b/pages/user/promotion/Poster/index.vue
@@ -73,23 +73,6 @@ export default {
);
},
downloadIamge: function(imgsrc, name) {
- // let image = new Image();
- // image.setAttribute("crossOrigin", "anonymous");
- // image.onload = function() {
- // // let canvas = document.createElement("canvas");
- // // canvas.width = image.width;
- // // canvas.height = image.height;
- // // let context = canvas.getContext("2d");
- // // context.drawImage(image, 0, 0, image.width, image.height);
- // // let url = canvas.toDataURL("image/png"); //得到图片的base64编码数据
- // // let a = document.createElement("a"); // 生成一个a元素
- // // let event = new MouseEvent("click"); // 创建一个单击事件
- // // a.download = name || "photo"; // 设置图片名称
- // // a.href = url; // 将生成的URL设置为a.href属性
- // // a.dispatchEvent(event); // 触发a的单击事件
- // };
- // image.src = imgsrc;
-
var that = this;
this.isDown = true;
var downloadUrl = imgsrc;
diff --git a/store/index.js b/store/index.js
index d0a2efc..4384ce8 100644
--- a/store/index.js
+++ b/store/index.js
@@ -12,15 +12,11 @@ const LOGIN_KEY = "login_status";
const vuexStore = new Vuex.Store({
state: {
- wxCode: null,
+ // 是否已经在授权页面
isAuthorizationPage: false,
+ // 是否授权
isAuthorization: false,
- footer: true,
- home: true,
- tabtarIndex: 0,
- homeActive: false,
token: store.get(LOGIN_KEY) || null,
- backgroundColor: "#fff",
userInfo: null
},
mutations: {
@@ -50,8 +46,9 @@ const vuexStore = new Vuex.Store({
store.set(LOGIN_KEY, token, expires_time);
},
LOGOUT(state) {
- state.token = undefined;
- store.remove(LOGIN_KEY);
+ state.token = null;
+ state.userInfo = null
+ store.clearAll()
},
BACKGROUND_COLOR(state, color) {
state.color = color;
@@ -66,10 +63,6 @@ const vuexStore = new Vuex.Store({
UPDATE_AUTHORIZATION(state, isAuthorization) {
state.isAuthorization = isAuthorization;
},
- UPDATE_WXCODE(state, wxCode) {
- console.log(wxCode, 'wxCode')
- state.wxCode = wxCode;
- }
},
actions: {
USERINFO({ state, commit }, force) {
@@ -85,31 +78,25 @@ const vuexStore = new Vuex.Store({
dialog.error("获取信息失败!");
});
},
+ changeLogin({ state, commit }, data, date) {
+ commit("LOGIN", data, date);
+ },
changeUserInfo({ state, commit }, user) {
commit("UPDATE_USERINFO", user.user);
},
- changeTabtar({ state, commit }, index) {
- commit("CHANGE_TABTAR", index);
+ changeAuthorizationPage({ state, commit }, index) {
+ commit("UPDATE_AUTHORIZATIONPAGE", index);
},
changeAuthorization({ state, commit }, index) {
commit("UPDATE_AUTHORIZATION", index);
},
- changeWxCode({ state, commit }, index) {
- commit("UPDATE_WXCODE", index);
- },
},
getters: {
- wxCode: state => state.wxCode,
isAuthorizationPage: state => state.isAuthorizationPage,
isAuthorization: state => state.isAuthorization,
- footer: state => state.footer,
- homeActive: state => state.homeActive,
- home: state => state.home,
token: state => state.token,
isLogin: state => !!state.token,
- backgroundColor: state => state.backgroundColor,
userInfo: state => state.userInfo || {},
- tabtarIndex: state => state.tabtarIndex
},
strict: debug
});
diff --git a/utils/index.js b/utils/index.js
index 121d048..7ce7820 100644
--- a/utils/index.js
+++ b/utils/index.js
@@ -97,7 +97,7 @@ export function getCurrentPageUrlWithArgs() {
// 复制到剪切板
export const copyClipboard = (data) => {
- wx.setClipboardData({
+ uni.setClipboardData({
data: data,
success: (res) => {
uni.showToast({
@@ -110,139 +110,209 @@ export const copyClipboard = (data) => {
}
-export const toAuthorization = (msg) => {
+export const replaceLogin = (msg) => {
uni.hideLoading();
uni.showToast({
title: msg,
icon: 'none',
duration: 2000
});
- console.log(222222222)
- replace({
- path: '/pages/user/Login/index',
- query: {
- redirect: `/${getCurrentPageUrl()}`,
- ...parseQuery()
- }
+ console.log(Vue.prototype.$deviceType)
+ // 这里代表已经失去登录状态以及401强制推出登录了
+ store.commit('LOGOUT')
+
+ if (Vue.prototype.$deviceType == 'Weixin') {
+ // 如果是微信小程序,跳转到授权页
+ replace({
+ path: '/pages/authorization/index',
+ query: {
+ redirect: `/${getCurrentPageUrl()}`,
+ ...parseQuery()
+ }
+ })
+ } else {
+ // 如果不是小程序跳转到登录页
+ replace({
+ path: '/pages/user/Login/index',
+ query: query || {
+ redirect: `/${getCurrentPageUrl()}`,
+ ...parseQuery()
+ }
+ })
+ }
+}
+
+export const getProvider = () => {
+ return new Promise((resolve, reject) => {
+ // 获取当前环境的服务商
+ uni.getProvider({
+ service: 'oauth',
+ success: function (res) {
+ console.log(`当前环境的服务商为 | ${res.provider}`)
+ // 此处可以排除h5
+ if (res.provider) {
+ resolve(res.provider[0])
+ }
+ },
+ fail() {
+ reject('获取环境服务商失败')
+ }
+ })
+ }).catch(error => {
+ console.log(error)
+ })
+
+}
+
+export const authorize = (authorizeStr) => {
+ return new Promise((resolve, reject) => {
+ uni.authorize({
+ scope: `scope.${authorizeStr}`,
+ success() {
+ resolve('获取授权成功')
+ },
+ fail() {
+ reject('获取授权失败')
+ }
+ })
+ }).catch(error => {
+ console.log(error)
})
}
export const login = (option) => {
console.log('调用登录')
return new Promise((resolve, reject) => {
- // 获取当前环境的服务商
- uni.getProvider({
- service: 'oauth',
- success: function(res) {
- console.log(res.provider)
- // 此处可以排除h5
- if (res.provider) {
- // 调用登录接口
- uni.login({
- provider: res.provider[0],
- success: function(loginRes) {
- // 微信登录
- console.log('获取code')
- let code = loginRes.code;
- store.commit("UPDATE_WXCODE", loginRes.code);
+ getProvider().then(provider => {
+ // 调用登录接口
+ uni.login({
+ provider: provider,
+ success: function (loginRes) {
+ // 微信登录
+ console.log(`获取code | ${loginRes.code}`)
+ let code = loginRes.code;
+ // 检查授权, 检查用户信息授权
+ authorize('userInfo').then(() => {
+ uni.getUserInfo({
+ provider: provider,
+ success: function (user) {
+ console.log(user)
+ console.log(`用户昵称为 | ${user.userInfo.nickName}`);
+ console.log(`当前的环境 | ${Vue.prototype.$deviceType}`)
+ if (Vue.prototype.$deviceType == 'Weixin') {
+ wxappAuth({
+ encryptedData: user.encryptedData,
+ iv: user.iv,
+ code: code,
+ spread: cookie.get("spread")
+ }).then(({
+ data
+ }) => {
+ console.log('登录成功')
+ console.log(data)
+ console.log('登录成功1')
- console.log(JSON.stringify(loginRes));
- // 检查授权, 检查用户信息授权
- uni.authorize({
- scope: 'scope.userInfo',
- success() {
- uni.getUserInfo({
- provider: res.provider[0],
- success: function(user) {
- console.log(user)
- console.log('用户昵称为:' + user.userInfo.nickName);
- if (Vue.prototype.$deviceType == 'Weixin') {
- wxappAuth({
- encryptedData: user.encryptedData,
- iv: user.iv,
- code: code,
- spread: cookie.get("spread")
- }).then(({
- data
- }) => {
- resolve(res.data)
- uni.hideLoading();
- store.commit("LOGIN", data.token, dayjs(data.expires_time));
- getUser().then(res => {
- store.dispatch('changeUserInfo', {
- user: res.data
- })
- });
- var pages = getCurrentPages() //获取加载的页面
- var currentPage = pages[pages.length - 1] //获取当前页面的对象
- let url = "/pages/home/index"
- let query = {}
- if (currentPage) {
- if (currentPage.route != 'pages/Loading/index' && currentPage.route !=
- 'pages/user/Login/index') {
- url = currentPage.route
- }
- if (currentPage.route == 'pages/user/Login/index') {
- const {
- redirect,
- ...querys
- } = currentPage.options
- url = redirect
- query = { ...querys
- }
- }
+ resolve(data)
+ console.log('登录成功3')
+
+ uni.hideLoading();
+ console.log('登录成功4')
+ store.commit("LOGIN", data.token, dayjs(data.expires_time));
+ console.log('登录成功5')
+
+ getUser().then(res => {
+ store.dispatch('changeUserInfo', {
+ user: res.data
+ })
+ console.log('登录成功6')
+ console.log(option)
+ // option && option.success ? option.success() : null
+ var pages = getCurrentPages() //获取加载的页面
+ console.log('登录成功7')
+
+ var currentPage = pages[pages.length - 1] //获取当前页面的对象
+ let url = "/pages/home/index"
+ let query = {}
+ console.log('登录成功8')
+ console.log(currentPage)
+
+ if (currentPage) {
+ // 获取到最后一个页面
+ if (
+ currentPage.route != 'pages/Loading/index'
+ &&
+ currentPage.route != 'pages/user/Login/index'
+ ) {
+ url = currentPage.route
+ }
+ if (currentPage.route == 'pages/authorization/index') {
+ const {
+ redirect,
+ ...querys
+ } = currentPage.options
+ url = redirect
+ query = {
+ ...querys
}
- switchTab({
- path: url,
- query
- });
- }).catch(error => {
- reject()
- option && option.fail ? option.fail() : toAuthorization('获取用户信息失败,请重试')
- });
+ }
}
+ console.log('登录成功9')
+ console.log({
+ path: url,
+ query
+ })
+ switchTab({
+ path: `${url}`,
+ query
+ });
+ })
-
- },
- fail() {
- // 获取用户信息失败
- reject()
- option && option.fail ? option.fail() : toAuthorization('获取用户信息失败,请重试')
- }
+ }).catch(error => {
+ reject()
+ console.log('微信登录失败')
+ console.log(error)
+ handleFail(option, '微信登录失败')
});
- },
- fail() {
- // 获取用户信息失败
- reject()
- option && option.fail ? option.fail() : toAuthorization('获取用户信息失败,请重试')
}
- })
- },
- fail() {
- // 调用登录接口失败
- reject()
- option && option.fail ? option.fail() : toAuthorization('获取用户信息失败,请重试')
- }
- });
+ },
+ fail() {
+ // 获取用户信息失败
+ reject()
+ handleFail(option, '获取用户信息失败')
+ }
+ });
+ }).catch(error => {
+ reject()
+ console.log(error)
+ handleFail(option, '拒绝授权')
+ })
+ },
+ fail() {
+ // 调用登录接口失败
+ reject()
+ handleFail(option, '登录失败')
}
- },
- fail() {
- reject()
- option && option.fail ? option.fail() : toAuthorization('获取用户信息失败,请重试')
- }
- });
-
+ });
+ }).catch(error => {
+ reject()
+ console.log(error)
+ handleFail(option, '获取环境服务商失败')
+ })
+ }).catch(error => {
+ console.log(error)
+ handleFail(option, '登录失败')
})
}
-
-
-
+const handleFail = (option, msg) => {
+ // 此处是处理登录失效的问题的
+ console.log(store)
+ option && option.fail ? option.fail() : replaceLogin('登录失败,请重新登录')
+}
export function parseUrl(location) {
if (typeof location === 'string') return location
-
const {
path,
query
@@ -272,53 +342,95 @@ export function parseRoute($mp) {
}
}
-export function push(location, complete, fail, success) {
+
+export const handleLoginStatus = (location, complete, fail, success) => {
+ console.log(location, '开始健全')
+ // 不登录可访问的页面
+ let page = [{
+ path: '/pages/Loading/index',
+ name: 'loading页面'
+ },
+ {
+ path: '/pages/home/index',
+ name: '首页'
+ },
+ {
+ path: '/pages/user/Login/index',
+ name: '登录页面'
+ },
+ {
+ path: '/pages/authorization/index',
+ name: '授权页面'
+ },
+ ]
+
+ // 是否可以访问
+ let isAuth = false
+
+ // 从 location 中获取当前url,location typeof string || object
let path = ''
if (typeof location === 'string') {
path = location
} else {
path = location.path
}
- console.log(path)
- if (path != '/pages/launch/index' || path != '/pages/loading/index' || path != '/pages/home/index' || path !=
- '/pages/loading/index') {
- if (!store.getters.userInfo.uid) {
- replace({
- path: '/pages/user/Login/index',
- query: {
- redirect: `/${getCurrentPageUrl()}`,
- ...parseQuery()
- }
- })
- return
- }
- }
- const url = parseUrl(location)
- const params = {
- url,
- complete,
- fail,
- success
+
+ console.log(store.getters.userInfo, '用户信息')
+ if (!store.getters.userInfo.uid) {
+ page.map((item) => {
+ console.log(item.path == path)
+ if (item.path == path) {
+ isAuth = true
+ }
+ })
+ } else {
+ isAuth = true
}
- if (location.isTab) {
- uni.switchTab(params)
- return
- }
- if (location.reLaunch) {
- uni.reLaunch(params)
- return
- }
- uni.navigateTo(params)
+ return new Promise((resolve, reject) => {
+ if (isAuth) {
+ console.log('有权限')
+ // 登录了有权限
+ console.log({
+ url: parseUrl(location),
+ complete,
+ fail,
+ success
+ })
+ resolve({
+ url: parseUrl(location),
+ complete,
+ fail,
+ success
+ })
+ } else {
+ console.log('无权限')
+ // 未登录没有权限
+ replaceLogin()
+ reject()
+ }
+ }).catch(error => {
+ console.log(error)
+ })
+}
+
+export function push(location, complete, fail, success) {
+ handleLoginStatus(location, complete, fail, success).then(params => {
+ console.log(params)
+ uni.navigateTo(params)
+ }).catch(error => {
+ // 没有权限
+
+ })
}
export function replace(location, complete, fail, success) {
- const url = parseUrl(location)
- uni.redirectTo({
- url,
- complete,
- fail,
- success
+ handleLoginStatus(location, complete, fail, success).then(params => {
+ console.log(params)
+ uni.redirectTo(params)
+ }).catch(error => {
+ // 没有权限
+
})
}
@@ -331,18 +443,18 @@ export function go(delta) {
export function back() {
uni.navigateBack({
delta: 1,
- success: function(e) {},
- fail: function(e) {}
+ success: function (e) { },
+ fail: function (e) { }
})
}
export function switchTab(location, complete, fail, success) {
- const url = parseUrl(location)
- uni.switchTab({
- url,
- complete,
- fail,
- success
+ console.log(location)
+ handleLoginStatus(location, complete, fail, success).then(params => {
+ console.log(params)
+ uni.switchTab(params)
+ }).catch(error => {
+ // 没有权限
})
}
@@ -383,20 +495,19 @@ export function handleQrCode() {
}
const getImageInfo = (images) => {
- console.log(images)
return new Promise((resolve, reject) => {
let imageAry = {}
images.map((item, index) => {
- wx.getImageInfo({
+ uni.getImageInfo({
src: item,
- fail: function(res) {
+ fail: function (res) {
imageAry[index] = null
console.log(res)
if (imageAry.length == images.length) {
resolve(imageAry)
}
},
- success: function(res) {
+ success: function (res) {
imageAry[index] = res
console.log(res)
if (Object.keys(imageAry).length == images.length) {
@@ -425,7 +536,7 @@ export const PosterCanvas = (store, successCallBack) => {
});
getImageInfo([store.image, store.code]).then(res => {
let contentHh = 48 * 1.3
- const ctx = wx.createCanvasContext('myCanvas');
+ const ctx = uni.createCanvasContext('myCanvas');
ctx.clearRect(0, 0, 0, 0);
const WIDTH = 747
const HEIGHT = 1326;
@@ -455,17 +566,17 @@ export const PosterCanvas = (store, successCallBack) => {
ctx.fillText('长按识别二维码立即购买', WIDTH / 2, 1167);
// ctx.drawImage(store.code, 199, 1064, 200, 200);
ctx.save();
- ctx.draw(true, function(oi) {
- wx.canvasToTempFilePath({
+ ctx.draw(true, function (oi) {
+ uni.canvasToTempFilePath({
canvasId: 'myCanvas',
fileType: 'png',
destWidth: WIDTH,
destHeight: HEIGHT,
- success: function(res) {
+ success: function (res) {
uni.hideLoading();
successCallBack && successCallBack(res.tempFilePath);
},
- fail: function(error) {
+ fail: function (error) {
console.log(error)
},
@@ -473,7 +584,7 @@ export const PosterCanvas = (store, successCallBack) => {
});
})
- // wx.getImageInfo({
+ // uni.getImageInfo({
// src: store.image,
// fail: function (res) {
// uni.showToast({
@@ -486,4 +597,4 @@ export const PosterCanvas = (store, successCallBack) => {
// }
// })
-}
+}
diff --git a/utils/store/cookie.js b/utils/store/cookie.js
index f887015..eeb6714 100644
--- a/utils/store/cookie.js
+++ b/utils/store/cookie.js
@@ -7,69 +7,36 @@ function get(key) {
if (!key || !_has(key)) {
return null;
}
- return wx.getStorageSync(key)
- // let regexpStr =
- // "(?:^|.*;\\s*)" +
- // escape(key).replace(/[-.+*]/g, "\\$&") +
- // "\\s*\\=\\s*((?:[^;](?!;))*[^;]?).*";
- // return JSON.parse(unescape(doc.cookie.replace(new RegExp(regexpStr), "$1")));
-
+ return uni.getStorageSync(key)
}
function all() {
- return wx.getStorageInfoSync()
- // let cookies = doc.cookie.split(/; ?/g),
- // data = {};
- // for (let i = cookies.length - 1; i >= 0; i--) {
- // if (!trim(cookies[i])) {
- // continue;
- // }
- // let kvp = cookies[i].split("=");
- // let key = unescape(kvp[0]);
- // data[key] = unescape(kvp[1]);
- // }
- // return data;
+ return uni.getStorageInfoSync()
}
function set(key, data, time) {
if (!key) {
return;
}
- // let expires = "Tue, 19 Jan 2038 03:14:07 GMT";
- // if (time) {
- // let date;
- // if (isType(time, "Date")) {
- // date = time;
- // } else {
- // date = new Date();
- // date.setTime(date.getTime() + time * 60000);
- // }
- // expires = date.toGMTString();
- // }
-
- // data = JSON.stringify(data);
- // doc.cookie =
- // escape(key) + "=" + escape(data) + "; expires=" + expires + "; path=/";
-
- wx.setStorageSync(key, data)
+ uni.setStorageSync(key, data)
}
function remove(key) {
if (!key || !_has(key)) {
return;
}
- wx.removeStorageSync(key)
+ uni.removeStorageSync(key)
}
function clearAll() {
- wx.clearStorage()
+ uni.clearStorage()
}
function _has(key) {
if (!key) {
return
}
- let value = wx.getStorageSync(key)
+ let value = uni.getStorageSync(key)
if (value) {
return true
}