feat: 将搜索组件抽离为公共组件
This commit is contained in:
112
src/component/common/TableSearchBar.vue
Normal file
112
src/component/common/TableSearchBar.vue
Normal file
@@ -0,0 +1,112 @@
|
||||
<template>
|
||||
<div class="table_search_bar flex flex-justify-between flex-align-center">
|
||||
<div class="search_preset flex flex-1">
|
||||
<div
|
||||
class="preset_item gallery_btn white"
|
||||
v-for="item in buttonList"
|
||||
:class="{ active: searchParams.currentPreset === item.value }"
|
||||
:key="item.value"
|
||||
@click="handleButtonClick(item.value)"
|
||||
>
|
||||
{{ item.label }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="search_input flex flex-align-center">
|
||||
<input
|
||||
class="search_input_inner flex-1"
|
||||
v-model="searchParams.searchText"
|
||||
:bordered="false"
|
||||
@keydown.enter="handleSearch"
|
||||
:placeholder="placeholder"
|
||||
/>
|
||||
<SearchOutlined @click="handleSearch" />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, reactive } from 'vue'
|
||||
import { SearchOutlined } from '@ant-design/icons-vue'
|
||||
|
||||
interface ButtonItem {
|
||||
label: string
|
||||
value: string
|
||||
}
|
||||
|
||||
interface Props {
|
||||
buttonList: ButtonItem[]
|
||||
placeholder?: string
|
||||
}
|
||||
|
||||
interface SearchParams {
|
||||
searchText: string
|
||||
currentPreset: string
|
||||
}
|
||||
|
||||
interface Emits {
|
||||
(e: 'search', params: SearchParams): void
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
placeholder: 'batchGeneration.Search'
|
||||
})
|
||||
|
||||
const emit = defineEmits<Emits>()
|
||||
|
||||
// 内部状态管理
|
||||
const searchParams = reactive({
|
||||
searchText: '',
|
||||
currentPreset:props.buttonList[0]?.value || ''
|
||||
})
|
||||
|
||||
// 处理按钮点击
|
||||
const handleButtonClick = (value: string) => {
|
||||
searchParams.currentPreset = value
|
||||
handleSearch()
|
||||
}
|
||||
|
||||
// 处理搜索
|
||||
const handleSearch = () => {
|
||||
emit('search', searchParams)
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
.flex {
|
||||
display: flex;
|
||||
}
|
||||
.flex-1 {
|
||||
flex: 1;
|
||||
}
|
||||
.flex-justify-between {
|
||||
justify-content: space-between;
|
||||
}
|
||||
.flex-align-center {
|
||||
align-items: center;
|
||||
}
|
||||
.table_search_bar {
|
||||
.search_preset {
|
||||
column-gap: 2rem;
|
||||
.preset_item {
|
||||
line-height: 4rem;
|
||||
min-width: 10rem;
|
||||
font-weight: normal;
|
||||
}
|
||||
}
|
||||
|
||||
.search_input {
|
||||
height: 4rem;
|
||||
background-color: #fff;
|
||||
border: 0.1rem solid #000;
|
||||
border-radius: 43rem;
|
||||
// column-gap: 3rem;
|
||||
padding-right: 1rem;
|
||||
.search_input_inner {
|
||||
border: none;
|
||||
height: 100%;
|
||||
padding-left: 3rem;
|
||||
border-radius: 4rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -72,29 +72,11 @@
|
||||
</div>
|
||||
</div>
|
||||
</div> -->
|
||||
<div class="history_table_search flex flex-justify-between">
|
||||
<div class="search_preset flex flex-1">
|
||||
<div
|
||||
class="preset_item started_btn"
|
||||
v-for="item in presetList"
|
||||
:class="{ active: currentPreset === item.value }"
|
||||
:key="item.value"
|
||||
@click="handleChangePreset(item.value)"
|
||||
>
|
||||
{{ t(item.label) }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="search_input flex flex-align-center">
|
||||
<input
|
||||
class="search_input_inner flex-1"
|
||||
v-model="searchParam.text"
|
||||
:bordered="false"
|
||||
@keydown.enter="searchHistoryList"
|
||||
:placeholder="t('batchGeneration.Search')"
|
||||
/>
|
||||
<search-outlined @click="searchHistoryList" />
|
||||
</div>
|
||||
</div>
|
||||
<TableSearchBar
|
||||
:button-list="presetList"
|
||||
:placeholder="t('batchGeneration.Search')"
|
||||
@search="searchHistoryList"
|
||||
/>
|
||||
<div class="history_table_content flex-1" ref="historyTable">
|
||||
<a-config-provider :locale="tableLocale">
|
||||
<a-table
|
||||
@@ -161,6 +143,7 @@ import { useI18n } from 'vue-i18n'
|
||||
import enUS from 'ant-design-vue/es/locale/en_US'
|
||||
import zhCN from 'ant-design-vue/es/locale/zh_CN'
|
||||
import { ConfigProvider } from 'ant-design-vue'
|
||||
import TableSearchBar from '@/component/common/TableSearchBar.vue'
|
||||
import setLabel from '@/component/LibraryPage/setLabel.vue'
|
||||
import searchLabel from '@/component/LibraryPage/searchLabel.vue'
|
||||
import { useStore } from 'vuex'
|
||||
@@ -174,7 +157,8 @@ export default defineComponent({
|
||||
ElCascader,
|
||||
searchLabel,
|
||||
SearchOutlined,
|
||||
ConfigProvider
|
||||
ConfigProvider,
|
||||
TableSearchBar
|
||||
},
|
||||
setup() {
|
||||
const store = useStore()
|
||||
@@ -182,7 +166,7 @@ export default defineComponent({
|
||||
|
||||
let renameData: any = ref({}) //修改名字选中的数据
|
||||
let isShowMark: any = ref(false)
|
||||
|
||||
|
||||
// 根据store中的语言设置返回对应的ant-design-vue语言包
|
||||
const tableLocale = computed(() => {
|
||||
const language = store.state.UserHabit?.userDetail?.language
|
||||
@@ -192,7 +176,7 @@ export default defineComponent({
|
||||
return [
|
||||
{
|
||||
title: useI18n().t('HistoryPage.CollectionsName'),
|
||||
align: 'center',
|
||||
align: 'left',
|
||||
ellipsis: true,
|
||||
width: 150,
|
||||
dataIndex: 'name',
|
||||
@@ -293,13 +277,12 @@ export default defineComponent({
|
||||
pageSize: 10,
|
||||
total: 0,
|
||||
presetList: [
|
||||
{ label: 'Header.All', value: 'all' },
|
||||
{ label: 'newProjectg.series', value: 'series' },
|
||||
{ label: 'newProjectg.single', value: 'single' },
|
||||
{ label: 'Header.Product', value: 'product' },
|
||||
{ label: 'Header.POSE_TRANSFER', value: 'video' }
|
||||
{ label: this.t('Header.All'), value: 'all' },
|
||||
{ label: this.t('newProjectg.series'), value: 'series' },
|
||||
{ label: this.t('newProjectg.single'), value: 'single' },
|
||||
{ label: this.t('Header.Product'), value: 'product' },
|
||||
{ label: this.t('Header.POSE_TRANSFER'), value: 'video' }
|
||||
],
|
||||
currentPreset: 'all',
|
||||
searchParam: {
|
||||
text: '',
|
||||
type: '',
|
||||
@@ -386,16 +369,12 @@ export default defineComponent({
|
||||
},
|
||||
|
||||
//查询列表
|
||||
searchHistoryList() {
|
||||
searchHistoryList(value:any) {
|
||||
console.log('value',value)
|
||||
this.currentPage = 1
|
||||
this.getHistoryList()
|
||||
},
|
||||
|
||||
// 点击预设
|
||||
handleChangePreset(value) {
|
||||
this.currentPreset = value
|
||||
},
|
||||
|
||||
getHistoryList() {
|
||||
this.isShowMark = true
|
||||
let startDate: any = this.rangePickerValue
|
||||
@@ -659,42 +638,6 @@ export default defineComponent({
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
.history_table_search {
|
||||
.search_preset {
|
||||
column-gap: 2rem;
|
||||
.preset_item {
|
||||
// cursor: pointer;
|
||||
// box-sizing: border-box;
|
||||
// height: 6rem;
|
||||
// line-height: 6rem;
|
||||
// padding: 0 5rem;
|
||||
border: 0.1rem solid #000;
|
||||
// border-radius: 5rem;
|
||||
color: #000;
|
||||
background-color: #fff;
|
||||
&.active {
|
||||
color: #fff;
|
||||
background-color: #000;
|
||||
}
|
||||
}
|
||||
}
|
||||
.search_input {
|
||||
background-color: #fff;
|
||||
border: 0.1rem solid #000;
|
||||
border-radius: 3rem;
|
||||
// column-gap: 3rem;
|
||||
padding-right: 1rem;
|
||||
.search_input_inner {
|
||||
border: none;
|
||||
height: 100%;
|
||||
padding-left: 3rem;
|
||||
border-radius: 3rem;
|
||||
}
|
||||
:deep(.ant-input) {
|
||||
border: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.history_table_content {
|
||||
margin-top: 2.6rem;
|
||||
|
||||
Reference in New Issue
Block a user