<template>
<view class="certification" style="height: 100vh;">
<wx-open-launch-weapp
style="position: absolute; top: 0; left: 0; width: 100%; height: 100%"
:username="userName"
:path="path"
@launch="handleLaunchFn"
@error="handleErrorFn"
id="launch-btn"
>
<div v-is="'script'" type="text/wxtag-template">
<div
class="btn"
style="height: 100%;display: flex;flex-direction: column;align-items: center;padding-top: 50px;width: 100%;background: #666666;"
>
打开小程序
</div>
</div>
</wx-open-launch-weapp>
</view>
</template>
<script setup>
import { ref, reactive, getCurrentInstance, toRefs, nextTick } from 'vue';
import { wxConfig } from '@/common/api.js';
import { onLoad, onShow } from '@dcloudio/uni-app';
import wx from 'weixin-js-sdk';
let dataRef = reactive({
path: '/pages/secondary/product-details',
userName: 'gh_fa95b8d03e47'
});
const { proxy } = getCurrentInstance();
onLoad(option => {
nextTick(function() {
let paramData = { url: window.location.href.split('#')[0]};
wxConfig(paramData).then(res => {
if(res.code == 0){
const data = res.result
wx.config({
debug: false,
appId: data.appId,
timestamp: data.timestamp,
nonceStr: data.nonceStr,
signature: data.signature,
jsApiList: ['wx-open-launch-weapp'],
openTagList: ['wx-open-launch-weapp']
});
wx.ready(e => {
var btn = document.getElementById('launch-btn');
btn.addEventListener('launch', function (e) {
console.log('success');
});
btn.addEventListener('error', function (e) {
console.log('fail', e.detail);
});
console.log(e, '成功验证');
});
wx.error(e => {
console.log(e, '失败信息');
});
}
})
});
});
onShow(() => {});
const { path, userName } = toRefs(dataRef);
const handleLaunchFn = e => {
console.log('success');
};
const handleErrorFn = e => {
console.log('Error');
};
</script>
<style lang="scss" scoped>
.certification {
width: 100%;
background: #f0f0f0;
overflow: hidden;
}
.opentag {
display: block;
width: 400rpx;
height: 400rpx;
background-color: aliceblue;
}
</style>