瑞梦思预约小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.4 KiB

3 years ago
// app.js
3 years ago
const http = require('./api/http.js')
3 years ago
App({
onLaunch() {
},
3 years ago
login(){
3 years ago
return new Promise((resolve,reject)=>{
3 years ago
wx.getUserProfile({
lang: 'zh_CN',
desc: '需要获取您的信息用来展示',
success: res => {
wx.showLoading({ title: '登录中' })
wx.login({
success: result => {
// 发送 res.code 到后台换取 openId, sessionKey, unionId
let data = {
code: result.code,
iv: res.iv,
encryptedData: res.encryptedData
3 years ago
}
console.log(data)
3 years ago
http.$http('post','wxapp/auth',data).then((result)=>{
if(result.data.success){
wx.setStorageSync('token', result.data.data.token)
wx.setStorageSync('userInfo', result.data.data.user)
wx.showToast({
title: '授权成功!',
icon: 'none'
})
} else{
wx.showToast({
title: result.data.msg,
icon: 'none'
})
}
3 years ago
resolve(result)
})
}
3 years ago
})
3 years ago
},
fail: res=>{
console.log('取消授权')
3 years ago
}
})
})
},
globalData: {
http: http.$http,
products: []
3 years ago
}
})