搜索热词

This commit is contained in:
bb_pan 2025-02-28 10:40:52 +08:00
parent 4f7f4b658d
commit d755f2a60e
4 changed files with 82 additions and 5 deletions

6
package-lock.json generated
View File

@ -21,6 +21,7 @@
"file-saver": "^2.0.5", "file-saver": "^2.0.5",
"force": "^0.0.3", "force": "^0.0.3",
"js-base64": "^3.7.7", "js-base64": "^3.7.7",
"lodash": "^4.17.21",
"lodash-es": "^4.17.21", "lodash-es": "^4.17.21",
"mitt": "^3.0.1", "mitt": "^3.0.1",
"moment": "^2.29.4", "moment": "^2.29.4",
@ -3390,9 +3391,8 @@
}, },
"node_modules/lodash": { "node_modules/lodash": {
"version": "4.17.21", "version": "4.17.21",
"resolved": "https://repo.huaweicloud.com/repository/npm/lodash/-/lodash-4.17.21.tgz", "resolved": "https://registry.npmmirror.com/lodash/-/lodash-4.17.21.tgz",
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==", "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg=="
"license": "MIT"
}, },
"node_modules/lodash-es": { "node_modules/lodash-es": {
"version": "4.17.21", "version": "4.17.21",

View File

@ -28,6 +28,7 @@
"file-saver": "^2.0.5", "file-saver": "^2.0.5",
"force": "^0.0.3", "force": "^0.0.3",
"js-base64": "^3.7.7", "js-base64": "^3.7.7",
"lodash": "^4.17.21",
"lodash-es": "^4.17.21", "lodash-es": "^4.17.21",
"mitt": "^3.0.1", "mitt": "^3.0.1",
"moment": "^2.29.4", "moment": "^2.29.4",

View File

@ -37,3 +37,8 @@ export const apiGetCollect = (params = {}) => {
export const loginNewApi = (data: any) => { export const loginNewApi = (data: any) => {
return post('/auth/iwsLogin', data) return post('/auth/iwsLogin', data)
} }
// 热词查询
export const getHotSearch = (data: any) => {
return post('/material-mall/dev/list', data)
}

View File

@ -1,10 +1,16 @@
<script setup lang="ts"> <script setup lang="ts">
import { debounce } from 'lodash'
import $bus from '@/utils/bus' import $bus from '@/utils/bus'
import { mainStore } from 'store/main' import { mainStore } from 'store/main'
import { useStore } from 'store/user' import { useStore } from 'store/user'
import { cartStore } from 'store/cart' import { cartStore } from 'store/cart'
import { ElMessage, ElMessageBox } from 'element-plus' import { ElMessage, ElMessageBox } from 'element-plus'
import { getHotSearchListApi, getBookCarDetailsApi, getCompanyListApi } from 'http/api/home/index' import {
getHotSearchListApi,
getBookCarDetailsApi,
getCompanyListApi,
getHotSearch,
} from 'http/api/home/index'
import userClass from '../hooks/userClass' import userClass from '../hooks/userClass'
import { import {
getUserInfo, // getUserInfo, //
@ -387,6 +393,45 @@ const resetPhone = async () => {
}) })
} }
const hotWordList = ref<any[]>([])
//
const changeInputValue = debounce(async () => {
// console.log('🚀 ~ changeInputValue ~ keywordIptValue.value:', keywordIptValue.value)
if (!keywordIptValue.value) {
hotWordList.value = []
return
}
//
try {
const params = {
deviceName: keywordIptValue.value,
maStatus: 2,
}
const res: any = await getHotSearch(params)
// console.log('🚀 ~ changeInputValue ~ res:', res)
// 5
const arr = res.data.rows.filter((item: any, index: number, self: any) => {
return self.findIndex((e: any) => e.deviceName === item.deviceName) === index
})
if (res.data.rows && res.data.rows.length > 5) {
// deviceName
hotWordList.value = arr.slice(0, 5)
} else {
hotWordList.value = arr
}
// console.log('🚀 ~ changeInputValue ~ hotWordList.value:', hotWordList.value)
} catch (error) {
console.log('🚀 ~ changeInputValue ~ error:', error)
hotWordList.value = []
}
}, 500)
//
const onHotWord = (item: any) => {
// console.log('🚀 ~ onHotWord ~ e:', item.deviceName)
keywordIptValue.value = item.deviceName
}
onMounted(() => { onMounted(() => {
if (tokenNew) { if (tokenNew) {
getUserListData() getUserListData()
@ -427,7 +472,14 @@ onMounted(() => {
<div class="header-item" v-if="isShowLogout"> <div class="header-item" v-if="isShowLogout">
<a @click="onJumpMessage" v-if="!form.msgNum || form.msgNum == 0">消息</a> <a @click="onJumpMessage" v-if="!form.msgNum || form.msgNum == 0">消息</a>
<el-badge v-else :value="form.msgNum ? Number(form.msgNum) : ''" :max="99" @click="onJumpMessage" style="margin: 0 10px;">消息</el-badge> <el-badge
v-else
:value="form.msgNum ? Number(form.msgNum) : ''"
:max="99"
@click="onJumpMessage"
style="margin: 0 10px"
>消息</el-badge
>
<div class="line"></div> <div class="line"></div>
</div> </div>
<div class="header-item" v-if="isShowLogout"> <div class="header-item" v-if="isShowLogout">
@ -467,6 +519,7 @@ onMounted(() => {
placeholderText = placeholderText =
searchTypeName === '装备' ? '搜索装备关键词' : '搜索需求关键词' searchTypeName === '装备' ? '搜索装备关键词' : '搜索需求关键词'
" "
@input="changeInputValue"
/> />
<button class="search-btn" @click="searchKeywordBtn">搜索</button> <button class="search-btn" @click="searchKeywordBtn">搜索</button>
<div <div
@ -505,6 +558,17 @@ onMounted(() => {
需求 需求
</div> </div>
</div> </div>
<!-- 热词 -->
<div class="hot-word">
<span
v-for="(item, index) in hotWordList"
:key="index"
@click="onHotWord(item)"
style="margin-right: 10px; cursor: pointer"
>
{{ item.deviceName }}
</span>
</div>
</div> </div>
<div class="cart-container"> <div class="cart-container">
<div class="cart-icon" @click="onCarts"> <div class="cart-icon" @click="onCarts">
@ -758,6 +822,13 @@ onMounted(() => {
// width: 1000px; // width: 1000px;
// margin-left: 40px; // margin-left: 40px;
.hot-word {
margin: 15px 0 0 10%;
max-width: 80%;
display: flex;
flex-wrap: wrap;
}
.left-check-box { .left-check-box {
position: absolute; position: absolute;
left: 0; left: 0;