Browse Source

feat(登录): 实现H5和微信小程序的双平台登录逻辑

- 添加H5平台的微信授权登录流程
- 分离H5和小程序的登录逻辑到不同commit方法
- 更新登录API接口配置支持多平台
- 添加微信验证文件和配置参数
- 调整导航栏组件在微信平台的显示
- 修复登录状态检查逻辑
master
前端-胡立永 19 hours ago
parent
commit
964031adb9
9 changed files with 229 additions and 129 deletions
  1. +1
    -0
      MP_verify_wfZF8R25IxLLUUXi.txt
  2. +9
    -0
      api/model/login.js
  3. +9
    -0
      components/base/navbar.vue
  4. +6
    -1
      config.js
  5. +5
    -0
      manifest.json
  6. +2
    -2
      pages/index/center.vue
  7. +179
    -124
      pages_order/auth/wxLogin.vue
  8. +2
    -2
      pages_order/mine/help.vue
  9. +16
    -0
      store/store.js

+ 1
- 0
MP_verify_wfZF8R25IxLLUUXi.txt View File

@ -0,0 +1 @@
wfZF8R25IxLLUUXi

+ 9
- 0
api/model/login.js View File

@ -5,8 +5,17 @@
const api = {
// 微信登录接口
wxLogin: {
// #ifdef H5
url: '/login/wxLogin',
method: 'POST',
// #endif
// #ifdef MP-WEIXIN
url: '/login/login',
method: 'GET',
// #endif
limit : 500,
showLoading : true,
},


+ 9
- 0
components/base/navbar.vue View File

@ -1,6 +1,11 @@
<template>
<!-- <view class="navbar"
:style="{backgroundColor : bgColor}"> -->
<!-- #ifdef MP-WEIXIN -->
<view class="title nav-bar__view"
:style="{backgroundColor : bgColor,color}">
<view class="left">
@ -40,6 +45,7 @@
</view>
</view>
<!-- #endif -->
<!-- </view> -->
</template>
@ -76,6 +82,9 @@
}
},
created() {
if(typeof document != 'undefined'){
document.title = this.title
}
},
beforeDestroy() {
},


+ 6
- 1
config.js View File

@ -14,10 +14,14 @@ const type = 'prod'
const config = {
dev: {
baseUrl: 'http://augcl.natapp1.cc/massage-admin/massage',
// redirect : 'http://h5.xzaiyp.top',
redirect : 'https://wwwh5.yurangongfang.com',
},
prod: {
baseUrl: 'https://www.yurangongfang.com/massage-admin/massage',
}
// baseUrl: 'https://www.yurangongfang.com/massage-admin/massage',
redirect : 'https://wwwh5.yurangongfang.com',
},
}
@ -40,6 +44,7 @@ const defaultConfig = {
},
//商户号
mchId : '1712378227',
appId : 'wxb1c123a63736f789',
}


+ 5
- 0
manifest.json View File

@ -87,6 +87,8 @@
},
"devServer" : {
"https" : false,
"port" : 8002,
"disableHostCheck" : true,
"proxy" : {
"/ws/geocoder/v1/" : {
"target" : "https://apis.map.qq.com",
@ -97,6 +99,9 @@
"changeOrigin" : true
}
}
},
"router" : {
"mode" : "hash"
}
}
}

+ 2
- 2
pages/index/center.vue View File

