提交 5939ac45 authored 作者: matian's avatar matian

Merge remote-tracking branch 'origin/vite' into vite

...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
v-if="isSetScoreRange" v-if="isSetScoreRange"
@close="isSetScoreRange = false" @close="isSetScoreRange = false"
@scoreRangeChange="scoreRangeChange" @scoreRangeChange="scoreRangeChange"
:recordScoreRange="recordScoreRange"
></set-score-range> ></set-score-range>
</div> </div>
</template> </template>
...@@ -26,6 +27,7 @@ export default { ...@@ -26,6 +27,7 @@ export default {
data() { data() {
return { return {
data: [], data: [],
recordScoreRange: [],
isSetScoreRange: false, isSetScoreRange: false,
option: { option: {
tooltip: { tooltip: {
...@@ -71,13 +73,16 @@ export default { ...@@ -71,13 +73,16 @@ export default {
} }
}, },
mounted() { mounted() {
this.scoreRangeChange([{ a: 0, b: 100 }]) this.scoreRangeChange()
}, },
methods: { methods: {
scoreRangeChange(data) { scoreRangeChange(data = {}) {
const { datas = [{ a: 0, b: 100 }], tags = [0, 100] } = data
const arr = [0, 10, 11, 12, 13, 20, 22, 24, 50, 50, 50, 21, 54, 100] const arr = [0, 10, 11, 12, 13, 20, 22, 24, 50, 50, 50, 21, 54, 100]
const colors = ['#6F85CC', '#96C080', '#EAC370', '#D96685', '#B170CE'] const colors = ['#6F85CC', '#96C080', '#EAC370', '#D96685', '#B170CE']
this.option.series[0].data = data.reduce((prev, cur, index) => { this.recordScoreRange = tags
// 组装echart数据
this.option.series[0].data = datas.reduce((prev, cur, index) => {
let count = 0 let count = 0
arr.forEach(i => { arr.forEach(i => {
if (i >= (i === 0 ? cur.a : cur.a + 1) && i <= cur.b) count++ if (i >= (i === 0 ? cur.a : cur.a + 1) && i <= cur.b) count++
...@@ -85,8 +90,10 @@ export default { ...@@ -85,8 +90,10 @@ export default {
prev.push({ value: count, name: `${cur.a}-${cur.b}`, itemStyle: colors[index] }) prev.push({ value: count, name: `${cur.a}-${cur.b}`, itemStyle: colors[index] })
return prev return prev
}, []) }, [])
// 渲染echart
const myChart = echarts.init(document.getElementById('score')) const myChart = echarts.init(document.getElementById('score'))
myChart.setOption(this.option) myChart.setOption(this.option)
// 关闭弹窗
this.isSetScoreRange = false this.isSetScoreRange = false
} }
} }
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
<div class="btn" @click="addTag">添加</div> <div class="btn" @click="addTag">添加</div>
</div> </div>
<div class="range-box"> <div class="range-box">
<template v-for="(item, index) in tagCount"> <template v-for="(item, index) in tags">
<div class="li-item" <div class="li-item"
:key="index" :key="index"
v-if="item != 0 && item != 100" v-if="item != 0 && item != 100"
...@@ -35,15 +35,19 @@ ...@@ -35,15 +35,19 @@
<script> <script>
export default { export default {
props: { props: {
recordScoreRange: { type: Array, default: () => [] }
}, },
data() { data() {
return { return {
tagInput: '', tagInput: '',
tagCount: [0, 100] tags: [0, 100]
} }
}, },
mounted() { mounted() {
}, },
created() {
this.tags = [...this.recordScoreRange]
},
methods: { methods: {
// 添加标签 // 添加标签
addTag() { addTag() {
...@@ -53,28 +57,29 @@ export default { ...@@ -53,28 +57,29 @@ export default {
this.$message('请填写正确分数段') this.$message('请填写正确分数段')
return false return false
} }
if (this.tagCount.length === 9) { if (this.tags.length === 9) {
this.$message('最多可添加8个') this.$message('最多可添加8个')
return false return false
} }
if (!this.tagCount.includes(value)) { if (!this.tags.includes(value)) {
this.tagCount.push(value) this.tags.push(value)
this.tagCount.sort((a, b) => a - b) this.tags.sort((a, b) => a - b)
this.tagInput = '' this.tagInput = ''
} }
console.log(this.recordScoreRange, '===123')
}, },
// 删除标签 // 删除标签
removeTag(index) { removeTag(index) {
this.tagCount.splice(index, 1) this.tags.splice(index, 1)
}, },
// 确认选择 // 确认选择
confirmTag() { confirmTag() {
const data = this.tagCount.reduce((prev, cur) => { const data = this.tags.reduce((prev, cur) => {
const findPrev = prev[prev.length - 1] const findPrev = prev[prev.length - 1]
if (cur !== 0) prev.push({ a: findPrev ? findPrev.b : 0, b: cur }) if (cur !== 0) prev.push({ a: findPrev ? findPrev.b : 0, b: cur })
return prev return prev
}, []) }, [])
this.$emit('scoreRangeChange', data) this.$emit('scoreRangeChange', { datas: data, tags: this.tags })
} }
} }
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论