|
|
@@ -0,0 +1,121 @@
|
|
|
+<template>
|
|
|
+ <div :style="mainStyle" class="flex overflow-hidden">
|
|
|
+ <div class="flex box-border" :style="tabMainStyle">
|
|
|
+ <div
|
|
|
+ class="flex-1 shrink-0 grid place-items-center box-border"
|
|
|
+ v-for="(item, index) in children || []"
|
|
|
+ :key="index"
|
|
|
+ :style="activeIndex === index ? activeStyle : styleMap?.itemsStyle"
|
|
|
+ >
|
|
|
+ {{ item.name }}
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ <div class="w-auto h-auto flex-1"></div>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script setup lang="ts">
|
|
|
+import { computed, type CSSProperties } from 'vue'
|
|
|
+import { useWidgetStyle, getStyle } from '../hooks/useWidgetStyle'
|
|
|
+import { useProjectStore } from '@/store/modules/project'
|
|
|
+import defaultStyle from './style.json'
|
|
|
+
|
|
|
+const props = defineProps<{
|
|
|
+ width: number
|
|
|
+ height: number
|
|
|
+ styles: any
|
|
|
+ state: string
|
|
|
+ part: string
|
|
|
+ scrollbar: string
|
|
|
+ size: number
|
|
|
+ position: string
|
|
|
+ children?: any[]
|
|
|
+ activeIndex: number
|
|
|
+}>()
|
|
|
+
|
|
|
+const styleMap = useWidgetStyle({
|
|
|
+ widget: 'lv_tabview',
|
|
|
+ props
|
|
|
+})
|
|
|
+
|
|
|
+const projectStore = useProjectStore()
|
|
|
+
|
|
|
+// 根据位置动态调整样式
|
|
|
+const tabMainStyle = computed((): CSSProperties => {
|
|
|
+ const { position = 'top', size } = props
|
|
|
+ return ['left', 'right'].includes(position)
|
|
|
+ ? {
|
|
|
+ width: `${size}px`,
|
|
|
+ height: '100%',
|
|
|
+ flexDirection: 'column',
|
|
|
+ ...styleMap.value?.tabStyle
|
|
|
+ }
|
|
|
+ : {
|
|
|
+ height: `${size}px`,
|
|
|
+ width: '100%',
|
|
|
+ flexDirection: 'row',
|
|
|
+ ...styleMap.value?.tabStyle
|
|
|
+ }
|
|
|
+})
|
|
|
+
|
|
|
+// 激活样式
|
|
|
+const activeStyle = computed(() => {
|
|
|
+ const styles = props.styles
|
|
|
+
|
|
|
+ const itemStyle = styles.find(
|
|
|
+ (item) => item?.part?.name === 'items' && item.part?.state === 'checked'
|
|
|
+ )
|
|
|
+
|
|
|
+ const globalItemStyle = projectStore.globalStyle
|
|
|
+ ?.find((item) => item.widget === 'lv_tabview')
|
|
|
+ ?.part?.find((item) => item.partName === 'items')
|
|
|
+ ?.state?.find((item) => item.state === 'checked')?.style
|
|
|
+
|
|
|
+ const defaultItemStyle = defaultStyle.part
|
|
|
+ .find((item) => item.partName === 'items')
|
|
|
+ ?.state.find((item) => item.state === 'checked')?.style
|
|
|
+
|
|
|
+ const style = itemStyle || globalItemStyle || defaultItemStyle
|
|
|
+
|
|
|
+ let styleMap: CSSProperties = {}
|
|
|
+
|
|
|
+ Object.keys(style || {}).forEach((key) => {
|
|
|
+ // 合并样式
|
|
|
+ styleMap = {
|
|
|
+ ...styleMap,
|
|
|
+ ...getStyle(key, style?.[key])
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ return styleMap
|
|
|
+})
|
|
|
+
|
|
|
+// 动态计算main样式
|
|
|
+const mainStyle = computed(() => {
|
|
|
+ const { position = 'top' } = props
|
|
|
+ const otherStyle: CSSProperties = {}
|
|
|
+
|
|
|
+ if (position === 'top') {
|
|
|
+ otherStyle.flexDirection = 'column'
|
|
|
+ }
|
|
|
+
|
|
|
+ if (position === 'left') {
|
|
|
+ otherStyle.flexDirection = 'row'
|
|
|
+ }
|
|
|
+
|
|
|
+ if (position === 'right') {
|
|
|
+ otherStyle.flexFlow = 'row-reverse'
|
|
|
+ }
|
|
|
+
|
|
|
+ if (position === 'bottom') {
|
|
|
+ otherStyle.flexFlow = 'column-reverse'
|
|
|
+ }
|
|
|
+
|
|
|
+ return {
|
|
|
+ ...styleMap.value?.mainStyle,
|
|
|
+ ...otherStyle
|
|
|
+ }
|
|
|
+})
|
|
|
+</script>
|
|
|
+
|
|
|
+<style scoped></style>
|