wangguoyu 2 місяців тому
батько
коміт
b83dc8d608
4 змінених файлів з 110 додано та 27 видалено
  1. 11 0
      api/my.js
  2. 20 8
      pages/my/headImg.vue
  3. 42 15
      pages/my/index.vue
  4. 37 4
      pages/my/yingyongshezhi.vue

+ 11 - 0
api/my.js

@@ -88,4 +88,15 @@ export function getFilePolicy(data = {}) {
     data,
     timeout: 20000
   })
+}
+export function updataHead(data = {}) {
+  return request({
+    'url': '/app/user/my/update/icon',
+    headers: {
+      isToken: true
+    },
+    method: 'post',
+    data,
+    timeout: 20000
+  })
 }

+ 20 - 8
pages/my/headImg.vue

@@ -19,7 +19,8 @@
 	} from "@/utils/common";
 	import cacheManager from '@/utils/cacheManager.js';
 	import {
-		getFilePolicy
+		getFilePolicy,
+		updataHead
 	} from '@/api/my.js'
 	import {
 		onLoad
@@ -66,7 +67,20 @@
 			})
 		}
 	}
-
+	function updateIcon(data){
+		updataHead({icon:data}).then(res=>{
+			if(res.code ==0){
+			uni.showToast({
+				title: '上传成功',
+				icon: 'success'
+			});	
+			}else{
+				uni.showToast({
+					title: '上传失败',
+				});
+			}
+		})
+	}
 	function uploadFile(filePath) {
 		const suffix = filePath.split('.').pop();
 		let req = {
@@ -94,15 +108,13 @@
 					success(uploadRes) {
 						console.log('uploadRes', uploadRes);
 						if (uploadRes.statusCode === 200) {
-							userImg.value = `${policyData.downloadUrl}/${policyData.key}`;
-							uni.showToast({
-								title: '上传成功',
-								icon: 'success'
-							});
+							userImg.value = `${policyData.downloadUrl}/${policyData.key}`;					
+							updateIcon(userImg.value)
 						} else {
 							uni.showToast({
-								title: '上传失败',
+								title: '阿里云上传错误,请重试!',
 							});
+							return false
 						}
 					},
 					fail(err) {

+ 42 - 15
pages/my/index.vue

@@ -1,9 +1,9 @@
 <template>
 	<view class="ezy-my-page">
 		<view class="my-head-box">
-			<icon class="head-img-box" :style="{backgroundImage: 'url(' + myInfoData.userImg + ')'}"></icon>
+			<icon class="head-img-box" :style="{backgroundImage: 'url(' + myInfoData.icon + ')'}"></icon>
 			<view class="head-content-box">
-				<text>{{myInfoData.userName}}</text>
+				<text>{{myInfoData.nickName}}</text>
 				<view class="ezy-jf-box" v-if="loginFlag">
 					<icon class="jf-icon"></icon>
 					<text class="jf-text">{{myInfoData.credit}}</text>
@@ -46,7 +46,7 @@
 			<view v-if="loginFlag" class="list-row" @click="xxjlClick">
 				<icon class="list-icon sxtk-icon"></icon>
 				<text>学习记录</text>
-			</view>	
+			</view>
 			<view v-if="loginFlag" class="list-row" @click="xxscClick">
 				<icon class="list-icon sxtk-icon"></icon>
 				<text>学习时长</text>
@@ -163,6 +163,8 @@
 		userName: '',
 		credit: '',
 		vipFlag: '',
+		nickName: '',
+		icon: '',
 	});
 	let routerOpt = ref(false);
 	let appleCode = ref(null);
@@ -267,11 +269,21 @@
 		uni.redirectTo({
 			url: '/pages/login/index'
 		});
-	}
+	}
+
 	function yingyongshezhi() {
-		uni.redirectTo({
-			url: '/pages/my/yingyongshezhi'
-		});
+		if (loginFlag.value) {
+			const AuthCode = getUserIdentity();
+			if (AuthCode == 'Visitor') {
+				youkeDialogRef.value.handleShow();
+				return;
+			}
+			uni.redirectTo({
+				url: '/pages/my/yingyongshezhi'
+			});
+		} else {
+			youkeDialogRef.value.handleShow();
+		}
 	}
 
 	// 手机号码
@@ -319,7 +331,8 @@
 		uni.redirectTo({
 			url: '/pages/my/xuexiJilu'
 		});
