n20-common-lib 2.9.59 → 2.9.60
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/directives/watermark/index.js +115 -47
- package/src/index.js +8 -7
package/package.json
CHANGED
|
@@ -1,66 +1,134 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
// 全局状态
|
|
2
|
+
let isGlobalWatermarkActive = false
|
|
3
|
+
let globalObserver = null
|
|
4
|
+
|
|
5
|
+
// 默认配置
|
|
6
|
+
const defaultOptions = {
|
|
7
|
+
text: '', // 水印文本
|
|
8
|
+
font: '16px Microsoft JhengHei', // 字体
|
|
9
|
+
textColor: 'rgba(180, 180, 180, 0.3)', // 文字颜色
|
|
10
|
+
width: 220, // 水印宽度
|
|
11
|
+
height: 180, // 水印高度
|
|
12
|
+
rotate: -20, // 旋转角度
|
|
13
|
+
zIndex: 99999, // z-index
|
|
14
|
+
global: false // 是否全局应用
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// 创建水印canvas
|
|
18
|
+
const createWatermarkCanvas = (options) => {
|
|
19
|
+
const can = document.createElement('canvas')
|
|
20
|
+
can.width = options.width
|
|
21
|
+
can.height = options.height
|
|
9
22
|
can.style.display = 'none'
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
23
|
+
|
|
24
|
+
const ctx = can.getContext('2d')
|
|
25
|
+
ctx.rotate((options.rotate * Math.PI) / 180)
|
|
26
|
+
ctx.font = options.font
|
|
27
|
+
ctx.fillStyle = options.textColor
|
|
28
|
+
ctx.textAlign = 'left'
|
|
29
|
+
ctx.textBaseline = 'Middle'
|
|
30
|
+
ctx.fillText(options.text, can.width / 10, can.height / 2)
|
|
31
|
+
|
|
32
|
+
return can.toDataURL('image/png')
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// 创建水印容器
|
|
36
|
+
const createWatermarkContainer = (options) => {
|
|
37
|
+
const div = document.createElement('div')
|
|
38
|
+
div.className = 'n20_v_watermark'
|
|
39
|
+
|
|
40
|
+
const style = `
|
|
41
|
+
position:absolute;
|
|
42
|
+
top:0;
|
|
43
|
+
left:0;
|
|
44
|
+
width:100%;
|
|
45
|
+
height:100%;
|
|
46
|
+
inset:0;
|
|
47
|
+
z-index:${options.zIndex};
|
|
48
|
+
pointer-events:none;
|
|
49
|
+
background-repeat:repeat;
|
|
50
|
+
background-image:url('${createWatermarkCanvas(options)}')`
|
|
51
|
+
|
|
52
|
+
div.setAttribute('style', style)
|
|
53
|
+
return div
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// 清除水印
|
|
57
|
+
const clearWatermark = () => {
|
|
58
|
+
const watermarks = document.querySelectorAll('.n20_v_watermark')
|
|
59
|
+
watermarks.forEach((wm) => wm.remove())
|
|
60
|
+
if (globalObserver) {
|
|
61
|
+
globalObserver.disconnect()
|
|
62
|
+
globalObserver = null
|
|
63
|
+
}
|
|
64
|
+
isGlobalWatermarkActive = false
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// 添加水印
|
|
68
|
+
const addWatermark = (el, options) => {
|
|
69
|
+
// 如果全局水印已激活且当前不是全局调用,则跳过
|
|
70
|
+
if (isGlobalWatermarkActive && el !== document.body) {
|
|
71
|
+
return
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const parent = el || document.body
|
|
75
|
+
const watermark = createWatermarkContainer(options)
|
|
76
|
+
|
|
77
|
+
parent.style.position = 'relative'
|
|
78
|
+
parent.insertBefore(watermark, parent.firstChild)
|
|
79
|
+
|
|
80
|
+
// 如果是全局水印,设置状态
|
|
81
|
+
if (el === document.body) {
|
|
82
|
+
isGlobalWatermarkActive = true
|
|
33
83
|
}
|
|
84
|
+
|
|
85
|
+
// 监听DOM变化
|
|
34
86
|
const MutationObserver = window.MutationObserver || window.WebKitMutationObserver
|
|
35
87
|
if (MutationObserver) {
|
|
36
|
-
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
mo.disconnect()
|
|
42
|
-
mo = null
|
|
43
|
-
addWaterMarker(str, parentNode, font, textColor)
|
|
88
|
+
const observer = new MutationObserver(() => {
|
|
89
|
+
const wm = document.querySelector('.n20_v_watermark')
|
|
90
|
+
if (!wm || wm.getAttribute('style') !== watermark.getAttribute('style')) {
|
|
91
|
+
observer.disconnect()
|
|
92
|
+
addWatermark(el, options)
|
|
44
93
|
}
|
|
45
94
|
})
|
|
46
95
|
|
|
47
|
-
|
|
96
|
+
observer.observe(parent, {
|
|
48
97
|
attributes: true,
|
|
49
98
|
subtree: true,
|
|
50
99
|
childList: true
|
|
51
100
|
})
|
|
52
|
-
}
|
|
53
101
|
|
|
54
|
-
|
|
55
|
-
|
|
102
|
+
// 如果是全局水印,保存observer
|
|
103
|
+
if (el === document.body) {
|
|
104
|
+
globalObserver = observer
|
|
105
|
+
}
|
|
106
|
+
}
|
|
56
107
|
}
|
|
57
108
|
|
|
58
109
|
const watermark = {
|
|
59
|
-
install
|
|
110
|
+
install(Vue, options = {}) {
|
|
111
|
+
// 合并配置
|
|
112
|
+
const config = { ...defaultOptions, ...options }
|
|
113
|
+
|
|
114
|
+
// 全局应用
|
|
115
|
+
if (config.global) {
|
|
116
|
+
clearWatermark()
|
|
117
|
+
addWatermark(document.body, config)
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// 指令方式
|
|
60
121
|
Vue.directive('watermark', {
|
|
61
|
-
inserted
|
|
62
|
-
|
|
63
|
-
|
|
122
|
+
inserted(el, binding) {
|
|
123
|
+
if (isGlobalWatermarkActive) return
|
|
124
|
+
|
|
125
|
+
const directiveOptions = typeof binding.value === 'string' ? { text: binding.value } : binding.value
|
|
126
|
+
addWatermark(el, { ...config, ...directiveOptions, global: false })
|
|
127
|
+
},
|
|
128
|
+
unbind(el) {
|
|
129
|
+
if (!isGlobalWatermarkActive) {
|
|
130
|
+
clearWatermark()
|
|
131
|
+
}
|
|
64
132
|
}
|
|
65
133
|
})
|
|
66
134
|
}
|
package/src/index.js
CHANGED
|
@@ -64,13 +64,13 @@ import Upload from './components/Upload/index.vue'
|
|
|
64
64
|
import WornPagination from './components/WornPagination/index.vue'
|
|
65
65
|
|
|
66
66
|
import AdvancedFilter from './components/AdvancedFilter/index.vue'
|
|
67
|
+
import AttachmentPass from './components/AttachmentPass/index.vue'
|
|
67
68
|
import DateChoose from './components/DateChoose/index.vue'
|
|
68
69
|
import ElectronicArchive from './components/ElectronicArchive/index.vue'
|
|
70
|
+
import HandlingAdvice from './components/HandlingAdvice/index.vue'
|
|
69
71
|
import Preview from './components/Preview/index.vue'
|
|
70
72
|
import SelectTreePro from './components/SelectTree/pro.vue'
|
|
71
73
|
import Tree from './components/Tree/index.vue'
|
|
72
|
-
import AttachmentPass from './components/AttachmentPass/index.vue'
|
|
73
|
-
import HandlingAdvice from './components/HandlingAdvice/index.vue'
|
|
74
74
|
|
|
75
75
|
// 新版日期选择框
|
|
76
76
|
import BusiDatePicker from './components/DateSelect/busiDate.vue'
|
|
@@ -263,7 +263,7 @@ const install = function (Vue, opts = { prefix: 'Cl', i18nConfig: {} }) {
|
|
|
263
263
|
Vue.use(VHas)
|
|
264
264
|
Vue.use(VTableLoading)
|
|
265
265
|
Vue.use(VErrorMessage)
|
|
266
|
-
Vue.use(watermark)
|
|
266
|
+
// Vue.use(watermark)
|
|
267
267
|
|
|
268
268
|
Vue.use(i18n, opts.i18nConfig)
|
|
269
269
|
Vue.prototype.$axios = axios
|
|
@@ -299,6 +299,7 @@ export {
|
|
|
299
299
|
ApprovalRecordZjk,
|
|
300
300
|
ApproveCard,
|
|
301
301
|
ApproveCardZjk,
|
|
302
|
+
AttachmentPass,
|
|
302
303
|
BusiDatePicker,
|
|
303
304
|
Button,
|
|
304
305
|
ButtonGroup,
|
|
@@ -326,6 +327,8 @@ export {
|
|
|
326
327
|
FlowDialog,
|
|
327
328
|
FlowStep,
|
|
328
329
|
FooterBox,
|
|
330
|
+
HalfYearPicker,
|
|
331
|
+
HandlingAdvice,
|
|
329
332
|
IconGroupButton,
|
|
330
333
|
InputNumber,
|
|
331
334
|
InputNumberRange,
|
|
@@ -337,7 +340,6 @@ export {
|
|
|
337
340
|
Pagination,
|
|
338
341
|
Preview,
|
|
339
342
|
QuarterDatePicker,
|
|
340
|
-
HalfYearPicker,
|
|
341
343
|
SecondaryTab,
|
|
342
344
|
SelectDatePicker,
|
|
343
345
|
SelectDatePickerPro,
|
|
@@ -364,12 +366,10 @@ export {
|
|
|
364
366
|
TertiaryTab,
|
|
365
367
|
TimePicker,
|
|
366
368
|
Tree,
|
|
367
|
-
AttachmentPass,
|
|
368
369
|
Upload,
|
|
369
370
|
UploadMsg,
|
|
370
371
|
WorkCard,
|
|
371
372
|
WornPagination,
|
|
372
|
-
HandlingAdvice,
|
|
373
373
|
asyncGetRelaNos,
|
|
374
374
|
// 方法
|
|
375
375
|
auth,
|
|
@@ -402,5 +402,6 @@ export {
|
|
|
402
402
|
// 页签/路由
|
|
403
403
|
setTabs,
|
|
404
404
|
type,
|
|
405
|
-
version
|
|
405
|
+
version,
|
|
406
|
+
watermark
|
|
406
407
|
}
|