courseItem.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638
  1. <template>
  2. <view class="courselist-item">
  3. <view class="courselist-con x-start" @click="toCourseDetail(info)">
  4. <view class="courselist-img">
  5. <!-- <view class="status">进行中</view> -->
  6. <image :src="info.thumbnail" mode="aspectFill"></image>
  7. </view>
  8. <view class="courselist-con-r">
  9. <view @click.passive.stop>
  10. <text class="more-t ">{{info.title}}</text>
  11. <view class="btn_icon" style="margin-left: 5px;" @click="copyId">ID
  12. <image src="@/static/images/copy_icon.png" mode="aspectFill"></image>
  13. </view>
  14. </view>
  15. <view class="courselist-desc one-t" v-show="from != 'course'">{{info.courseName}}</view>
  16. <view :class="from == 'course' ? 'courselist-con-timebox ':'courselist-con-timebox x-f'">
  17. <view class="x-f acea-row"><u-icon class="icon" name="file-text" color="#999"
  18. size="20"></u-icon>{{info.createTime}}</view>
  19. <view class="x-f acea-row"><u-icon class="icon" name="clock" color="#999"
  20. size="16"></u-icon>{{$formatSeconds(info.duration,1)}}</view>
  21. </view>
  22. </view>
  23. </view>
  24. <view class="courselist-footer x-f ">
  25. <view class="courselist-footer-item x-c " @click="handleShare"><u-icon
  26. name="share-square" color="#1677ff" size="18"></u-icon>分享课程</view>
  27. <view class="courselist-footer-item x-c shishi" v-show="activeTab == 1" @click="handleStatistics"><u-icon
  28. name="share-square" color="#1677ff" size="18"></u-icon>课程统计</view>
  29. <view class="courselist-footer-item x-c shuju" v-show="activeTab == 2" @click="handleStatistics"><u-icon
  30. name="share-square" color="#1677ff" size="18"></u-icon>数据统计</view>
  31. </view>
  32. <!-- 分享弹窗 -->
  33. <u-popup :show="showShare" :closeOnClickOverlay="true" :round='20' @close="closeShare" @open="openShare">
  34. <view class="sharePop x-ac">
  35. <!--#ifdef MP-WEIXIN-->
  36. <view class="sharePop-item y-f card-share" >
  37. <image src="@/static/images/card_icon.png" mode="aspectFill"
  38. style="width: 80rpx; height: 80rpx;margin-top: 20rpx;"></image>
  39. <view style="font-weight: bold;margin-bottom: 4px;">生成卡片</view>
  40. <view style="font-size: 12px;color: #888;">指导分享轻松转发</view>
  41. <button open-type="share" class="share" @click="handleClick()">分享课程</button>
  42. </view>
  43. <!--#endif-->
  44. <view class="sharePop-item y-f" @click="buildimg">
  45. <image src="@/static/images/poster_icon.png" mode="aspectFill"></image>
  46. <view style="font-weight: bold;margin-bottom: 4px;">生成海报</view>
  47. <view style="font-size: 12px;color: #888;">保存海报美观宣传</view>
  48. </view>
  49. <view class="sharePop-item y-f" @click="copyLink">
  50. <image src="@/static/images/link_icon.png" mode="aspectFill"></image>
  51. <view style="font-weight: bold;margin-bottom: 4px;">复制链接</view>
  52. <view style="font-size: 12px;color: #888;">生成链接一键复制</view>
  53. </view>
  54. </view>
  55. </u-popup>
  56. <!-- 设置链接有效时长弹窗 -->
  57. <u-modal :show="setTimeShow" content='content' class="model" @confirm="confirmTime" :closeOnClickOverlay='true'
  58. @close="closetext">
  59. <view class="setTimebox">
  60. <view class="timetip">不传默认以系统参数为准</view>
  61. <view class="x-f">
  62. <text style="margin-right: 20px;">链接有效时长(分钟)</text>
  63. <u-input fontSize="14px" placeholder="链接有效时长" border="none" v-model="time" maxlength="5"></u-input>
  64. </view>
  65. </view>
  66. </u-modal>
  67. <u-notify ref="uNotify" message=""></u-notify>
  68. <!-- 生成海报 -->
  69. <u-popup :show="setImg" @close="closeimg" :round="12" style="z-index: 999;">
  70. <view class="w100 h540 center">
  71. <image :src="codeLink.url" mode="aspectFill" ></image>
  72. </view>
  73. <view class="justify-around mb40">
  74. <!-- <view class="column justify-center align-center" @click="shareimg">
  75. <image src='@/static/image/wechat.png' class="w80 h80"></image>
  76. <view class="mt10">微信好友</view>
  77. </view> -->
  78. <view class="column justify-center align-center" @click="downimg">
  79. <image src='@/static/image/downicon.png' class="w80 h80"></image>
  80. <view class=" mb10">长按图片保存</view>
  81. </view>
  82. </view>
  83. </u-popup>
  84. <u-overlay :show="showzhidao" @click="showzhidao = false" style="z-index: 9999;">
  85. <view class="point-box">
  86. <view class="imgshe">
  87. <image src='@/static/image/point.png' class="w300 h300"></image>
  88. </view>
  89. <view class="column colorf fs32 xu-box fs40
  90. align-center justify-center">
  91. <view class="justify-center">点击右上角
  92. <image src="@/static/image/wxmore.png" class="w50 h50 mlr10"></image>
  93. </view>
  94. <view class="mt20">选择 “转发给朋友”</view>
  95. <view style="color: #cbcbcb;" class="fs28 mt40">点击任意位置关闭弹窗</view>
  96. </view>
  97. </view>
  98. </u-overlay>
  99. </view>
  100. </template>
  101. <script>
  102. import {
  103. sharecourselink,
  104. buildCode,
  105. getSDK
  106. } from '@/api/courseManage'
  107. import html2canvas from 'html2canvas'
  108. import wx from 'weixin-js-sdk'
  109. export default {
  110. props: {
  111. activeTab: {
  112. type: [Number, String],
  113. default: 0
  114. },
  115. // 来源
  116. from: {
  117. type: String,
  118. default: 'live'
  119. },
  120. info: {
  121. type: Object,
  122. default: () => {
  123. return {}
  124. }
  125. },
  126. parentMethod:{
  127. type: Function
  128. }
  129. },
  130. data() {
  131. return {
  132. cavansimg: false,
  133. showShare: false,
  134. setTimeShow: false,
  135. time: "",
  136. user: [],
  137. type: 1,
  138. copylink: '',
  139. setImg: '',
  140. codeLink: '',
  141. setImg: false,
  142. painterId: 'myPainter',
  143. isLongPress: false,
  144. painterSrc: '',
  145. showzhidao: false,
  146. imgs:'https://fbylive.obs.cn-southwest-2.myhuaweicloud.com/fs/20250416/1744811256845.png'
  147. }
  148. },
  149. onLoad() {},
  150. mounted() {
  151. this.user = uni.getStorageSync("companyUserInfo") ? JSON.parse(uni.getStorageSync("companyUserInfo")) : {}
  152. },
  153. methods: {
  154. handleClick(){
  155. console.log(123)
  156. this.parentMethod();
  157. this.$emit('trigger-share', {
  158. title: this.info.courseName+this.info.title,
  159. path: "/pages_course/viedo",
  160. params: { companyId: this.user.companyId, companyUserId: this.user.userId,
  161. courseId:this.info.courseId,videoId:this.info.courseId },
  162. img:this.info.thumbnail||this.imgs
  163. });
  164. },
  165. // 获取jssdk
  166. getjssdklist() {
  167. const param = {
  168. url: window.location.href.split('#')[0] // 注意去除 hash
  169. }
  170. getSDK(param).then(res => {
  171. wx.config({
  172. debug: false,
  173. appId: res.data.appId, // 必填,公众号的唯一标识
  174. timestamp: res.data.timestamp, // 必填,生成签名的时间戳
  175. nonceStr: res.data.nonceStr, // 必填,生成签名的随机串
  176. signature: res.data.signature, // 必填,签名
  177. jsApiList: ["updateAppMessageShareData", "onMenuShareAppMessage", ] // 必填,需要使用的JS接口列表
  178. });
  179. })
  180. },
  181. shareimg() {
  182. let self = this
  183. //分享好友
  184. // 配置--配置全局
  185. console.log(self.info.thumbnail + self.copylink, 11111)
  186. wx.ready(function() { //需在用户可能点击分享按钮前就先调用
  187. wx.updateAppMessageShareData({
  188. title: self.info.courseName + self.info.title, // 分享标题
  189. desc: self.info.description, // 分享描述
  190. // link: self.copylink,
  191. link: self.copylink,
  192. // 分享链接,该链接域名或路径必须与当前页面对应的公众 号JS安全域名一致
  193. imgUrl: self.info.thumbnail||self.imgs, // 分享图标
  194. success: function(res) {
  195. console.log(self.info, '456');
  196. self.showzhidao = true
  197. self.setImg = false
  198. self.showShare = false
  199. // 设置成功
  200. uni.showToast({
  201. title: '卡片已生成',
  202. icon: 'none',
  203. duration: 1000
  204. });
  205. },
  206. })
  207. // 另外一个方法·
  208. wx.onMenuShareAppMessage({
  209. title: self.info.courseName + self.info.title, // 分享标题
  210. desc: self.info.title, // 分享描述
  211. link: self.copylink,
  212. // 分享链接,该链接域名或路径必须与当前页面对应的公众 号JS安全域名一致
  213. imgUrl: self.info.thumbnail, // 分享图标
  214. success: function(res) {
  215. console.log(self.info, '456');
  216. self.showzhidao = true
  217. self.setImg = false
  218. self.showShare = false
  219. // 设置成功
  220. uni.showToast({
  221. title: '卡片已生成',
  222. icon: 'none',
  223. duration: 1000
  224. });
  225. },
  226. // complete: function(res) {
  227. // uni.showToast({
  228. // title: JSON.stringify(res),
  229. // icon: 'none',
  230. // duration: 2000
  231. // })
  232. // }
  233. })
  234. // wx.error((res) => {
  235. // console.log('wx.error:', res);
  236. // })
  237. });
  238. },
  239. downimg() {
  240. },
  241. handleLongPress() {
  242. this.isLongPress = true;
  243. // 延时执行保存操作,避免误触
  244. setTimeout(() => {
  245. if (this.isLongPress) {
  246. this.saveImage();
  247. }
  248. }, 1000); // 1000毫秒后执行保存操作
  249. },
  250. saveImage() {
  251. const painter = this.$painter.getPainter(this.painterId);
  252. painter.saveImage('jpg', (path) => {
  253. uni.saveImageToPhotosAlbum({
  254. filePath: path,
  255. success: () => {
  256. uni.showToast({
  257. title: '保存成功'
  258. });
  259. },
  260. fail: () => {
  261. uni.showToast({
  262. title: '保存失败',
  263. icon: 'none'
  264. });
  265. }
  266. });
  267. }, 'myCanvas');
  268. },
  269. closeimg() {
  270. this.setImg = false
  271. this.showShare = false
  272. },
  273. closetext() {
  274. this.setTimeShow = false
  275. },
  276. buildimg() {
  277. this.buildimgAcode()
  278. },
  279. //生成海报和二维码
  280. buildimgAcode() {
  281. uni.showLoading({
  282. title: '正在生成中...'
  283. })
  284. buildCode({
  285. companyId: this.user.companyId,
  286. companyUserId: this.user.userId,
  287. courseId: this.info.courseId,
  288. effectiveDuration: this.time,
  289. videoId: this.info.videoId,
  290. imgUrl:this.info.thumbnail,
  291. title:this.info.title,
  292. duration:this.info.duration
  293. }).then(res => {
  294. if (res.code == 200) {
  295. this.codeLink = res.posterImage
  296. this.setImg = true
  297. this.getlink()
  298. console.log(this.codeLink)
  299. } else {
  300. uni.showToast({
  301. icon: 'none',
  302. title: res.msg
  303. })
  304. }
  305. })
  306. },
  307. toCourseDetail(info) {
  308. uni.navigateTo({
  309. // url: '/pages/courseManage/course/learning?course='+JSON.stringify(info)
  310. // url: `/pages/courseManage/course/learning?course=${JSON.stringify(info)}&isvip=1`
  311. url:'/pages/courseManage/course/courseVideo?videoId='+info.videoId
  312. })
  313. },
  314. handleShare() {
  315. this.showShare = true
  316. // #ifdef H5
  317. this.getjssdklist()
  318. // #endif
  319. // this.getlink('preload'); // 提前加载链接
  320. },
  321. closeShare() {
  322. this.showShare = false
  323. // console.log('open');
  324. },
  325. openShare() {
  326. // this.showShare = false
  327. // console.log('close');
  328. },
  329. copyLink() {
  330. this.setTimeShow = true
  331. },
  332. confirmTime() {
  333. this.setTimeShow = !this.setTimeShow
  334. this.showShare = !this.showShare
  335. const params = {
  336. companyId: this.user.companyId,
  337. companyUserId: this.user.userId,
  338. courseId: this.info.courseId,
  339. time: this.time,
  340. videoId: this.info.videoId,
  341. }
  342. sharecourselink(params).then(res => {
  343. if (res.code == 200) {
  344. this.copylink = res.url
  345. if (this.copylink.startsWith('http://')) {
  346. this.copylink = this.copylink.replace('http://', 'https://');
  347. }
  348. // console.log(this.copylink)
  349. setTimeout(() => {
  350. uni.setClipboardData({
  351. data: this.copylink,
  352. success: () => {
  353. uni.showToast({
  354. title: '链接已复制',
  355. icon: 'none',
  356. duration: 2000
  357. });
  358. },
  359. fail: () => {
  360. uni.showToast({
  361. title: '复制失败',
  362. icon: 'none'
  363. });
  364. }
  365. });
  366. }, 100)
  367. console.log(this.copylink)
  368. } else {
  369. uni.showToast({
  370. icon: 'none',
  371. title: res.msg
  372. })
  373. }
  374. })
  375. },
  376. getlink(type) {
  377. const params = {
  378. companyId: this.user.companyId,
  379. companyUserId: this.user.userId,
  380. courseId: this.info.courseId,
  381. time: this.time,
  382. // type: this.type,
  383. videoId: this.info.videoId,
  384. }
  385. sharecourselink(params).then(res => {
  386. if (res.code == 200) {
  387. this.copylink = res.url
  388. // 强制使用 HTTPS
  389. if (this.copylink.startsWith('http://')) {
  390. this.copylink = this.copylink.replace('http://', 'https://');
  391. }
  392. } else {
  393. uni.showToast({
  394. icon: 'none',
  395. title: res.msg
  396. })
  397. }
  398. })
  399. },
  400. handleStatistics() {
  401. const info = {
  402. courseId: this.info.courseId,
  403. title: this.info.title,
  404. thumbnail: this.info.thumbnail,
  405. createTime: this.info.createTime,
  406. duration: this.info.duration,
  407. fileId: this.info.fileId,
  408. courseName: this.info.courseName,
  409. videoId:this.info.videoId,
  410. }
  411. uni.navigateTo({
  412. url: '/pages/courseManage/statistics?info=' + JSON.stringify(info)
  413. })
  414. },
  415. copyId() {
  416. uni.setClipboardData({
  417. data: this.info.title,
  418. success: () => {
  419. // this.$refs.uNotify.show({
  420. // top: 0,
  421. // type: 'success',
  422. // // color: '#000',
  423. // // bgColor: '#e8e8e8',
  424. // message: '复制课程标题成功',
  425. // duration: 1000 * 2,
  426. // fontSize: 20,
  427. // safeAreaInsetTop: true
  428. // })
  429. uni.showToast({
  430. icon: 'none',
  431. title: '复制课程标题成功'
  432. })
  433. }
  434. });
  435. }
  436. }
  437. }
  438. </script>
  439. <style scoped lang="scss">
  440. .card-share{
  441. position: relative;
  442. }
  443. .share{
  444. display: inline-block;
  445. position: absolute;
  446. top: 0;
  447. left: 0;
  448. width: 100%;
  449. height: 100%;
  450. opacity: 0;
  451. }
  452. .imgshe {
  453. display: flex;
  454. flex-direction: row-reverse
  455. }
  456. .point-box {
  457. height: 100%;
  458. width: 100%;
  459. .xu-box {
  460. border: #f5f5f5 4rpx dashed;
  461. padding: 20rpx 20rpx;
  462. }
  463. }
  464. #codeurl {
  465. position: relative;
  466. }
  467. ::v-deep {
  468. .model .u-fade-enter-active {
  469. z-index: 10075 !important;
  470. }
  471. }
  472. .sharePop {
  473. background-color: #fff;
  474. padding: 20px 0;
  475. padding-bottom: 60px;
  476. border-radius: 20px 20px 0 0;
  477. &-item {
  478. padding: 0 10px;
  479. box-sizing: border-box;
  480. font-family: PingFang SC, PingFang SC;
  481. font-weight: 400;
  482. font-size: 14px;
  483. display: inline-flex !important;
  484. image {
  485. height: 48px;
  486. width: 48px;
  487. margin-bottom: 10px;
  488. }
  489. }
  490. }
  491. .setTimebox {
  492. font-family: PingFang SC, PingFang SC;
  493. font-weight: 400;
  494. font-size: 14px;
  495. }
  496. .timetip {
  497. font-family: PingFang SC, PingFang SC;
  498. font-weight: 400;
  499. font-size: 14px;
  500. color: #2979ff;
  501. text-align: center;
  502. margin-bottom: 5px;
  503. }
  504. .courselist {
  505. font-family: PingFang SC, PingFang SC;
  506. font-weight: 400;
  507. font-size: 14px;
  508. &-item {
  509. width: 100%;
  510. border-radius: 14px;
  511. background-color: #fff;
  512. overflow: hidden;
  513. margin-bottom: 10px;
  514. }
  515. &-con {
  516. padding: 10px 10px 5px 10px;
  517. font-size: 12px;
  518. color: #777;
  519. }
  520. &-con-r {
  521. flex: 1;
  522. overflow: hidden;
  523. .more-t {
  524. flex: 1;
  525. font-size: 14px;
  526. color: #222;
  527. display: inline;
  528. }
  529. image {
  530. width: 20px;
  531. height: 20px;
  532. }
  533. .btn_icon {
  534. font-size: 14px;
  535. color: #1677ff;
  536. display: inline-flex;
  537. align-items: center;
  538. }
  539. }
  540. &-img {
  541. width: 110px;
  542. height: 70px;
  543. border-radius: 10px;
  544. overflow: hidden;
  545. flex-shrink: 0;
  546. margin-right: 10px;
  547. position: relative;
  548. image {
  549. height: 100%;
  550. width: 100%;
  551. }
  552. .status {
  553. position: absolute;
  554. top: 0;
  555. left: 0;
  556. z-index: 2;
  557. height: 21px;
  558. padding: 0 5px;
  559. box-sizing: border-box;
  560. line-height: 21px;
  561. border-radius: 10px 0 10px 0;
  562. text-align: center;
  563. color: #fff;
  564. background-color: #08ce36;
  565. }
  566. }
  567. &-desc {
  568. flex: 1;
  569. margin-top: 7px;
  570. }
  571. &-con-timebox {
  572. margin-top: 7px;
  573. flex-wrap: wrap;
  574. .acea-row {
  575. margin-right: 12px;
  576. margin-bottom: 5px;
  577. flex-wrap: nowrap;
  578. }
  579. .icon {
  580. margin-right: 5px;
  581. }
  582. }
  583. &-footer {
  584. padding: 5px;
  585. font-size: 14px;
  586. &-item {
  587. flex: 1;
  588. text-align: center;
  589. color: #1677ff;
  590. padding: 6px;
  591. box-sizing: border-box;
  592. }
  593. .shishi {
  594. border-left: 1px solid #f5f5f5;
  595. }
  596. .shuju {
  597. border-radius: 5px;
  598. border: 1px solid #1677ff;
  599. }
  600. }
  601. }
  602. </style>