vue2+TS获取到数据后自动叫号写法

1.父组件写法

初始化:

//引入子组件  
<odialog ref="odialogRef" @onSure="onSurea"></odialog>
//子传父
  private onSurea() {
    // 初始化信息/重新叫号来的数据
    this.initTabelData()
    setTimeout(() => {
      // 播放声音的数据
      this.searchCallInfo()
    }, 2000)
  }




 activated() {
    // 初始化信息/重新叫号来的数据
    this.initTabelData()
    // 播放声音的数据
    this.searchCallInfo()
  }



// 一开始进入的时候激活一下,表格的数据
  private async initTabelData() {
    let res = await getCallInfo()
    this.tableData = res
    
  }


// 一开始进入的时候激活一下
  private async searchCallInfo() {
    try {
      //需要播报的文字数据
      let res = await getALLCallText()
      // 如果有数据
      if (res.data !== '') {
        clearTimeout(this.timer)
        // 打开弹窗播放数据
        ;(this.$refs.odialogRef as any).openDialog(res)
      } else {
        // 如果没有数据,5秒后获取一次表格所有数据
        this.timer = setTimeout(() => {
          this.initTabelData()
          console.log('(((((((((((((((((((((((((((((获取数据)))))))))))))))))))))))))))))')
          // 播放声音的数据
          this.searchCallInfo()
        }, 10000)
      }
    } catch (error) {
      this.$message({
        message: error,
        type: 'error'
      })
    }
  }

 2.子组件写法

template写法:

<template>
  <el-dialog :show-close="false" title="叫号显示" :visible.sync="customerDialogVisible" top="200px" width="40%" center :close-on-click-modal="false"
    destroy-on-close append-to-body>
    <div class="details">

      <div style="font-size:50px" @click="playVoice" id="playVoiceButton">{{carName}}</div>
      <div style="font-size:50px" @click="playVoice" id="playVoiceButton">{{detail}}</div>
      <!-- <div v-else>没有叫号数据!</div> -->
      <!-- <div style="font-size:50px" v-if="this.text==''">没有叫号数据!</div> -->
    </div>

  </el-dialog>

</template>

方法:

  // 车牌号
  private carName: string = ''

  // 鹤位地点
  private detail: string = ''

  //   dialog打开后携带需要播报的数据

private async openDialog(data) {
    this.callTextInfo = data
    // 截取文字
    let str = data.split(' ')
    this.detail = str[str.length - 1]
    this.carName = str[str.length - 3]
    this.customerDialogVisible = true
    await this.$nextTick()
    // 播放声音
    await this.playVoice()
  }


  //播放声音
  private async playVoice() {
    // 四秒后播放一次声音
    this.handleSpeak(this.callTextInfo)
    await setTimeout(() => {
      this.handleSpeak(this.callTextInfo)
    }, 4000)
    // 播放声音十秒后关闭
    await setTimeout(() => {
      this.customerDialogVisible = false
      this.onSure(null)
    }, 10000)
  }


  //刷新
  @Emit('onSure')
  private onSure(row: any) {}

 

3.全部写法:

//父组件:
<template>
  <div class="fullScreenBox">
    <!-- <el-button type="primary" v-if="fullScreenSwitch" @click="fullScreenFn">全 屏</el-button>
    <el-button type="primary" v-else @click="goBack">退 出</el-button> -->
    <xTable ref="xtable" :tableData="tableData" :tablePage="tablePage" :showSearchBox="false" :isShowPage="false" :showOperationBtn="true" :tableConfigure="tableConfigure" :showClearSearchInfoBtn="false">
      <template #optionBtns>
        <div class="operationBtnBox">
          <el-row>
            <el-button type="primary" v-if="fullScreenSwitch" @click="fullScreenFn">
              <div>
                <p style="color:#fff">全 屏</p>
              </div>
            </el-button>
            <el-button type="primary" v-else @click="goBack">
              <div>
                <p style="color:#fff">退 出</p>
              </div>
            </el-button>
          </el-row>
        </div>
      </template>
      <template v-slot:columns>
        <vxe-column type="seq" width="50px" align="center"></vxe-column>
        <vxe-column field="carNumber" title="车牌号" width="6.6%" align="center"></vxe-column>
        <vxe-column field="driverName" title="驾驶员姓名" width="6.6%" align="center"></vxe-column>
        <vxe-column field="pickUpNo" title="提货单号" width="6.6%" align="center"></vxe-column>
        <vxe-column field="createTime" title="入场时间" width="6.6%" align="center"></vxe-column>
        <vxe-column field="equDao" title="岛" width="6.6%" align="center"></vxe-column>
        <vxe-column field="equName" title="鹤位名称" width="6.6%" align="center"></vxe-column>
        <vxe-column field="state" title="状态" width="6.6%" align="center"></vxe-column>
      </template>
    </xTable>
    <odialog ref="odialogRef" @onSure="onSurea"></odialog>
  </div>
