| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327 |
- const n = `<template>
- <div class="s-skeleton-layout" ref="layout">
- <div class="tools" ref="tools">
- <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">
- <span class="item-btn" v-for="btn in buttons" :key="btn.key">
- <a-button
- class="btn"
- v-action="btn.action || btn.key"
- v-show="btn.show !== false"
- :disabled="!!btn.disabled"
- :type="btn.type || btn.key === 'add' ? 'primary' : 'default'"
- @click="btnCallback(btn)"
- >
- <template #icon>
- <component v-if="renderIcon(btn)" :is="renderIcon(btn)" />
- </template>
- {{ $l(btn.name) }}
- </a-button>
- </span>
- <slot name="otherBtns" />
- <a-button
- class="btn"
- v-if="steps.length"
- :disabled="stepActive === stepDefaultActive"
- @click="handStepChange('prev')"
- >
- <arrow-left-outlined />{{ $l('上一步') }}
- </a-button>
- <a-button
- class="btn"
- type="primary"
- v-if="steps.length"
- :disabled="stepActive === steps.length - 1"
- @click="handStepChange('next')"
- >
- <arrow-right-outlined />{{ $l('下一步') }}
- </a-button>
- <a-button type="primary" @click="handStepConfirm">
- <save-outlined />
- {{ $l('确认') }}
- </a-button>
- </a-space>
- </div>
- </div>
- <div class="skeleton-layout-main">
- <div
- class="side s-side-tree"
- ref="side"
- :style="{ width: sideWidth + 'px' }"
- v-if="$slots.tree"
- >
- <slot name="tree" />
- </div>
- <div class="side-bar s-theme-bg" v-if="$slots.tree" v-sidedrag />
- <div class="skeleton-content">
- <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="skeleton-container">
- <slot></slot>
- </div>
- </div>
- </div>
- <div class="other" ref="other">
- <slot name="other" />
- </div>
- <!-- 底栏:flex 定高,跟随容器贴底;不 fixed、不脱离文档流,内容区自动让位不被遮挡 -->
- <div class="skeleton-footer" ref="footer" v-if="$slots.footer">
- <a-space :size="spaceSize">
- <slot name="footer" />
- </a-space>
- </div>
- </div>
- </template>
- <script setup>
- import { computed, ref, watch } from 'vue'
- import { createSideDrag } from '../../utils/side-drag'
- defineOptions({ name: 'SSkeletonLayout' })
- const emit = defineEmits(['tabsChange', 'btnCallback', 'stepChange', 'stepConfirm'])
- const props = defineProps({
- // 页面标题
- title: {
- type: String,
- required: true
- },
- // 页面副标题
- subTitle: {
- type: String,
- default: ''
- },
- // 工具条按钮:[{ key, name, icon, type, show, disabled, action }]
- buttons: {
- type: Array,
- default: () => []
- },
- // 页签配置,传了才显示页签区
- tabs: {
- type: Array,
- default: () => []
- },
- // 页签字段映射:{ label, value }
- tabKey: {
- type: Object,
- default: () => ({
- label: 'label',
- value: 'value'
- })
- },
- // 步骤条配置,传了才显示步骤区
- steps: {
- type: Array,
- default: () => []
- }
- })
- const layout = ref(null)
- const tools = ref(null)
- const other = ref(null)
- const footer = ref(null)
- const sideWidth = ref(232)
- const activeTabKey = ref('')
- const tabsRef = ref(null)
- const stepRef = ref(null)
- const stepActive = ref(0)
- const spaceSize = ref(8)
- const stepDefaultActive = 0
- 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]
- }
- }
- const tabKeyValue = computed(() => (props.tabKey && props.tabKey.value) || 'value')
- watch(() => props.tabs, syncActiveTab, { immediate: true, deep: true })
- function handTabChange(v) {
- // 同步受控页签,再按 key 找出整条配置回传(回传整条 item 是既有约定,不改)
- activeTabKey.value = v
- const item = props.tabs.find((i) => i[tabKeyValue.value] === v)
- emit('tabsChange', item)
- }
- function handStepChange(v) {
- stepActive.value += v === 'prev' ? -1 : 1
- emit('stepChange', v, stepActive.value)
- }
- function handStepConfirm() {
- emit('stepConfirm', stepActive.value)
- }
- // 图标表:key 对应按钮的 key,值为已全局注册的图标组件名
- const iconMap = {
- add: 'PlusCircleOutlined',
- edit: 'FormOutlined',
- delete: 'DeleteOutlined',
- remove: 'DeleteOutlined',
- import: 'UploadOutlined',
- export: 'DownloadOutlined',
- assign: 'ClusterOutlined',
- execute: 'PlayCircleOutlined',
- pause: 'PauseCircleOutlined',
- resume: 'PoweroffOutlined',
- approve: 'HighlightOutlined',
- setting: 'SettingOutlined',
- TopOfType: 'VerticalAlignTopOutlined',
- TOP: 'VerticalAlignTopOutlined',
- synchronize: 'SyncOutlined'
- }
- // 按钮回调:把 key 抛给业务
- function btnCallback(item) {
- emit('btnCallback', item.key)
- }
- // icon 传字符串直接当组件名用;传 true 按按钮 key 查图标表
- function renderIcon(v) {
- if (typeof v.icon === 'string') {
- return v.icon
- }
- if (typeof v.icon === 'boolean' && v.icon) {
- return iconMap[v.key] || ''
- }
- return ''
- }
- // ---------- 拖拽分隔条指令 ----------
- const vSidedrag = createSideDrag(
- () => sideWidth.value,
- (width) => (sideWidth.value = width),
- { min: 232 }
- )
- <\/script>
- <style lang="less" scoped>
- // 高度实现:纯 CSS flex,零 JS 测量。
- // 根节点撑满父容器,标题条/底栏定高,内容区 flex:1 吃掉剩余高度。
- // 前提:父容器有确定高度(基座 BasicLayout 的 router-view 已带 height);
- // 父容器高度不确定时退化为「按内容撑开」,不会像旧版那样测量成 0 直接塌掉。
- .s-skeleton-layout {
- height: 100%;
- min-height: 0;
- display: flex;
- flex-direction: column;
- overflow: hidden;
- }
- .tools {
- 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;
- }
- }
- .skeleton-layout-main {
- flex: 1 1 auto;
- min-height: 0;
- display: flex;
- justify-content: flex-start;
- // stretch(默认)让左右两栏撑满主区高度;写成 flex-start 会让内容区高度退化成 auto,
- // 结果表格不吃剩余高度、整页改由外层滚动
- align-items: stretch;
- border-radius: 6px;
- background-color: var(--s-bg-color-container);
- overflow: hidden;
- }
- .side {
- min-width: 232px;
- padding: 10px;
- box-sizing: border-box;
- overflow: hidden auto;
- }
- .side-bar {
- width: 10px;
- cursor: pointer;
- user-select: none;
- }
- .skeleton-content {
- flex: 1;
- min-width: 0;
- min-height: 0;
- display: flex;
- flex-direction: column;
- overflow: hidden;
- padding: 10px;
- box-sizing: border-box;
- .step-wrap,
- .tabs-wrap {
- flex: 0 0 auto;
- padding: 0 16px;
- box-sizing: border-box;
- }
- .skeleton-container {
- flex: 1 1 auto;
- min-height: 0;
- overflow: hidden auto;
- }
- }
- .other {
- flex: 0 0 auto;
- box-sizing: border-box;
- }
- .skeleton-footer {
- flex: 0 0 60px;
- height: 60px;
- display: flex;
- justify-content: flex-start;
- align-items: center;
- padding: 0 16px;
- border-top: 1px solid var(--s-border-color-split);
- background-color: var(--s-bg-color-container);
- box-sizing: border-box;
- overflow: hidden;
- }
- </style>
- `;
- export {
- n as default
- };
|