Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
web-lib
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
郑磊
web-lib
Commits
c933efcf
Commit
c933efcf
authored
Jul 14, 2026
by
郑磊
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
允许query参数覆盖cookie参数
parent
79876586
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
12 deletions
+22
-12
environment.ts
miniapp/environment.ts
+4
-5
environment.ts
web/environment.ts
+18
-7
No files found.
miniapp/environment.ts
View file @
c933efcf
import
{
getCookie
}
from
'../web/cookie'
import
{
run_methods
}
from
'../web/environment'
import
{
run_methods
,
getQueryOrCookie
}
from
'../web/environment'
//小程序的run_methods总是不显示顶部状态栏
if
(
!
run_methods
.
includes
(
'hidetopbar'
))
{
...
...
@@ -11,12 +10,12 @@ export { type DeviceType, device, in_app, lang, open_source, run_methods } from
/**
* 当前轻应用的appid
*/
export
const
appid
=
getCookie
(
'appid'
,
''
)
export
const
appid
=
get
QueryOr
Cookie
(
'appid'
,
''
)
/**
* 当前轻应用登录用户的openid
*/
export
const
openid
=
getCookie
(
'openid'
,
''
)
export
const
openid
=
get
QueryOr
Cookie
(
'openid'
,
''
)
/**
* 当前轻应用所在直播间主播的openid
*/
export
const
room_openid
=
getCookie
(
'room_openid'
,
''
)
export
const
room_openid
=
get
QueryOr
Cookie
(
'room_openid'
,
''
)
web/environment.ts
View file @
c933efcf
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'
/**
* 包名
*/
export
const
source
=
getCookie
(
'source'
)
||
'xinxiuweb'
export
const
source
=
get
QueryOr
Cookie
(
'source'
)
||
'xinxiuweb'
/**
* 是否在app内运行
*/
export
const
in_app
=
getCookie
(
'platform'
)
===
'app'
&&
!!
source
export
const
in_app
=
get
QueryOr
Cookie
(
'platform'
)
===
'app'
&&
!!
source
/**
* 设备类型
...
...
@@ -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
?
get
QueryOr
Cookie
(
'canUseIAP'
)
===
'true'
:
false
/**
* 当前所在直播间的主播号
*/
export
const
room_number
=
(()
=>
{
if
(
!
in_app
)
return
0
if
(
getCookie
(
'isOnLiveRoom'
)
!==
'1'
)
return
0
const
identifier
=
parseInt
(
getCookie
(
'roomIdentifier'
,
'0'
))
if
(
get
QueryOr
Cookie
(
'isOnLiveRoom'
)
!==
'1'
)
return
0
const
identifier
=
parseInt
(
get
QueryOr
Cookie
(
'roomIdentifier'
,
'0'
))
return
!
isNaN
(
identifier
)
&&
Number
.
isSafeInteger
(
identifier
)
&&
identifier
>
0
?
identifier
:
0
})()
...
...
@@ -50,12 +61,12 @@ function normalizeLang(lang: string): string {
/**
* 语言标识
*/
export
const
lang
=
normalizeLang
(
getCookie
(
'lang'
)
||
navigator
.
language
)
export
const
lang
=
normalizeLang
(
get
QueryOr
Cookie
(
'lang'
)
||
navigator
.
language
)
/**
* 当前页面的打开来源
*/
export
const
open_source
=
getCookie
(
'open_source'
)
||
''
export
const
open_source
=
get
QueryOr
Cookie
(
'open_source'
)
||
''
/**
* 通过地址栏runmethod参数传递给页面的控制参数
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment