From 3fa8054983fb4bf087e0a0d3f85c104f499b48fd Mon Sep 17 00:00:00 2001 From: gaoxs Date: Thu, 19 Mar 2020 16:17:26 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=B0=8F=E7=A8=8B=E5=BA=8F?= =?UTF-8?q?=E5=92=8Capp=E7=99=BB=E5=BD=95=E7=9A=84=E9=80=BB=E8=BE=91,?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=83=A8=E5=88=86=E9=A1=B5=E9=9D=A2=E6=A0=B7?= =?UTF-8?q?=E5=BC=8F=E9=94=99=E4=B9=B1=E7=9A=84=E9=97=AE=E9=A2=98,?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=B7=B3=E8=BD=AC=E9=A1=B5=E9=9D=A2=E5=90=8E?= =?UTF-8?q?=E9=83=A8=E5=88=86=E9=A1=B5=E9=9D=A2=E6=97=A0=E6=B3=95=E6=8E=A5?= =?UTF-8?q?=E5=8F=97url=E5=8F=82=E6=95=B0=E7=9A=84=E9=97=AE=E9=A2=98,?= =?UTF-8?q?=E4=BC=98=E5=8C=96app=E7=AB=AF=E7=9A=84=E5=85=BC=E5=AE=B9?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/ProductWindow.vue | 2 +- main.js | 35 +- pages/Loading/index.vue | 138 +++--- pages/activity/GoodsGroup/index.vue | 1 + pages/activity/GroupDetails/index.vue | 27 +- pages/authorization/index.vue | 2 +- pages/home/index.vue | 2 +- pages/user/Login/index.vue | 621 +++++++++++++------------- pages/user/Register/index.vue | 12 +- pages/user/User/index.vue | 12 +- store/index.js | 11 +- utils/index.js | 104 ++--- 12 files changed, 503 insertions(+), 464 deletions(-) diff --git a/components/ProductWindow.vue b/components/ProductWindow.vue index 240cb39..6aca291 100644 --- a/components/ProductWindow.vue +++ b/components/ProductWindow.vue @@ -58,7 +58,7 @@ export default { default: () => {} }, cartNum: { - type: String, + type: Number, default: () => 1 } }, diff --git a/main.js b/main.js index df3c7a4..6409666 100644 --- a/main.js +++ b/main.js @@ -33,8 +33,6 @@ Vue.prototype.$validator = function(rule) { return new schema(rule); }; -Vue.prototype.$dialog = dialog; - const CACHE_KEY = "clear_0.0.1"; if (!cookie.has(CACHE_KEY)) { @@ -54,6 +52,7 @@ Vue.mixin({ const { $mp } = this.$root + console.log($mp) this._route = parseRoute($mp) // this.$VUE_APP_RESOURCES_URL = VUE_APP_RESOURCES_URL; this._data.$VUE_APP_RESOURCES_URL = VUE_APP_RESOURCES_URL; @@ -78,25 +77,29 @@ Object.defineProperty(Vue.prototype, '$yroute', { Vue.prototype.$VUE_APP_RESOURCES_URL = VUE_APP_RESOURCES_URL Vue.prototype.$VUE_APP_API_URL = VUE_APP_API_URL - -// #ifdef APP-PLUS -// App平台编译的代码 -Vue.prototype.$deviceType = 'App' -Vue.prototype.$platform = uni.getSystemInfoSync().platform -// #endif -// #ifndef H5 -// H5编译的代码 + + +// #ifdef H5 +// H5编译的代码 Vue.prototype.$deviceType = 'H5' // #endif +// #ifdef APP-PLUS +// App平台编译的代码 +Vue.prototype.$deviceType = 'App' +Vue.prototype.$platform = uni.getSystemInfoSync().platform +// #endif + // #ifdef MP-WEIXIN // 微信小程序编译的代码 Vue.prototype.$deviceType = 'Weixin' -// #endif - -if(wx){ - Vue.prototype.$deviceType = 'Weixin' -} +// #endif + +console.log(wx,121212) +console.log(Vue.prototype.$deviceType) +// if(wx){ +// Vue.prototype.$deviceType = 'Weixin' +// } -app.$mount() +app.$mount() diff --git a/pages/Loading/index.vue b/pages/Loading/index.vue index 75a62eb..5532b08 100644 --- a/pages/Loading/index.vue +++ b/pages/Loading/index.vue @@ -1,77 +1,97 @@ diff --git a/pages/activity/GoodsGroup/index.vue b/pages/activity/GoodsGroup/index.vue index 93275b8..787429b 100644 --- a/pages/activity/GoodsGroup/index.vue +++ b/pages/activity/GoodsGroup/index.vue @@ -10,6 +10,7 @@ :key="combinationListIndex" @click="link(item.id)" > + {{item.id}} diff --git a/pages/activity/GroupDetails/index.vue b/pages/activity/GroupDetails/index.vue index aa3817a..f1a65b6 100644 --- a/pages/activity/GroupDetails/index.vue +++ b/pages/activity/GroupDetails/index.vue @@ -114,7 +114,7 @@ 单独购买 立即开团 - + - + login({ + username: account, + password, + spread: cookie.get("spread") + }) + .then(({ + data + }) => { + this.$store.commit("LOGIN", data.token, dayjs(data.expires_time)); + handleGetUserInfo() + // let replace=this.$yroute.query.replace + // if(replace){ + + // } + // this.$yrouter.replace({ + // path: this.$yroute.query.replace || '/pages/home/index' + // }); + }) + .catch(err => { + uni.showToast({ + title: err.msg || err.response.data.msg, + icon: "none", + duration: 2000 + }); + }); + } + } + }; + diff --git a/pages/user/Register/index.vue b/pages/user/Register/index.vue index 530f60d..fa6feea 100644 --- a/pages/user/Register/index.vue +++ b/pages/user/Register/index.vue @@ -10,17 +10,17 @@ - - 待付款 @@ -142,11 +142,11 @@ By@意象 - + > --> @@ -310,7 +310,7 @@ export default { }, onShow() { console.log(this.userInfo); - if (this.userInfo.uid) { + if (this.$store.getters.token) { this.User(); this.MenuUser(); this.isWeixin = isWeixin(); diff --git a/store/index.js b/store/index.js index 4384ce8..d509251 100644 --- a/store/index.js +++ b/store/index.js @@ -17,7 +17,7 @@ const vuexStore = new Vuex.Store({ // 是否授权 isAuthorization: false, token: store.get(LOGIN_KEY) || null, - userInfo: null + userInfo: store.get('userInfo') }, mutations: { SHOW_FOOTER(state) { @@ -81,8 +81,13 @@ const vuexStore = new Vuex.Store({ changeLogin({ state, commit }, data, date) { commit("LOGIN", data, date); }, - changeUserInfo({ state, commit }, user) { - commit("UPDATE_USERINFO", user.user); + setUserInfo({ state, commit }, user) { + commit("UPDATE_USERINFO", user); + if (user) { + store.set('userInfo', user) + } else { + store.set('userInfo', null) + } }, changeAuthorizationPage({ state, commit }, index) { commit("UPDATE_AUTHORIZATIONPAGE", index); diff --git a/utils/index.js b/utils/index.js index 7ce7820..de944f8 100644 --- a/utils/index.js +++ b/utils/index.js @@ -120,7 +120,7 @@ export const replaceLogin = (msg) => { console.log(Vue.prototype.$deviceType) // 这里代表已经失去登录状态以及401强制推出登录了 store.commit('LOGOUT') - + console.log(uni, 989) if (Vue.prototype.$deviceType == 'Weixin') { // 如果是微信小程序,跳转到授权页 replace({ @@ -132,9 +132,9 @@ export const replaceLogin = (msg) => { }) } else { // 如果不是小程序跳转到登录页 - replace({ + push({ path: '/pages/user/Login/index', - query: query || { + query: { redirect: `/${getCurrentPageUrl()}`, ...parseQuery() } @@ -220,52 +220,7 @@ export const login = (option) => { 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 - } - } - } - console.log('登录成功9') - console.log({ - path: url, - query - }) - switchTab({ - path: `${url}`, - query - }); - }) + handleGetUserInfo() }).catch(error => { reject() @@ -304,6 +259,51 @@ export const login = (option) => { }) } +export const handleGetUserInfo = () => { + getUser().then(res => { + console.log(res.data, '登录后的样式') + store.dispatch('setUserInfo', res.data) + console.log('登录成功6') + 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 + } + } + } + console.log('登录成功9') + console.log({ + path: url, + query + }) + switchTab({ + path: `${url}`, + query + }); + }) +} + const handleFail = (option, msg) => { // 此处是处理登录失效的问题的 @@ -332,11 +332,11 @@ export function parseRoute($mp) { return { path: `/${path}`, params: {}, - query: _$mp.query, + query: _$mp.query || _$mp.page.options, hash: '', fullPath: parseUrl({ path: `/${path}`, - query: _$mp.query + query: _$mp.query || _$mp.page.options }), name: path && path.replace(/\/(\w)/g, ($0, $1) => $1.toUpperCase()) } @@ -376,7 +376,7 @@ export const handleLoginStatus = (location, complete, fail, success) => { } console.log(store.getters.userInfo, '用户信息') - if (!store.getters.userInfo.uid) { + if (!store.getters.token) { page.map((item) => { console.log(item.path == path) if (item.path == path) {