Explorar el Código

Merge branch 'master' of http://139.9.50.163:3000/Project2024/menber-center

LinWuTai hace 1 semana
padre
commit
402fc4a520
Se han modificado 6 ficheros con 256 adiciones y 102 borrados
  1. 33 0
      api/home.js
  2. 34 0
      api/user.js
  3. 20 0
      components/lgSwiper.vue
  4. 43 11
      pages/index/index.vue
  5. 123 88
      pages/login/login.vue
  6. 3 3
      utils/request.js

+ 33 - 0
api/home.js

@@ -0,0 +1,33 @@
+// 首页
+import request from '@/utils/request'
+
+// 获取推荐课程列表
+export function homeCourseList(){
+	return request({
+		'url': '/home/course',
+		headers: {
+			isToken: false
+		},
+		'method': 'get'
+	})
+}
+// 获取首页研究报告列表
+export function homeReportList() {
+	return request({
+		'url': '/home/report',
+		headers: {
+			isToken: false
+		},
+		'method': 'get'
+	})
+}
+// 获取样式设置
+export function homeSetting(){
+	return request({
+		'url': '/home/setting',
+		headers: {
+			isToken: false
+		},
+		'method': 'get'
+	})
+}

+ 34 - 0
api/user.js

@@ -25,6 +25,29 @@ export function register (data) {
 	})
 }
 
+
+// 加载数字校验码图片
+export function getCaptchaImage(){
+	return request({
+		'url': '/user/captcha/image',
+		headers: {
+			isToken: false
+		},
+		'method': 'get'
+	})
+}
+// 校验数字校验码
+export function checknumberCaptcha(data){
+	return request({
+		'url': '/user/captcha/verify',
+		headers: {
+			isToken: false
+		},
+		'method': 'post',
+		data: data
+	})
+}
+
 // 发送手机验证码
 export function smsSend (data) {
 	return request({
@@ -35,4 +58,15 @@ export function smsSend (data) {
 		'method': 'post',
 		'data': data
 	})
+}
+// 手机号码验证登录
+export function loginPhone(data){
+	return request({
+		'url': '/user/login/phone',
+		headers: {
+			isToken: false
+		},
+		'method': 'post',
+		'data': data
+	})
 }

+ 20 - 0
components/lgSwiper.vue

@@ -6,6 +6,14 @@
 			@change="changeCurrent">
 			<swiper-item v-for="(slide, index) in processedSildeItems" :key="index" style="overflow: initial;"
 				:class="index==currentIndex? 'swiper-item-active':'swiper-item-normal'" @click="swiperClick(slide)">
+				<!-- <view :class="index==currentIndex? 'swiper-item active':'swiper-item'">
+					<view style="width: 100%;height: 90%;">
+						<image style="width: 100%;height: 100%;" mode="aspectFit" :src="slide[image]"></image>
+					</view>
+					<view style="width: 100%;overflow: hidden;white-space: nowrap;">
+						<text class="swiper-text">{{ slide[title] }}</text>
+					</view>
+				</view> -->
 				<view :class="index==currentIndex? 'swiper-item active':'swiper-item'">
 					<image style="width: 100%;height: 90%;" mode="aspectFill" :src="slide[image]"></image>
 					<text class="swiper-text">{{ slide[title] }}</text>
@@ -75,8 +83,20 @@
 		align-items: center;
 		.swiper-text {
 				font-weight: bold;
+				display: inline-block;
+			  // animation: marquee 10s linear infinite;
+			  /* 以下属性防止文字换行 */
+			  white-space: nowrap;
 			}
 	}
