courseItem.vue 17 KB

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