登录跳转首页功能实现

This commit is contained in:
minimaxagent1 2025-07-30 09:20:18 +08:00
parent d5269a96d4
commit 1cd1f8d4ea
2 changed files with 28 additions and 91 deletions

View File

@ -83,55 +83,9 @@ const install = (Vue, vm) => {
// // return res.result; // // return res.result;
// } // }
if(res.code == 401) { if(res.code == 401) {
// res为服务端返回值可能有coderesult等字段 uni.reLaunch({
// 这里对res.result进行返回将会在this.$u.post(url).then(res => {})的then回调中的res的到 url:'/pages/login/login'
// 如果配置了originalData为true请留意这里的返回值 })
// return res.result;
uni.login({
success: function(ret) {
console.log("main.js==>res", ret)
// vm.$u.post('/user/login',{"js_code": ret.code}).then(res=>{
// if (res.code == 10003) {
// // console.log("新用户登录")
// uni.setStorageSync('token', res.data);
// } else if (res.code == 200) {
// // console.log("老用户登录",res.data)
// uni.setStorageSync('token', res.data);
// }
// });
}
});
wx.login({
success(res) {
if (res.code) {
console.log('登录!', res);
let data = {
wxOpenId: res.code,
};
vm.$u.post('/app/auth/wxLogin',data).then(res=>{
if (res.code == 10003) {
uni.navigateTo({
url:'/pages/login/login'
})
} else if (res.code == 200) {
// console.log("老用户登录",res.data)
uni.switchTab({
url:'/pages/index/index'
})
}
});
}
},
});
} }
return res; return res;
// else if(res.code == 201) { // else if(res.code == 201) {

View File

@ -1,12 +1,12 @@
<template> <template>
<view class="page"> <view class="page">
<u-navbar :is-back="false" :title="tittxt" :border-bottom="false" :background="bgc" title-color='#000' title-size='36' height='36' > <u-navbar :is-back="false" :title="titleTxt" :border-bottom="false" :background="bgc" title-color='#000' title-size='36' height='36' >
</u-navbar> </u-navbar>
<view class="imgbox"> <view class="imgbox">
<image src="https://api.ccttiot.com/smartmeter/img/static/uGPwljIaEppyKAT1iQaW" mode=""></image> <image src="https://api.ccttiot.com/smartmeter/img/static/uGPwljIaEppyKAT1iQaW" mode=""></image>
</view> </view>
<button class="button" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber" > <button class="button" @click="getPhoneNumber" >
授权登录 授权登录
</button> </button>
<view class="tip"> <view class="tip">
@ -23,7 +23,7 @@
bgc: { bgc: {
backgroundColor: "#fff", backgroundColor: "#fff",
}, },
tittxt:"登录", titleTxt:"登录",
chooseType:true, chooseType:true,
usertype:'', usertype:'',
login:false login:false
@ -33,51 +33,34 @@
userType(num){ userType(num){
this.chooseType=false this.chooseType=false
this.login=true this.login=true
if(num==1){ if(num===1){
this.usertype='01' this.usertype='01'
}else{ }else{
this.usertype='00' this.usertype='00'
} }
}, },
getPhoneNumber(e) { getPhoneNumber() {
let that = this; let that = this;
console.log("eeeeeeee", e); wx.login({
const wxLoginAsync = () => { success(res) {
return new Promise((resolve, reject) => { if (res.code) {
wx.login({ console.log('登录!', res);
success(res) { let data = {
if (res.code) { loginCode: res.code,
console.log('登录!', res); appId:1,
let data = { };
wxOpenId: res.code, that.$u.post("/wxLogin",data).then((res) => {
userType: that.usertype, if (res.code == 200) {
mobileCode: e.detail.code, console.log(res,'resres');
}; wx.setStorageSync('token', res.token);
resolve(data); that.ceshi()
} else { }
reject(res.errMsg); });
} }
}, },
fail(err) { fail(err) {
reject(err); }
} });
});
});
};
wxLoginAsync()
.then(async (data) => {
this.$u.post("/wxLogin",data).then((res) => {
if (res.code == 200) {
console.log(res,'resres');
wx.setStorageSync('token', res.token);
that.ceshi()
}
});
})
.catch((err) => {
console.error(err);
});
}, },
async ceshi() { async ceshi() {
uni.switchTab({ uni.switchTab({