热词部分代码

master
lemon橪 2022-04-25 09:18:31 +08:00
parent 0d09920314
commit 9b14cd633e
7 changed files with 488 additions and 136 deletions

View File

@ -439,11 +439,18 @@ export const setHotWords = (params) => {
}; };
// 删除热搜词 // 删除热搜词
export const deleteHotWords = (words) => { export const deleteHotWords = (params) => {
return deleteRequest(`/hotwords/hotwords/${words}`); return deleteRequest(`/hotwords/hotwords`,params);
}; };
// 获取热搜词 // 获取热搜词
export const getHotWords = () => { export const getHotWords = () => {
return getRequest(`/hotwords/hotwords`); return getRequest(`/hotwords/hotwords`);
}; };
// 获取热词统计
export const getHotWordsStatistics = (params) => {
return getRequest(`/hotwords/hotwords/statistics`,params);
};

View File

@ -21,6 +21,7 @@ const app = {
path: '', path: '',
name: 'home_index' name: 'home_index'
}], }],
hotWords:[], //今日热词数据
// 面包屑数组 左侧菜单 // 面包屑数组 左侧菜单
menuList: [], menuList: [],
tagsList: [...otherRouter.children], //这块是面包屑的内容不能删除 tagsList: [...otherRouter.children], //这块是面包屑的内容不能删除

View File

@ -1,154 +1,71 @@
<template> <template>
<div class="search"> <div class="search">
<Card> <Card>
<Row class="operation"> <Tabs @on-click="handleClickTab">
<Button @click="add()" type="primary">设置今日热词</Button> <TabPane
</Row> v-for="(item, index) in templatesWay"
<Row> :key="index"
<p> :name="item.template"
<Alert type="success"> :label="item.label"
这里展示今日系统中搜索前一百的搜索热词分数为热词在排序系统中的分数分数越高可以在用户获取热词时进行优先展示首页商品搜索栏下方推荐位分数可以填写负数会降低推荐度
</Alert>
</p>
</Row>
<div class="card-list">
<Card v-for="words in data" class="card-item" :key="words" onclick="">
<p>
<a href="#" slot="extra" @click.prevent="add(words)">{{ words }}</a>
</p>
<p slot="extra">
<a @click="deleteWords(words)">
<Icon type="md-close" />
</a>
</p>
</Card>
</div>
</Card>
<Modal :title="modalTitle" v-model="modalVisible" :mask-closable="false" :width="500">
<Form ref="form" :model="form" :label-width="100" :rules="formValidate">
<FormItem label="热词" prop="keywords">
<Input v-model="form.keywords" clearable style="width: 100%" />
</FormItem>
<FormItem label="分数" prop="point">
<Input v-model="form.point" clearable style="width: 100%" />
</FormItem>
</Form>
<div slot="footer">
<Button type="text" @click="modalVisible = false">取消</Button>
<Button type="primary" :loading="submitLoading" @click="handleSubmit"
>提交</Button
> >
</div> <components v-if="item.template == currentTemplate" :is="currentTemplate"></components>
</Modal> </TabPane>
</Tabs>
</Card>
</div> </div>
</template> </template>
<script> <script>
import { getHotWords, setHotWords, deleteHotWords } from "@/api/index"; import todayHotWords from "./template/todayHotWords";
import historyHotWords from "./template/historyHotWords";
import { regular } from "@/utils"; import setupHotWords from "./template/setupHotWords";
import statisticsHotWords from "./template/statisticsHotWords";
export default { export default {
name: "hotWords", name: "hotWords",
components: {}, components: {
todayHotWords,
historyHotWords,
setupHotWords,
statisticsHotWords
},
data() { data() {
return { return {
submitLoading: false, // key value
modalTitle: "", templatesWay: [
loading: true, // {
modalVisible: false, // template: "todayHotWords",
form: { label: "今日热次",
keywords: "", },
point: 0, {
}, template: "historyHotWords",
data: [], // label: "历史热词",
},
// {
formValidate: { template: "statisticsHotWords",
keywords: [regular.REQUIRED, regular.VARCHAR20], label: "热词统计",
point: [regular.REQUIRED, regular.NUMBER], },
{
template: "setupHotWords",
label: "设置热词",
},
],
//
templates: {
todayHotWords,
historyHotWords,
setupHotWords,
statisticsHotWords
}, },
//
currentTemplate: "todayHotWords",
}; };
}, },
methods: { methods: {
init() { handleClickTab(val) {
this.getDataList(); this.currentTemplate = val;
},
getDataList() {
this.loading = true;
getHotWords().then((res) => {
this.loading = false;
if (res.success) {
this.data = res.result;
}
});
this.loading = false;
},
handleSubmit() {
this.$refs.form.validate((valid) => {
if (valid) {
this.submitLoading = true;
setHotWords(this.form).then((res) => {
this.submitLoading = false;
if (res.success) {
this.$Message.success("操作成功");
this.getDataList();
this.modalVisible = false;
}
});
}
});
},
//
add(words) {
this.modalType = 0;
this.modalTitle = "设置热词";
if (words) {
this.form.keywords = words;
} else {
this.form.keywords = "";
}
this.form.point = 1;
this.modalVisible = true;
},
deleteWords(words) {
this.$Modal.confirm({
title: "是否确定删除热词",
content: "<p>您确定要删除此热词吗?</p>",
okText: "确实",
cancelText: "取消",
onOk: () => {
deleteHotWords(words).then((res) => {
if (res.success) {
this.$Message.success("删除成功");
this.getDataList();
}
});
},
});
}, },
}, },
mounted() {
this.init();
},
}; };
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped></style>
.card-list {
display: flex;
flex-wrap: wrap;
align-items: center;
}
.card-item {
min-width: 100px;
margin: 20px;
}
</style>
<style>
.ivu-card-extra{
right: 3px;
top:15px;
z-index: 99;
}
</style>

