update 优化 OSS 模块与上传组件 异常处理
This commit is contained in:
parent
a33a919169
commit
c91d33e4ab
|
@ -11,6 +11,7 @@ import com.ruoyi.oss.enumd.CloudServiceEnumd;
|
||||||
import com.ruoyi.oss.exception.OssException;
|
import com.ruoyi.oss.exception.OssException;
|
||||||
import com.ruoyi.oss.properties.CloudStorageProperties;
|
import com.ruoyi.oss.properties.CloudStorageProperties;
|
||||||
import com.ruoyi.oss.service.ICloudStorageStrategy;
|
import com.ruoyi.oss.service.ICloudStorageStrategy;
|
||||||
|
import com.ruoyi.oss.service.abstractd.AbstractCloudStorageStrategy;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -68,7 +69,8 @@ public class OssFactory {
|
||||||
return service;
|
return service;
|
||||||
}
|
}
|
||||||
// 获取redis配置信息 创建对象 并缓存
|
// 获取redis配置信息 创建对象 并缓存
|
||||||
service = (ICloudStorageStrategy) ReflectUtils.newInstance(CloudServiceEnumd.getServiceClass(type), properties);
|
service = (ICloudStorageStrategy) ReflectUtils.newInstance(CloudServiceEnumd.getServiceClass(type));
|
||||||
|
((AbstractCloudStorageStrategy)service).init(properties);
|
||||||
SERVICES.put(type, service);
|
SERVICES.put(type, service);
|
||||||
SERVICES_UPDATE_TIME.put(type, nowDate);
|
SERVICES_UPDATE_TIME.put(type, nowDate);
|
||||||
return service;
|
return service;
|
||||||
|
|
|
@ -20,6 +20,8 @@ public abstract class AbstractCloudStorageStrategy implements ICloudStorageStrat
|
||||||
|
|
||||||
protected CloudStorageProperties properties;
|
protected CloudStorageProperties properties;
|
||||||
|
|
||||||
|
public abstract void init(CloudStorageProperties properties);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public abstract void createBucket();
|
public abstract void createBucket();
|
||||||
|
|
||||||
|
|
|
@ -24,9 +24,10 @@ import java.io.InputStream;
|
||||||
*/
|
*/
|
||||||
public class AliyunCloudStorageStrategy extends AbstractCloudStorageStrategy {
|
public class AliyunCloudStorageStrategy extends AbstractCloudStorageStrategy {
|
||||||
|
|
||||||
private final OSSClient client;
|
private OSSClient client;
|
||||||
|
|
||||||
public AliyunCloudStorageStrategy(CloudStorageProperties cloudStorageProperties) {
|
@Override
|
||||||
|
public void init(CloudStorageProperties cloudStorageProperties) {
|
||||||
properties = cloudStorageProperties;
|
properties = cloudStorageProperties;
|
||||||
try {
|
try {
|
||||||
ClientConfiguration configuration = new ClientConfiguration();
|
ClientConfiguration configuration = new ClientConfiguration();
|
||||||
|
@ -35,7 +36,7 @@ public class AliyunCloudStorageStrategy extends AbstractCloudStorageStrategy {
|
||||||
client = new OSSClient(properties.getEndpoint(), credentialProvider, configuration);
|
client = new OSSClient(properties.getEndpoint(), credentialProvider, configuration);
|
||||||
createBucket();
|
createBucket();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new IllegalArgumentException("阿里云存储配置错误! 请检查系统配置!");
|
throw new OssException("阿里云存储配置错误! 请检查系统配置!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,9 +20,10 @@ import java.io.InputStream;
|
||||||
*/
|
*/
|
||||||
public class MinioCloudStorageStrategy extends AbstractCloudStorageStrategy {
|
public class MinioCloudStorageStrategy extends AbstractCloudStorageStrategy {
|
||||||
|
|
||||||
private final MinioClient minioClient;
|
private MinioClient minioClient;
|
||||||
|
|
||||||
public MinioCloudStorageStrategy(CloudStorageProperties cloudStorageProperties) {
|
@Override
|
||||||
|
public void init(CloudStorageProperties cloudStorageProperties) {
|
||||||
properties = cloudStorageProperties;
|
properties = cloudStorageProperties;
|
||||||
try {
|
try {
|
||||||
minioClient = MinioClient.builder()
|
minioClient = MinioClient.builder()
|
||||||
|
@ -31,7 +32,7 @@ public class MinioCloudStorageStrategy extends AbstractCloudStorageStrategy {
|
||||||
.build();
|
.build();
|
||||||
createBucket();
|
createBucket();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new IllegalArgumentException("Minio存储配置错误! 请检查系统配置!");
|
throw new OssException("Minio存储配置错误! 请检查系统配置!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,9 +24,10 @@ import java.io.InputStream;
|
||||||
*/
|
*/
|
||||||
public class QcloudCloudStorageStrategy extends AbstractCloudStorageStrategy {
|
public class QcloudCloudStorageStrategy extends AbstractCloudStorageStrategy {
|
||||||
|
|
||||||
private final COSClient client;
|
private COSClient client;
|
||||||
|
|
||||||
public QcloudCloudStorageStrategy(CloudStorageProperties cloudStorageProperties) {
|
@Override
|
||||||
|
public void init(CloudStorageProperties cloudStorageProperties) {
|
||||||
properties = cloudStorageProperties;
|
properties = cloudStorageProperties;
|
||||||
try {
|
try {
|
||||||
COSCredentials credentials = new BasicCOSCredentials(
|
COSCredentials credentials = new BasicCOSCredentials(
|
||||||
|
@ -43,7 +44,7 @@ public class QcloudCloudStorageStrategy extends AbstractCloudStorageStrategy {
|
||||||
client = new COSClient(credentials, clientConfig);
|
client = new COSClient(credentials, clientConfig);
|
||||||
createBucket();
|
createBucket();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new IllegalArgumentException("腾讯云存储配置错误! 请检查系统配置!");
|
throw new OssException("腾讯云存储配置错误! 请检查系统配置!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,11 +22,12 @@ import java.io.InputStream;
|
||||||
*/
|
*/
|
||||||
public class QiniuCloudStorageStrategy extends AbstractCloudStorageStrategy {
|
public class QiniuCloudStorageStrategy extends AbstractCloudStorageStrategy {
|
||||||
|
|
||||||
private final UploadManager uploadManager;
|
private UploadManager uploadManager;
|
||||||
private final BucketManager bucketManager;
|
private BucketManager bucketManager;
|
||||||
private final String token;
|
private String token;
|
||||||
|
|
||||||
public QiniuCloudStorageStrategy(CloudStorageProperties cloudStorageProperties) {
|
@Override
|
||||||
|
public void init(CloudStorageProperties cloudStorageProperties) {
|
||||||
properties = cloudStorageProperties;
|
properties = cloudStorageProperties;
|
||||||
try {
|
try {
|
||||||
Configuration config = new Configuration(getRegion(properties.getRegion()));
|
Configuration config = new Configuration(getRegion(properties.getRegion()));
|
||||||
|
@ -43,7 +44,7 @@ public class QiniuCloudStorageStrategy extends AbstractCloudStorageStrategy {
|
||||||
bucketManager.createBucket(bucketName, properties.getRegion());
|
bucketManager.createBucket(bucketName, properties.getRegion());
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new IllegalArgumentException("七牛云存储配置错误! 请检查系统配置!");
|
throw new OssException("七牛云存储配置错误! 请检查系统配置!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -180,7 +180,7 @@ export default {
|
||||||
// 调整光标到最后
|
// 调整光标到最后
|
||||||
quill.setSelection(length + 1);
|
quill.setSelection(length + 1);
|
||||||
} else {
|
} else {
|
||||||
this.$message.error("图片插入失败");
|
this.$message.error(res.msg);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
handleUploadError() {
|
handleUploadError() {
|
||||||
|
|
|
@ -146,9 +146,14 @@ export default {
|
||||||
},
|
},
|
||||||
// 上传成功回调
|
// 上传成功回调
|
||||||
handleUploadSuccess(res, file) {
|
handleUploadSuccess(res, file) {
|
||||||
this.$message.success("上传成功");
|
if (res.code === 200) {
|
||||||
this.fileList.push({ name: res.data.fileName, url: res.data.fileName });
|
this.$message.success("上传成功");
|
||||||
this.$emit("input", this.listToString(this.fileList));
|
this.fileList.push({ name: res.data.fileName, url: res.data.fileName });
|
||||||
|
this.$emit("input", this.listToString(this.fileList));
|
||||||
|
} else {
|
||||||
|
this.$message.error(res.msg);
|
||||||
|
this.loading.close();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
// 删除文件
|
// 删除文件
|
||||||
handleDelete(index) {
|
handleDelete(index) {
|
||||||
|
@ -170,9 +175,9 @@ export default {
|
||||||
for (let i in list) {
|
for (let i in list) {
|
||||||
strs += list[i].url + separator;
|
strs += list[i].url + separator;
|
||||||
}
|
}
|
||||||
return strs != '' ? strs.substr(0, strs.length - 1) : '';
|
return strs != "" ? strs.substr(0, strs.length - 1) : "";
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
@ -118,9 +118,14 @@ export default {
|
||||||
},
|
},
|
||||||
// 上传成功回调
|
// 上传成功回调
|
||||||
handleUploadSuccess(res) {
|
handleUploadSuccess(res) {
|
||||||
this.fileList.push({ name: res.data.fileName, url: res.data.url });
|
if (res.code == 200) {
|
||||||
this.$emit("input", this.listToString(this.fileList));
|
this.fileList.push({ name: res.data.fileName, url: res.data.url });
|
||||||
this.loading.close();
|
this.$emit("input", this.listToString(this.fileList));
|
||||||
|
this.loading.close();
|
||||||
|
} else {
|
||||||
|
this.$message.error(res.msg);
|
||||||
|
this.loading.close();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
// 上传前loading加载
|
// 上传前loading加载
|
||||||
handleBeforeUpload(file) {
|
handleBeforeUpload(file) {
|
||||||
|
@ -130,7 +135,7 @@ export default {
|
||||||
if (file.name.lastIndexOf(".") > -1) {
|
if (file.name.lastIndexOf(".") > -1) {
|
||||||
fileExtension = file.name.slice(file.name.lastIndexOf(".") + 1);
|
fileExtension = file.name.slice(file.name.lastIndexOf(".") + 1);
|
||||||
}
|
}
|
||||||
isImg = this.fileType.some(type => {
|
isImg = this.fileType.some((type) => {
|
||||||
if (file.type.indexOf(type) > -1) return true;
|
if (file.type.indexOf(type) > -1) return true;
|
||||||
if (fileExtension && fileExtension.indexOf(type) > -1) return true;
|
if (fileExtension && fileExtension.indexOf(type) > -1) return true;
|
||||||
return false;
|
return false;
|
||||||
|
@ -163,7 +168,7 @@ export default {
|
||||||
this.$message.error(`上传文件数量不能超过 ${this.limit} 个!`);
|
this.$message.error(`上传文件数量不能超过 ${this.limit} 个!`);
|
||||||
},
|
},
|
||||||
// 上传失败
|
// 上传失败
|
||||||
handleUploadError() {
|
handleUploadError(res) {
|
||||||
this.$message({
|
this.$message({
|
||||||
type: "error",
|
type: "error",
|
||||||
message: "上传失败",
|
message: "上传失败",
|
||||||
|
@ -182,25 +187,26 @@ export default {
|
||||||
for (let i in list) {
|
for (let i in list) {
|
||||||
strs += list[i].url + separator;
|
strs += list[i].url + separator;
|
||||||
}
|
}
|
||||||
return strs != '' ? strs.substr(0, strs.length - 1) : '';
|
return strs != "" ? strs.substr(0, strs.length - 1) : "";
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
<style scoped lang="scss">
|
<style scoped lang="scss">
|
||||||
// .el-upload--picture-card 控制加号部分
|
// .el-upload--picture-card 控制加号部分
|
||||||
::v-deep.hide .el-upload--picture-card {
|
::v-deep.hide .el-upload--picture-card {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
// 去掉动画效果
|
// 去掉动画效果
|
||||||
::v-deep .el-list-enter-active,
|
::v-deep .el-list-enter-active,
|
||||||
::v-deep .el-list-leave-active {
|
::v-deep .el-list-leave-active {
|
||||||
transition: all 0s;
|
transition: all 0s;
|
||||||
}
|
}
|
||||||
|
|
||||||
::v-deep .el-list-enter, .el-list-leave-active {
|
::v-deep .el-list-enter,
|
||||||
opacity: 0;
|
.el-list-leave-active {
|
||||||
transform: translateY(0);
|
opacity: 0;
|
||||||
|
transform: translateY(0);
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
|
|
@ -138,7 +138,7 @@
|
||||||
<el-input v-model="form.accessKey" placeholder="请输入accessKey" />
|
<el-input v-model="form.accessKey" placeholder="请输入accessKey" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="secretKey" prop="secretKey">
|
<el-form-item label="secretKey" prop="secretKey">
|
||||||
<el-input v-model="form.secretKey" placeholder="请输入秘钥" />
|
<el-input v-model="form.secretKey" placeholder="请输入秘钥" show-password />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="桶名称" prop="bucketName">
|
<el-form-item label="桶名称" prop="bucketName">
|
||||||
<el-input v-model="form.bucketName" placeholder="请输入桶名称" />
|
<el-input v-model="form.bucketName" placeholder="请输入桶名称" />
|
||||||
|
|
Loading…
Reference in New Issue