</template>

<script lang="ts">
import { Component, Prop, Vue, Emit, Watch } from 'vue-property-decorator'
import PageBase from '@src/views/PageBase'
import { Route } from 'vue-router'
import { getCallInfo, getALLCallText } from '../../../deliverPetroleum_apis/index_api'
import odialog from './opendialog.vue'
import dateRangePicker from '@src/components/TimePickr/dateRangePicker.vue'
import moment from 'moment'
import xTable from '@src/components/TableBase/baseTable.vue'
/***贮运厂总览 */
@Component({
  // previewDialog,
  components: { xTable, dateRangePicker, odialog },
  name: 'mapView'
})
export default class Index extends PageBase {
  mounted() {
    // this.time()
  }
  activated() {
    // 初始化信息/重新叫号来的数据
    this.initTabelData()
    // 播放声音的数据
    this.searchCallInfo()
  }
  private timer: any = null
  deactivated() {
    clearTimeout(this.timer)
  }
  // private async searchCallInfo() {
  //   try {
  //     let res = await getALLCallText()
  //     // 如果有数据
  //     if (res) {

  //       // clearTimeout(this.timer)

  //       // 打开弹窗播放数据
  //       ;(this.$refs.odialogRef as any).openDialog(res)
  //     } else {
  //       // // 如果没有数据,每隔十秒获取一次所有数据
  //       // this.timer = setTimeout(() => {
  //       //   this.initTabelData()
  //       //   // 播放声音的数据
  //       //   this.searchCallInfo()
  //       // }, 10000)
  //     }
  //   } catch (error) {
  //     this.$message({
  //       message: error,
  //       type: 'error'
  //     })
  //   }
  // }
  private fullScreenSwitch: boolean = true
  // 全屏
  private async fullScreenFn() {
    $('.fullScreenBox').css({ position: 'fixed', top: '0px', left: '0px' })
    this.fullScreenSwitch = !this.fullScreenSwitch
  }
  private async goBack() {
    $('.fullScreenBox').css({ position: 'relative' })
    this.fullScreenSwitch = !this.fullScreenSwitch
  }

  // 一开始进入的时候激活一下
  private async initTabelData() {
    let res = await getCallInfo()

    this.tableData = res
    // 处理一下状态
    this.tableData.forEach((item1) => {
      this.options.forEach((item2) => {
        if (item1.state == item2.value) {
          item1.state = item2.label
        }
      })
    })
  }

  // 一开始进入的时候激活一下
  private async searchCallInfo() {
    try {
      let res = await getALLCallText()
      // 如果有数据
      if (res.data !== '') {
        clearTimeout(this.timer)

        // 打开弹窗播放数据
        ;(this.$refs.odialogRef as any).openDialog(res)
      } else {
        // 如果没有数据,5秒后获取一次所有数据
        this.timer = setTimeout(() => {
          this.initTabelData()
          console.log('(((((((((((((((((((((((((((((获取数据)))))))))))))))))))))))))))))')
          // 播放声音的数据
          this.searchCallInfo()
        }, 10000)
      }
    } catch (error) {
      this.$message({
        message: error,
        type: 'error'
      })
    }
  }
  private tablePage: any = {
    total: 0,
    currentPage: 1,
    pageSize: 10
  }
  private onSurea() {
    // 初始化信息/重新叫号来的数据
    this.initTabelData()
    setTimeout(() => {
      // 播放声音的数据
      this.searchCallInfo()
    }, 2000)
  }
  private tableData: any[] = []
  private printName: string = ''
  private tableConfigure: any = {
    tableTitle: '叫号信息',
    imgSrc: 'queuing'
  }