View File

@ -0,0 +1,135 @@
<template>
<div class="layout">
<Form
ref="formValidate"
:label-width="150"
label-position="right"
:model="formValidate"
:rules="ruleValidate"
>
<FormItem label="热词默认配置" prop="hotWordsSettingItems">
<div
class="item-label"
v-for="(item, index) in formValidate.hotWordsSettingItems"
:key="index"
>
<div>
<div class="item-keyword">
<div>热词</div>
<Input type="text" v-model="item.keywords"> </Input>
</div>
<div class="item-score">
<div>分数</div>
<InputNumber :max="5" :min="0" v-model="item.score"></InputNumber>
</div>
</div>
<div>
<Button type="primary" @click="formValidate.hotWordsSettingItems.splice(index,1)"></Button>
</div>
</div>
<Button @click="addSetItem"></Button>
</FormItem>
<FormItem label="每日保存数量" prop="saveNum">
<InputNumber :min="0" v-model="formValidate.saveNum" />
</FormItem>
<div class="label-btns">
<Button type="primary" @click="submit('formValidate')"></Button>
</div>
</Form>
</div>
</template>
<script>
import { setSetting, getSetting } from "@/api/index";
export default {
data() {
return {
ruleValidate: {}, //
formValidate: {
//
saveNum: 1, //
hotWordsSettingItems: [
{
keywords: "",
score: 1,
},
], //
},
};
},
created() {
this.init();
},
methods: {
//
addSetItem(val) {
if (this.formValidate.hotWordsSettingItems.length >= 5) {
this.$Message.error("最多5个热词项");
} else {
this.formValidate.hotWordsSettingItems.push({
keywords: "",
score: 1,
});
}
},
submit(name) {
this.$refs["formValidate"].validate(async (valid) => {
if (valid) {
this.setupSetting();
} else {
that.$Message.error("请正确填写内容!");
return flag;
}
});
},
//
setupSetting() {
setSetting("HOT_WORDS", this.formValidate).then((res) => {
if (res.success) {
this.$Message.success("保存成功!");
} else {
this.$Message.error("保存失败!");
}
this.init();
});
},
//
async init() {
const res = await getSetting("HOT_WORDS");
if (res.success) {
this.formValidate = res.result;
}
},
},
};
</script>
<style lang="scss" scoped>
.item-label {
border-bottom: 1px solid #ededed;
margin-bottom: 10px;
display: flex;
align-items: center;
width:500px;
justify-content:space-between;
}
/deep/ .ivu-input {
width: 100px !important;
}
.ivu-input-wrapper {
width: 300px;
margin-right: 10px;
}
.item-keyword,
.item-score {
display: flex;
align-items: center;
margin-bottom: 10px;
> div {
margin-right: 20px;
}
}
</style>

View File

