courseDetail.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612
  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" style="color: red;font-weight: 500;font-size: 30rpx;">如需取消报名,请联系教育培训部工作人员13332876414/13302262603</view>
  31. <view class="text-tip" v-if="!isMember && courseDetail.viewMode === '2'" @click="toJoin">个人会员或单位会员免费,点击现在入会></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. const toJoin = () =>{
  145. uni.navigateTo({
  146. url: "/pages/swiperDetail/swiperDetail?id=12117"
  147. })
  148. }
  149. // 初始化
  150. function init(id) {
  151. loadCourseDetail(id).then(res => {
  152. if (res?.data) {
  153. courseDetail.value = res.data;
  154. showBuy.value = showBuyAction()
  155. if(courseDetail.value.regType === '1'
  156. && (courseDetail.value.status === '2' ||
  157. courseDetail.value.status === '3')){
  158. // console.log(123456)
  159. getVideo()
  160. }
  161. // console.log(courseDetail, "课程详情")
  162. }
  163. })
  164. }
  165. function getComment(id) {
  166. loadCommentList(id).then(res => {
  167. if (res?.data) {
  168. commentList.value = res.data;
  169. }
  170. })
  171. }
  172. // 购买课程
  173. function toBuy() {
  174. uni.navigateTo({
  175. url: "/pages/goOnEdu/course/courseDetail/courseOrder?id=" + courseId.value
  176. })
  177. // console.log("购买该课程", courseDetail.value.id)
  178. }
  179. // 获取图片信息
  180. const getImageInfo = (imgUrl) => {
  181. return new Promise((resolve) => {
  182. uni.getImageInfo({
  183. src: imgUrl,
  184. success: (res) => resolve(res),
  185. fail: () => resolve(null)
  186. });
  187. });
  188. };
  189. function toSend() {
  190. sendComment({
  191. courseId: courseId.value,
  192. content: comment.value,
  193. commentTime: formatDate(new Date())
  194. }).then(res => {
  195. getComment(courseId.value)
  196. comment.value = ""
  197. })
  198. }
  199. function formatDate(date) {
  200. const pad = (num) => num.toString().padStart(2, '0');
  201. const year = date.getFullYear();
  202. const month = pad(date.getMonth() + 1); // 月份从0开始,需加1
  203. const day = pad(date.getDate());
  204. const hours = pad(date.getHours());
  205. const minutes = pad(date.getMinutes());
  206. const seconds = pad(date.getSeconds());
  207. return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
  208. }
  209. function showBuyAction() {
  210. if (courseDetail.value.viewMode === '2' &&
  211. !isMember.value &&
  212. !courseDetail.value.hasBuy &&
  213. currentTab.value === 0) {
  214. // console.log(1)
  215. return true
  216. }
  217. // 付费,不管是不是会员,并且没买的
  218. if (courseDetail.value.viewMode === '3' &&
  219. !courseDetail.value.hasBuy &&
  220. currentTab.value === 0) {
  221. // console.log(2)
  222. return true
  223. }
  224. // console.log(3)
  225. return false
  226. }
  227. const showBuy = ref(false)
  228. const isMember = computed(() => {
  229. return authStore.userInfo.isMember == '0' ? false : true
  230. })
  231. const isLogin = computed(() => {
  232. if (getToken() && authStore.isAuthenticated) {
  233. return true
  234. } else {
  235. return false
  236. }
  237. })
  238. const loginShow = ref(true)
  239. function toLogin() {
  240. // loginShow.value = false
  241. let url = {
  242. url: '/pages/goOnEdu/course/courseDetail/courseDetail',
  243. id: courseId.value,
  244. title: courseName.value
  245. }
  246. uni.setStorageSync("redirect", url)
  247. uni.navigateTo({
  248. url: `/pages/login/login`
  249. })
  250. }
  251. // 初始化页面
  252. onLoad((option) => {
  253. const {
  254. id,
  255. title
  256. } = option;
  257. courseId.value = id
  258. courseName.value = title
  259. uni.setNavigationBarTitle({
  260. title: title
  261. });
  262. if (isLogin.value) {
  263. loginShow.value = false
  264. } else {
  265. loginShow.value = true
  266. }
  267. // toVideo()
  268. // loginShow.value = true
  269. })
  270. onShow(() => {
  271. if (isLogin.value) {
  272. init(courseId.value)
  273. getComment(courseId.value)
  274. }
  275. })
  276. function formatDateS(dateStr) {
  277. return dateStr.replace(" ", "T");
  278. }
  279. // 日期格式:xxxx年xx月xx日(星期x)
  280. function getDateWeek(dateStr) {
  281. console.log(dateStr,"dateStr")
  282. // 将日期字符串转换为 Date 对象
  283. const date = new Date(dateStr.replace(/-/g, '/'));
  284. // 检查日期是否有效
  285. if (isNaN(date.getTime())) {
  286. return dateStr; // 如果无效,返回原字符串
  287. }
  288. // 获取年月日
  289. const year = date.getFullYear();
  290. const month = String(date.getMonth() + 1).padStart(2, '0');
  291. const day = String(date.getDate()).padStart(2, '0');
  292. // 获取星期几
  293. const weekdays = ['日', '一', '二', '三', '四', '五', '六'];
  294. const weekday = weekdays[date.getDay()];
  295. // 获取时分
  296. const hours = String(date.getHours()).padStart(2, '0');
  297. const minutes = String(date.getMinutes()).padStart(2, '0');
  298. // 组合成新格式
  299. return `${year}-${month}-${day}(星期${weekday}) ${hours}:${minutes}`;
  300. }
  301. function formatTime(timeString) {
  302. const commentDate = new Date(formatDateS(timeString));
  303. const now = new Date();
  304. const diff = now - commentDate;
  305. const minutes = Math.floor(diff / 60000);
  306. const hours = Math.floor(diff / 3600000);
  307. const days = Math.floor(diff / 86400000);
  308. if (minutes < 1) { // 修改这里以处理0分钟
  309. return "刚刚";
  310. } else if (minutes < 60) {
  311. return `${minutes}分钟前`;
  312. } else if (hours < 24) {
  313. return `${hours}小时前`;
  314. } else {
  315. return commentDate.toISOString().split('T')[0];
  316. }
  317. }
  318. const sortedCommentList = computed(() => {
  319. return commentList.value.sort((a, b) =>
  320. new Date(formatDateS(b.commentTime)) - new Date(formatDateS(a.commentTime))
  321. );
  322. });
  323. onShareAppMessage(async (res) => {
  324. // console.log(processedImage)
  325. return {
  326. title: courseName.value,
  327. path: `/pages/goOnEdu/course/courseDetail/courseDetail?id=${courseId.value}&title=${courseName.value}`,
  328. // imageUrl: courseDetail.value.cover
  329. };
  330. })
  331. onShareTimeline(async () => {
  332. return {
  333. title: courseName.value,
  334. query: `id=${courseId.value}&title=${courseName.value}`,
  335. imageUrl: courseDetail.value.cover
  336. };
  337. })
  338. // 线上-点击预约-跳转预告
  339. function toVideo(){
  340. wx.getChannelsLiveNoticeInfo({
  341. 'finderUserName': "sphIfs9sYiL5RB3",
  342. success: (res)=>{
  343. let noticeId = null;
  344. if(res.otherInfos.length > 0){
  345. let date1 = new Date(formatDateS(courseDetail.value.date))
  346. res.otherInfos.forEach(item=>{
  347. let date = new Date(item.startTime*1000);
  348. // console.log(item,date1, date)
  349. if(date1.getTime()===date.getTime()){
  350. noticeId = item.noticeId;
  351. }
  352. })
  353. }
  354. // console.log(noticeId)
  355. if(!noticeId){
  356. noticeId = res.noticeId
  357. }
  358. // console.log(res)
  359. wx.reserveChannelsLive({
  360. "noticeId": noticeId,
  361. success: (resp)=>{
  362. console.log(resp)
  363. },
  364. fail: (err)=>{
  365. console.log(err)
  366. }
  367. })
  368. },
  369. fail(err) {
  370. console.error('调用失败:', err);
  371. }
  372. })
  373. }
  374. // 线上课程-获取视频号回放
  375. function getVideo(){
  376. const startDate = dayjs(courseDetail.value.date).format("YYYY-MM-DD");
  377. const endDate = dayjs(startDate).add(1, 'day').format("YYYY-MM-DD");
  378. // 获取时间戳
  379. const startTime = new Date(startDate).getTime();
  380. const endTime = new Date(endDate).getTime();
  381. wx.getChannelsLiveInfo({
  382. 'finderUserName': "sphIfs9sYiL5RB3",
  383. startTime: startTime,
  384. endTime: endTime,
  385. success: (res)=>{
  386. feedId.value = res.feedId;
  387. // console.log("直播信息", res)
  388. feedShow.value = true
  389. },
  390. fail(err) {
  391. console.error('调用失败:', err);
  392. }
  393. })
  394. }
  395. // 线上课程-进来后-是否显示预约按钮
  396. const videoShow = computed(()=>{
  397. // regType = 1 是线上课程
  398. // feedShow为true是回放
  399. if(courseDetail.value?.status==='2' || courseDetail.value?.status==='3'){
  400. return false;
  401. }
  402. return (courseDetail.value?.regType ==='1') && !feedShow.value
  403. })
  404. // 线下课程-是否显示报名按钮
  405. const regShow = computed(()=>{
  406. // regType = 0 是线上课程
  407. // 缺少判断是否购买
  408. if(courseDetail.value?.status === '2' || courseDetail.value?.status === '3' ){
  409. return false
  410. }
  411. return courseDetail.value?.regType ==='0'
  412. })
  413. function toReg(){
  414. let isReg = courseDetail.value.hasReg ?? false;
  415. let viewMode = courseDetail.value.viewMode
  416. if(isReg){
  417. return;
  418. }
  419. if(viewMode==='1' || (isMember.value && viewMode==='2')){
  420. // 直接报名
  421. console.log("直接报名")
  422. regCourse(courseId.value).then(res=>{
  423. if(res.code===0){
  424. init(courseId.value)
  425. }
  426. })
  427. return
  428. }
  429. uni.navigateTo({
  430. url: "/pages/goOnEdu/course/courseDetail/courseOrder?id=" + courseId.value
  431. })
  432. return
  433. }
  434. </script>
  435. <style lang="scss">
  436. .u-drawer-bottom {
  437. background-color: transparent !important;
  438. }
  439. </style>
  440. <style lang="scss" scoped>
  441. .container {
  442. // height: 100vh;
  443. width: 100vw;
  444. background-color: #fff;
  445. // padding: 0 20rpx;
  446. }
  447. .course-tab-list {
  448. display: flex;
  449. background-color: #f2f2f2;
  450. flex: 0 0 auto;
  451. margin: 0 20rpx;
  452. .course-tab-item {
  453. width: 100%;
  454. height: 80rpx;
  455. line-height: 80rpx;
  456. text-align: center;
  457. }
  458. .tab-active {
  459. border-bottom: 1px solid #0069f6;
  460. }
  461. }
  462. // .container-poster{
  463. // height: calc(100vh - 500rpx - env(safe-area-inset-bottom, 0));
  464. // }
  465. .content {
  466. overflow: scroll;
  467. // height: calc(100vh - 500rpx - env(safe-area-inset-bottom, 0));
  468. height: 700rpx;
  469. position: relative;
  470. .content-text {
  471. // env(safe-area-inset-bottom, 0)
  472. // padding: 0 20rpx 0;
  473. font-size: 38rpx;
  474. .text-title {
  475. font-weight: bold;
  476. margin-bottom: 15rpx;
  477. margin-top: 15rpx;
  478. }
  479. .text-content {
  480. font-size: 32rpx;
  481. margin-bottom: 20rpx;
  482. }
  483. .text-tip {
  484. color: red;
  485. // margin-bottom: 20rpx;
  486. margin-bottom: env(safe-area-inset-bottom, 0);
  487. }
  488. }
  489. .content-button-hold{
  490. width: 100%;
  491. height: 120rpx;
  492. }
  493. .content-button{
  494. width: 100%;
  495. // height: 100rpx;
  496. // line-height: 100rpx;
  497. text-align: center;
  498. background-color: #fe0000;
  499. color: #fff;
  500. // position: absolute;
  501. // bottom: 0; calc(20rpx + env(safe-area-inset-bottom, 0))
  502. padding:20rpx 0 20rpx;
  503. }
  504. }
  505. .section-bottom-fixed {
  506. height: 90rpx;
  507. color: #fff;
  508. font-size: 34rpx;
  509. text-align: center;
  510. line-height: 80rpx;
  511. background-color: #fe0000;
  512. width: 100%;
  513. position: fixed;
  514. bottom: 0;
  515. box-sizing: content-box;
  516. // padding-bottom: env(safe-area-inset-bottom, 0);
  517. }
  518. .section-bottom {
  519. height: 90rpx;
  520. color: #fff;
  521. font-size: 34rpx;
  522. text-align: center;
  523. line-height: 80rpx;
  524. background-color: #fe0000;
  525. width: 100%;
  526. position: absolute;
  527. bottom: 0;
  528. box-sizing: content-box;
  529. padding-bottom: env(safe-area-inset-bottom, 0);
  530. }
  531. .bg-blue{
  532. background-color: #3097ff;
  533. }
  534. .comment-input-box {
  535. width: 100%;
  536. height: 100%;
  537. display: flex;
  538. box-sizing: border-box;
  539. padding: 0 20rpx;
  540. align-items: center;
  541. .comment-input {
  542. flex: 1;
  543. }
  544. .comment-button {
  545. flex: 0 0 auto;
  546. }
  547. }
  548. .comment-list-item {
  549. display: flex;
  550. padding: 20rpx 0;
  551. font-size: 28rpx;
  552. .comment-list-left {
  553. flex: 0 0 auto;
  554. padding-right: 20rpx;
  555. padding-left: 10rpx;
  556. .comment-list-avator {
  557. width: 100rpx;
  558. height: 100rpx;
  559. border-radius: 50%;
  560. }
  561. }
  562. .comment-list-right {
  563. flex: 1;
  564. .comment-list-username {
  565. padding-right: 25rpx;
  566. font-size: 32rpx;
  567. font-weight: bold;
  568. }
  569. }
  570. }
  571. </style>