From acab3ceb24b7c9c40586fc1c82ece23a9f2d7420 Mon Sep 17 00:00:00 2001 From: fit2cloud-chenyw Date: Thu, 19 Aug 2021 14:54:32 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=85=AC=E5=85=B1=E9=93=BE=E6=8E=A5?= =?UTF-8?q?=E5=88=86=E4=BA=AB=E5=A2=9E=E5=8A=A0=E7=9F=AD=E9=93=BE=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/panel/api/LinkApi.java | 5 ++++ .../controller/panel/server/LinkServer.java | 7 +++++ .../service/panel/PanelLinkService.java | 29 ++++++++++++++++++- frontend/src/api/link/index.js | 8 +++++ frontend/src/lang/en.js | 2 ++ frontend/src/lang/tw.js | 2 ++ frontend/src/lang/zh.js | 2 ++ frontend/src/views/link/generate/index.vue | 21 ++++++++++++-- 8 files changed, 73 insertions(+), 3 deletions(-) diff --git a/backend/src/main/java/io/dataease/controller/panel/api/LinkApi.java b/backend/src/main/java/io/dataease/controller/panel/api/LinkApi.java index 5b2eb05d08..96e95b94a9 100644 --- a/backend/src/main/java/io/dataease/controller/panel/api/LinkApi.java +++ b/backend/src/main/java/io/dataease/controller/panel/api/LinkApi.java @@ -2,6 +2,7 @@ package io.dataease.controller.panel.api; import com.github.xiaoymin.knife4j.annotations.ApiSupport; +import io.dataease.controller.ResultHolder; import io.dataease.controller.request.chart.ChartExtRequest; import io.dataease.controller.request.panel.link.EnablePwdRequest; import io.dataease.controller.request.panel.link.LinkRequest; @@ -51,4 +52,8 @@ public interface LinkApi { @ApiOperation("视图详息") @PostMapping("/viewDetail/{viewId}") Object viewDetail(@PathVariable String viewId, @RequestBody ChartExtRequest requestList) throws Exception; + + @ApiOperation("压缩链接") + @PostMapping("/shortUrl") + ResultHolder shortUrl(@RequestBody Map param); } diff --git a/backend/src/main/java/io/dataease/controller/panel/server/LinkServer.java b/backend/src/main/java/io/dataease/controller/panel/server/LinkServer.java index 8931451652..cd63ab3b2b 100644 --- a/backend/src/main/java/io/dataease/controller/panel/server/LinkServer.java +++ b/backend/src/main/java/io/dataease/controller/panel/server/LinkServer.java @@ -3,6 +3,7 @@ package io.dataease.controller.panel.server; import com.google.gson.Gson; import io.dataease.base.domain.PanelLink; +import io.dataease.controller.ResultHolder; import io.dataease.controller.panel.api.LinkApi; import io.dataease.controller.request.chart.ChartExtRequest; import io.dataease.controller.request.panel.link.EnablePwdRequest; @@ -90,4 +91,10 @@ public class LinkServer implements LinkApi { public Object viewDetail(String viewId, ChartExtRequest requestList) throws Exception{ return chartViewService.getData(viewId, requestList); } + + @Override + public ResultHolder shortUrl(Map param) { + String url = param.get("url"); + return panelLinkService.getShortUrl(url); + } } diff --git a/backend/src/main/java/io/dataease/service/panel/PanelLinkService.java b/backend/src/main/java/io/dataease/service/panel/PanelLinkService.java index 9d6c9b1ab5..ddb7d29fa1 100644 --- a/backend/src/main/java/io/dataease/service/panel/PanelLinkService.java +++ b/backend/src/main/java/io/dataease/service/panel/PanelLinkService.java @@ -1,5 +1,6 @@ package io.dataease.service.panel; +import cn.hutool.http.HttpUtil; import com.google.gson.Gson; import io.dataease.auth.config.RsaProperties; import io.dataease.auth.util.JWTUtils; @@ -9,6 +10,7 @@ import io.dataease.base.domain.PanelLink; import io.dataease.base.mapper.PanelGroupMapper; import io.dataease.base.mapper.PanelLinkMapper; import io.dataease.commons.utils.ServletUtils; +import io.dataease.controller.ResultHolder; import io.dataease.controller.request.panel.link.EnablePwdRequest; import io.dataease.controller.request.panel.link.LinkRequest; import io.dataease.controller.request.panel.link.PasswordRequest; @@ -28,9 +30,15 @@ public class PanelLinkService { private static final String baseUrl = "/link.html?link="; - @Value("${public-link-salt:DataEaseLinkSalt}") + @Value("${dataease.public-link-salt:DataEaseLinkSalt}") private String salt; + @Value("${dataease.short-url-site:https://dh6.ink/}") + private String shortUrlSite; + + @Value("${dataease.short-url-api:api/url/add}") + private String shortUrlApi; + @Resource private PanelLinkMapper mapper; @@ -156,4 +164,23 @@ public class PanelLinkService { } + public ResultHolder getShortUrl(String url) { + Gson gson = new Gson(); + Map param = new HashMap<>(); + param.put("diy", false); + param.put("link", url); + param.put("sort", ""); + String post = HttpUtil.post(shortUrlSite + shortUrlApi, param); + try{ + Map map = gson.fromJson(post, Map.class); + Map data = (Map) map.get("data"); + String sort = shortUrlSite + data.get("sort").toString(); + ResultHolder success = ResultHolder.success(sort); + return success; + }catch (Exception e) { + ResultHolder error = ResultHolder.error(e.getMessage()); + return error; + } + + } } diff --git a/frontend/src/api/link/index.js b/frontend/src/api/link/index.js index 93cdcf568b..fd637069d0 100644 --- a/frontend/src/api/link/index.js +++ b/frontend/src/api/link/index.js @@ -65,3 +65,11 @@ export function viewInfo(id, data) { data }) } + +export function shortUrl(data) { + return request({ + url: 'api/link/shortUrl', + method: 'post', + data + }) +} diff --git a/frontend/src/lang/en.js b/frontend/src/lang/en.js index 9e060d75be..d93a7b477c 100644 --- a/frontend/src/lang/en.js +++ b/frontend/src/lang/en.js @@ -1082,6 +1082,8 @@ export default { drag_here: 'Please drag the left field here', copy_link_passwd: 'Copy link and password', copy_link: 'Copy link', + copy_short_link: 'Copy short link', + copy_short_link_passwd: 'Copy short link and password', passwd_protect: 'Password Protect', link: 'Link', link_share: 'Share Link', diff --git a/frontend/src/lang/tw.js b/frontend/src/lang/tw.js index 540539c9b6..a0006686ce 100644 --- a/frontend/src/lang/tw.js +++ b/frontend/src/lang/tw.js @@ -1081,6 +1081,8 @@ export default { drag_here: '請將左側字段拖至此處', copy_link_passwd: '複製鏈接及密碼', copy_link: '複製鏈接', + copy_short_link: '複製短鏈接', + copy_short_link_passwd: '複製短鏈接及密碼', passwd_protect: '密碼保護', link: '鏈接', link_share: '鏈接分享', diff --git a/frontend/src/lang/zh.js b/frontend/src/lang/zh.js index 881f1ef0e5..ba6d5cd0b2 100644 --- a/frontend/src/lang/zh.js +++ b/frontend/src/lang/zh.js @@ -1083,6 +1083,8 @@ export default { drag_here: '请将左侧字段拖至此处', copy_link_passwd: '复制链接及密码', copy_link: '复制链接', + copy_short_link: '复制短链接', + copy_short_link_passwd: '复制短链接及密码', passwd_protect: '密码保护', link: '链接', link_share: '链接分享', diff --git a/frontend/src/views/link/generate/index.vue b/frontend/src/views/link/generate/index.vue index 50112b241e..61d1c68099 100644 --- a/frontend/src/views/link/generate/index.vue +++ b/frontend/src/views/link/generate/index.vue @@ -32,6 +32,8 @@
+ {{ $t('panel.copy_short_link') }} + {{ $t('panel.copy_short_link_passwd') }} {{ $t('panel.copy_link') }} {{ $t('panel.copy_link_passwd') }} @@ -43,9 +45,8 @@