test4.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <template>
  2. <view style="padding: 100rpx">
  3. <wx-open-launch-weapp
  4. id="launch-btn"
  5. username="gh_170e5722c167"
  6. path="pages/index/index"
  7. >
  8. <script type="text/wxtag-template">
  9. <style>
  10. .link_btn {
  11. width: 400rpx;
  12. /* margin: 600rpx auto 0; */
  13. height: 88rpx;
  14. background: linear-gradient(88deg, #5FBC23 0%, #85CE52 100%);
  15. opacity: 1;
  16. border-radius: 44rpx;
  17. color: #fff;
  18. text-align: center;
  19. line-height: 88rpx;
  20. font-size: 50rpx;
  21. }
  22. </style>
  23. <div class="link_btn">前往争霸赛小程序</div>
  24. </script>
  25. </wx-open-launch-weapp>
  26. </view>
  27. </template>
  28. <script>
  29. import { getSignPackage } from '@/apis/app.js';
  30. export default {
  31. name: 'ShareIndex',
  32. data() {
  33. return {
  34. html: '',
  35. username: 'gh_170e5722c167',
  36. path: 'pages/index/index', //争霸赛小程序初始进入路径
  37. }
  38. },
  39. onReady() {
  40. this.signInit();
  41. // 微信 config 信息验证后,渲染开放标签
  42. uni.$on('jweixinReady', () => {
  43. // this.init()
  44. })
  45. },
  46. methods: {
  47. //进入争霸赛小程序
  48. signInit() {
  49. const script = document.createElement('script')
  50. script.type = 'text/javascript'
  51. script.src = 'https://res.wx.qq.com/open/js/jweixin-1.6.0.js'
  52. document.getElementsByTagName('head')[0].appendChild(script)
  53. const _this = this;
  54. let link = window.location.href;
  55. getSignPackage({
  56. url: link
  57. }).then(res => {
  58. if (res.code == 200) {
  59. let data = JSON.parse(res.data);
  60. // 判断是否支持分享
  61. wx.config({
  62. debug: false, //开启debug模式.正式环境设置为false,测试环境设置为true
  63. appId: data.appId,
  64. timestamp: data.timestamp,
  65. nonceStr: data.nonceStr,
  66. signature: data.signature,
  67. jsApiList: ['wx-open-launch-weapp'], //根据需要看需要哪些SDK的功能
  68. openTagList: ['wx-open-launch-weapp'] // 跳转小程序时必填
  69. });
  70. wx.ready(() => {
  71. uni.showToast({
  72. title: '获取成功',
  73. })
  74. uni.$emit('jweixinReady', res)
  75. this.$nextTick(() => {
  76. uni.showToast({
  77. title: '拿到了',
  78. })
  79. let btn = document.getElementById('launch-btn');
  80. btn.addEventListener('launch', e => {
  81. uni.showToast({
  82. title: '小程序打开成功',
  83. })
  84. console.log('success');
  85. });
  86. btn.addEventListener('error', e => {
  87. uni.showToast({
  88. title: '小程序打开失败',
  89. })
  90. console.log('fail', e.detail);
  91. });
  92. });
  93. })
  94. wx.error(err => {
  95. uni.showToast({
  96. title: '获取失败',
  97. })
  98. console.log(err, 'err')
  99. uni.showModal({
  100. content: err || '失败',
  101. showCancel: false
  102. })
  103. });
  104. } else {
  105. uni.showModal({
  106. content: res.msg || '分享失败',
  107. showCancel: false
  108. })
  109. }
  110. });
  111. },
  112. }
  113. }
  114. </script>
  115. <style scoped lang="scss">
  116. #share_container {
  117. width: 100%;
  118. height: 100%;
  119. display: flex;
  120. justify-content: space-between;
  121. flex-direction: column;
  122. }
  123. #imgWrapper {
  124. flex: 1;
  125. @include flex();
  126. .showCan {
  127. width: 680rpx;
  128. height: 960rpx;
  129. border-radius: 14rpx;
  130. box-shadow:0px 0px 23px 2px rgba(194,133,58,0.5);
  131. }
  132. }
  133. .sharetext {
  134. font-size: 80rpx;
  135. text-align: center;
  136. margin: 8rpx 0;
  137. box-sizing: border-box;
  138. padding: 30rpx 24rpx;
  139. }
  140. </style>