语音播报

This commit is contained in:
2025-03-01 02:00:47 +08:00
parent 391f4d3c14
commit 1745293d05
20 changed files with 392 additions and 11 deletions

View File

@ -25,5 +25,6 @@ export default {
receive:(orderid)=>request.post(`/api/order/${orderid}/deliveryman/receive`),
pickup:(orderid)=>request.post(`/api/order/${orderid}/deliveryman/pickup`),
complete:(orderid,images)=>request.post(`/api/order/${orderid}/deliveryman/complete`,{images:images}),
cancel:(orderid,reason)=>request.post(`/api/order/${orderid}/deliveryman/cancel`,{reason})
cancel:(orderid,reason)=>request.post(`/api/order/${orderid}/deliveryman/cancel`,{reason}),
check:()=>request.get('/api/order/deliveryman/check_new_order')
}

View File

@ -53,5 +53,19 @@ export default {
task.onProgressUpdate(progress);
}
});
},
downloadFile(url,filePath){
return new Promise((rs,rj)=>{
wx.downloadFile({
url: url,
filePath: filePath,
success: (result) => {
rs()
},
fail: (res) => {
rj()
}
})
})
}
}

6
app.js
View File

@ -5,6 +5,9 @@ const date = new Date();
App({
verifyCodeWaitingTime:60,
onLaunch() {
wx.setInnerAudioOption({
obeyMuteSwitch:false
});
if(!token){
wx.reLaunch({
url: '/pages/login/index',
@ -16,6 +19,9 @@ App({
}
})
},
onHide(){
console.log('app on hide');
},
resetUserInfoUpdateTag(){
this.globalData.userInfoGetTime = null;
},

View File

@ -21,5 +21,8 @@
"style": "v2",
"componentFramework": "glass-easel",
"sitemapLocation": "sitemap.json",
"lazyCodeLoading": "requiredComponents"
"lazyCodeLoading": "requiredComponents",
"requiredBackgroundModes": [
"audio"
]
}

View File

@ -370,4 +370,25 @@ navigator button{
}
list-view{
display: block;
}
switch .wx-switch-input.wx-switch-input-checked {
background-color:var(--main-color);
border-color: var(--main-color);
}
switch .wx-switch-input::after {
width: 40rpx;
height: 40rpx;
}
.weui-loading{
font-size:16px;width:1em;height:1em;display:inline-block;vertical-align:middle;
background:transparent url("data:image/svg+xml,%3C%3Fxml version='1.0' encoding='UTF-8'%3F%3E%3Csvg width='80px' height='80px' viewBox='0 0 80 80' version='1.1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink'%3E%3Ctitle%3Eloading%3C/title%3E%3Cdefs%3E%3ClinearGradient x1='94.0869141%25' y1='0%25' x2='94.0869141%25' y2='90.559082%25' id='linearGradient-1'%3E%3Cstop stop-color='%23606060' stop-opacity='0' offset='0%25'%3E%3C/stop%3E%3Cstop stop-color='%23606060' stop-opacity='0.3' offset='100%25'%3E%3C/stop%3E%3C/linearGradient%3E%3ClinearGradient x1='100%25' y1='8.67370605%25' x2='100%25' y2='90.6286621%25' id='linearGradient-2'%3E%3Cstop stop-color='%23606060' offset='0%25'%3E%3C/stop%3E%3Cstop stop-color='%23606060' stop-opacity='0.3' offset='100%25'%3E%3C/stop%3E%3C/linearGradient%3E%3C/defs%3E%3Cg stroke='none' stroke-width='1' fill='none' fill-rule='evenodd' opacity='0.9'%3E%3Cg%3E%3Cpath d='M40,0 C62.09139,0 80,17.90861 80,40 C80,62.09139 62.09139,80 40,80 L40,73 C58.2253967,73 73,58.2253967 73,40 C73,21.7746033 58.2253967,7 40,7 L40,0 Z' fill='url(%23linearGradient-1)'%3E%3C/path%3E%3Cpath d='M40,0 L40,7 C21.7746033,7 7,21.7746033 7,40 C7,58.2253967 21.7746033,73 40,73 L40,80 C17.90861,80 0,62.09139 0,40 C0,17.90861 17.90861,0 40,0 Z' fill='url(%23linearGradient-2)'%3E%3C/path%3E%3Ccircle id='Oval' fill='%23606060' cx='40.5' cy='3.5' r='3.5'%3E%3C/circle%3E%3C/g%3E%3CanimateTransform attributeName='transform' begin='0s' dur='1s' type='rotate' values='0 40 40;360 40 40' repeatCount='indefinite'/%3E%3C/g%3E%3C/svg%3E%0A") no-repeat;
background-size:100%
}

Binary file not shown.

View File

@ -0,0 +1,114 @@
import userApi from '../../api/user';
Component({
/**
* 组件的属性列表
*/
properties: {
start:{
type:Boolean,
value:false
}
},
/**
* 组件的初始数据
*/
data: {
emptyAudio:'',
haveOrderAudio:'',
initing:true
},
lifetimes:{
attached(){
this.data.initing = true;
this.downloadResource().then(()=>{
this.bgam = wx.getBackgroundAudioManager();
this.bgam.title = '后台通知';
this.bgam.audioType = 'music';
this.bgam.coverImgUrl = 'https://dman-1311994147.cos.ap-chengdu.myqcloud.com/20250227/DoADoEhKi4U4ab75d180b27fa14b7c34ae7969762809_d7ee9018-828e-43c7-8b2b-29d4352c0277.jpg?imageMogr2/thumbnail/800x800/format/webp';
this.bgam.onEnded(()=>{
this.bgam.src = this.data.emptyAudio;
});
this.triggerEvent('initSuccess');
}).catch(()=>{
this.triggerEvent('initError');
})
}
},
observers:{
"start"(s){
if(s){
this.start();
}else{
this.stop();
}
}
},
/**
* 组件的方法列表
*/
methods: {
async downloadResource(){
this.data.emptyAudio = `${wx.env.USER_DATA_PATH}/empty.mp3`;
const emptyServerPath = 'https://dman-1311994147.cos.ap-chengdu.myqcloud.com/static/silence_file.wav';
this.data.haveOrderAudio = `${wx.env.USER_DATA_PATH}/haveorder.wav`;
const haveOrderPath = 'https://dman-1311994147.cos.ap-chengdu.myqcloud.com/static/new_order.mp3'
await this.download(this.data.emptyAudio,emptyServerPath);
await this.download(this.data.haveOrderAudio,haveOrderPath);
},
async download(localPath,serverPath){
try {
//判断文件是否存在
const fs = wx.getFileSystemManager();
fs.accessSync(localPath);
} catch (error) {
await userApi.downloadFile(serverPath,localPath);
}
},
start(){
this.bgam.src = this.data.emptyAudio;
if(this.loopOrderTimer){
clearInterval(this.loopOrderTimer);
}
this.loopOrderTimer = setInterval(()=>{
this.triggerEvent('onTrigger');
},10000);
},
stop(){
if(this.loopOrderTimer){
clearInterval(this.loopOrderTimer);
}
if(this.emptyAutioPlayTimer){
clearTimeout(this.emptyAutioPlayTimer)
}
if(this.bgam){
this.bgam.stop();
}
},
notice(){
if(this.emptyAutioPlayTimer){
clearTimeout(this.emptyAutioPlayTimer)
}
// this.bgam.src = this.data.haveOrderAudio;
// this.bgam.onEnded(()=>{
// console.log('notice onend');
// this.emptyAutioPlayTimer = setTimeout(()=>{
// this.bgam.src = this.data.emptyAudio;
// },1000)
// });
const innerAudioContext = wx.createInnerAudioContext({
useWebAudioImplement:true
})
innerAudioContext.src = this.data.haveOrderAudio;
innerAudioContext.play();
innerAudioContext.onEnded(()=>{
innerAudioContext.destroy();
})
}
}
})

View File

@ -0,0 +1,4 @@
{
"component": true,
"usingComponents": {}
}

View File

@ -0,0 +1,2 @@
<!--components/background-notice/index.wxml-->
<text>components/background-notice/index.wxml</text>

View File

@ -0,0 +1 @@
/* components/background-notice/index.wxss */

View File

@ -79,7 +79,6 @@ Component({
},
observers:{
"loading"(l){
console.log('loading',l);
if(!l){
this.setData({
moveViewX:0,

View File

@ -6,6 +6,7 @@ const app = getApp();
Page({
currentOrder:null,
haveNewOrder:false,
data: {
statusBarHeight:0,
snBarHeight:0,
@ -52,9 +53,19 @@ Page({
completing:false,
isShowRefundConfirm:false
isShowRefundConfirm:false,
isStartLoopOrder:false,
bgNoticeLoadResult:{
error:false,
loading:true
},
unReadOrderCount:0
},
onLoad(){
console.log(wx.env.USER_DATA_PATH);
this.orderBackgroundNotice = this.selectComponent('#orderBackgroundNotice');
const snHeight = getStatusNavBarHeight();
this.setData({
statusBarHeight:snHeight.statusBar,
@ -74,6 +85,52 @@ Page({
});
});
},
findNewOrder(){
// app.forceGetUserInfo().then((data)=>{
// if(data.nickname=='仙人模斗'){
// this.haveNewOrder = true;
// this.orderBackgroundNotice.notice();
// }
// })
// return;
orderApi.check().then((data)=>{
if(data.has_new_order){
this.orderBackgroundNotice.notice();
this.setData({
unReadOrderCount:this.data.unReadOrderCount+data.order_ids.length
})
}
})
},
bgNoticeSuccess(){
this.setData({
bgNoticeLoadResult:{
error:false,
loading:false
}
})
},
bgNoticeError(){
wx.showToast({
icon:'error',
title: '资源加载失败',
})
this.setData({
bgNoticeLoadResult:{
error:true,
loading:false
}
})
},
bgNoticeRetry(){
this.setData({
bgNoticeLoadResult:{
error:false,
loading:true
}
})
this.orderBackgroundNotice.downloadResource();
},
async getUserInfo(){
await app.forceGetUserInfo().then((data)=>{
this.setData({
@ -203,12 +260,16 @@ Page({
pItem.receivedAll = this.getPackageReceiveStatus(item.orderid,pItem);
})
})
this.setData({
let needSetData = {
list:this.data.list,
pager:this.data.pager,
statusDetailKey:this.data.statusDetailKey,
buildingIndex:this.data.buildingIndex
});
}
if(this.data.statusDetailKey==this.data.statusDetail.created.key.toLowerCase()){
needSetData.unReadOrderCount = 0;
}
this.setData(needSetData);
})
},
@ -384,7 +445,6 @@ Page({
})
return;
}
console.log(this.data.tempImgs);
this.setData({
completing:true
})
@ -469,6 +529,12 @@ Page({
})
this.setData(needRefreshData);
}
if(this.haveNewOrder){
this.data.statusDetailKey = this.data.statusDetail.created.key.toLowerCase();
this.data.buildingIndex = 0;
this.refreshList();
this.haveNewOrder = false;
}
},
getPackageReceiveStatus(orderId,pkg){
let receivedInfo = wx.getStorageSync(orderId);
@ -477,5 +543,10 @@ Page({
return true;
}
return false;
},
loopOrderChange(event){
this.setData({
isStartLoopOrder:event.detail.value
})
}
})

View File

@ -2,7 +2,8 @@
"usingComponents": {
"list-view":"/components/listView",
"swipe-button":"/components/swipeButton",
"modal-view":"/components/modalView"
"modal-view":"/components/modalView",
"background-notice":"/components/background-notice"
},
"navigationStyle": "custom",
"navigationBarTextStyle": "white"

View File

@ -3,15 +3,25 @@
<view style="height:{{statusBarHeight}}px" class="status-bar"></view>
<view class="nav-bar">
<image src="/assets/icon/left-panel-btn.png" class="left-btn" bind:tap="openLeftPanel"/>
<view class="community">
<!-- <view class="community">
<image class="icon" src="/assets/icon/community.png"/>
<label>{{userInfo.community_name}}</label>
</view> -->
<view class="loop-order-switch">
<label>语音播报</label>
<view class="weui-loading" wx:if="{{bgNoticeLoadResult.loading}}"></view>
<view class="retry" wx:elif="{{bgNoticeLoadResult.error}}" bind:tap="bgNoticeRetry">重试</view>
<switch wx:else class="switch" checked="{{isStartLoopOrder}}" bindchange="loopOrderChange"/>
</view>
</view>
<view class="head {{pager.loading?'loading':''}}">
<view class="item {{statusDetailKey==key?'current':''}}" wx:for="{{statusDetail}}"
wx:for-index="key" wx:key="key" bind:tap="setStatus" data-item="{{item}}">
<view class="red-bubble"
wx:if="{{item.key==statusDetail.created.key&&unReadOrderCount>0}}">
{{unReadOrderCount}}
</view>
{{item.text}}({{item.value}})
</view>
</view>
@ -182,4 +192,8 @@
</movable-area>
<modal-view titleText="取消订单需联系客户说明原因" editable content-placeholder="请输入退款原因" bind:ok="refund" show="{{isShowRefundConfirm}}" wx:if="{{isShowRefundConfirm}}" titleTextCenter="{{false}}" editRequired/>
<modal-view titleText="取消订单需联系客户说明原因" editable content-placeholder="请输入退款原因" bind:ok="refund" show="{{isShowRefundConfirm}}" wx:if="{{isShowRefundConfirm}}" titleTextCenter="{{false}}" editRequired/>
<background-notice bind:onTrigger="findNewOrder" id="orderBackgroundNotice"
start="{{isStartLoopOrder}}" bind:initSuccess="bgNoticeSuccess"
bind:initError="bgNoticeError"/>

View File

@ -8,6 +8,11 @@
display: flex;
align-items: center;
}
.nav-bar .retry{
text-decoration: underline;
color: rgb(250, 67, 67);
padding:14rpx;
}
.nav-bar .left-btn{
width:56rpx;
height:56rpx;
@ -26,6 +31,23 @@
width:20rpx;height:20rpx;
margin-right:8rpx;
}
.nav-bar .loop-order-switch{
background: rgba(255, 255, 255, 0.08);
border-radius: 40rpx;
color: #fff;
padding:4rpx 4rpx 4rpx 18rpx;
margin-left:24rpx;
display: flex;
align-items: center;
gap: 14rpx;
font-size: 28rpx;
}
.nav-bar .loop-order-switch .switch .wx-switch-input{
width:84rpx;
height: 48rpx;
--switch-checked-color:red;
--switch-node-size: 16rpx;
}
.head{
display: flex;
background-color: #111111;
@ -42,11 +64,20 @@
flex:1;
text-align: center;
padding:39rpx 0 19rpx 0;
position: relative;
}
.head .item.current{
color:#ffffff;
font-weight: 500;
}
.head .item .red-bubble{
position: absolute;
right:8rpx;top:20rpx;
background-color: red;
border-radius: 50%;
font-size: 24rpx;
padding:4rpx 8rpx;
}
.building{
display: flex;
overflow-x: auto;

94
pages/test/audio.js Normal file
View File

@ -0,0 +1,94 @@
// pages/test/audio.js
Page({
/**
* 页面的初始数据
*/
data: {
time:0
},
gbam:null,
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
this.bgam = wx.getBackgroundAudioManager();
this.bgam.src = 'https://dman-1311994147.cos.ap-chengdu.myqcloud.com/static/empty.mp3';
this.bgam.title = '后台通知';
this.bgam.audioType = 'music';
this.bgam.coverImgUrl = 'https://dman-1311994147.cos.ap-chengdu.myqcloud.com/20250227/DoADoEhKi4U4ab75d180b27fa14b7c34ae7969762809_d7ee9018-828e-43c7-8b2b-29d4352c0277.jpg?imageMogr2/thumbnail/800x800/format/webp';
this.bgam.play();
this.bgam.onPlay();
this.bgam.onEnded(()=>{
console.log('end');
// this.bgam.src = 'https://dman-1311994147.cos.ap-chengdu.myqcloud.com/static/empty.mp3';
// this.bgam.play();
})
// const innerAudioContext = wx.createInnerAudioContext({
// useWebAudioImplement:true
// })
// innerAudioContext.src = '/assets/audio/order_complete.wav';
// innerAudioContext.play();
},
playAudio(){
setInterval(()=>{
this.setData({
time:this.data.time+1
});
},1000);
setInterval(()=>{
this.bgam.src = 'https://dman-1311994147.cos.ap-chengdu.myqcloud.com/static/new_order.mp3';
this.bgam.play();
},10000)
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})

3
pages/test/audio.json Normal file
View File

@ -0,0 +1,3 @@
{
"usingComponents": {}
}

1
pages/test/audio.wxml Normal file
View File

@ -0,0 +1 @@
<button bind:tap="playAudio" type="primary">play({{time}})</button>

1
pages/test/audio.wxss Normal file
View File

@ -0,0 +1 @@
/* pages/test/audio.wxss */

View File

@ -1,7 +1,7 @@
<view class="custom-scroll-view">
<view class="total">
<view class="title">今日收益(元)</view>
<view class="num">{{summary.total_income}}</view>
<view class="num">{{summary.today_income}}</view>
</view>
<list-view bind:refresh="refreshList" bind:loadMore="loadList"
refresher-triggered="{{pager.refreshTrigger}}" class="income-list main"