Commit a69b0551 authored by lg's avatar lg

chore: 活动页入口

parent 7aa44551
......@@ -27,6 +27,13 @@
"navigationStyle": "custom"
}
},
{
"path": "pages/activity/index",
"style": {
"navigationBarTitleText": "",
"navigationStyle": "custom"
}
},
{
"path": "pages/search/search",
"style": {
......
<template>
<web-view :src="src" @message="onMessage"/>
</template>
<script setup>
import {ref} from "vue";
import {onLoad, onShareAppMessage, onShareTimeline} from "@dcloudio/uni-app";
import {useGlobalStore} from "../../stores/global";
const globalStore = useGlobalStore()
const src = ref("");
const urlMap = {
'main': 'http://192.168.10.108:8001/#/page',
};
const shareData = ref(null)
onLoad((options) => {
console.log('页面参数:', options)
wx.showShareMenu({
withShareTicket: true,
menus: ['shareAppMessage', 'shareTimeline']
})
let url = "";
if (options.type) {
const type = options.type;
url = urlMap[type];
}
const params = {...(options || {})}
delete params.type
delete params.params
const {unionId, cuk} = globalStore
if (unionId && !params.unionId) params.unionId = unionId
if (cuk && !params.cuk) params.cuk = cuk
const paramStr = Object.keys(params)
.filter(key => params[key] !== undefined && params[key] !== null && params[key] !== '')
.map(key => `${key}=${encodeURIComponent(params[key])}`)
.join('&')
url = paramStr
? url + (url.includes('?') ? '&' : '?') + paramStr + (options.params ? '&' + decodeURIComponent(options.params) : '')
: url
src.value = url
console.log('webview url:', url)
});
function onMessage(e) {
const data = e.detail.data
const lastData = data[data.length - 1]
console.log('webview 消息接收:', lastData)
switch (lastData.type) {
case 'share':
shareData.value = lastData.payload
break;
}
}
function shareHook() {
if (shareData.value) {
const {url, title, imageUrl = ''} = shareData.value
console.log('使用分享数据:', shareData.value)
return {
title,
path: url || '/pages/index/index',
imageUrl,
success: function (res) {
console.log('分享成功:', res)
//星妈会埋点方法,用户分享成功后触发事件
},
fail: function (res) {
console.log('分享失败:', res)
},
complete: function (res) {
console.log('分享完成:', res)
}
}
}
// 如果没有分享数据,返回默认分享
return {
path: '/pages/index/index'
}
}
onShareAppMessage((options) => {
console.log('分享给朋友数据:', shareData.value)
return shareHook()
})
onShareTimeline((options) => {
console.log('分享到朋友圈数据:', shareData.value)
return shareHook()
})
</script>
<script>
/*export default {
onShareAppMessage() {
return this.shareHook()
}
}*/
</script>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment