From 4b6636ba6ff0e97dd1ac0cc61a826726d97667ef Mon Sep 17 00:00:00 2001 From: Gao xiaosong <704041637@qq.com> Date: Mon, 6 Apr 2020 22:08:40 +0800 Subject: [PATCH] add --- assets/css/style.less | 2 +- main.js | 32 +- pages/activity/GoodsSeckill/index.vue | 424 ++++++----- pages/authorization/index.vue | 329 +++++---- pages/home/index.vue | 548 +++++++------- pages/shop/ShoppingCart/index.vue | 980 +++++++++++++------------- store/index.js | 211 +++--- utils/index.js | 1 - utils/request.js | 2 +- 9 files changed, 1230 insertions(+), 1299 deletions(-) diff --git a/assets/css/style.less b/assets/css/style.less index 5c4efe8..4f05928 100644 --- a/assets/css/style.less +++ b/assets/css/style.less @@ -2135,7 +2135,7 @@ flex: 0 2.4*100rpx; .shoppingCart .footer .checkAll { font-size: 0.28*100rpx; color: #282828; - margin-left: 0.6*100rpx; + margin-left: 0.1*100rpx; } .shoppingCart .footer .money { diff --git a/main.js b/main.js index 671b2b0..77f891d 100644 --- a/main.js +++ b/main.js @@ -76,28 +76,32 @@ 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 H5 // H5编译的代码 -Vue.prototype.$deviceType = 'h5' +Vue.prototype.$deviceType = 'h5' +store.commit('UPDATE_DEVICETYPE','h5') // #endif // #ifdef APP-PLUS -// App平台编译的代码 -Vue.prototype.$deviceType = 'app' +// App平台编译的代码 +console.log('App平台编译的代码') +Vue.prototype.$deviceType = 'app' +store.commit('UPDATE_DEVICETYPE','app') Vue.prototype.$platform = uni.getSystemInfoSync().platform // #endif // #ifdef MP-WEIXIN -// 微信小程序编译的代码 -Vue.prototype.$deviceType = 'weixin' +// 微信小程序编译的代码 +console.log('微信小程序编译的代码') +Vue.prototype.$deviceType = 'weixin' +store.commit('UPDATE_DEVICETYPE','weixin') // #endif - -console.log(wx,121212) -console.log(Vue.prototype.$deviceType) -// if(wx){ -// Vue.prototype.$deviceType = 'weixin' -// } - + +// !!! ps 不建议在 template 中使用 $deviceType 去判断当前环境,很有可能出现 $deviceType 为 undefined 导致判断出错的问题,可以在 script 模块中正常使用 +// 建议通过 store 去获取 $deviceType 可以保证 template 中取到的值有效 +// import { mapState, mapMutations, mapActions } from 'vuex'; +// computed: { +// ...mapState(['$deviceType']) +// }, + app.$mount() diff --git a/pages/activity/GoodsSeckill/index.vue b/pages/activity/GoodsSeckill/index.vue index 77f91a0..7cb0176 100644 --- a/pages/activity/GoodsSeckill/index.vue +++ b/pages/activity/GoodsSeckill/index.vue @@ -1,223 +1,201 @@ - - - + + + diff --git a/pages/authorization/index.vue b/pages/authorization/index.vue index f823cab..7064644 100644 --- a/pages/authorization/index.vue +++ b/pages/authorization/index.vue @@ -1,214 +1,209 @@ diff --git a/pages/home/index.vue b/pages/home/index.vue index 7d8b7c1..730a67d 100644 --- a/pages/home/index.vue +++ b/pages/home/index.vue @@ -1,313 +1,269 @@ + diff --git a/pages/shop/ShoppingCart/index.vue b/pages/shop/ShoppingCart/index.vue index 5114bda..07cde0b 100644 --- a/pages/shop/ShoppingCart/index.vue +++ b/pages/shop/ShoppingCart/index.vue @@ -1,135 +1,110 @@ + diff --git a/store/index.js b/store/index.js index d509251..bba8473 100644 --- a/store/index.js +++ b/store/index.js @@ -5,105 +5,126 @@ Vue.use(Vuex); const debug = process.env.NODE_ENV !== "production"; import store from "@/utils/store/cookie"; -import { getUserInfo } from "@/api/user"; +import { + getUserInfo +} from "@/api/user"; import dialog from "@/utils/dialog"; const LOGIN_KEY = "login_status"; const vuexStore = new Vuex.Store({ - state: { - // 是否已经在授权页面 - isAuthorizationPage: false, - // 是否授权 - isAuthorization: false, - token: store.get(LOGIN_KEY) || null, - userInfo: store.get('userInfo') - }, - mutations: { - SHOW_FOOTER(state) { - state.footer = true; - }, - HIDE_FOOTER(state) { - state.footer = false; - }, - SHOW_HOME(state) { - state.home = true; - }, - HIDE_HOME(state) { - state.home = false; - }, - OPEN_HOME(state) { - state.homeActive = true; - }, - CLOSE_HOME(state) { - state.homeActive = false; - }, - CHANGE_TABTAR(state, index) { - state.tabtarIndex = index; - }, - LOGIN(state, token, expires_time) { - state.token = token; - store.set(LOGIN_KEY, token, expires_time); - }, - LOGOUT(state) { - state.token = null; - state.userInfo = null - store.clearAll() - }, - BACKGROUND_COLOR(state, color) { - state.color = color; - // document.body.style.backgroundColor = color; - }, - UPDATE_USERINFO(state, userInfo) { - state.userInfo = userInfo; - }, - UPDATE_AUTHORIZATIONPAGE(state, isAuthorizationPage) { - state.isAuthorizationPage = isAuthorizationPage; - }, - UPDATE_AUTHORIZATION(state, isAuthorization) { - state.isAuthorization = isAuthorization; - }, - }, - actions: { - USERINFO({ state, commit }, force) { - if (state.userInfo !== null && !force) - return Promise.resolve(state.userInfo); - else - return new Promise(reslove => { - getUserInfo().then(res => { - commit("UPDATE_USERINFO", res.data); - reslove(res.data); - }); - }).catch(() => { - dialog.error("获取信息失败!"); - }); - }, - changeLogin({ state, commit }, data, date) { - commit("LOGIN", data, date); - }, - 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); - }, - changeAuthorization({ state, commit }, index) { - commit("UPDATE_AUTHORIZATION", index); - }, - }, - getters: { - isAuthorizationPage: state => state.isAuthorizationPage, - isAuthorization: state => state.isAuthorization, - token: state => state.token, - isLogin: state => !!state.token, - userInfo: state => state.userInfo || {}, - }, - strict: debug + state: { + // 是否已经在授权页面 + isAuthorizationPage: false, + // 是否授权 + isAuthorization: false, + token: store.get(LOGIN_KEY) || null, + userInfo: store.get('userInfo'), + $deviceType: null, + }, + mutations: { + SHOW_FOOTER(state) { + state.footer = true; + }, + HIDE_FOOTER(state) { + state.footer = false; + }, + SHOW_HOME(state) { + state.home = true; + }, + HIDE_HOME(state) { + state.home = false; + }, + OPEN_HOME(state) { + state.homeActive = true; + }, + CLOSE_HOME(state) { + state.homeActive = false; + }, + CHANGE_TABTAR(state, index) { + state.tabtarIndex = index; + }, + LOGIN(state, token, expires_time) { + state.token = token; + store.set(LOGIN_KEY, token, expires_time); + }, + LOGOUT(state) { + state.token = null; + state.userInfo = null + store.clearAll() + }, + BACKGROUND_COLOR(state, color) { + state.color = color; + // document.body.style.backgroundColor = color; + }, + UPDATE_USERINFO(state, userInfo) { + state.userInfo = userInfo; + }, + UPDATE_AUTHORIZATIONPAGE(state, isAuthorizationPage) { + state.isAuthorizationPage = isAuthorizationPage; + }, + UPDATE_AUTHORIZATION(state, isAuthorization) { + state.isAuthorization = isAuthorization; + }, + UPDATE_DEVICETYPE(state, $deviceType) { + state.$deviceType = $deviceType; + }, + }, + actions: { + USERINFO({ + state, + commit + }, force) { + if (state.userInfo !== null && !force) + return Promise.resolve(state.userInfo); + else + return new Promise(reslove => { + getUserInfo().then(res => { + commit("UPDATE_USERINFO", res.data); + reslove(res.data); + }); + }).catch(() => { + dialog.error("获取信息失败!"); + }); + }, + changeLogin({ + state, + commit + }, data, date) { + commit("LOGIN", data, date); + }, + 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); + }, + changeAuthorization({ + state, + commit + }, index) { + commit("UPDATE_AUTHORIZATION", index); + }, + }, + getters: { + isAuthorizationPage: state => state.isAuthorizationPage, + isAuthorization: state => state.isAuthorization, + token: state => state.token, + isLogin: state => !!state.token, + userInfo: state => state.userInfo || {}, + }, + strict: debug }); -export default vuexStore +export default vuexStore diff --git a/utils/index.js b/utils/index.js index f919897..b2beca1 100644 --- a/utils/index.js +++ b/utils/index.js @@ -117,7 +117,6 @@ export const replaceLogin = (msg) => { icon: 'none', duration: 2000 }); - console.log(Vue.prototype.$deviceType) // 这里代表已经失去登录状态以及401强制推出登录了 store.commit('LOGOUT') console.log(uni, 989) diff --git a/utils/request.js b/utils/request.js index 6bb0b15..bde4257 100644 --- a/utils/request.js +++ b/utils/request.js @@ -45,7 +45,7 @@ function baseRequest(options) { ...option }).then(res => { console.log(res) - console.log(url,params,data, ...option) + // console.log(url,params,data, ...option) const data = res.data || {}; if (res.status !== 200) return Promise.reject({ msg: "请求失败", res, data });