//const app = require('../../js/api'); import api from '../../js/api' // pages/login/login.js Page({ /** * 页面的初始数据 */ data: { }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { }, pay(){ api.request_wechatPay(1) .then(res => { wx.requestPayment({ timeStamp: res.data.data.unifiedOrderResult.timeStamp, nonceStr: res.data.data.unifiedOrderResult.nonceStr, package: res.data.data.unifiedOrderResult.package, signType: res.data.data.unifiedOrderResult.signType, paySign: res.data.data.unifiedOrderResult.paySign, success: res => { wx.hideLoading() wx.showToast({ title: '支付成功!', }) setTimeout(function () { wx.redirectTo({ url: '../scan/scan', }) }, 2000) }, fail: res => { wx.hideLoading() wx.showModal({ title: '支付失败', content: res.errMsg + '请稍后再试', showCancel: false, success(res) { if (res.confirm) { wx.switchTab({ url: '../home/home', }) } } }) } }) }); }, handleAuthLogin(e) { console.log('一键授权登录按钮被点击'); wx.showLoading({ title: '正在登录中...', }) // if(e.detail.userInfo) { wx.getUserProfile({ desc: '用于完善用户信息', success:(res) => { console.log(res.userInfo) }, fail:(err) => { console.log("获取用户信息失败",err) } }) // } // 调用微信登录接口 wx.login({ success(res) { if (res.code) { console.log('登录成功,code:', res.code); api.request_Wechatlogin(res.code) .then(res => { wx.setStorageSync('WachatID', res.data.data) wx.hideLoading() wx.redirectTo({ url: '../scan/scan', }) }); } else { wx.hideLoading() console.log('登录失败:', res.errMsg); } }, fail(err) { wx.hideLoading() console.error('登录接口调用失败:', err); }, }); } })