mirror of
https://gitee.com/anji-plus/report.git
synced 2026-02-02 09:27:47 +08:00
图片组件增加svg格式识别+仪表盘增加最大值设置
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user