2 changed files with 116 additions and 0 deletions
@ -0,0 +1,27 @@ |
|||
export function hasLogin() { |
|||
return !!uni.getStorageSync('id') |
|||
} |
|||
|
|||
export function getCurrentPagePath() { |
|||
const pages = typeof getCurrentPages === 'function' ? getCurrentPages() : [] |
|||
const page = pages[pages.length - 1] |
|||
if (!page || !page.route) return '/pages/index/index' |
|||
const options = page.options || {} |
|||
const query = Object.keys(options) |
|||
.filter(key => options[key] !== undefined && options[key] !== null && options[key] !== '') |
|||
.map(key => key + '=' + encodeURIComponent(String(options[key]))) |
|||
.join('&') |
|||
return '/' + page.route + (query ? '?' + query : '') |
|||
} |
|||
|
|||
export function requireLoginToCurrentPage() { |
|||
if (hasLogin()) return true |
|||
const redirectKey = 'login_redirect_' + Date.now() |
|||
const targetPath = getCurrentPagePath() |
|||
uni.setStorageSync(redirectKey, targetPath) |
|||
uni.setStorageSync('authPendingTargetPath', targetPath) |
|||
uni.redirectTo({ |
|||
url: '/package2/login/login?redirect=' + redirectKey |
|||
}) |
|||
return false |
|||
} |
|||
@ -0,0 +1,89 @@ |
|||
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) |
|||
} |
|||
Loading…
Reference in new issue