An error occurred while loading the file. Please try again.
An error occurred while loading the file. Please try again.
An error occurred while loading the file. Please try again.
-
luye authored8970e6db
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<template>
<div>
<slot :images="images" :options="option">
</slot>
</div>
</template>
<script>
import Viewer from 'viewerjs'
export default {
data() {
return {
option: {}
}
},
created() {
this.init()
},
props: {
images: {
type: Array,
},
rebuild: {
type: Boolean,
default: false,
},
trigger: {},
options: {
type: Object,
},
},
computed: {
// option2(){
// return this.option
// }
},
watch: {
images() {
this.$nextTick(() => {
this.onChange()
})
},
trigger: {
handler() {
this.$nextTick(() => {
this.onChange()
})
},
deep: true,
},
options: {
handler() {
this.$nextTick(() => {
this.rebuildViewer()
})
},
deep: true,
},
},
mounted() {
this.createViewer()
},
unmounted() {
this.destroyViewer()
},
methods: {
init() {
Object.assign(this.option, this.options)
Object.assign(this.option, {show: this.show})
},
show() {
let container = document.getElementsByClassName('viewer-container')[0]
let reg = /.+({.+}).+/
let viewBigBtn = document.createElement('div')
viewBigBtn.innerText = '查看大图'
viewBigBtn.className = 'xnwBtn viewBig'
viewBigBtn.addEventListener('click', _ => {
let url = window.decodeURIComponent(container.getElementsByClassName('viewer-canvas')[0].getElementsByTagName('img')[0].src)
let fileid = url.match(reg)[1]
let bigUrl = `//cdn.xnwimg.com/down/${fileid}/1.jpg`
window.open(bigUrl, '_blank')
})
container.appendChild(viewBigBtn)
if (this.options && this.options.correct) {
let correctBtn = document.createElement('div')
correctBtn.innerText = '批注'
correctBtn.className = 'xnwBtn correct'
correctBtn.addEventListener('click', _ => {
let url = window.decodeURIComponent(container.getElementsByClassName('viewer-canvas')[0].getElementsByTagName('img')[0].src)
let fileid = url.match(reg)[1]
this.$emit('correct', fileid)
this.rebuildViewer()
})
container.appendChild(correctBtn)
}
},
onChange() {
if (this.rebuild) {
this.rebuildViewer()
}
else {
this.updateViewer()
}
},
rebuildViewer() {
this.destroyViewer()
this.createViewer()
},
updateViewer() {
if (this.$viewer) {
this.$viewer.update()
this.$emit('inited', this.$viewer)
}
else {
this.createViewer()
}
},
destroyViewer() {
this.$viewer && this.$viewer.destroy()
},
createViewer() {
this.init()
this.$viewer = new Viewer(this.$el, this.option)
this.$emit('inited', this.$viewer)
},
},
}
</script>
<style lang="scss">
.viewer-container {
.xnwBtn {
background-color: orange;
border-radius: 2px;
cursor: pointer;
height: 28px;
line-height: 28px;
color: white;
font-size: 14px;
overflow: hidden;
position: absolute;
right: 100px;
top: 40px;
padding: 0 7px;
transition: background-color 0.15s;
&.viewBig {
right: 100px;
}
&.correct {
right: 200px;
}
&:hover {
opacity: .9;
}
}
}
</style>