index.vue
14.4 KB
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
<template>
<Head title="音频上传 - 泡泡留声"/>
<a-layout style="height: 100vh;width: 100vw">
<a-layout-header class="header">
<div class="content">
<img class="logo" alt="logo" :src="logoSrc">
<div class="title">泡泡留声</div>
<img class="intro" alt="intro"
src="https://hising-cdn.hikoon.com/file/20231218/vxdqg9e0wum1702878136654ca1v3xg6w5d.png"/>
</div>
</a-layout-header>
<a-layout-content class="main">
<a-card ref="contentRef" :bordered="false" style="overflow: hidden;padding: 20px"
:body-style="{ display: 'flex',flexWarp:'nowrap',justifyContent:'center',padding:0,height:'65vh' }">
<a-upload ref="uploadRef" :accept="uploadAccept" class="left" response-url-key="url"
:auto-upload="true" :draggable="true" :show-file-list="false" :disabled="!!uploadFile"
:custom-request="uploadRequest" :on-before-upload="onBefore">
<template #upload-button>
<a-layout style="height: 100%;">
<a-layout-header class="top">
<div style="font-size: 20px;font-weight: bold">音频文件上传</div>
<div v-if="isUploadSuccess" style="margin-right: 1em">
<a-button type="primary" status="danger" @click.stop="onReUpload">继续上传
</a-button>
<a-button class="close-btn" type="primary" @click.stop="onClose">关闭</a-button>
</div>
</a-layout-header>
<a-layout-content class="middle">
<template v-if="isUploading">
<div style="font-size: 16px;margin-bottom: 1em;color: #4E5969;">
{{ floor(uploadFile?.percent || 0, 2) * 100 }}%
</div>
<a-progress style="width: 50%" :show-text="false" size="large"
:percent="uploadFile?.percent"/>
<div style="font-size: 16px;margin-top: 1em;color: #4E5969;">
文件上传中 ...
</div>
</template>
<template v-else-if="isUploadError">
<div style="display: flex;align-items: center">
<icon-exclamation-circle-fill style="color: #D62926" :size="25"/>
<div style="font-size: 16px;color: #666666;margin-left: 10px">
文件上传失败:网络连接超时
</div>
</div>
<div style="font-size: 14px;margin-top: 1em;color: #999999;">
您可以选择
<span class="action" @click="onRetry">重试</span>
或
<span class="action" @click.stop="onCancel">取消上传</span>
</div>
</template>
<template v-else-if="isUploadSuccess">
<div style="display: flex;align-items: center">
<icon-check-circle-fill style="color: #0a7350" :size="25"/>
<div style="font-size: 16px;color: #666666;margin-left: 10px">
文件成功
</div>
</div>
<div style="width: 52%;position: absolute;bottom: 40px;overflow: hidden">
<audio-tool :name="uploadFile?.name" :url="uploadFile?.url as string"/>
<div style="font-size: 14px;margin-top: 1em;color: #999999;">
如确认音频无误,请点击通过【扫码上传】,识别右侧二维码
</div>
</div>
</template>
<template v-else>
<img :width="80" :height="80" alt=""
src="https://hising-cdn.hikoon.com/file/20231218/e1v0latccea1702891747759kklfhqv7a1o.png"/>
<div style="font-size: 16px;margin-top: 1em;color: #4E5969;">
拖拽文件到框内,或点击
<span style="color: #D62926;border-bottom: 1px solid #D62926">上传</span>
</div>
</template>
</a-layout-content>
</a-layout>
</template>
</a-upload>
<div class="right">
<div class="info">
<div v-if="isUploadSuccess">
<vue-qr :size="150" :margin="5" :logo-margin="3" :logo-scale="0.2" :logo-src="logoSrc"
:text="uploadFileEncrypt" :correct-level="3"/>
<a-typography-paragraph type="secondary" style="margin-bottom: 0;margin-top: 10px">
<icon-check-circle-fill style="color: #0a7350"/>
请在应用中通过[扫码上传]识别
</a-typography-paragraph>
</div>
<div v-else>
<a-progress v-if="isUploading" size="medium" type="circle" :percent="uploadFile?.percent"
style="margin-bottom: 20px"/>
<a-typography-paragraph type="secondary">文件上传成功后</a-typography-paragraph>
<a-typography-paragraph style="margin-bottom: 0" type="secondary">
即可生成二维码
</a-typography-paragraph>
</div>
</div>
<a-typography>
<a-typography-title :heading="6">操作说明:</a-typography-title>
<a-typography-paragraph type="secondary">
1、将电脑上的【试唱音频】或【其它音频文件】通过网页上传,生成二维码
</a-typography-paragraph>
<a-typography-paragraph type="secondary">
2、在【泡泡留声】应用中点击【扫码上传】识别上方二维码即可
</a-typography-paragraph>
</a-typography>
<div class="customer">
<img alt="" :width="110" :height="110" :src="customerSrc"/>
<div>问题咨询及反馈,请联系客服</div>
</div>
</div>
</a-card>
</a-layout-content>
<a-layout-footer class="footer">
Copyright © 2023 北京海葵科技有限公司. All Rights Reserved.
<a class="link" href="https://beian.miit.gov.cn/" target="_blank">京ICP备 17046250号</a>
<a class="link" href="https://www.beian.gov.cn/portal/registerSystemInfo?recordcode=11011202000841"
target="_blank">
京公网安备 11011202000841号
</a>
</a-layout-footer>
</a-layout>
<login-modal :logo="logoSrc" :width="300"/>
</template>
<script lang="ts" setup>
import LoginModal from "@/page/upload/components/login-modal.vue";
import AudioTool from "@/page/upload/components/audio-tool.vue";
import {computed, ref} from "vue";
import {Head, usePage} from '@inertiajs/vue3'
import {useElementSize, useLocalStorage} from '@vueuse/core'
import {floor} from "lodash-es";
import OSS from "ali-oss";
import axios from "axios";
import {v4 as uuid4} from "uuid";
import {FileItem, Modal, RequestOption, Upload} from "@arco-design/web-vue";
import vueQr from 'vue-qr/src/packages/vue-qr.vue'
import {Base64} from "js-base64";
const {logoSrc, customerSrc, uploadAccept, ossConfig}: any = usePage().props
const contentRef = ref()
const {width: headWidth} = useElementSize(contentRef)
const uploadRef = ref<InstanceType<typeof Upload>>()
const uploadFile = ref<FileItem>()
const uploadHover = computed(() => uploadFile.value ? 'unset' : 'pointer')
const uploadClient = new OSS({
region: ossConfig.region,
bucket: ossConfig.bucket,
accessKeyId: ossConfig.accessKeyId,
accessKeySecret: ossConfig.accessKeySecret,
stsToken: ossConfig.stsToken,
refreshSTSTokenInterval: 3000000,
refreshSTSToken: async () => {
const {data} = await axios.post('/app/upload-sts-token')
return {accessKeyId: data.accessKeyId, accessKeySecret: data.accessKeySecret, stsToken: data.stsToken}
}
})
const isUploading = computed(() => uploadFile.value?.status === 'uploading')
const isUploadSuccess = computed(() => uploadFile.value?.status === 'done')
const isUploadError = computed(() => uploadFile.value?.status === 'error')
const uploadFileEncrypt = computed((): string =>
Base64.encode(JSON.stringify({type: 'uploadFile', data: uploadFile.value?.response})))
const token = useLocalStorage('token', '', {initOnMounted: false})
axios.interceptors.request.use((config) => {
config.headers.Authorization = token.value
return config;
})
axios.interceptors.response.use((response) => {
if (response.data.code === 401) {
token.value = ''
return Promise.reject(response.data)
}
return response.data;
})
const uploadRequest = (option: RequestOption) => {
const {onProgress, onError, onSuccess, fileItem} = option
uploadFile.value = fileItem
const fileDir = new Date().toISOString().slice(0, 10).replace(/-/g, '');
const fileType = fileItem.file?.name?.split('.')?.pop()?.toLowerCase();
uploadClient.multipartUpload(`audio/${fileDir}/${uuid4()}.${fileType}`, fileItem.file, {
progress: (p) => onProgress(Number(p.toFixed(2))),
parallel: 4, partSize: 2 * 1024 * 1024, mime: fileItem.file?.type
}).then(({name}) => onSuccess({
name: fileItem.name,
type: fileItem.file?.type,
size: fileItem.file?.size,
url: `${ossConfig.domain}/${name}`,
})).catch(e => onError(e))
return {}
}
const onBefore = (file: File) => {
if (file.size > 100 * 1024 * 1024) {
Modal.open({
title: '温馨提示',
content: '文件超过最大100M限制',
okText: '我知道了',
hideCancel: true, escToClose: false, maskClosable: false, closable: false,
})
return false;
}
return true;
}
const onCancel = () => {
uploadFile.value = undefined
}
const onRetry = () => {
uploadRef.value?.submit(uploadFile.value)
}
const onClose = () => Modal.open({
title: '温馨提示',
content: '确定关闭吗?',
escToClose: false, maskClosable: false, closable: false,
onOk: () => onCancel()
})
const onReUpload = () => Modal.open({
title: '温馨提示',
content: '已完成该文件上传,确定继续上传吗?',
escToClose: false, maskClosable: false, closable: false,
onOk: () => {
uploadRef.value?.$el?.querySelector('input').removeAttribute('disabled')
uploadRef.value?.$el?.querySelector('input').click()
}
})
</script>
<style scoped>
.header {
background-color: #1E1B29;
color: #ffffff;
padding: 0 20px;
z-index: 1;
.content {
display: flex;
align-items: center;
justify-content: flex-start;
height: 60px;
width: v-bind(headWidth+ 'px');
margin: auto;
.logo {
width: 32px;
height: 32px;
border-radius: 3px;
}
.title {
margin-left: 8px;
font-size: 15px;
font-weight: 600;
line-height: 18px;
}
.intro {
height: 15px;
margin-left: 15px;
}
}
}
.footer {
height: 60px;
background-color: #1E1B29;
color: #7F7F7F;
text-align: center;
font-size: 12px;
line-height: 60px;
z-index: 1;
.link {
text-decoration: none;
color: inherit;
}
}
.main {
display: flex;
justify-content: center;
align-items: center;
overflow: auto;
min-height: 540px;
.left {
width: 900px;
background-color: #FAFAFA;
cursor: v-bind(uploadHover);
.top {
height: 60px;
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 32px;
.close-btn {
margin-left: 1em;
background-color: #efefef;
color: #666666;
}
}
.middle {
display: flex;
flex-direction: column;
flex-wrap: nowrap;
align-content: center;
justify-content: center;
align-items: center;
padding-bottom: 60px;
.action {
color: #666666;
border-bottom: 1px solid #666666;
&:hover {
cursor: pointer;
}
}
}
}
.right {
margin-left: 20px;
height: 100%;
display: flex;
flex-direction: column;
justify-content: space-between;
.info {
width: 80%;
height: 215px;
border: 1px solid #bdc1c6;
text-align: center;
display: flex;
flex-direction: column;
flex-wrap: nowrap;
justify-content: center;
align-items: center;
}
.customer {
display: flex;
align-items: center;
:not(:first-child) {
margin-left: 14px;
}
}
}
}
</style>