12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- <template>
- <view>
- <!-- 用于显示提示信息 -->
- <view v-if="showTips" class="tips">
- <text>请点击右上角“...”选择“在浏览器打开”跳转应用</text>
- <button @click="copyLink">复制链接</button>
- </view>
- <!-- 内置 WebView 组件 -->
- <web-view v-if="url" :src="url" @message="handleMessage"></web-view>
- </view>
- </template>
- <script>
- export default {
- data() {
- return {
- url: '', // 要加载的 H5 链接
- schemeUrl: '', // 接收的 Scheme(如 rtlive://course?courseId=1)
- showTips: false, // 是否显示引导提示
- };
- },
- onLoad(options) {
- if (options.url) {
- this.schemeUrl = decodeURIComponent(options.url);
- console.log('Scheme 数据:', this.schemeUrl); // 输出:rtlive://course?courseId=1
- // 尝试直接跳转(可能被微信拦截)
- this.tryOpenScheme();
- }
- },
- methods: {
- // 尝试直接打开 Scheme(通常会被微信拦截)
- tryOpenScheme() {
- const timestamp = new Date().getTime(); // 获取当前时间戳
- this.url = `https://yjf.natappvip.cc/H5Demo/index.html?t=${timestamp}`;
- // 如果跳转失败,显示引导提示
- this.showTips = true;
- },
- // 复制链接到剪贴板
- copyLink() {
- uni.setClipboardData({
- data: this.schemeUrl,
- success: () => {
- uni.showToast({ title: '链接已复制,请在浏览器打开' });
- },
- });
- },
- // 监听 WebView 消息(可选)
- handleMessage(e) {
- console.log('WebView 消息:', e.detail);
- },
- },
- };
- </script>
- <style>
- .tips {
- padding: 20px;
- text-align: center;
- background: #f8f8f8;
- }
- </style>
|