@mixd-id/web-scaffold 0.1.230406134 → 0.1.230406136
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/components/Image.vue +34 -11
- package/src/index.js +5 -4
package/package.json
CHANGED
package/src/components/Image.vue
CHANGED
|
@@ -65,6 +65,10 @@ export default{
|
|
|
65
65
|
|
|
66
66
|
computed:{
|
|
67
67
|
|
|
68
|
+
actualSrc(){
|
|
69
|
+
return this.mediaSrc[this.$screenPrefix]
|
|
70
|
+
},
|
|
71
|
+
|
|
68
72
|
compClass(){
|
|
69
73
|
return [
|
|
70
74
|
this.$style.comp,
|
|
@@ -89,21 +93,31 @@ export default{
|
|
|
89
93
|
data(){
|
|
90
94
|
return {
|
|
91
95
|
status: 0, // 0:empty, 1:loading, 2:image, 3:error
|
|
92
|
-
|
|
93
|
-
|
|
96
|
+
moved: false,
|
|
97
|
+
mediaSrc: {},
|
|
98
|
+
visibled: false
|
|
94
99
|
}
|
|
95
100
|
},
|
|
96
101
|
|
|
97
102
|
mounted(){
|
|
98
103
|
this.$observe.once(this.$el, () => {
|
|
104
|
+
this.visibled = true
|
|
99
105
|
this.loadSrc()
|
|
100
106
|
})
|
|
101
107
|
|
|
102
|
-
this.$resize(
|
|
108
|
+
this.$resize(this.onResize)
|
|
103
109
|
},
|
|
104
110
|
|
|
111
|
+
unmounted() {
|
|
112
|
+
this.$unresize(this.onResize)
|
|
113
|
+
},
|
|
114
|
+
|
|
105
115
|
methods:{
|
|
106
116
|
|
|
117
|
+
onResize(){
|
|
118
|
+
this.loadSrc()
|
|
119
|
+
},
|
|
120
|
+
|
|
107
121
|
onChange(e){
|
|
108
122
|
if(e.target.files.length > 0){
|
|
109
123
|
var reader = new FileReader();
|
|
@@ -122,10 +136,20 @@ export default{
|
|
|
122
136
|
|
|
123
137
|
async loadSrc(){
|
|
124
138
|
|
|
139
|
+
// src: String | Array | File
|
|
140
|
+
|
|
141
|
+
if(!this.visibled){
|
|
142
|
+
return
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if(this.$screenPrefix in this.mediaSrc){
|
|
146
|
+
return
|
|
147
|
+
}
|
|
148
|
+
|
|
125
149
|
if(typeof this.src === 'string') {
|
|
126
150
|
|
|
127
151
|
if (this.src.startsWith('data:image')) {
|
|
128
|
-
this.
|
|
152
|
+
this.mediaSrc[this.$screenPrefix] = this.src
|
|
129
153
|
this.status = 2
|
|
130
154
|
}
|
|
131
155
|
else{
|
|
@@ -156,12 +180,12 @@ export default{
|
|
|
156
180
|
img.addEventListener('load', () => {
|
|
157
181
|
if(img.getAttribute('data-src') !== this.src) return
|
|
158
182
|
this.status = 2
|
|
159
|
-
this.
|
|
183
|
+
this.mediaSrc[this.$screenPrefix] = img.src
|
|
160
184
|
})
|
|
161
185
|
img.addEventListener('error', (err) => {
|
|
162
186
|
if(img.getAttribute('data-src') !== this.src) return
|
|
163
187
|
this.status = 3
|
|
164
|
-
this.
|
|
188
|
+
this.mediaSrc[this.$screenPrefix] = this.defaultSrc
|
|
165
189
|
})
|
|
166
190
|
img.src = imgSrc
|
|
167
191
|
img.setAttribute('data-src', this.src)
|
|
@@ -188,11 +212,11 @@ export default{
|
|
|
188
212
|
var img = new Image()
|
|
189
213
|
img.addEventListener('load', () => {
|
|
190
214
|
this.status = 2
|
|
191
|
-
this.
|
|
215
|
+
this.mediaSrc[this.$screenPrefix] = img.src
|
|
192
216
|
})
|
|
193
217
|
img.addEventListener('error', (err) => {
|
|
194
218
|
this.status = 3
|
|
195
|
-
this.
|
|
219
|
+
this.mediaSrc[this.$screenPrefix] = this.defaultSrc
|
|
196
220
|
})
|
|
197
221
|
img.src = imgSrc
|
|
198
222
|
this.status = 1
|
|
@@ -203,18 +227,17 @@ export default{
|
|
|
203
227
|
|
|
204
228
|
reader.addEventListener('load', () => {
|
|
205
229
|
this.status = 2
|
|
206
|
-
this.
|
|
230
|
+
this.mediaSrc[this.$screenPrefix] = reader.result
|
|
207
231
|
}, false)
|
|
208
232
|
|
|
209
233
|
reader.addEventListener('error', () => {
|
|
210
234
|
this.status = 3
|
|
211
|
-
this.
|
|
235
|
+
this.mediaSrc[this.$screenPrefix] = this.defaultSrc
|
|
212
236
|
})
|
|
213
237
|
|
|
214
238
|
reader.readAsDataURL(this.src)
|
|
215
239
|
this.status = 1
|
|
216
240
|
}
|
|
217
|
-
|
|
218
241
|
},
|
|
219
242
|
|
|
220
243
|
onClick(){
|
package/src/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {defineAsyncComponent, ref} from "vue"
|
|
1
|
+
import {defineAsyncComponent, reactive, ref} from "vue"
|
|
2
2
|
import {accessNestedObject, observeInit} from './utils/helpers.mjs'
|
|
3
3
|
import throttle from "lodash/throttle"
|
|
4
4
|
|
|
@@ -273,11 +273,12 @@ export default{
|
|
|
273
273
|
app.config.globalProperties.$observe = observeInit()
|
|
274
274
|
}
|
|
275
275
|
|
|
276
|
-
app.config.globalProperties.$screenPrefix =
|
|
276
|
+
app.config.globalProperties.$screenPrefix = reactive(util.calculateMediaPrefix(window.innerWidth))
|
|
277
277
|
const onWindowResize = throttle(() => {
|
|
278
|
-
app.config.globalProperties.$screenPrefix
|
|
278
|
+
app.config.globalProperties.$screenPrefix = util.calculateMediaPrefix(window.innerWidth)
|
|
279
279
|
resizeEvents.forEach((fn) => fn())
|
|
280
|
-
|
|
280
|
+
console.log('1')
|
|
281
|
+
}, 500, { leading:true })
|
|
281
282
|
|
|
282
283
|
window.addEventListener('resize', onWindowResize)
|
|
283
284
|
}
|