完善搜索

bak
Dragon 1 year ago
parent c2ed424995
commit acd318bcde

@ -1,43 +1,17 @@
<script setup lang="ts"> <script setup lang="ts">
import { reactive, ref, toRefs } from 'vue' import { reactive, ref, toRefs } from 'vue'
import { debounce, difference } from 'lodash-es' import { debounce } from 'lodash-es'
import { useRoute, useRouter } from 'vue-router'
import { deleteSearch, getSearchList, historySearch } from '@/api/search/search' import { deleteSearch, getSearchList, historySearch } from '@/api/search/search'
const emit = defineEmits(['close'])
const value = ref('') const value = ref('')
const showList = ref(false) const showList = ref(false)
const historyList: any = ref([]) const historyList: any = ref([])
const handlerShowList = () => (showList.value = true) const handlerShowList = () => (showList.value = true)
// const resultList = [ const router = useRouter()
// { const route = useRoute()
// title: '',
// data: [
// {
// title: '-1访',
// },
// {
// title: '-12访',
// },
// {
// title: '--访',
// },
// ],
// },
// {
// title: '',
// data: [
// {
// title: '-1访',
// },
// {
// title: '-12访',
// },
// {
// title: '-12访',
// },
// ],
// },
// ]
const state = reactive({ const state = reactive({
resultList: [], resultList: [],
}) as any }) as any
@ -55,13 +29,31 @@ async function handlerSearch(value) {
search: value, search: value,
}) })
if (res.code === 'OK') { if (res.code === 'OK') {
resultList.value = [{ state.resultList = [
title: 'AI工单管理', {
data: res.data, title: 'AI工单管理',
}] path: 'worksheet',
data: res.data.ai,
},
{
title: '任务审批管理',
path: 'task',
data: res.data.preliminary,
},
{
title: '任务终审管理',
path: 'final',
data: res.data.final,
},
]
} }
} }
function handlerHistory(name) {
value.value = name
handlerSearch(name)
}
// //
async function deleteHistory() { async function deleteHistory() {
const res = await deleteSearch({ const res = await deleteSearch({
@ -79,12 +71,14 @@ async function getHistory() {
} }
getHistory() getHistory()
function goTask() {} function goPath(item, id) {
router.push({ name: item.path, query: { id } })
emit('close')
}
function highlightText(text, query) { function highlightText(text, query) {
if (!query) if (!query)
return text return text
console.log(text)
const regex = new RegExp(query, 'gi') const regex = new RegExp(query, 'gi')
const highlightedText = text.replace(regex, (match) => { const highlightedText = text.replace(regex, (match) => {
return `<span style="color:#507AFD" class="highlight">${match}</span>` return `<span style="color:#507AFD" class="highlight">${match}</span>`
@ -123,7 +117,7 @@ function highlightText(text, query) {
</div> </div>
<div class="history-list flex"> <div class="history-list flex">
<div class="tag-wrap"> <div class="tag-wrap">
<div v-for="(item, index) of historyList" :key="index" class="tag"> <div v-for="(item, index) of historyList" :key="index" class="tag" @click="handlerHistory(item.historyname)">
{{ item.historyname }} {{ item.historyname }}
</div> </div>
</div> </div>
@ -139,10 +133,9 @@ function highlightText(text, query) {
<div class="list_title"> <div class="list_title">
{{ item.title }} {{ item.title }}
</div> </div>
<div v-for="(sitem, sindex) in item.data" :key="sindex" class="list_item" @click="goTask(sitem.id)"> <div v-for="(sitem, sindex) in item.data" :key="sindex" class="list_item" @click="goPath(item, sitem.id)">
<SvgIcon name="task-icon" size="16" /> <SvgIcon name="task-icon" size="16" />
<!-- <a style="margin-left: 5px">{{ sitem.name }}</a> --> <span class="name" v-html="highlightText(sitem.name, value)" />
<span style="margin-left: 5px" v-html="highlightText(sitem.name, value)" />
</div> </div>
</div> </div>
</div> </div>
@ -209,6 +202,11 @@ function highlightText(text, query) {
padding-bottom: 9px; padding-bottom: 9px;
} }
.name{
margin-left: 5px;
cursor: pointer;
}
.tag-wrap{ .tag-wrap{
display: flex; display: flex;
align-items: center; align-items: center;
@ -227,6 +225,7 @@ function highlightText(text, query) {
font-weight: Regular; font-weight: Regular;
text-align: left; text-align: left;
color: #666666; color: #666666;
cursor: pointer;
} }
} }

@ -15,7 +15,7 @@ defineExpose({
<template> <template>
<div> <div>
<n-modal v-model:show="show" :mask="false" transform-origin="center"> <n-modal v-model:show="show" :mask="false" transform-origin="center">
<Search /> <Search @close="show = false" />
</n-modal> </n-modal>
</div> </div>
</template> </template>

Loading…
Cancel
Save