Commit 04832f27 by 前端

录音上传

1 parent f3158552
......@@ -2,51 +2,61 @@
* @Author: 前端 qianduan01@didihu.com.cn
* @Date: 2024-04-08 11:28:48
* @LastEditors: 前端 qianduan01@didihu.com.cn
* @LastEditTime: 2024-04-08 13:47:00
* @LastEditTime: 2024-04-08 16:38:43
* @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";
export default {
data() {
return {
voicePath: "",
timer: null,
times: 0,
timeout: 10 * 60,
reaction: 10,
message: "3",
};
},
onShow() {
window.addEventListener("devicemotion", this.handleDeviceMotion);
},
onHide() {
window.removeEventListener("devicemotion", this.handleDeviceMotion);
},
// onShow() {
// window.addEventListener("devicemotion", this.handleDeviceMotion);
// },
// onHide() {
// window.removeEventListener("devicemotion", this.handleDeviceMotion);
// },
created() {
recorderManager.start();
this.initTime();
document.addEventListener("visibilitychange", this.handleVisibilityChange);
this.checkVoice();
recorderManager.onStop((res) => {
uni.$storage.set("storageFile", res.tempFilePath);
this.uploadVoice(res.tempFilePath);
});
},
methods: {
handleDeviceMotion(event) {
let acceleration = event.accelerationIncludingGravity;
let brightness =
Math.abs(acceleration.x) +
Math.abs(acceleration.y) +
Math.abs(acceleration.z);
if (brightness < 10) {
// 假设<10的值代表屏幕可能变暗了
console.log("屏幕可能熄灭了");
// 在这里执行你需要的操作
}
checkVoice() {
const file = uni.$storage.get("storageFile");
if (file) this.uploadVoice(file);
},
uploadVoice(tempFilePath) {
upload(tempFilePath).then((res) => {
uni.$storage.set("storageFile", "");
});
},
//开始录音
start() {
recorderManager.start();
},
//结束录音
pause() {
recorderManager.stop();
},
//监听点击事件
initTime() {
this.timer = setInterval(() => {
this.times++;
console.log(this.times);
if (this.times >= this.timeout) {
this.showToast();
// this.showToast();
}
if (this.times >= this.reaction + this.timeout) {
this.handleEnd();
......@@ -56,12 +66,13 @@ export default {
handleTouchStart() {
this.times = 0;
},
},
handleVisibilityChange() {
if (document.visibilityState === "hidden") {
// 屏幕被关闭
console.log("Screen closed");
}
handleVisibilityChange() {
this.message = 999;
if (document.visibilityState === "hidden") {
// 屏幕被关闭
this.message = 999;
}
},
},
beforeCreate() {
clearInterval(this.timer);
......
<template>
<view class="content">
<image class="logo" src="/static/logo.png"></image>
<view class="text-area">
<text class="title">
uView - 多平台快速开发的UI框架
</text>
</view>
<view class="button-demo">
<u-button type="primary" plain @click="go()">登录</u-button>
</view>
</view>
<view class="content">
<image class="logo" src="/static/logo.png"></image>
<view class="text-area">
<text class="title"> {{ voicePath }} </text>
</view>
<view class="button-demo">
<u-button type="primary" plain @click="start()">开始</u-button>
<u-button type="primary" plain @click="go()">登录</u-button>
</view>
</view>
</template>
<script>
export default {
data() {
return {
title: 'Hello',
}
},
onLoad() {
},
methods: {
go() {
this.$Router.push({name:'login'})
}
}
}
import myClick from "@/mixin/click";
export default {
mixins: [myClick],
data() {
return {
title: "Hello",
};
},
onLoad() {},
methods: {
go() {
uni.navigateTo({
url: "/pages/login/login",
success: function (res) {
// success
},
fail: function () {
// fail
},
complete: function () {
// complete
},
});
},
},
};
</script>
<style lang="scss" scoped>
.content {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 40rpx;
}
.content {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 40rpx;
}
.logo {
height: 200rpx;
width: 200rpx;
margin-top: 100rpx;
margin-left: auto;
margin-right: auto;
margin-bottom: 50rpx;
}
.logo {
height: 200rpx;
width: 200rpx;
margin-top: 100rpx;
margin-left: auto;
margin-right: auto;
margin-bottom: 50rpx;
}
.text-area {
display: flex;
justify-content: center;
}
.text-area {
display: flex;
justify-content: center;
}
.title {
font-size: 28rpx;
color: $u-content-color;
}
.title {
font-size: 28rpx;
color: $u-content-color;
}
.button-demo {
margin-top: 80rpx;
}
.button-demo {
margin-top: 80rpx;
}
</style>
// export const IMG_URL = 'https://img02.glsx.com.cn/weapp/resource/miniprogram/store-assistant/'
// import util from '~/utils/util'
export const IMG_URL = 'https://img02.glsx.com.cn/weapp/resource/app-tape/'
export const IMG_URL = "https://img02.glsx.com.cn/weapp/resource/app-tape/";
// 缓存get方法为空的默认指定值
export const DEFAULT_GET_STORAGEKEY = ['sessionId', 'merchantId', 'userInfo']
export const DEFAULT_GET_STORAGEKEY = ["sessionId", "merchantId", "userInfo"];
// 缓存get方法key的对应才映射值
export const STORAGE_OBJECTkEY = {
DEFAULT_GET_STORAGEKEY,
mock_data: 'mock_data'
}
mock_data: "mock_data",
storageFile: "storageFile",
};
// export const IMG_VERSION = async () => {
// const accountInfo = await util.getMockData()
// return accountInfo?.version || Date.now()
// }
\ No newline at end of file
// }
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!