From c0aa455761cf317d75508348194fbbd0ef823bf3 Mon Sep 17 00:00:00 2001 From: Raod <1130305001@qq.com> Date: Thu, 23 Sep 2021 10:18:22 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E7=BC=96=E7=A0=81=E8=BE=93=E5=85=A5?= =?UTF-8?q?=E9=99=90=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- report-ui/src/utils/validate.js | 14 ++++++++++++++ .../datasource/components/EditDataSource.vue | 2 ++ report-ui/src/views/report/report/index.vue | 4 +++- .../report/resultset/components/EditDataSet.vue | 4 +++- 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/report-ui/src/utils/validate.js b/report-ui/src/utils/validate.js index e1103104..aa056196 100644 --- a/report-ui/src/utils/validate.js +++ b/report-ui/src/utils/validate.js @@ -30,3 +30,17 @@ export function validatAlphabets(str) { const reg = /^[A-Za-z]+$/ return reg.test(str) } + +/*验证内容是否英文数字以及下划线*/ +export function validateEngOrNum(rule, value, callback) { + const reg =/^[_a-zA-Z0-9]+$/; + if(value==''||value==undefined||value==null){ + callback(); + } else { + if (!reg.test(value)){ + callback(new Error('英文字母、数字或下划线')); + } else { + callback(); + } + } +} diff --git a/report-ui/src/views/report/datasource/components/EditDataSource.vue b/report-ui/src/views/report/datasource/components/EditDataSource.vue index 7a307f16..0267f240 100644 --- a/report-ui/src/views/report/datasource/components/EditDataSource.vue +++ b/report-ui/src/views/report/datasource/components/EditDataSource.vue @@ -44,6 +44,7 @@ import { testConnection, reportDataSourceDetail, reportDataSourceAdd, reportDataSourceUpdate } from '@/api/reportDataSource' import { getDictList } from '@/api/dict-data' // 获取数据字典 import Dictionary from '@/components/Dictionary/index' +import {validateEngOrNum} from "@/utils/validate"; export default { name: 'Support', components: { Dictionary }, @@ -97,6 +98,7 @@ export default { ], sourceCode: [ { required: true, message: '数据集编码必填', trigger: 'blur' }, + { validator: validateEngOrNum, trigger: 'blur' }, ], sourceName: [ { required: true, message: '数据源名称必选', trigger: 'blur' }, diff --git a/report-ui/src/views/report/report/index.vue b/report-ui/src/views/report/report/index.vue index b5636902..4c27c037 100644 --- a/report-ui/src/views/report/report/index.vue +++ b/report-ui/src/views/report/report/index.vue @@ -46,6 +46,7 @@ import { reportDetail } from "@/api/reportmanage"; import Share from "@/views/report/report/components/share"; +import {validateEngOrNum} from "@/utils/validate"; export default { name: "Report", components: { @@ -131,7 +132,8 @@ export default { editField: "reportCode", inputType: "input", rules: [ - { min: 1, max: 100, message: "不超过100个字符", trigger: "blur" } + { min: 1, max: 100, message: "不超过100个字符", trigger: "blur" }, + { validator: validateEngOrNum, trigger: 'blur' }, ], disabled: "disableOnEdit" }, diff --git a/report-ui/src/views/report/resultset/components/EditDataSet.vue b/report-ui/src/views/report/resultset/components/EditDataSet.vue index 5aaf1099..17520511 100644 --- a/report-ui/src/views/report/resultset/components/EditDataSet.vue +++ b/report-ui/src/views/report/resultset/components/EditDataSet.vue @@ -383,6 +383,7 @@ import "codemirror/lib/codemirror.css"; // 核心样式 import "codemirror/theme/cobalt.css"; // 引入主题后还需要在 options 中指定主题才会生效 import vueJsonEditor from "vue-json-editor"; import MonacoEditor from "./MonacoEditor.vue"; +import {validateEngOrNum} from "@/utils/validate"; export default { name: "Support", components: { Dictionary, codemirror, vueJsonEditor, MonacoEditor }, @@ -469,7 +470,8 @@ export default { { required: true, message: "数据集名称必填", trigger: "blur" } ], setCode: [ - { required: true, message: "数据集编码必填", trigger: "blur" } + { required: true, message: "数据集编码必填", trigger: "blur" }, + { validator: validateEngOrNum, trigger: 'blur' }, ], sourceCode: [ { required: true, message: "数据源必选", trigger: "change" } From 7259593066809bedf29fe2c174c50310ef10c64a Mon Sep 17 00:00:00 2001 From: Raod <1130305001@qq.com> Date: Thu, 23 Sep 2021 14:50:50 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E5=88=86=E4=BA=AB=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/dto/ReportShareDto.java | 5 ++ .../reportshare/dao/entity/ReportShare.java | 13 ++++- .../service/impl/ReportShareServiceImpl.java | 17 +++++- .../template/gaea/business/util/JwtUtil.java | 17 ++++++ .../template/gaea/business/util/UuidUtil.java | 23 +++++++- report-ui/src/views/report/aj/index.vue | 56 +++++++++++++++++-- .../views/report/report/components/share.vue | 54 ++++++++++++++---- 7 files changed, 163 insertions(+), 22 deletions(-) diff --git a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/reportshare/controller/dto/ReportShareDto.java b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/reportshare/controller/dto/ReportShareDto.java index 0b139d01..14690975 100644 --- a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/reportshare/controller/dto/ReportShareDto.java +++ b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/reportshare/controller/dto/ReportShareDto.java @@ -53,4 +53,9 @@ public class ReportShareDto extends GaeaBaseDTO implements Serializable { @ApiModelProperty(value = "0--未删除 1--已删除 DIC_NAME=DELETE_FLAG") private Integer deleteFlag; + /** 分享码 */ + private String sharePassword; + + private boolean sharePasswordFlag = false; + } diff --git a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/reportshare/dao/entity/ReportShare.java b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/reportshare/dao/entity/ReportShare.java index 59bd466d..b2d06a52 100644 --- a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/reportshare/dao/entity/ReportShare.java +++ b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/reportshare/dao/entity/ReportShare.java @@ -1,11 +1,11 @@ package com.anjiplus.template.gaea.business.modules.reportshare.dao.entity; -import lombok.Data; -import io.swagger.annotations.ApiModelProperty; import com.anji.plus.gaea.curd.entity.GaeaBaseEntity; +import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableName; -import javax.validation.constraints.*; +import lombok.Data; + import java.util.Date; /** * @description 报表分享 entity @@ -39,5 +39,12 @@ public class ReportShare extends GaeaBaseEntity { /** 0--未删除 1--已删除 DIC_NAME=DELETE_FLAG */ private Integer deleteFlag; + /** 分享码 */ + @TableField(exist = false) + private String sharePassword; + + @TableField(exist = false) + private boolean sharePasswordFlag; + } diff --git a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/reportshare/service/impl/ReportShareServiceImpl.java b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/reportshare/service/impl/ReportShareServiceImpl.java index 60e165c8..5a1b9819 100644 --- a/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/reportshare/service/impl/ReportShareServiceImpl.java +++ b/report-core/src/main/java/com/anjiplus/template/gaea/business/modules/reportshare/service/impl/ReportShareServiceImpl.java @@ -13,9 +13,11 @@ import com.anjiplus.template.gaea.business.modules.reportshare.dao.entity.Report import com.anjiplus.template.gaea.business.modules.reportshare.service.ReportShareService; import com.anjiplus.template.gaea.business.util.DateUtil; import com.anjiplus.template.gaea.business.util.JwtUtil; +import com.anjiplus.template.gaea.business.util.MD5Util; import com.anjiplus.template.gaea.business.util.UuidUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -51,12 +53,18 @@ public class ReportShareServiceImpl implements ReportShareService { @Override public ReportShareDto insertShare(ReportShareDto dto) { + //设置分享码 + if (dto.isSharePasswordFlag()) { + dto.setSharePassword(UuidUtil.getRandomPwd(4)); + } + ReportShareDto reportShareDto = new ReportShareDto(); ReportShare entity = new ReportShare(); BeanUtils.copyProperties(dto, entity); insert(entity); //将分享链接返回 reportShareDto.setShareUrl(entity.getShareUrl()); + reportShareDto.setSharePassword(dto.getSharePassword()); return reportShareDto; } @@ -69,6 +77,12 @@ public class ReportShareServiceImpl implements ReportShareService { if (null == reportShare) { throw BusinessExceptionBuilder.build(ResponseCode.REPORT_SHARE_LINK_INVALID); } + //解析jwt token,获取密码 + String password = JwtUtil.getPassword(reportShare.getShareToken()); + if (StringUtils.isNotBlank(password)) { + //md5加密返回 + reportShare.setSharePassword(MD5Util.encrypt(password)); + } return reportShare; } @@ -101,7 +115,8 @@ public class ReportShareServiceImpl implements ReportShareService { } else { entity.setShareUrl(entity.getShareUrl() + SHARE_FLAG + shareCode); } + entity.setShareValidTime(DateUtil.getFutureDateTmdHms(entity.getShareValidType())); - entity.setShareToken(JwtUtil.createToken(entity.getReportCode(), shareCode, entity.getShareValidTime())); + entity.setShareToken(JwtUtil.createToken(entity.getReportCode(), shareCode, entity.getSharePassword(), entity.getShareValidTime())); } } diff --git a/report-core/src/main/java/com/anjiplus/template/gaea/business/util/JwtUtil.java b/report-core/src/main/java/com/anjiplus/template/gaea/business/util/JwtUtil.java index c2867eb6..753f4def 100644 --- a/report-core/src/main/java/com/anjiplus/template/gaea/business/util/JwtUtil.java +++ b/report-core/src/main/java/com/anjiplus/template/gaea/business/util/JwtUtil.java @@ -7,6 +7,7 @@ import com.auth0.jwt.JWTVerifier; import com.auth0.jwt.algorithms.Algorithm; import com.auth0.jwt.interfaces.Claim; import com.auth0.jwt.interfaces.DecodedJWT; +import org.apache.commons.lang3.StringUtils; import java.util.Date; import java.util.Map; @@ -19,11 +20,16 @@ public class JwtUtil { private static final String JWT_SECRET = "aj-report"; public static String createToken(String reportCode, String shareCode, Date expires) { + return createToken(reportCode, shareCode, null, expires); + } + + public static String createToken(String reportCode, String shareCode, String password, Date expires) { String token = JWT.create() .withIssuedAt(new Date()) .withExpiresAt(expires) .withClaim("reportCode", reportCode) .withClaim("shareCode", shareCode) + .withClaim("sharePassword", password) .sign(Algorithm.HMAC256(JWT_SECRET)); return token; } @@ -55,4 +61,15 @@ public class JwtUtil { return claim.asString(); } + public static String getPassword(String token) { + Claim claim = getClaim(token).get("sharePassword"); + if (null == claim) { + return null; + } + if (StringUtils.isNotBlank(claim.asString())) { + return claim.asString(); + } + return null; + } + } diff --git a/report-core/src/main/java/com/anjiplus/template/gaea/business/util/UuidUtil.java b/report-core/src/main/java/com/anjiplus/template/gaea/business/util/UuidUtil.java index b152ea75..40031aab 100644 --- a/report-core/src/main/java/com/anjiplus/template/gaea/business/util/UuidUtil.java +++ b/report-core/src/main/java/com/anjiplus/template/gaea/business/util/UuidUtil.java @@ -1,5 +1,6 @@ package com.anjiplus.template.gaea.business.util; +import java.security.SecureRandom; import java.util.UUID; /** @@ -31,6 +32,24 @@ public class UuidUtil { } + /** + * 获取随机小写密码 + * @param num + * @return + */ + public static String getRandomPwd(int num) { + StringBuilder builder = new StringBuilder(); + // 因为已经把 4 种字符放进list了,所以 i 取值从 4开始 + // 产生随机数用于随机调用生成字符的函数 + for (int i = 0; i < num; i++) { + SecureRandom random = new SecureRandom(); + int funNum = random.nextInt(chars.length); + builder.append(chars[funNum]); + } + + return builder.toString().toLowerCase(); + } + public static String generateUuid() { return UUID.randomUUID().toString().replace("-", ""); @@ -38,7 +57,9 @@ public class UuidUtil { public static void main(String[] args) { for (int i = 0; i < 100; i++) { - System.out.println(generateShortUuid()); +// System.out.println(generateShortUuid()); + System.out.println(getRandomPwd(4)); } + } } diff --git a/report-ui/src/views/report/aj/index.vue b/report-ui/src/views/report/aj/index.vue index 8474facb..369f9e62 100644 --- a/report-ui/src/views/report/aj/index.vue +++ b/report-ui/src/views/report/aj/index.vue @@ -6,6 +6,18 @@ !--> @@ -18,7 +30,11 @@ export default { }, data() { return { - + password: '', + sharePassword: '', + dialogVisible: false, + reportCode: '', + shareToken: '' }; }, @@ -33,18 +49,46 @@ export default { const {code, data} = await reportShareDetailByCode(shareCode) if (code != '200') return - setShareToken(data.shareToken) - //将shareToken缓存在浏览器 - //跳转至大屏预览页面 + console.log(data) + this.reportCode = data.reportCode + this.sharePassword = data.sharePassword + this.shareToken = data.shareToken + if (this.sharePassword) { + console.log(this.sharePassword) + this.dialogVisible = true + }else { + this.pushAj() + } + }, + checkPassword(){ + const md5 = require('js-md5') + const inputPassword = md5(this.password); + console.log(this.password +'--------------'+inputPassword + "--------" + this.sharePassword) + if (inputPassword == this.sharePassword) { + this.pushAj() + }else { + this.$message.error('分享码输入不正确') + } + + }, + pushAj(){ + setShareToken(this.shareToken) this.$router.push({ path: '/bigscreen/viewer', query: { - reportCode: data.reportCode + reportCode: this.reportCode }, }) - }, + handleClose(done) { + this.$confirm('确认关闭?') + .then(_ => { + done(); + }) + .catch(_ => {}); + } } + }; diff --git a/report-ui/src/views/report/report/components/share.vue b/report-ui/src/views/report/report/components/share.vue index f61335b3..430a67f7 100644 --- a/report-ui/src/views/report/report/components/share.vue +++ b/report-ui/src/views/report/report/components/share.vue @@ -11,19 +11,40 @@ + + + + + + + + + 创建链接
- - - - - - - 复制链接 + + + + + + + + + + + + + + + + + 复制链接 + 复制链接和分享码 - +
@@ -71,6 +92,8 @@ export default { reportCode: '', shareUrl: '', shareCode: '', + sharePassword: '', + sharePasswordFlag: false, }, shareLinkFlag1: true, rules: { @@ -103,24 +126,33 @@ export default { if (code != '200') return this.shareValidTypeOptions = data this.dialogForm.shareValidType = this.shareValidTypeOptions[0].id + this.dialogForm.sharePasswordFlag = false + this.dialogForm.sharePassword = '' }, async createShare() { this.dialogForm.reportCode = this.reportCode this.dialogForm.shareUrl = window.location.href - console.log(this.dialogForm) + // console.log(this.dialogForm) const {code, data} = await reportShareAdd(this.dialogForm) if (code != '200') return - console.log(data) + // console.log(data) this.shareLinkFlag1 = false this.$message({ message: '创建链接成功!', type: 'success', }) this.reportShareUrl = data.shareUrl + this.dialogForm.sharePassword = data.sharePassword }, copyShare(){ - this.copyToClip(this.reportShareUrl) + let content = '' + if (this.dialogForm.sharePassword == '') { + content = 'AJ-Report分享链接:' + this.reportShareUrl + }else { + content = 'AJ-Report分享链接:' + this.reportShareUrl + ' 分享码:' + this.dialogForm.sharePassword; + } + this.copyToClip(content) this.$message({ message: '复制链接成功!', type: 'success', From 95a137a36a765ba13b9a1e5c11ad4841af3222a5 Mon Sep 17 00:00:00 2001 From: Raod <1130305001@qq.com> Date: Thu, 23 Sep 2021 14:56:19 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E9=9B=86=E7=82=B9?= =?UTF-8?q?=E5=87=BB=E4=BA=8B=E4=BB=B6=E9=97=AE=E9=A2=98(=E7=82=B9?= =?UTF-8?q?=E5=87=BB=E7=BC=96=E8=BE=91=E4=BC=9A=E5=87=BA=E7=8E=B0=E7=BC=96?= =?UTF-8?q?=E8=BE=91=E5=92=8C=E9=A2=84=E8=A7=88=E7=9A=84=E5=BC=B9=E6=A1=86?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- report-ui/src/views/report/resultset/components/DataView.vue | 2 ++ report-ui/src/views/report/resultset/components/EditDataSet.vue | 2 ++ 2 files changed, 4 insertions(+) diff --git a/report-ui/src/views/report/resultset/components/DataView.vue b/report-ui/src/views/report/resultset/components/DataView.vue index a812de14..2469a64f 100644 --- a/report-ui/src/views/report/resultset/components/DataView.vue +++ b/report-ui/src/views/report/resultset/components/DataView.vue @@ -1,8 +1,10 @@