  private queryCondition: any = {
    time: [
      moment(new Date()).format('YYYY-MM-DD HH:mm:ss'),
      moment(new Date())
        .add(1, 'days')
        .format('YYYY-MM-DD HH:mm:ss')
    ],
    carNumber: '',
    start: '全部'
  }
  private options: any[] = [
    {
      value: '全部',
      label: '全部'
    },
    {
      value: 2,
      label: '已入库'
    },
    {
      value: 0,
      label: '待呼叫'
    },
    {
      value: 1,
      label: '呼叫中'
    },
    {
      value: -1,
      label: '已取消'
    }
  ]

  //  初始化数据
}
</script>
<style lang="less" scoped>
/deep/.vxe-table--body-wrapper.body--wrapper {
  height: calc(95% - 0px);
}
/deep/span.span_button {
  cursor: pointer;
  text-decoration: underline;
  color: var(--lyl_addBtnAndLogoColor) !important;
}
/deep/.input-box.el-row {
  padding-left: 1%;
}
/deep/.table-box {
  height: calc(100% - 44px) !important;
}
/deep/.el-col.el-col-8 {
  padding-left: 20px;
}
.fullScreenBox {
  height: 100%;
  width: 100%;
}
</style>
//子组件
<template>
  <el-dialog :show-close="false" title="叫号显示" :visible.sync="customerDialogVisible" top="200px" width="40%" center :close-on-click-modal="false"
    destroy-on-close append-to-body>
    <div class="details">

      <div style="font-size:50px" @click="playVoice" id="playVoiceButton">{{carName}}</div>
      <div style="font-size:50px" @click="playVoice" id="playVoiceButton">{{detail}}</div>
      <!-- <div v-else>没有叫号数据!</div> -->
      <!-- <div style="font-size:50px" v-if="this.text==''">没有叫号数据!</div> -->
    </div>

  </el-dialog>

</template>
<script lang="ts">
import { Component, Prop, Vue, Emit, Watch } from 'vue-property-decorator'
import PageBase from '@src/views/PageBase'
import { Route } from 'vue-router'
import dialog from './dialog.vue'
import dateRangePicker from '@src/components/TimePickr/dateRangePicker.vue'
import moment from 'moment'
import xTable from '@src/components/TableBase/baseTable.vue'
// import { setInterval } from 'timers/promises'
const synth = window.speechSynthesis
const msg = new SpeechSynthesisUtterance()
/***贮运厂总览 */
@Component({
  // previewDialog,
  components: { xTable, dateRangePicker }
})
export default class Index extends PageBase {
  // dialog开关
  private customerDialogVisible: boolean = false
  mounted() {}
  // 车牌号
  private carName: string = ''
  // 鹤位地点
  private detail: string = ''
  // 呼叫文本信息
  private callTextInfo: string = ''
  //   dialog打开后携带需要播报的数据
  private async openDialog(data) {
    this.callTextInfo = data
    // 一打开弹窗获得的数据
    // await this.getALLCallText()
    // 截取文字
    let str = data.split(' ')
    this.detail = str[str.length - 1]
    this.carName = str[str.length - 3]
    this.customerDialogVisible = true
    await this.$nextTick()
    // 播放声音
    await this.playVoice()
  }

  //播放声音
  private async playVoice() {
    // 四秒后播放一次声音
    this.handleSpeak(this.callTextInfo)
    await setTimeout(() => {
      this.handleSpeak(this.callTextInfo)
    }, 4000)
    // 播放声音六秒后刷新显示数据,两秒后获取新的需要播放的数据
    await setTimeout(() => {
      this.customerDialogVisible = false
      this.onSure(null)
    }, 10000)
  }
  //刷新
  @Emit('onSure')
  private onSure(row: any) {}
  // 语音播报的函数
  private handleSpeak(text) {
    msg.text = text // 文字内容: 小朋友,你是否有很多问号
    msg.lang = 'zh-CN' // 使用的语言:中文
    msg.volume = 1 // 声音音量:1
    msg.rate = 1 // 语速:1
    msg.pitch = 1 // 音高:1
    synth.speak(msg) // 播放
  }
}
</script>
<style lang="less" scoped>
/deep/ .el-dialog--center .el-dialog__body {
  text-align: initial;
  padding: 25px 25px 30px;
  height: 30%;
}
.details {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}
</style>