@ -180,7 +180,7 @@
}
},
onShow() {
if(this.isLogin){
if(uni.getStorageSync('token')){
this.$store.commit('getUserInfo')
this.$store.commit('getUserCenterInfo')
this.$store.commit('getRiceInfo')
@ -311,7 +311,7 @@
}
.member {
width: calc(100vw - 13rpx*2);
width: calc(724rpx);
position: absolute;
bottom: 0;
left: 13rpx;


+ 179
- 124
pages_order/auth/wxLogin.vue View File

@ -6,9 +6,8 @@
{{ configList.config_app_name }}
</view>
</view>
<button class="btn btn-login mt"
@click="wxLogin">
<button class="btn btn-login mt" @click="wxLogin">
<view class="icon">
<uv-icon name="weixin-fill" color="#ffffff" size="36rpx"></uv-icon>
</view>
@ -20,23 +19,15 @@
<button class="btn btn-cancel" :plain="true" :hairline="false" @click="onCancel">
暂不登录
</button>
<view class="config mt">
<view style="flex: 1;">
<uv-checkbox-group
v-model="checkboxValue"
shape="circle"
>
<uv-checkbox-group v-model="checkboxValue" shape="circle">
<view class="content">
<uv-checkbox
size="28rpx"
icon-size="28rpx"
activeColor="#07C261"
:name="1"
></uv-checkbox>
<uv-checkbox size="28rpx" icon-size="28rpx" activeColor="#07C261" :name="1"></uv-checkbox>
已同意
<text @click="openModal">注册协议隐私协议</text>
</view>
</view>
</uv-checkbox-group>
</view>
<view class="flex">
@ -45,138 +36,202 @@
</view>
<agreementModal ref="modal" @confirm="onConfirmAggrement"></agreementModal>
</view>
</template>
<script>
import agreementModal from './agreementModal.vue'
export default {
name : 'Login',
data() {
return {
checkboxValue : []
}
},
components: {
agreementModal
},
methods: {
wxLogin(){
if(!this.checkboxValue.length){
return uni.showToast({
title: '请先同意隐私协议',
icon:'none'
})
import agreementModal from './agreementModal.vue'
import Vue from 'vue'
export default {
name: 'Login',
data() {
return {
checkboxValue: []
}
this.$store.commit('login')
},
openModal() {
this.$refs.modal.open()
components: {
agreementModal
},
onConfirmAggrement(confirm) {
if (confirm) {
this.checkboxValue = [1]
} else {
this.checkboxValue = []
onShow() {
if (this.GetQueryString('code')) { //code
this.agreement = true; //
//
this.toWxLogin(this.GetQueryString('code'))
}
},
onCancel() {
console.log('--onCancel')
uni.reLaunch({
url: '/pages/index/index'
})
},
methods: {
wxLogin() {
if (!this.checkboxValue.length) {
return uni.showToast({
title: '请先同意隐私协议',
icon: 'none'
})
}
// #ifdef MP-WEIXIN
this.$store.commit('login')
// #endif
// #ifdef H5
this.getwx_authorize();
// #endif
},
openModal() {
this.$refs.modal.open()
},
onConfirmAggrement(confirm) {
if (confirm) {
this.checkboxValue = [1]
} else {
this.checkboxValue = []
}
},
onCancel() {
console.log('--onCancel')
uni.reLaunch({
url: '/pages/index/index'
})
},
getwx_authorize() {
console.log(Vue.prototype.$config.redirect);
let redirect_uri = encodeURIComponent(Vue.prototype.$config.redirect + '/#/pages_order/auth/wxLogin');
let appid = Vue.prototype.$config.appId;
window.location.href = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + appid +
'&redirect_uri=' + redirect_uri +
'&response_type=code&scope=snsapi_userinfo&state=123#wechat_redirect' + '&t=' + new Date().getTime();
},
//url
GetQueryString(name) {
var url = window.location.href;
try {
var cs = url.split('?')[1]; //?
var cs_arr = cs.split('&'); //
for (var i = 0; i < cs_arr.length; i++) { //json
if (cs_arr[i].split('=')[0] == name) {
return cs_arr[i].split('=')[1];
}
}
return "";
} catch {
return "";
}
},
//
toWxLogin(code) {
let vid = sessionStorage.getItem('vid');
this.$api('wxLogin', {
code,
vid
}, res => {
if (res.code == 200) {
this.$store.commit('h5Login', res.result)
} else {
location.href = Vue.prototype.$config.redirect + '/#/pages_order/auth/wxLogin'
}
sessionStorage.removeItem('vid')
})
},
}
}
}
</script>
<style scoped lang="scss">
.login{
display: flex;
justify-content: flex-start;
align-items: center;
height: 100vh;
flex-direction: column;
position: relative;
background: $uni-fg-color;
.logo{
margin-top: 334rpx;
width: 320rpx;
image{
height: 150rpx;
.login {
display: flex;
justify-content: flex-start;
align-items: center;
height: 100vh;
flex-direction: column;
position: relative;
background: $uni-fg-color;
.logo {
margin-top: 334rpx;
width: 320rpx;
image {
height: 150rpx;
width: 320rpx;
}
.text {
margin-top: 90rpx;
font-size: 38rpx;
font-family: PingFang SC, PingFang SC-Bold;
font-weight: 700;
text-align: center;
color: #000000;
}
}
.text{
margin-top: 90rpx;
font-size: 38rpx;
font-family: PingFang SC, PingFang SC-Bold;
font-weight: 700;
text-align: center;
color: #000000;
}
}
.btn{
width: 80%;
height: 100rpx;
font-size: 15px;
font-family: PingFang SC, PingFang SC-Regular;
font-weight: 400;
.btn {
width: 80%;
height: 100rpx;
display: flex;
justify-content: center;
align-items: center;
border-radius: 50rpx;
&-login {
background-image: linear-gradient(to right, #84A73F, #D8FF8F);
color: #fff;
border: none;
.icon{
margin-right: 10rpx;
image{
width: 40rpx;
height: 35rpx;
font-size: 15px;
font-family: PingFang SC, PingFang SC-Regular;
font-weight: 400;
display: flex;
justify-content: center;
align-items: center;
border-radius: 50rpx;
&-login {
background-image: linear-gradient(to right, #84A73F, #D8FF8F);
color: #fff;
border: none;
.icon {
margin-right: 10rpx;
image {
width: 40rpx;
height: 35rpx;
}
}
}
&-cancel {
height: calc(100rpx - 1rpx * 2);
color: #c7c7c7;
background-color: transparent;
border: 1rpx solid #c7c7c7;
margin-top: 60rpx;
}
}
&-cancel {
height: calc(100rpx - 1rpx * 2);
color: #c7c7c7;
background-color: transparent;
border: 1rpx solid #c7c7c7;
margin-top: 60rpx;
.mt {
margin-top: 200rpx;
}
}
.mt{
margin-top: 200rpx;
}
.config{
width: 80%;
line-height: 40rpx;
// margin-top: 27rpx;
color: #C7C7C7;
text-align: left;
display: flex;
.content {
font-size: 22rpx;
.config {
width: 80%;
line-height: 40rpx;
// margin-top: 27rpx;
color: #C7C7C7;
text-align: left;
display: flex;
align-items: center;
}
text{
color: #07C261;
.content {
font-size: 22rpx;
display: flex;
align-items: center;
}
text {
color: #07C261;
}
}
}
}
.flex {
display: flex;
align-items: center;
}
</style>
.flex {
display: flex;
align-items: center;
}
</style>

+ 2
- 2
pages_order/mine/help.vue View File

@ -21,8 +21,8 @@
<view class="help-screenshot">
<uv-upload :fileList="fileList" multiple :maxCount="3" width="180rpx" height="180rpx" multiple
@afterRead="afterRead" @delete="deleteImage">
<image src="../static/help/uploading.png" mode="aspectFill"
style="width: 180rpx;height: 180rpx;" />
<!-- <image src="../static/help/uploading.png" mode="aspectFill"
style="width: 180rpx;height: 180rpx;" /> -->
</uv-upload>
</view>
</view>


+ 16
- 0
store/store.js View File

@ -1,6 +1,7 @@
import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex); //vue的插件机制
import api from '@/api/api.js'
@ -62,6 +63,21 @@ const store = new Vuex.Store({
// })
},
login(state, config) {
// #ifdef MP-WEIXIN
this.commit('wxLogin', config)
// #endif
// #ifdef H5
this.commit('h5Login', config)
// #endif
},
h5Login(state, config){
Vue.set(state, 'userInfo', config.userInfo)
uni.setStorageSync('token', config.token)
uni.reLaunch({
url: '/pages/index/index'
})
},
wxLogin(state, config){
uni.showLoading({
title: '登录中...'
})


Loading…
Cancel
Save