magic-helper
Version:
this is magic helper
28 lines (25 loc) • 736 B
text/typescript
import qs from 'qs'
import { onLaunch } from '@dcloudio/uni-app'
import { PARAMS_LOCAL_KEY } from '../constant'
import { SCAN_RES_KEY } from '../constant'
export const getParamsForH5 = () => {
const paramsStr = location.href.split('?')[1]
const params = qs.parse(paramsStr)
return params
}
// 初始化参数
export const initParams = () => {
return new Promise((resolve, reject) => {
onLaunch(() => {
const params = getParamsForH5()
if (params.authorization) {
uni.setStorageSync(PARAMS_LOCAL_KEY, params)
}
// 存储扫码结果到本地
if (params.scan) {
uni.setStorageSync(SCAN_RES_KEY, params.scan)
}
resolve(params)
})
})
}