From 16213c0f85aa3ac8317797bf4a05fd12940e16d3 Mon Sep 17 00:00:00 2001 From: zhangwei <1504152376@qq.com> Date: 星期三, 05 三月 2025 17:29:42 +0800 Subject: [PATCH] - --- src/pages/login/index.vue | 580 +++++++++------------------------------------------------- 1 files changed, 90 insertions(+), 490 deletions(-) diff --git a/src/pages/login/index.vue b/src/pages/login/index.vue index 8e484aa..75ada2c 100644 --- a/src/pages/login/index.vue +++ b/src/pages/login/index.vue @@ -1,183 +1,63 @@ <template> <view> <view class="wrap"> - <image src="@/static/logo.png" mode="widthFix" class="tip_img"></image> <view class="login_tip"> 涓轰簡鎻愪緵鏇翠紭璐ㄧ殑鏈嶅姟锛岄渶瑕佽幏鍙栨偍鐨勫ご鍍忓拰鏄电О銆� </view> <view class="login_btn"> <!-- #ifdef MP-WEIXIN || MP-QQ || MP-BAIDU --> - <button v-if="canIUseGetUserProfile" type="primary" class="uni-tip-button" @click="login">鎺堟潈骞剁櫥褰�</button> - <button v-else type="primary" open-type="getUserInfo" @getuserinfo="login" - class="uni-tip-button">鎺堟潈骞剁櫥褰�</button> - <view class="no_login" @click="back"> + <button v-if="canIUseGetPhoneNumber" class="uni-tip-button" + style="backgroundColor:#fece01;borderColor:#fece01" @click="mobileAuthLogin">鎺堟潈骞剁櫥褰�</button> + <button style="backgroundColor:#fece01;borderColor:#fece01" v-else open-type="getPhoneNumber" + @getphonenumber="getPhoneNumber" class="uni-tip-button">鎺堟潈骞剁櫥褰�</button> + <view class="no_login" @click="back" style="color:#fece01;borderColor:#fece01"> 鏆備笉鎺堟潈 </view> <!-- #endif --> <checkbox-group @change="changeAgree"> <view class="regisiter-agreement"> - <label> - <checkbox value="1" :checked="isChecked" color="#35A6FF" style="transform:scale(0.7)" /> - + <checkbox value="1" :checked="isChecked" color="#fece01" style="transform:scale(0.7)" /> 宸查槄璇诲苟鍚屾剰浠ヤ笅鍗忚 - <text class="color-base-text" @click.stop="openPopup(1)">銆婄敤鎴锋湇鍔″崗璁��</text>鍜� <text - class="color-base-text" @click.stop="openPopup(2)">銆婇殣绉佹斂绛栥��</text> + <text class="color-base-text" @click.stop="toArticle(1)">銆婄敤鎴锋湇鍔″崗璁��</text> + <!-- 鍜� <text class="color-base-text" @click.stop="toArticle(2)">銆婇殣绉佹斂绛栥��</text> --> </label> </view> </checkbox-group> </view> - <!-- <view class="mobile_login" @click="toMobileLogin"> - 鍚屾剰骞惰緭鍏ユ墜鏈哄彿鐧诲綍 - </view> --> - <!-- <view class="agreement_wrap"> - <view class="agree_item"> - <view class="item_icon" @click="isChecked = !isChecked"> - <image v-if="!isChecked" :src="$util.img('upload/img/iconCheck.png')" mode="aspectFit" - class="item_select_img"></image> - <image v-else :src="$util.img('upload/img/publish-selected.png')" mode="aspectFit" - class="item_select_img"></image> - </view> - <view class="item_content"> - 棣栨鐧诲綍鑷姩娉ㄥ唽杩愭弧婊″強璐ц溅甯处鍙凤紝涓斿凡闃呰骞跺悓鎰�<text class="agreement">銆婄敤鎴锋湇鍔″崗璁��</text><text - class="agreement">銆婁釜浜轰俊鎭繚鎶ゆ斂绛栥��</text><text class="agreement">銆婅处鍙峰叧鑱斿崗璁��</text> - </view> - </view> - <view class="agree_item"> - <view class="item_icon" @click="isCheckedSan = !isCheckedSan"> - <image v-if="!isCheckedSan" :src="$util.img('upload/img/iconCheck.png')" mode="aspectFit" - class="item_select_img"></image> - <image v-else :src="$util.img('upload/img/publish-selected.png')" mode="aspectFit" - class="item_select_img"></image> - </view> - <view class="item_content"> - 宸查槄璇诲苟鍚屾剰<text class="agreement">銆婄涓夋柟鍚堜綔娓呭崟銆�</text> - </view> - </view> - </view> --> </view> - <u-popup ref="popup" type="center"> - <view class="bind-wrap"> - <!-- #ifdef MP-WEIXIN || MP-QQ || MP-BAIDU --> - <view class="heard">鎻愮ず</view> - <view class="bind-tips">涓轰簡鏂逛究鎮ㄦ帴鏀堕�氱煡娑堟伅锛岄渶瑕佹偍瀹屾垚鎺堟潈</view> - <view class="auth-login ns-btn-default-all color-base-bg" @click="toWeb"> - 鍘绘巿鏉� - </view> - <!-- <button open-type="getPhoneNumber" class="auth-login ns-btn-default-all color-base-bg" - @getphonenumber="mobileAuthLogin"><text>鐐瑰嚮缁戝畾鎵嬫満鍙风爜</text></button> --> - <!-- #endif --> - </view> - </u-popup> - <u-popup ref="bindMobile"> - <view class="bind-wrap"> - <!-- #ifdef MP-WEIXIN || MP-QQ || MP-BAIDU --> - <view class="heard">鎻愮ず</view> - <view class="bind-tips">涓轰簡鏂逛究鑱旂郴鎮紝闇�瑕佺粦瀹氭偍鐨勬墜鏈哄彿鐮�</view> - <button open-type="getPhoneNumber" class="auth-login ns-btn-default-all color-base-bg" - @getphonenumber="mobileAuthLogin"><text>鐐瑰嚮缁戝畾鎵嬫満鍙风爜</text></button> - <!-- #endif --> - </view> - </u-popup> </view> </template> <script> + import { + mapActions, + mapGetters, + mapMutations + } from 'vuex' export default { data() { return { isChecked: false, - isCheckedSan: false, - canIUseGetUserProfile: false + canIUseGetPhoneNumber: false }; }, created() { // #ifdef MP-WEIXIN - if (wx.getUserProfile) this.canIUseGetUserProfile = true; + if (uni.getStorageSync('queryPhoneNumber')) this.canIUseGetPhoneNumber = true; // #endif }, onShow() { - if (uni.getStorageSync('wx_openid_set') && uni.getStorageSync('wx_openid_set') == 1) { - uni.showLoading({ - title: '鍔犺浇涓�', - mask: true - }) - this.$api.sendRequest({ - url: '/api.php/user/info', - data: { - uid: uni.getStorageSync('authInfo').id - }, - success: res => { - if (res.code == 1) { - // uni.hideLoading() - // if (res.data.openid) this.authInfo.weapp_openid = res.data.openid; - // if (res.data.unionid) this.authInfo.wx_unionid = res.data.unionid; - if (res.data.wx_openid) { - this.$util.showToast({ - title: "鐧诲綍鎴愬姛", - icon: "success" - }) - uni.setStorage({ - key: 'uid', - data: res.data.id, - success: () => { - uni.removeStorageSync('wx_openid_set'); - uni.removeStorageSync('source_member'); - uni.removeStorageSync('authInfo'); - this.$api.sendRequest({ - url: "/api.php/user/is_perfect", - data: { - uid: res.data.id, - }, - success: res => { - if (res.code == 1) { - console.log(res) - uni.setStorageSync( - 'is_perfect_user', '1') - } else { - uni.setStorageSync( - 'is_perfect_user', res.code - ) - } - }, - fail: res => { - this.$util.showToast({ - title: "鎺ュ彛閿欒" - }); - } - }); - // this.$store.dispatch('getCartNumber'); - setTimeout(() => { - this.$util.redirectTo( - '/pages/index/index', {}, - 'tabbar') - }, 1000) - } - }); - } else { - this.$util.showToast({ - title: '鎺堟潈澶辫触' - }); - } - if (this.$refs.loadingCover) this.$refs.loadingCover.hide(); - } else { - uni.removeStorageSync('uid') - this.$forceUpdate() - this.$util.showToast({ - title: res.msg - }); - if (this.$refs.loadingCover) this.$refs.loadingCover.hide(); - } - } - }) - } }, methods: { - openPopup(type) { - this.$util.redirectTo('/otherPages/member/webView/webView', { - link: type + ...mapActions([ + 'getUserInfo' + ]), + toArticle(type) { + uni.navigateTo({ + url: '/pages/article/article' }) }, changeAgree(e) { @@ -188,164 +68,93 @@ this.isChecked = false } }, - toWeb() { - if (!this.isChecked) { - return this.$util.showToast({ - title: "璇峰厛鍚屾剰鍗忚" - }) - } - uni.setStorageSync('wx_openid_set', 1) - this.$util.redirectTo('/otherPages/member/webView/webView', { - uid: uni.getStorageSync('authInfo').id - }) - }, back() { - uni.navigateBack() + uni.switchTab({ + url: '/pages/index/index' + }); }, - toMobileLogin() { + getPhoneNumber(e) { if (!this.isChecked) { - return this.$util.showToast({ + return this.$common.showToast({ title: "璇峰厛鍚屾剰鍗忚" }) } - this.$util.redirectTo('/otherPages/member/mobileLogin/mobileLogin') + if (e.detail.errMsg == 'getPhoneNumber:ok') { + this.$db.set('queryPhoneNumber', 'getPhoneNumber:ok'); + uni.login({ + provider: 'weixin', + timeout: 3000, + success: res => { + let obj = { + bindgetphonenumber: e.detail.code, + jsCode: res.code + } + this.$api.CreateUser(obj).then(result => { + if (result.code == 1) { + this.$db.set('userToken', result.data.accessToken); + this.getUserInfo() + this.$util.redirectTo( + '/pages/index/index', {}, + 'tabbar') + } else { + this.$util.showToast({ + title: result.msg + }); + } + }).catch((err) => { + console.log(err, 'uni.loginerr') + }) + }, + }) + } + console.log(e) }, mobileAuthLogin(e) { - console.log(e) if (!this.isChecked) { - return this.$util.showToast({ + return this.$common.showToast({ title: "璇峰厛鍚屾剰鍗忚" }) } - // return - if (e.detail.errMsg == 'getPhoneNumber:ok') { - let authData = uni.getStorageSync('authInfo'); - console.log(authData) - var data = { - code: e.detail.code, - uid: authData.id - // iv: e.detail.iv, - // encryptedData: e.detail.encryptedData - }; - console.log(e) - // if (Object.keys(authData).length) { - // Object.assign(data, authData); - // } - // if (authData.avatarUrl) data.headimg = authData.avatarUrl; - // if (authData.nickName) data.nickname = authData.nickName; - // if (uni.getStorageSync('source_member')) data.source_member = uni.getStorageSync('source_member'); - - if (this.isSub) return; - this.isSub = true; - - this.$api.sendRequest({ - url: '/api.php/login/binding_mobile', - data, - success: res => { - if (res.code == 1) { - console.log(res) - - if (res.data.wx_openid) { - this.$util.showToast({ - title: "鐧诲綍鎴愬姛", - icon: "success" - }) - uni.setStorage({ - key: 'uid', - data: res.data.id, - success: () => { - uni.removeStorageSync('wx_openid_set'); - uni.removeStorageSync('source_member'); - uni.removeStorageSync('authInfo'); - this.$api.sendRequest({ - url: "/api.php/user/is_perfect", - data: { - uid: res.data.id, - }, - success: res => { - if (res.code == 1) { - console.log(res) - uni.setStorageSync( - 'is_perfect_user', '1') - } else { - uni.setStorageSync( - 'is_perfect_user', res - .code) - } - }, - fail: res => { - this.$util.showToast({ - title: "鎺ュ彛閿欒" - }); - } - }); - // this.$store.dispatch('getCartNumber'); - setTimeout(() => { - this.$util.redirectTo( - '/pages/index/index', {}, - 'tabbar') - }, 1000) - } - }); - } else { - this.$refs.bindMobile.close() - // uni.setStorageSync('wx_openid_set',1) - this.$refs.popup.open() - } - - // this.$store.commit('setToken', res.data.token); - // this.$refs.bindMobile.close(); - // if (res.data.is_register && this.$refs.registerReward.getReward()) { - // this.$refs.registerReward.open(); - // } + uni.login({ + provider: 'weixin', + timeout: 3000, + success: res => { + this.$api.temLogin(res.code).then((result) => { + if (result.code == 1) { + this.$db.set('userToken', result.data.accessToken); + this.getUserInfo() + this.$util.redirectTo( + '/pages/index/index', {}, + 'tabbar') } else { - this.isSub = false; this.$util.showToast({ - title: res.msg + title: result.msg ? result.msg : result.error }); } - }, - fail: res => { - this.isSub = false; - this.$util.showToast({ - title: 'request:fail' - }); - } - }); - } + }).catch((err) => { + console.log('err', err); + }) + }, + }) }, getCode(userInfo, callback) { uni.login({ provider: 'weixin', timeout: 3000, success: res => { - console.log(res) + console.log(res, 'getCode') let data = { code: res.code, nickname: userInfo.nickName, avatar: userInfo.avatarUrl, } - if (uni.getStorageSync('source_member')) { - data.source_member = uni.getStorageSync('source_member') - } - if (res.code) { - this.$api.sendRequest({ - url: '/api.php/login/wx_login', - data, - success: res => { - if (res.code >= 0) { - // if (res.data.openid) this.authInfo.weapp_openid = res.data.openid; - // if (res.data.unionid) this.authInfo.wx_unionid = res.data.unionid; - typeof callback == 'function' && callback(res); - } else { - this.$util.showToast({ - title: '灏忕▼搴忛厤缃敊璇�' - }); - } - } - }) - } + // if (uni.getStorageSync('source_member')) { + // data.source_member = uni.getStorageSync('source_member') + // } + // if (res.code) { + // this.$api.temLogin(data) + // } }, fail: () => { this.$util.showToast({ @@ -356,225 +165,15 @@ }, login(e) { if (!this.isChecked) { - return this.$util.showToast({ + return this.$common.showToast({ title: "璇峰厛鍚屾剰鍗忚" }) } - // if (!this.isChecked || !this.isCheckedSan) { - // this.$util.showToast({ - // title: "璇峰嬀閫夌敤鎴锋敞鍐�/鐧诲綍鍗忚鍜岀涓夋柟鍚堜綔娓呭崟" - // }) - // return - // } - // #ifdef MP-WEIXIN - if (this.canIUseGetUserProfile) { - wx.getUserProfile({ - desc: '鑾峰彇鐢ㄦ埛涓汉淇℃伅', // 澹版槑鑾峰彇鐢ㄦ埛涓汉淇℃伅鍚庣殑鐢ㄩ�旓紝鍚庣画浼氬睍绀哄湪寮圭獥涓紝璇疯皑鎱庡~鍐� - success: (res) => { - console.log(res) - if (res.errMsg == 'getUserProfile:ok') { - - // this.authInfo.nickName = res.userInfo.nickName; - // this.authInfo.avatarUrl = res.userInfo.avatarUrl; - // uni.setStorageSync('authInfo', this.authInfo) - - this.getCode(res.userInfo, data => { - console.log(data) - if (data.code == 1) { - uni.setStorageSync('authInfo', data.data) - if (!data.data.mobile) { - this.$refs.bindMobile.open() - } else { - if (data.data.wx_openid) { - this.$util.showToast({ - title: "鐧诲綍鎴愬姛", - icon: "success" - }) - uni.setStorage({ - key: 'uid', - data: data.data.id, - success: () => { - uni.removeStorageSync( - 'wx_openid_set'); - uni.removeStorageSync( - 'source_member'); - uni.removeStorageSync('authInfo'); - this.$api.sendRequest({ - url: "/api.php/user/is_perfect", - data: { - uid: data.data.id, - }, - success: res => { - if (res.code == - 1) { - console - .log( - res - ) - uni.setStorageSync( - 'is_perfect_user', - '1' - ) - } else { - uni.setStorageSync( - 'is_perfect_user', - res - .code - ) - } - }, - fail: res => { - this.$util - .showToast({ - title: "鎺ュ彛閿欒" - }); - } - }); - // this.$store.dispatch('getCartNumber'); - setTimeout(() => { - this.$util.redirectTo( - '/pages/index/index', {}, - 'tabbar') - }, 1000) - } - }); - } else { - // uni.setStorageSync('wx_openid_set',1) - this.$refs.popup.open() - } - - - } - } - return - // if (data) { - // this.authLogin(data); - // } else { - // this.$refs.auth.close(); - // this.toLogin(); - // } - }); - } - } - }) - } else if (e.detail.errMsg == 'getUserInfo:ok') { - this.getCode(data => { - if (data.code == 1) { - uni.setStorageSync('authInfo', data.data) - if (!data.data.mobile) { - this.$refs.bindMobile.open() - } else { - if (data.data.wx_openid) { - this.$util.showToast({ - title: "鐧诲綍鎴愬姛", - icon: "success" - }) - uni.setStorage({ - key: 'uid', - data: data.data.id, - success: () => { - uni.removeStorageSync('wx_openid_set'); - uni.removeStorageSync('source_member'); - uni.removeStorageSync('authInfo'); - this.$api.sendRequest({ - url: "/api.php/user/is_perfect", - data: { - uid: data.data.id, - }, - success: res => { - if (res.code == 1) { - console.log(res) - uni.setStorageSync( - 'is_perfect_user', '1') - } else { - uni.setStorageSync( - 'is_perfect_user', res.code - ) - } - }, - fail: res => { - this.$util.showToast({ - title: "鎺ュ彛閿欒" - }); - } - }); - // this.$store.dispatch('getCartNumber'); - setTimeout(() => { - this.$util.redirectTo( - '/pages/index/index', {}, - 'tabbar') - }, 1000) - } - }); - } else { - // uni.setStorageSync('wx_openid_set',1) - this.$refs.popup.open() - } - - - } - } - }); - } - // #endif - // if (!uni.getStorageSync('wx_openid_set')) { - // // #ifdef MP-QQ || MP-BAIDU - // if (e.detail.errMsg == 'getUserInfo:ok') { - // this.getCode(data => { - // if (data) { - // this.authLogin(data); - // } else { - // this.$refs.auth.close(); - // this.toLogin(); - // } - // }); - // } - // // #endif - - // // #ifdef MP-WEIXIN - // if (this.canIUseGetUserProfile) { - // wx.getUserProfile({ - // desc: '鑾峰彇鐢ㄦ埛涓汉淇℃伅', // 澹版槑鑾峰彇鐢ㄦ埛涓汉淇℃伅鍚庣殑鐢ㄩ�旓紝鍚庣画浼氬睍绀哄湪寮圭獥涓紝璇疯皑鎱庡~鍐� - // success: (res) => { - // if (res.errMsg == 'getUserProfile:ok') { - - // // this.authInfo.nickName = res.userInfo.nickName; - // // this.authInfo.avatarUrl = res.userInfo.avatarUrl; - // // uni.setStorageSync('authInfo', this.authInfo) - - // this.getCode(data => { - // console.log(data) - // return - // if (data) { - // this.authLogin(data); - // } else { - // this.$refs.auth.close(); - // this.toLogin(); - // } - // }); - // } - // } - // }) - // } else if (e.detail.errMsg == 'getUserInfo:ok') { - // this.getCode(data => { - // if (data) { - // this.authLogin(data); - // } else { - // this.$refs.auth.close(); - // this.toLogin(); - // } - // }); - // } - // // #endif - - // // #ifndef MP - // this.$refs.auth.close(); - // this.toLogin(); - // // #endif - // } else { - // this.$refs.auth.close(); - // this.toLogin(); - // } + uni.login({ + provider: 'weixin', + timeout: 3000, + success: res => {}, + }) }, } } @@ -582,7 +181,7 @@ <style lang="scss" scoped> .wrap { - background: linear-gradient(to bottom, #B4DEFF, #ffffff); + background: linear-gradient(to bottom, #fbec99, #ffffff); display: flex; align-items: center; flex-direction: column; @@ -613,7 +212,7 @@ line-height: 60rpx; .color-base-text { - color: #35A6FF; + color: #fece01; } } @@ -624,6 +223,7 @@ line-height: 70rpx; background-color: #35A6FF; border-radius: 70rpx; + padding: 0; } .no_login { @@ -741,4 +341,4 @@ color: #ffffff; background-color: #35A6FF; } -</style> +</style> \ No newline at end of file -- Gitblit v1.9.1