12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- import { api_login, api_queryUserInfo } from './api/login';
- const config = require("./config");
- App<IAppOption>({
- globalData: {
-
- top: 0,
- baseUrl: config?.baseUrl,
- appId: '',
- deviceNum: '',
- isLogin: false,
- userInfo: {} as any
- },
- onLaunch() {
-
-
-
-
- this.setAppId();
-
- wx.login({
- success: async (res) => {
- this.onLogin(res.code)
- },
- })
- },
- setAppId() {
-
- const accountInfo = wx.getAccountInfoSync();
- this.globalData.appId = accountInfo.miniProgram.appId;
-
-
-
-
- const deviceInfo = wx.getDeviceInfo()
-
- const deviceNum = deviceInfo.brand + '-' + deviceInfo.model + '-' + deviceInfo.platform + '-' + deviceInfo.system
- this.globalData.deviceNum = deviceNum
-
- const systemInfo = wx.getWindowInfo();
- this.globalData.top = systemInfo.windowHeight - 180
- },
-
-
-
-
- async onLogin(code: string) {
- wx.showLoading({
- mask: true,
- title: "加载中...",
- });
- try {
-
- const { data } = await api_login({
- autoRegister: false,
- client_id: 'cooleshow-student-wxlite',
- client_secret: 'cooleshow-student-wxlite',
- deviceNum: this.globalData.deviceNum,
- extra: '',
- grant_type: 'password',
- loginType: 'WECHAT_MA',
- multiUser: false,
- username: this.globalData.appId,
- password: code
- })
- if(data.code === 200) {
- const userToken = data.data.token_type + " " + data.data.access_token;
- wx.setStorageSync("token", userToken);
- this.globalData.isLogin = true;
- const users = await api_queryUserInfo({ wxAppId: this.globalData.appId })
- if(users.data.code === 200) {
- this.globalData.userInfo = users.data.data
- } else {
- wx.removeStorageSync("token");
- this.globalData.isLogin = false
- }
- console.log(users)
- } else {
- this.globalData.isLogin = false;
- }
- } catch {}
- wx.hideLoading()
- }
- })
|