-	}
+	}
+
 	function xxscClick() {
 		uni.redirectTo({
 			url: '/pages/my/xuexishichang'
@@ -354,9 +367,22 @@
 	// 获取用户数据
 	function getMyInfo() {
 		myInfo({}).then(res => {
-			getUserImg(res.data.growthType)
+
 			myInfoData.userName = res.data.userName;
 			myInfoData.credit = res.data.credit;
+
+			myInfoData.nickName = res.data.nickName;
+
+			if (res.data.nickName) {
+				myInfoData.nickName = res.data.nickName;
+			} else {
+				myInfoData.nickName = '鹅状元';
+			}
+			if (res.data.icon) {
+				myInfoData.icon = res.data.icon;
+			} else {
+				getUserImg(res.data.growthType)
+			}
 		})
 		getMyCardList();
 	}
@@ -377,19 +403,19 @@
 	function getUserImg(data) {
 		switch (data) {
 			case 0:
-				myInfoData.userImg = 'static/images/my/head-img0.png'
+				myInfoData.icon = 'static/images/my/head-img0.png'
 				break;
 			case 1:
-				myInfoData.userImg = 'static/images/my/head-img1.png'
+				myInfoData.icon = 'static/images/my/head-img1.png'
 				break;
 			case 2:
-				myInfoData.userImg = 'static/images/my/head-img2.png'
+				myInfoData.icon = 'static/images/my/head-img2.png'
 				break;
 			case 3:
-				myInfoData.userImg = 'static/images/my/head-img3.png'
+				myInfoData.icon = 'static/images/my/head-img3.png'
 				break;
 			default:
-				myInfoData.userImg = 'static/images/my/head-unlogin-img.png'
+				myInfoData.icon = 'static/images/my/head-unlogin-img.png'
 				break;
 
 		}
@@ -432,7 +458,8 @@
 		// my游客
 		loginFlag.value = false;
 		myInfoData.userName = '游客';
-		myInfoData.userImg = 'static/images/my/head-unlogin-img.png'
+		myInfoData.nickName = '鹅状元';
+		myInfoData.icon = 'static/images/my/head-unlogin-img.png'
 	}
 
 	// 非游客

+ 37 - 4
pages/my/yingyongshezhi.vue

@@ -8,12 +8,12 @@
 			<view class="list-row" @click="headClick">
 				<icon class="list-icon tel-icon"></icon>
 				<text>头像</text>
-				<icon class="head-img-box" :style="{backgroundImage: 'url(' + myInfoData.userImg + ')'}"></icon>
+				<icon style="width: 20px;height: 20px;" class="head-img-box" :style="{backgroundImage: 'url(' + myInfoData.icon + ')'}"></icon>
 			</view>
 			<view class="list-row" @click="nichengClick">
 				<icon class="list-icon tel-icon"></icon>
 				<text>昵称</text>
-				<text>{{myInfoData.nichengValue}}</text>
+				<text>{{myInfoData.nickName}}</text>
 			</view>
 			<view class="list-row" @click="telClick">
 				<icon class="list-icon tel-icon"></icon>
@@ -103,7 +103,8 @@
 		userName: '',
 		credit: '',
 		vipFlag: '',
-		nichengValue: '',
+		nickName: '',
+		icon: '',
 	});
 	let routerOpt = ref(false);
 	let appleCode = ref(null);
@@ -180,7 +181,7 @@
 		nichengUpdate(req).then(res => {
 			if (res.code == 0) {
 				toast('修改成功')
-				myInfoData.nichengValue = data
+				myInfoData.nickName = data
 			} else {
 				toast('修改失败请重试或联系管理员')
 				return false
@@ -237,9 +238,41 @@
 		myInfo({}).then(res => {
 			myInfoData.userName = res.data.userName;
 			myInfoData.credit = res.data.credit;
+			myInfoData.nickName = res.data.nickName;
+			
+			if (res.data.nickName) {
+				myInfoData.nickName = res.data.nickName;
+			} else {
+				myInfoData.nickName = '鹅状元';
+			}
+			if (res.data.icon) {
+				myInfoData.icon = res.data.icon;
+			} else {
+				getUserImg(res.data.growthType)
+			}
+			
 		})
 	}
+	function getUserImg(data) {
+		switch (data) {
+			case 0:
+				myInfoData.icon = 'static/images/my/head-img0.png'
+				break;
+			case 1:
+				myInfoData.icon = 'static/images/my/head-img1.png'
+				break;
+			case 2:
+				myInfoData.icon = 'static/images/my/head-img2.png'
+				break;
+			case 3:
+				myInfoData.icon = 'static/images/my/head-img3.png'
+				break;
+			default:
+				myInfoData.icon = 'static/images/my/head-unlogin-img.png'
+				break;
 
+		}
+	}
 	function isIOSorAndroid() {
 		const systemInfo = uni.getSystemInfoSync();