diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..95cfff78 --- /dev/null +++ b/.gitignore @@ -0,0 +1,24 @@ +.DS_Store +node_modules +/dist + +# local env files +.env.local +.env.*.local + +# Log files +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +# Editor directories and files +.idea +.vscode +*.suo +*.ntvs* +*.njsproj +*.sln +*.sw? +build.sh +.idea +unpackage \ No newline at end of file diff --git a/.hbuilderx/launch.json b/.hbuilderx/launch.json new file mode 100644 index 00000000..501e01c8 --- /dev/null +++ b/.hbuilderx/launch.json @@ -0,0 +1,11 @@ +{ // launch.json 配置了启动调试时相关设置,configurations下节点名称可为 app-plus/h5/mp-weixin/mp-baidu/mp-alipay/mp-qq/mp-toutiao/mp-360/ + // launchtype项可配置值为local或remote, local代表前端连本地云函数,remote代表前端连云端云函数 + "version": "0.0", + "configurations": [{ + "type": "uniCloud", + "default": { + "launchtype": "remote" + } + } + ] +} diff --git a/App.vue b/App.vue index bd076f53..8497b2a6 100644 --- a/App.vue +++ b/App.vue @@ -1,13 +1,8 @@ - diff --git a/components/couponListWindow/index.vue b/components/couponListWindow/index.vue index 0d7d3792..a7fa2cf7 100644 --- a/components/couponListWindow/index.vue +++ b/components/couponListWindow/index.vue @@ -5,7 +5,7 @@ - {{item.money}} + {{item.money?Number(item.money):''}} 满{{item.minPrice}}元可用 diff --git a/components/couponWindow/index.vue b/components/couponWindow/index.vue index b0428035..d30efa09 100644 --- a/components/couponWindow/index.vue +++ b/components/couponWindow/index.vue @@ -3,7 +3,7 @@ - {{item.money}} + {{ item.money?Number(item.money):'' }} 购物买{{item.minPrice}}减{{item.money}} 领取后{{item.day}}天内可用 diff --git a/components/login_mobile/index.vue b/components/login_mobile/index.vue new file mode 100644 index 00000000..b78d26a6 --- /dev/null +++ b/components/login_mobile/index.vue @@ -0,0 +1,239 @@ + + + + + diff --git a/components/login_mobile/routine_phone.vue b/components/login_mobile/routine_phone.vue new file mode 100644 index 00000000..4d5b8800 --- /dev/null +++ b/components/login_mobile/routine_phone.vue @@ -0,0 +1,163 @@ + + + + diff --git a/components/tabNav.vue b/components/tabNav.vue index 6ba2d8e2..0518488d 100644 --- a/components/tabNav.vue +++ b/components/tabNav.vue @@ -83,7 +83,7 @@ index:index } this.parentEmit(obj) - // this.$parent.currentTab = index //设置swiper的第几页 + this.$parent.currentTab = index //设置swiper的第几页 }, // 导航子类点击 childTab(tabClick,index){ diff --git a/libs/login.js b/libs/login.js index 0a47d335..3979b9a6 100644 --- a/libs/login.js +++ b/libs/login.js @@ -1,5 +1,6 @@ import store from "../store"; import Cache from '../utils/cache'; +import { Debounce } from '@/utils/validate.js' // #ifdef H5 || APP-PLUS import { isWeixin } from "../utils"; import auth from './wechat'; @@ -10,31 +11,74 @@ import { LOGIN_STATUS, USER_INFO, EXPIRES_TIME, STATE_R_KEY} from './../config/c function prePage(){ let pages = getCurrentPages(); let prePage = pages[pages.length - 1]; + // #ifndef APP-PLUS return prePage.route; + // #endif + // #ifdef APP-PLUS + return prePage.$page.fullPath; + // #endif } -export function toLogin(push, pathLogin) { +export const toLogin = Debounce(_toLogin,800) + +export function _toLogin(push, pathLogin) { store.commit("LOGOUT"); let path = prePage(); // #ifdef H5 - path = location.href; + // path = location.href; + path = location.pathname + location.search; // #endif if(!pathLogin) pathLogin = '/page/users/login/index' Cache.set('login_back_url',path); - // #ifdef H5 || APP-PLUS + // #ifdef H5 if (isWeixin()) { - auth.oAuth(); - } else { - if (path !== pathLogin) { - push ? uni.navigateTo({ - url:'/pages/users/login/index' - }) : uni.reLaunch({ - url: '/pages/users/login/index' - }); + // auth.oAuth(); + let urlData = location.pathname + location.search + if (urlData.indexOf('?') !== -1) { + urlData += '&go_longin=1'; + } else { + urlData += '?go_longin=1'; } + console.log('ppppp',Cache.has('snsapiKey')) + if (Cache.has('snsapiKey')) { + uni.navigateTo({ + url: '/pages/users/wechat_login/index', + }); + } + // if (!Cache.has('snsapiKey')) { + + // auth.oAuth('snsapi_base', urlData); + // } else { + // uni.navigateTo({ + // url: '/pages/users/wechat_login/index', + // }); + // } + } else { + uni.navigateTo({ + url: '/pages/users/login/index' + }) + // if (path !== pathLogin) { + // push ? uni.navigateTo({ + // url:'/pages/users/login/index' + // }) : uni.reLaunch({ + // url: '/pages/users/login/index' + // }); + // } } // #endif + + // #ifdef MP + uni.navigateTo({ + url: '/pages/users/wechat_login/index' + }) + // #endif + + // #ifdef APP-PLUS + uni.navigateTo({ + url: '/pages/users/login/index' + }) + // #endif } diff --git a/libs/routine.js b/libs/routine.js index 6845f375..17a1b36a 100644 --- a/libs/routine.js +++ b/libs/routine.js @@ -3,7 +3,6 @@ import { checkLogin } from './login'; import { login } from '../api/public'; import Cache from '../utils/cache'; import { STATE_R_KEY, USER_INFO, EXPIRES_TIME, LOGIN_STATUS} from './../config/cache'; - class Routine { @@ -65,9 +64,6 @@ class Routine async getCode(){ let provider = await this.getProvider(); return new Promise((resolve,reject)=>{ - if(Cache.has(STATE_R_KEY)){ - return resolve(Cache.get(STATE_R_KEY)); - } uni.login({ provider:provider, success(res) { @@ -122,14 +118,18 @@ class Routine authUserInfo(code,data) { + console.log('code:',code); + console.log('data:',data); return new Promise((resolve, reject)=>{ login(code,data).then(res=>{ - // let time = res.data.expiresTime - Cache.time(); - store.commit('UPDATE_USERINFO', res.data.user); - store.commit('LOGIN', {token:res.data.token}); - store.commit('SETUID', res.data.user.uid); - // Cache.set(EXPIRES_TIME,res.data.expiresTime,time); - Cache.set(USER_INFO,res.data.user); + if(res.data.type==='login'){ + // let time = res.data.expiresTime - Cache.time(); + store.commit('UPDATE_USERINFO', res.data.user); + store.commit('LOGIN', {token:res.data.token}); + store.commit('SETUID', res.data.user.uid); + // Cache.set(EXPIRES_TIME,res.data.expiresTime,time); + Cache.set(USER_INFO,res.data.user); + } return resolve(res); }).catch(res=>{ return reject(res); diff --git a/libs/wechat.js b/libs/wechat.js index 6f31182c..9c802d11 100644 --- a/libs/wechat.js +++ b/libs/wechat.js @@ -153,12 +153,37 @@ class AuthWechat { /** * 自动去授权 */ - oAuth() { - if (uni.getStorageSync(WX_AUTH) && store.state.app.token) return; + oAuth(snsapiBase,url) { + if (uni.getStorageSync(WX_AUTH) && store.state.app.token && snsapiBase == 'snsapi_base') return; const { code } = parseQuery(); - if (!code) return this.toAuth(); + if (!code || code == uni.getStorageSync('snsapiCode')){ + return this.toAuth(snsapiBase,url); + }else{ + if(Cache.has('snsapiKey')) + return this.auth(code).catch(error=>{ + uni.showToast({ + title:error, + icon:'none' + }) + }) + } + // if (uni.getStorageSync(WX_AUTH) && store.state.app.token) return; + // const { + // code + // } = parseQuery(); + // if (!code){ + // return this.toAuth(snsapiBase,url); + // }else{ + // if(Cache.has('snsapiKey')) + // return this.auth(code).catch(error=>{ + // uni.showToast({ + // title:error, + // icon:'none' + // }) + // }) + // } } clearAuthStatus() { @@ -188,7 +213,7 @@ class AuthWechat { Cache.clear(STATE_KEY); // Cache.clear('spread'); loginType && Cache.clear(LOGINTYPE); - resolve(); + resolve(data); }) .catch(reject); }); @@ -198,32 +223,42 @@ class AuthWechat { * 获取跳转授权后的地址 * @param {Object} appId */ - getAuthUrl(appId) { - const redirect_uri = encodeURIComponent( - `${location.origin}/pages/auth/index?back_url=` + - encodeURIComponent( - encodeURIComponent( - uni.getStorageSync(BACK_URL) ? - uni.getStorageSync(BACK_URL) : - location.pathname + location.search - ) - ) - ); - uni.removeStorageSync(BACK_URL); - const state = encodeURIComponent( - ("" + Math.random()).split(".")[1] + "authorizestate" - ); - uni.setStorageSync(STATE_KEY, state); - return `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appId}&redirect_uri=${redirect_uri}&response_type=code&scope=snsapi_userinfo&state=${state}#wechat_redirect`; - } - + getAuthUrl(appId,snsapiBase,backUrl) { + let url = `${location.origin}${backUrl}` + if(url.indexOf('?') == -1){ + url = url+'?' + }else{ + url = url+'&' + } + const redirect_uri = encodeURIComponent( + `${url}scope=${snsapiBase}&back_url=` + + encodeURIComponent( + encodeURIComponent( + uni.getStorageSync(BACK_URL) ? + uni.getStorageSync(BACK_URL) : + location.pathname + location.search + ) + ) + ); + uni.removeStorageSync(BACK_URL); + const state = encodeURIComponent( + ("" + Math.random()).split(".")[1] + "authorizestate" + ); + uni.setStorageSync(STATE_KEY, state); + if(snsapiBase==='snsapi_base'){ + return `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appId}&redirect_uri=${redirect_uri}&response_type=code&scope=snsapi_base&state=${state}#wechat_redirect`; + }else{ + return `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appId}&redirect_uri=${redirect_uri}&response_type=code&scope=snsapi_userinfo&state=${state}#wechat_redirect`; + } + } + /** * 跳转自动登录 */ - toAuth() { + toAuth(snsapiBase,backUrl) { let that = this; this.wechat().then(wx => { - location.href = this.getAuthUrl(that.initConfig.appId); + location.href = this.getAuthUrl(that.initConfig.appId,snsapiBase,backUrl); }) } diff --git a/main.js b/main.js index 9ba62985..3b64b321 100644 --- a/main.js +++ b/main.js @@ -46,7 +46,7 @@ if (vconsole !== undefined && vconsole === md5Crmeb) { let vConsole = new VConsole(); } -Auth.isWeixin() && Auth.oAuth(); +// Auth.isWeixin() && Auth.oAuth(); // #endif diff --git a/pages.json b/pages.json index 5efad8e9..6a65473b 100644 --- a/pages.json +++ b/pages.json @@ -360,6 +360,13 @@ "style": { "navigationBarTitleText": "商品评价" } + }, + { + "path": "wechat_login/index", + "style": { + "navigationBarTitleText": "账户登录", + "navigationStyle": "custom" + } } ] }, diff --git a/pages/activity/goods_bargain/index.vue b/pages/activity/goods_bargain/index.vue index 4fe12efb..3bb8071a 100644 --- a/pages/activity/goods_bargain/index.vue +++ b/pages/activity/goods_bargain/index.vue @@ -1,7 +1,9 @@ - + + + + + diff --git a/pages/order_addcart/order_addcart.vue b/pages/order_addcart/order_addcart.vue index 5e956dfe..1fa71c85 100644 --- a/pages/order_addcart/order_addcart.vue +++ b/pages/order_addcart/order_addcart.vue @@ -113,13 +113,19 @@ - + - - diff --git a/pages/order_addcart/order_addcart11.vue b/pages/order_addcart/order_addcart11.vue deleted file mode 100644 index 09974a7f..00000000 --- a/pages/order_addcart/order_addcart11.vue +++ /dev/null @@ -1,1083 +0,0 @@ - - - - - \ No newline at end of file diff --git a/pages/order_details/index.vue b/pages/order_details/index.vue index 5ecf3040..8bf99718 100644 --- a/pages/order_details/index.vue +++ b/pages/order_details/index.vue @@ -226,7 +226,7 @@ - + @@ -658,7 +658,8 @@ isAuto: false, //没有授权的不会自动授权 isShowAuth: false, //是否隐藏授权 id: 0, //订单id - uniId: '' + uniId: '', + utils: this.$util, }; }, computed: mapGetters(['isLogin', 'chatUrl']), @@ -676,13 +677,7 @@ this.getOrderInfo(); this.getUserInfo(); } else { - // #ifdef H5 || APP-PLUS toLogin(); - // #endif - // #ifdef MP - this.isAuto = true; - this.$set(this, 'isShowAuth', true); - // #endif } }, onHide: function() { @@ -835,7 +830,6 @@ newCartInfo.push(item.info); }); that.$set(that, 'cartInfo', newCartInfo); - console.log(that.cartInfo) if (res.data.refundStatus != 0) { that.isGoodsReturn = true; }; @@ -961,7 +955,7 @@ */ delOrder: function() { let that = this; - orderDel(this.order_id).then(res => { + orderDel(this.id).then(res => { return that.$util.Tips({ title: '删除成功', icon: 'success' diff --git a/pages/order_pay_status/index.vue b/pages/order_pay_status/index.vue index 116c094c..a142d0d0 100644 --- a/pages/order_pay_status/index.vue +++ b/pages/order_pay_status/index.vue @@ -47,7 +47,7 @@ - + @@ -88,6 +88,16 @@ }; }, computed: mapGetters(['isLogin']), + watch:{ + isLogin:{ + handler:function(newV,oldV){ + if(newV){ + this.getOrderPayInfo(); + } + }, + deep:true + } + }, onLoad: function(options) { if (!options.order_id) return this.$util.Tips({ title: '缺少参数无法查看订单支付状态' @@ -101,13 +111,7 @@ if (this.isLogin) { this.getOrderPayInfo(); } else { - // #ifdef H5 || APP-PLUS toLogin(); - // #endif - // #ifdef MP - this.isAuto = true; - this.$set(this, 'isShowAuth', true); - // #endif } }, methods: { diff --git a/pages/user/index.vue b/pages/user/index.vue index c020ea17..98c4b77f 100644 --- a/pages/user/index.vue +++ b/pages/user/index.vue @@ -12,6 +12,11 @@ 请点击授权 + + + 请点击授权 + + {{userInfo.nickname}} @@ -20,7 +25,7 @@ - ID:{{userInfo.uid}} + {{userInfo.phone}} @@ -71,9 +76,7 @@ indicator-color="rgba(255,255,255,0.6)" indicator-active-color="#fff"> - - - + @@ -92,7 +95,7 @@ - + 联系客服 @@ -101,7 +104,7 @@