/
login.js
45 lines (44 loc) · 1.1 KB
/
login.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
const regeneratorRuntime = require("../lib/runtime");
Component({
properties: {
text: {
type: String,
value: '默认文本'
}
},
data: {},
externalClasses: ['weui-btn'],
methods: {
bindTap (e) {
const that = this
// 点击登录/注册按钮触发
wx.login({
async success (res) {
const { code } = res
const { rawData, userInfo } = e.detail
wx.showLoading({ title: '登录中...' })
const { result } = await wx.cloud.callFunction({
// 要调用的云函数名称
name: 'loginRegister',
// 传递给云函数的参数
data: {
code,
rawData
}
});
wx.hideLoading()
if (result.code === 0) {
wx.setStorageSync('session', result.data.session);
that.triggerEvent('loginsuccess',userInfo);
} else {
wx.showToast({
title: result.message,
icon: 'none',
duration: 2000
});
}
}
})
}
}
})