course.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. </view>
  10. </template>
  11. <script>
  12. import liveCourse from "@/components/liveCourse.vue"
  13. import living from "@/components/living.vue"
  14. export default {
  15. components: {
  16. living,
  17. liveCourse
  18. },
  19. data() {
  20. return {
  21. list: [{
  22. name: '直播课',
  23. }, {
  24. name: '训练营'
  25. }],
  26. current:0,
  27. childdata:[]
  28. }
  29. },
  30. onLoad() {
  31. wx.showShareMenu({
  32. withShareTicket: true, // 支持群聊分享带shareTicket
  33. menus: ['shareAppMessage'] // 同时启用两种分享
  34. })
  35. },
  36. mounted() {
  37. },
  38. methods: {
  39. handleParentMethod() {
  40. uni.showToast({ title: '父组件方法被调用' });
  41. if (!this.childdata || Object.keys(this.childdata).length === 0) {
  42. uni.showToast({ title: '数据未准备好,无法分享', icon: 'none' });
  43. return;
  44. }
  45. this.$nextTick(()=>{
  46. setTimeout(()=>{
  47. uni.share({
  48. provider: 'weixin',
  49. scene: 'WXSceneSession', // 分享到会话
  50. type: 0,
  51. title: this.childdata.title,
  52. path: this.childdata.path+"?course="+this.childdata.params,
  53. imageUrl: this.childdata.img,
  54. success: (res) => {
  55. console.log('分享成功', res);
  56. uni.showToast({
  57. title: '分享成功',
  58. icon: 'none'
  59. });
  60. },
  61. fail: (err) => {
  62. console.log('分享失败', err);
  63. uni.showToast({
  64. title: '分享失败,请稍后再试',
  65. icon: 'none'
  66. });
  67. }
  68. });
  69. },200)
  70. })
  71. },
  72. onChildDataUpdate(data){
  73. this.childdata=data
  74. console.log('父组件',data)
  75. },
  76. onShareAppMessage() {
  77. return {
  78. title:this.childdata.title , // 分享卡片标题
  79. path:this.childdata.path+"?course="+this.childdata.params, // 目标页面路径
  80. // 携带参数:将当前页面的数据拼接到路径中
  81. imageUrl: this.childdata.img, // 分享卡片封面图(可选)
  82. success: (res) => {
  83. console.log("分享成功", res);
  84. },
  85. fail: (err) => {
  86. console.log("分享失败", err);
  87. },
  88. }
  89. },
  90. sectionChange(index){
  91. this.current=index
  92. }
  93. }
  94. }
  95. </script>
  96. <style lang="scss">
  97. </style>