fluency.vue
6.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
<!-- 流利度 -->
<template>
<div>
<div class="box">
<div class="box-item">
<div class="left">
<div class="title">语速</div>
<div class="value">{{ speedData.starText }}</div>
</div>
<div class="line"></div>
<div class="content-text">{{ speedData.starDescribe }}</div>
</div>
<div class="box-item">
<div class="left">
<div class="title">冗余词</div>
<div class="value">{{ wordsData.wordNum }}个</div>
</div>
<div class="line"></div>
<div class="content-text">{{ wordsData.resultWords }}</div>
</div>
</div>
<div class="chart-box">
<div class="wave-chart" id="wave-chart"></div>
<div class="pie-chart">
<div v-if="wordsData.wordNum > 0" class="pie-chart" id="pie-chart"></div>
<div class="empty-box" v-else>
<div class="icon">
<img src="@/assets/empty-3.png" />
</div>
<div class="text">
无冗余词
</div>
</div>
</div>
</div>
</div>
</template>
<script>
import chartOption from './chartOption'
import * as echarts from 'echarts'
import contantData from './contantData'
export default {
name: 'fluency',
props: {
itemData: {
type: Object,
default: () => ({})
}
},
data() {
return {
wordsData: {},
speedData: {}
}
},
mounted() {
this.initData()
},
methods: {
initData() {
this.filterWordsData()
this.filterSpeedData()
this.$nextTick(() => {
window.addEventListener("resize", () => this.resize())
})
},
resize() {
this.waveChart && this.waveChart.resize()
this.pieChart && this.pieChart.resize()
},
// 处理冗余词数据
filterWordsData() {
const toneWords = contantData.toneWords
const toneList = contantData.toneList
const {redundantWords} = this.itemData.fluency
let words = ''
try {
words = JSON.parse(redundantWords).content
} catch (error) {
}
const wordCountMap = new Map();
toneWords.forEach(word => {
const count = (words.match(new RegExp(word, 'g')) || []).length;
if(count>0) {
wordCountMap.set(word, count);
}
});
const positionX = [...wordCountMap.keys()]
const positionY = [...wordCountMap.values()];
const wordNum = positionY.reduce((cur, prev) => {
return cur + prev
}, 0)
let star = 5 - Math.ceil(wordNum / 2)
if (star < 1) {
star = 1
}
this.wordsData = {
wordNum,
resultWords: toneList[star - 1],
positionX,
positionY
}
if (wordNum > 0) this.initPieChart()
},
// 处理语速数据
filterSpeedData() {
const { speechSpeed } = this.itemData.fluency
let data = {}
try {
data = JSON.parse(speechSpeed)
} catch (error) {
}
this.speedData = {
starText: contantData.speedText[data?.star - 1],
starDescribe: contantData.speedDescribe[data?.star - 1],
x: data?.x,
y: data?.y,
min: data?.min,
max: data?.max
}
if (data?.x && data?.y) this.initWaveChart()
},
initWaveChart() {
this.$nextTick(() => {
this.waveChart = echarts.init(document.getElementById('wave-chart'))
chartOption.waveChartOption.xAxis.data = this.speedData.x
chartOption.waveChartOption.yAxis.max = this.speedData.max > Math.max(...this.speedData.y) ? this.speedData.max : Math.max(...this.speedData.y)
chartOption.waveChartOption.series[0].data = this.speedData.y
chartOption.waveChartOption.series[0].markArea.data = [
[{ xAxis: this.speedData.x[0], yAxis: this.speedData.min }, { xAxis: this.speedData.x[this.speedData.x.length - 1], yAxis: this.speedData.max }]
]
chartOption.waveChartOption.xAxis.axisLabel.formatter = (value, index) => {
if (index == 0 || index == this.speedData.x.length - 1) {
return value
} else {
return ''
}
}
this.waveChart.setOption(chartOption.waveChartOption)
})
},
initPieChart() {
this.$nextTick(() => {
let result = this.wordsData?.positionX.map((name, index) => {
let color = contantData.colorContentData.find((item) => item.name == name)?.color
return { name: name, value: this.wordsData?.positionY[index], itemStyle: {color: color} };
})
this.pieChart = echarts.init(document.getElementById('pie-chart'))
chartOption.pieChartOption.series[0].data = result
this.pieChart.setOption(chartOption.pieChartOption)
})
}
}
}
</script>
<style lang="scss" scoped>
.box{
display: flex;
.box-item{
flex: 1;
box-sizing: border-box;
height: 92px;
padding: 16px 20px;
margin-right: 16px;
display: flex;
align-items: center;
color: #333333;
background: #FBFBFB;
border-radius: 4px;
&:last-child{
margin: 0;
}
.left{
flex-shrink: 0;
width: 100px;
.title{
font-weight: 14px;
margin-bottom: 8px;
}
.value{
font-weight: 700;
font-size: 22px;
}
}
.line{
flex-shrink: 0;
width: 1px;
height: 44px;
background: #E5E5E5;
margin: 0 32px;
}
.content-text{
color: #999EA8;
font-size: 12px;
}
}
}
.chart-box{
height: 216px;
display: flex;
margin-top: 12px;
.wave-chart{
box-sizing: border-box;
height: 100%;
flex: 1;
margin-right: 16px;
padding: 8px 16px;
}
.pie-chart{
height: 100%;
flex: 1;
}
.empty-box {
display: flex;
flex-direction: column;
font-size: 12px;
color: #999999;
text-align: center;
width: 100%;
height: 100%;
box-sizing: border-box;
border-radius: 0 4px 4px 4px;
.icon {
width: 270px;
height: 120px;
margin: 0 auto 8px;
img {
width: 100%;
height: 100%;
}
}
}
}
</style>