Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
jinfa-admin
Project
Project
Details
Activity
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
shenshaokai
jinfa-admin
Commits
89e89a19
Commit
89e89a19
authored
Feb 24, 2022
by
前端-许佳敏
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: 调整构建前脚本,引入国际化
parent
d4faf550
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
151 additions
and
95 deletions
+151
-95
package.json
package.json
+1
-1
batchAxiosHttps.js
scripts/services/batchAxiosHttps.js
+91
-0
index.js
scripts/services/index.js
+14
-94
server.js
scripts/services/server.js
+44
-0
global.d.ts
src/global/config/global.d.ts
+1
-0
No files found.
package.json
View file @
89e89a19
...
...
@@ -14,7 +14,7 @@
"start:analyze"
:
"ANALYZE=1 umi dev"
,
"scripts:build"
:
"node scripts/run"
,
"scripts:init"
:
"node scripts/init"
,
"scripts:build-
yxc"
:
"node scripts/run http://yxc-web-demo.shushangyun.com/api
"
,
"scripts:build-
test"
:
"cross-env PRO_ENV=v2 node scripts/run
"
,
"start"
:
"yarn scripts:init && yarn api && yarn scripts:build && umi dev"
,
"start:dev"
:
"umi dev"
,
"build"
:
"yarn api && yarn scripts:build && yarn build:clean"
,
...
...
scripts/services/batchAxiosHttps.js
0 → 100644
View file @
89e89a19
const
Axios
=
require
(
'axios'
).
default
;
const
deepClone
=
require
(
'clone'
)
const
{
prefixServiceConfig
,
serviceConfig
}
=
require
(
'./server'
)
const
BACK_GATEWAY
=
process
.
env
.
BACK_GATEWAY
const
demoFetch
=
require
(
'../../demo'
).
fetchConfig
const
isDemo
=
true
const
remoteUrl
=
BACK_GATEWAY
||
process
.
argv
[
2
]
||
'http://10.0.0.25:8100'
console
.
log
(
`\n当前访问的后端url是
${
remoteUrl
}
!!!!!!`
)
const
axios
=
Axios
.
create
({
baseURL
:
remoteUrl
,
responseType
:
'json'
,
headers
:
{
"source"
:
"1"
}
})
async
function
prefixHttp
()
{
try
{
const
{
data
}
=
await
axios
(
prefixServiceConfig
.
global
)
if
(
data
.
code
===
1000
)
{
return
data
.
data
}
else
{
return
{}
}
}
catch
(
error
)
{
console
.
log
(
error
)
}
}
// 批量组装接口
async
function
batchAxiosHttps
(
requestConfig
)
{
const
asyncHttpQueue
=
deepClone
(
serviceConfig
)
const
httpErrorQueue
=
[]
const
serverErrorQueue
=
[]
console
.
log
(
'
\
n'
)
for
(
const
item
in
serviceConfig
)
{
if
(
JSON
.
stringify
(
item
)
!==
'{}'
)
{
for
(
const
subItem
in
serviceConfig
[
item
])
{
try
{
axios
.
interceptors
.
request
.
use
(
config
=>
{
config
.
headers
=
Object
.
assign
({},
config
.
headers
,
requestConfig
.
headers
)
return
config
})
const
data
=
await
axios
(
serviceConfig
[
item
][
subItem
])
// 当接口出错时 不写入json文件
if
(
data
.
data
.
code
===
1000
)
{
asyncHttpQueue
[
item
][
subItem
]
=
data
.
data
.
data
}
else
{
serverErrorQueue
.
push
({
...
asyncHttpQueue
[
item
][
subItem
],
...
data
.
data
})
// 默认置为null
asyncHttpQueue
[
item
][
subItem
]
=
null
}
}
catch
(
err
)
{
console
.
log
(
err
)
httpErrorQueue
.
push
({
...
serviceConfig
[
item
][
subItem
],
...
err
.
response
.
data
})
}
}
}
}
if
(
httpErrorQueue
.
length
>
0
)
{
console
.
log
(
'
\
n网络错误
\
n'
)
// 可在此做日志收集
console
.
log
(
httpErrorQueue
)
}
if
(
serverErrorQueue
.
length
>
0
)
{
console
.
log
(
'
\
n接口服务错误
\
n'
)
// 可在此做日志收集
console
.
log
(
serverErrorQueue
)
}
if
(
httpErrorQueue
.
length
>
0
||
serverErrorQueue
.
length
>
0
)
{
// 退出构建
console
.
log
(
'
\
n脚本构建失败!!!!!!'
)
// 终止当前进程
process
.
exit
(
1
)
}
return
isDemo
?
Object
.
assign
(
asyncHttpQueue
,
await
demoFetch
())
:
asyncHttpQueue
}
module
.
exports
=
{
prefixHttp
,
batchAxiosHttps
,
}
scripts/services/index.js
View file @
89e89a19
/*
* @Author: LeeJiancong
* @Date: 2020-0
8-10 14:41:27
* @Date: 2020-0
7-17 18:01:43
* @LastEditors: XieZhiXiong
* @LastEditTime: 2021-08-11 10:01:27
* @Copyright: 1549414730@qq.com
* @LastEditTime: 2021-08-07 11:08:07
*/
/**
* 用于在项目开始前获取所有的配置
...
...
@@ -12,16 +13,11 @@
*/
const
Axios
=
require
(
'axios'
).
default
;
const
deepClone
=
require
(
'clone'
)
const
demoFetch
=
require
(
'../../demo'
).
fetchConfig
const
{
prefixHttp
,
batchAxiosHttps
}
=
require
(
'./batchAxiosHttps'
)
const
isDemo
=
true
const
SITE_ID
=
Number
(
process
.
env
.
SITE_ID
)
const
BACK_GATEWAY
=
process
.
env
.
BACK_GATEWAY
const
remoteUrl
=
BACK_GATEWAY
||
process
.
argv
[
2
]
||
'http://10.0.0.25:8100'
console
.
log
(
`\n当前访问的后端url是
${
remoteUrl
}
!!!!!!`
)
if
(
!
SITE_ID
)
{
console
.
log
(
'
\
n构建失败!!!!!!'
)
...
...
@@ -29,92 +25,16 @@ if (!SITE_ID) {
process
.
exit
(
1
)
}
const
axios
=
Axios
.
create
({
baseURL
:
remoteUrl
,
responseType
:
'json'
,
})
const
serviceConfig
=
{
//初始化会员支付策略配置
// payConfig: {
// payInitializeConfig: {
// url: '/pay/initialize/config',
// method: 'get'
// },
// payPlatformPayConfig: {
// url: '/pay/platform/pay/config',
// method: 'get'
// }
// },
web
:
{
shopInfo
:
{
url
:
'/manage/shop/findShopsBySiteId'
,
params
:
{
siteId
:
SITE_ID
,
},
method
:
'get'
},
orderMode
:
{
url
:
'/system/rule/getOrderMode'
,
method
:
'get'
}
},
global
:
{
siteInfo
:
{
url
:
'/manage/paas/site/details'
,
params
:
{
id
:
SITE_ID
},
method
:
'get'
}
}
}
// 批量组装接口
async
function
batchAxiosHttps
()
{
const
asyncHttpQueue
=
deepClone
(
serviceConfig
)
const
httpErrorQueue
=
[]
const
serverErrorQueue
=
[]
console
.
log
(
'
\
n'
)
for
(
const
item
in
serviceConfig
)
{
if
(
JSON
.
stringify
(
item
)
!==
'{}'
)
{
for
(
const
subItem
in
serviceConfig
[
item
])
{
try
{
const
data
=
await
axios
(
serviceConfig
[
item
][
subItem
])
// 当接口出错时 不写入json文件
if
(
data
.
data
.
code
===
1000
)
{
asyncHttpQueue
[
item
][
subItem
]
=
data
.
data
.
data
}
else
{
serverErrorQueue
.
push
({
...
asyncHttpQueue
[
item
][
subItem
],
...
data
.
data
})
// 默认置为null
asyncHttpQueue
[
item
][
subItem
]
=
null
}
}
catch
(
err
)
{
httpErrorQueue
.
push
({
...
serviceConfig
[
item
][
subItem
],
...
err
.
response
.
data
})
}
}
}
}
if
(
httpErrorQueue
.
length
>
0
)
{
console
.
log
(
'
\
n网络错误
\
n'
)
// 可在此做日志收集
console
.
log
(
httpErrorQueue
)
}
if
(
serverErrorQueue
.
length
>
0
)
{
console
.
log
(
'接口服务错误
\
n'
)
// 可在此做日志收集
console
.
log
(
serverErrorQueue
)
}
if
(
httpErrorQueue
.
length
>
0
||
serverErrorQueue
.
length
>
0
)
{
// 退出构建
console
.
log
(
'
\
n脚本构建失败!!!!!!'
)
// 终止当前进程
process
.
exit
(
1
)
async
function
pullConfigHttp
()
{
const
data
=
await
prefixHttp
()
const
{
language
=
'zh'
}
=
data
console
.
log
(
`当前站点语言为
${
language
}
`
)
const
result
=
await
batchAxiosHttps
({
headers
:
{
'Accept-Language'
:
language
}
return
isDemo
?
Object
.
assign
(
asyncHttpQueue
,
await
demoFetch
())
:
asyncHttpQueue
})
return
result
}
exports
.
fetchConfig
=
batchAxiosHttps
exports
.
fetchConfig
=
pullConfigHttp
scripts/services/server.js
0 → 100644
View file @
89e89a19
const
SITE_ID
=
Number
(
process
.
env
.
SITE_ID
)
/**
* 前置接口 用于后续配置接口的信息获取
*/
const
prefixServiceConfig
=
{
global
:
{
url
:
'/manage/paas/site/details'
,
params
:
{
id
:
SITE_ID
},
method
:
'get'
}
}
const
serviceConfig
=
{
web
:
{
shopInfo
:
{
url
:
'/manage/shop/findShopsBySiteId'
,
params
:
{
siteId
:
SITE_ID
,
},
method
:
'get'
},
orderMode
:
{
url
:
'/system/rule/getOrderMode'
,
method
:
'get'
}
},
global
:
{
siteInfo
:
{
url
:
'/manage/paas/site/details'
,
params
:
{
id
:
SITE_ID
},
method
:
'get'
}
}
}
module
.
exports
=
{
serviceConfig
,
prefixServiceConfig
}
src/global/config/global.d.ts
View file @
89e89a19
...
...
@@ -33,6 +33,7 @@ export interface SiteInfo {
logo
:
string
;
siteUrl
:
string
;
symbol
?:
any
;
language
:
string
;
}
export
interface
Global
{
...
...
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