!134 图片组件增加svg格式识别+仪表盘增加最大值设置

Merge pull request !134 from 陈旭光/dev
Foming 1 year ago committed by Gitee
commit b29f11115b
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F

@ -12,6 +12,7 @@ import com.anjiplus.template.gaea.business.code.ResponseCode;
import com.anjiplus.template.gaea.business.modules.file.dao.GaeaFileMapper;
import com.anjiplus.template.gaea.business.modules.file.entity.GaeaFile;
import com.anjiplus.template.gaea.business.modules.file.service.GaeaFileService;
import com.anjiplus.template.gaea.business.util.ResponseUtil2;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.extern.slf4j.Slf4j;
@ -159,7 +160,7 @@ public class GaeaFileServiceImpl implements GaeaFileService {
byte[] fileBytes = gaeaOSSTemplate.downloadFile(fileObjectName);
// 根据文件后缀来判断,是显示图片\视频\音频,还是下载文件
return ResponseUtil.writeBody(originalFilename, fileBytes, isIEBrowser);
return ResponseUtil2.writeBody(originalFilename, fileBytes, isIEBrowser);
} catch (Exception e) {
log.error("file download error", e);
throw BusinessExceptionBuilder.build(ResponseCode.FILE_OPERATION_FAILED, e.getMessage());

@ -0,0 +1,60 @@
package com.anjiplus.template.gaea.business.util;
import com.anji.plus.gaea.oss.exceptions.GaeaOSSException;
import com.anji.plus.gaea.oss.utils.ResponseUtil;
import com.anji.plus.gaea.oss.utils.StringPatternUtil;
import org.springframework.http.CacheControl;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.util.StringUtils;
import java.net.URLEncoder;
public class ResponseUtil2 extends ResponseUtil {
/**
* \\
* @param fileObjectName .xls banner.png
* @param fileBytes
* @param isIEBrowser IE
* @return
*/
public static ResponseEntity<byte[]> writeBody(String fileObjectName, byte[] fileBytes, boolean isIEBrowser){
try{
if(StringUtils.isEmpty(fileObjectName) || !fileObjectName.contains(".")){
throw new GaeaOSSException("original file name or type is empty");
}
// 文件后缀名
String fileSuffixName = fileObjectName.substring(fileObjectName.lastIndexOf("."));
// 初始化响应体
ResponseEntity.BodyBuilder builder = ResponseEntity.ok();
builder.contentLength(fileBytes.length);
// 判断文件是图片视频还是文件
String pattern1 = "(.png|.jpg|.jpeg|.bmp|.gif|.icon|.svg)";
String pattern2 = "(.flv|.swf|.mkv|.avi|.rm|.rmvb|.mpeg|.mpg|.ogg|.ogv|.mov|.wmv|.mp4|.webm|.wav|.mid|.mp3|.aac)";
if (StringPatternUtil.StringMatchIgnoreCase(fileSuffixName, pattern1)) {
if (fileSuffixName.equalsIgnoreCase(".svg")) {
builder.cacheControl(CacheControl.noCache()).contentType(MediaType.parseMediaType("image/svg+xml"));
} else {
builder.cacheControl(CacheControl.noCache()).contentType(MediaType.IMAGE_PNG);
}
} else if (StringPatternUtil.StringMatchIgnoreCase(fileSuffixName, pattern2)) {
builder.header("Content-Type", "video/mp4; charset=UTF-8");
} else {
//application/octet-stream 二进制数据流(最常见的文件下载)
builder.contentType(MediaType.APPLICATION_OCTET_STREAM);
fileObjectName = URLEncoder.encode(fileObjectName, "UTF-8");
if (isIEBrowser) {
builder.header("Content-Disposition", "attachment; filename=" + fileObjectName);
} else {
builder.header("Content-Disposition", "attacher; filename*=UTF-8''" + fileObjectName);
}
}
return builder.body(fileBytes);
}catch (Exception e){
e.printStackTrace();
return null;
}
}
}

@ -31,6 +31,14 @@ export const widgetGauge = {
placeholder: '',
value: ''
},
{
type: 'el-input-number',
label: '最大值',
name: 'maxValue',
require: false,
placeholder: '',
value: 100,
},
[
{
name: "圆环设置",

@ -111,7 +111,11 @@ export default {
},
detail: {
valueAnimation: true,
formatter: "{value} %",
formatter: function(value) {
const max = series[0].max; //
const formattedValue = (value / max * 100).toFixed(0); //
return formattedValue + ' %'; //
},
color: "white",
fontSize: 18,
},
@ -263,7 +267,11 @@ export default {
};
const detail = {
valueAnimation: true,
formatter: "{value} %",
formatter: function(value) {
const max = series[0].max; //
const formattedValue = (value / max * 100).toFixed(0); //
return formattedValue + ' %'; //
},
color: optionsSetup.detailColor,
fontSize: optionsSetup.detailFontSize,
fontWeight: optionsSetup.detailFontWeight,
@ -274,6 +282,7 @@ export default {
series[0].splitLine = splitLine;
series[0].axisLabel = axisLabel;
series[0].detail = detail;
series[0].max = optionsSetup.maxValue;
}
},
setOptionsData(e, paramsConfig) {

Loading…
Cancel
Save