tijian_tieying/web/德城公账号小程序/pages/inquiryList/inquiryList.js
2025-02-20 12:14:39 +08:00

289 lines
7.6 KiB
JavaScript

const recorderManager = wx.getRecorderManager()
const innerAudioContext = wx.createInnerAudioContext()
Page({
data: {
id:"",
name:"",
date: "2018-08-20",
RecordPause:"开始录音",
num:1,
tempFilePath:[],
fileSize:"",
filePhth:[],
status: "",
personName:""
},
//开始录音的时候
start: function () {
//点击后 变为暂停
if (this.data.status ==2){
if (this.data.num == 1) {
this.setData({
num: 2,
RecordPause: "暂停录音"
})
const options = {
duration: 540000,//指定录音的时长,单位 ms
sampleRate: 16000,//采样率
numberOfChannels: 1,//录音通道数
encodeBitRate: 24000,//编码码率
format: 'mp3',//音频格式,有效值 aac/mp3
frameSize: 50,//指定帧大小,单位 KB
}
//开始录音
recorderManager.start(options);
recorderManager.onStop((res) => {
this.data.tempFilePath.push(res.tempFilePath);
this.tempFilePath = res.tempFilePath;
console.log('停止录音', res.tempFilePath)
const { tempFilePath } = res
recorderManager.start(options);
console.log(this.data.tempFilePath)
});
//错误回调
recorderManager.onError((res) => {
console.log('停止录音', res.tempFilePath)
})
} else if (this.data.num == 2) { //点击后 变为继续
recorderManager.pause();
this.setData({
num: 3,
RecordPause: "继续录音"
})
} else if (this.data.num == 3) {
recorderManager.resume();
this.setData({
num: 2,
RecordPause: "暂停录音"
})
}
}
},
//停止录音
stop: function () {
recorderManager.stop();
recorderManager.onStop((res) => {
this.data.tempFilePath.push(res.tempFilePath);
this.tempFilePath = res.tempFilePath;
const { tempFilePath } = res;
console.log(this.data.tempFilePath);
this.setData({
num: 1,
RecordPause: "开始录音"
})
})
},
onLoad: function (options) {
var that = this
var queryBean = options.id;
var username = options.name;
var uname = options.username;
console.log(username)
that.setData({
id: queryBean,
name:username,
personName:uname
})
wx.authorize({
scope: 'scope.record',
success() {
console.log("录音授权成功");
that.setData({
status: 2,
})
// 用户已经同意小程序使用录音功能,后续调用 wx.startRecord 接口不会弹窗询问
// wx.startRecord();
},
fail() {
console.log("第一次录音授权失败");
wx.showModal({
title: '提示',
content: '您未授权录音,功能将无法使用',
showCancel: true,
confirmText: "授权",
confirmColor: "#52a2d8",
success: function (res) {
if (res.confirm) {
//确认则打开设置页面(重点)
wx.openSetting({
success: (res) => {
console.log(res.authSetting);
if (!res.authSetting['scope.record']) {
//未设置录音授权
console.log("未设置录音授权");
wx.showModal({
title: '提示',
content: '您未授权录音,功能将无法使用',
showCancel: false,
success: function (res) {
},
})
} else {
//第二次才成功授权
console.log("设置录音授权成功");
that.setData({
status: 2,
})
// recorderManager.start(options);
}
},
fail: function () {
console.log("授权设置录音失败");
}
})
} else if (res.cancel) {
console.log("cancel");
}
},
fail: function () {
console.log("openfail");
}
})
}
})
},
bindDateChange:function(e){
var that = this;
that.setData({
date:e.detail.value
})
},
formSubmit: function (e) {//定义函数名称
var that = this;
that.stop();
console.log(that.data.id)
var dataList = e.detail.value;
var t02_date = "";
for (var i in dataList){
if(i == "A03"){
var list = dataList[i];
dataList[i] = list.replace("-", "/").replace("-", "/");
console.log(dataList[i])
}
if (i == "T02b_year"){
t02_date += dataList[i] +"/";
}
if (i == "T02b_month") {
t02_date += dataList[i];
dataList["T02b"] = t02_date;
}
if (Array.isArray(dataList[i])){
var list ="";
for (var n = 0; n < dataList[i].length;n++){
if(n == dataList[i].length-1){
list += dataList[i][n];
}else{
list += dataList[i][n] + ";";
}
}
dataList[i] = list;
}
}
var dataLists = JSON.stringify(dataList);
console.log(dataLists)
var filePath = this.data.tempFilePath;
for (var a in filePath){
console.log(1+a);
wx.uploadFile({
url: "https://oa.dcqcdc.com/dccdc/Infection/SaveData_QuestionAnswer",//演示域名、自行配置
filePath: filePath[a],
name: 'file',
header: {
"Content-Type": "multipart/form-data"
},
formData:
{
id: that.data.id ,//附加信息为用户ID
username: that.data.name
},
success: function (res) {
console.log(res)
wx.showToast({
title: '上传成功',
icon: 'success',
duration: 2000
})
},
fail: function (res) {
wx.showToast({
title: '上传失败',
icon: 'success',
duration: 2000
})
},
complete: function (res) {
}
})
}
console.log(that.data.id)
wx.request({
url: 'https://oa.dcqcdc.com/dccdc/Infection/SaveData_QuestionAnswer',//请求地址
data: {
id: that.data.id,
json: dataLists,
username:that.data.name
},
header: {//请求头
"Content-Type": "application/x-www-form-urlencoded"
},
method: "POST",//get为默认方法/POST
success: function (res) {
console.log(res)
if (res.data == "保存成功!"){
wx.showToast({
title: '上传成功',
icon: 'success',
duration: 2000
})
wx.navigateTo({
url: '../inquiry/inquiry?name=' + that.data.name,
success: function (res) {
},
fail: function (res) {
},
complete: function (res) {
},
})
}
},
fail: function (err) { console.log(err) },//请求失败
complete: function () { }//请求完成后执行的函数
})
},
close: function () {
var that = this;
that.stop();
wx.navigateTo({
url: '../inquiry/inquiry?name='+that.data.name,
success: function (res) {
},
fail: function (res) {
},
complete: function (res) {
},
})
}
})