courseDetail.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608
  1. <template>
  2. <view>
  3. <view v-if="!loginShow" class="container" :style="{ height : `${loginShow ? '100vh' : 'auto' }`,
  4. overflow: `${loginShow ? 'hidden' : 'auto' }` }">
  5. <view class="container-poster" style="width: 100%;padding: 0 20rpx;">
  6. <channel-live v-if="feedShow" :feed-id="feedId" :finder-user-name="finderId"></channel-live>
  7. <image v-else show-menu-by-longpress :src="courseDetail.poster?courseDetail.poster:''" mode="widthFix"
  8. style="width: 100%;"></image>
  9. </view>
  10. <view class="course-tab-list">
  11. <view class="course-tab-item" v-for="(data, index) in items" :key="index" @click="onClickItem(index)"
  12. :class="currentTab === index ? 'tab-active' : ''">
  13. {{ data }}
  14. </view>
  15. </view>
  16. <view class="content" v-if="currentTab === 0" style="overflow: hidden;">
  17. <view class="content-text"
  18. :style="{
  19. marginBottom: `${videoShow?'140rpx':'0'}`,
  20. paddingBottom: `${videoShow?'150rpx':'0'}`
  21. }"
  22. style="height: 100%;overflow: scroll;padding-left: 20rpx;padding-right: 20rpx;">
  23. <view class="text-title">{{courseDetail.title}}</view>
  24. <view class="text-title">课程概述</view>
  25. <view class="text-content">{{courseDetail.summary}}</view>
  26. <view class="text-title">课程时间</view>
  27. <view class="text-content">{{courseDetail.date ? getDateWeek(courseDetail.date) : ''}}</view>
  28. <view class="text-title">培训地点</view>
  29. <view class="text-content">{{courseDetail.loc}}</view>
  30. <view class="text-title">如需取消报名,请联系培训服务部刘小姐取消报名,电话:13332876414。</view>
  31. <view class="text-tip" v-if="!isMember && courseDetail.viewMode === '2'">个人会员或单位会员免费,点击现在入会></view>
  32. <view style="width: 100%;height: 200rpx;"></view>
  33. </view>
  34. <view class="section-bottom-fixed" @click="toVideo" v-show="videoShow">
  35. <text>预约课程</text>
  36. </view>
  37. <view :class="['section-bottom-fixed', `${courseDetail.hasReg ? 'bg-blue' : ''}`]" v-show="regShow" @click="toReg">
  38. <text>{{ courseDetail?.hasReg ? '报名成功' : '点击报名' }}</text>
  39. </view>
  40. </view>
  41. <view class="content" v-if="currentTab === 1" style="overflow: hidden;">
  42. <view class=""
  43. style="margin-bottom: 140rpx;padding-bottom: 150rpx;height: 100%;overflow: scroll;padding-left: 20rpx;padding-right: 20rpx;">
  44. <view v-for="(comment, index) in sortedCommentList" :key="index" class="comment-list-item">
  45. <view class="comment-list-left">
  46. <image :src="comment.icon" class="comment-list-avator"></image>
  47. </view>
  48. <view class="comment-list-right">
  49. <view style="margin-bottom: 15rpx;">
  50. <text class="comment-list-username">{{ comment.username }}</text>
  51. <text class="comment-list-moment">{{ formatTime(comment.commentTime) }}</text>
  52. </view>
  53. <view>{{ comment.content }}</view>
  54. </view>
  55. </view>
  56. </view>
  57. <view class="section-bottom " style="background-color: #f2f2f2;">
  58. <view class="comment-input-box">
  59. <u-input :custom-style="inputStyle" class="comment-input" v-model="comment" :border="false"
  60. placeholder="写留言" height="60" adjust-position />
  61. <u-button class="comment-button" :hair-line="false" :custom-style="customStyle"
  62. @click="toSend">发送</u-button>
  63. </view>
  64. </view>
  65. </view>
  66. </view>
  67. <u-popup v-model="loginShow" :mask="false" :closeable='false' mode="bottom" :mask-close-able='false'
  68. safe-area-inset-bottom>
  69. <view style="height: 70vh;padding: 40rpx;position: relative;background:none;">
  70. <view style="text-align: center;margin: 70rpx 0;">
  71. <u-button size="medium" type="error" @click="toLogin">登录查看</u-button>
  72. </view>
  73. </view>
  74. </u-popup>
  75. <canvas canvas-id="shareCanvas"
  76. :style="{ position: 'absolute', top: '-10000px', width: '750px', height: '600px' }"></canvas>
  77. </view>
  78. </template>
  79. <script setup>
  80. import {
  81. loadCourseDetail,
  82. loadCommentList,
  83. sendComment,
  84. regCourse
  85. } from "@/api/edu.js"
  86. import {
  87. getToken
  88. } from '@/utils/auth.js'
  89. import {
  90. useAuthStore
  91. } from '@/store/authStore'
  92. import dayjs from 'dayjs'
  93. dayjs.locale('zh-cn')
  94. const authStore = useAuthStore();
  95. // const isMember = ref(false)
  96. const feedShow = ref(false)
  97. import {
  98. ref,
  99. computed
  100. } from 'vue'
  101. import {
  102. onLoad,
  103. onShow,
  104. onShareAppMessage,
  105. onShareTimeline
  106. } from '@dcloudio/uni-app'
  107. const courseDetail = ref({});
  108. const courseId = ref(null);
  109. const courseName = ref(null);
  110. const items = ref(['课程简介', '观看评论']);
  111. const currentTab = ref(0);
  112. const comment = ref("");
  113. const feedId = ref(null);
  114. const finderId = "sphIfs9sYiL5RB3"
  115. // 评论发送按钮样式
  116. const customStyle = ref({
  117. backgroundColor: '#e6e6e6',
  118. color: '#333333',
  119. fontWeight: 'bold',
  120. height: '60rpx',
  121. marginLeft: '20rpx',
  122. border: 'none',
  123. fontSize: '26rpx'
  124. })
  125. // 评论输入框样式
  126. const inputStyle = ref({
  127. backgroundColor: '#e6e6e6',
  128. color: '#333333',
  129. borderRadius: '5px',
  130. padding: '0 20rpx',
  131. fontSize: '26rpx'
  132. })
  133. // 评论列表
  134. const commentList = ref([])
  135. // 点击tabs,切换
  136. function onClickItem(e) {
  137. if (currentTab.value != e) {
  138. currentTab.value = e;
  139. if (e === 2) {
  140. getComment(courseId.value)
  141. }
  142. }
  143. }
  144. // 初始化
  145. function init(id) {
  146. loadCourseDetail(id).then(res => {
  147. if (res?.data) {
  148. courseDetail.value = res.data;
  149. showBuy.value = showBuyAction()
  150. if(courseDetail.value.regType === '1'
  151. && (courseDetail.value.status === '2' ||
  152. courseDetail.value.status === '3')){
  153. // console.log(123456)
  154. getVideo()
  155. }
  156. // console.log(courseDetail, "课程详情")
  157. }
  158. })
  159. }
  160. function getComment(id) {
  161. loadCommentList(id).then(res => {
  162. if (res?.data) {
  163. commentList.value = res.data;
  164. }
  165. })
  166. }
  167. // 购买课程
  168. function toBuy() {
  169. uni.navigateTo({
  170. url: "/pages/goOnEdu/course/courseDetail/courseOrder?id=" + courseId.value
  171. })
  172. // console.log("购买该课程", courseDetail.value.id)
  173. }
  174. // 获取图片信息
  175. const getImageInfo = (imgUrl) => {
  176. return new Promise((resolve) => {
  177. uni.getImageInfo({
  178. src: imgUrl,
  179. success: (res) => resolve(res),
  180. fail: () => resolve(null)
  181. });
  182. });
  183. };
  184. function toSend() {
  185. sendComment({
  186. courseId: courseId.value,
  187. content: comment.value,
  188. commentTime: formatDate(new Date())
  189. }).then(res => {
  190. getComment(courseId.value)
  191. comment.value = ""
  192. })
  193. }
  194. function formatDate(date) {
  195. const pad = (num) => num.toString().padStart(2, '0');
  196. const year = date.getFullYear();
  197. const month = pad(date.getMonth() + 1); // 月份从0开始,需加1
  198. const day = pad(date.getDate());
  199. const hours = pad(date.getHours());
  200. const minutes = pad(date.getMinutes());
  201. const seconds = pad(date.getSeconds());
  202. return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
  203. }
  204. function showBuyAction() {
  205. if (courseDetail.value.viewMode === '2' &&
  206. !isMember.value &&
  207. !courseDetail.value.hasBuy &&
  208. currentTab.value === 0) {
  209. // console.log(1)
  210. return true
  211. }
  212. // 付费,不管是不是会员,并且没买的
  213. if (courseDetail.value.viewMode === '3' &&
  214. !courseDetail.value.hasBuy &&
  215. currentTab.value === 0) {
  216. // console.log(2)
  217. return true
  218. }
  219. // console.log(3)
  220. return false
  221. }
  222. const showBuy = ref(false)
  223. const isMember = computed(() => {
  224. return authStore.userInfo.isMember == '0' ? false : true
  225. })
  226. const isLogin = computed(() => {
  227. if (getToken() && authStore.isAuthenticated) {
  228. return true
  229. } else {
  230. return false
  231. }
  232. })
  233. const loginShow = ref(true)
  234. function toLogin() {
  235. // loginShow.value = false
  236. let url = {
  237. url: '/pages/goOnEdu/course/courseDetail/courseDetail',
  238. id: courseId.value,
  239. title: courseName.value
  240. }
  241. uni.setStorageSync("redirect", url)
  242. uni.navigateTo({
  243. url: `/pages/login/login`
  244. })
  245. }
  246. // 初始化页面
  247. onLoad((option) => {
  248. const {
  249. id,
  250. title
  251. } = option;
  252. courseId.value = id
  253. courseName.value = title
  254. uni.setNavigationBarTitle({
  255. title: title
  256. });
  257. if (isLogin.value) {
  258. loginShow.value = false
  259. } else {
  260. loginShow.value = true
  261. }
  262. // toVideo()
  263. // loginShow.value = true
  264. })
  265. onShow(() => {
  266. if (isLogin.value) {
  267. init(courseId.value)
  268. getComment(courseId.value)
  269. }
  270. })
  271. function formatDateS(dateStr) {
  272. return dateStr.replace(" ", "T");
  273. }
  274. // 日期格式:xxxx年xx月xx日(星期x)
  275. function getDateWeek(dateStr) {
  276. console.log(dateStr,"dateStr")
  277. // 将日期字符串转换为 Date 对象
  278. const date = new Date(dateStr.replace(/-/g, '/'));
  279. // 检查日期是否有效
  280. if (isNaN(date.getTime())) {
  281. return dateStr; // 如果无效,返回原字符串
  282. }
  283. // 获取年月日
  284. const year = date.getFullYear();
  285. const month = String(date.getMonth() + 1).padStart(2, '0');
  286. const day = String(date.getDate()).padStart(2, '0');
  287. // 获取星期几
  288. const weekdays = ['日', '一', '二', '三', '四', '五', '六'];
  289. const weekday = weekdays[date.getDay()];
  290. // 获取时分
  291. const hours = String(date.getHours()).padStart(2, '0');
  292. const minutes = String(date.getMinutes()).padStart(2, '0');
  293. // 组合成新格式
  294. return `${year}-${month}-${day}(星期${weekday}) ${hours}:${minutes}`;
  295. }
  296. function formatTime(timeString) {
  297. const commentDate = new Date(formatDateS(timeString));
  298. const now = new Date();
  299. const diff = now - commentDate;
  300. const minutes = Math.floor(diff / 60000);
  301. const hours = Math.floor(diff / 3600000);
  302. const days = Math.floor(diff / 86400000);
  303. if (minutes < 1) { // 修改这里以处理0分钟
  304. return "刚刚";
  305. } else if (minutes < 60) {
  306. return `${minutes}分钟前`;
  307. } else if (hours < 24) {
  308. return `${hours}小时前`;
  309. } else {
  310. return commentDate.toISOString().split('T')[0];
  311. }
  312. }
  313. const sortedCommentList = computed(() => {
  314. return commentList.value.sort((a, b) =>
  315. new Date(formatDateS(b.commentTime)) - new Date(formatDateS(a.commentTime))
  316. );
  317. });
  318. onShareAppMessage(async (res) => {
  319. const processedImage = courseDetail.value.cover;
  320. // console.log(processedImage)
  321. return {
  322. title: courseName.value,
  323. path: `/pages/goOnEdu/course/courseDetail/courseDetail?id=${courseId.value}&title=${courseName.value}`,
  324. imageUrl: processedImage
  325. };
  326. })
  327. onShareTimeline(async () => {
  328. return {
  329. title: courseName.value,
  330. query: `id=${courseId.value}&title=${courseName.value}`,
  331. imageUrl: courseDetail.value.cover
  332. };
  333. })
  334. // 线上-点击预约-跳转预告
  335. function toVideo(){
  336. wx.getChannelsLiveNoticeInfo({
  337. 'finderUserName': "sphIfs9sYiL5RB3",
  338. success: (res)=>{
  339. let noticeId = null;
  340. if(res.otherInfos.length > 0){
  341. let date1 = new Date(formatDateS(courseDetail.value.date))
  342. res.otherInfos.forEach(item=>{
  343. let date = new Date(item.startTime*1000);
  344. // console.log(item,date1, date)
  345. if(date1.getTime()===date.getTime()){
  346. noticeId = item.noticeId;
  347. }
  348. })
  349. }
  350. // console.log(noticeId)
  351. if(!noticeId){
  352. noticeId = res.noticeId
  353. }
  354. // console.log(res)
  355. wx.reserveChannelsLive({
  356. "noticeId": noticeId,
  357. success: (resp)=>{
  358. console.log(resp)
  359. },
  360. fail: (err)=>{
  361. console.log(err)
  362. }
  363. })
  364. },
  365. fail(err) {
  366. console.error('调用失败:', err);
  367. }
  368. })
  369. }
  370. // 线上课程-获取视频号回放
  371. function getVideo(){
  372. const startDate = dayjs(courseDetail.value.date).format("YYYY-MM-DD");
  373. const endDate = dayjs(startDate).add(1, 'day').format("YYYY-MM-DD");
  374. // 获取时间戳
  375. const startTime = new Date(startDate).getTime();
  376. const endTime = new Date(endDate).getTime();
  377. wx.getChannelsLiveInfo({
  378. 'finderUserName': "sphIfs9sYiL5RB3",
  379. startTime: startTime,
  380. endTime: endTime,
  381. success: (res)=>{
  382. feedId.value = res.feedId;
  383. // console.log("直播信息", res)
  384. feedShow.value = true
  385. },
  386. fail(err) {
  387. console.error('调用失败:', err);
  388. }
  389. })
  390. }
  391. // 线上课程-进来后-是否显示预约按钮
  392. const videoShow = computed(()=>{
  393. // regType = 1 是线上课程
  394. // feedShow为true是回放
  395. if(courseDetail.value?.status==='2' || courseDetail.value?.status==='3'){
  396. return false;
  397. }
  398. return (courseDetail.value?.regType ==='1') && !feedShow.value
  399. })
  400. // 线下课程-是否显示报名按钮
  401. const regShow = computed(()=>{
  402. // regType = 0 是线上课程
  403. // 缺少判断是否购买
  404. if(courseDetail.value?.status === '2' || courseDetail.value?.status === '3' ){
  405. return false
  406. }
  407. return courseDetail.value?.regType ==='0'
  408. })
  409. function toReg(){
  410. let isReg = courseDetail.value.hasReg ?? false;
  411. let viewMode = courseDetail.value.viewMode
  412. if(isReg){
  413. return;
  414. }
  415. if(viewMode==='1' || (isMember.value && viewMode==='2')){
  416. // 直接报名
  417. console.log("直接报名")
  418. regCourse(courseId.value).then(res=>{
  419. if(res.code===0){
  420. init(courseId.value)
  421. }
  422. })
  423. return
  424. }
  425. uni.navigateTo({
  426. url: "/pages/goOnEdu/course/courseDetail/courseOrder?id=" + courseId.value
  427. })
  428. return
  429. }
  430. </script>
  431. <style lang="scss">
  432. .u-drawer-bottom {
  433. background-color: transparent !important;
  434. }
  435. </style>
  436. <style lang="scss" scoped>
  437. .container {
  438. // height: 100vh;
  439. width: 100vw;
  440. background-color: #fff;
  441. // padding: 0 20rpx;
  442. }
  443. .course-tab-list {
  444. display: flex;
  445. background-color: #f2f2f2;
  446. flex: 0 0 auto;
  447. margin: 0 20rpx;
  448. .course-tab-item {
  449. width: 100%;
  450. height: 80rpx;
  451. line-height: 80rpx;
  452. text-align: center;
  453. }
  454. .tab-active {
  455. border-bottom: 1px solid #0069f6;
  456. }
  457. }
  458. // .container-poster{
  459. // height: calc(100vh - 500rpx - env(safe-area-inset-bottom, 0));
  460. // }
  461. .content {
  462. overflow: scroll;
  463. // height: calc(100vh - 500rpx - env(safe-area-inset-bottom, 0));
  464. height: 700rpx;
  465. position: relative;
  466. .content-text {
  467. // env(safe-area-inset-bottom, 0)
  468. // padding: 0 20rpx 0;
  469. font-size: 38rpx;
  470. .text-title {
  471. font-weight: bold;
  472. margin-bottom: 15rpx;
  473. margin-top: 15rpx;
  474. }
  475. .text-content {
  476. font-size: 32rpx;
  477. margin-bottom: 20rpx;
  478. }
  479. .text-tip {
  480. color: red;
  481. // margin-bottom: 20rpx;
  482. margin-bottom: env(safe-area-inset-bottom, 0);
  483. }
  484. }
  485. .content-button-hold{
  486. width: 100%;
  487. height: 120rpx;
  488. }
  489. .content-button{
  490. width: 100%;
  491. // height: 100rpx;
  492. // line-height: 100rpx;
  493. text-align: center;
  494. background-color: #fe0000;
  495. color: #fff;
  496. // position: absolute;
  497. // bottom: 0;
  498. padding:20rpx 0 calc(20rpx + env(safe-area-inset-bottom, 0));
  499. }
  500. }
  501. .section-bottom-fixed {
  502. height: 90rpx;
  503. color: #fff;
  504. font-size: 34rpx;
  505. text-align: center;
  506. line-height: 80rpx;
  507. background-color: #fe0000;
  508. width: 100%;
  509. position: fixed;
  510. bottom: 0;
  511. box-sizing: content-box;
  512. padding-bottom: env(safe-area-inset-bottom, 0);
  513. }
  514. .section-bottom {
  515. height: 90rpx;
  516. color: #fff;
  517. font-size: 34rpx;
  518. text-align: center;
  519. line-height: 80rpx;
  520. background-color: #fe0000;
  521. width: 100%;
  522. position: absolute;
  523. bottom: 0;
  524. box-sizing: content-box;
  525. padding-bottom: env(safe-area-inset-bottom, 0);
  526. }
  527. .bg-blue{
  528. background-color: #3097ff;
  529. }
  530. .comment-input-box {
  531. width: 100%;
  532. height: 100%;
  533. display: flex;
  534. box-sizing: border-box;
  535. padding: 0 20rpx;
  536. align-items: center;
  537. .comment-input {
  538. flex: 1;
  539. }
  540. .comment-button {
  541. flex: 0 0 auto;
  542. }
  543. }
  544. .comment-list-item {
  545. display: flex;
  546. padding: 20rpx 0;
  547. font-size: 28rpx;
  548. .comment-list-left {
  549. flex: 0 0 auto;
  550. padding-right: 20rpx;
  551. padding-left: 10rpx;
  552. .comment-list-avator {
  553. width: 100rpx;
  554. height: 100rpx;
  555. border-radius: 50%;
  556. }
  557. }
  558. .comment-list-right {
  559. flex: 1;
  560. .comment-list-username {
  561. padding-right: 25rpx;
  562. font-size: 32rpx;
  563. font-weight: bold;
  564. }
  565. }
  566. }
  567. </style>