@ -0,0 +1,130 @@
<template>
<div>
<div class="affix-time">
<Affix :offset-top="100">
<div class="flex affix-box">
<affixTime :closeShop="true" @selected="clickBreadcrumb" />
<Input
placeholder="关键词"
style="width: 100px; margin-left: 10px"
v-model="params.keyWords"
></Input>
<Button style="margin-left: 10px" @click="init"></Button>
</div>
</Affix>
</div>
<div v-if="!hotWords.length"></div>
<div v-else id="container"></div>
</div>
</template>
<script>
import { Chart } from "@antv/g2";
import { getHotWordsStatistics } from "@/api/index";
import affixTime from "@/views/lili-components/affix-time";
export default {
components: {
affixTime,
},
data() {
return {
params: {
//
searchType: "LAST_SEVEN",
year: "",
month: "",
keywords: "",
},
};
},
computed: {
hotWords() {
this.params.keyWords = this.$store.state.app.hotWords
? this.$store.state.app.hotWords[0]
: "";
return this.$store.state.app.hotWords
? this.$store.state.app.hotWords[0]
: "";
},
},
methods: {
clickBreadcrumb(val) {
console.log(val)
this.params = {...this.params,...val}
},
//
async init() {
const res = await getHotWordsStatistics(this.params);
if (res.success) {
}
},
handleClickSearch() {},
},
mounted() {
this.init();
const data = [
{ type: "未知", value: 654, percent: 0.02 },
{ type: "17 岁以下", value: 654, percent: 0.02 },
{ type: "18-24 岁", value: 4400, percent: 0.2 },
{ type: "25-29 岁", value: 5300, percent: 0.24 },
{ type: "30-39 岁", value: 6200, percent: 0.28 },
{ type: "40-49 岁", value: 3300, percent: 0.14 },
{ type: "50 岁以上", value: 1500, percent: 0.06 },
];
const chart = new Chart({
container: "container",
autoFit: true,
height: 500,
padding: [50, 20, 50, 20],
});
chart.data(data);
chart.scale("value", {
alias: "销售额(万)",
});
chart.axis("type", {
tickLine: {
alignTick: false,
},
});
chart.axis("value", false);
chart.tooltip({
showMarkers: false,
});
chart.interval().position("type*value");
chart.interaction("element-active");
//
data.forEach((item) => {
chart
.annotation()
.text({
position: [item.type, item.value],
content: item.value,
style: {
textAlign: "center",
},
offsetY: -30,
})
.text({
position: [item.type, item.value],
content: (item.percent * 100).toFixed(0) + "%",
style: {
textAlign: "center",
},
offsetY: -12,
});
});
chart.render();
},
};
</script>
<style lang="scss" scoped>
.affix-time {
padding-left: 15px;
}
</style>

View File

@ -0,0 +1,162 @@
<template>
<div>
<Row class="operation">
<Button @click="add()" type="primary">设置今日热词</Button>
</Row>
<Row>
<p>
<Alert type="success">
这里展示今日系统中搜索前一百的搜索热词分数为热词在排序系统中的分数分数越高可以在用户获取热词时进行优先展示首页商品搜索栏下方推荐位分数可以填写负数会降低推荐度
</Alert>
</p>
</Row>
<div class="card-list">
<Card v-for="words in data" class="card-item" :key="words" onclick="">
<p>
<a href="#" slot="extra" @click.prevent="add(words)">{{ words }}</a>
</p>
<p slot="extra">
<a @click="deleteWords(words)">
<Icon type="md-close" />
</a>
</p>
</Card>
</div>
<Modal
:title="modalTitle"
v-model="modalVisible"
:mask-closable="false"
:width="500"
>
<Form ref="form" :model="form" :label-width="100" :rules="formValidate">
<FormItem label="热词" prop="keywords">
<Input v-model="form.keywords" clearable style="width: 100%" />
</FormItem>
<FormItem label="分数" prop="point">
<InputNumber v-model="form.point" clearable style="width: 100%" />
</FormItem>
</Form>
<div slot="footer">
<Button type="text" @click="modalVisible = false">取消</Button>
<Button type="primary" :loading="submitLoading" @click="handleSubmit"
>提交</Button
>
</div>
</Modal>
</div>
</template>
<script>
import { getHotWords, setHotWords, deleteHotWords } from "@/api/index";
import { regular } from "@/utils";
export default {
name: "hotWords",
components: {},
data() {
return {
submitLoading: false,
modalTitle: "",
loading: true, //
modalVisible: false, //
form: {
keywords: "",
point: 0,
},
data: [], //
//
formValidate: {
keywords: [regular.REQUIRED, regular.VARCHAR20],
point: [regular.REQUIRED, regular.NUMBER],
},
};
},
methods: {
init() {
this.getDataList();
},
handleClickTab(val) {
console.log(val);
},
getDataList() {
this.loading = true;
getHotWords().then((res) => {
this.loading = false;
if (res.success) {
this.data = res.result;
this.$store.state.app.hotWords = this.data
}
});
this.loading = false;
},
handleSubmit() {
this.$refs.form.validate((valid) => {
if (valid) {
this.submitLoading = true;
setHotWords(this.form).then((res) => {
this.submitLoading = false;
if (res.success) {
this.$Message.success("操作成功");
this.getDataList();
this.modalVisible = false;
}
});
}
});
},
//
add(words) {
this.modalType = 0;
this.modalTitle = "设置热词";
if (words) {
this.form.keywords = words;
} else {
this.form.keywords = "";
}
this.form.point = 1;
this.modalVisible = true;
},
deleteWords(words) {
this.$Modal.confirm({
title: "是否确定删除热词",
content: "<p>您确定要删除此热词吗?</p>",
okText: "确实",
cancelText: "取消",
onOk: () => {
deleteHotWords({words}).then((res) => {
if (res.success) {
this.$Message.success("删除成功");
this.getDataList();
}
});
},
});
},
},
mounted() {
this.init();
},
};
</script>
<style lang="scss" scoped>
.card-list {
display: flex;
flex-wrap: wrap;
align-items: center;
}
.card-item {
min-width: 100px;
margin: 20px;
}
</style>
<style>
.ivu-card-extra {
right: 3px;
top: 15px;
z-index: 99;
}
</style>