You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
89 lines
2.7 KiB
89 lines
2.7 KiB
export function buildHomeSharePath(targetPath) {
|
|
if (!targetPath) return '/pages/index/index'
|
|
return '/pages/index/index?targetPath=' + encodeURIComponent(targetPath)
|
|
}
|
|
|
|
export function buildGroupHomeSharePath(params) {
|
|
params = params || {}
|
|
const query = [
|
|
'shareType=group',
|
|
'type=shop',
|
|
'shopId=' + encodeURIComponent(params.shopId || ''),
|
|
'groupId=' + encodeURIComponent(params.groupId || ''),
|
|
'targetMembers=' + encodeURIComponent(params.targetMembers || 2),
|
|
'isFaceToFace=' + encodeURIComponent(params.isFaceToFace || 0)
|
|
]
|
|
if (params.orderScene) {
|
|
query.push('orderScene=' + encodeURIComponent(params.orderScene))
|
|
}
|
|
return '/pages/index/index?' + query.join('&')
|
|
}
|
|
|
|
export function buildGroupTargetPath(params) {
|
|
params = params || {}
|
|
if (!params.shopId || !params.groupId) return ''
|
|
let targetPath = '/package2/group/groupBuySingle?type=shop' +
|
|
'&shopId=' + encodeURIComponent(params.shopId) +
|
|
'&groupId=' + encodeURIComponent(params.groupId) +
|
|
'&targetMembers=' + encodeURIComponent(params.targetMembers || 2) +
|
|
'&isFaceToFace=' + encodeURIComponent(params.isFaceToFace || 0)
|
|
if (params.orderScene) {
|
|
targetPath += '&orderScene=' + encodeURIComponent(params.orderScene)
|
|
}
|
|
return targetPath
|
|
}
|
|
|
|
export function normalizeShareTargetPath(value) {
|
|
let targetPath = String(value || '')
|
|
if (targetPath.indexOf('%2F') === 0 || targetPath.indexOf('%2f') === 0) {
|
|
try {
|
|
targetPath = decodeURIComponent(targetPath)
|
|
} catch (e) {}
|
|
}
|
|
if (!targetPath || targetPath.charAt(0) !== '/') return ''
|
|
if (targetPath.indexOf('/pages/index/index') === 0) return ''
|
|
return targetPath
|
|
}
|
|
|
|
export function resolveHomeShareTarget(query) {
|
|
query = query || {}
|
|
if (query.shareType === 'group') {
|
|
return buildGroupTargetPath(query)
|
|
}
|
|
if (query.targetPath) {
|
|
return normalizeShareTargetPath(query.targetPath)
|
|
}
|
|
return ''
|
|
}
|
|
|
|
export function isShareEnterScene(options) {
|
|
if (!options || options.scene == null) return false
|
|
const scene = Number(options.scene)
|
|
return scene === 1007 || scene === 1008 || scene === 1044 || scene === 1154
|
|
}
|
|
|
|
export function getEnterShareTarget(options) {
|
|
if (!options) {
|
|
try {
|
|
if (uni.getEnterOptionsSync) {
|
|
options = uni.getEnterOptionsSync()
|
|
} else if (uni.getLaunchOptionsSync) {
|
|
options = uni.getLaunchOptionsSync()
|
|
}
|
|
} catch (e) {}
|
|
}
|
|
if (!isShareEnterScene(options)) return ''
|
|
return resolveHomeShareTarget(options && options.query)
|
|
}
|
|
|
|
export function getCurrentEnterShareTarget() {
|
|
let options = null
|
|
try {
|
|
if (uni.getEnterOptionsSync) {
|
|
options = uni.getEnterOptionsSync()
|
|
} else if (uni.getLaunchOptionsSync) {
|
|
options = uni.getLaunchOptionsSync()
|
|
}
|
|
} catch (e) {}
|
|
return getEnterShareTarget(options)
|
|
}
|
|
|