+	@keyframes marquee {
+	  0% {
+	    transform: translateX(20%);
+	  }
+	  100% {
+	    transform: translateX(-100%);
+	  }
+	}
 
 	.swiper-item-normal {
 		z-index: 1;

+ 43 - 11
pages/index/index.vue

@@ -28,7 +28,8 @@
 					<u-section title="课程预告" sub-title="查看更多" sub-color="#000000"></u-section>
 				</template>
 				<template v-slot:body>
-					<lg-swiper :sildeItems="courseList" @swiperClick="swiperClick" image="courseImg"  title="courseName"></lg-swiper>
+					<lg-swiper v-if="reportList.length!=0" :sildeItems="courseList" @swiperClick="swiperClick" image="courseImg"  title="courseName"></lg-swiper>
+					<u-empty text="暂无内容" mode="data" v-else></u-empty>
 				</template>
 			</u-card>
 			<u-card padding="30" margin="0rpx 0rpx 30rpx" border-radius="20"
@@ -37,7 +38,7 @@
 					<u-section title="研究报告" sub-title="查看更多" sub-color="#000000"></u-section>
 				</template>
 				<template v-slot:body>
-					<view>
+					<view v-if="reportList.length!=0">
 						<view v-for="(data,index) in reportList" :key="index" class="u-body-item u-flex u-p-t-0 "
 							style="align-items: inherit;">
 							<image :src="data.imgUrl" mode="aspectFill"></image>
@@ -59,6 +60,7 @@
 							</view>
 						</view>
 					</view>
+					<u-empty text="暂无内容" mode="data" v-else></u-empty>
 				</template>
 			</u-card>
 		</view>
@@ -79,12 +81,18 @@
 	} from 'vue'
 	import {
 		onReady,
-		onLoad
+		onLoad,
+		onShow
 	} from '@dcloudio/uni-app'
 	import {
 		useAuthStore
 	} from '@/store/authStore'
 	import { count } from '@/api/chat.js'
+	import { 
+		homeCourseList,
+		homeReportList,
+		homeSetting
+	} from '@/api/home.js'
 	const authStore = useAuthStore()
 	// 屏幕状态栏高度
 	const statusBarHeight = ref(0)
@@ -258,16 +266,23 @@
 	const swiperClick = (data) => {
 		console.log(data, "课程预告数据")
 	}
