Browse Source

优化查询,增加标题高亮关键字

main
dark 4 months ago
parent
commit
ad098a8520
  1. 36
      src/pages/videos/list/index.tsx
  2. 3
      src/pages/videos/list/style.ts

36
src/pages/videos/list/index.tsx

@ -41,6 +41,7 @@ const Video = () => {
const { data: category, isLoading: isCategoryFetching } = useAtomValue(categoryByIdAtom) const { data: category, isLoading: isCategoryFetching } = useAtomValue(categoryByIdAtom)
const [ open, setOpen ] = useState(false) const [ open, setOpen ] = useState(false)
const [ openFilter, setFilterOpen ] = useState(false) const [ openFilter, setFilterOpen ] = useState(false)
const [ searchKey, setSearchKey ] = useState(search?.title)
const columns = useMemo(() => { const columns = useMemo(() => {
return [ return [
@ -69,6 +70,12 @@ const Video = () => {
colProps: { colProps: {
span: 8 span: 8
}, },
render: (_text, record) => {
//高亮搜索关键字, 从search.title中获取
const title = record.title?.replace?.(new RegExp(`(${search?.title})`, 'ig'), '<span class="ant-pro-table-highlight">$1</span>')
return <span dangerouslySetInnerHTML={{ __html: title }}></span>
}
}, },
{ {
'title': t(`${i18nPrefix}.columns.title_sub`, 'TitleSub'), 'title': t(`${i18nPrefix}.columns.title_sub`, 'TitleSub'),
@ -79,6 +86,12 @@ const Video = () => {
}, },
colProps: { colProps: {
span: 16 span: 16
},
render: (_text, record) => {
//高亮搜索关键字, 从search.title中获取
const title = record.title_sub?.replace?.(new RegExp(`(${search?.title_sub})`, 'ig'), '<span class="ant-pro-table-highlight">$1</span>')
return <span dangerouslySetInnerHTML={{ __html: title }}></span>
} }
}, },
{ {
@ -558,6 +571,7 @@ const Video = () => {
useEffect(() => { useEffect(() => {
setSearchKey(search?.title)
filterForm.setFieldsValue(search) filterForm.setFieldsValue(search)
}, [ search ]) }, [ search ])
@ -575,14 +589,18 @@ const Video = () => {
headerTitle={t(`${i18nPrefix}.title`, '视频管理')} headerTitle={t(`${i18nPrefix}.title`, '视频管理')}
toolbar={{ toolbar={{
search: { search: {
loading: isFetching && !!search.key,
loading: isFetching && !!search.title,
onSearch: (value: string) => { onSearch: (value: string) => {
setSearch(prev => ({ setSearch(prev => ({
...prev, ...prev,
key: value
title: value
})) }))
}, },
allowClear: true, allowClear: true,
onChange: (e) => {
setSearchKey(e.target?.value)
},
value: searchKey,
placeholder: t(`${i18nPrefix}.placeholder`, '输入视频名称') placeholder: t(`${i18nPrefix}.placeholder`, '输入视频名称')
}, },
actions: [ actions: [
@ -714,6 +732,7 @@ const Video = () => {
<Space> <Space>
<Button onClick={() => { <Button onClick={() => {
props.reset() props.reset()
}}>{props.searchConfig?.resetText}</Button> }}>{props.searchConfig?.resetText}</Button>
<Button type="primary" <Button type="primary"
onClick={() => { onClick={() => {
@ -745,16 +764,9 @@ const Video = () => {
} }
}) })
if (Object.keys(values).length === 0) {
setSearch({})
} else {
setSearch(prev => {
return {
...prev,
...values
}
})
}
setSearch(values)
}} }}
columns={columns.filter(item => !item.hideInSearch) as ProFormColumnsType[]}/> columns={columns.filter(item => !item.hideInSearch) as ProFormColumnsType[]}/>
</ListPageLayout> </ListPageLayout>

3
src/pages/videos/list/style.ts

@ -15,6 +15,9 @@ export const useStyle = createStyles(({ token, css, cx, prefixCls }, props: any)
height: calc(100vh - 350px) height: calc(100vh - 350px)
} }
} }
.ant-pro-table-highlight{
color: red;
}
` `
return { return {

Loading…
Cancel
Save