2023-12-26 16:17:30 +08:00
|
|
|
<template>
|
2024-01-05 13:56:33 +08:00
|
|
|
<div ref="tableHeader" class="cn-table-header">
|
|
|
|
|
<div class="table-header ba-scroll-style">
|
2024-01-30 16:52:13 +08:00
|
|
|
<el-form
|
2024-04-01 18:29:32 +08:00
|
|
|
style="flex: 1; height: 32px; margin-right: 20px"
|
|
|
|
|
ref="headerForm"
|
2024-01-30 16:52:13 +08:00
|
|
|
@submit.prevent=""
|
|
|
|
|
@keyup.enter="onComSearch"
|
|
|
|
|
label-position="left"
|
|
|
|
|
:inline="true"
|
|
|
|
|
>
|
|
|
|
|
<el-form-item label="区域" v-if="area">
|
|
|
|
|
<Area ref="areaRef" v-model="tableStore.table.params.deptIndex" />
|
|
|
|
|
</el-form-item>
|
|
|
|
|
<el-form-item label="日期" v-if="datePicker" style="grid-column: span 2; max-width: unset">
|
|
|
|
|
<DatePicker ref="datePickerRef"></DatePicker>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
<slot name="select"></slot>
|
|
|
|
|
</el-form>
|
2024-01-05 15:44:31 +08:00
|
|
|
<template v-if="$slots.select || datePicker">
|
2024-01-30 16:52:13 +08:00
|
|
|
<el-button type="primary" @click="showSelectChange" v-if="showUnfoldButton">
|
|
|
|
|
<Icon size="14" name="el-icon-ArrowUp" style="color: #fff" v-if="showSelect" />
|
|
|
|
|
<Icon size="14" name="el-icon-ArrowDown" style="color: #fff" v-else />
|
|
|
|
|
</el-button>
|
2024-04-01 18:29:32 +08:00
|
|
|
<el-button @click="onComSearch" v-if="showSearch" type="primary" :icon="Search">查询</el-button>
|
|
|
|
|
<el-button @click="onResetForm" v-if="showSearch" :icon="RefreshLeft">重置</el-button>
|
2024-01-04 16:39:05 +08:00
|
|
|
</template>
|
2024-01-05 13:56:33 +08:00
|
|
|
<slot name="operation"></slot>
|
2023-12-26 16:17:30 +08:00
|
|
|
</div>
|
2024-01-30 16:52:13 +08:00
|
|
|
<el-form
|
|
|
|
|
:style="showSelect && showUnfoldButton ? headerFormSecondStyleOpen : headerFormSecondStyleClose"
|
2024-04-01 18:29:32 +08:00
|
|
|
ref="headerFormSecond"
|
2024-01-30 16:52:13 +08:00
|
|
|
@submit.prevent=""
|
|
|
|
|
@keyup.enter="onComSearch"
|
|
|
|
|
label-position="left"
|
|
|
|
|
:inline="true"
|
2024-04-01 18:29:32 +08:00
|
|
|
></el-form>
|
2023-12-26 16:17:30 +08:00
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
2024-01-05 13:56:33 +08:00
|
|
|
<script setup lang="ts">
|
2024-01-04 10:38:41 +08:00
|
|
|
import { inject, ref, onMounted, nextTick, onUnmounted } from 'vue'
|
2023-12-26 16:17:30 +08:00
|
|
|
import type TableStore from '@/utils/tableStore'
|
2023-12-29 10:05:09 +08:00
|
|
|
import DatePicker from '@/components/form/datePicker/index.vue'
|
2024-01-19 09:23:31 +08:00
|
|
|
import Area from '@/components/form/area/index.vue'
|
2024-01-04 10:38:41 +08:00
|
|
|
import { mainHeight } from '@/utils/layout'
|
2024-01-19 09:23:31 +08:00
|
|
|
import { useDictData } from '@/stores/dictData'
|
2024-01-24 15:42:54 +08:00
|
|
|
import { Search, RefreshLeft } from '@element-plus/icons-vue'
|
|
|
|
|
|
2023-12-26 16:17:30 +08:00
|
|
|
const tableStore = inject('tableStore') as TableStore
|
2024-01-04 10:38:41 +08:00
|
|
|
const tableHeader = ref()
|
2024-01-11 08:54:09 +08:00
|
|
|
const datePickerRef = ref()
|
2024-01-19 09:23:31 +08:00
|
|
|
const dictData = useDictData()
|
2024-01-22 20:24:50 +08:00
|
|
|
const areaRef = ref()
|
2024-04-01 18:29:32 +08:00
|
|
|
const headerForm = ref()
|
|
|
|
|
const headerFormSecond = ref()
|
2024-01-30 16:52:13 +08:00
|
|
|
|
2023-12-27 10:39:40 +08:00
|
|
|
interface Props {
|
2023-12-27 16:36:10 +08:00
|
|
|
datePicker?: boolean
|
2024-01-19 09:23:31 +08:00
|
|
|
area?: boolean
|
2024-04-01 18:29:32 +08:00
|
|
|
showSearch?: boolean
|
2023-12-27 10:39:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const props = withDefaults(defineProps<Props>(), {
|
2024-01-19 09:23:31 +08:00
|
|
|
datePicker: false,
|
2024-04-01 18:29:32 +08:00
|
|
|
area: false,
|
|
|
|
|
showSearch: true
|
2023-12-27 10:39:40 +08:00
|
|
|
})
|
2024-01-04 10:38:41 +08:00
|
|
|
// 动态计算table高度
|
|
|
|
|
const resizeObserver = new ResizeObserver(entries => {
|
|
|
|
|
for (const entry of entries) {
|
|
|
|
|
handlerHeight()
|
2024-01-30 16:52:13 +08:00
|
|
|
computedSearchRow()
|
2024-01-04 10:38:41 +08:00
|
|
|
}
|
|
|
|
|
})
|
2024-01-04 16:39:05 +08:00
|
|
|
const showUnfoldButton = ref(false)
|
2024-01-30 16:52:13 +08:00
|
|
|
const headerFormSecondStyleOpen = {
|
|
|
|
|
opacity: 1,
|
|
|
|
|
height: 'auto',
|
2024-02-02 09:29:19 +08:00
|
|
|
padding: '0 15px 13px 15px'
|
2024-01-30 16:52:13 +08:00
|
|
|
}
|
|
|
|
|
const headerFormSecondStyleClose = {
|
|
|
|
|
opacity: 0,
|
|
|
|
|
height: '0',
|
|
|
|
|
padding: '0'
|
|
|
|
|
}
|
2024-01-04 10:38:41 +08:00
|
|
|
onMounted(() => {
|
2024-01-05 13:56:33 +08:00
|
|
|
if (props.datePicker) {
|
2024-01-11 08:54:09 +08:00
|
|
|
tableStore.table.params.searchBeginTime = datePickerRef.value.timeValue[0]
|
|
|
|
|
tableStore.table.params.searchEndTime = datePickerRef.value.timeValue[1]
|
2024-01-11 16:40:44 +08:00
|
|
|
tableStore.table.params.startTime = datePickerRef.value.timeValue[0]
|
|
|
|
|
tableStore.table.params.endTime = datePickerRef.value.timeValue[1]
|
2024-01-11 08:54:09 +08:00
|
|
|
tableStore.table.params.timeFlag = datePickerRef.value.timeFlag
|
2024-01-05 13:56:33 +08:00
|
|
|
}
|
2024-01-19 09:23:31 +08:00
|
|
|
if (props.area) {
|
|
|
|
|
tableStore.table.params.deptIndex = dictData.state.area[0].id
|
|
|
|
|
}
|
2024-01-04 16:39:05 +08:00
|
|
|
nextTick(() => {
|
|
|
|
|
resizeObserver.observe(tableHeader.value)
|
2024-01-30 16:52:13 +08:00
|
|
|
computedSearchRow()
|
2024-01-04 16:39:05 +08:00
|
|
|
})
|
2024-01-04 10:38:41 +08:00
|
|
|
})
|
|
|
|
|
onUnmounted(() => {
|
|
|
|
|
resizeObserver.disconnect()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const handlerHeight = () => {
|
|
|
|
|
tableStore.table.height = mainHeight(
|
|
|
|
|
tableStore.table.publicHeight + tableHeader.value.offsetHeight + (tableStore.showPage ? 58 : 0) + 20
|
|
|
|
|
).height as string
|
|
|
|
|
}
|
2024-01-30 16:52:13 +08:00
|
|
|
const computedSearchRow = () => {
|
2024-04-01 18:29:32 +08:00
|
|
|
if (!headerForm.value.$el) return
|
2024-01-30 16:52:13 +08:00
|
|
|
|
2024-04-01 18:29:32 +08:00
|
|
|
// 清空headerFormSecond.value.$el下的元素
|
|
|
|
|
while (headerFormSecond.value.$el.firstChild) {
|
|
|
|
|
headerForm.value.$el.appendChild(headerFormSecond.value.$el.firstChild)
|
2024-01-30 16:52:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取第一行放了几个表单
|
2024-04-01 18:29:32 +08:00
|
|
|
const elFormItem = headerForm.value.$el.querySelectorAll('.el-form-item')
|
|
|
|
|
// 把第一行放不下的复制一份放到headerFormSecond.value.$el
|
2024-01-30 16:52:13 +08:00
|
|
|
let width = 0
|
|
|
|
|
for (let i = 0; i < elFormItem.length; i++) {
|
|
|
|
|
width += elFormItem[i].offsetWidth + 32
|
2024-04-01 18:29:32 +08:00
|
|
|
if (width > headerForm.value.$el.offsetWidth) {
|
|
|
|
|
headerFormSecond.value.$el.appendChild(elFormItem[i])
|
2024-01-30 16:52:13 +08:00
|
|
|
}
|
|
|
|
|
}
|
2024-04-01 18:29:32 +08:00
|
|
|
|
|
|
|
|
// 判断是否需要折叠
|
|
|
|
|
if (headerFormSecond.value.$el.scrollHeight > 0) {
|
|
|
|
|
showUnfoldButton.value = true
|
|
|
|
|
} else {
|
|
|
|
|
showUnfoldButton.value = false
|
|
|
|
|
}
|
2024-01-30 16:52:13 +08:00
|
|
|
}
|
|
|
|
|
|
2024-01-04 16:39:05 +08:00
|
|
|
const showSelect = ref(false)
|
2023-12-27 10:39:40 +08:00
|
|
|
const showSelectChange = () => {
|
|
|
|
|
showSelect.value = !showSelect.value
|
|
|
|
|
}
|
2024-01-05 09:14:53 +08:00
|
|
|
const onComSearch = async () => {
|
2024-01-05 13:56:33 +08:00
|
|
|
if (props.datePicker) {
|
2024-01-11 08:54:09 +08:00
|
|
|
tableStore.table.params.searchBeginTime = datePickerRef.value.timeValue[0]
|
|
|
|
|
tableStore.table.params.searchEndTime = datePickerRef.value.timeValue[1]
|
2024-01-11 16:40:44 +08:00
|
|
|
tableStore.table.params.startTime = datePickerRef.value.timeValue[0]
|
|
|
|
|
tableStore.table.params.endTime = datePickerRef.value.timeValue[1]
|
2024-01-11 08:54:09 +08:00
|
|
|
tableStore.table.params.timeFlag = datePickerRef.value.timeFlag
|
2024-01-05 13:56:33 +08:00
|
|
|
}
|
2024-01-05 09:14:53 +08:00
|
|
|
|
|
|
|
|
await tableStore.onTableAction('search', {})
|
2023-12-27 10:39:40 +08:00
|
|
|
}
|
|
|
|
|
const onResetForm = () => {
|
|
|
|
|
tableStore.onTableAction('reset', {})
|
2023-12-26 16:17:30 +08:00
|
|
|
}
|
2024-04-01 18:29:32 +08:00
|
|
|
const setDatePicker = (list: any) => {
|
|
|
|
|
datePickerRef.value.setTimeOptions(list)
|
|
|
|
|
}
|
|
|
|
|
const setInterval = (val: any) => {
|
|
|
|
|
datePickerRef.value.setInterval(val)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
defineExpose({ onComSearch, areaRef, setDatePicker, setInterval, datePickerRef })
|
2023-12-26 16:17:30 +08:00
|
|
|
</script>
|
|
|
|
|
|
2024-01-05 13:56:33 +08:00
|
|
|
<style scoped lang="scss">
|
2024-04-01 18:29:32 +08:00
|
|
|
.cn-table-header {
|
|
|
|
|
border: 1px solid var(--el-border-color);
|
|
|
|
|
}
|
2023-12-26 16:17:30 +08:00
|
|
|
.table-header {
|
|
|
|
|
position: relative;
|
|
|
|
|
overflow-x: auto;
|
|
|
|
|
box-sizing: border-box;
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
width: 100%;
|
|
|
|
|
max-width: 100%;
|
|
|
|
|
background-color: var(--ba-bg-color-overlay);
|
2024-04-01 18:29:32 +08:00
|
|
|
|
2023-12-26 16:17:30 +08:00
|
|
|
border-bottom: none;
|
|
|
|
|
padding: 13px 15px;
|
|
|
|
|
font-size: 14px;
|
2023-12-27 10:39:40 +08:00
|
|
|
|
2023-12-26 16:17:30 +08:00
|
|
|
.table-header-operate-text {
|
|
|
|
|
margin-left: 6px;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.table-com-search {
|
|
|
|
|
box-sizing: border-box;
|
|
|
|
|
width: 100%;
|
|
|
|
|
max-width: 100%;
|
|
|
|
|
background-color: var(--ba-bg-color-overlay);
|
|
|
|
|
border: 1px solid var(--ba-border-color);
|
|
|
|
|
border-bottom: none;
|
2024-01-04 16:39:05 +08:00
|
|
|
padding: 13px 15px 20px 15px;
|
2023-12-26 16:17:30 +08:00
|
|
|
font-size: 14px;
|
2024-01-04 16:39:05 +08:00
|
|
|
}
|
2024-01-05 11:35:13 +08:00
|
|
|
|
2024-01-30 16:52:13 +08:00
|
|
|
#header-form-second,
|
|
|
|
|
#header-form {
|
2024-02-02 09:29:19 +08:00
|
|
|
// display: flex;
|
|
|
|
|
// flex-wrap: wrap;
|
2024-02-02 09:58:14 +08:00
|
|
|
transition: all 0.3s;
|
2024-01-04 16:39:05 +08:00
|
|
|
}
|
2023-12-27 10:39:40 +08:00
|
|
|
|
2023-12-26 16:17:30 +08:00
|
|
|
.mlr-12 {
|
|
|
|
|
margin-left: 12px;
|
|
|
|
|
}
|
2023-12-27 10:39:40 +08:00
|
|
|
|
2023-12-26 16:17:30 +08:00
|
|
|
.mlr-12 + .el-button {
|
|
|
|
|
margin-left: 12px;
|
|
|
|
|
}
|
2023-12-27 10:39:40 +08:00
|
|
|
|
2023-12-26 16:17:30 +08:00
|
|
|
.table-search {
|
|
|
|
|
display: flex;
|
|
|
|
|
margin-left: auto;
|
2023-12-27 10:39:40 +08:00
|
|
|
|
2023-12-26 16:17:30 +08:00
|
|
|
.quick-search {
|
|
|
|
|
width: auto;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-12-27 10:39:40 +08:00
|
|
|
|
2023-12-26 16:17:30 +08:00
|
|
|
.table-search-button-group {
|
|
|
|
|
display: flex;
|
|
|
|
|
margin-left: 12px;
|
|
|
|
|
border: 1px solid var(--el-border-color);
|
|
|
|
|
border-radius: var(--el-border-radius-base);
|
|
|
|
|
overflow: hidden;
|
2023-12-27 10:39:40 +08:00
|
|
|
|
2023-12-26 16:17:30 +08:00
|
|
|
button:focus,
|
|
|
|
|
button:active {
|
|
|
|
|
background-color: var(--ba-bg-color-overlay);
|
|
|
|
|
}
|
2023-12-27 10:39:40 +08:00
|
|
|
|
2023-12-26 16:17:30 +08:00
|
|
|
button:hover {
|
|
|
|
|
background-color: var(--el-color-info-light-7);
|
|
|
|
|
}
|
2023-12-27 10:39:40 +08:00
|
|
|
|
2023-12-26 16:17:30 +08:00
|
|
|
.table-search-button-item {
|
|
|
|
|
height: 30px;
|
|
|
|
|
border: none;
|
|
|
|
|
border-radius: 0;
|
|
|
|
|
}
|
2023-12-27 10:39:40 +08:00
|
|
|
|
2023-12-26 16:17:30 +08:00
|
|
|
.el-button + .el-button {
|
|
|
|
|
margin: 0;
|
|
|
|
|
}
|
2023-12-27 10:39:40 +08:00
|
|
|
|
2023-12-26 16:17:30 +08:00
|
|
|
.right-border {
|
|
|
|
|
border-right: 1px solid var(--el-border-color);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
html.dark {
|
|
|
|
|
.table-search-button-group {
|
|
|
|
|
button:focus,
|
|
|
|
|
button:active {
|
|
|
|
|
background-color: var(--el-color-info-dark-2);
|
|
|
|
|
}
|
2023-12-27 10:39:40 +08:00
|
|
|
|
2023-12-26 16:17:30 +08:00
|
|
|
button:hover {
|
|
|
|
|
background-color: var(--el-color-info-light-7);
|
|
|
|
|
}
|
2023-12-27 10:39:40 +08:00
|
|
|
|
2023-12-26 16:17:30 +08:00
|
|
|
button {
|
|
|
|
|
background-color: var(--ba-bg-color-overlay);
|
2023-12-27 10:39:40 +08:00
|
|
|
|
2023-12-26 16:17:30 +08:00
|
|
|
el-icon {
|
|
|
|
|
color: white !important;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-02-02 09:29:19 +08:00
|
|
|
#header-form,
|
|
|
|
|
#header-form-second {
|
|
|
|
|
:deep(.el-select) {
|
|
|
|
|
--el-select-width: 220px;
|
|
|
|
|
}
|
|
|
|
|
:deep(.el-input) {
|
|
|
|
|
--el-input-width: 220px;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-12-26 16:17:30 +08:00
|
|
|
</style>
|