| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479 |
- const n = `<template>
- <div class="form-layout" ref="layout">
- <a-spin :spinning="loading">
- <div class="tools" ref="toolsRef" v-if="title || subTitle || $slots.otherBtns">
- <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" size="small">
- <a-step :title="step" v-for="step in steps" :key="step" :disabled="true" />
- </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-content">
- <div
- class="border-top"
- :style="{
- width: borderWidth
- }"
- ></div>
- <div class="form-layout-main-scroll" ref="mainScroll">
- <div
- class="form-layout-main"
- ref="formMain"
- :class="{ whiteBg: !!$slots.form || !!$slots.collapses }"
- :style="{
- width: formWidth
- }"
- id="form-container"
- >
- <div class="form-container-wrap" :style="formStyle" v-if="$slots.form">
- <slot name="form" />
- </div>
- <div class="collapses-content-wrap" v-if="$slots.collapses">
- <div class="collapese-container">
- <slot name="collapses" />
- </div>
- </div>
- </div>
- </div>
- <div class="collapses-nav" v-if="showAnchor && $slots.collapses" :style="absStyle">
- <s-anchor el="form-layout-main-scroll"></s-anchor>
- </div>
- </div>
- <div class="modal">
- <slot name="other" />
- </div>
- <div class="form-fixed-footer">
- <a-space :size="spaceSize">
- <a-button v-if="goBack" @click="rollback" class="btn">
- <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>
- <div class="calc-width" ref="caclWidth" :style="{ width: width }"></div>
- </a-spin>
- </div>
- </template>
- <script setup>
- import { computed, nextTick, onMounted, onUnmounted, ref, useSlots, watch } from 'vue'
- defineOptions({ name: 'SFormLayout' })
- const props = defineProps({
- // 手动指定内容高度,单位 px;0 表示自动撑满
- viewHeight: {
- type: Number,
- default: 0
- },
- // 是否显示右侧锚点导航
- showAnchor: {
- type: Boolean,
- default: true
- },
- // 表单 loading 遮罩
- loading: {
- type: Boolean,
- default: false
- },
- // 页面标题
- title: {
- type: String,
- required: true
- },
- // 标题右侧副标题
- subTitle: {
- type: String,
- default: ''
- },
- // 底部按钮是否显示图标
- showBtnIcon: {
- type: Boolean,
- default: true
- },
- // 步骤条配置,传了才显示步骤区
- steps: {
- type: Array,
- default: () => []
- },
- // 步骤条默认选中下标
- stepDefaultActive: {
- type: Number,
- default: 0
- },
- // 切换步骤前的校验函数,返回 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: window.$l('保存')
- },
- // 表单内容区宽度,默认 1000px
- width: {
- type: String,
- default: '1000px'
- }
- })
- const emit = defineEmits(['footer-callback', 'tabsChange'])
- const slots = useSlots()
- // ---------- 模板 ref ----------
- const layout = ref(null)
- const mainScroll = ref(null)
- const toolsRef = ref(null)
- const stepRef = ref(null)
- const tabsRef = ref(null)
- const formMain = ref(null)
- const caclWidth = ref(null)
- const spaceSize = ref(8)
- // ---------- 状态 ----------
- const absStyle = ref({})
- const formWidth = ref('100%')
- const borderWidth = ref(0)
- // 高度类状态已删除:布局高度全部交给 CSS flex,不再做 JS 测量
- const stepActive = ref(0)
- // 页签取值字段:tabKey.value 未传时回退到 label,避免所有 pane 的 key 都是 undefined
- const tabKeyValue = computed(() => (props.tabKey && props.tabKey.value) || 'value')
- // 当前页签受控维护,保证首屏高亮项与 pane 的 key 是同一个值(原来取 label 而 key 取 value,两者不同则首屏不高亮)
- 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 })
- const initForm = computed(() => props.showAnchor && props.width)
- watch(initForm, () => handClacStyle(), { immediate: true, deep: true })
- // 高度全部由 CSS flex 决定(根 100% → 标题条/页签定高 → 表单区吃剩余 → 底栏定高),
- // 这里不需要再测量任何高度;宽度相关计算在 handClacStyle 里。
- function initStyle() {
- handClacStyle()
- }
- function rollback() {
- emit('footer-callback', 'cancel')
- }
- function handPrev() {
- stepActive.value--
- emit('footer-callback', 'prev', stepActive.value)
- }
- function handNext() {
- if (!window.$utils.isFunction(props.stepValid)) {
- 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) {
- // 同步受控页签,再按 key 找出整条配置回传(回传整条 item 是既有约定,不改)
- activeTabKey.value = v
- const item = props.tabs.find((i) => i[tabKeyValue.value] === v)
- emit('tabsChange', item)
- }
- // 锚点定位与表单区宽度自适应(宽度计算,与高度无关)
- function handClacStyle() {
- nextTick(() => {
- const style = {}
- const sEl = mainScroll.value?.offsetWidth || 0
- const mEl = caclWidth.value?.offsetWidth || 0
- if (mEl + 200 > sEl) {
- style.right = '0px'
- } else {
- style.left = props.width
- }
- absStyle.value = style
- if (props.showAnchor && slots.collapses) {
- formWidth.value = mEl + 200 > sEl ? \`\${sEl - 200}px\` : props.width
- } else {
- formWidth.value = mEl > sEl ? \`\${sEl}px\` : props.width
- }
- borderWidth.value = formMain.value.offsetWidth - 10 + 'px'
- })
- }
- // ---------- 生命周期 ----------
- let resizeObserver = null
- onMounted(() => {
- initStyle()
- stepActive.value = props.stepDefaultActive
- if (window.ResizeObserver && layout.value) {
- resizeObserver = new ResizeObserver(() => {
- initStyle()
- handClacStyle()
- })
- resizeObserver.observe(layout.value)
- }
- })
- onUnmounted(() => {
- resizeObserver?.disconnect()
- resizeObserver = null
- })
- defineExpose({
- save,
- rollback,
- handNext,
- handPrev,
- stepActive,
- formWidth
- })
- <\/script>
- <style lang="less" scoped>
- .form-layout {
- height: 100%;
- min-height: 0;
- overflow: hidden;
- display: flex;
- flex-direction: column;
- box-sizing: border-box;
- :deep(.ant-spin-nested-loading),
- :deep(.ant-spin-container) {
- flex: 1 1 auto;
- min-height: 0;
- display: flex;
- flex-direction: column;
- width: 100%;
- }
- }
- .tools {
- flex: 0 0 60px;
- height: 60px;
- display: flex;
- justify-content: space-between;
- align-items: center;
- .sub-title-wrap {
- margin: 10px 0 0;
- font-size: 16px;
- // text-indent: 32px;
- }
- .rollback {
- margin-right: 10px;
- color: var(--s-color);
- cursor: pointer;
- }
- .title {
- color: var(--s-text-color);
- font-size: 18px;
- font-weight: 500;
- }
- }
- .form-layout-main-content {
- position: relative;
- flex: 1 1 auto;
- min-height: 0;
- display: flex;
- flex-direction: column;
- .collapses-nav {
- width: 200px;
- position: absolute;
- top: 0;
- right: 0;
- z-index: 9;
- .anchor-link-item {
- width: 100%;
- height: 32px;
- }
- }
- }
- .form-layout-main-scroll {
- flex: 1 1 auto;
- min-height: 0;
- overflow: hidden auto;
- // 必须是 flex 容器,否则里面的 .form-layout-main 拿不到 flex:1,表单区退回内容高度
- display: flex;
- flex-direction: column;
- }
- .border-top {
- position: absolute;
- top: 0;
- left: 10px;
- z-index: 2;
- border-top: 10px solid var(--s-bg-color-container);
- border-radius: 8px 8px 0 0;
- }
- .form-layout-main {
- flex: 1 1 auto;
- min-height: 0;
- padding: 10px;
- box-sizing: border-box;
- position: relative;
- // 表单插槽内容要能吃满这个区域(业务在里面放 s-filter-table-toolbar 之类)
- display: flex;
- flex-direction: column;
- }
- .form-layout-main.whiteBg {
- background-color: var(--s-bg-color-container);
- border-radius: 6px 6px 0 0;
- }
- .form-container-wrap {
- width: 100%;
- flex: 1 1 auto;
- min-height: 0;
- }
- .collapses-content-wrap {
- width: 100%;
- display: flex;
- justify-content: flex-start;
- align-content: flex-start;
- .collapese-container {
- flex: 1;
- }
- }
- .step-wrap {
- width: 100%;
- flex: 0 0 auto;
- background-color: var(--s-bg-color-container);
- border-bottom: 1px solid var(--s-border-color-split);
- margin-bottom: 16px;
- }
- .tabs-wrap {
- flex: 0 0 auto;
- }
- .modal {
- flex: 0 0 auto;
- }
- .form-fixed-footer {
- width: 100%;
- height: 60px;
- // 由 position:fixed 改为 flex 定高贴底:不脱离文档流,表单区自动让位、不被遮挡
- flex: 0 0 60px;
- display: flex;
- justify-content: flex-start;
- align-items: center;
- // padding: 0 24px;
- 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;
- }
- </style>
- <style lang="less" scoped>
- :deep(.tabs-wrap) {
- 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 .ant-tabs-tab) {
- border-color: transparent;
- background: transparent;
- }
- </style>
- `;
- export {
- n as default
- };
|