course.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <template>
  2. <view class="column hidden" style="height: 100%;">
  3. <!-- <view class="p20 bgf" style="z-index: 999;">
  4. <u-subsection class="subsection" :list="list" :current="current" bgColor="#e7f1fe" activeColor="#1677ff"
  5. :fontSize="15" :bold="false" @change="sectionChange" ></u-subsection>
  6. </view>
  7. <living v-if="current==0" style="margin-top: -240rpx;"></living> -->
  8. <liveCourse @child-data-update="onChildDataUpdate" :parent-method="handleParentMethod"></liveCourse>
  9. <u-popup :show="showShare" :closeOnClickOverlay="true" :round='20' @close="closeShare">
  10. <view class="sharePop x-ac">
  11. <!--#ifdef MP-WEIXIN-->
  12. <view class="sharePop-item y-f card-share">
  13. <image :src="imgPath+'/app/images/card_icon.png'"
  14. mode="aspectFill" style="width: 80rpx; height: 80rpx;margin-top: 20rpx;"></image>
  15. <view style="font-weight: bold;margin-bottom: 4px;">生成卡片</view>
  16. <view style="font-size: 12px;color: #888;">指导分享轻松转发</view>
  17. <button open-type="share" class="share">分享课程</button>
  18. <view @click="copy"
  19. class="base-color-6 u-border ptb10 plr30 radius50 mt20">复制页面地址</view>
  20. </view>
  21. <!--#endif-->
  22. </view>
  23. </u-popup>
  24. </view>
  25. </template>
  26. <script>
  27. import liveCourse from "@/components/liveCourse.vue"
  28. import living from "@/components/living.vue"
  29. import {copyuniLink} from "@/api/courseManage.js"
  30. export default {
  31. components: {
  32. living,
  33. liveCourse
  34. },
  35. data() {
  36. return {
  37. list: [{
  38. name: '直播课',
  39. }, {
  40. name: '训练营'
  41. }],
  42. current: 0,
  43. childdata: [],
  44. showShare: false
  45. }
  46. },
  47. onLoad() {
  48. wx.showShareMenu({
  49. withShareTicket: true, // 支持群聊分享带shareTicket
  50. menus: ['shareAppMessage'] // 同时启用两种分享
  51. })
  52. console.log(this.$store.state.imgpath+'/app/images/card_icon.png')
  53. },
  54. computed: {
  55. imgPath() {
  56. return this.$store.state.imgpath
  57. },
  58. imgname() {
  59. return this.$store.state.logoname
  60. }
  61. },
  62. mounted() {},
  63. onShareAppMessage() {
  64. return {
  65. title: this.childdata.title, // 分享卡片标题
  66. path: this.childdata.path + "?course=" + JSON.stringify(this.childdata.params), // 目标页面路径
  67. // 携带参数:将当前页面的数据拼接到路径中
  68. imageUrl: this.childdata.img, // 分享卡片封面图(可选)
  69. success: (res) => {
  70. console.log("分享成功", res);
  71. },
  72. fail: (err) => {
  73. console.log("分享失败", err);
  74. },
  75. }
  76. },
  77. methods: {
  78. copy(){
  79. this.copyuniLinks()
  80. },
  81. copyuniLinks(){
  82. const data={
  83. appid:wx.getAccountInfoSync().miniProgram.appId,//乐氏本源
  84. linkStr:this.childdata.path + "?course=" + JSON.stringify(this.childdata.params)
  85. }
  86. copyuniLink(data).then(res=>{
  87. if(res.code==200){
  88. uni.hideLoading();
  89. setTimeout(() => {
  90. uni.setClipboardData({
  91. data:res.data,
  92. success: () => {
  93. uni.showToast({
  94. title: '链接已复制',
  95. icon: 'none',
  96. duration: 2000
  97. });
  98. },
  99. fail: () => {
  100. uni.showToast({
  101. title: '复制失败',
  102. icon: 'none'
  103. });
  104. }
  105. });
  106. }, 200)
  107. }else{
  108. uni.hideLoading();
  109. uni.showToast({
  110. title: res.msg,
  111. icon: 'none'
  112. });
  113. }
  114. })
  115. },
  116. closeShare() {
  117. this.showShare = false
  118. // console.log('open');
  119. },
  120. handleParentMethod() {
  121. // uni.showToast({ title: '父组件方法被调用' });
  122. /* if (!this.childdata || Object.keys(this.childdata).length === 0) {
  123. uni.showToast({
  124. title: '数据未准备好,无法分享',
  125. icon: 'none'
  126. });
  127. return;
  128. }
  129. this.$nextTick(() => {
  130. setTimeout(() => {
  131. this.showShare = this.childdata.onshow
  132. }, 200)
  133. }) */
  134. },
  135. onChildDataUpdate(data) {
  136. this.childdata = data
  137. this.showShare = this.childdata.onshow
  138. console.log(this.childdata);
  139. console.log('父组件', this.childdata.path + "?course=" +JSON.stringify(this.childdata.params) )
  140. },
  141. sectionChange(index) {
  142. this.current = index
  143. }
  144. }
  145. }
  146. </script>
  147. <style lang="scss">
  148. .card-share{
  149. position: relative;
  150. }
  151. .share{
  152. display: inline-block;
  153. position: absolute;
  154. top: 0;
  155. left: 0;
  156. width: 100%;
  157. height: 80%;
  158. opacity: 0;
  159. }
  160. .sharePop {
  161. background-color: #fff;
  162. padding: 30rpx 0;
  163. border-radius: 20px 20px 0 0;
  164. /* #ifdef MP-WEIXIN */
  165. /* #endif */
  166. /* #ifdef H5 */
  167. padding-bottom: 60px;
  168. /* #endif */
  169. &-item {
  170. padding: 0 10px;
  171. box-sizing: border-box;
  172. font-family: PingFang SC, PingFang SC;
  173. font-weight: 400;
  174. font-size: 14px;
  175. display: inline-flex !important;
  176. image {
  177. height: 48px;
  178. width: 48px;
  179. margin-bottom: 10px;
  180. }
  181. }
  182. }
  183. </style>