cloudcc-cli 1.6.0 → 1.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1147 -1128
- package/bin/cc.js +48 -48
- package/bin/plugin.js +5 -5
- package/bin/project.js +5 -5
- package/package.json +34 -34
- package/src/classes/create.js +43 -43
- package/src/classes/index.js +8 -8
- package/src/classes/publish.js +48 -47
- package/src/config/get.js +22 -0
- package/src/config/index.js +8 -0
- package/src/config/use.js +16 -0
- package/src/object/get.js +16 -0
- package/src/object/index.js +7 -0
- package/src/plugin/create.js +80 -80
- package/src/plugin/create1.js +66 -67
- package/src/plugin/index.js +8 -8
- package/src/plugin/publish.js +298 -305
- package/src/plugin/publish1.js +286 -293
- package/src/project/create.js +89 -89
- package/src/project/create1.js +111 -94
- package/src/project/index.js +7 -7
- package/src/recordType/get.js +16 -0
- package/src/recordType/index.js +7 -0
- package/src/script/create.js +33 -0
- package/src/script/index.js +8 -0
- package/src/script/publish.js +69 -0
- package/src/timer/create.js +29 -29
- package/src/timer/index.js +8 -8
- package/src/timer/publish.js +47 -47
- package/src/token/get.js +13 -0
- package/src/token/index.js +7 -0
- package/src/triggers/create.js +35 -35
- package/src/triggers/index.js +8 -8
- package/src/triggers/publish.js +51 -51
- package/template/Appvue +29 -29
- package/template/babelconfigjs +5 -5
- package/template/cloudcc-cli.configjs +1 -0
- package/template/demojava +14 -14
- package/template/gitignore +11 -0
- package/template/index.js +57 -52
- package/template/indexhtml +21 -21
- package/template/indexvue +34 -34
- package/template/javaconfigjson +2 -2
- package/template/mainjs +13 -13
- package/template/package-lockjson +12115 -12115
- package/template/packagejson +42 -46
- package/template/vueconfigjs +26 -26
- package/utils/checkVersion.js +105 -105
- package/utils/http.js +122 -122
- package/utils/utils.js +54 -44
package/template/packagejson
CHANGED
|
@@ -1,47 +1,43 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "cloudcc-plugin",
|
|
3
|
-
"version": "1.0.0",
|
|
4
|
-
"description": "cloudcc-plugin-dev",
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
"
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
"vue": "
|
|
15
|
-
"vue-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
"
|
|
30
|
-
|
|
31
|
-
"
|
|
32
|
-
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
"
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
"> 1%",
|
|
44
|
-
"last 2 versions",
|
|
45
|
-
"not dead"
|
|
46
|
-
]
|
|
1
|
+
{
|
|
2
|
+
"name": "cloudcc-plugin",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "cloudcc-plugin-dev",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"serve": "vue-cli-service serve"
|
|
7
|
+
},
|
|
8
|
+
"dependencies": {
|
|
9
|
+
"element-ui": "2.15.12",
|
|
10
|
+
"vue": "2.6.14",
|
|
11
|
+
"vue-custom-element": "3.3.0"
|
|
12
|
+
},
|
|
13
|
+
"devDependencies": {
|
|
14
|
+
"@vue/cli-plugin-babel": "~4.5.0",
|
|
15
|
+
"@vue/cli-plugin-eslint": "~4.5.0",
|
|
16
|
+
"@vue/cli-service": "~4.5.0",
|
|
17
|
+
"babel-eslint": "^10.1.0",
|
|
18
|
+
"eslint": "^6.7.2",
|
|
19
|
+
"eslint-plugin-vue": "^6.2.2",
|
|
20
|
+
"sass": "1.26.8",
|
|
21
|
+
"sass-loader": "8.0.2",
|
|
22
|
+
"vue-template-compiler": "2.6.14"
|
|
23
|
+
},
|
|
24
|
+
"eslintConfig": {
|
|
25
|
+
"root": true,
|
|
26
|
+
"env": {
|
|
27
|
+
"node": true
|
|
28
|
+
},
|
|
29
|
+
"extends": [
|
|
30
|
+
"plugin:vue/essential",
|
|
31
|
+
"eslint:recommended"
|
|
32
|
+
],
|
|
33
|
+
"parserOptions": {
|
|
34
|
+
"parser": "babel-eslint"
|
|
35
|
+
},
|
|
36
|
+
"rules": {}
|
|
37
|
+
},
|
|
38
|
+
"browserslist": [
|
|
39
|
+
"> 1%",
|
|
40
|
+
"last 2 versions",
|
|
41
|
+
"not dead"
|
|
42
|
+
]
|
|
47
43
|
}
|
package/template/vueconfigjs
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
// 打包排除依赖包
|
|
2
|
-
const external = process.env.NODE_ENV == 'development' ? {} : {
|
|
3
|
-
"vue": 'Vue',
|
|
4
|
-
"vue-router": 'VueRouter',
|
|
5
|
-
'vue-echarts': 'VueECharts',
|
|
6
|
-
'element-ui': 'ELEMENT',
|
|
7
|
-
"axios": 'axios',
|
|
8
|
-
"d3": 'd3',
|
|
9
|
-
'echarts': 'echarts',
|
|
10
|
-
"jschardet": 'jschardet',
|
|
11
|
-
"crypto-js": 'CryptoJS',
|
|
12
|
-
"vue-i18n": 'VueI18n',
|
|
13
|
-
}
|
|
14
|
-
module.exports = {
|
|
15
|
-
publicPath: '/',
|
|
16
|
-
// 关闭生成Map文件
|
|
17
|
-
productionSourceMap: false,
|
|
18
|
-
configureWebpack: {
|
|
19
|
-
},
|
|
20
|
-
// css强制内联在js中
|
|
21
|
-
css: { extract: false },
|
|
22
|
-
// 精细化修改webpack打包逻辑
|
|
23
|
-
chainWebpack: config => {
|
|
24
|
-
// 排除某些包,禁止打包到chunck中
|
|
25
|
-
config.externals(external)
|
|
26
|
-
}
|
|
1
|
+
// 打包排除依赖包
|
|
2
|
+
const external = process.env.NODE_ENV == 'development' ? {} : {
|
|
3
|
+
"vue": 'Vue',
|
|
4
|
+
"vue-router": 'VueRouter',
|
|
5
|
+
'vue-echarts': 'VueECharts',
|
|
6
|
+
'element-ui': 'ELEMENT',
|
|
7
|
+
"axios": 'axios',
|
|
8
|
+
"d3": 'd3',
|
|
9
|
+
'echarts': 'echarts',
|
|
10
|
+
"jschardet": 'jschardet',
|
|
11
|
+
"crypto-js": 'CryptoJS',
|
|
12
|
+
"vue-i18n": 'VueI18n',
|
|
13
|
+
}
|
|
14
|
+
module.exports = {
|
|
15
|
+
publicPath: '/',
|
|
16
|
+
// 关闭生成Map文件
|
|
17
|
+
productionSourceMap: false,
|
|
18
|
+
configureWebpack: {
|
|
19
|
+
},
|
|
20
|
+
// css强制内联在js中
|
|
21
|
+
css: { extract: false },
|
|
22
|
+
// 精细化修改webpack打包逻辑
|
|
23
|
+
chainWebpack: config => {
|
|
24
|
+
// 排除某些包,禁止打包到chunck中
|
|
25
|
+
config.externals(external)
|
|
26
|
+
}
|
|
27
27
|
}
|
package/utils/checkVersion.js
CHANGED
|
@@ -1,105 +1,105 @@
|
|
|
1
|
-
// 导入cli配置文件
|
|
2
|
-
const config = require("../package.json")
|
|
3
|
-
const inquirer = require("inquirer")
|
|
4
|
-
const exec = require('child_process').execSync;
|
|
5
|
-
const chalk = require("chalk")
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* 检查cli版本号
|
|
9
|
-
*/
|
|
10
|
-
function checkNpmVersion() {
|
|
11
|
-
let currentVersion = Number(config.version.replace(/\./g, ""));
|
|
12
|
-
let onlineVersionNum
|
|
13
|
-
let onlineVersion = '0.0.1'
|
|
14
|
-
|
|
15
|
-
// 从阿里源获取版本号
|
|
16
|
-
onlineVersion = exec(`npm view cloudcc-cli version --registry http://registry.npmmirror.com`)
|
|
17
|
-
onlineVersion = onlineVersion.toString("utf8").trim();
|
|
18
|
-
|
|
19
|
-
// 从阿里源获取版本号
|
|
20
|
-
// try {
|
|
21
|
-
// onlineVersion = exec(`curl -s https://npmmirror.com/api/info?pkgName=cloudcc-cli`)
|
|
22
|
-
// onlineVersion = JSON.parse(onlineVersion.toString("utf8").trim()).data['dist-tags'].latest
|
|
23
|
-
// } catch (e) {
|
|
24
|
-
// }
|
|
25
|
-
onlineVersionNum = Number(onlineVersion.replace(/\./g, ""));
|
|
26
|
-
|
|
27
|
-
console.log(chalk.green(
|
|
28
|
-
`
|
|
29
|
-
********************************************************************************
|
|
30
|
-
* *
|
|
31
|
-
* CloudCC CLI *
|
|
32
|
-
* *
|
|
33
|
-
* 当前版本:V${config.version} *
|
|
34
|
-
* 最新版本:V${onlineVersion} *
|
|
35
|
-
* 更新内容:https://npmmirror.com/package/cloudcc-cli/home *
|
|
36
|
-
* *
|
|
37
|
-
* 开发者文档:https://cloudccone.feishu.cn/wiki/JZ7CwcRfriU8taknCKCcwKEmncd *
|
|
38
|
-
* *
|
|
39
|
-
********************************************************************************
|
|
40
|
-
`
|
|
41
|
-
))
|
|
42
|
-
|
|
43
|
-
// 如果结果大于0,那么提示升级
|
|
44
|
-
if (onlineVersionNum - currentVersion > 0) {
|
|
45
|
-
return onlineVersion;
|
|
46
|
-
}
|
|
47
|
-
return null;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* 是否升级
|
|
52
|
-
* @returns 对象
|
|
53
|
-
*/
|
|
54
|
-
function askUpdate() {
|
|
55
|
-
console.log();
|
|
56
|
-
const prompt = [{
|
|
57
|
-
type: 'list',
|
|
58
|
-
message: '是否进行自动升级?',
|
|
59
|
-
name: 'update',
|
|
60
|
-
choices: [
|
|
61
|
-
"Yes", 'No'
|
|
62
|
-
],
|
|
63
|
-
}];
|
|
64
|
-
return inquirer.prompt(prompt)
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* 升级cli
|
|
69
|
-
*/
|
|
70
|
-
function update(onlineVersion) {
|
|
71
|
-
console.log()
|
|
72
|
-
console.log(chalk.green("升级中,预计3分钟完成,请稍后..."));
|
|
73
|
-
console.log()
|
|
74
|
-
let os = process.platform
|
|
75
|
-
console.log(chalk.yellow(`如无法自动更新,请使用命令更新:${'darwin' == os ? 'sudo' : ''} npm install -g cloudcc-cli@${onlineVersion} --registry http://registry.npmmirror.com`));
|
|
76
|
-
exec(`${'darwin' == os ? 'sudo' : ''} npm install -g cloudcc-cli@${onlineVersion} --registry http://registry.npmmirror.com`)
|
|
77
|
-
console.log()
|
|
78
|
-
console.log(chalk.green("升级完成!请重新运行"));
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* 检查更新
|
|
83
|
-
*/
|
|
84
|
-
async function checkUpdate() {
|
|
85
|
-
let onlineVersion;
|
|
86
|
-
try {
|
|
87
|
-
onlineVersion = checkNpmVersion();
|
|
88
|
-
} catch (error) {
|
|
89
|
-
console.log("error", error)
|
|
90
|
-
onlineVersion = false;
|
|
91
|
-
}
|
|
92
|
-
if (onlineVersion) {
|
|
93
|
-
let res = await askUpdate()
|
|
94
|
-
if ("Yes" == res.update) {
|
|
95
|
-
update(onlineVersion)
|
|
96
|
-
return true;
|
|
97
|
-
} else {
|
|
98
|
-
return false
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
return false
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
module.exports = { checkUpdate }
|
|
1
|
+
// 导入cli配置文件
|
|
2
|
+
const config = require("../package.json")
|
|
3
|
+
const inquirer = require("inquirer")
|
|
4
|
+
const exec = require('child_process').execSync;
|
|
5
|
+
const chalk = require("chalk")
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 检查cli版本号
|
|
9
|
+
*/
|
|
10
|
+
function checkNpmVersion() {
|
|
11
|
+
let currentVersion = Number(config.version.replace(/\./g, ""));
|
|
12
|
+
let onlineVersionNum
|
|
13
|
+
let onlineVersion = '0.0.1'
|
|
14
|
+
|
|
15
|
+
// 从阿里源获取版本号
|
|
16
|
+
onlineVersion = exec(`npm view cloudcc-cli version --registry http://registry.npmmirror.com`)
|
|
17
|
+
onlineVersion = onlineVersion.toString("utf8").trim();
|
|
18
|
+
|
|
19
|
+
// 从阿里源获取版本号
|
|
20
|
+
// try {
|
|
21
|
+
// onlineVersion = exec(`curl -s https://npmmirror.com/api/info?pkgName=cloudcc-cli`)
|
|
22
|
+
// onlineVersion = JSON.parse(onlineVersion.toString("utf8").trim()).data['dist-tags'].latest
|
|
23
|
+
// } catch (e) {
|
|
24
|
+
// }
|
|
25
|
+
onlineVersionNum = Number(onlineVersion.replace(/\./g, ""));
|
|
26
|
+
|
|
27
|
+
console.log(chalk.green(
|
|
28
|
+
`
|
|
29
|
+
********************************************************************************
|
|
30
|
+
* *
|
|
31
|
+
* CloudCC CLI *
|
|
32
|
+
* *
|
|
33
|
+
* 当前版本:V${config.version} *
|
|
34
|
+
* 最新版本:V${onlineVersion} *
|
|
35
|
+
* 更新内容:https://npmmirror.com/package/cloudcc-cli/home *
|
|
36
|
+
* *
|
|
37
|
+
* 开发者文档:https://cloudccone.feishu.cn/wiki/JZ7CwcRfriU8taknCKCcwKEmncd *
|
|
38
|
+
* *
|
|
39
|
+
********************************************************************************
|
|
40
|
+
`
|
|
41
|
+
))
|
|
42
|
+
|
|
43
|
+
// 如果结果大于0,那么提示升级
|
|
44
|
+
if (onlineVersionNum - currentVersion > 0) {
|
|
45
|
+
return onlineVersion;
|
|
46
|
+
}
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* 是否升级
|
|
52
|
+
* @returns 对象
|
|
53
|
+
*/
|
|
54
|
+
function askUpdate() {
|
|
55
|
+
console.log();
|
|
56
|
+
const prompt = [{
|
|
57
|
+
type: 'list',
|
|
58
|
+
message: '是否进行自动升级?',
|
|
59
|
+
name: 'update',
|
|
60
|
+
choices: [
|
|
61
|
+
"Yes", 'No'
|
|
62
|
+
],
|
|
63
|
+
}];
|
|
64
|
+
return inquirer.prompt(prompt)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* 升级cli
|
|
69
|
+
*/
|
|
70
|
+
function update(onlineVersion) {
|
|
71
|
+
console.log()
|
|
72
|
+
console.log(chalk.green("升级中,预计3分钟完成,请稍后..."));
|
|
73
|
+
console.log()
|
|
74
|
+
let os = process.platform
|
|
75
|
+
console.log(chalk.yellow(`如无法自动更新,请使用命令更新:${'darwin' == os ? 'sudo' : ''} npm install -g cloudcc-cli@${onlineVersion} --registry http://registry.npmmirror.com`));
|
|
76
|
+
exec(`${'darwin' == os ? 'sudo' : ''} npm install -g cloudcc-cli@${onlineVersion} --registry http://registry.npmmirror.com`)
|
|
77
|
+
console.log()
|
|
78
|
+
console.log(chalk.green("升级完成!请重新运行"));
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* 检查更新
|
|
83
|
+
*/
|
|
84
|
+
async function checkUpdate() {
|
|
85
|
+
let onlineVersion;
|
|
86
|
+
try {
|
|
87
|
+
onlineVersion = checkNpmVersion();
|
|
88
|
+
} catch (error) {
|
|
89
|
+
console.log("error", error)
|
|
90
|
+
onlineVersion = false;
|
|
91
|
+
}
|
|
92
|
+
if (onlineVersion) {
|
|
93
|
+
let res = await askUpdate()
|
|
94
|
+
if ("Yes" == res.update) {
|
|
95
|
+
update(onlineVersion)
|
|
96
|
+
return true;
|
|
97
|
+
} else {
|
|
98
|
+
return false
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return false
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
module.exports = { checkUpdate }
|
package/utils/http.js
CHANGED
|
@@ -1,122 +1,122 @@
|
|
|
1
|
-
const https = require("https")
|
|
2
|
-
const http = require("http")
|
|
3
|
-
const axios = require("axios")
|
|
4
|
-
|
|
5
|
-
const httpsAgent = new https.Agent({
|
|
6
|
-
rejectUnauthorized: false,
|
|
7
|
-
})
|
|
8
|
-
const httpAgent = new http.Agent({
|
|
9
|
-
rejectUnauthorized: false,
|
|
10
|
-
})
|
|
11
|
-
axios.defaults.httpsAgent = httpsAgent
|
|
12
|
-
axios.defaults.httpAgent = httpAgent
|
|
13
|
-
|
|
14
|
-
const service = axios.create({
|
|
15
|
-
timeout: 60000, // request timeout
|
|
16
|
-
headers: {
|
|
17
|
-
'Content-Type': 'application/json; charset=utf-8',
|
|
18
|
-
},
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
// request interceptor
|
|
22
|
-
service.interceptors.request.use(
|
|
23
|
-
config => {
|
|
24
|
-
if (global.accessToken) {
|
|
25
|
-
config.headers.accessToken = global.accessToken
|
|
26
|
-
}
|
|
27
|
-
return config
|
|
28
|
-
},
|
|
29
|
-
error => {
|
|
30
|
-
// Do something with request error
|
|
31
|
-
Promise.reject(error)
|
|
32
|
-
}
|
|
33
|
-
)
|
|
34
|
-
|
|
35
|
-
// response interceptor
|
|
36
|
-
service.interceptors.response.use(
|
|
37
|
-
response => {
|
|
38
|
-
const code = response.data.code || 200
|
|
39
|
-
if (code !== 200) {
|
|
40
|
-
return Promise.reject(null == response.data.msg ? "未知异常" : response.data.msg)
|
|
41
|
-
} else {
|
|
42
|
-
return response.data;
|
|
43
|
-
}
|
|
44
|
-
},
|
|
45
|
-
error => {
|
|
46
|
-
return Promise.reject(error)
|
|
47
|
-
}
|
|
48
|
-
)
|
|
49
|
-
const formateData = (data, header) => {
|
|
50
|
-
if (header) {
|
|
51
|
-
Object.assign(header, { source: "cloudcc_cli" })
|
|
52
|
-
}
|
|
53
|
-
return {
|
|
54
|
-
head: {
|
|
55
|
-
...header
|
|
56
|
-
},
|
|
57
|
-
body: {
|
|
58
|
-
...data
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
module.exports = {
|
|
63
|
-
get: (url, data = {}, responseType = '') => {
|
|
64
|
-
return service({
|
|
65
|
-
url: url,
|
|
66
|
-
method: 'get',
|
|
67
|
-
params: formateData(data),
|
|
68
|
-
responseType: responseType
|
|
69
|
-
})
|
|
70
|
-
},
|
|
71
|
-
getParams: (url, data = {}) => {
|
|
72
|
-
return service({
|
|
73
|
-
url: url,
|
|
74
|
-
method: 'get',
|
|
75
|
-
params: data,
|
|
76
|
-
})
|
|
77
|
-
},
|
|
78
|
-
post: (url, data = {}, header = { appVersion: "1.0.0" }, responseType = '') => {
|
|
79
|
-
return service({
|
|
80
|
-
url: url,
|
|
81
|
-
method: 'post',
|
|
82
|
-
data: formateData(data, header),
|
|
83
|
-
responseType: responseType
|
|
84
|
-
})
|
|
85
|
-
},
|
|
86
|
-
postParams: (url, data = {}) => {
|
|
87
|
-
return service({
|
|
88
|
-
url: url,
|
|
89
|
-
method: 'post',
|
|
90
|
-
params: data,
|
|
91
|
-
})
|
|
92
|
-
},
|
|
93
|
-
postNormal: (url, data = {}) => {
|
|
94
|
-
return service({
|
|
95
|
-
url: url,
|
|
96
|
-
method: 'post',
|
|
97
|
-
data: data
|
|
98
|
-
})
|
|
99
|
-
},
|
|
100
|
-
patch: (url, data = {}) => {
|
|
101
|
-
return service({
|
|
102
|
-
url: url,
|
|
103
|
-
method: 'patch',
|
|
104
|
-
data: formateData(data)
|
|
105
|
-
})
|
|
106
|
-
},
|
|
107
|
-
delete: (url, data = {}) => {
|
|
108
|
-
return service({
|
|
109
|
-
url: url,
|
|
110
|
-
method: 'delete',
|
|
111
|
-
data: formateData(data)
|
|
112
|
-
})
|
|
113
|
-
},
|
|
114
|
-
put: (url, data = {}) => {
|
|
115
|
-
return service({
|
|
116
|
-
url: url,
|
|
117
|
-
method: 'put',
|
|
118
|
-
data: formateData(data)
|
|
119
|
-
})
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
}
|
|
1
|
+
const https = require("https")
|
|
2
|
+
const http = require("http")
|
|
3
|
+
const axios = require("axios")
|
|
4
|
+
|
|
5
|
+
const httpsAgent = new https.Agent({
|
|
6
|
+
rejectUnauthorized: false,
|
|
7
|
+
})
|
|
8
|
+
const httpAgent = new http.Agent({
|
|
9
|
+
rejectUnauthorized: false,
|
|
10
|
+
})
|
|
11
|
+
axios.defaults.httpsAgent = httpsAgent
|
|
12
|
+
axios.defaults.httpAgent = httpAgent
|
|
13
|
+
|
|
14
|
+
const service = axios.create({
|
|
15
|
+
timeout: 60000, // request timeout
|
|
16
|
+
headers: {
|
|
17
|
+
'Content-Type': 'application/json; charset=utf-8',
|
|
18
|
+
},
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
// request interceptor
|
|
22
|
+
service.interceptors.request.use(
|
|
23
|
+
config => {
|
|
24
|
+
if (global.accessToken) {
|
|
25
|
+
config.headers.accessToken = global.accessToken
|
|
26
|
+
}
|
|
27
|
+
return config
|
|
28
|
+
},
|
|
29
|
+
error => {
|
|
30
|
+
// Do something with request error
|
|
31
|
+
Promise.reject(error)
|
|
32
|
+
}
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
// response interceptor
|
|
36
|
+
service.interceptors.response.use(
|
|
37
|
+
response => {
|
|
38
|
+
const code = response.data.code || 200
|
|
39
|
+
if (code !== 200) {
|
|
40
|
+
return Promise.reject(null == response.data.msg ? "未知异常" : response.data.msg)
|
|
41
|
+
} else {
|
|
42
|
+
return response.data;
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
error => {
|
|
46
|
+
return Promise.reject(error)
|
|
47
|
+
}
|
|
48
|
+
)
|
|
49
|
+
const formateData = (data, header) => {
|
|
50
|
+
if (header) {
|
|
51
|
+
Object.assign(header, { source: "cloudcc_cli" })
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
head: {
|
|
55
|
+
...header
|
|
56
|
+
},
|
|
57
|
+
body: {
|
|
58
|
+
...data
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
module.exports = {
|
|
63
|
+
get: (url, data = {}, responseType = '') => {
|
|
64
|
+
return service({
|
|
65
|
+
url: url,
|
|
66
|
+
method: 'get',
|
|
67
|
+
params: formateData(data),
|
|
68
|
+
responseType: responseType
|
|
69
|
+
})
|
|
70
|
+
},
|
|
71
|
+
getParams: (url, data = {}) => {
|
|
72
|
+
return service({
|
|
73
|
+
url: url,
|
|
74
|
+
method: 'get',
|
|
75
|
+
params: data,
|
|
76
|
+
})
|
|
77
|
+
},
|
|
78
|
+
post: (url, data = {}, header = { appVersion: "1.0.0" }, responseType = '') => {
|
|
79
|
+
return service({
|
|
80
|
+
url: url,
|
|
81
|
+
method: 'post',
|
|
82
|
+
data: formateData(data, header),
|
|
83
|
+
responseType: responseType
|
|
84
|
+
})
|
|
85
|
+
},
|
|
86
|
+
postParams: (url, data = {}) => {
|
|
87
|
+
return service({
|
|
88
|
+
url: url,
|
|
89
|
+
method: 'post',
|
|
90
|
+
params: data,
|
|
91
|
+
})
|
|
92
|
+
},
|
|
93
|
+
postNormal: (url, data = {}) => {
|
|
94
|
+
return service({
|
|
95
|
+
url: url,
|
|
96
|
+
method: 'post',
|
|
97
|
+
data: data
|
|
98
|
+
})
|
|
99
|
+
},
|
|
100
|
+
patch: (url, data = {}) => {
|
|
101
|
+
return service({
|
|
102
|
+
url: url,
|
|
103
|
+
method: 'patch',
|
|
104
|
+
data: formateData(data)
|
|
105
|
+
})
|
|
106
|
+
},
|
|
107
|
+
delete: (url, data = {}) => {
|
|
108
|
+
return service({
|
|
109
|
+
url: url,
|
|
110
|
+
method: 'delete',
|
|
111
|
+
data: formateData(data)
|
|
112
|
+
})
|
|
113
|
+
},
|
|
114
|
+
put: (url, data = {}) => {
|
|
115
|
+
return service({
|
|
116
|
+
url: url,
|
|
117
|
+
method: 'put',
|
|
118
|
+
data: formateData(data)
|
|
119
|
+
})
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
}
|