|
@@ -83,6 +83,7 @@
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
+import Speech from 'speak-tts'
|
|
|
import { EventBus } from 'data-room-ui/js/utils/eventBus'
|
|
|
import commonMixins from 'data-room-ui/js/mixins/commonMixins'
|
|
|
import paramsMixins from 'data-room-ui/js/mixins/paramsMixins'
|
|
@@ -117,8 +118,19 @@ export default {
|
|
|
top: '100%',
|
|
|
bottom: '-100%'
|
|
|
},
|
|
|
- isAnimate: true
|
|
|
+ isAnimate: true,
|
|
|
+ // 组件内部数据
|
|
|
+ innerData: null,
|
|
|
+ // 音频播放
|
|
|
+ aduio: null,
|
|
|
+ // 语音播报
|
|
|
+ speech: null,
|
|
|
+ // 语音播报定时器
|
|
|
+ speechTimer: null
|
|
|
}
|
|
|
+ },
|
|
|
+ computed: {
|
|
|
+
|
|
|
},
|
|
|
mixins: [paramsMixins, commonMixins],
|
|
|
mounted () {
|
|
@@ -131,20 +143,115 @@ export default {
|
|
|
EventBus.$on('startMarquee', () => {
|
|
|
this.isAnimate = true
|
|
|
})
|
|
|
+ document.addEventListener('visibilitychange', this.handleVisibilityChange)
|
|
|
},
|
|
|
beforeDestroy () {
|
|
|
EventBus.$off('stopMarquee')
|
|
|
EventBus.$off('startMarquee')
|
|
|
+ // 销毁语音播报定时器
|
|
|
+ if (this.speechTimer) {
|
|
|
+ clearInterval(this.speechTimer)
|
|
|
+ }
|
|
|
},
|
|
|
methods: {
|
|
|
- changeStyle () {
|
|
|
- },
|
|
|
dataFormatting (config, data) {
|
|
|
- // 文本数据配置原则:选择数据集则以后端返回的数据为主,否则以设置面板中标题设置为准
|
|
|
- if (config.dataSource.businessKey) {
|
|
|
- config.customize.title = data && data.data && data.data.length ? data.data[0][config.dataSource.metricField] : '暂无数据'
|
|
|
+ // 数据返回成功则赋值
|
|
|
+ if (data.success) {
|
|
|
+ data = data.data
|
|
|
+ // 获取到后端返回的数据,有则赋值
|
|
|
+ if (config.dataHandler) {
|
|
|
+ try {
|
|
|
+ // 此处函数处理data
|
|
|
+ eval(config.dataHandler)
|
|
|
+ } catch (e) {
|
|
|
+ console.error(e)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ config.option.data = data
|
|
|
+ config.customize.title = config.option.data[config.dataSource.dimensionField] || config.customize.title
|
|
|
+ this.innerData = config
|
|
|
+ // 语音播报
|
|
|
+ } else {
|
|
|
+ // 数据返回失败则赋前端的模拟数据
|
|
|
+ config.option.data = []
|
|
|
}
|
|
|
return config
|
|
|
+ },
|
|
|
+ // 语音播报
|
|
|
+ voiceBroadcast (config) {
|
|
|
+ if (this.innerData) {
|
|
|
+ if (config.customize.voiceBroadcast) {
|
|
|
+ if (this.innerData.dataSource.businessKey && this.innerData.option.data[this.innerData.dataSource.metricField]) {
|
|
|
+ // 如果aduio存在,先销毁这个实例,或者替换它的URL
|
|
|
+ if (this.aduio) {
|
|
|
+ this.aduio.pause()
|
|
|
+ this.aduio = null
|
|
|
+ }
|
|
|
+ this.aduio = new Audio()
|
|
|
+ this.aduio.src = this.innerData.option.data[this.innerData.dataSource.metricField]
|
|
|
+ this.aduio.play()
|
|
|
+ } else if (config.customize.title) {
|
|
|
+ this.speechBroadcast(config.customize.title)
|
|
|
+ // 根据配置的时间,定时播报,第一次播报后,再定时播报
|
|
|
+ this.speechBroadcast(config.customize.title)
|
|
|
+ if (config.customize.dur) {
|
|
|
+ this.speechTimer = setInterval(() => {
|
|
|
+ this.speechBroadcast(config.customize.title)
|
|
|
+ }, config.customize.dur * 1000)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (this.aduio) {
|
|
|
+ this.aduio.pause()
|
|
|
+ this.aduio = null
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (config.customize.voiceBroadcast) {
|
|
|
+ this.speech = new Speech()
|
|
|
+ if (config.customize.dur) {
|
|
|
+ this.speechBroadcast(config.customize.title)
|
|
|
+ this.speechTimer = setInterval(() => {
|
|
|
+ this.speechBroadcast(config.customize.title)
|
|
|
+ }, config.customize.dur * 1000)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 语音播报
|
|
|
+ speechBroadcast (text) {
|
|
|
+ if (this.speech.hasBrowserSupport()) {
|
|
|
+ this.speech.setLanguage('zh-CN')
|
|
|
+ this.speech.pitch = 1
|
|
|
+ this.speech.init()
|
|
|
+ this.speech.speak({ text: text })
|
|
|
+ } else {
|
|
|
+ this.$message({
|
|
|
+ message: '您的浏览器不支持语音播报',
|
|
|
+ type: 'warning'
|
|
|
+ })
|
|
|
+ }
|
|
|
+ },
|
|
|
+ changeStyle (config) {
|
|
|
+ this.voiceBroadcast(config)
|
|
|
+ },
|
|
|
+ // 监听页面是否可见
|
|
|
+ handleVisibilityChange () {
|
|
|
+ if (document.visibilityState === 'hidden') {
|
|
|
+ if (this.aduio) {
|
|
|
+ this.aduio.pause()
|
|
|
+ }
|
|
|
+ if (this.speech) {
|
|
|
+ this.speech.pause()
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (this.aduio) {
|
|
|
+ this.aduio.play()
|
|
|
+ }
|
|
|
+ if (this.speech) {
|
|
|
+ this.speech.resume()
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -154,14 +261,12 @@ export default {
|
|
|
.marquee-box {
|
|
|
width: 100%;
|
|
|
height: 100%;
|
|
|
- display: inline-block;
|
|
|
white-space: nowrap;
|
|
|
overflow: hidden;
|
|
|
|
|
|
.scroll-area {
|
|
|
width: 100%;
|
|
|
height: 100%;
|
|
|
- display: inline-block;
|
|
|
|
|
|
.marquee-container {
|
|
|
width: 100%;
|
|
@@ -169,7 +274,6 @@ export default {
|
|
|
display: flex;
|
|
|
|
|
|
.svg-container {
|
|
|
- display: inline-block;
|
|
|
width: 100%;
|
|
|
height: 100%;
|
|
|
}
|