Skip to content

Commit a4e5e08

Browse files
Merge pull request dataease#3751 from dataease/feat_watermark-support
feat: 支持水印设置
2 parents e1a4e4b + aa4e568 commit a4e5e08

File tree

15 files changed

+143
-110
lines changed

15 files changed

+143
-110
lines changed

backend/src/main/java/io/dataease/plugins/server/PluginCommonServer.java

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.springframework.web.bind.annotation.RequestMapping;
1212
import org.springframework.web.bind.annotation.RestController;
1313
import springfox.documentation.annotations.ApiIgnore;
14+
1415
import javax.servlet.http.HttpServletResponse;
1516
import java.io.BufferedInputStream;
1617
import java.io.IOException;
@@ -40,20 +41,20 @@ public void menuInfo(@PathVariable Long menuId) {
4041
BufferedInputStream bis = null;
4142
InputStream inputStream = null;
4243
OutputStream os = null; //输出流
43-
try{
44+
try {
4445
inputStream = service.vueResource(jsName);
4546
byte[] buffer = new byte[1024];
4647
os = response.getOutputStream();
4748
bis = new BufferedInputStream(inputStream);
4849
int i = bis.read(buffer);
49-
while(i != -1){
50+
while (i != -1) {
5051
os.write(buffer, 0, i);
5152
i = bis.read(buffer);
5253
}
5354
os.flush();
54-
}catch (Exception e) {
55+
} catch (Exception e) {
5556
e.printStackTrace();
56-
}finally {
57+
} finally {
5758
try {
5859
bis.close();
5960
inputStream.close();
@@ -69,28 +70,28 @@ public void menuInfo(@PathVariable Long menuId) {
6970

7071
@GetMapping("/component/{componentName}")
7172
public void componentInfo(@PathVariable String componentName) {
72-
Map<String, PluginComponentService> beansOfType = SpringContextUtil.getApplicationContext().getBeansOfType(PluginComponentService.class);
73-
beansOfType.values().stream().forEach(service -> {
73+
Map<String, PluginComponentService> beansOfType = SpringContextUtil.getApplicationContext().getBeansOfType(PluginComponentService.class);
74+
beansOfType.values().stream().forEach(service -> {
7475
List<String> components = service.components();
7576
if (components.contains(componentName)) {
7677
HttpServletResponse response = ServletUtils.response();
7778
BufferedInputStream bis = null;
7879
InputStream inputStream = null;
7980
OutputStream os = null; //输出流
80-
try{
81+
try {
8182
inputStream = service.vueResource(componentName);
8283
byte[] buffer = new byte[1024];
8384
os = response.getOutputStream();
8485
bis = new BufferedInputStream(inputStream);
8586
int i = bis.read(buffer);
86-
while(i != -1){
87+
while (i != -1) {
8788
os.write(buffer, 0, i);
8889
i = bis.read(buffer);
8990
}
9091
os.flush();
91-
}catch (Exception e) {
92+
} catch (Exception e) {
9293
e.printStackTrace();
93-
}finally {
94+
} finally {
9495
try {
9596
bis.close();
9697
inputStream.close();
@@ -101,7 +102,7 @@ public void componentInfo(@PathVariable String componentName) {
101102
}
102103
return;
103104
}
104-
});
105+
});
105106
}
106107

107108
@GetMapping("/staticInfo/{name}/{suffix}")
@@ -115,22 +116,24 @@ public void staticInfo(@PathVariable("name") String name, @PathVariable("suffix"
115116
BufferedInputStream bis = null;
116117
InputStream inputStream = null;
117118
OutputStream os = null; //输出流
118-
try{
119+
try {
119120
inputStream = service.vueResource(name, suffix);
120121
byte[] buffer = new byte[1024];
121122
os = response.getOutputStream();
122123
bis = new BufferedInputStream(inputStream);
123124
int i = bis.read(buffer);
124-
while(i != -1){
125+
while (i != -1) {
125126
os.write(buffer, 0, i);
126127
i = bis.read(buffer);
127128
}
128129
if (suffix.indexOf("svg") != -1)
129130
response.setContentType("image/svg+xml");
131+
if (suffix.indexOf("png") != -1)
132+
response.setContentType("image/png");
130133
os.flush();
131-
}catch (Exception e) {
134+
} catch (Exception e) {
132135
e.printStackTrace();
133-
}finally {
136+
} finally {
134137
try {
135138
bis.close();
136139
inputStream.close();

backend/src/main/java/io/dataease/plugins/server/XWatermarkServer.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@
44
import io.dataease.plugins.xpack.watermark.WatermarkService;
55
import io.dataease.plugins.xpack.watermark.dto.PanelWatermarkDTO;
66
import io.swagger.annotations.ApiOperation;
7-
import org.springframework.web.bind.annotation.GetMapping;
8-
import org.springframework.web.bind.annotation.PostMapping;
9-
import org.springframework.web.bind.annotation.RequestMapping;
10-
import org.springframework.web.bind.annotation.RestController;
7+
import org.springframework.web.bind.annotation.*;
118
import springfox.documentation.annotations.ApiIgnore;
129

1310
/**
@@ -29,7 +26,7 @@ public PanelWatermarkDTO find() {
2926

3027
@ApiOperation("保存水印配置")
3128
@PostMapping("/save")
32-
public void save(PanelWatermarkDTO panelWatermark) {
29+
public void save(@RequestBody PanelWatermarkDTO panelWatermark) {
3330
WatermarkService userXpackService = SpringContextUtil.getBean(WatermarkService.class);
3431
userXpackService.saveWatermarkInfo(panelWatermark);
3532
}

backend/src/main/resources/db/migration/V44__1.17.sql

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,33 @@ ALTER TABLE `sys_log`
66
ALTER TABLE `panel_group`
77
ADD COLUMN `watermark_open` tinyint(1) NULL DEFAULT 1 COMMENT '是否单独打开水印' AFTER `update_time`;
88

9-
INSERT INTO `panel_watermark` (`id`, `version`, `setting_content`, `create_by`, `create_time`)
10-
VALUES ('system_default', '1.0',
11-
'{\"enable\":false,\"enablePanelCustom\":true,\"type\":\"custom\",\"content\":\"${time}-${nickName}\",\"watermark_color\":\"#999999\",\"watermark_x_space\":20,\"watermark_y_space\":100,\"watermark_fontsize\":20}',
12-
'admin', NULL);
13-
9+
DROP TABLE IF EXISTS `panel_watermark`;
1410
CREATE TABLE `panel_watermark`
1511
(
16-
`id` varchar(50) NOT NULL,
17-
`name` varchar(255) DEFAULT NULL,
18-
`version` varchar(255) DEFAULT NULL COMMENT '版本',
19-
`type` varchar(255) DEFAULT NULL COMMENT '类型',
20-
`content` varchar(255) DEFAULT NULL,
12+
`id` varchar(50) NOT NULL,
13+
`version` varchar(255) DEFAULT NULL COMMENT '版本号',
14+
`setting_content` longtext COMMENT '设置内容',
15+
`create_by` varchar(255) DEFAULT NULL,
16+
`create_time` bigint(13) DEFAULT NULL,
2117
PRIMARY KEY (`id`)
2218
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE utf8mb4_general_ci;
2319

20+
INSERT INTO `panel_watermark` (`id`, `version`, `setting_content`, `create_by`, `create_time`)
21+
VALUES ('system_default', '1.0',
22+
'{\"enable\":false,\"enablePanelCustom\":true,\"type\":\"custom\",\"content\":\"${time}-${nickName}\",\"watermark_color\":\"#999999\",\"watermark_x_space\":20,\"watermark_y_space\":100,\"watermark_fontsize\":20}',
23+
'admin', NULL);
24+
2425
SET
2526
FOREIGN_KEY_CHECKS = 1;
2627

27-
UPDATE `sys_menu` SET `component` = 'dataset/Form' WHERE (`menu_id` = '800');
28+
UPDATE `sys_menu`
29+
SET `component` = 'dataset/Form'
30+
WHERE (`menu_id` = '800');
2831

2932

30-
UPDATE `sys_menu` SET `component` = 'msg/All' WHERE (`component` = 'msg/all');
31-
UPDATE `sys_menu` SET `component` = 'msg/Setting' WHERE (`component` = 'msg/setting');
33+
UPDATE `sys_menu`
34+
SET `component` = 'msg/All'
35+
WHERE (`component` = 'msg/all');
36+
UPDATE `sys_menu`
37+
SET `component` = 'msg/Setting'
38+
WHERE (`component` = 'msg/setting');

frontend/src/api/panel/panel.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,10 @@ export function initPanelData(panelId, useCache = false, callback) {
163163
if (response.data) {
164164
// 初始化视图data和style 数据
165165
panelInit(JSON.parse(response.data.panelData), JSON.parse(response.data.panelStyle))
166+
const watermarkInfo = {
167+
...response.data.watermarkInfo,
168+
settingContent: JSON.parse(response.data.watermarkInfo.settingContent)
169+
}
166170
// 设置当前仪表板全局信息
167171
store.dispatch('panel/setPanelInfo', {
168172
id: response.data.id,
@@ -177,7 +181,7 @@ export function initPanelData(panelId, useCache = false, callback) {
177181
updateName: response.data.updateName,
178182
updateTime: response.data.updateTime,
179183
watermarkOpen: response.data.watermarkOpen,
180-
watermarkInfo: response.data.watermarkInfo
184+
watermarkInfo: watermarkInfo
181185
})
182186
// 刷新联动信息
183187
getPanelAllLinkageInfo(panelId).then(rsp => {

frontend/src/api/panel/shareProxy.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ export function proxyInitPanelData(panelId, proxy, callback) {
1010
if (response.data) {
1111
// 初始化视图data和style 数据
1212
panelInit(JSON.parse(response.data.panelData), JSON.parse(response.data.panelStyle))
13+
const watermarkInfo = {
14+
...response.data.watermarkInfo,
15+
settingContent: JSON.parse(response.data.watermarkInfo.settingContent)
16+
}
1317
// 设置当前仪表板全局信息
1418
store.dispatch('panel/setPanelInfo', {
1519
id: response.data.id,
@@ -25,7 +29,7 @@ export function proxyInitPanelData(panelId, proxy, callback) {
2529
updateName: response.data.updateName,
2630
updateTime: response.data.updateTime,
2731
watermarkOpen: response.data.watermarkOpen,
28-
watermarkInfo: response.data.watermarkInfo
32+
watermarkInfo: watermarkInfo
2933
})
3034
// 刷新联动信息
3135
getPanelAllLinkageInfo(panelId, proxy).then(rsp => {
-509 KB
Binary file not shown.

frontend/src/components/canvas/DeCanvas.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
@mouseup="deselectCurComponent"
99
@scroll="canvasScroll"
1010
>
11-
<slot name="optBar"/>
11+
<slot name="optBar" />
1212
<de-editor
1313
:ref="editorRefName"
1414
:canvas-style-data="canvasStyleData"
@@ -265,7 +265,7 @@ export default {
265265
if (this.panelInfo.watermarkInfo) {
266266
userLoginInfo().then(res => {
267267
const userInfo = res.data
268-
activeWatermark(JSON.parse(this.panelInfo.watermarkInfo.settingContent), userInfo, this.canvasDomId, this.canvasId, this.panelInfo.watermarkOpen)
268+
activeWatermark(this.panelInfo.watermarkInfo.settingContent, userInfo, this.canvasDomId, this.canvasId, this.panelInfo.watermarkOpen)
269269
})
270270
}
271271
},

frontend/src/components/canvas/components/Toolbar.vue

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
@change="openMobileLayout"
88
>
99
<el-radio-button :label="false">
10-
<span class="icon iconfont icon-icon_pc_outlined icon16_only"/>
10+
<span class="icon iconfont icon-icon_pc_outlined icon16_only" />
1111
</el-radio-button>
1212
<el-radio-button :label="true">
13-
<span class="icon iconfont icon-icon_phone_outlined icon16_only"/>
13+
<span class="icon iconfont icon-icon_phone_outlined icon16_only" />
1414
</el-radio-button>
1515
</el-radio-group>
1616
</div>
@@ -95,7 +95,7 @@
9595
<el-dropdown-item>
9696
<el-dropdown placement="right-start">
9797
<span>
98-
<span class="icon iconfont icon-icon_moments-categories_outlined icon16"/>
98+
<span class="icon iconfont icon-icon_moments-categories_outlined icon16" />
9999
<span class="text14 margin-left8">{{ $t('panel.new_element_distribution') }}</span>
100100
<svg-icon
101101
icon-class="icon_right_outlined"
@@ -121,7 +121,7 @@
121121
</el-dropdown>
122122
</el-dropdown-item>
123123
<el-dropdown-item>
124-
<span class="icon iconfont icon-icon_dialpad_outlined icon16"/>
124+
<span class="icon iconfont icon-icon_dialpad_outlined icon16" />
125125
<span class="text14 margin-left8">{{ $t('panel.aided_grid') }}</span>
126126
<el-switch
127127
v-model="showGridSwitch"
@@ -131,20 +131,23 @@
131131
/>
132132
</el-dropdown-item>
133133
<el-dropdown-item @click.native="openOuterParamsSet">
134-
<span class="icon iconfont icon-icon-quicksetting icon16"/>
134+
<span class="icon iconfont icon-icon-quicksetting icon16" />
135135
<span class="text14 margin-left8">{{ $t('panel.params_setting') }}</span>
136136
</el-dropdown-item>
137137
<el-dropdown-item @click.native="clearCanvas">
138-
<span class="icon iconfont icon-icon_clear_outlined icon16"/>
138+
<span class="icon iconfont icon-icon_clear_outlined icon16" />
139139
<span class="text14 margin-left8">{{ $t('panel.clean_canvas') }}</span>
140140
</el-dropdown-item>
141-
<el-dropdown-item>
142-
<span class="icon iconfont icon-WATERMARK icon16"/>
141+
<el-dropdown-item
142+
v-if="showWatermarkSetting"
143+
>
144+
<span class="icon iconfont icon-WATERMARK icon16" />
143145
<span class="text14 margin-left8">{{ $t('panel.watermark') }}</span>
144146
<el-switch
145147
v-model="panelInfo.watermarkOpen"
146148
:class="[{['grid-active']: panelInfo.watermarkOpen},'margin-left8']"
147149
size="mini"
150+
@change="styleChange"
148151
/>
149152
</el-dropdown-item>
150153
</el-dropdown-menu>
@@ -191,8 +194,8 @@
191194
</el-col>
192195
<el-col :span="20">
193196
<span style="font-size: 13px;margin-left: 10px;font-weight: bold;line-height: 20px">{{
194-
$t('panel.panel_save_warn_tips')
195-
}}</span>
197+
$t('panel.panel_save_warn_tips')
198+
}}</span>
196199
</el-col>
197200
</el-row>
198201
<div
@@ -259,6 +262,9 @@ export default {
259262
}
260263
},
261264
computed: {
265+
showWatermarkSetting() {
266+
return this.panelInfo.watermarkInfo && this.panelInfo.watermarkInfo.settingContent.enable && this.panelInfo.watermarkInfo.settingContent.enablePanelCustom
267+
},
262268
panelInfo() {
263269
return this.$store.state.panel.panelInfo
264270
},
@@ -437,9 +443,10 @@ export default {
437443
if (_this.$store.state.cacheStyleChangeTimes > 0) {
438444
const requestInfo = _this.savePrepare()
439445
const cacheRequest = {
440-
...this.panelInfo,
446+
...deepCopy(this.panelInfo),
441447
...requestInfo
442448
}
449+
cacheRequest.watermarkInfo.settingContent = JSON.stringify(this.panelInfo.watermarkInfo.settingContent)
443450
saveCache(cacheRequest)
444451
_this.$store.state.cacheStyleChangeTimes = 0
445452
}
@@ -449,6 +456,7 @@ export default {
449456
// 保存到数据库
450457
const requestInfo = {
451458
id: this.panelInfo.id,
459+
watermarkOpen: this.panelInfo.watermarkOpen,
452460
panelStyle: JSON.stringify(this.canvasStyleData),
453461
panelData: JSON.stringify(this.componentData)
454462
}
@@ -619,6 +627,9 @@ export default {
619627
}
620628
})
621629
this.cancelMobileLayoutStatue(sourceComponentData)
630+
},
631+
styleChange() {
632+
this.$store.commit('canvasChange')
622633
}
623634
}
624635
}

frontend/src/components/canvas/components/editor/DeEditor.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@
121121
:canvas-id="canvasId"
122122
/>
123123
<!-- 右击菜单 -->
124-
<ContextMenu/>
124+
<ContextMenu />
125125

126126
<!-- 对齐标线 -->
127127
<span

frontend/src/components/canvas/components/editor/Preview.vue

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<template>
22
<div
3-
class="bg"
43
:id="previewMainDomId"
4+
class="bg"
55
:style="customStyle"
66
@scroll="canvasScroll"
77
>
8-
<canvas-opt-bar/>
8+
<canvas-opt-bar />
99
<div
1010
:id="previewDomId"
1111
:ref="previewRefId"
@@ -315,10 +315,12 @@ export default {
315315
},
316316
methods: {
317317
initWatermark() {
318-
userLoginInfo().then(res => {
319-
const userInfo = res.data
320-
activeWatermark(JSON.parse(this.panelInfo.watermarkInfo.settingContent), userInfo, 'preview-main-canvas-main', this.canvasId, this.panelInfo.watermarkOpen)
321-
})
318+
if (this.panelInfo.watermarkInfo) {
319+
userLoginInfo().then(res => {
320+
const userInfo = res.data
321+
activeWatermark(this.panelInfo.watermarkInfo.settingContent, userInfo, 'preview-main-canvas-main', this.canvasId, this.panelInfo.watermarkOpen)
322+
})
323+
}
322324
},
323325
isMainCanvas() {
324326
return this.canvasId === 'canvas-main'

0 commit comments

Comments
 (0)