Forráskód Böngészése

feat(controller): 获取用户信息

xiansin 3 éve
szülő
commit
81e8e2bf2a
4 módosított fájl, 57 hozzáadás és 9 törlés
  1. 2 0
      core/apiList.js
  2. 3 0
      core/http.api.js
  3. 16 6
      core/http.interceptor.js
  4. 36 3
      pages/my/index.vue

+ 2 - 0
core/apiList.js

xqd
@@ -23,6 +23,8 @@ module.exports = {
     userShares: '/user/shares',
     // 绑定上级
     userBind: '/user/bind',
+    // 用户绑定手机号
+    userBindPhone: '/user/bindPhone',
 
     // 提现申请
     withdrawApply: '/withdraw/apply',

+ 3 - 0
core/http.api.js

xqd xqd
@@ -28,6 +28,8 @@ const install = (Vue, vm) => {
 	const userShares = (params = {}) => vm.$u.get(apiList.userShares, params)
 	// 提现列表
 	const userBind = (data = {}) => vm.$u.post(apiList.userBind, data)
+	// 用户绑定手机号
+	const userBindPhone = (data = {}) => vm.$u.post(apiList.userBindPhone, data)
 
 	//将各个定义的接口名称,统一放进对象挂载到vm.$u.api(因为vm就是this,也即this.$u.api)下
 	vm.$u.api = {
@@ -43,6 +45,7 @@ const install = (Vue, vm) => {
 		userQuery,
 		userShares,
 		userBind,
+		userBindPhone,
 
 		withdrawApply,
 		withdrawLists,

+ 16 - 6
core/http.interceptor.js

xqd xqd
@@ -9,7 +9,7 @@ const install = (Vue, vm) => {
 		showLoading: true, // 是否显示请求中的loading
 		loadingText: '努力加载中...', // 请求loading中的文字提示
 		loadingTime: 300, // 在此时间内,请求还没回来的话,就显示加载中动画,单位ms
-		originalData: false, // 是否在拦截器中返回服务端的原始数据
+		originalData: true, // 是否在拦截器中返回服务端的原始数据
 		loadingMask: true, // 展示loading的时候,是否给一个透明的蒙层,防止触摸穿透
 		// 配置请求头信息
 		header: {
@@ -26,13 +26,23 @@ const install = (Vue, vm) => {
 	Vue.prototype.$u.http.interceptor.response = (res) => {
 		// 如果把originalData设置为了true,这里得到将会是服务器返回的所有的原始数据
 		// 判断可能变成了res.statueCode,或者res.data.code之类的,请打印查看结果
-		if(res.code === 200) {
-			// 如果把originalData设置为了true,这里return回什么,this.$u.post的then回调中就会得到什么
-			return typeof res.data === 'string' ? JSON.parse(res.data) : res.data;
-		} else {
+		if(res.statusCode === 200){
+			res = res.data;
+			if(res.code === 200) {
+				// 如果把originalData设置为了true,这里return回什么,this.$u.post的then回调中就会得到什么
+				return typeof res.data === 'string' ? JSON.parse(res.data) : res.data;
+			}else {
+				uni.showModal({
+					title: '提示',
+					content: res.message,
+					showCancel: false,
+				});
+				return false;
+			}
+		}else{
 			uni.showModal({
 				title: '提示',
-				content: res.message,
+				content: '服务器错误!'+res.data.message,
 				showCancel: false,
 			});
 			return false;

+ 36 - 3
pages/my/index.vue

xqd xqd xqd xqd xqd
@@ -13,12 +13,12 @@
 					</view>
 					<view class="nickname">{{userData.nickname}}</view>
 					<view class="mobile">
-						{{userData.phone_num}}
 						<!--#ifdef MP-WEIXIN-->
 						<u-button size="mini"
 								  v-if="!userData.phone_num"
 								  :custom-style="{backgroundColor: '#097268'}"
 								  type="success" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">获取手机号</u-button>
+						<text v-else>{{userData.phone_num}}</text>
 						<!--#endif-->
 					</view>
 				</view>
@@ -40,6 +40,8 @@
 				<u-cell-item title="在线客服" :border-bottom="false" bg-color="#f9f9f9">
 					<view slot="icon" class="icon kefu"></view>
 				</u-cell-item>
+				<u-cell-item title="清除缓存" :border-bottom="false" icon="reload" bg-color="#f9f9f9" @click="handleClearCache">
+				</u-cell-item>
 			</u-cell-group>
 			<view class="qrcode dir-top-wrap cross-center">
 				<view class="img">
@@ -52,6 +54,16 @@
 				<text class="title">扫描二维码联系客服</text>
 			</view>
 		</view>
+		<u-modal v-model="modal.show"
+				 :show-cancel-button="true"
+				 content="确定清除缓存?"
+				 cancel-text="取消"
+				 cancel-color="#CCCCCC"
+				 confirm-text="确定"
+				 confirm-color="#046E64"
+				 @confirm="sureClearCache"
+		>
+		</u-modal>
 	</app-layout>
 </template>
 
@@ -64,12 +76,25 @@
 		data() {
 			return {
 				userData: this.vuex_user_data,
-				setting: {}
+				setting: {},
+				modal: {
+					show : false
+				}
 			}
 		},
 		methods: {
 			getPhoneNumber(phoneNumber){
-				console.log('-->data',phoneNumber)
+				uni.checkSession({
+					success: data => {
+						this.$u.api.userBindPhone(phoneNumber.detail).then(data => {
+							this.$u.vuex(this.$const.USER_DATA,data)
+							this.userData = data;
+						})
+					},
+					fail: err => {
+						this.sureClearCache()
+					}
+				})
 			},
 			getUser(){
 				this.$u.api.userGet().then(data => {
@@ -80,6 +105,14 @@
 				this.$u.api.settingGet().then(data => {
 					this.setting = data;
 				})
+			},
+			handleClearCache(){
+				this.modal.show = true
+			},
+			sureClearCache(){
+				this.$u.vuex(this.$const.USER_TOKEN,null)
+				this.$u.vuex(this.$const.USER_DATA,null)
+				this.$jump({url:'/pages/login/login?redirect=pages/my/index',type:'redirect'})
 			}
 		},
 		onLoad(){