Newer
Older
gdtMimiProgram / utils / auth.js
dutingting on 23 Nov 2022 1022 bytes 消息列表和详情接口联调
import store from '@/store/index.js';
import {login} from '@/api/user.js';
import { getUserInfo } from "@/api/index.js";
//获取用户信息
export function getUserProfile() {
	getUserInfo().then(resporse => {
		uni.setStorageSync('userInfo', JSON.stringify(resporse));
	})
}

export function getLogin() {
	return new Promise((resolve, reject) => {
		wx.login({
			onlyAuthorize: true,
			success(data) {
				console.log('登录参数', data, uni.getStorageSync('sessionId'))
				login(data.code).then(res => {
					uni.setStorageSync('sessionId', res);
					// //获取用户信息
					// getUserInfo().then(resporse => {
					// 	uni.setStorageSync('userInfo', JSON.stringify(resporse));
					// })
					uni.showToast({
					  title: `登录成功`,
					  icon: "none",
					  duration: 2000,
					});
					resolve('登录成功');
				});
			},
			fail(err) {
				console.log('login fail', err);
				uni.showToast({
					title: '登录错误',
					icon: 'none'
				});
				reject('登录错误');
			},
		});
	})
}