Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
saas
/
mini-program
/
ai-card
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 0ece257b
authored
Oct 28, 2022
by
luyt
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
fix:调整分享
1 parent
fe710afe
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
146 additions
and
2 deletions
app.js
pages/checkProduct/checkProduct.js
project.private.config.json
utils/share.js
app.js
View file @
0ece257
...
...
@@ -7,6 +7,8 @@ import {
wechatApi
}
from
'./api/api'
import
{
trackData
}
from
'./utils/data'
// //全局分享
// import './utils/share'
import
eventbus
from
'./utils/evenbus'
// 实例化对象存储
...
...
pages/checkProduct/checkProduct.js
View file @
0ece257
...
...
@@ -573,12 +573,13 @@ Page({
* 用户点击右上角分享
*/
onShareAppMessage() {
let {senceData,actNum,activeNavIdx} = this.data
let {senceData,actNum,activeNavIdx
,isShare
} = this.data
let product = senceData[actNum]?.productList[activeNavIdx].proName
console.log('product: ', product);
return {
// title: `
给你分享一个活动
$
{
product
}
,戳我参与
~
`,
title: `
给你分享一个活动,戳我参与
~
`,
path:`
/
pages
/
checkProduct
/
checkProduct
?
actNum
=
$
{
actNum
}
&
activeNavIdx
=
$
{
activeNavIdx
}
&
isShare
=
$
{
isShare
}
`
}
},
/**
...
...
project.private.config.json
View file @
0ece257
...
...
@@ -178,7 +178,7 @@
},
"setting"
:
{
"urlCheck"
:
false
,
"compileHotReLoad"
:
tru
e
"compileHotReLoad"
:
fals
e
},
"libVersion"
:
"2.26.1"
,
"projectname"
:
"ai-card"
...
...
utils/share.js
0 → 100644
View file @
0ece257
/** 分享
* @param {*} shareTitle 分享标题
* @param {*} sharePath 分享页面路径 不传默认当前页
* @param {*} shareImage 分享图片 不传默认当前页面截图
* @param {*} shareQuery 分享页面参数
* @param {*} noPageAuth 分享页面是否需要登录拦截
* @param {*} shareFun 分享页面
* @param {*} shareTrackData 分享埋点数据
* @param {*} onViewTrack 开启浏览埋点
* @returns
*/
// import {
// reportData
// } from '~/api/index.js'
// import USERAPI from '~/api/usersApi/index'
class
Share
{
constructor
()
{
console
.
log
(
'---------------- 分享初始化 ----------------'
)
this
.
initPageProxy
()
}
/**全局注册事件 */
initPageProxy
()
{
let
thisPage
=
Page
let
_this
=
this
Page
=
function
(
el
)
{
try
{
el
||
(
el
=
{}),
_this
.
pageLeaveProxy
(
el
),
thisPage
.
apply
(
this
,
arguments
)
}
catch
(
el
)
{
thisPage
.
apply
(
this
,
arguments
)
}
}
}
/**设置全局分享 */
pageLeaveProxy
(
page
)
{
const
onLoad
=
page
.
onLoad
,
that
=
this
if
(
page
.
onShareAppMessage
)
{
const
that
=
this
page
.
onShareAppMessage
=
function
()
{
let
{
shareTitle
,
sharePath
,
shareImage
,
shareQuery
,
noPageAuth
,
shareFun
,
shareTrackData
}
=
this
,
path
=
`/
${
this
.
route
}
`
if
(
sharePath
)
path
=
`/
${
sharePath
}
`
path
+=
that
.
setCommonShareQuery
()
if
(
shareQuery
)
path
+=
`&
${
shareQuery
}
`
console
.
log
(
'==============='
,
path
)
if
(
!
noPageAuth
)
path
=
`/login/loading/loading?url=
${
encodeURIComponent
(
path
)}
`
if
(
shareFun
)
shareFun
()
if
(
shareTrackData
)
that
.
reportShareData
(
shareTrackData
)
return
{
path
,
title
:
shareTitle
,
imageUrl
:
shareImage
}
}
}
if
(
page
.
onShareTimeline
)
{
page
.
onShareTimeline
=
function
()
{
let
{
shareTitle
,
shareImage
,
shareQuery
,
shareFun
,
shareTrackData
}
=
this
if
(
shareFun
)
shareFun
()
if
(
shareTrackData
)
that
.
reportShareData
(
shareTrackData
)
shareQuery
=
that
.
setCommonShareQuery
(
shareQuery
)
console
.
log
(
shareQuery
)
return
{
query
:
shareQuery
,
title
:
shareTitle
,
imageUrl
:
shareImage
}
}
}
page
.
onLoad
=
async
function
()
{
onLoad
&&
onLoad
.
apply
(
this
,
arguments
)
if
(
this
.
onViewTrack
)
{
const
WXUSERINFO
=
await
USERAPI
.
getWXUserInfo
(),
{
USERINFO
}
=
that
.
getCommonData
(),
shareInfo
=
this
.
options
// if (shareInfo.shareOpenId) reportData({
// openId: WXUSERINFO.openId || '',
// unionId: WXUSERINFO.unionId || '',
// nickName: WXUSERINFO.nickName || '',
// avatar: WXUSERINFO.avatarUrl || '',
// phone: WXUSERINFO.phone || USERINFO.phone || '',
// ...shareInfo
// }, 1)
}
}
}
getCommonData
()
{
const
WXUSERINFO
=
wx
.
$storage
.
get
(
'wx_user_info'
),
USERINFO
=
wx
.
$storage
.
get
(
'userInfo'
)
return
{
WXUSERINFO
,
USERINFO
}
}
setCommonShareQuery
(
query
)
{
const
{
WXUSERINFO
,
USERINFO
}
=
this
.
getCommonData
(),
thisPage
=
wx
.
$router
.
getPageInstance
().
options
query
=
`
${
query
?
`?
${
query
}
&`
:
'?'
}
merchantId=
${
thisPage
.
merchantId
||
USERINFO
.
merchantId
||
''
}
&shareOpenId=
${
thisPage
.
shareOpenId
||
WXUSERINFO
.
openId
||
''
}
&sharePhone=
${
thisPage
.
sharePhone
||
USERINFO
.
phone
||
''
}
`
return
query
}
// reportShareData(shareTrackData) {
// const {
// WXUSERINFO,
// USERINFO
// } = this.getCommonData(),
// thisPage = wx.$router.getPageInstance().options
// // reportData({
// // openId: WXUSERINFO.openId || '',
// // unionId: WXUSERINFO.unionId || '',
// // nickName: WXUSERINFO.nickName || '',
// // avatar: WXUSERINFO.avatarUrl || '',
// // phone: USERINFO.phone || '',
// // merchantId: thisPage.merchantId || USERINFO.merchantId || '',
// // shareOpenId: thisPage.shareOpenId || WXUSERINFO.openId || '',
// // sharePhone: thisPage.sharePhone || USERINFO.phone || '',
// // ...shareTrackData
// // })
// }
}
new
Share
()
\ No newline at end of file
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment