courseItem.vue 15 KB

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