本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/753254.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

elementUI搭建使用过程

前言 Element&#xff0c;一套为开发者、设计师和产品经理准备的基于 Vue 2.0 的桌面端组 件库 安装 ElementUI 在终端命令行输入 npm i element-ui -S 在 main.js 中写入以下内容&#xff1a; import ElementUI from element-ui ; import element-ui/lib/theme-chalk/i…

0-30 VDC 稳压电源,电流控制 0.002-3 A

怎么运行的 首先&#xff0c;有一个次级绕组额定值为 24 V/3 A 的降压电源变压器&#xff0c;连接在电路输入点的引脚 1 和 2 上。&#xff08;电源输出的质量将直接影响与变压器的质量成正比&#xff09;。变压器次级绕组的交流电压经四个二极管D1-D4组成的电桥整流。桥输出端…

北邮《计算机网络》蒋老师思考题及答案-传输层

蒋yj老师yyds&#xff01; 答案自制&#xff0c;仅供参考&#xff0c;欢迎质疑讨论 问题一览 传输层思考题P2P和E2E的区别使用socket的c/s模式通信&#xff0c;流控如何反映到编程模型三次握手解决什么问题举一个两次握手失败的例子为什么链路层是两次握手而非三次&#xff1f;…

深入理解 XML 和 HTML 之间的区别

在现代网络技术的世界中&#xff0c;XML&#xff08;可扩展标记语言&#xff09;和 HTML&#xff08;超文本标记语言&#xff09; 是两个非常重要的技术。尽管它们都使用标签和属性的格式来描述数据&#xff0c;但它们在形式和用途上有显著的区别。 概述 什么是 XML&#xff…

安装CLion配置opencv和torch环境

配置操作如图&#xff0c;源码见底部附录部分 安装CLion 官网下载 创建项目 设置环境 调整类型为release 配置opencv和项目 编译环境 编译后 重启CLion 测试opencv环境 测试代码 运行main.cpp显示图片 测试torch环境 没标红表示配置成功 附件 CMakeList.txt cmake_mi…

Redis集群部署合集

目录 一. 原理简述 二. 集群配置​​​​​​​ 2.1 环境准备 2.2 编译安装一个redis 2.3 创建集群 2.4 写入数据测试 实验一&#xff1a; 实验二&#xff1a; 实验三&#xff1a; 实验四&#xff1a; 添加节点 自动分配槽位 提升节点为master&#xff1a; 实验…

陪诊小程序开发:寻找陪诊师更加快速,全程陪护!

陪诊行业是一个新兴行业&#xff0c;在当下市场中具有较大的发展前景。对于无法陪家人看病或者对医院不熟悉的人来说&#xff0c;陪诊师成为了刚需&#xff01;目前随着社会的发展&#xff0c;人们的生活节奏不断加快&#xff0c;陪诊市场的需求量也在不断增加&#xff0c;发展…

web使用cordova打包Andriod

一.安装Gradel 1.下载地址 Gradle Distributions 2.配置环境 3.测试是否安装成功 在cmd gradle -v 二.创建vite项目 npm init vitelatest npm install vite build 三.创建cordova项目 1.全局安装cordova npm install -g cordova 2. 创建项目 cordova create cordova-app c…

30个接口自动化测试面试题,看完的现在已经在办理入职了...

1. 什么是接口自动化测试&#xff1f; 答&#xff1a;接口自动化测试是指使用自动化工具对接口进行测试&#xff0c;验证接口的正确性、稳定性和性能等方面的指标。 2. 为什么要进行接口自动化测试&#xff1f; 答&#xff1a;接口自动化测试可以提高测试效率&#xff0c;减…

ffmpeg将多个yuv文件编码为MP4视频文件

