|
@@ -1,16 +1,31 @@
|
|
|
import {
|
|
|
userLogin,
|
|
|
} from '~/api/user'
|
|
|
+import {
|
|
|
+ createStoreBindings
|
|
|
+} from 'mobx-miniprogram-bindings'
|
|
|
+import {
|
|
|
+ store
|
|
|
+} from '~/store/index'
|
|
|
+let storeBindings
|
|
|
Page({
|
|
|
data: {
|
|
|
checkedAgree: false,
|
|
|
loginSuccess: false, // 标记是否登录成功
|
|
|
},
|
|
|
-
|
|
|
+ onLoad() {
|
|
|
+ if (!this.storeBindings) {
|
|
|
+ this.storeBindings = createStoreBindings(this, {
|
|
|
+ store,
|
|
|
+ actions: ['setUser']
|
|
|
+ })
|
|
|
+ }
|
|
|
+ },
|
|
|
/**
|
|
|
* 退出页面时触发基础库回调,由基础库内部处理系统登录态。
|
|
|
*/
|
|
|
onUnload() {
|
|
|
+ this.storeBindings.destroyStoreBindings()
|
|
|
const eventChannel = this.getOpenerEventChannel();
|
|
|
if (eventChannel) {
|
|
|
eventChannel.emit('__donutLogin__', {
|
|
@@ -23,27 +38,35 @@ Page({
|
|
|
* 触发小程序登录,登录成功后自动退出页面
|
|
|
*/
|
|
|
onTapWeixinMiniProgramLogin() {
|
|
|
- wx.getMiniProgramCode({
|
|
|
- success: async (res) => {
|
|
|
- let data = {
|
|
|
- code: res.code,
|
|
|
- userChannelCode
|
|
|
- }
|
|
|
- let userRes = await userLogin(data)
|
|
|
+ wx.weixinMiniProgramLogin({
|
|
|
+ success: () => {
|
|
|
+ this.setData({
|
|
|
+ loginSuccess: true
|
|
|
+ });
|
|
|
+ wx.getMiniProgramCode({
|
|
|
+ success: async (res) => {
|
|
|
+ console.log(res);
|
|
|
+ let data = {
|
|
|
+ code: res.code,
|
|
|
+ userChannelCode: 3001
|
|
|
+ }
|
|
|
+ let userRes = await userLogin(data)
|
|
|
+ this.setUser(userRes.data)
|
|
|
+ wx.setStorageSync('uid', userRes.data.uid)
|
|
|
+ wx.setStorageSync('user', userRes.data)
|
|
|
+ wx.switchTab({
|
|
|
+ url: '/pages/index/index',
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ fail: () => {
|
|
|
+ wx.showToast({
|
|
|
+ title: '小程序登录失败',
|
|
|
+ icon: 'none'
|
|
|
+ });
|
|
|
}
|
|
|
})
|
|
|
- /* wx.weixinMiniProgramLogin({
|
|
|
- success: () => {
|
|
|
- this.setData({ loginSuccess: true });
|
|
|
- wx.navigateBack();
|
|
|
- },
|
|
|
- fail: () => {
|
|
|
- wx.showToast({
|
|
|
- title: '小程序登录失败',
|
|
|
- icon: 'none'
|
|
|
- });
|
|
|
- }
|
|
|
- }) */
|
|
|
},
|
|
|
|
|
|
onCheckboxChange() {
|