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.

111 lines
3.2 KiB

3 months ago
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
}
21 hours ago
export function buildGroupShopTargetPath(shopId) {
if (!shopId) return ''
return '/package2/group/groupBuySingle?type=shop&shopId=' + encodeURIComponent(shopId)
}
export function resolveMiniCodeSceneTarget(scene) {
let value = String(scene || '').trim()
if (!value) return ''
try {
value = decodeURIComponent(value)
} catch (e) {}
if (!value) return ''
if (value.indexOf('groupShop:') === 0) {
return buildGroupShopTargetPath(value.replace('groupShop:', ''))
}
if (/^s[A-Za-z0-9_-]{1,31}$/.test(value)) {
return buildGroupShopTargetPath(value.slice(1))
}
return ''
}
3 months ago
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)
}