开发完成全站搜索功能
This commit is contained in:
parent
4ff482bbbf
commit
e4b66175f9
@ -112,3 +112,11 @@ export const msgListApi = (data) => {
|
|||||||
export const saveMsg = (data) => {
|
export const saveMsg = (data) => {
|
||||||
return request.post('/web/saveMessage', data)
|
return request.post('/web/saveMessage', data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @function 全站搜索
|
||||||
|
* @param {string} text
|
||||||
|
**/
|
||||||
|
export const fullTextSearchApi = (params) => {
|
||||||
|
return request.get('/web/searchText', {params})
|
||||||
|
}
|
109
src/application/search-result.vue
Normal file
109
src/application/search-result.vue
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
<template>
|
||||||
|
<view class="pages">
|
||||||
|
<view
|
||||||
|
class="prod-item"
|
||||||
|
v-for="item in list"
|
||||||
|
:key="item.id"
|
||||||
|
@click="goDetails(item)"
|
||||||
|
>
|
||||||
|
<view class="cover">
|
||||||
|
<image :src="item.mainPic"></image>
|
||||||
|
</view>
|
||||||
|
<view class="title text-ellipsis">
|
||||||
|
{{item.title}}
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { onLoad, onReachBottom, onPullDownRefresh } from '@dcloudio/uni-app';
|
||||||
|
import { ref } from 'vue';
|
||||||
|
import { useI18n } from 'vue-i18n';
|
||||||
|
import { fullTextSearchApi } from '@/api/index.js';
|
||||||
|
|
||||||
|
const { t } = useI18n()
|
||||||
|
|
||||||
|
const total = ref(0)
|
||||||
|
const list = ref([])
|
||||||
|
const params = ref({
|
||||||
|
pageNum: 1,
|
||||||
|
pageSize: 10,
|
||||||
|
text: ''
|
||||||
|
})
|
||||||
|
const init = (isLoad) => {
|
||||||
|
if (isLoad) {
|
||||||
|
params.value.pageNum += 1
|
||||||
|
} else {
|
||||||
|
params.value.pageNum = 1
|
||||||
|
}
|
||||||
|
return fullTextSearchApi(params.value).then(({data:res}) => {
|
||||||
|
if (isLoad) {
|
||||||
|
list.value = [...list.value,...res.data.records]
|
||||||
|
} else {
|
||||||
|
list.value = res.data.records
|
||||||
|
}
|
||||||
|
total.value = res.data.total
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const routeMap = {
|
||||||
|
'news': 'article-details', // 文章栏目
|
||||||
|
'product': 'product-details' // 产品栏目
|
||||||
|
}
|
||||||
|
const goDetails = (row) => {
|
||||||
|
uni.navigateTo({
|
||||||
|
url: `/application/${routeMap[row.dataType]}?id=${row.id}`
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
onPullDownRefresh(async() => {
|
||||||
|
try {
|
||||||
|
await init()
|
||||||
|
} catch(err) {}
|
||||||
|
uni.stopPullDownRefresh()
|
||||||
|
})
|
||||||
|
|
||||||
|
onReachBottom(() => {
|
||||||
|
if(total.value === list.value.length) {
|
||||||
|
return uni.$showTost(t('common.Allloaded'))
|
||||||
|
}
|
||||||
|
init(true)
|
||||||
|
})
|
||||||
|
|
||||||
|
onLoad((options) => {
|
||||||
|
params.value.text = options.str
|
||||||
|
init()
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
.pages {
|
||||||
|
padding: 20rpx;
|
||||||
|
.prod-item {
|
||||||
|
width: 100%;
|
||||||
|
height: 240rpx;
|
||||||
|
display: flex;
|
||||||
|
padding: 18rpx 0;
|
||||||
|
border-bottom: 1rpx solid #eeeeee;
|
||||||
|
.cover {
|
||||||
|
width: 240rpx;
|
||||||
|
height: 100%;
|
||||||
|
border-radius: 15rpx;
|
||||||
|
overflow: hidden;
|
||||||
|
image {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
object-fit: cover;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.title {
|
||||||
|
flex: 1;
|
||||||
|
height: 99%;
|
||||||
|
padding-left: 34rpx;
|
||||||
|
color: #323437;
|
||||||
|
-webkit-line-clamp: 5;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
@ -51,7 +51,8 @@
|
|||||||
"sending": "sending",
|
"sending": "sending",
|
||||||
"Reset": "Reset",
|
"Reset": "Reset",
|
||||||
"Sure": "Sure",
|
"Sure": "Sure",
|
||||||
"Newdetail": "Newdetail"
|
"Newdetail": "Newdetail",
|
||||||
|
"Allloaded": "All loaded"
|
||||||
},
|
},
|
||||||
"menu": {
|
"menu": {
|
||||||
"Home": "Home",
|
"Home": "Home",
|
||||||
|
@ -51,7 +51,8 @@
|
|||||||
"sending": "发送",
|
"sending": "发送",
|
||||||
"Reset": "重置",
|
"Reset": "重置",
|
||||||
"Sure": "确认",
|
"Sure": "确认",
|
||||||
"Newdetail": "文章详情"
|
"Newdetail": "文章详情",
|
||||||
|
"Allloaded": "已全部加载"
|
||||||
},
|
},
|
||||||
"menu": {
|
"menu": {
|
||||||
"Home": "首页",
|
"Home": "首页",
|
||||||
|
@ -68,6 +68,14 @@
|
|||||||
"enablePullDownRefresh": true,
|
"enablePullDownRefresh": true,
|
||||||
"navigationStyle": "default"
|
"navigationStyle": "default"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "search-result",
|
||||||
|
"style": {
|
||||||
|
"navigationBarTitleText": "Full text search",
|
||||||
|
"enablePullDownRefresh": true,
|
||||||
|
"navigationStyle": "default"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -160,7 +160,9 @@
|
|||||||
if (!searchVal.value) {
|
if (!searchVal.value) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
console.log(searchVal.value)
|
uni.navigateTo({
|
||||||
|
url: `/application/search-result?str=${searchVal.value}`
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const hotProductList = ref([])
|
const hotProductList = ref([])
|
||||||
|
Loading…
Reference in New Issue
Block a user