SSkeletonLayout2.js 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. const n = `<template>
  2. <div class="s-skeleton-layout" ref="layout">
  3. <div class="tools" ref="tools">
  4. <div class="title">
  5. <span style="margin-right: 10px">{{ title }}</span>
  6. <a-tooltip
  7. placement="topLeft"
  8. v-if="subTitle"
  9. :mouseEnterDelay="0.5"
  10. :mouseLeaveDelay="0.5"
  11. >
  12. <template #title>
  13. {{ subTitle }}
  14. </template>
  15. <InfoCircleOutlined />
  16. </a-tooltip>
  17. </div>
  18. <div class="btns">
  19. <a-space :size="spaceSize">
  20. <span class="item-btn" v-for="btn in buttons" :key="btn.key">
  21. <a-button
  22. class="btn"
  23. v-action="btn.action || btn.key"
  24. v-show="btn.show !== false"
  25. :disabled="!!btn.disabled"
  26. :type="btn.type || btn.key === 'add' ? 'primary' : 'default'"
  27. @click="btnCallback(btn)"
  28. >
  29. <template #icon>
  30. <component v-if="renderIcon(btn)" :is="renderIcon(btn)" />
  31. </template>
  32. {{ $l(btn.name) }}
  33. </a-button>
  34. </span>
  35. <slot name="otherBtns" />
  36. <a-button
  37. class="btn"
  38. v-if="steps.length"
  39. :disabled="stepActive === stepDefaultActive"
  40. @click="handStepChange('prev')"
  41. >
  42. <arrow-left-outlined />{{ $l('上一步') }}
  43. </a-button>
  44. <a-button
  45. class="btn"
  46. type="primary"
  47. v-if="steps.length"
  48. :disabled="stepActive === steps.length - 1"
  49. @click="handStepChange('next')"
  50. >
  51. <arrow-right-outlined />{{ $l('下一步') }}
  52. </a-button>
  53. <a-button type="primary" @click="handStepConfirm">
  54. <save-outlined />
  55. {{ $l('确认') }}
  56. </a-button>
  57. </a-space>
  58. </div>
  59. </div>
  60. <div class="skeleton-layout-main">
  61. <div
  62. class="side s-side-tree"
  63. ref="side"
  64. :style="{ width: sideWidth + 'px' }"
  65. v-if="$slots.tree"
  66. >
  67. <slot name="tree" />
  68. </div>
  69. <div class="side-bar s-theme-bg" v-if="$slots.tree" v-sidedrag />
  70. <div class="skeleton-content">
  71. <div class="step-wrap" ref="stepRef" v-if="steps && steps.length">
  72. <a-steps :current="stepActive" type="navigation" size="small">
  73. <a-step :title="step" v-for="step in steps" :key="step" :disabled="true" />
  74. </a-steps>
  75. </div>
  76. <div class="tabs-wrap" ref="tabsRef" v-if="tabs && tabs.length">
  77. <a-tabs :active-key="activeTabKey" @change="handTabChange">
  78. <a-tab-pane
  79. :tab="tab[tabKey.label]"
  80. v-for="tab in tabs"
  81. :key="tab[tabKeyValue]"
  82. ></a-tab-pane>
  83. </a-tabs>
  84. </div>
  85. <div class="skeleton-container">
  86. <slot></slot>
  87. </div>
  88. </div>
  89. </div>
  90. <div class="other" ref="other">
  91. <slot name="other" />
  92. </div>
  93. <!-- 底栏:flex 定高,跟随容器贴底;不 fixed、不脱离文档流,内容区自动让位不被遮挡 -->
  94. <div class="skeleton-footer" ref="footer" v-if="$slots.footer">
  95. <a-space :size="spaceSize">
  96. <slot name="footer" />
  97. </a-space>
  98. </div>
  99. </div>
  100. </template>
  101. <script setup>
  102. import { computed, ref, watch } from 'vue'
  103. import { createSideDrag } from '../../utils/side-drag'
  104. defineOptions({ name: 'SSkeletonLayout' })
  105. const emit = defineEmits(['tabsChange', 'btnCallback', 'stepChange', 'stepConfirm'])
  106. const props = defineProps({
  107. // 页面标题
  108. title: {
  109. type: String,
  110. required: true
  111. },
  112. // 页面副标题
  113. subTitle: {
  114. type: String,
  115. default: ''
  116. },
  117. // 工具条按钮:[{ key, name, icon, type, show, disabled, action }]
  118. buttons: {
  119. type: Array,
  120. default: () => []
  121. },
  122. // 页签配置,传了才显示页签区
  123. tabs: {
  124. type: Array,
  125. default: () => []
  126. },
  127. // 页签字段映射:{ label, value }
  128. tabKey: {
  129. type: Object,
  130. default: () => ({
  131. label: 'label',
  132. value: 'value'
  133. })
  134. },
  135. // 步骤条配置,传了才显示步骤区
  136. steps: {
  137. type: Array,
  138. default: () => []
  139. }
  140. })
  141. const layout = ref(null)
  142. const tools = ref(null)
  143. const other = ref(null)
  144. const footer = ref(null)
  145. const sideWidth = ref(232)
  146. const activeTabKey = ref('')
  147. const tabsRef = ref(null)
  148. const stepRef = ref(null)
  149. const stepActive = ref(0)
  150. const spaceSize = ref(8)
  151. const stepDefaultActive = 0
  152. const syncActiveTab = () => {
  153. const list = props.tabs || []
  154. if (!list.length) {
  155. activeTabKey.value = ''
  156. return
  157. }
  158. const field = tabKeyValue.value
  159. if (!list.some((tab) => tab && tab[field] === activeTabKey.value)) {
  160. activeTabKey.value = list[0][field]
  161. }
  162. }
  163. const tabKeyValue = computed(() => (props.tabKey && props.tabKey.value) || 'value')
  164. watch(() => props.tabs, syncActiveTab, { immediate: true, deep: true })
  165. function handTabChange(v) {
  166. // 同步受控页签,再按 key 找出整条配置回传(回传整条 item 是既有约定,不改)
  167. activeTabKey.value = v
  168. const item = props.tabs.find((i) => i[tabKeyValue.value] === v)
  169. emit('tabsChange', item)
  170. }
  171. function handStepChange(v) {
  172. stepActive.value += v === 'prev' ? -1 : 1
  173. emit('stepChange', v, stepActive.value)
  174. }
  175. function handStepConfirm() {
  176. emit('stepConfirm', stepActive.value)
  177. }
  178. // 图标表:key 对应按钮的 key,值为已全局注册的图标组件名
  179. const iconMap = {
  180. add: 'PlusCircleOutlined',
  181. edit: 'FormOutlined',
  182. delete: 'DeleteOutlined',
  183. remove: 'DeleteOutlined',
  184. import: 'UploadOutlined',
  185. export: 'DownloadOutlined',
  186. assign: 'ClusterOutlined',
  187. execute: 'PlayCircleOutlined',
  188. pause: 'PauseCircleOutlined',
  189. resume: 'PoweroffOutlined',
  190. approve: 'HighlightOutlined',
  191. setting: 'SettingOutlined',
  192. TopOfType: 'VerticalAlignTopOutlined',
  193. TOP: 'VerticalAlignTopOutlined',
  194. synchronize: 'SyncOutlined'
  195. }
  196. // 按钮回调:把 key 抛给业务
  197. function btnCallback(item) {
  198. emit('btnCallback', item.key)
  199. }
  200. // icon 传字符串直接当组件名用;传 true 按按钮 key 查图标表
  201. function renderIcon(v) {
  202. if (typeof v.icon === 'string') {
  203. return v.icon
  204. }
  205. if (typeof v.icon === 'boolean' && v.icon) {
  206. return iconMap[v.key] || ''
  207. }
  208. return ''
  209. }
  210. // ---------- 拖拽分隔条指令 ----------
  211. const vSidedrag = createSideDrag(
  212. () => sideWidth.value,
  213. (width) => (sideWidth.value = width),
  214. { min: 232 }
  215. )
  216. <\/script>
  217. <style lang="less" scoped>
  218. // 高度实现:纯 CSS flex,零 JS 测量。
  219. // 根节点撑满父容器,标题条/底栏定高,内容区 flex:1 吃掉剩余高度。
  220. // 前提:父容器有确定高度(基座 BasicLayout 的 router-view 已带 height);
  221. // 父容器高度不确定时退化为「按内容撑开」,不会像旧版那样测量成 0 直接塌掉。
  222. .s-skeleton-layout {
  223. height: 100%;
  224. min-height: 0;
  225. display: flex;
  226. flex-direction: column;
  227. overflow: hidden;
  228. }
  229. .tools {
  230. height: 60px;
  231. display: flex;
  232. justify-content: space-between;
  233. align-items: center;
  234. .sub-title-wrap {
  235. margin: 10px 0 0;
  236. font-size: 16px;
  237. // text-indent: 32px;
  238. }
  239. .rollback {
  240. margin-right: 10px;
  241. color: var(--s-color);
  242. cursor: pointer;
  243. }
  244. .title {
  245. color: var(--s-text-color);
  246. font-size: 18px;
  247. font-weight: 500;
  248. }
  249. }
  250. .skeleton-layout-main {
  251. flex: 1 1 auto;
  252. min-height: 0;
  253. display: flex;
  254. justify-content: flex-start;
  255. // stretch(默认)让左右两栏撑满主区高度;写成 flex-start 会让内容区高度退化成 auto,
  256. // 结果表格不吃剩余高度、整页改由外层滚动
  257. align-items: stretch;
  258. border-radius: 6px;
  259. background-color: var(--s-bg-color-container);
  260. overflow: hidden;
  261. }
  262. .side {
  263. min-width: 232px;
  264. padding: 10px;
  265. box-sizing: border-box;
  266. overflow: hidden auto;
  267. }
  268. .side-bar {
  269. width: 10px;
  270. cursor: pointer;
  271. user-select: none;
  272. }
  273. .skeleton-content {
  274. flex: 1;
  275. min-width: 0;
  276. min-height: 0;
  277. display: flex;
  278. flex-direction: column;
  279. overflow: hidden;
  280. padding: 10px;
  281. box-sizing: border-box;
  282. .step-wrap,
  283. .tabs-wrap {
  284. flex: 0 0 auto;
  285. padding: 0 16px;
  286. box-sizing: border-box;
  287. }
  288. .skeleton-container {
  289. flex: 1 1 auto;
  290. min-height: 0;
  291. overflow: hidden auto;
  292. }
  293. }
  294. .other {
  295. flex: 0 0 auto;
  296. box-sizing: border-box;
  297. }
  298. .skeleton-footer {
  299. flex: 0 0 60px;
  300. height: 60px;
  301. display: flex;
  302. justify-content: flex-start;
  303. align-items: center;
  304. padding: 0 16px;
  305. border-top: 1px solid var(--s-border-color-split);
  306. background-color: var(--s-bg-color-container);
  307. box-sizing: border-box;
  308. overflow: hidden;
  309. }
  310. </style>
  311. `;
  312. export {
  313. n as default
  314. };