Commit 04832f27 by 前端

录音上传

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