Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
IPC-footer
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Allen Bai
IPC-footer
Commits
e6876113
Commit
e6876113
authored
Feb 22, 2021
by
Allen Bai
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 添加环境变量
parent
a43165b8
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
9 deletions
+18
-9
index.ts
src/index.ts
+18
-9
No files found.
src/index.ts
View file @
e6876113
...
@@ -37,15 +37,26 @@ function request(option) {
...
@@ -37,15 +37,26 @@ function request(option) {
xhr
.
send
(
option
.
method
===
'POST'
?
option
.
data
:
null
)
xhr
.
send
(
option
.
method
===
'POST'
?
option
.
data
:
null
)
}
}
function
getRequestUrl
()
{
function
getRequestUrl
(
env
:
string
)
{
// 如果有测试链接 就用测试的链接
// 如果有测试链接 就用测试的链接
return
window
.
localStorage
.
getItem
(
'__ipc_test_url__'
)
||
'https://activity.tuia.cn/land/getIcpInfo'
let
localUrl
=
window
.
localStorage
.
getItem
(
'__ipc_test_url__'
)
if
(
localUrl
)
{
return
localUrl
}
switch
(
env
)
{
case
'test'
:
return
'https://activity.tuiatest.cn/land/getIcpInfo'
case
'pre'
:
return
'https://activity.tuiapre.cn/land/getIcpInfo'
default
:
return
'https://activity.tuia.cn/land/getIcpInfo'
}
}
}
function
getIPCByDomain
(
domain
:
string
)
{
function
getIPCByDomain
(
domain
:
string
,
env
:
string
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
request
({
request
({
url
:
`
${
getRequestUrl
()}
?domain=
${
encodeURIComponent
(
domain
)}
`
,
url
:
`
${
getRequestUrl
(
env
)}
?domain=
${
encodeURIComponent
(
domain
)}
`
,
method
:
'GET'
,
method
:
'GET'
,
success
(
res
)
{
success
(
res
)
{
console
.
log
(
'当前域名的IPC备案为'
,
res
)
console
.
log
(
'当前域名的IPC备案为'
,
res
)
...
@@ -71,6 +82,8 @@ type IPCFooterOptions = {
...
@@ -71,6 +82,8 @@ type IPCFooterOptions = {
boardStyles
?:
Optional
<
CSSStyleDeclaration
>
boardStyles
?:
Optional
<
CSSStyleDeclaration
>
/** 是否测试 */
/** 是否测试 */
isTest
?:
boolean
isTest
?:
boolean
/** 运行环境 */
env
?:
'test'
|
'pre'
|
undefined
}
}
function
addStyles
(
ele
:
HTMLElement
,
styles
:
Optional
<
CSSStyleDeclaration
>
=
{})
{
function
addStyles
(
ele
:
HTMLElement
,
styles
:
Optional
<
CSSStyleDeclaration
>
=
{})
{
...
@@ -117,15 +130,11 @@ async function mountIPCFooter(opts: IPCFooterOptions = {}) {
...
@@ -117,15 +130,11 @@ async function mountIPCFooter(opts: IPCFooterOptions = {}) {
let
IPCNumberString
=
''
let
IPCNumberString
=
''
try
{
try
{
IPCNumberString
=
(
await
getIPCByDomain
(
opts
.
domain
||
location
.
host
))
as
string
IPCNumberString
=
(
await
getIPCByDomain
(
opts
.
domain
||
location
.
host
,
opts
.
env
))
as
string
}
catch
(
err
)
{
}
catch
(
err
)
{
console
.
log
(
'备案号获取失败'
)
console
.
log
(
'备案号获取失败'
)
}
}
if
(
opts
.
isTest
)
{
IPCNumberString
=
'测试环境的 IPC-123'
}
if
(
!
IPCNumberString
)
{
if
(
!
IPCNumberString
)
{
currentTaskId
=
null
currentTaskId
=
null
return
return
...
...
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