VoiceDialog.vue
10.1 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
<template>
<d2-dialog
title="上传音频"
:is-visible="visible"
width="70%"
@closeDialog="handleClose"
@confirmDialog="handleConfirm"
>
<div
class="voice-box"
v-loading="loading"
>
<el-form
ref="voiceForm"
:model="dataForm"
:rules="formRules"
label-width="154px"
size="small"
>
<el-form-item
label="门店:"
prop="storeMerchantNo"
>
<el-select
v-model="dataForm.storeMerchantNo"
class="form-select"
filterable
placeholder="请选择"
@change="chaneMerchant"
>
<el-option
v-for="(subItem, subIndex) in merchantList"
:key="subIndex"
:value="subItem.merchantId"
:label="subItem.merchantName"
></el-option>
</el-select>
</el-form-item>
<el-form-item
label="员工:"
prop="badgeId"
>
<el-select
v-model="dataForm.badgeId"
class="form-select"
filterable
placeholder="请选择"
:disabled="!dataForm.storeMerchantNo"
>
<el-option
v-for="(subItem, subIndex) in employeeList"
:key="subIndex"
:value="subItem.badgeId"
:label="subItem.employeeName"
></el-option>
</el-select>
</el-form-item>
<el-form-item
label="导入文件:"
prop="recordings"
>
<el-button
size="small"
class="import-button"
>
<i class="el-icon-plus"></i>
上传文件
<input
type="file"
ref="fileUpload"
multiple
class="import-input"
accept=".mp3,.aac,.m4a"
@change="importFile($event)"
/>
</el-button>
<template v-if="dataForm.recordings.length">
<div class="file-table">
<d2-table
ref="qualityTable"
:table-params="tableParams"
:tableData="dataForm.recordings"
:hasNum="false"
:hasPage="false"
>
<template
slot="recordingFilename"
slot-scope="scope"
>
<div class="file-name">
<img src="https://img02.glsx.com.cn/weapp/resource/dj-car-boutique-work-wechat/voice-file.png">
{{scope.scope.recordingFilename}}
</div>
</template>
<template
slot="recordingStartTime"
slot-scope="scope"
>
<el-date-picker
v-model="scope.scope.recordingStartTime"
type="datetime"
placeholder="请手动选择接待时间"
:picker-options="rangePickerOptions"
>
</el-date-picker>
</template>
<template
slot="auth-button-other"
slot-scope="scope"
>
<el-button
type="text"
@click="del(scope)"
>删除</el-button>
</template>
</d2-table>
</div>
</template>
</el-form-item>
</el-form>
</div>
</d2-dialog>
</template>
<script type='text/ecmascript-6'>
import { listShop4sByRef } from "@api/merchant"
import { getMerchantEmployeeList, updateRecordings, getAliOSSToken } from "@api/serviceManage"
import OSS from 'ali-oss'
import * as dayjs from 'dayjs'
import { rangePickerOptions } from "@/common/format"
import reportTrackFunMixin from '@/mixins/reportTrackFunMixin'
export default {
mixins: [reportTrackFunMixin],
name: 'VoiceDialog',
props: {
visible: Boolean
},
data () {
return {
rangePickerOptions,
client: null,
loading: false,
merchantList: [],
employeeList: [],
dataForm: {
storeMerchantNo: '',
badgeId: '',
recordings: []
},
formRules: {
storeMerchantNo: [{ required: true, message: '请选择门店', trigger: 'change' }],
badgeId: [{ required: true, message: '请选择员工', trigger: 'change' }],
recordings: [{
required: true, trigger: 'change',
validator: (rule, value, callback) => {
try {
if (!value.length) callback(new Error('请上传文件'))
else {
value.map(e => {
if (!e.recordingStartTime) throw '请选择接待开始时间'
})
}
callback()
} catch (error) {
callback(new Error(error))
}
},
}]
},
tableParams: {
tableOption: {
width: 60
},
tableColumns: [
{
label: '文件名',
addHtml: 'recordingFilename'
},
{
label: '接待开始时间',
addHtml: 'recordingStartTime',
},
]
},
}
},
watch: {
visible (n) {
if (n && !this.client) this.init()
}
},
mounted () {
this.getServiceStore()
},
methods: {
async init () {
try {
this.loading = true
const res = await getAliOSSToken()
if (res) this.client = new OSS({
// yourRegion填写Bucket所在地域。以华东1(杭州)为例,yourRegion填写为oss-cn-hangzhou。
region: 'oss-cn-shenzhen',
// 从STS服务获取的临时访问密钥(AccessKey ID和AccessKey Secret)。
accessKeyId: res.lsaccessKeyId,
accessKeySecret: res.lsaccessKeySecret,
stsToken: res.securityToken, // 从STS服务获取的安全令牌(SecurityToken)。
// 填写Bucket名称。
bucket: 'glsk-oss',
secure: true
})
else this.$message.error('获取阿里云配置失败!')
this.loading = false
} catch (error) {
this.loading = false
}
},
handleClose () {
this.loading = false
this.dataForm = this.$options.data.call(this).dataForm
this.$refs.voiceForm.resetFields()
this.$refs.fileUpload.value = ''
this.$emit('update:visible', false)
},
chaneMerchant (e) {
this.dataForm.badgeId = ''
this.employeeList = []
this.getMerchantEmployeeList(e)
},
del ({ index }) {
this.dataForm.recordings.splice(index, 1)
},
async importFile (event) {
try {
if (!this.client) {
this.$refs.fileUpload.value = ''
this.init()
return this.$message.error('请重试!')
}
const data = event.srcElement.files
console.log(data)
this.loading = true
for (let i = 0; i < data.length; i++) {
await this.putObject(data[i])
}
this.loading = false
this.$refs.fileUpload.value = ''
} catch (error) {
this.loading = false
this.$refs.fileUpload.value = ''
}
},
handleConfirm () {
this.$refs.voiceForm.validate(async (valid) => {
if (valid) {
try {
this.loading = true
const { badgeId, recordings } = this.dataForm
recordings.map(e => {
e.badgeId = badgeId
e.recordingStartTime = dayjs(e.recordingStartTime).format('YYYY-MM-DD HH:mm:ss')
})
this.setReportTrackData(0,'upload_audio',{recordings})
console.log(recordings)
const res = await updateRecordings({ recordings })
console.log(res)
if (res) {
this.$message.success('上传成功')
this.$emit('refresh')
this.handleClose()
this.loading = false
}
} catch (error) {
this.loading = false
this.$message.error(error)
}
}
})
},
getServiceStore () {
listShop4sByRef({
yqMerchantId: ''
}).then((res) => {
this.merchantList = res || []
console.log(res)
})
},
async getMerchantEmployeeList (storeMerchantNo) {
try {
this.loading = true
const res = await getMerchantEmployeeList({
storeMerchantNo
})
this.employeeList = res
this.loading = false
console.log(res)
} catch (error) {
this.loading = false
}
},
async putObject (data) {
let date = '',
[originalString] = data.name.split('.'),
[_day, _time] = originalString.split('_')
if (_day && _time) {
const rex = /^\d+$/
let year = originalString.slice(0, 4),
month = originalString.slice(4, 6),
day = originalString.slice(6, 8),
time = originalString.slice(9, 13)
if (rex.test(year) && rex.test(month) && rex.test(day) && rex.test(time)) date = `${year}-${month}-${day} ${time.slice(0, 2)}:${time.slice(2)}`
}
try {
const result = await this.client.put(`quality/${data.name}`, data)
console.log(result)
const { length } = this.dataForm.recordings
this.$set(this.dataForm.recordings, length, {
recordingFilename: data.name,
recordingStartTime: date,
recordingUrl: result.url
})
} catch (error) {
console.log(error)
this.init()
this.$message.error('上传失败')
}
}
}
}
</script>
<style scoped lang='scss'>
.form-select {
width: 432px;
}
.file-table {
margin-top: 6px;
}
.file-name {
display: flex;
align-items: center;
justify-content: center;
font-size: 14px;
color: #666666;
img {
width: 16px;
height: 16px;
margin-right: 6px;
}
}
.import-button {
position: relative;
.import-input {
position: absolute;
left: 0;
top: 0;
opacity: 0;
width: 100%;
height: 100%;
cursor: pointer;
}
}
</style>