courseDetail.vue 14 KB

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