Commit e6876113 authored by Allen Bai's avatar Allen Bai

feat: 添加环境变量

parent a43165b8
...@@ -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
......
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