guoyanqiang 3 months ago
parent
commit
c94de16b83
  1. 5
      src/api/homeApi.js
  2. 10
      src/api/zhiboApi.js
  3. 24
      src/views/ClubView.vue
  4. 309
      src/views/HomeView.vue
  5. 151
      src/views/LiveView.vue
  6. 27
      vite.config.js

5
src/api/homeApi.js

@ -1,9 +1,8 @@
import service from "./indexApi";
const homeApi = {
selectHome(queryType){
selectHome(){
//查询首页的数据
return service.post('/api/show/getShowList', {queryType: queryType});
return service.post('/api/show/getShowList');
}
}

10
src/api/zhiboApi.js

@ -0,0 +1,10 @@
import service from "./indexApi";
const zhiboApi = {
selectZhibo(queryType){
//查询首页的数据
return service.post('/api/live/getLiveList', {queryType: queryType});
}
}
export default zhiboApi;

24
src/views/ClubView.vue

@ -79,6 +79,25 @@
<script setup>
import { ref, onMounted } from 'vue';
import axios from 'axios';
//
const API_URL = 'http://192.168.8.235:8000/api/show/getShowList';
//
const fetchShowList = async () => {
try {
// POST
const response = await axios.post(API_URL);
//
console.log('接口返回数据:', response.data);
//
} catch (error) {
//
console.error('接口请求出错:', error);
}
};
const videos = ref([
{
@ -170,11 +189,12 @@ const loadFromLocalStorage = () => {
}
};
//
localStorage.removeItem('videos');
//
// onMounted
onMounted(() => {
fetchShowList();
loadFromLocalStorage();
});
</script>

309
src/views/HomeView.vue

@ -4,27 +4,27 @@
<el-col :span="17" :xs="24">
<div class="section-title">推荐</div>
<el-row :gutter="20" class="recommend-videos" style="margin-right: -25px;">
<el-col :span="24" v-for="video in video" :key="video.id">
<el-card class="video-card" @click="incrementViews(scope.row.id)">
<el-col :span="24" v-for="video in recommendedVideos" :key="video.id">
<el-card class="video-card">
<div class="video-content">
<img :src="video.cover" alt="视频缩略图" class="video-thumbnail" />
<img :src="video.thumbnail" alt="视频缩略图" class="video-thumbnail" />
<div class="video-info">
<div class="video-title1">{{ video.title }}</div>
<div style="text-align: left;"><img src="../pic/bogu.png" v-if="video.clubId == '1'" /><img v-else /></div>
<div style="text-align: left;"><img src="../pic/bogu.png" v-if="video.author == '博股俱乐部'" /><img v-else /></div>
<div class="video-meta1">
<img class="icon" :src="video.publisherAvatar" />
<span> {{ video.publisherName }} {{ video.publishTime }}</span>
<img class="icon" src="../pic/link.jpg" />
<span> {{ video.author }} {{ video.time }}</span>
<div class="video-stats">
<el-icon>
<View />
</el-icon>
<el-button type="text">{{ video.videoDuration }}</el-button>
<el-button type="text">{{ video.views }}</el-button>
<el-icon>
<ChatDotSquare />
</el-icon>
<el-button type="text">{{ video.likeCount }}</el-button>
<el-button type="text">{{ video.likes }}</el-button>
<img src="../pic/like.png" class="like">
<el-button type="text">{{ video.commentCount }}</el-button>
<el-button type="text">{{ video.comments }}</el-button>
</div>
</div>
</div>
@ -39,16 +39,16 @@
<el-col :span="24" v-for="video in featuredVideos" :key="video.id">
<el-card class="video-card">
<div class="video-content">
<img :src="video.cover" alt="视频缩略图" class="video-thumbnail" />
<img :src="video.thumbnail" alt="视频缩略图" class="video-thumbnail" />
<div class="video-info">
<div class="video-title2">{{ video.title }}</div>
<div class="video-meta2">
<div class="video-stats">
<el-icon class="my-icon">
<el-icon>
<View />
</el-icon>
<el-button type="text">{{ video.viewCount }}</el-button>
<el-button type="text">{{ video.publishTime }}</el-button>
<el-button type="text">{{ video.views }}</el-button>
<el-button type="text">{{ video.time }}</el-button>
<!-- <el-button type="text">{{ video.comments }}</el-button> -->
</div>
</div>
@ -63,172 +63,134 @@
</template>
<script setup>
import 'element-plus/dist/index.css';
import homeApi from '@/api/homeApi';
import { ref } from 'vue';
//
const video = ref([]);
//
function getAllRecommendedVideos(queryType) {
homeApi.selectHome(queryType)
.then(resp =>{
if(resp.data){
video.value = resp.data.list;
console.log(video.value);
}else{
console.log('获取推荐视频失败');
}
});
}
//
const featuredVideos = ref([]);
//
function getAllFeaturedVideos(queryType) {
homeApi.selectHome(queryType)
.then(resp =>{
if(resp.data){
featuredVideos.value = resp.data.list;
console.log(featuredVideos.value);
}else{
console.log('获取精选视频失败');
}
});
}
//
getAllRecommendedVideos(1);
getAllFeaturedVideos(2);
// const recommendedVideos = ref([
// {
// id: 1,
// thumbnail: 'src/pic/money.png',
// title: '5MCD()',
// author: '',
// time: '23',
// views: 15,
// likes: 0,
// comments: 1,
// },
// {
// id: 2,
// thumbnail: 'src/pic/touzi.png',
// title: '()(13.7.24)',
// author: 'STW',
// time: '07-16 17:47',
// views: 5,
// likes: 0,
// comments: 0,
// },
// {
// id: 3,
// thumbnail: 'src/pic/qiangshi.png',
// title: '',
// author: '',
// time: '01-24 09:55',
// views: 498,
// likes: 0,
// comments: 12,
// },
// {
// id: 4,
// thumbnail: 'src/pic/jihuigu.png',
// title: 'Josie(11.7.24)',
// author: 'STW',
// time: '07-16 17:37',
// views: 6,
// likes: 0,
// comments: 0,
// },
// {
// id: 5,
// thumbnail: 'src/pic/A.png',
// title: 'A',
// author: '',
// time: '07-16 16:22',
// views: 3,
// likes: 0,
// comments: 0,
// },
// ]);
import 'element-plus/dist/index.css';
// import homeApi from '@/api/homeApi';
//
// const video = ref([]);
//
// function getAllRecommendedVideos(queryType) {
// homeApi.selectHome()
// .then(resp =>{
// video.value = resp.data.QueryRecommend;
// });
// }
//
// getAllRecommendedVideos(1);
const recommendedVideos = ref([
{
id: 1,
thumbnail: 'src/pic/money.png',
title: '【机构财富密码破局之道5】MCD六彩神龙之吉龙抬头(普通话)',
author: '小金',
time: '23小时前',
views: 15,
likes: 0,
comments: 1,
},
{
id: 2,
thumbnail: 'src/pic/touzi.png',
title: '投资的真谛(永远的价值投资)一陆健大师(13.7.24)',
author: 'STW',
time: '07-16 17:47',
views: 5,
likes: 0,
comments: 0,
},
{
id: 3,
thumbnail: 'src/pic/qiangshi.png',
title: '第二节《强势结构形态》',
author: '博股俱乐部',
time: '01-24 09:55',
views: 498,
likes: 0,
comments: 12,
},
{
id: 4,
thumbnail: 'src/pic/jihuigu.png',
title: '价值投资之机会谷一Josie老师(11.7.24)',
author: 'STW',
time: '07-16 17:37',
views: 6,
likes: 0,
comments: 0,
},
{
id: 5,
thumbnail: 'src/pic/A.png',
title: 'A股释放积极信号!一大批上市公司发布回购、业绩预增等公告',
author: '宋建军',
time: '07-16 16:22',
views: 3,
likes: 0,
comments: 0,
},
]);
//
// const featuredVideos = ref([
// {
// id: 1,
// thumbnail: 'src/pic/wengehua.png',
// title: '-',
// author: 'CANADA',
// time: '07-08 19:47',
// views: 523,
// likes: 0,
// comments: 0,
// },
// {
// id: 2,
// thumbnail: 'src/pic/shengkuang.png',
// title: '',
// author: '',
// time: '07-08 19:47',
// views: 307,
// likes: 0,
// comments: 0,
// },
// {
// id: 3,
// thumbnail: 'src/pic/jinrongzhan.png',
// title: '-',
// author: '',
// time: '06-27 17:30',
// views: 144,
// likes: 0,
// comments: 0,
// },
// {
// id: 4,
// thumbnail: 'src/pic/youxueban.png',
// title: '',
// author: '',
// time: '06-29 19:11',
// views: 658,
// likes: 0,
// comments: 0,
// },
// {
// id: 5,
// thumbnail: 'src/pic/meiyuanbaquan.png',
// title: '""...',
// author: '',
// time: '06-18 14:00',
// views: 538,
// likes: 0,
// comments: 0,
// },
// ]);
const featuredVideos = ref([
{
id: 1,
thumbnail: 'src/pic/wengehua.png',
title: '温哥华弘粉之约-北美同城会陪你共话投资',
author: 'CANADA',
time: '07-08 19:47',
views: 523,
likes: 0,
comments: 0,
},
{
id: 2,
thumbnail: 'src/pic/shengkuang.png',
title: '盛况!香港弘粉同城会圆满成功!',
author: '精彩回顾',
time: '07-08 19:47',
views: 307,
likes: 0,
comments: 0,
},
{
id: 3,
thumbnail: 'src/pic/jinrongzhan.png',
title: '金融战事再升级-欧盟对中国电动车征税的真相',
author: '精彩回顾',
time: '06-27 17:30',
views: 144,
likes: 0,
comments: 0,
},
{
id: 4,
thumbnail: 'src/pic/youxueban.png',
title: '弘粉游学班:赏美景、品美食、学投资!',
author: '精彩回顾',
time: '06-29 19:11',
views: 658,
likes: 0,
comments: 0,
},
{
id: 5,
thumbnail: 'src/pic/meiyuanbaquan.png',
title: '美元霸权地位动摇!"石油美元"时代...',
author: '精彩回顾',
time: '06-18 14:00',
views: 538,
likes: 0,
comments: 0,
},
]);
</script>
<style scoped>
.video-card:hover{
transform: scale(1.01);
}
.my-icon{
right: 3px;
}
.like {
height: 14px;
width: 14px;
@ -313,7 +275,6 @@ span {
align-items: center;
font-size: 14px;
color: #666;
padding-top: 40px;
}

151
src/views/LiveView.vue

@ -3,17 +3,17 @@
<div class="course-grid">
<div v-for="course in courses" :key="course.id" class="course-card">
<div class="course-image">
<img :src="course.image" alt="课程图片">
<img :src="course.cover" alt="课程图片">
<div class="live-badge">即将开播</div>
<div class="live-time">{{ course.time }}</div>
<div class="live-time">{{ course.startTime }}</div>
</div>
<div class="course-info">
<div class="course-title">{{ course.title }}</div>
<div class="course-footer">
<div class="course-tag">
<img :src="course.avatar" alt="讲师头像">
<img :src="course.cover" alt="讲师头像">
<!-- <img src="../pic/images/1.png" alt="讲师头像"> -->
{{ course.teacher }}
{{ course.publisherName }}
</div>
<button class="book-btn" :class="{ active: course.booked }" @click="toggleBook(course.id)">预约</button>
</div>
@ -23,141 +23,24 @@
</div>
</template>
<script>
<script setup>
import zhiboApi from '@/api/zhiboApi';
import { ref } from 'vue';
const courses = ref([
]);
export default {
name: 'LiveCourses',
setup() {
const courses = ref([
{
id: 1,
title: '猎庄之顶级波段我公司不...',
teacher: '猎庄之顶级波段',
time: '明天09:55开播',
image: 'src/pic/images/1.png',
avatar: 'src/pic/images/link.jpg',
booked: false
},
{
id: 2,
title: '如何提前把握大盘和个股...',
teacher: '多空识庄短线寻...',
time: '明天10:00开播',
image: 'src/pic/images/2.png',
avatar: 'src/pic/images/link.jpg',
booked: false
},
{
id: 3,
title: '【粤语】AI铁皮训练-Tom...',
teacher: '【粤语】AI铁皮...',
time: '明天11:30开播',
image: 'src/pic/images/3.png',
avatar: 'src/pic/images/link.jpg',
booked: false
},
{
id: 4,
title: '构建有效的价值投资体系...',
teacher: '构建有效的价值...',
time: '明天20:30开播',
image: 'src/pic/images/4.png',
avatar: 'src/pic/images/link.jpg',
booked: false
},
{
id: 5,
title: '猎庄之顶级波段我公司不...',
teacher: '猎庄之顶级波段',
time: '明天09:55开播',
image: 'src/pic/images/5.png',
avatar: 'src/pic/images/link.jpg',
booked: false
},
{
id: 6,
title: '如何提前把握大盘和个股...',
teacher: '多空识庄短线寻...',
time: '明天10:00开播',
image: 'src/pic/images/6.png',
avatar: 'src/pic/images/link.jpg',
booked: false
},
{
id: 7,
title: '【粤语】AI铁皮训练-Tom...',
teacher: '【粤语】AI铁皮...',
time: '明天11:30开播',
image: 'src/pic/images/7.png',
avatar: 'src/pic/images/link.jpg',
booked: false
},
{
id: 8,
title: '构建有效的价值投资体系...',
teacher: '构建有效的价值...',
time: '明天20:30开播',
image: 'src/pic/images/8.png',
avatar: 'src/pic/images/link.jpg',
booked: false
}
]);
const toggleBook = async (id) => {
const courseIndex = courses.value.findIndex(course => course.id === id);
if (courseIndex !== -1) {
const course = courses.value[courseIndex];
try {
if (!course.booked) {
// - POST
const response = await fetch(`https://your-backend-api.com/bookings/${id}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
courseId: id
})
});
if (!response.ok) {
throw new Error('预约失败');
}
//
course.booked = true;
alert(`您已成功预约课程:${course.title}`);
} else {
// - DELETE
const response = await fetch(`https://your-backend-api.com/bookings/${id}`, {
method: 'DELETE',
headers: {
'Content-Type': 'application/json',
}
});
if (!response.ok) {
throw new Error('取消预约失败');
}
function formatTime(queryType) {
zhiboApi.selectZhibo(queryType).then(resp => {
if(resp.data){
courses.value = resp.data.list;
console.log(courses.value);
}
})
}
//
course.booked = false;
alert(`您已取消预约课程:${course.title}`);
}
} catch (error) {
console.error('预约请求失败:', error);
alert('预约请求失败,请稍后再试');
}
}
};
formatTime();
return {
courses,
toggleBook
};
}
};
</script>
<style scoped>

27
vite.config.js

@ -1,18 +1,25 @@
import { fileURLToPath, URL } from 'node:url'
import { fileURLToPath, URL } from 'node:url';
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import vueDevTools from 'vite-plugin-vue-devtools';
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueDevTools from 'vite-plugin-vue-devtools'
// https://vite.dev/config/
export default defineConfig({
server: {
proxy: {
'/api': {
target: 'http://192.168.8.235:8000', // 后端服务器地址
changeOrigin: true, // 改变请求源
rewrite: (path) => path.replace(/^\/api/, '') // 重写路径,去掉 /api
}
}
},
plugins: [
vue(),
vueDevTools(),
vueDevTools()
],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
},
},
})
}
}
});
Loading…
Cancel
Save