Newer
Older
XiaoGanWXMini / App.vue
@zhangdeliang zhangdeliang on 29 Jul 1 KB 迁移
<script>
import { wechartLogin, getWechartMiniuserByOpenId } from '@/utils/homeApi.js';
import defaultHeadImg from '@/static/images/userUtar.png'; //默认头像

export default {
	onLaunch: () => {
		// 使用微信小程序获取code
		uni.login({
			provider: 'weixin',
			success: (res) => {
				console.log('微信小程序登录code--', res);
				wechartLogin({ jsCode: res.code }).then((res2) => {
					if (res2.code == 200 && res2.data.openId) {
						uni.setStorageSync('openidXGWXMN', res2.data.openId);
						// 根据openid获取微信粉丝信息
						getWechartMiniuserByOpenId({ openId: res2.data.openId }).then((res3) => {
							if (res3.code == 200) {
								uni.setStorageSync('userIdXGWXMN', res3.data.id);
								uni.setStorageSync('nickNameXGWXMN', res3.data.nickName || '微信昵称');
								uni.setStorageSync('headImgXGWXMN', res3.data.coverPhotosFileList.length > 0 ? res3.data.coverPhotosFileList[0].url : defaultHeadImg);
								uni.setStorageSync('authStatusXGWXMN', res3.data.authStatus); // 0:未认证 1:已认证 2认证中
							}
						});
					} else {
						console.log('登录失败', res.msg);
					}
				});
			}
		});
	},
	onShow: () => {
		// console.log('App Show', document)
	},
	onHide: () => {
		// console.log('App Hide')
	}
};
</script>

<style>
/*每个页面公共css */
</style>