This commit is contained in:
parent
226eeabece
commit
c152e495a2
|
|
@ -5,15 +5,15 @@ import './index.scss'
|
|||
// xunmeng2,devcon
|
||||
|
||||
const LINK_PREFIX = '/p/'
|
||||
const DEFAULT_LINK_CODE = 'PJQQ'
|
||||
const LANDING_PAGE_URL = '/pages/landing/index'
|
||||
const SCENE_STORAGE_KEY = 'qrcodeScene'
|
||||
|
||||
function isValidLinkCode (code: string) {
|
||||
return Boolean(code) && !/[/?#&=]/.test(code)
|
||||
}
|
||||
|
||||
function normalizeQrLinkCode (scene?: string) {
|
||||
if (!scene) return DEFAULT_LINK_CODE
|
||||
if (!scene) return ''
|
||||
|
||||
try {
|
||||
const decodedScene = decodeURIComponent(scene)
|
||||
|
|
@ -23,10 +23,10 @@ function normalizeQrLinkCode (scene?: string) {
|
|||
? rawCode.slice(LINK_PREFIX.length)
|
||||
: rawCode
|
||||
|
||||
return isValidLinkCode(code) ? code : DEFAULT_LINK_CODE
|
||||
return isValidLinkCode(code) ? code : ''
|
||||
} catch (error) {
|
||||
console.warn('Invalid qrcode scene.', error)
|
||||
return DEFAULT_LINK_CODE
|
||||
return ''
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -34,9 +34,27 @@ export default function Index () {
|
|||
const [url, setUrl] = useState('')
|
||||
|
||||
useLoad(async (options) => {
|
||||
const scene = typeof options?.scene === 'string' ? options.scene.trim() : ''
|
||||
const currentScene = typeof options?.scene === 'string' ? options.scene.trim() : ''
|
||||
let scene = currentScene
|
||||
|
||||
if (!scene) {
|
||||
if (currentScene) {
|
||||
try {
|
||||
Taro.setStorageSync(SCENE_STORAGE_KEY, currentScene)
|
||||
} catch (error) {
|
||||
console.warn('Failed to save qrcode scene.', error)
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
const storedScene = Taro.getStorageSync(SCENE_STORAGE_KEY)
|
||||
scene = typeof storedScene === 'string' ? storedScene.trim() : ''
|
||||
} catch (error) {
|
||||
console.warn('Failed to read stored qrcode scene.', error)
|
||||
}
|
||||
}
|
||||
|
||||
const linkCode = normalizeQrLinkCode(scene)
|
||||
|
||||
if (!linkCode) {
|
||||
try {
|
||||
await Taro.redirectTo({ url: LANDING_PAGE_URL })
|
||||
} catch (error) {
|
||||
|
|
@ -51,7 +69,6 @@ export default function Index () {
|
|||
}
|
||||
|
||||
const wxCode = await Taro.login()
|
||||
const linkCode = normalizeQrLinkCode(scene)
|
||||
|
||||
console.log('Page loaded.', LINK_PREFIX, linkCode, wxCode)
|
||||
setUrl(`https://nb.zuom8.cn${LINK_PREFIX}${encodeURIComponent(linkCode)}?mpCode=${encodeURIComponent(wxCode.code)}`)
|
||||
|
|
|
|||
Loading…
Reference in New Issue