|
@@ -3,11 +3,11 @@
|
|
|
//其他较复杂的主页面表单场景还是简易手写组件和业务(便于可读性和维护)
|
|
|
<template>
|
|
|
<div
|
|
|
- v-if="columns?.length"
|
|
|
+ v-if="fields?.length"
|
|
|
class="table-search"
|
|
|
:class="{ 'in-padding': inPadding }"
|
|
|
>
|
|
|
- <t-form ref="formRef" :model="searchParam" :inline="true">
|
|
|
+ <t-form ref="formRef" :model="params" :inline="true">
|
|
|
<div class="first-row flex">
|
|
|
<t-form-item
|
|
|
v-for="item in firstLineItemsFilter"
|
|
@@ -17,7 +17,7 @@
|
|
|
:style="{ width: colToWidth(item.colSpan || 0) }"
|
|
|
:class="{ 'buttons-wrap': item.type == 'buttons' }"
|
|
|
>
|
|
|
- <SearchFormItem :item="item" :search-param="searchParam" />
|
|
|
+ <SearchFormItem :item="item" :params="params" />
|
|
|
</t-form-item>
|
|
|
<div class="flex-1"></div>
|
|
|
<t-form-item
|
|
@@ -28,7 +28,7 @@
|
|
|
:style="{ width: colToWidth(item.colSpan || 0) }"
|
|
|
:class="{ 'buttons-wrap': item.type == 'buttons' }"
|
|
|
>
|
|
|
- <SearchFormItem :item="item" :search-param="searchParam" />
|
|
|
+ <SearchFormItem :item="item" :params="params" />
|
|
|
</t-form-item>
|
|
|
<div v-if="showExpandBtn && !showAll" class="flex-1 text-right">
|
|
|
<t-button
|
|
@@ -57,7 +57,7 @@
|
|
|
:style="{ width: colToWidth(item.colSpan || 0) }"
|
|
|
:class="{ 'buttons-wrap': item.type == 'buttons' }"
|
|
|
>
|
|
|
- <SearchFormItem :item="item" :search-param="searchParam" />
|
|
|
+ <SearchFormItem :item="item" :params="params" />
|
|
|
</t-form-item>
|
|
|
</div>
|
|
|
</t-form>
|
|
@@ -101,28 +101,44 @@ onUnmounted(() => {
|
|
|
|
|
|
// 默认值
|
|
|
const props = defineProps({
|
|
|
- columns: Object, // 搜索配置列,见下方示例
|
|
|
- searchParam: Object, // 搜索参数
|
|
|
+ fields: Object, // 搜索配置列,见下方示例
|
|
|
+ params: Object, // 搜索参数
|
|
|
showAll: Boolean, //是否要求直接展开,无需折叠换行按钮
|
|
|
inPadding: Boolean,
|
|
|
});
|
|
|
-//columns示例:(目前支持控件:input、select、dropdown按钮、treeSelect、date选择框、time选择框、timerange时间范围选择框、daterange日期范围选择框...后期可以按需求扩展)
|
|
|
+//fields示例:(目前支持控件:input、select、dropdown按钮、treeSelect、date选择框、time选择框、timerange时间范围选择框、daterange日期范围选择框...后期可以按需求扩展)
|
|
|
/*
|
|
|
-const exampleColumnsProp = [
|
|
|
- {
|
|
|
- prop: 'b',
|
|
|
- label: '姓名',
|
|
|
- labelWidth: '60px',
|
|
|
- colSpan: 3.6,
|
|
|
- },
|
|
|
- {
|
|
|
- prop: 'c',
|
|
|
- label: '来源',
|
|
|
- type: 'select',
|
|
|
- labelWidth: '60px',
|
|
|
- colSpan: 3.6,
|
|
|
- },
|
|
|
- {
|
|
|
+const fields = [
|
|
|
+ {
|
|
|
+ prop: 'b',
|
|
|
+ label: '姓名',
|
|
|
+ labelWidth: '60px',
|
|
|
+ colSpan: 3.6,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ prop: 'c',
|
|
|
+ label: '来源',
|
|
|
+ type: 'select',
|
|
|
+ labelWidth: '60px',
|
|
|
+ colSpan: 3.6,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ type: 'button',
|
|
|
+ text: '查询',
|
|
|
+ attrs: {
|
|
|
+ class: 'm-l-10px',
|
|
|
+ },
|
|
|
+ },
|
|
|
+ {
|
|
|
+ type: 'button',
|
|
|
+ text: '新增',
|
|
|
+ position: 'right', //搜索条件中可能会有按钮在首行中居右,可以使用position:'right'
|
|
|
+ attrs: {
|
|
|
+ theme: 'success',
|
|
|
+ },
|
|
|
+ onClick: () => {},
|
|
|
+ },
|
|
|
+ {
|
|
|
type: 'buttons',
|
|
|
colSpan: 6,
|
|
|
children: [
|
|
@@ -150,19 +166,10 @@ const exampleColumnsProp = [
|
|
|
},
|
|
|
],
|
|
|
},
|
|
|
- {
|
|
|
- type: 'button',
|
|
|
- text: '新增',
|
|
|
- position: 'right', //搜索条件中可能会有按钮在首行中居右,可以使用position:'right'
|
|
|
- attrs: {
|
|
|
- theme: 'success',
|
|
|
- },
|
|
|
- onClick: () => {},
|
|
|
- },
|
|
|
];
|
|
|
*/
|
|
|
const showExpandBtn = computed(() => {
|
|
|
- let allColSpanNum = props.columns.reduce((total, item) => {
|
|
|
+ let allColSpanNum = props.fields.reduce((total, item) => {
|
|
|
return total + item.colSpan;
|
|
|
}, 0);
|
|
|
return allColSpanNum > 24;
|
|
@@ -193,8 +200,8 @@ watch(showMore, (val) => {
|
|
|
const firstLineItems = computed(() => {
|
|
|
let init = 0;
|
|
|
let arr = [];
|
|
|
- for (let i = 0; i < props.columns.length; i++) {
|
|
|
- let column = props.columns[i];
|
|
|
+ for (let i = 0; i < props.fields.length; i++) {
|
|
|
+ let column = props.fields[i];
|
|
|
if (init + (column.colSpan || 0) > 24) {
|
|
|
cutIndex.value = i;
|
|
|
break;
|
|
@@ -213,7 +220,7 @@ const firstLineItemsIsRight = computed(() => {
|
|
|
});
|
|
|
|
|
|
const otherLineItems = computed(() => {
|
|
|
- return props.columns?.slice(cutIndex.value) || [];
|
|
|
+ return props.fields?.slice(cutIndex.value) || [];
|
|
|
});
|
|
|
const colToWidth = (colSpan) => {
|
|
|
if (colSpan === 0) {
|
|
@@ -227,6 +234,9 @@ const colToWidth = (colSpan) => {
|
|
|
.table-search {
|
|
|
padding: 10px;
|
|
|
background-color: #fff;
|
|
|
+ :deep(.t-date-range-picker) {
|
|
|
+ width: 100%;
|
|
|
+ }
|
|
|
:deep(.t-form__item.buttons-wrap) {
|
|
|
.t-form__controls-content {
|
|
|
.t-button {
|
|
@@ -239,14 +249,14 @@ const colToWidth = (colSpan) => {
|
|
|
overflow: hidden;
|
|
|
transition: all 0.2s;
|
|
|
}
|
|
|
- :deep(
|
|
|
- .other-rows
|
|
|
- .t-form__item.buttons-wrap
|
|
|
- .t-form__controls-content
|
|
|
- .t-button:first-child
|
|
|
- ) {
|
|
|
- margin-left: 0;
|
|
|
- }
|
|
|
+ // :deep(
|
|
|
+ // .other-rows
|
|
|
+ // .t-form__item.buttons-wrap
|
|
|
+ // .t-form__controls-content
|
|
|
+ // .t-button:first-child
|
|
|
+ // ) {
|
|
|
+ // margin-left: 0;
|
|
|
+ // }
|
|
|
&.in-padding {
|
|
|
margin: -10px;
|
|
|
}
|