| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365 |
- const n = `<template>
- <div class="s-form-basic-layout" ref="layoutRef">
- <a-spin :spinning="loading">
- <div class="tools" ref="toolsRef">
- <div class="title">
- <span style="margin-right: 10px">{{ title }}</span>
- <a-tooltip
- placement="topLeft"
- v-if="subTitle"
- :mouseEnterDelay="0.5"
- :mouseLeaveDelay="0.5"
- >
- <template #title>
- {{ subTitle }}
- </template>
- <InfoCircleOutlined />
- </a-tooltip>
- </div>
- <div class="btns">
- <a-space :size="spaceSize">
- <slot name="otherBtns" />
- </a-space>
- </div>
- </div>
- <div class="step-wrap" ref="stepRef" v-if="steps && steps.length">
- <a-steps :current="stepActive" type="navigation">
- <a-step :title="step" v-for="step in steps" :key="step" disabled />
- </a-steps>
- </div>
- <div class="tabs-wrap" ref="tabsRef" v-if="tabs && tabs.length">
- <a-tabs :active-key="activeTabKey" @change="handTabChange">
- <a-tab-pane
- :tab="tab[tabKey.label]"
- v-for="tab in tabs"
- :key="tab[tabKeyValue]"
- ></a-tab-pane>
- </a-tabs>
- </div>
- <div
- class="form-layout-main"
- :class="{ whiteBg: !!$slots.form }"
- :id="commonId"
- ref="formMain"
- >
- <div class="form-container-wrap" :style="formStyle" v-if="$slots.form">
- <slot name="form" />
- </div>
- <div class="collapses-content-wrap" v-if="$slots.collapses">
- <slot name="collapses" />
- </div>
- </div>
- <div class="modal">
- <slot name="other" />
- </div>
- <div class="s-form-basic-fixed-footer" ref="footerRef">
- <a-space :size="spaceSize">
- <a-button v-if="goBack" class="btn" @click="rollback">
- <close-outlined />{{ $l('取消') }}
- </a-button>
- <a-button
- class="btn"
- v-if="steps.length"
- :disabled="stepActive === stepDefaultActive"
- @click="handPrev"
- >
- <arrow-left-outlined />{{ $l('上一步') }}
- </a-button>
- <a-button
- class="btn"
- type="primary"
- v-if="steps.length"
- :disabled="stepActive === steps.length - 1"
- @click="handNext"
- >
- <arrow-right-outlined />{{ $l('下一步') }}
- </a-button>
- <a-button v-if="isShowSave" type="primary" @click="save">
- <save-outlined />
- {{ $l(saveBtnText) }}
- </a-button>
- <slot name="footer" />
- </a-space>
- </div>
- </a-spin>
- </div>
- </template>
- <script setup>
- import { computed, onMounted, ref, watch } from 'vue'
- defineOptions({ name: 'SFormBasicLayout' })
- const props = defineProps({
- // 表单 loading 遮罩
- loading: {
- type: Boolean,
- default: false
- },
- // 表单主体容器的 id(锚点/表单定位用)
- commonId: {
- type: String,
- default: 'form-container'
- },
- // 页面标题
- title: {
- type: String,
- required: true
- },
- // 标题右侧副标题
- subTitle: {
- type: String,
- default: ''
- },
- // 底部按钮是否显示图标
- showBtnIcon: {
- type: Boolean,
- default: true
- },
- // 步骤条配置,传了才显示步骤区
- steps: {
- type: Array,
- default: () => []
- },
- // 步骤条默认选中下标
- stepDefaultActive: {
- type: Number,
- default: 0
- },
- // 上一步校验:返回 Promise<boolean>,resolve(false) 时停在当前步
- stepValid: {
- type: Function,
- default: undefined
- },
- // 页签配置,传了才显示页签区
- tabs: {
- type: Array,
- default: () => []
- },
- // 页签字段映射:{ label, value }
- tabKey: {
- type: Object,
- default: () => ({
- label: 'label',
- value: 'value'
- })
- },
- // 表单区自定义样式
- formStyle: {
- type: Object,
- default: () => ({})
- },
- // 是否显示返回按钮
- goBack: {
- type: Boolean,
- default: true
- },
- // 是否显示保存按钮
- isShowSave: {
- type: Boolean,
- default: true
- },
- // 保存按钮文案
- saveBtnText: {
- type: String,
- default: '保存'
- }
- })
- const emit = defineEmits(['footer-callback', 'tabsChange'])
- // ---------- 模板 ref ----------
- const layoutRef = ref(null)
- const toolsRef = ref(null)
- const stepRef = ref(null)
- const tabsRef = ref(null)
- const formMain = ref(null)
- const footerRef = ref(null)
- const spaceSize = ref(8)
- // ---------- 状态 ----------
- // 高度类状态已删除:布局高度全部交给 CSS flex,不再做 JS 测量
- const stepActive = ref(0)
- // 页签取值字段:tabKey.value 未传时回退到 label,避免 pane 的 key 全是 undefined
- const tabKeyValue = computed(() => (props.tabKey && props.tabKey.value) || 'value')
- // 受控页签,保证首屏高亮项与 pane 的 key 同源
- const activeTabKey = ref('')
- const syncActiveTab = () => {
- const list = props.tabs || []
- if (!list.length) {
- activeTabKey.value = ''
- return
- }
- const field = tabKeyValue.value
- if (!list.some((tab) => tab && tab[field] === activeTabKey.value)) {
- activeTabKey.value = list[0][field]
- }
- }
- watch(() => props.tabs, syncActiveTab, { immediate: true, deep: true })
- // ---------- 方法 ----------
- // 高度全部由 CSS flex 决定(根 100% → 标题条/步骤条/页签定高 → 表单区吃剩余 → 底栏定高贴底),
- // 不再测量任何高度;保留空实现兼容既有调用点。
- function initStyle() {}
- function rollback() {
- emit('footer-callback', 'cancel')
- }
- function handPrev() {
- stepActive.value--
- emit('footer-callback', 'prev', stepActive.value)
- }
- function handNext() {
- if (typeof props.stepValid !== 'function') {
- stepActive.value++
- emit('footer-callback', 'next', stepActive.value)
- return
- }
- props.stepValid(stepActive.value).then((res) => {
- if (res) {
- stepActive.value++
- emit('footer-callback', 'next', stepActive.value)
- }
- })
- }
- function save() {
- emit('footer-callback', 'save')
- }
- function handTabChange(v) {
- activeTabKey.value = v
- const item = props.tabs.find((i) => i[tabKeyValue.value] === v)
- emit('tabsChange', item)
- }
- // ---------- 生命周期 ----------
- onMounted(() => {
- initStyle()
- stepActive.value = props.stepDefaultActive
- })
- defineExpose({
- save,
- rollback,
- handNext,
- handPrev,
- stepActive
- })
- <\/script>
- <style lang="less" scoped>
- // 高度实现:纯 CSS flex,零 JS 测量。
- // 前提:父容器有确定高度(基座 BasicLayout 的 router-view 已带 height)。
- .s-form-basic-layout {
- height: 100%;
- min-height: 0;
- display: flex;
- flex-direction: column;
- overflow: hidden;
- box-sizing: border-box;
- }
- // a-spin 包在中间,把剩余高度透传下去
- .s-form-basic-layout > :deep(.ant-spin-nested-loading),
- .s-form-basic-layout > :deep(.ant-spin-container) {
- flex: 1 1 auto;
- min-height: 0;
- display: flex;
- flex-direction: column;
- }
- .tools {
- flex: 0 0 60px;
- height: 60px;
- display: flex;
- justify-content: space-between;
- align-items: center;
- // border-bottom: 1px solid var(--s-bg-color);
- // padding: 0 16px;
- box-sizing: border-box;
- .title {
- font-size: 18px;
- font-weight: 500;
- }
- }
- .form-layout-main {
- flex: 1 1 auto;
- min-height: 0;
- display: flex;
- flex-direction: column;
- align-items: flex-start;
- overflow-x: hidden;
- overflow-y: auto;
- &::-webkit-scrollbar {
- opacity: 0 !important;
- position: relative;
- z-index: -1;
- display: none;
- }
- }
- .form-layout-main.whiteBg {
- background-color: var(--s-bg-color-container);
- border-radius: 6px 6px 0 0;
- overflow: hidden;
- }
- .form-container-wrap {
- width: 100%;
- flex: 1 1 auto;
- min-height: 0;
- padding: 32px;
- box-sizing: border-box;
- overflow: auto;
- }
- .collapses-content-wrap {
- width: 100%;
- }
- .step-wrap {
- width: 100%;
- }
- .s-form-basic-fixed-footer {
- width: 100%;
- height: 60px;
- // 由 position:fixed 改为 flex 定高贴底:不脱离文档流,表单区自动让位
- flex: 0 0 60px;
- display: flex;
- justify-content: flex-start;
- align-items: center;
- border-top: 1px solid var(--s-border-color-split);
- box-sizing: border-box;
- z-index: 9;
- background-color: var(--s-bg-color-container);
- overflow: hidden;
- }
- :deep(.tabs-wrap) {
- background: var(--s-bg-color);
- overflow: hidden;
- }
- :deep(.tabs-wrap > .ant-tabs-card > .ant-tabs-content) {
- margin-top: -16px;
- margin-bottom: 8px;
- }
- :deep(.tabs-wrap > .ant-tabs-card > .ant-tabs-bar) {
- border-color: var(--s-bg-color);
- }
- :deep(.tabs-wrap > .ant-tabs-card > .ant-tabs-bar .ant-tabs-tab) {
- border-color: transparent;
- background: transparent;
- }
- </style>
- `;
- export {
- n as default
- };
|