65 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Python
		
	
	
	
			
		
		
	
	
			65 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Python
		
	
	
	
| <script>
 | ||
| 	export default {
 | ||
| 		// 此处globalData为了演示其作用,不是uView框架的一部分
 | ||
| 		globalData: {
 | ||
| 			username: '白居易'
 | ||
| 		},
 | ||
| 		onLaunch() {
 | ||
| 			// 1.1.0版本之前关于http拦截器代码,已平滑移动到/common/http.interceptor.js中
 | ||
| 			// 注意,需要在/main.js中实例化Vue之后引入如下(详见文档说明):
 | ||
| 			// import httpInterceptor from '@/common/http.interceptor.js'
 | ||
| 			// Vue.use(httpInterceptor, app)
 | ||
| 			// process.env.VUE_APP_PLATFORM 为通过js判断平台名称的方法,结果分别如下:
 | ||
| 			/**
 | ||
| 			 * h5,app-plus(nvue下也为app-plus),mp-weixin,mp-alipay......
 | ||
| 			 */
 | ||
| 			//var that=this
 | ||
| 			// 小程序自动登录
 | ||
| 			uni.showLoading({
 | ||
| 				title: '微信自动登录中...',
 | ||
| 				mask: true
 | ||
| 			})
 | ||
| 			uni.login({
 | ||
| 				provider: 'weixin',
 | ||
| 				success: (loginRes) => {
 | ||
| 					this.$u.api.wxmplogin({
 | ||
| 						code: loginRes.code
 | ||
| 					}).then(res => {
 | ||
| 						this.$u.vuex('vuex_token', res.data.access)
 | ||
| 						this.$u.api.getUserInfo().then(res => {
 | ||
| 							uni.hideLoading()
 | ||
| 							uni.showToast({
 | ||
| 								title: "登录成功",
 | ||
| 								icon: "none"
 | ||
| 							})
 | ||
| 							uni.reLaunch({
 | ||
| 								url: "/pages/home/home"
 | ||
| 							})
 | ||
| 							this.$u.vuex('vuex_user', res.data)
 | ||
| 							// 修改资源请求地址
 | ||
| 							this.$u.vuex('vuex_user.avatar', this.vuex_user.avatar +
 | ||
| 								'?token=' + this.vuex_token)
 | ||
| 						})
 | ||
| 					}).catch(e => {
 | ||
| 						uni.hideLoading()
 | ||
| 						// uni.showToast({
 | ||
| 						// 	title: "暂未绑定微信!",
 | ||
| 						// 	icon: "none"
 | ||
| 						// })
 | ||
| 						uni.reLaunch({
 | ||
| 							url: '/pages/login/login'
 | ||
| 						})
 | ||
| 					})
 | ||
| 				}
 | ||
| 			});
 | ||
| 
 | ||
| 		},
 | ||
| 	}
 | ||
| </script>
 | ||
| 
 | ||
| <style lang="scss">
 | ||
| 	@import "uview-ui/index.scss";
 | ||
| 	@import "common/demo.scss";
 | ||
| 	@import "common/uni-ui.scss";
 | ||
| </style>
 |