@smart100/spu-web-plugin 0.0.9 → 0.0.12
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/dist/index.d.ts +12 -19
- package/dist/spu-web-plugin.mjs +44388 -6
- package/package.json +1 -5
- package/src/axios.ts +1 -1
- package/src/components/common/index.ts +19 -0
- package/src/components/expandexp/export.vue +820 -0
- package/src/components/expandexp/icons/icon_csv.png +0 -0
- package/src/components/expandexp/icons/icon_excel.png +0 -0
- package/src/components/expandexp/icons/icon_pdf.png +0 -0
- package/src/components/expandexp/icons/icon_zip.png +0 -0
- package/src/components/expandexp/index.ts +697 -0
- package/src/components/expandexp/step.ts +46 -0
- package/src/components/expandexp/template.ts +320 -0
- package/src/components/expandexp/util.ts +91 -0
- package/src/components/index.ts +7 -0
- package/src/components/loadding/index.ts +152 -0
- package/src/core.js +471 -0
- package/src/index.ts +8 -4
- package/src/install.ts +38 -12
- package/src/login.ts +27 -10
- package/src/oss/downloadService.ts +72 -9
- package/src/test.ts +23 -0
- package/src/types/global.d.ts +1 -1
- package/src/types/shims-lib.d.ts +2 -2
- /package/src/{loadding → components/loadding-vue3}/img/loading.gif +0 -0
- /package/src/{loadding → components/loadding-vue3}/index.ts +0 -0
- /package/src/{loadding → components/loadding-vue3}/index.vue +0 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export class Step {
|
|
2
|
+
statusMap: Array<string> = [
|
|
3
|
+
'initial',
|
|
4
|
+
'ready',
|
|
5
|
+
'running',
|
|
6
|
+
'ext_readyrun',
|
|
7
|
+
'ext_running',
|
|
8
|
+
'success',
|
|
9
|
+
'error',
|
|
10
|
+
'cancel'
|
|
11
|
+
]
|
|
12
|
+
statusTextMap: Array<string> = [
|
|
13
|
+
'',
|
|
14
|
+
'已加入导出队列,等待导出',
|
|
15
|
+
'文件下载中',
|
|
16
|
+
'图片处理中',
|
|
17
|
+
'图片处理中',
|
|
18
|
+
'导出完成',
|
|
19
|
+
'导出失败',
|
|
20
|
+
'任务已取消'
|
|
21
|
+
]
|
|
22
|
+
status = 0
|
|
23
|
+
statusName = 'initial'
|
|
24
|
+
statusText = ''
|
|
25
|
+
|
|
26
|
+
next () {
|
|
27
|
+
this.go(this.statusMap[this.status + 1])
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
go (statusName: string) {
|
|
31
|
+
const status = this.statusMap.findIndex((item) => {
|
|
32
|
+
return item === statusName
|
|
33
|
+
})
|
|
34
|
+
if (status < 0) {
|
|
35
|
+
console.error(`不存在 ${statusName} 状态`)
|
|
36
|
+
} else {
|
|
37
|
+
this.status = status
|
|
38
|
+
this.statusName = this.statusMap[this.status]
|
|
39
|
+
this.statusText = this.statusTextMap[this.status]
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
current () {
|
|
44
|
+
return this.statusName
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
import SpuExpandexp from './index'
|
|
2
|
+
|
|
3
|
+
export default (ele: SpuExpandexp) => {
|
|
4
|
+
return `
|
|
5
|
+
<style>
|
|
6
|
+
:host {
|
|
7
|
+
display: block;
|
|
8
|
+
width: 100%;
|
|
9
|
+
height: 100%;
|
|
10
|
+
position: fixed;
|
|
11
|
+
top: 0;
|
|
12
|
+
left: 0px;
|
|
13
|
+
right: 0px;
|
|
14
|
+
bottom: 0px;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.hide {
|
|
18
|
+
display: none!important;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.spu-expandexp {
|
|
22
|
+
width: 100%;
|
|
23
|
+
height: 100%;
|
|
24
|
+
background-color: rgba(0, 0, 0, 0.5);
|
|
25
|
+
overflow: auto;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
.modal {
|
|
32
|
+
width: 80%;
|
|
33
|
+
max-width: 800px;
|
|
34
|
+
min-width: 500px;
|
|
35
|
+
margin: 50px auto 0;
|
|
36
|
+
border-radius: 2px;
|
|
37
|
+
overflow: hidden;
|
|
38
|
+
}
|
|
39
|
+
.modal-th {
|
|
40
|
+
height: 40px;
|
|
41
|
+
background-color: #409eff;
|
|
42
|
+
}
|
|
43
|
+
.modal-th .title {
|
|
44
|
+
float: left;
|
|
45
|
+
line-height: 40px;
|
|
46
|
+
color: #fff;
|
|
47
|
+
font-size: 16px;
|
|
48
|
+
margin-left: 16px;
|
|
49
|
+
}
|
|
50
|
+
.modal-th .close {
|
|
51
|
+
float: right;
|
|
52
|
+
line-height: 40px;
|
|
53
|
+
height: 40px;
|
|
54
|
+
width: 40px;
|
|
55
|
+
color: #fff;
|
|
56
|
+
font-size: 16px;
|
|
57
|
+
text-align: center;
|
|
58
|
+
cursor: pointer;
|
|
59
|
+
}
|
|
60
|
+
.modal-tb {
|
|
61
|
+
padding: 16px;
|
|
62
|
+
background-color: #fff;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.export {}
|
|
66
|
+
.export-wait {
|
|
67
|
+
line-height: 32px;
|
|
68
|
+
height: 32px;
|
|
69
|
+
text-align: center;
|
|
70
|
+
background-color: rgba(255, 73, 73, .1);
|
|
71
|
+
color: #333;
|
|
72
|
+
}
|
|
73
|
+
.export-wait span {
|
|
74
|
+
color: red;
|
|
75
|
+
margin: 0 4px;
|
|
76
|
+
}
|
|
77
|
+
.export-tit {
|
|
78
|
+
line-height: 32px;
|
|
79
|
+
height: 32px;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
.export-sel {
|
|
83
|
+
margin-bottom: 12px;
|
|
84
|
+
}
|
|
85
|
+
.export-sel-title {
|
|
86
|
+
margin-bottom: 12px;
|
|
87
|
+
}
|
|
88
|
+
.export-sel-con {
|
|
89
|
+
display: flex;
|
|
90
|
+
}
|
|
91
|
+
.export-sel-con-item {
|
|
92
|
+
display: flex;
|
|
93
|
+
align-items: center;
|
|
94
|
+
margin-right: 32px;
|
|
95
|
+
cursor: pointer;
|
|
96
|
+
}
|
|
97
|
+
.export-sel-con-item label {
|
|
98
|
+
font-size: 14px;
|
|
99
|
+
font-weight: bold;
|
|
100
|
+
cursor: pointer;
|
|
101
|
+
}
|
|
102
|
+
.export-sel-con-item input {
|
|
103
|
+
cursor: pointer;
|
|
104
|
+
margin: 4px;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
.export-section-wrap {}
|
|
108
|
+
.export-section {
|
|
109
|
+
border: 1px solid #ddd;
|
|
110
|
+
padding: 12px;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
.export-file {
|
|
114
|
+
height: 28px;
|
|
115
|
+
line-height: 28px;
|
|
116
|
+
display: flex;
|
|
117
|
+
justify-content: space-between;
|
|
118
|
+
// margin-bottom: 12px;
|
|
119
|
+
}
|
|
120
|
+
.export-file-l {
|
|
121
|
+
flex: 1;
|
|
122
|
+
display: flex;
|
|
123
|
+
}
|
|
124
|
+
.export-file-l img {
|
|
125
|
+
flex: none;
|
|
126
|
+
display: block;
|
|
127
|
+
height: 28px;
|
|
128
|
+
width: 28px;
|
|
129
|
+
margin-right: 4px;
|
|
130
|
+
}
|
|
131
|
+
.export-file-l-filename {
|
|
132
|
+
flex: 1;
|
|
133
|
+
}
|
|
134
|
+
.export-file-l-filesize {
|
|
135
|
+
flex: none;
|
|
136
|
+
}
|
|
137
|
+
.export-file-r {
|
|
138
|
+
display: flex;
|
|
139
|
+
width: 80px;
|
|
140
|
+
flex-direction: row-reverse;
|
|
141
|
+
}
|
|
142
|
+
.export-file-r-download {
|
|
143
|
+
line-height: 26px;
|
|
144
|
+
border-radius: 3px;
|
|
145
|
+
background-color: #67c23a;
|
|
146
|
+
border: 1px solid #67c23a;
|
|
147
|
+
color: #fff;
|
|
148
|
+
padding: 0 12px;
|
|
149
|
+
font-size: 14px;
|
|
150
|
+
cursor: pointer;
|
|
151
|
+
}
|
|
152
|
+
.export-file-r-download:hover {
|
|
153
|
+
background: #85ce61;
|
|
154
|
+
border-color: #85ce61;
|
|
155
|
+
}
|
|
156
|
+
.export-file-r-cancel {
|
|
157
|
+
line-height: 26px;
|
|
158
|
+
width: 26px;
|
|
159
|
+
border-radius: 14px;
|
|
160
|
+
color: #f56c6c;
|
|
161
|
+
background: #fef0f0;
|
|
162
|
+
border: 1px solid #fbc4c4;
|
|
163
|
+
text-align: center;
|
|
164
|
+
font-size: 14px;
|
|
165
|
+
cursor: pointer;
|
|
166
|
+
}
|
|
167
|
+
.export-file-r-cancel:hover {
|
|
168
|
+
background: #f56c6c;
|
|
169
|
+
border-color: #f56c6c;
|
|
170
|
+
color: #fff;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
.export-progress {
|
|
176
|
+
display: flex;
|
|
177
|
+
justify-content: center;
|
|
178
|
+
align-items: center;
|
|
179
|
+
height: 30px;
|
|
180
|
+
}
|
|
181
|
+
.export-progress-outer {
|
|
182
|
+
flex: 1;
|
|
183
|
+
height: 8px;
|
|
184
|
+
background-color: #EBEEF5;
|
|
185
|
+
overflow: hidden;
|
|
186
|
+
position: relative;
|
|
187
|
+
vertical-align: middle;
|
|
188
|
+
}
|
|
189
|
+
.export-progress-inner {
|
|
190
|
+
animation-duration: 3s;
|
|
191
|
+
height: 100%;
|
|
192
|
+
width: 0;
|
|
193
|
+
background-color: #417AE7;
|
|
194
|
+
-webkit-transition: width .6s ease;
|
|
195
|
+
transition: width .6s ease;
|
|
196
|
+
}
|
|
197
|
+
.export-progress-inner.error {
|
|
198
|
+
background: red;
|
|
199
|
+
}
|
|
200
|
+
.export-progress-inner.success {
|
|
201
|
+
background: #67C23A;
|
|
202
|
+
}
|
|
203
|
+
.export-progress-text {
|
|
204
|
+
flex: none;
|
|
205
|
+
width: 50px;
|
|
206
|
+
font-size: 14px;
|
|
207
|
+
line-height: 30px;
|
|
208
|
+
text-align: right;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
.export-result {
|
|
214
|
+
height: 28px;
|
|
215
|
+
line-height: 28px;
|
|
216
|
+
text-align: right;
|
|
217
|
+
font-size: 12px;
|
|
218
|
+
padding: 0px 8px;
|
|
219
|
+
}
|
|
220
|
+
.export-result.error {
|
|
221
|
+
background: #fdf1ef;
|
|
222
|
+
white-space: nowrap;
|
|
223
|
+
text-overflow: ellipsis;
|
|
224
|
+
overflow: hidden;
|
|
225
|
+
}
|
|
226
|
+
.export-result.success {
|
|
227
|
+
background: #e5f7f3;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
.export-tip {
|
|
232
|
+
height: 28px;
|
|
233
|
+
line-height: 28px;
|
|
234
|
+
margin-top: 8px;
|
|
235
|
+
font-size: 12px;
|
|
236
|
+
text-align: right;
|
|
237
|
+
color: #999;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
.export-btnwrap {
|
|
241
|
+
margin-top: 12px;
|
|
242
|
+
display: flex;
|
|
243
|
+
flex-direction: row-reverse;
|
|
244
|
+
}
|
|
245
|
+
.btn {
|
|
246
|
+
line-height: 38px;
|
|
247
|
+
line-height: 38px;
|
|
248
|
+
border: 1px solid #409eff;
|
|
249
|
+
background-color: #409eff;
|
|
250
|
+
border-radius: 5px;
|
|
251
|
+
color: #fff;
|
|
252
|
+
padding: 0 20px;
|
|
253
|
+
font-size: 16px;
|
|
254
|
+
cursor: pointer;
|
|
255
|
+
}
|
|
256
|
+
.btn:hover {
|
|
257
|
+
background: #66b1ff;
|
|
258
|
+
border-color: #66b1ff;
|
|
259
|
+
}
|
|
260
|
+
</style>
|
|
261
|
+
|
|
262
|
+
<div class="spu-expandexp">
|
|
263
|
+
<div class="modal">
|
|
264
|
+
<div class="modal-th">
|
|
265
|
+
<div class="title">
|
|
266
|
+
数据导出
|
|
267
|
+
</div>
|
|
268
|
+
<div class="close">
|
|
269
|
+
x
|
|
270
|
+
</div>
|
|
271
|
+
</div>
|
|
272
|
+
<div class="modal-tb">
|
|
273
|
+
<div class="export">
|
|
274
|
+
<div class="export-wait hide">
|
|
275
|
+
导出等待队列中:还有<span></span>位,请耐心稍等...
|
|
276
|
+
</div>
|
|
277
|
+
|
|
278
|
+
<div class="export-sel hide">
|
|
279
|
+
<div class="export-sel-title">请选择导出内容</div>
|
|
280
|
+
<div class="export-sel-con"></div>
|
|
281
|
+
</div>
|
|
282
|
+
|
|
283
|
+
<div class="export-section-wrap hide">
|
|
284
|
+
<div class="export-tit"></div>
|
|
285
|
+
<div class="export-section">
|
|
286
|
+
<div class="export-file">
|
|
287
|
+
<div class="export-file-l">
|
|
288
|
+
<img src="" class="hide" />
|
|
289
|
+
<span class="export-file-l-filename"></span>
|
|
290
|
+
<span class="export-file-l-filesize"></span>
|
|
291
|
+
</div>
|
|
292
|
+
<div class="export-file-r">
|
|
293
|
+
<div class="export-file-r-download hide">下载</div>
|
|
294
|
+
<div class="export-file-r-cancel hide">x</div>
|
|
295
|
+
</div>
|
|
296
|
+
</div>
|
|
297
|
+
|
|
298
|
+
<div class="export-progress">
|
|
299
|
+
<div class="export-progress-outer">
|
|
300
|
+
<div class="export-progress-inner"></div>
|
|
301
|
+
</div>
|
|
302
|
+
<div class="export-progress-text"></div>
|
|
303
|
+
</div>
|
|
304
|
+
|
|
305
|
+
<div class="export-result hide"></div>
|
|
306
|
+
|
|
307
|
+
<div class="export-tip hide">您可以随时关闭该弹框,之后在导入导出列表中查看结果。</div>
|
|
308
|
+
</div>
|
|
309
|
+
</div>
|
|
310
|
+
|
|
311
|
+
<div class="export-btnwrap">
|
|
312
|
+
<div class="btn">导出</div>
|
|
313
|
+
</div>
|
|
314
|
+
|
|
315
|
+
</div>
|
|
316
|
+
</div>
|
|
317
|
+
</div>
|
|
318
|
+
</div>
|
|
319
|
+
`
|
|
320
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
export const dealCostTime = (val: number) => {
|
|
2
|
+
// const $t = useI18n().t
|
|
3
|
+
// 1000 * 60 * 1 + 1000 *58 + 500 //1分58.5秒
|
|
4
|
+
// val = 1000 * 60 * 60 * 2 + 1000 * 60 * 1 + 1000 *58 + 500 // 两小时1分58.5秒
|
|
5
|
+
if (val < 1000) {
|
|
6
|
+
return '1' + '秒'
|
|
7
|
+
} else if (val >= 1000 && val < 1000 * 60) {
|
|
8
|
+
return `${(val / 1000).toFixed(2)}` + '秒'
|
|
9
|
+
} else if (val >= 1000 * 60 && val < 1000 * 60 * 60) {
|
|
10
|
+
// return `${moment
|
|
11
|
+
// .duration((val / (1000 * 60)).toFixed(2), 'minute')
|
|
12
|
+
// .locale('zh_CN')
|
|
13
|
+
// .humanize()}`
|
|
14
|
+
return Math.floor(val / (1000 * 60)) + '分' + Math.ceil((val % (1000 * 60)) / 1000) + '秒'
|
|
15
|
+
} else {
|
|
16
|
+
// return `${moment
|
|
17
|
+
// .duration((val / (1000 * 60 * 60)).toFixed(2), 'hour')
|
|
18
|
+
// .locale('zh_CN')
|
|
19
|
+
// .humanize()}`
|
|
20
|
+
return (
|
|
21
|
+
Math.floor(val / (1000 * 60 * 60)) +
|
|
22
|
+
'时' +
|
|
23
|
+
Math.floor((val % (1000 * 60 * 60)) / (1000 * 60)) +
|
|
24
|
+
'分' +
|
|
25
|
+
Math.ceil((val % (1000 * 60)) / 1000) +
|
|
26
|
+
'秒'
|
|
27
|
+
)
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export const fixFileName = (sheetname: string, type: string, exportcontent: string) => {
|
|
32
|
+
let fileName = sheetname && sheetname.replace('.xlsx', '').replace('.csv', '')
|
|
33
|
+
if (exportcontent === 'link') {
|
|
34
|
+
fileName = fileName + '.zip'
|
|
35
|
+
} else {
|
|
36
|
+
if (parseInt(type) === 1) {
|
|
37
|
+
fileName = fileName + '.xlsx'
|
|
38
|
+
} else if (parseInt(type) === 2) {
|
|
39
|
+
fileName = fileName + '.csv'
|
|
40
|
+
} else if (parseInt(type) === 3) {
|
|
41
|
+
fileName = fileName + '.pdf'
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return fileName
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export const dealResultMessage = (item: any) => {
|
|
48
|
+
if (!item.errorfileurl && !item.fatalerrormsg) {
|
|
49
|
+
// 成功
|
|
50
|
+
return `成功导出${item.exptotalitem}条数据,耗时${dealCostTime(+item.finishdate - +item.initdate)}`
|
|
51
|
+
} else if (item.fatalerrormsg) {
|
|
52
|
+
return `${item.fatalerrormsg}`
|
|
53
|
+
} else {
|
|
54
|
+
return `总计${item.exptotalitem}条数据,成功${item.expsuctotalitem}条,失败${
|
|
55
|
+
item.exptotalitem - item.expsuctotalitem
|
|
56
|
+
}条,耗时${dealCostTime(+item.finishdate - +item.initdate)}`
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export const sizeUnit = (val: number) => {
|
|
61
|
+
if (!val) {
|
|
62
|
+
return '0kb'
|
|
63
|
+
}
|
|
64
|
+
if (val < 1024) {
|
|
65
|
+
return `${val}b`
|
|
66
|
+
} else if (val >= 1024 && val < 1024 * 1024) {
|
|
67
|
+
return `${(val / 1024).toFixed(2)}kb`
|
|
68
|
+
} else {
|
|
69
|
+
return `${(val / (1024 * 1024)).toFixed(2)}mb`
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// 兼容 val 为数字如4000 或者 4kb
|
|
74
|
+
export const dealFileSize = (val: number | string): string => {
|
|
75
|
+
if (val === '' || val === null) {
|
|
76
|
+
return ''
|
|
77
|
+
} else if (val === 0 || val === '0') {
|
|
78
|
+
return '0kb'
|
|
79
|
+
} else if (Number(val)) {
|
|
80
|
+
val = Number(val)
|
|
81
|
+
if (val < 1024) {
|
|
82
|
+
return `${val}b`
|
|
83
|
+
} else if (val >= 1024 && val < 1024 * 1024) {
|
|
84
|
+
return `${(val / 1024).toFixed(2)}kb`
|
|
85
|
+
} else {
|
|
86
|
+
return `${(val / (1024 * 1024)).toFixed(2)}mb`
|
|
87
|
+
}
|
|
88
|
+
} else {
|
|
89
|
+
return val.toString()
|
|
90
|
+
}
|
|
91
|
+
}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
const styletext = `
|
|
2
|
+
:host {
|
|
3
|
+
width: 100%;
|
|
4
|
+
height: 100%;
|
|
5
|
+
position: fixed;
|
|
6
|
+
top: 0;
|
|
7
|
+
left: 0;
|
|
8
|
+
z-index: 10000;
|
|
9
|
+
background-color: rgba(255, 255, 255, 0.2);
|
|
10
|
+
}
|
|
11
|
+
:host .spu-loadding {
|
|
12
|
+
width: 100%;
|
|
13
|
+
height: 100%;
|
|
14
|
+
display: flex;
|
|
15
|
+
align-items: center;
|
|
16
|
+
justify-content: center;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
:host .spu-loadding-icon {
|
|
20
|
+
width: 24px;
|
|
21
|
+
height: 24px;
|
|
22
|
+
background-size: cover;
|
|
23
|
+
background-position: center center;
|
|
24
|
+
background-repeat: no-repeat;
|
|
25
|
+
background-image: url(data:image/gif;base64,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);
|
|
26
|
+
}
|
|
27
|
+
`
|
|
28
|
+
|
|
29
|
+
const template = `
|
|
30
|
+
<div class="spu-loadding">
|
|
31
|
+
<div class="spu-loadding-icon"></div>
|
|
32
|
+
</div>
|
|
33
|
+
`
|
|
34
|
+
|
|
35
|
+
export default class SpuLoadding extends HTMLElement {
|
|
36
|
+
|
|
37
|
+
static componentName: string = 'spu-loadding'
|
|
38
|
+
static register () {
|
|
39
|
+
if (!window.customElements.get(SpuLoadding.componentName)) {
|
|
40
|
+
window.customElements.define(SpuLoadding.componentName, SpuLoadding)
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
isuseshadow = true
|
|
45
|
+
// isuseshadow = false
|
|
46
|
+
shadow: ShadowRoot | null = null
|
|
47
|
+
constructor () {
|
|
48
|
+
super()
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// 当自定义元素第一次被连接到文档DOM时被调用。
|
|
52
|
+
connectedCallback () {
|
|
53
|
+
// console.log('connectedCallback')
|
|
54
|
+
const templateElem = document.createElement('template')
|
|
55
|
+
templateElem.innerHTML = template
|
|
56
|
+
const content = templateElem.content.cloneNode(true)
|
|
57
|
+
|
|
58
|
+
if (this.isuseshadow) {
|
|
59
|
+
this.shadow = this.attachShadow({ mode: 'open' })
|
|
60
|
+
this.shadow.append(content)
|
|
61
|
+
this.appendStyle()
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
// this.shadow.querySelector('.spu-loadding').addEventListener('click', () => {
|
|
65
|
+
// console.log(this)
|
|
66
|
+
// console.log(this.isuseshadow)
|
|
67
|
+
// console.log(this.shadow)
|
|
68
|
+
// })
|
|
69
|
+
// this.addEventListener('click', () => {
|
|
70
|
+
// console.log(this)
|
|
71
|
+
// console.log(this.isuseshadow)
|
|
72
|
+
// console.log(this.shadow)
|
|
73
|
+
// })
|
|
74
|
+
|
|
75
|
+
} else {
|
|
76
|
+
this.append(content)
|
|
77
|
+
this.appendStyle()
|
|
78
|
+
|
|
79
|
+
// this.addEventListener('click', () => {
|
|
80
|
+
// console.log(this)
|
|
81
|
+
// console.log(this.isuseshadow)
|
|
82
|
+
// console.log(this.shadow)
|
|
83
|
+
// })
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// 当组件从 DOM 文档移除后调用。
|
|
88
|
+
disconnectedCallback () {
|
|
89
|
+
// console.log('disconnectedCallback')
|
|
90
|
+
// setTimeout(() => {
|
|
91
|
+
// console.log(this)
|
|
92
|
+
// }, 100)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
createStyleEle () {
|
|
96
|
+
var styleElement = document.createElement('style')
|
|
97
|
+
styleElement.type = 'text/css'
|
|
98
|
+
styleElement.id = SpuLoadding.componentName
|
|
99
|
+
styleElement.innerHTML = styletext
|
|
100
|
+
return styleElement
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
appendStyle () {
|
|
104
|
+
if (this.isuseshadow) {
|
|
105
|
+
const style = this.createStyleEle()
|
|
106
|
+
this.shadow!.appendChild(style)
|
|
107
|
+
} else {
|
|
108
|
+
if (!document.getElementById(SpuLoadding.componentName)) {
|
|
109
|
+
const style = this.createStyleEle()
|
|
110
|
+
document.getElementsByTagName('head')[0].appendChild(style)
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
class Loadding {
|
|
119
|
+
count = 0
|
|
120
|
+
|
|
121
|
+
ele: null | HTMLElement = null
|
|
122
|
+
|
|
123
|
+
constructor () {
|
|
124
|
+
SpuLoadding.register()
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
open () {
|
|
128
|
+
this.count++
|
|
129
|
+
if (!this.ele) {
|
|
130
|
+
this.ele = document.createElement('spu-loadding')
|
|
131
|
+
// console.log(this.ele)
|
|
132
|
+
document.body.appendChild(this.ele)
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
close () {
|
|
137
|
+
this.count--
|
|
138
|
+
if (this.count <= 0) {
|
|
139
|
+
this.count = 0
|
|
140
|
+
if (this.ele) {
|
|
141
|
+
document.body.removeChild(this.ele)
|
|
142
|
+
this.ele = null
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const loadding = new Loadding()
|
|
149
|
+
|
|
150
|
+
export {
|
|
151
|
+
loadding
|
|
152
|
+
}
|