<script>
	import USER from '@/api/user.js'
	export default {
		onLaunch: async function() {
			await this.handleWxLogin()
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		},
		methods: {
			async handleWxLogin() {
				// #ifdef MP-WEIXIN
				// 1. 获取code
				return new Promise((resolve, reject) => {
				  uni.login({
					success: async({code} ) => {
					  const { data } = await USER.fetchLogin({code})
					  uni.setStorageSync('userInfo', data);
					  resolve(data)
					},
					fail: err => {
					  console.error(err)
					  reject(err)
					}
				  })
				})
				// #endif
				
				// #ifdef H5
				const {data} = await USER.userInfo()
				uni.setStorageSync('userInfo', data);
				// #endif
			}
		}
	}
</script>

<style lang="scss">
	/*每个页面公共css */
	@import "@/uni_modules/uview-plus/index.scss";
	@import "@/static/style/common.scss"
</style>