This commit is contained in:
2025-03-09 23:19:35 +08:00
parent 912da26042
commit cc44cf2067

View File

@@ -8,173 +8,137 @@ Page({
* 页面的初始数据 * 页面的初始数据
*/ */
data: { data: {
// 用户信息相关
userInfo: null,
hasUserInfo: false,
canIUseOpenData: wx.canIUse('open-data.type.userAvatarUrl') && wx.canIUse('open-data.type.userNickName'), canIUseOpenData: wx.canIUse('open-data.type.userAvatarUrl') && wx.canIUse('open-data.type.userNickName'),
// 登录状态相关
phone: wx.getStorageSync('uid'), phone: wx.getStorageSync('uid'),
uidFlag: wx.getStorageSync('uidFlag'), uidFlag: wx.getStorageSync('uidFlag'),
status: '',
code: '', code: '',
height: '',
userInfo: null, // 界面布局相关
isUser: false, statusBarHeight: 0,
userInfo: {}, height: 0,
hasUserInfo: false,
}, },
/** /**
* 生命周期函数--监听页面加载 * 生命周期函数--监听页面加载
*/ */
onLoad: function (options) { onLoad: function (options) {
var statusBarHeight = wx.getSystemInfoSync().statusBarHeight; this.initStatusBarHeight()
app.console(statusBarHeight + "=================xxxxxxxxxxxxxxxxxxxxxxxx")
this.setData({
statusBarHeight: statusBarHeight,
height: 46 + statusBarHeight,
});
app.console(this.data.height + "=================xxxxxxxxxxxxxxxxxxxxxxxx")
//调试参数
// wx.setStorageSync('phone', 18133922183);
// wx.setStorageSync('uid', 'adfdffb45a364fc23162f1ebfe9dd66f');
// wx.setStorageSync('token', '797d4q7XT8/PM9bU+T+CNpEpNfsWeVb5j+eXnrRXW0yq+wKXY9fBNSvb7qPiCRMlzZmwG3u1ods8R8Rh3gITxCkyiZGUtLZf');
// wx.setStorageSync('uidFlag', true);
}, },
/** /**
* 生命周期函数--监听页面显示 * 生命周期函数--监听页面显示
*/ */
onShow: function () { onShow: function () {
this.getLogin() this.getLogin()
console.log("code==" + this.data.code)
// if (wx.getStorageSync('phone') != '') {
// this.getUserBaseInfo()
// }
}, },
// 登录 // 初始化状态栏高度
initStatusBarHeight() {
const statusBarHeight = wx.getSystemInfoSync().statusBarHeight
this.setData({
statusBarHeight,
height: 46 + statusBarHeight
})
},
// 登录相关方法
getLogin() { getLogin() {
var that = this;
wx.login({ wx.login({
success: res => { success: res => {
console.log(res)
app.globalData.code = res.code app.globalData.code = res.code
that.setData({ this.setData({ code: res.code })
code: res.code
}) this.getUserInfo()
wx.getUserInfo({
success: (data) => {
const encryptedData = data.encryptedData;
const iv = data.iv;
app.globalData.encryptedData = encryptedData
app.globalData.iv = iv
// 将code、encryptedData、iv发送到后端接口
console.log("encryptedData==" + app.globalData.encryptedData)
console.log("iv==" + app.globalData.iv)
console.log("wxcode==" + app.globalData.code)
}
})
} }
}) })
}, },
// 获取电话号码 getUserInfo() {
getPhoneNumber(e) { wx.getUserInfo({
// console.log("encryptedData==" + app.globalData.encryptedData) success: (data) => {
// console.log("iv==" + app.globalData.iv) const { encryptedData, iv } = data
// console.log("wxcode==" + app.globalData.code) app.globalData.encryptedData = encryptedData
var _this = this; app.globalData.iv = iv
}
})
},
// 获取手机号并登录
getPhoneNumber() {
wx.request({ wx.request({
url: app.globalData.url + 'app/Ghdwechat/wechatLogin', url: app.globalData.url + 'app/Ghdwechat/wechatLogin',
method: 'POST',
header: { 'content-type': 'application/x-www-form-urlencoded' },
data: { data: {
code: app.globalData.code, code: app.globalData.code,
encryptedData: app.globalData.encryptedData, encryptedData: app.globalData.encryptedData,
iv: app.globalData.iv iv: app.globalData.iv
}, },
method: 'POST', success: this.handleLoginResponse.bind(this)
header: {
'content-type': 'application/x-www-form-urlencoded'
},
success(res) {
if (res.data.erro == 0) {
app.globalData.uid = res.data.uid;
wx.setStorageSync('phone', res.data.uid);
wx.setStorageSync('uid', res.data.uid);
wx.setStorageSync('token', res.data.uid);
wx.setStorageSync('uidFlag', true);
_this.setData({
uidFlag: true,
phone: res.data.uid
}) })
app.globalData.uid = res.data.uid; },
handleLoginResponse(res) {
if (res.data.erro === 0) {
this.saveUserData(res.data)
this.navigateToHome()
}
wx.showToast({
title: res.data.msg,
icon: 'none'
})
},
saveUserData(data) {
const { uid } = data
wx.setStorageSync('phone', uid)
wx.setStorageSync('uid', uid)
wx.setStorageSync('token', uid)
wx.setStorageSync('uidFlag', true)
this.setData({
uidFlag: true,
phone: uid
})
app.globalData.uid = uid
},
navigateToHome() {
wx.switchTab({ wx.switchTab({
url: '/pages/home/home' url: '/pages/home/home'
}) })
// _this.getToken()
// _this.ceshi()
wx.showToast({
title: res.data.msg,
icon: 'none'
});
} else {
wx.showToast({
title: res.data.msg,
icon: 'none'
});
}
}
})
}, },
//上传测试数据
ceshi() {
wx.request({
url: app.buildUrltwo("/member/logintwo"),
header: app.getRequestHeader(),
method: "POST",
data: {
name: wx.getStorageSync('uid'),
phone: wx.getStorageSync('phone'),
storename: wx.getStorageSync('token')
},
success: function (res) {
var resp = res.data;
if (resp.code != 200) {
app.alert({
"content": resp.msg
});
return;
}
// 跳转
wx.navigateBack({});
}
})
},
//获取token
getUserBaseInfo: function () {
var that = this;
//假数据
// if (this.data.resp.erro == 0) {
// that.setData({
// infor: this.data.resp.infor
// });
// }
wx.request({
url: app.globalData.url + '/getUserToken',
header: app.getRequestHeader(),
method: 'GET',
data: {
phonenumber: '18133922183'
},
success: function (res) {
var resp = res.data;
console.log(resp + "=======dddddddddddddddddd")
console.log(resp.erro + "======ddddddddddddddddddd")
if (resp.erro == 0) {
that.setData({ // 页面导航方法
infor: resp.infor shoucang() {
}); wx.navigateTo({
} url: '/pages/myshoucang/myshoucang_index?type=1'
} })
}); },
pintuan() {
wx.navigateTo({
url: '/pages/order/order'
})
},
qianbao() {
wx.navigateTo({
url: '/pages/wodeqianbao/qianbao'
})
},
guanyu() {
wx.navigateTo({
url: '/pages/guanyu/guanyu'
})
}, },
/** /**
@@ -218,26 +182,4 @@ Page({
onShareAppMessage: function () { onShareAppMessage: function () {
}, },
shoucang() {
wx.navigateTo({
url: '/pages/myshoucang/myshoucang_index?' + "type=" + "1",
})
},
pintuan() {
wx.navigateTo({
// url: '/pages/myshoucang/myshoucang_index?'+"type="+"2",
url: '/pages/order/order',
})
},
qianbao() {
wx.navigateTo({
url: '/pages/wodeqianbao/qianbao'
})
},
guanyu() {
wx.navigateTo({
url: '/pages/guanyu/guanyu'
})
},
}) })