click.js
3.2 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
/*
* @Author: 前端 qianduan01@didihu.com.cn
* @Date: 2024-04-08 11:28:48
* @LastEditors: 前端 qianduan01@didihu.com.cn
* @LastEditTime: 2024-04-09 13:36:48
* @FilePath: \gl_tape\mixin\click.js
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
const recorderManager = uni.getRecorderManager();
import upload from "@/utils/ossUploadFile/uploadFile.js";
import { mapMutations, mapState } from "vuex";
export default {
data() {
return {
voicePath: "",
timer: null,
times: 0,
timeout: 10 * 60,
reaction: 10,
message: "3",
};
},
mounted() {
this.initTime();
this.checkVoice();
},
computed: {
...mapState("audio", [
"isEnd",
"audioList",
"isStart",
"receptionEndTime",
"receptionStartTime",
]),
},
methods: {
...mapMutations("audio", ["setAudioStart", "setAudioList", "setAudioEnd"]),
//检查缓存录音
checkVoice() {
const file = uni.$storage.get("storageFile");
if (file) this.uploadVoice(file);
},
//保存录音记录及其他信息
async uploadVoice(tempFilePath) {
const { phone, merchantId, uuid, name } = uni.$storage.get("userInfo"),
params = {
carModel: "问界",
customerName: name,
phoneNumber: phone,
loginPhone: phone,
salesUuid: uuid,
recordUrlList: tempFilePath,
receptionStartTime: this.receptionEndTime,
receptionEndTime: this.receptionEndTime,
merchantId,
};
console.log(params, "params");
uni.$api.commonApi.saveRecCustomer(params).then((res) => {
console.log(res);
});
uni.$storage.set("storageFile", "");
},
//开始录音
startAudio() {
if (this.isStart) return;
this.setAudioStart(true);
this.setAudioList([]);
this.setAudioEnd(false);
recorderManager.start({
duration: 600000,
});
recorderManager.onStop(async (res) => {
if (!this.isEnd) {
recorderManager.start({
duration: 600000,
});
}
const result = await upload(res.tempFilePath);
const storageFile = [...this.audioList, result];
uni.$storage.set("storageFile", storageFile);
this.setAudioList(storageFile);
if (this.isEnd) this.uploadVoice(storageFile);
});
},
//结束录音
stopAudio() {
this.setAudioStart(false);
this.setAudioEnd(true);
recorderManager.stop();
},
//监听点击事件
initTime() {
this.timer = setInterval(() => {
this.times++;
if (this.times >= this.timeout) {
// this.showToast();
}
if (this.times >= this.reaction + this.timeout) {
this.handleEnd();
}
}, 1000);
},
handleTouchStart() {
this.times = 0;
},
handleVisibilityChange() {
this.message = 999;
if (document.visibilityState === "hidden") {
// 屏幕被关闭
this.message = 999;
}
},
},
beforeCreate() {
clearInterval(this.timer);
this.timer = null;
},
};