123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- <template>
- <view class="link_btn">
- <wx-open-launch-weapp
- id="launch-btn"
- username="gh_170e5722c167"
- path="pages/index/index"
- >
- <script type="text/wxtag-template">
- <div style="width: 400rpx">前往争霸赛小程序</div>
- </script>
- </wx-open-launch-weapp>
- </view>
- </template>
- <script>
- import { getSignPackage } from '@/apis/app.js';
- export default {
- name: 'ShareIndex',
- data() {
- return {
- html: '',
- username: 'gh_170e5722c167',
- path: 'pages/index/index', //争霸赛小程序初始进入路径
- }
- },
- onReady() {
- this.signInit();
- // 微信 config 信息验证后,渲染开放标签
- uni.$on('jweixinReady', () => {
- // this.init()
- })
- },
- methods: {
- //进入争霸赛小程序
- signInit() {
- const script = document.createElement('script')
- script.type = 'text/javascript'
- script.src = 'https://res.wx.qq.com/open/js/jweixin-1.6.0.js'
- document.getElementsByTagName('head')[0].appendChild(script)
- const _this = this;
- let link = window.location.href;
- getSignPackage({
- url: link
- }).then(res => {
- if (res.code == 200) {
- let data = JSON.parse(res.data);
- // 判断是否支持分享
- wx.config({
- debug: false, //开启debug模式.正式环境设置为false,测试环境设置为true
- appId: data.appId,
- timestamp: data.timestamp,
- nonceStr: data.nonceStr,
- signature: data.signature,
- jsApiList: ['wx-open-launch-weapp'], //根据需要看需要哪些SDK的功能
- openTagList: ['wx-open-launch-weapp'] // 跳转小程序时必填
- });
- wx.ready(() => {
- uni.showToast({
- title: '获取成功',
- })
- uni.$emit('jweixinReady', res)
- this.$nextTick(() => {
- uni.showToast({
- title: '拿到了',
- })
- let btn = document.getElementById('launch-btn');
- btn.addEventListener('launch', e => {
- uni.showToast({
- title: '小程序打开成功',
- })
- console.log('success');
- });
- btn.addEventListener('error', e => {
- uni.showToast({
- title: '小程序打开失败',
- })
- console.log('fail', e.detail);
- });
- });
- })
- wx.error(err => {
- uni.showToast({
- title: '获取失败',
- })
- console.log(err, 'err')
- uni.showModal({
- content: err || '失败',
- showCancel: false
- })
- });
- } else {
- uni.showModal({
- content: res.msg || '分享失败',
- showCancel: false
- })
- }
- });
- },
- }
- }
- </script>
- <style scoped lang="scss">
- .link_btn {
- width: 400rpx;
- margin: 600rpx auto 0;
- height: 88rpx;
- background: linear-gradient(88deg, #5FBC23 0%, #85CE52 100%);
- opacity: 1;
- border-radius: 44rpx;
- color: #fff;
- text-align: center;
- line-height: 88rpx;
- font-size: 50rpx;
- }
- </style>
|