course.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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" v-if="imgname!='乐氏本源'"
  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. appid() {
  62. return this.$store.state.appid
  63. },
  64. },
  65. mounted() {},
  66. onShareAppMessage() {
  67. return {
  68. title: this.childdata.title, // 分享卡片标题
  69. path: this.childdata.path + "?course=" + JSON.stringify(this.childdata.params), // 目标页面路径
  70. // 携带参数:将当前页面的数据拼接到路径中
  71. imageUrl: this.childdata.img, // 分享卡片封面图(可选)
  72. success: (res) => {
  73. console.log("分享成功", res);
  74. },
  75. fail: (err) => {
  76. console.log("分享失败", err);
  77. },
  78. }
  79. },
  80. methods: {
  81. copyuniLinks(){
  82. const data={
  83. linkStr:this.childdata.path + "?course=" + JSON.stringify(this.childdata.params),
  84. }
  85. copyuniLink(data).then(res=>{
  86. console.log(res)
  87. })
  88. },
  89. copy(){
  90. uni.showLoading({
  91. title: "处理中..."
  92. });
  93. const data={
  94. appid:this.appid,
  95. linkStr:this.childdata.path + "?course=" + JSON.stringify(this.childdata.params)
  96. }
  97. copyuniLink(data).then(res=>{
  98. if(res.code==200){
  99. uni.hideLoading();
  100. setTimeout(() => {
  101. uni.setClipboardData({
  102. data:res.data,
  103. // data: this.childdata.path + "?course=" + JSON.stringify(this.childdata.params),
  104. success: () => {
  105. uni.showToast({
  106. title: '链接已复制',
  107. icon: 'none',
  108. duration: 2000
  109. });
  110. },
  111. fail: () => {
  112. uni.showToast({
  113. title: '复制失败',
  114. icon: 'none'
  115. });
  116. }
  117. });
  118. }, 200)
  119. }else{
  120. uni.hideLoading();
  121. uni.showToast({
  122. title: res.msg,
  123. icon: 'none'
  124. });
  125. }
  126. })
  127. // copyuniLinks(){
  128. // },
  129. },
  130. closeShare() {
  131. this.showShare = false
  132. // console.log('open');
  133. },
  134. handleParentMethod() {
  135. // uni.showToast({ title: '父组件方法被调用' });
  136. /* if (!this.childdata || Object.keys(this.childdata).length === 0) {
  137. uni.showToast({
  138. title: '数据未准备好,无法分享',
  139. icon: 'none'
  140. });
  141. return;
  142. }
  143. this.$nextTick(() => {
  144. setTimeout(() => {
  145. this.showShare = this.childdata.onshow
  146. }, 200)
  147. }) */
  148. },
  149. onChildDataUpdate(data) {
  150. this.childdata = data
  151. this.showShare = this.childdata.onshow
  152. console.log(this.childdata);
  153. console.log('父组件', this.childdata.path + "?course=" +JSON.stringify(this.childdata.params) )
  154. },
  155. sectionChange(index) {
  156. this.current = index
  157. }
  158. }
  159. }
  160. </script>
  161. <style lang="scss">
  162. .card-share{
  163. position: relative;
  164. }
  165. .share{
  166. display: inline-block;
  167. position: absolute;
  168. top: 0;
  169. left: 0;
  170. width: 100%;
  171. height: 80%;
  172. opacity: 0;
  173. }
  174. .sharePop {
  175. background-color: #fff;
  176. padding: 30rpx 0;
  177. border-radius: 20px 20px 0 0;
  178. /* #ifdef MP-WEIXIN */
  179. /* #endif */
  180. /* #ifdef H5 */
  181. padding-bottom: 60px;
  182. /* #endif */
  183. &-item {
  184. padding: 0 10px;
  185. box-sizing: border-box;
  186. font-family: PingFang SC, PingFang SC;
  187. font-weight: 400;
  188. font-size: 14px;
  189. display: inline-flex !important;
  190. image {
  191. height: 48px;
  192. width: 48px;
  193. margin-bottom: 10px;
  194. }
  195. }
  196. }
  197. </style>