一、编码方案 在视频录制时&#xff0c;每一帧保存为一个yuv文件&#xff0c;便于纠错和修改。在编码为MP4文件时&#xff0c;我的方案是将所有yuv文件先转码为单个MP4文件&#xff0c;然后使用ffmpeg的concat功能拼接为完整的视频。 二、shell脚本 #!/bin/bash# 检查参数数量…

每日一道算法题 有效括号序列

题目 有效括号序列_牛客题霸_牛客网 (nowcoder.com) Python 1长度必须为偶数 2就像开心消消乐一样&#xff0c;一左一右就消掉。 class Solution:def isValid(self , s: str) -> bool:# write code here# flag[(),{},[]]# for _ in range(len(s)//2):# for i in fl…

RK35x8通过TFTP下载内核到开发板

对于有网线接口的RK35X8开发板&#xff0c;调试时候&#xff0c;可以通过网线下载内核镜像和设备树到开发板&#xff0c;不用每次修改驱动都要重新打开下载工具&#xff0c;进入下载模式。通过TFTP可以大大提高调试效率。 在ubuntu安装TFTP服务 安装tftp服务器 sudo apt-get…

多图示例:如何呈现论文结果中的各种图表

本文根据《Journal of the American College of Cardiology》上曾发表的一篇文章《Making Sense of Statistics in Clinical Trial Reports》&#xff0c;来全面而具体地说明临床试验论文中&#xff0c;各种类型数据与结果使用图表的正确展示方法。 本文将着重介绍基线数据、试…

桌面提醒工具哪个好?简单好用的便签提醒app推荐

在日常的生活和工作中&#xff0c;我们经常会遇到各种各样的事情&#xff0c;有时候可能会遗忘一些重要的事情。这个时候&#xff0c;一个简单好用的便签提醒工具就显得尤为重要了。那么&#xff0c;哪款桌面提醒工具比较好用呢&#xff1f;下面&#xff0c;就为大家推荐一款我…

【jdk】jdk11 jdk17 jdk21的新特性 虚拟线程创建方式

前言&#xff1a;按照博主的个人理解&#xff0c;一般来说 除了jdk8时代 说jdk8的新特性是特指jdk8这一个版本的特性&#xff0c;之后例如jdk11 jdk17新特性 都是泛特性 什么意思呢&#xff1f; 比如jdk11新特性&#xff0c;一般是指jdk9——jdk11 这一个泛版本的所有新特性&am…

某山词霸翻译js逆向分析

一、基础知识 1、post的几种发包的方式 2、query string和form data的区别 Query String Parameters&#xff1a; GET请求时&#xff0c;参数会以url string 的形式进行传递&#xff0c;即?后的字符串则为其请求参数&#xff0c;并以&作为分隔符。&#xff08;有时候pos…

稀疏迭代最近点算法(Sparse ICP)

2013年&#xff0c;2013年Sofien Bouaziz等提出了一种新的ICP改进算法&#xff0c;稀疏迭代最近点(Sparse Iterative Closest Point, Sparse ICP)算法。更多扩展资料可参看随书附赠资源中的说明文档。 Sparse ICP算法的设计的灵感、应用范围、优缺点和泛化能力 两个几何数据集…

vue 代理

一、常用的发送一个ajax请求&#xff1a; 1、xhr new XMLHttpRequest(),真正开发中不常用 2、jq&#xff0c;jq主要功能是获取dom&#xff0c;周边才是请求接口 3、axios&#xff08;大名鼎鼎的&#xff09; axios.get("url").then(response>{},error>{} )4、…

大数据组件--Hue

Apache Hue hue是一个集成化的大数据可视化软件&#xff0c;可以通过hue访问浏览操作主流的大数据生态圈软件。hue本身来自于cloudera后来贡献给了apachehue本身是一个web项目&#xff0c;基于python实现的&#xff0c;通过该web项目的UI集成了各个软件的UI 下面是一个hue调度…

远程桌面无法复制粘贴文件到本地怎么办?

远程桌面不能复制粘贴问题 Windows远程桌面为我们提供了随时随地访问文件和数据的便捷途径&#xff0c;大大提升了工作和生活的效率。然而&#xff0c;在使用过程中&#xff0c;我们也可能遇到一些问题。例如&#xff0c;在通过远程桌面传输文件时&#xff0c;常常会出现无法复…