feat: 公共链接分享增加短链接

This commit is contained in:
fit2cloud-chenyw 2021-08-19 14:54:32 +08:00
parent b6c03d1ebe
commit acab3ceb24
8 changed files with 73 additions and 3 deletions

View File

@ -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<String,String> param);
}

View File

@ -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<String,String> param) {
String url = param.get("url");
return panelLinkService.getShortUrl(url);
}
}

View File

@ -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;
}
}
}

View File

@ -65,3 +65,11 @@ export function viewInfo(id, data) {
data
})
}
export function shortUrl(data) {
return request({
url: 'api/link/shortUrl',
method: 'post',
data
})
}

View File

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

View File

@ -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: '鏈接分享',

View File

@ -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: '链接分享',

View File

@ -32,6 +32,8 @@
<div v-if="valid" class="auth-root-class">
<span slot="footer">
<el-button v-if="newUrl && !form.enablePwd" v-clipboard:copy="newUrl" v-clipboard:success="onCopy" v-clipboard:error="onError" size="mini" type="primary">{{ $t('panel.copy_short_link') }}</el-button>
<el-button v-if="newUrl && form.enablePwd" v-clipboard:copy="newUrl + ' Password: '+ form.pwd" v-clipboard:success="onCopy" v-clipboard:error="onError" size="mini" type="primary">{{ $t('panel.copy_short_link_passwd') }}</el-button>
<el-button v-if="!form.enablePwd" v-clipboard:copy="form.uri" v-clipboard:success="onCopy" v-clipboard:error="onError" size="mini" type="primary">{{ $t('panel.copy_link') }}</el-button>
<el-button v-if="form.enablePwd" v-clipboard:copy="form.uri + ' Password: '+ form.pwd" v-clipboard:success="onCopy" v-clipboard:error="onError" size="mini" type="primary">{{ $t('panel.copy_link_passwd') }}</el-button>
@ -43,9 +45,8 @@
</template>
<script>
import { loadGenerate, setPwd, switchValid, switchEnablePwd } from '@/api/link'
import { loadGenerate, setPwd, switchValid, switchEnablePwd, shortUrl } from '@/api/link'
import { encrypt, decrypt } from '@/utils/rsaEncrypt'
export default {
name: 'LinkGenerate',
@ -63,6 +64,7 @@ export default {
pwdNums: 4,
valid: false,
form: {},
newUrl: null,
defaultForm: { enablePwd: false, pwd: null, uri: null }
}
},
@ -84,6 +86,7 @@ export default {
this.form.uri = uri ? (this.origin + uri) : uri
//
pwd && (this.form.pwd = decrypt(pwd))
this.requestShort()
})
},
@ -135,6 +138,20 @@ export default {
switchValid(param).then(res => {
})
},
requestShort() {
const url = this.form.uri
if (!url) return
// if (this.origin.includes('localhost') || this.origin.includes('127.0.0.1')) {
// console.log('')
// this.$warning('')
// return
// }
shortUrl({ url }).then(res => {
if (res.success) {
this.newUrl = res.data
}
})
}
}
}