Quellcode durchsuchen

首页接上接口,但没有对数据

littleblue55 vor 1 Woche
Ursprung
Commit
bef2bc4e23
3 geänderte Dateien mit 96 neuen und 11 gelöschten Zeilen
  1. 33 0
      api/home.js
  2. 20 0
      components/lgSwiper.vue
  3. 43 11
      pages/index/index.vue

+ 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'
+	})
+}

+ 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>