diff --git a/web/dashboard/.env.development b/web/dashboard/.env.development index f324ce5..04f19f9 100644 --- a/web/dashboard/.env.development +++ b/web/dashboard/.env.development @@ -4,8 +4,19 @@ VUE_APP_HTTP_TIMEOUT = 15000 VUE_APP_HTTP_API = "http://localhost:8088/manager" VUE_APP_TITLE = "APP 管理平台 - 开发" +#上传到云的开关 +VUE_APP_CLOUD_STORAGE_TYPE_ENABLE = "1" + # OSS 配置 +VUE_APP_OSS_CLOUD_STORAGE_TYPE = "1" VUE_APP_OSS_REGION = "" VUE_APP_OSS_KEYID = "" VUE_APP_OSS_KEYSECRET = "" -VUE_APP_OSS_BUCKET = "" \ No newline at end of file +VUE_APP_OSS_BUCKET = "" + +# COS 配置 +VUE_APP_COS_CLOUD_STORAGE_TYPE = "2" +VUE_APP_COS_REGION = "" +VUE_APP_COS_KEYID = "" +VUE_APP_COS_KEYSECRET = "" +VUE_APP_COS_BUCKET = "" \ No newline at end of file diff --git a/web/dashboard/.env.production b/web/dashboard/.env.production index 24b4e56..7c056c9 100644 --- a/web/dashboard/.env.production +++ b/web/dashboard/.env.production @@ -4,8 +4,19 @@ VUE_APP_HTTP_TIMEOUT = 15000 VUE_APP_HTTP_API = "http://localhost:8088/manager" VUE_APP_TITLE = "APP 管理平台 - 开发" +#上传到云的开关 +VUE_APP_CLOUD_STORAGE_TYPE_ENABLE = "1" + # OSS 配置 +VUE_APP_OSS_CLOUD_STORAGE_TYPE = "1" VUE_APP_OSS_REGION = "" VUE_APP_OSS_KEYID = "" VUE_APP_OSS_KEYSECRET = "" -VUE_APP_OSS_BUCKET = "" \ No newline at end of file +VUE_APP_OSS_BUCKET = "" + +# COS 配置 +VUE_APP_COS_CLOUD_STORAGE_TYPE = "2" +VUE_APP_COS_REGION = "" +VUE_APP_COS_KEYID = "" +VUE_APP_COS_KEYSECRET = "" +VUE_APP_COS_BUCKET = "" \ No newline at end of file diff --git a/web/dashboard/.env.test b/web/dashboard/.env.test index 6c52ad2..9221d62 100644 --- a/web/dashboard/.env.test +++ b/web/dashboard/.env.test @@ -4,8 +4,19 @@ VUE_APP_HTTP_TIMEOUT = 15000 VUE_APP_HTTP_API = "http://localhost:8088/manager" VUE_APP_TITLE = "APP 管理平台 - 开发" +#上传到云的开关 +VUE_APP_CLOUD_STORAGE_TYPE_ENABLE = "1" + # OSS 配置 +VUE_APP_OSS_CLOUD_STORAGE_TYPE = "1" VUE_APP_OSS_REGION = "" VUE_APP_OSS_KEYID = "" VUE_APP_OSS_KEYSECRET = "" -VUE_APP_OSS_BUCKET = "" \ No newline at end of file +VUE_APP_OSS_BUCKET = "" + +# COS 配置 +VUE_APP_COS_CLOUD_STORAGE_TYPE = "2" +VUE_APP_COS_REGION = "" +VUE_APP_COS_KEYID = "" +VUE_APP_COS_KEYSECRET = "" +VUE_APP_COS_BUCKET = "" \ No newline at end of file diff --git a/web/dashboard/.env.uat b/web/dashboard/.env.uat index 0ffac08..b261641 100644 --- a/web/dashboard/.env.uat +++ b/web/dashboard/.env.uat @@ -4,8 +4,19 @@ VUE_APP_HTTP_TIMEOUT = 15000 VUE_APP_HTTP_API = "http://localhost:8088/manager" VUE_APP_TITLE = "APP 管理平台 - 开发" +#上传到云的开关 +VUE_APP_CLOUD_STORAGE_TYPE_ENABLE = "1" + # OSS 配置 +VUE_APP_OSS_CLOUD_STORAGE_TYPE = "1" VUE_APP_OSS_REGION = "" VUE_APP_OSS_KEYID = "" VUE_APP_OSS_KEYSECRET = "" -VUE_APP_OSS_BUCKET = "" \ No newline at end of file +VUE_APP_OSS_BUCKET = "" + +# COS 配置 +VUE_APP_COS_CLOUD_STORAGE_TYPE = "2" +VUE_APP_COS_REGION = "" +VUE_APP_COS_KEYID = "" +VUE_APP_COS_KEYSECRET = "" +VUE_APP_COS_BUCKET = "" \ No newline at end of file diff --git a/web/dashboard/package.json b/web/dashboard/package.json index c1a69c3..9e04b6a 100644 --- a/web/dashboard/package.json +++ b/web/dashboard/package.json @@ -17,6 +17,7 @@ "axios": "^0.18.0", "co": "^4.6.0", "codemirror": "^5.39.0", + "cos-js-sdk-v5": "^0.5.27", "filesize": "^3.6.1", "iview": "^3.2.2", "js-beautify": "^1.7.5", diff --git a/web/dashboard/src/libs/cloud.js b/web/dashboard/src/libs/cloud.js new file mode 100644 index 0000000..0c4e6f3 --- /dev/null +++ b/web/dashboard/src/libs/cloud.js @@ -0,0 +1,15 @@ +import uploadFileToOSS from '@/libs/oss'; +import uploadFileToCOS from '@/libs/cos'; + +const uploadFileToCloud = (file, fileName = '', callBack, progressCB = null) => { + switch (process.env.VUE_APP_CLOUD_STORAGE_TYPE_ENABLE) { + case process.env.VUE_APP_OSS_CLOUD_STORAGE_TYPE: + uploadFileToOSS(file, fileName, callBack, progressCB); + break; + case process.env.VUE_APP_COS_CLOUD_STORAGE_TYPE: + uploadFileToCOS(file, fileName, callBack, progressCB); + break; + } +}; + +export default uploadFileToCloud; diff --git a/web/dashboard/src/libs/cos.js b/web/dashboard/src/libs/cos.js new file mode 100644 index 0000000..6ccf082 --- /dev/null +++ b/web/dashboard/src/libs/cos.js @@ -0,0 +1,37 @@ +import COS from 'cos-js-sdk-v5'; + +const client = new COS({ + SecretId: process.env.VUE_APP_COS_KEYID, + SecretKey: process.env.VUE_APP_COS_KEYSECRET +}); + +const uploadFileToCOS = (file, fileName = '', callBack, progressCB = null) => { + client.putObject({ + Bucket: process.env.VUE_APP_COS_BUCKET, + /* 必须 */ + Region: process.env.VUE_APP_COS_REGION, + /* 存储桶所在地域,必须字段 */ + Key: fileName, + /* 必须 */ + StorageClass: 'STANDARD', + Body: file, // 上传文件对象 + onProgress: function (progressData) { + console.log('progress data:', progressData); + if (progressCB !== null) { + progressCB(progressData.percent * 100); + } + // console.log(JSON.stringify(progressData)); + } + }, function (err, data) { + console.log('err && data', err, data); + if (data && !err) { + callBack({ + fileCloudUrl: data.Location + }); + } + + console.log(err || data); + }); +}; + +export default uploadFileToCOS; diff --git a/web/dashboard/src/libs/oss.js b/web/dashboard/src/libs/oss.js index 9b4d058..6a79adc 100644 --- a/web/dashboard/src/libs/oss.js +++ b/web/dashboard/src/libs/oss.js @@ -18,7 +18,9 @@ const uploadFileToOSS = (file, fileName = '', callBack, progressCB = null) => { }); // 上传完成 let response = yield client.head(name); - callBack(response); + callBack({ + fileCloudUrl: response.res.requestUrls[0] + }); }).catch(() => { }); }; diff --git a/web/dashboard/src/views/rn/editPackage.vue b/web/dashboard/src/views/rn/editPackage.vue index b69a008..e9c6e7e 100644 --- a/web/dashboard/src/views/rn/editPackage.vue +++ b/web/dashboard/src/views/rn/editPackage.vue @@ -97,7 +97,7 @@