achao 2 年之前
父节点
当前提交
54f78562bd
共有 1 个文件被更改,包括 53 次插入2 次删除
  1. 53 2
      xiaochengxu/pages/cardHolder/cardHolder.vue

+ 53 - 2
xiaochengxu/pages/cardHolder/cardHolder.vue

@@ -92,12 +92,63 @@
 			};
 		},
 		onShow() {
+			if (uni.getStorageSync("userInfo")) {
+				this.userInfo = uni.getStorageSync("userInfo")
+				this.init()
+			} else {
+				this.login()
+			}
 			this.searchVal = uni.getStorageSync("search_val") ? uni.getStorageSync("search_val") : ''
 		},
 		methods: {
-			toNotice(){
+			init(){
+				
+			},
+			login() {
+				let that = this
+				uni.login({
+					"provider": "weixin",
+					success: function(wxres) {
+						that.$request.baseRequest('commonUserApp', 'commonUserLogin', {
+							loginType: 1,
+							raw: JSON.stringify(wxres)
+						}, failres => {
+							this.$refs.uToast.show({
+								type: 'error',
+								message: failres.errmsg,
+							})
+							uni.hideLoading()
+						}).then(res => {
+							uni.getUserInfo({
+								provider: 'weixin',
+								success: function(info) {
+									console.log(info)
+									res.data.nickname = info.userInfo.nickName
+									res.data.head = info.userInfo.avatarUrl
+									that.$request.baseRequest('commonUserApp', 'edit', {
+										commonUserInfo: JSON.stringify(res.data)
+									}, failres => {
+										this.$refs.uToast.show({
+											type: 'error',
+											message: failres.errmsg,
+										})
+										uni.hideLoading()
+									}).then(res1 => {
+										uni.setStorageSync("userInfo",res1.data)
+									})
+								}
+							})
+						})
+					},
+					fail: function(err) {
+						// 登录授权失败  
+						// err.code是错误码
+					}
+				})
+			},
+			toNotice() {
 				uni.navigateTo({
-					url:"/pages/cardHolder/notice"
+					url: "/pages/cardHolder/notice"
 				})
 			},
 			micOpen: function() {