Commit c933efcf authored by 郑磊's avatar 郑磊

允许query参数覆盖cookie参数

parent 79876586
import { getCookie } from '../web/cookie' import { run_methods, getQueryOrCookie } from '../web/environment'
import { run_methods } from '../web/environment'
//小程序的run_methods总是不显示顶部状态栏 //小程序的run_methods总是不显示顶部状态栏
if (!run_methods.includes('hidetopbar')) { if (!run_methods.includes('hidetopbar')) {
...@@ -11,12 +10,12 @@ export { type DeviceType, device, in_app, lang, open_source, run_methods } from ...@@ -11,12 +10,12 @@ export { type DeviceType, device, in_app, lang, open_source, run_methods } from
/** /**
* 当前轻应用的appid * 当前轻应用的appid
*/ */
export const appid = getCookie('appid', '') export const appid = getQueryOrCookie('appid', '')
/** /**
* 当前轻应用登录用户的openid * 当前轻应用登录用户的openid
*/ */
export const openid = getCookie('openid', '') export const openid = getQueryOrCookie('openid', '')
/** /**
* 当前轻应用所在直播间主播的openid * 当前轻应用所在直播间主播的openid
*/ */
export const room_openid = getCookie('room_openid', '') export const room_openid = getQueryOrCookie('room_openid', '')
import { getCookie } from './cookie' import { getCookie } from './cookie'
export function getQueryOrCookie(name: string): string | undefined | null
export function getQueryOrCookie(name: string, defaultValue: string): string
export function getQueryOrCookie(name: string, defaultValue?: string) {
const url = new URL(location.href)
const query = url.searchParams.get(name)
if (typeof query === 'string') {
return query
}
return getCookie(name) ?? defaultValue
}
/** /**
* 设备类型 * 设备类型
*/ */
...@@ -8,12 +19,12 @@ export type DeviceType = 'iOS' | 'android' | 'wap' ...@@ -8,12 +19,12 @@ export type DeviceType = 'iOS' | 'android' | 'wap'
/** /**
* 包名 * 包名
*/ */
export const source = getCookie('source') || 'xinxiuweb' export const source = getQueryOrCookie('source') || 'xinxiuweb'
/** /**
* 是否在app内运行 * 是否在app内运行
*/ */
export const in_app = getCookie('platform') === 'app' && !!source export const in_app = getQueryOrCookie('platform') === 'app' && !!source
/** /**
* 设备类型 * 设备类型
...@@ -27,15 +38,15 @@ export const device: DeviceType = in_app ...@@ -27,15 +38,15 @@ export const device: DeviceType = in_app
/** /**
* 是否允许使用内购 * 是否允许使用内购
*/ */
export const can_use_iap = in_app ? getCookie('canUseIAP') === 'true' : false export const can_use_iap = in_app ? getQueryOrCookie('canUseIAP') === 'true' : false
/** /**
* 当前所在直播间的主播号 * 当前所在直播间的主播号
*/ */
export const room_number = (() => { export const room_number = (() => {
if (!in_app) return 0 if (!in_app) return 0
if (getCookie('isOnLiveRoom') !== '1') return 0 if (getQueryOrCookie('isOnLiveRoom') !== '1') return 0
const identifier = parseInt(getCookie('roomIdentifier', '0')) const identifier = parseInt(getQueryOrCookie('roomIdentifier', '0'))
return !isNaN(identifier) && Number.isSafeInteger(identifier) && identifier > 0 ? identifier : 0 return !isNaN(identifier) && Number.isSafeInteger(identifier) && identifier > 0 ? identifier : 0
})() })()
...@@ -50,12 +61,12 @@ function normalizeLang(lang: string): string { ...@@ -50,12 +61,12 @@ function normalizeLang(lang: string): string {
/** /**
* 语言标识 * 语言标识
*/ */
export const lang = normalizeLang(getCookie('lang') || navigator.language) export const lang = normalizeLang(getQueryOrCookie('lang') || navigator.language)
/** /**
* 当前页面的打开来源 * 当前页面的打开来源
*/ */
export const open_source = getCookie('open_source') || '' export const open_source = getQueryOrCookie('open_source') || ''
/** /**
* 通过地址栏runmethod参数传递给页面的控制参数 * 通过地址栏runmethod参数传递给页面的控制参数
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment