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',