web/manager/src/views/page/article-manage/template/statisticsHotWords.vue

144 lines
3.1 KiB
Vue
Raw Normal View History

2022-04-25 09:18:31 +08:00
<template>
<div>
<div class="affix-time">
<Affix :offset-top="100">
<div class="flex affix-box">
<affixTime :closeShop="true" @selected="clickBreadcrumb" />
2022-04-25 18:09:49 +08:00
<InputNumber
placeholder="展示前N"
:max="200"
:min="10"
v-model="params.top"
></InputNumber>
<Button style="margin-left: 10px" @click="search">搜索</Button>
2022-04-25 09:18:31 +08:00
</div>
</Affix>
</div>
2022-08-11 10:32:26 +08:00
2022-04-25 18:09:49 +08:00
<div id="container"></div>
2022-08-11 10:32:26 +08:00
<Table border :columns="columns" :data="hotWordsData"></Table>
2022-04-25 09:18:31 +08:00
</div>
</template>
<script>
import { Chart } from "@antv/g2";
import { getHotWordsStatistics } from "@/api/index";
2022-09-02 17:51:33 +08:00
import affixTime from "@/components/affix-time";
2022-04-25 09:18:31 +08:00
export default {
components: {
affixTime,
},
data() {
return {
params: {
// 请求参数
searchType: "LAST_SEVEN",
year: "",
month: "",
top: 50,
2022-04-25 09:18:31 +08:00
},
columns: [
2022-08-11 10:32:26 +08:00
{
title: "热词名称",
key: "keywords",
},
{
title: "搜索次数",
key: "score",
},
],
hotWordsChart: "", //图表
hotWordsData: [], //数据
orderChart: "",
2022-04-25 09:18:31 +08:00
};
},
2022-04-25 18:09:49 +08:00
computed: {},
watch: {
params: {
handler(val) {
this.search();
},
deep: true,
immediate: true,
},
year(val) {
this.params.year = new Date(val).getFullYear();
},
},
2022-04-25 09:18:31 +08:00
methods: {
clickBreadcrumb(val) {
this.params = { ...this.params, ...val };
2022-04-25 09:18:31 +08:00
},
// 初始化图表
2022-04-25 18:09:49 +08:00
async search() {
2022-04-25 09:18:31 +08:00
const res = await getHotWordsStatistics(this.params);
if (res.success) {
this.hotWordsData = res.result;
if (!this.hotWordsChart) {
this.hotWordsChart = new Chart({
container: "container",
autoFit: true,
height: 500,
padding: [50, 20, 50, 20],
});
}
this.init();
2022-04-25 09:18:31 +08:00
}
},
handleClickSearch() {},
init() {
if (this.hotWordsChart) {
this.hotWordsChart.data(this.hotWordsData);
this.hotWordsChart.scale("score", {
alias: "搜索次数",
});
2022-04-25 18:09:49 +08:00
this.hotWordsChart.axis("keywords", {
tickLine: {
alignTick: false,
},
});
this.hotWordsChart.axis("score", false);
this.hotWordsChart.tooltip({
showMarkers: false,
});
this.hotWordsChart
.interval()
.position("keywords*score")
.color("#f59b99");
this.hotWordsChart.interaction("element-active");
2022-04-25 18:09:49 +08:00
// 添加文本标注
// this.hotWordsData.forEach((item) => {
// this.hotWordsChart
// .annotation()
// .text({
// position: [item.keywords, item.score],
// content: item.score,
// style: {
// textAlign: "center",
// },
// offsetY: -30,
// })
// });
this.hotWordsChart.render();
}
},
2022-04-25 09:18:31 +08:00
},
mounted() {
this.init();
},
};
</script>
<style lang="scss" scoped>
.affix-time {
padding-left: 15px;
}
</style>