refactor: 筛选搜索

bak
elseif 1 year ago
parent b31a82e8bd
commit 8a714f9076

@ -6,11 +6,14 @@ import type { FilterCondition, FilterParam, FilterSearchParam, FilterUpdate, Pag
* @param params * @param params
* @returns 1 * @returns 1
*/ */
export async function getConditionList(params: PageParam & FilterSearchParam): Promise<any> { export async function getConditionList(params: PageParam, searchParam: FilterSearchParam): Promise<any> {
const res = await http.request({ const res = await http.request({
url: `/ocr/ocrUsersearch/list`, url: `/ocr/ocrUsersearch/list?`,
method: 'get', method: 'get',
params, params: {
...params,
search_searchname: JSON.stringify(searchParam.search_searchname),
},
}) })
const { data: { records, pages } } = res const { data: { records, pages } } = res

@ -5,6 +5,7 @@ import { debounce } from 'lodash-es'
import { asideMap } from '@/config/aside' import { asideMap } from '@/config/aside'
import { favorite, getConditionList, unfavorite } from '@/api/home/filter' import { favorite, getConditionList, unfavorite } from '@/api/home/filter'
import type { Filter, FilterEntity } from '/#/home' import type { Filter, FilterEntity } from '/#/home'
import type { FilterSearchParam } from '/#/api'
defineOptions({ name: 'AdvanceFilter' }) defineOptions({ name: 'AdvanceFilter' })
@ -17,17 +18,17 @@ const emit = defineEmits<{
const data = ref<FilterEntity[]>([]) const data = ref<FilterEntity[]>([])
let loading = false let loading = false
let lastPostion = 0 const canloadMore = true
let canloadMore = true
const el = ref<HTMLDivElement | null>(null) const el = ref<HTMLDivElement | null>(null)
const popover = ref<ComponentRef | null>(null) const popover = ref<ComponentRef | null>(null)
const pagination = reactive({ const pagination = reactive({
pageNo: 1, pageNo: 1,
pageSize: 10, pageSize: 300,
}) })
const keyword = ref('')
onMounted(() => { onMounted(() => {
data.value = generateDefaultConfig() // data.value = generateDefaultConfig()
}) })
// //
@ -58,30 +59,29 @@ useInfiniteScroll(
() => { () => {
loadMore() loadMore()
}, },
{ distance: 10, interval: 3000, canLoadMore: () => canloadMore }, { distance: 10, interval: 300, canLoadMore: () => false },
) )
async function loadMore() { async function loadMore() {
if (loading || el.value == null) if (loading || el.value == null)
return return
lastPostion = el.value!.scrollTop
const more = await featchList() const more = await featchList()
if (more.length === 0) if (more.length === 0)
return return
data.value.push(...more) data.value.push(...more)
el.value?.scrollTo(0, lastPostion)
} }
async function featchList() { async function featchList() {
loading = true loading = true
try { try {
const result = await getConditionList({ ...pagination }) const searchParam: FilterSearchParam = { search_searchname: { value: keyword.value, op: 'like', type: 'string' } }
const { data, pageCount } = result const result = await getConditionList(pagination, searchParam)
pagination.pageNo += 1 const { data } = result
canloadMore = pageCount >= pagination.pageNo // pagination.pageNo += 1
// canloadMore = pageCount >= pagination.pageNo
const entityList = generateFilterEntityList(data) const entityList = generateFilterEntityList(data)
return entityList return entityList
} }
@ -124,8 +124,11 @@ function selectHandler(item: FilterEntity) {
emit('select', item.filterList) emit('select', item.filterList)
} }
const inputHandler = debounce((keyword) => { const inputHandler = debounce((word) => {
// keyword.value = word
featchList().then((list) => {
data.value = list
})
}, 300) }, 300)
function favoriteHandler(event: MouseEvent, item: any) { function favoriteHandler(event: MouseEvent, item: any) {

@ -15,19 +15,10 @@ const emit = defineEmits<{
const data = ref<SearchEntity[]>([]) const data = ref<SearchEntity[]>([])
const popover = ref<ComponentRef | null>(null) const popover = ref<ComponentRef | null>(null)
const configStore = useConfig() const configStore = useConfig()
let cacheData = [] const searchKeyword = ref('')
const inputHandler = debounce((keyword) => { const inputHandler = debounce((keyword) => {
if (keyword === '') { searchKeyword.value = keyword
data.value = cacheData
return
}
const result = data.value.filter((item) => {
return item.label.includes(keyword)
})
data.value = result
}, 300) }, 300)
configStore.$subscribe(() => { configStore.$subscribe(() => {
@ -48,7 +39,6 @@ configStore.$subscribe(() => {
}) })
data.value = list data.value = list
cacheData = list
}) })
function selectHandler(item: SearchEntity) { function selectHandler(item: SearchEntity) {
@ -72,7 +62,7 @@ function selectHandler(item: SearchEntity) {
</template> </template>
<div class="wrapper-popover"> <div class="wrapper-popover">
<ul class="wrapper-list"> <ul class="wrapper-list">
<li v-for="(item, index) in data" :key="index" @click="selectHandler(item)"> <li v-for="(item, index) in data" v-show="item.label.includes(searchKeyword)" :key="index" @click="selectHandler(item)">
{{ item.label }} {{ item.label }}
</li> </li>
</ul> </ul>

@ -8,7 +8,7 @@ import { useConfig } from '@/store/modules/asideConfig'
defineOptions({ name: 'CustomFilterModal' }) defineOptions({ name: 'CustomFilterModal' })
const show = ref(true) const show = ref(false)
const configStore = useConfig() const configStore = useConfig()
const checkAll = ref(false) const checkAll = ref(false)
const selectIds = ref<string[]>([]) const selectIds = ref<string[]>([])
@ -273,7 +273,7 @@ const rightInputHandler = debounce((keyword) => {
<n-checkbox v-model:checked="checkAll" label="全部" @update:checked="onCheckAllChange" /> <n-checkbox v-model:checked="checkAll" label="全部" @update:checked="onCheckAllChange" />
</div> </div>
<div <div
v-for="item in offList" v-show="item.name.includes(offKeyword) || offKeyword === ''" :key="item.id" :class="{ 'disable-check': item.fix }" v-for="item in offList" v-show="item.name.includes(offKeyword)" :key="item.id" :class="{ 'disable-check': item.fix }"
class="draggable-li" class="draggable-li"
> >
<n-checkbox <n-checkbox
@ -306,7 +306,7 @@ const rightInputHandler = debounce((keyword) => {
<n-scrollbar style="max-height: 500px;border: 1px solid #cad2dd;border-radius: 2px;" class="scroll"> <n-scrollbar style="max-height: 500px;border: 1px solid #cad2dd;border-radius: 2px;" class="scroll">
<VueDraggable v-model="onList" class="draggable-ul" :animation="150" group="shared"> <VueDraggable v-model="onList" class="draggable-ul" :animation="150" group="shared">
<div <div
v-for="item in onList" v-show="item.name.includes(onKeyword) || onKeyword === ''" :key="item.id" :class="{ fix: item.fix }" v-for="item in onList" v-show="item.name.includes(onKeyword)" :key="item.id" :class="{ fix: item.fix }"
class="cursor-move draggable-li" class="cursor-move draggable-li"
> >
<SvgIcon name="drag" size="24" /> <SvgIcon name="drag" size="24" />

@ -4,8 +4,10 @@ import { NDataTable } from 'naive-ui'
import type { DataTableColumns, DataTableRowKey } from 'naive-ui' import type { DataTableColumns, DataTableRowKey } from 'naive-ui'
import type { SortableEvent } from 'sortablejs' import type { SortableEvent } from 'sortablejs'
import Sortable from 'sortablejs' import Sortable from 'sortablejs'
import { debounce } from 'lodash-es'
import Action from '../Action.vue' import Action from '../Action.vue'
import { deleteCondition, getConditionList, sort } from '@/api/home/filter' import { deleteCondition, getConditionList, sort } from '@/api/home/filter'
import type { FilterSearchParam } from '/#/api'
defineOptions({ name: 'FilterModal' }) defineOptions({ name: 'FilterModal' })
@ -79,12 +81,14 @@ const loading = ref(true)
const pagination = reactive({ const pagination = reactive({
page: 1, page: 1,
pageCount: 1, pageCount: 1,
pageSize: 10, pageSize: 2,
}) })
const tableData = ref<Array<RowData>>([]) const tableData = ref<Array<RowData>>([])
const keyword = ref('')
async function query(page: number, pageSize: number) { async function query(page: number, pageSize: number) {
const result = await getConditionList({ pageNo: page, pageSize }) const searchParam: FilterSearchParam = { search_searchname: { value: keyword.value, op: 'like', type: 'string' } }
const result = await getConditionList({ pageNo: page, pageSize }, searchParam)
const { data, pageCount } = result const { data, pageCount } = result
tableData.value = data tableData.value = data
pagination.page = page pagination.page = page
@ -232,6 +236,11 @@ function closeModal() {
defineExpose({ defineExpose({
showModal, showModal,
}) })
const inputHandler = debounce((word) => {
keyword.value = word
query(1, 10)
}, 300)
</script> </script>
<template> <template>
@ -249,7 +258,7 @@ defineExpose({
</div> </div>
</div> </div>
<div class="wrapper-form"> <div class="wrapper-form">
<n-input :style="{ width: '360px', border: '1px solid #cad2dd' }" placeholder="请输入过滤条件名称搜索"> <n-input :style="{ width: '360px', border: '1px solid #cad2dd' }" placeholder="请输入过滤条件名称搜索" @input="inputHandler">
<template #suffix> <template #suffix>
<SvgIcon size="14px" name="magnifying-1" /> <SvgIcon size="14px" name="magnifying-1" />
</template> </template>

1
types/api.d.ts vendored

@ -12,6 +12,7 @@ export interface FilterSearchParam {
search_searchname?: { search_searchname?: {
value: string value: string
op: 'equal' | 'like' op: 'equal' | 'like'
type: 'string'
} }
} }

Loading…
Cancel
Save