feat: form 组件样式调整

This commit is contained in:
xuziqiang
2024-06-25 11:21:35 +08:00
parent cecd3a0325
commit 15fce86265
14 changed files with 241 additions and 163 deletions

View File

@@ -182,3 +182,7 @@
background-color: #AEAEAE; background-color: #AEAEAE;
} }
} }
#app {
min-width: 1200px;
}

View File

@@ -439,7 +439,7 @@
label: '账号名', label: '账号名',
component: 'NsInput', component: 'NsInput',
componentProps: { componentProps: {
placeholder: '请输入账号名', // placeholder: '请输入账号名',
maxLength: 30, maxLength: 30,
}, },
}, },
@@ -448,7 +448,7 @@
label: '姓名', label: '姓名',
component: 'NsInput', component: 'NsInput',
componentProps: { componentProps: {
placeholder: '请输入姓名', // placeholder: '请输入姓名',
maxLength: 30, maxLength: 30,
}, },
}, },
@@ -457,7 +457,7 @@
label: '手机号', label: '手机号',
component: 'NsInput', component: 'NsInput',
componentProps: { componentProps: {
placeholder: '请输入手机号', // placeholder: '请输入手机号',
maxLength: 11, maxLength: 11,
}, },
}, },
@@ -475,7 +475,6 @@
label: '用户状态', label: '用户状态',
component: 'NsSelect', component: 'NsSelect',
componentProps: { componentProps: {
placeholder: '请选择',
allowClear: true, allowClear: true,
options: [ options: [
{ {

View File

@@ -13,7 +13,7 @@ const DATE_TYPE = [
'ARangePicker', 'ARangePicker',
]; ];
const INPUT_TYPE = ['NsInput', 'AInput']; const INPUT_TYPE = ['NsInput', 'AInput', 'NsTextarea', 'ATextarea'];
/** /**
* 是否时间组件 * 是否时间组件

View File

@@ -51,6 +51,11 @@
import { isInputType } from '/nerv-lib/component/form/form-util'; import { isInputType } from '/nerv-lib/component/form/form-util';
import { useParams } from '/nerv-lib/use/use-params'; import { useParams } from '/nerv-lib/use/use-params';
enum prefix {
'请选择',
'请输入',
}
export default defineComponent({ export default defineComponent({
name: 'NsFormItem', name: 'NsFormItem',
components: {}, components: {},
@@ -221,21 +226,28 @@
const { const {
component, component,
field, field,
label,
dynamicParams, dynamicParams,
changeEvent = 'change', changeEvent = 'change',
valueField, valueField,
addModel = [], addModel = [],
autoAddLink = false, autoAddLink = false,
autoSubmit = false, autoSubmit = false,
componentProps,
} = props.schema; } = props.schema;
const isCheck = const isCheck =
component && ['NsSwitch', 'NsCheckbox', 'Switch', 'Checkbox'].includes(component); component && ['NsSwitch', 'NsCheckbox', 'Switch', 'Checkbox'].includes(component);
const eventKey = `on${upperFirst(changeEvent)}`; const eventKey = `on${upperFirst(changeEvent)}`;
const attr: Recordable = {}; const attr: Recordable = {};
if (isInputType(component)) { const isInput = isInputType(component);
if (isInput) {
attr.allowClear = true; attr.allowClear = true;
} }
// const { placeholder } = componentProps;
// // 赋予初始提示符
// componentProps['placeholder'] = placeholder || `${prefix[Number(isInput)]}${label}`;
const propsData: Recordable = { const propsData: Recordable = {
field, field,
dynamicParams, dynamicParams,
@@ -293,8 +305,6 @@
}, },
onValidateChange: (text: Object | undefined) => { onValidateChange: (text: Object | undefined) => {
if (isUndefined(text)) text = {}; if (isUndefined(text)) text = {};
console.error(text, 'onValidateChange');
validateRef.value = text; validateRef.value = text;
}, },
}; };

View File

@@ -7,7 +7,24 @@
v-bind="getBindValue" v-bind="getBindValue"
ref="formElRef" ref="formElRef"
:model="formModel"> :model="formModel">
<a-row class="ns-form-body" :justify="getFormClass.justify" :gutter="getFormClass.gutter"> <div v-if="showAction && showExpandAll" class="ns-form-title ns-title-extra-box">
<span>查询</span>
<a-button type="link" class="ns-operate-expand" @click="expandAll = !expandAll">
<template v-if="expandAll">
收起筛选
<UpOutlined />
</template>
<template v-else>
展开筛选
<DownOutlined />
</template>
</a-button>
</div>
<a-row
v-show="expandAll"
class="ns-form-body"
:justify="getFormClass.justify"
:gutter="getFormClass.gutter">
<template v-for="(schema, index) in getSchema" :key="schema.field"> <template v-for="(schema, index) in getSchema" :key="schema.field">
<ns-form-item <ns-form-item
:show="expandRef || index < splitNumber" :show="expandRef || index < splitNumber"
@@ -89,6 +106,7 @@
const { schemas } = toRefs(props); const { schemas } = toRefs(props);
const isInitDefaultValueRef = ref(false); const isInitDefaultValueRef = ref(false);
const expandRef = ref(props.expand); const expandRef = ref(props.expand);
const expandAll = ref(props.expandAll);
const formModel = computed(() => { const formModel = computed(() => {
return props.model; return props.model;
}); });
@@ -97,7 +115,7 @@
function addChildForm(form: any) { function addChildForm(form: any) {
childForms.value.push(form); childForms.value.push(form);
} }
let splitNumber = ref(3); let splitNumber = ref(4);
const { width: formWidth } = useElementSize(formElRef); const { width: formWidth } = useElementSize(formElRef);
provide('addChildForm', addChildForm); provide('addChildForm', addChildForm);
@@ -302,17 +320,19 @@
getComponentSpan, getComponentSpan,
splitNumber, splitNumber,
finish, finish,
expandAll,
}; };
}, },
}); });
</script> </script>
<style lang="less" scoped> <style lang="less" scoped>
@gap: 16px;
.ns-form { .ns-form {
.ant-row { .ant-row {
flex: 1; flex: 1;
} }
.ns-operate { .ns-operate {
margin-bottom: 16px; margin-bottom: @gap;
text-align: right; text-align: right;
margin-left: auto; margin-left: auto;
@@ -334,5 +354,20 @@
margin-left: 6px; margin-left: 6px;
} }
} }
.ns-form-title {
text-align: left;
height: 22px;
// line-height: 32px;
//font-size: 16px;
font-weight: bold;
user-select: text;
margin-bottom: calc(@gap - 0px);
display: flex;
justify-content: space-between;
align-items: center;
:deep(.ant-btn) {
padding: 0;
}
}
} }
</style> </style>

View File

@@ -15,4 +15,7 @@ export const formProps = {
formLayout: PropTypes.string.def('flex'), formLayout: PropTypes.string.def('flex'),
expand: PropTypes.bool.def(true), expand: PropTypes.bool.def(true),
showExpand: PropTypes.bool.def(false), showExpand: PropTypes.bool.def(false),
// 收起全部
expandAll: PropTypes.bool.def(true), // 默认是否全部展开
showExpandAll: PropTypes.bool.def(true), // 是否展示右上角的全部收起展开
}; };

View File

@@ -56,6 +56,9 @@ export const tableProps = {
rowKey: PropTypes.oneOfType([PropTypes.func, PropTypes.string]).def('key'), rowKey: PropTypes.oneOfType([PropTypes.func, PropTypes.string]).def('key'),
refreshTime: PropTypes.number.def(0), refreshTime: PropTypes.number.def(0),
enableTableSession: PropTypes.bool.def(false), enableTableSession: PropTypes.bool.def(false),
expand: PropTypes.bool.def(true), expand: PropTypes.bool.def(true), // 默认是否展开
showExpand: PropTypes.bool.def(true), showExpand: PropTypes.bool.def(false), // 是否展示右下角的收起展开
// 收起全部
expandAll: PropTypes.bool.def(true), // 默认是否全部展开
showExpandAll: PropTypes.bool.def(true), // 是否展示右上角的全部收起展开
}; };

View File

@@ -2,7 +2,7 @@
<template> <template>
<div class="ns-table-header" v-if="!isEmpty(getActions)"> <div class="ns-table-header" v-if="!isEmpty(getActions)">
<div class="ns-table-title extra-title-box" v-if="tableTitle">{{ tableTitle }}</div> <div class="ns-table-title ns-title-extra-box" v-if="tableTitle">{{ tableTitle }}</div>
<div class="ns-table-header-action"> <div class="ns-table-header-action">
<slot name="header" :data="data"></slot> <slot name="header" :data="data"></slot>
<template v-for="item in getActions" :key="item.name"> <template v-for="item in getActions" :key="item.name">
@@ -75,21 +75,6 @@
</script> </script>
<style lang="less" scoped> <style lang="less" scoped>
.extra-title-box {
position: relative;
padding-left: 9px;
&::before {
content: '';
position: absolute;
left: 0;
top: 50%;
transform: translateY(-50%);
height: 13px;
width: 3px;
border-radius: 1px;
background-color: @primary-color;
}
}
.ns-table-header { .ns-table-header {
min-width: fit-content; min-width: fit-content;
user-select: none; user-select: none;

View File

@@ -15,6 +15,7 @@
</div> --> </div> -->
<div class="ns-table-container"> <div class="ns-table-container">
<!-- todo drag --> <!-- todo drag -->
<div class="ns-part-tree" v-if="!isEmpty(treeConfig)"> <div class="ns-part-tree" v-if="!isEmpty(treeConfig)">
<ns-tree-api v-bind="getTreeBindValue" @select="treeSelect" /> <ns-tree-api v-bind="getTreeBindValue" @select="treeSelect" />
</div> </div>
@@ -28,93 +29,44 @@
v-bind="formConfig" v-bind="formConfig"
:expand="expand" :expand="expand"
:showExpand="showExpand" :showExpand="showExpand"
:expandAll="expandAll"
:showExpandAll="showExpandAll"
:model="formModel" :model="formModel"
@finish="formFinish" /> @finish="formFinish" />
</div> </div>
<a-row type="flex" class="ns-table-main"> <div class="ns-table-main">
<!-- <a-col :flex="getTreeWidth" v-if="!isEmpty(treeConfig)"> <ns-table-header
<ns-tree v-if="getTreeData.length" v-bind="getTreeBindValue" @select="treeSelect" /> v-if="!isEmpty(headerActions) || tableTitle"
</a-col> --> :headerActions="headerActions"
<a-col flex="auto"> :searchData="formModel"
<ns-table-header :tableTitle="tableTitle"
v-if="!isEmpty(headerActions) || tableTitle" :data="tableState.selectedRows">
:headerActions="headerActions" <template #header="data">
:searchData="formModel" <slot name="header" v-bind="data || {}"></slot>
:tableTitle="tableTitle" </template>
:data="tableState.selectedRows"> </ns-table-header>
<template #header="data"> <ns-basic-table ref="tableElRef" v-bind="getTableBindValues" :dataSource="tableData">
<slot name="header" v-bind="data || {}"></slot> <template #emptyText>
<template v-if="tableState.loadError">
<div class="ns-table-content">
<div class="fetch-error">
<p>{{ tableState.loadErrorMessage }}</p>
<ns-button type="primary" ghost @click="reload">重新加载</ns-button></div
></div
>
</template> </template>
</ns-table-header> <template v-else-if="tableState.loading"
<ns-basic-table ref="tableElRef" v-bind="getTableBindValues" :dataSource="tableData"> ><div class="ns-table-content"></div
<template #emptyText> ></template>
<template v-if="tableState.loadError"> <template v-else>
<div class="ns-table-content"> <div class="ns-table-content"> <a-empty /> </div>
<div class="fetch-error">
<p>{{ tableState.loadErrorMessage }}</p>
<ns-button type="primary" ghost @click="reload">重新加载</ns-button></div
></div
>
</template>
<template v-else-if="tableState.loading"
><div class="ns-table-content"></div
></template>
<template v-else>
<div class="ns-table-content"> <a-empty /> </div>
</template>
</template> </template>
</template>
<template #[item]="data" v-for="item in Object.keys($slots)" :key="item"> <template #[item]="data" v-for="item in Object.keys($slots)" :key="item">
<slot :name="item" v-bind="data || {}"></slot> <slot :name="item" v-bind="data || {}"></slot>
<template v-if="item === 'bodyCell'"> <template v-if="item === 'bodyCell'">
<template v-if="data?.column?.textEllipsis"> <template v-if="data?.column?.textEllipsis">
<span
class="tool-tips"
:style="{ width: `${data.column.textWidth || data.column.width}px` }">
<ns-tooltip
placement="top"
v-if="
data.column.customRender
? data.column.customRender(data)
: data.record[data.column.dataIndex]
">
<template #title>
<span>{{
data.column.customRender
? data.column.customRender(data)
: data.record[data.column.dataIndex] || '-'
}}</span>
</template>
<span class="text-ellipsis">{{
data.column.customRender
? data.column.customRender(data)
: data.record[data.column.dataIndex] || '-'
}}</span>
</ns-tooltip>
<span class="text-ellipsis" v-else> - </span>
</span>
</template>
<template v-if="data.column.dataIndex === 'tableAction'">
<ns-table-action
:data="data.record"
:searchData="formModel"
:columnActions="getColumnActions" />
</template>
<template v-if="data.column.edit">
<ns-table-cell
:value="data.text"
:record="data.record"
:column="data.column"
:index="data.index" />
</template>
</template>
<template v-if="item === 'footer'">
<ns-table-footer :footerActions="footerActions" :data="ediRowData" />
</template>
</template>
<template #bodyCell="data" v-if="!Object.keys($slots).includes('bodyCell')">
<template v-if="data.column.textEllipsis">
<span <span
class="tool-tips" class="tool-tips"
:style="{ width: `${data.column.textWidth || data.column.width}px` }"> :style="{ width: `${data.column.textWidth || data.column.width}px` }">
@@ -155,15 +107,61 @@
:index="data.index" /> :index="data.index" />
</template> </template>
</template> </template>
<template v-if="item === 'footer'">
<template
#footer
v-if="!Object.keys($slots).includes('footer') && !isEmpty(footerActions)">
<ns-table-footer :footerActions="footerActions" :data="ediRowData" /> <ns-table-footer :footerActions="footerActions" :data="ediRowData" />
</template> </template>
</ns-basic-table> </template>
</a-col>
</a-row> <template #bodyCell="data" v-if="!Object.keys($slots).includes('bodyCell')">
<template v-if="data.column.textEllipsis">
<span
class="tool-tips"
:style="{ width: `${data.column.textWidth || data.column.width}px` }">
<ns-tooltip
placement="top"
v-if="
data.column.customRender
? data.column.customRender(data)
: data.record[data.column.dataIndex]
">
<template #title>
<span>{{
data.column.customRender
? data.column.customRender(data)
: data.record[data.column.dataIndex] || '-'
}}</span>
</template>
<span class="text-ellipsis">{{
data.column.customRender
? data.column.customRender(data)
: data.record[data.column.dataIndex] || '-'
}}</span>
</ns-tooltip>
<span class="text-ellipsis" v-else> - </span>
</span>
</template>
<template v-if="data.column.dataIndex === 'tableAction'">
<ns-table-action
:data="data.record"
:searchData="formModel"
:columnActions="getColumnActions" />
</template>
<template v-if="data.column.edit">
<ns-table-cell
:value="data.text"
:record="data.record"
:column="data.column"
:index="data.index" />
</template>
</template>
<template
#footer
v-if="!Object.keys($slots).includes('footer') && !isEmpty(footerActions)">
<ns-table-footer :footerActions="footerActions" :data="ediRowData" />
</template>
</ns-basic-table>
</div>
</a-spin> </a-spin>
</div> </div>
</div> </div>
@@ -677,6 +675,13 @@
min-width: 0; min-width: 0;
} }
} }
:deep(.ant-spin-container) {
display: flex;
flex-direction: column;
.ns-table-main {
height: 100%;
}
}
.ns-table-content { .ns-table-content {
// background: #e5ebf0; // background: #e5ebf0;
margin: 16px; margin: 16px;

View File

@@ -14,11 +14,12 @@ export const formConfig = {
flex: { flex: {
// layout: 'horizontal', // layout: 'horizontal',
class: 'ns-flex-form ns-flex-form-horizontal', class: 'ns-flex-form ns-flex-form-horizontal',
wrapperCol: { span: 16 }, wrapperCol: { span: 24 },
span: 7, labelCol: { span: 0 },
span: 6,
sm: null, //≥576px <=768 sm: null, //≥576px <=768
lg: null, //>= 768 lg: null, //>= 768
gutter: [0, 0], gutter: [20, 0],
justify: 'space-between', justify: 'space-between',
}, },
flexv2: { flexv2: {

View File

@@ -163,6 +163,24 @@ a {
color: @primary-color; color: @primary-color;
} }
// 自定义的title样式
.ns-title-extra-box {
position: relative;
padding-left: 9px;
&::before {
content: '';
position: absolute;
left: 0;
top: 50%;
transform: translateY(-50%);
height: 13px;
width: 3px;
border-radius: 1px;
background-color: @primary-color;
}
}
//状态颜色 //状态颜色
.commonStatus { .commonStatus {
&::before { &::before {

View File

@@ -61,5 +61,6 @@
// main-content // main-content
@ns-content-bg: #f1f2f6; @ns-content-bg: #f1f2f6;
@ns-box-shadow: 0px 5px 16px #e4e6e8; @ns-box-shadow: 0px 5px 16px #e4e6e8;
@ns-content-box-shadow: 0px 0px 16px #e4e6e8;
@ns-gap: 20px; @ns-gap: 20px;
@ns-border-radius: 12px; @ns-border-radius: 12px;

View File

@@ -15,8 +15,6 @@
import { tableProps } from '/nerv-lib/component/table/props'; import { tableProps } from '/nerv-lib/component/table/props';
import { PropTypes } from '/nerv-lib/util/type'; import { PropTypes } from '/nerv-lib/util/type';
import { cloneDeep, get, isArray } from 'lodash-es'; import { cloneDeep, get, isArray } from 'lodash-es';
tableProps.expand = PropTypes.bool.def(false);
export default defineComponent({ export default defineComponent({
name: 'NsViewListTable', name: 'NsViewListTable',
props: { props: {
@@ -104,46 +102,62 @@
<style lang="less" scoped> <style lang="less" scoped>
//关闭 sticky 模式 底部滚动条 //关闭 sticky 模式 底部滚动条
@gap: 16px; @gap: 16px;
@border-gap: @gap solid #e5ebf0; @border-gap: @gap solid @ns-content-bg;
:deep(.ns-table-container) {
// border-top: @border-gap;
.ns-table-search {
border-radius: @ns-border-radius;
}
}
:deep(.ns-table) { // 以防样式串
.ns-part-tree { .ns-list-table:not(.ant-drawer-body > *):not(.ant-form > *) {
border-right: @border-gap; height: 100%;
height: calc(100vh - 158px); background-color: @ns-content-bg;
} :deep(.ns-table) {
.ns-table-main { height: inherit;
padding: 0px @gap; .ns-table-container,
border-top: @border-gap; .ns-part-tree,
// margin: 16px; .ant-spin-container {
// background-color: #fff; height: inherit;
} }
.ns-table-search {
padding: @gap @gap 0; .ns-part-tree,
// margin: 16px; .ns-table-search,
background: #fff; .ns-table-main {
// border-width: 16px 0 16px 0px; background-color: @white;
// border-color: #e5ebf0; border-radius: @ns-border-radius;
// border-style: solid; box-shadow: @ns-content-box-shadow;
// border-top: 16px solid #e5ebf0; }
}
.ns-table-header { .ns-table-container {
// position: sticky; gap: @ns-gap;
z-index: 3; }
top: 0; .ns-part-tree {
left: 0; }
background-color: @white; .ns-part-table {
} border-radius: @ns-border-radius;
.ant-table-sticky-scroll { }
display: none !important; .ns-table-main {
} padding: 0px @gap;
.ns-basic-table { margin-top: @ns-gap;
padding-top: @gap; background-color: @white;
box-shadow: @ns-content-box-shadow;
// border-top: @border-gap;
// margin: 16px;
// background-color: #fff;
}
.ns-table-search {
padding: @gap @gap 0;
}
.ns-table-header {
// position: sticky;
z-index: 3;
top: 0;
left: 0;
background-color: @white;
}
.ant-table-sticky-scroll {
display: none !important;
}
.ns-basic-table {
padding-top: @gap;
}
} }
} }

View File

@@ -339,8 +339,8 @@
height: 100%; height: 100%;
background-color: @white; background-color: @white;
border-radius: @ns-border-radius; border-radius: @ns-border-radius;
overflow-y: auto; // overflow-y: auto;
overflow-x: hidden; // overflow-x: hidden;
// margin: 0 16px 16px 16px; // margin: 0 16px 16px 16px;
} }
.ns-content-main { .ns-content-main {