courseItem.vue 13 KB

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