-	onReady(() => {
-		uni.getSystemInfo({
-			success(e) {
-				statusBarHeight.value = e.statusBarHeight;
-				let custom = uni.getMenuButtonBoundingClientRect();
-				navBarHeight.value = custom.height + (custom.top - e.statusBarHeight) * 2;
+	
+	function init() {
+		homeCourseList().then(res=>{
+			if(res?.data){
+				courseList.value = res.data
 			}
 		})
-	})
-	onLoad(() => {
+		homeReportList().then(res=>{
+			if(res?.data){
+				reportList.value = res.data
+			}
+		})
+		// homeSetting().then(res=>{
+		// 	console.log(res)
+		// })
+	}
+	function getCharCount(){
 		count().then(res => {
 			if (res && res.message === 'success') {
 				uni.setTabBarBadge({ //显示数字
@@ -276,6 +291,23 @@
 				})
 			}
 		})
+	}
+	onReady(() => {
+		uni.getSystemInfo({
+			success(e) {
+				statusBarHeight.value = e.statusBarHeight;
+				let custom = uni.getMenuButtonBoundingClientRect();
+				navBarHeight.value = custom.height + (custom.top - e.statusBarHeight) * 2;
+			}
+		})
+	})
+	onLoad(() => {
+		init()
+	})
+	onShow(()=>{
+		if(isLogin){
+			getCharCount()
+		}
 	})
 </script>
 

+ 123 - 88
pages/login/login.vue

@@ -40,7 +40,7 @@
 					</view>
 					<view class="form-item">
 						<u-input height="80" placeholder="请输入密码" border-color="#d0d0d0" v-model="userNameForm.password"
-							:border="true" class="form-item-input" @confirm="userNameLoginHandle" />
+							:border="true" class="form-item-input" @confirm="userNameLoginHandle" type="password" password-icon/>
 					</view>
 					<view class="form-button" @click="userNameLoginHandle">
 						立即登录
@@ -59,12 +59,19 @@
 			<u-divider bg-color="transparent" margin-bottom="30" color="#010101" border-color="#010101"
 				half-width="200">使用第三方账号登录</u-divider>
 			<view class="app-icon mb-30">
-				<u-button v-if="canIUseGetUserProfile" @click="getUserProfile" class="custom-button"
+				<!-- v-if="canIUseGetUserProfile" -->
+				<u-button  @click="getUserProfile" class="custom-button"
+					style="width: 40px;" plain :hair-line="false">
+					<image src="https://sylwt.top/api/visitor/resources/image?name=/ydl/menber-center/weixin.png"
+						mode="aspectFit" style="width: 40px;height: 40px;" />
+				</u-button>
+				<!-- v-else -->
+				<u-button  open-type="getPhoneNumber" @getphonenumber="decryptPhoneNumber" class="custom-button"
 					style="width: 40px;" plain :hair-line="false">
 					<image src="https://sylwt.top/api/visitor/resources/image?name=/ydl/menber-center/weixin.png"
 						mode="aspectFit" style="width: 40px;height: 40px;" />
 				</u-button>
-				<u-button v-else open-type="getPhoneNumber" @getuserinfo="decryptPhoneNumber" class="custom-button"
+				<u-button  @click="handleWxLogin()" class="custom-button"
 					style="width: 40px;" plain :hair-line="false">
 					<image src="https://sylwt.top/api/visitor/resources/image?name=/ydl/menber-center/weixin.png"
 						mode="aspectFit" style="width: 40px;height: 40px;" />
@@ -82,7 +89,7 @@
 						v-model="numberCaptchaForm.numberCaptcha" :border="true" class="form-item-input"
 						style="flex-grow: 1;" @confirm="submitCode" />
 					<image :src="numberCaptchaSrc" mode="aspectFit"
-						style="height:40px;margin-left:20rpx;width: 180rpx;flex: 0 0 auto;"></image>
+						style="height:40px;margin-left:20rpx;width: 180rpx;flex: 0 0 auto;" @click="loadImage"></image>
 				</view>
 				<view class="popup-btn">
 					<u-button type="primary" @click="submitCode" style="width: 48%;flex: 0 0 auto;">提交</u-button>
@@ -102,7 +109,11 @@
 
 <script>
 	import {
-		usernameLogin
+		usernameLogin,
+		getCaptchaImage,
+		checknumberCaptcha,
+		smsSend,
+		loginPhone
 	} from "@/api/user.js"
 	import {
 		msg,
@@ -117,6 +128,7 @@
 	export default {
 		data() {
 			return {
+				getPhoneCapt: 0,
 				canIUseGetUserProfile: false,
 				loginCode: '',
 				userBookModal: false,
@@ -125,15 +137,15 @@
 					numberCaptcha: '',
 					numberCaptchaUuid: ''
 				},
-				numberCaptchaSrc: 'https://imgconvert.csdnimg.cn/aHR0cDovL3RjLnhpYW55dWNvZGVyLmNuL2Jsb2cyMDIwMDEwNDIwMzUwNy5wbmc?x-oss-process=image/format,png',
+				numberCaptchaSrc: '',
 				show: false,
 				tips: '',
 				seconds: 60,
 				// ----验证码 end -----
 				loginType: "phone",
 				phoneForm: {
-					phone: '15312341234',
-					captcha: '123456',
+					phone: '18320082803',
+					captcha: '',
 					captchaUuid: ''
 				},
 				userNameForm: {
@@ -168,35 +180,49 @@
 					phone,
 					captcha
 				} = this.phoneForm;
-
+				
 				// 手机号正则验证
 				if (!/^1[3-9]\d{9}$/.test(phone)) {
 					msg("请输入正确的手机号");
 					return;
 				}
+				
+				if(this.getPhoneCapt <= 0){
+					msg("请先获取手机验证码");
+					return;
+				}
+				
 				// 验证码存在性检查
 				if (!captcha) {
 					msg("请输入验证码");
 					return;
 				}
+				
 				let checkUserBook = await this.checkUserBook()
 				if (!this.checkUserBook()) return;
-				console.log(this.phoneForm)
+				// console.log(this.phoneForm)
+				uni.showLoading({
+					title: '正在登录...'
+				})
+				loginPhone(this.phoneForm).then(res=>{
+					// msg("登录成功");
+					console.log(res);
+				})
 				// 联调
 				// 1.登录 发送请求
 				// 2.保存 token
 				// 3.获取个人信息,保存个人新
 				msg("登录成功");
-				setTimeout(() => {
-					this.useAuthStore.setAuthToken("test")
-					uni.setStorageSync("userinfo", {
-						userId: "2121",
-						isMember: true
-					})
-					uni.switchTab({
-						url: "/pages/index/index"
-					})
-				}, 1000)
+				// setTimeout(() => {
+				// 	this.useAuthStore.setAuthToken("test")
+				// 	uni.setStorageSync("userinfo", {
+				// 		userId: "2121",
+				// 		isMember: true
+				// 	})
+				// 	uni.switchTab({
+				// 		url: "/pages/index/index"
+				// 	})
+				// }, 1000)
 
 			},
 			// 账号登录
@@ -218,9 +244,10 @@
 				}
 				form.password = encryptAESCBC(form.password);
 				usernameLogin(form).then(res => {
-					if (res?.token) {
+					// console.log(res, "登录")
+					if (res.data.token) {
 						msgSuccess("登录成功!")
-						this.useAuthStore.setAuthToken(res.token)
+						this.useAuthStore.setAuthToken(res.data.token)
 						setTimeout(() => {
 							uni.switchTab({
 								url: "/pages/index/index"
@@ -258,23 +285,13 @@
 			start() {
 				msg('倒计时开始');
 			},
+			// 数字校验码
 			showPopup() {
 				// 模拟向后端请求验证码
 				// 1.获取数字校验码图片
 				// 2.显示弹窗
-				uni.showLoading({
-					title: '正在获取图片'
-				})
-				console.log("获取数字验证码图片")
-				setTimeout(() => {
-					uni.hideLoading();
-					msg('获取成功');
-					// 显示模拟态,把获取过来的数字校对码的uuid赋给 numberCaptchaForm.numberCaptchaUuid
-					this.show = true;
-				}, 1500);
-				// 联调
-				// this.loadImage()
-				// this.show = true;
+				this.loadImage()
+				this.show = true;
 			},
 			closePopup() {
 				this.show = false;
@@ -288,86 +305,103 @@
 					});
 					return;
 				}
-				console.log("联调:验证数字验证码是否正确")
-				console.log("联调:发送手机验证码")
 				// 联调 检验是否正确
-				// const checkRes = await checknumberCaptcha();
-				// if(!checkRes){
-				// 	uni.showToast({
-				// 		title: '验证码输入错误',
-				// 		icon: 'none'
-				// 	});
-				// 	return;
-				// }
-				// // 发送手机验证码
-				// const codeRes = await getCodeApi();
-				// if(codeRes && codeRes.captchaUuid){
-				// 	this.phoneForm.captchaUuid = codeRes.captchaUuid
-				// 	this.closePopup();
-				// 	this.$refs.uCode1.start()
-				// }
-
 				uni.showLoading({
 					title: '正在校验验证码'
 				})
-				setTimeout(() => {
-					uni.hideLoading();
-					msg('填写正确');
+				
+				const checkRes = await checknumberCaptcha(this.numberCaptchaForm);
+				if(!checkRes.data.valid){
+					uni.showToast({
+						title: '验证码输入错误',
+						icon: 'none'
+					});
+					return;
+				}
+				// // 发送手机验证码
+				const codeRes = await smsSend({
+					phone: this.phoneForm.phone
+				});
+				
+				if(codeRes && codeResdata.captchaUuid){
+					this.getPhoneCapt++;
+					this.phoneForm.captchaUuid = codeRes.captchaUuid
 					this.closePopup();
 					this.$refs.uCode1.start()
-				}, 1500);
+				}
+
+				uni.hideLoading();
 			},
 			// 加载验证码图片
 			async loadImage() {
 				// 联调
-				// const img = await loadnumberCaptcha();
-				// this.numberCaptchaForm.numberCaptchaUuid = img.numberCaptchaUuid
-				// this.numberCaptchaSrc = img.numberCaptchaSrc
-				console.log("加载图片")
+				uni.showLoading({
+					title: '正在获取图片'
+				})
+				const img = await getCaptchaImage();
+				if(!img.data.numberCaptchaSrc){
+					return
+				}
+				this.numberCaptchaForm.numberCaptchaUuid = img.data.numberCaptchaUuid
+				this.numberCaptchaSrc = img.data.numberCaptchaSrc;
+				uni.hideLoading();
 			},
+			
 			// --------验证码 end---------
-			handleWxLogin() {
-				console.log("weixindenglu")
+			async handleWxLogin() {
+				try {
+				    // 获取code
+				    const loginRes = await uni.login({
+				      provider: 'weixin'
+				    });
+				    const code = loginRes.code;
+					console.log(11, loginRes);
+				  } catch (error) {
+				    console.error('微信登录失败:', error);
+				  }
 			},
 			decryptPhoneNumber(e) {
+				console.log(1111,e)
 				if (e.detail.encryptedData) {
 					const {
 						encryptedData,
-						iv
+						iv,
+						code
 					} = e.detail;
+					console.log(code)
 					// 将 encryptedData 和 iv 发送到后端进行解密
 				} else {
 					msg('取消授权手机号');
 				}
 			},
 			getUserProfile() {
-				this.toPage("/pages/wxLogin/wxLogin")
+				// this.toPage("/pages/wxLogin/wxLogin")
 				// 用户微信登录
-				// let that = this;
+				let that = this;
 				// 推荐使用uni.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认
 				// 开发者妥善保管用户快速填写的头像昵称,避免重复弹窗
-				// uni.getUserProfile({
-				// 	desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
-				// 	success: (resp) => {
-				// 		//登录远程服务器
-				// 		console.log(resp)
-				// 		if (that.loginCode) {
-				// 			//登录远程服务器
-				// 			console.log("登录远程服务器")
-				// 			// that.loginByWeixin(resp)
-				// 		} else {
-				// 			uni.login({
-				// 				success: function(resp) {
-				// 					if (resp.code) {
-				// 						that.code = resp.code
-				// 						console.log(resp)
-				// 						// that.loginByWeixin(resp)
-				// 					}
-				// 				}
-				// 			});
-				// 		}
-				// 	}
-				// })
+				uni.getUserProfile({
+					desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
+					success: (resp) => {
+						//登录远程服务器
+						console.log(2222, resp)
+						// if (that.loginCode) {
+						// 	//登录远程服务器
+						// 	console.log("登录远程服务器")
+						// 	// that.loginByWeixin(resp)
+						// } else {
+						// 	uni.login({
+						// 		success: function(resp) {
+						// 			if (resp.code) {
+						// 				that.code = resp.code
+						// 				console.log(resp)
+						// 				// that.loginByWeixin(resp)
+						// 			}
+						// 		}
+						// 	});
+						// }
+					}
+				})
 			}
 		},
 		// 在组件销毁时清理定时器
@@ -382,6 +416,7 @@
 		onLoad() {
 			const that = this;
 			if (uni.getUserProfile) {
+				console.log(1)
 				that.canIUseGetUserProfile = true
 			}
 		}

+ 3 - 3
utils/request.js

@@ -33,8 +33,8 @@ const request = config => {
 				header: config.headers,
 				dataType: 'json'
 			}).then(res => {
-				const code = res.data.code || 200;
-				const msg = errorCode[code] || res.data.msg || errorCode['default'];
+				const code = res.data.code || 0;
+				const msg = errorCode[code] || res.data.message || errorCode['default'];
 				if (code === 401) {
 					showConfirm('登录状态已过期,您可以继续留在该页面,或者重新登录?').then(res => {
 						if (res.confirm) {
@@ -47,7 +47,7 @@ const request = config => {
 				} else if (code === 500) {
 					toast(msg);
 					reject('500');
-				} else if (code !== 200) {
+				} else if (code !== 0) {
 					toast(msg);
 					reject(code);
 				}