gi-component 0.0.38 → 0.0.39

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "gi-component",
3
3
  "type": "module",
4
- "version": "0.0.38",
4
+ "version": "0.0.39",
5
5
  "description": "Vue3中基于Element Plus二次封装基础组件库",
6
6
  "author": "lin",
7
7
  "license": "MIT",
@@ -0,0 +1,5 @@
1
+ import Descriptions from './src/descriptions.vue'
2
+
3
+ export type DescriptionsInstance = InstanceType<typeof Descriptions>
4
+ export * from './src/type'
5
+ export default Descriptions
@@ -0,0 +1,72 @@
1
+ <template>
2
+ <ElDescriptions :border="border" :column="column" :direction="direction" :size="size" :title="title" :extra="extra">
3
+ <template v-if="$slots.title" #title>
4
+ <slot name="title" />
5
+ </template>
6
+ <template v-if="$slots.extra" #extra>
7
+ <slot name="extra" />
8
+ </template>
9
+ <template v-if="useColumns">
10
+ <ElDescriptionsItem v-for="(col, idx) in columns" :key="col.value ?? idx"
11
+ :label="typeof col.label === 'string' ? col.label : ''" :span="col.span ?? 1" :width="col.width"
12
+ :min-width="col.minWidth" :align="col.align ?? 'left'" :label-align="col.labelAlign" :class-name="col.className"
13
+ :label-class-name="col.labelClassName">
14
+ <template v-if="typeof col.label === 'function'" #label>
15
+ <NodeRenderer :get-node="() => (col.label as (c: DescriptionsColumnItem) => any)(col)" />
16
+ </template>
17
+ <slot v-if="hasColumnSlot(col.value)" :name="col.value" :value="getFieldValue(col)" :data="data" :column="col" />
18
+ <NodeRenderer v-else-if="col.render && data" :get-node="() => col.render!({ value: getFieldValue(col), data, column: col })" />
19
+ <span v-else>{{ getFieldValue(col) }}</span>
20
+ </ElDescriptionsItem>
21
+ </template>
22
+ <template v-else>
23
+ <slot />
24
+ </template>
25
+ </ElDescriptions>
26
+ </template>
27
+
28
+ <script setup lang="ts">
29
+ import type { DescriptionsColumnItem, DescriptionsProps } from './type'
30
+ import { ElDescriptions, ElDescriptionsItem } from 'element-plus'
31
+ import { computed, defineComponent, useSlots } from 'vue'
32
+
33
+ const props = withDefaults(defineProps<DescriptionsProps>(), {
34
+ columns: () => [],
35
+ data: () => ({}),
36
+ border: false,
37
+ column: 3,
38
+ direction: 'horizontal',
39
+ size: 'default',
40
+ title: '',
41
+ extra: ''
42
+ })
43
+
44
+ defineSlots<{
45
+ default?: () => any
46
+ title?: () => any
47
+ extra?: () => any
48
+ }>()
49
+
50
+ const NodeRenderer = defineComponent({
51
+ name: 'NodeRenderer',
52
+ props: {
53
+ getNode: { type: Function, required: true }
54
+ },
55
+ setup(props: { getNode: () => any }) {
56
+ return () => props.getNode()
57
+ }
58
+ })
59
+
60
+ const slots = useSlots()
61
+ const useColumns = computed(() => (props.columns?.length ?? 0) > 0)
62
+
63
+ function hasColumnSlot(name: string | undefined): boolean {
64
+ return !!name && !!(slots as Record<string, unknown>)[name]
65
+ }
66
+
67
+ function getFieldValue(col: DescriptionsColumnItem) {
68
+ if (!props.data || col.value === undefined || col.value === null)
69
+ return ''
70
+ return props.data[col.value]
71
+ }
72
+ </script>
@@ -0,0 +1,44 @@
1
+ import type { VNode } from 'vue'
2
+
3
+ /** 描述列表列配置(对应 data 的字段与展示) */
4
+ export interface DescriptionsColumnItem {
5
+ /** 对应 data 的字段名 */
6
+ value?: string
7
+ /** 标签文本,或返回 VNode 的函数 */
8
+ label?: string | ((columnItem: DescriptionsColumnItem) => VNode)
9
+ /** 列的数量(占据几列) */
10
+ span?: number
11
+ /** 列宽度(如无 border,宽度包含标签与内容) */
12
+ width?: string | number
13
+ /** 列最小宽度,剩余宽度按比例分配给设置了 minWidth 的列 */
14
+ minWidth?: string | number
15
+ /** 列内容对齐方式 */
16
+ align?: 'left' | 'center' | 'right'
17
+ /** 列标签对齐方式(无 border 时用 align) */
18
+ labelAlign?: 'left' | 'center' | 'right'
19
+ /** 列内容自定义类名 */
20
+ className?: string
21
+ /** 列标签自定义类名 */
22
+ labelClassName?: string
23
+ /** 自定义渲染内容:({ value, data, column }) => VNode */
24
+ render?: (params: { value: any; data: Record<string, any>; column: DescriptionsColumnItem }) => VNode
25
+ }
26
+
27
+ export interface DescriptionsProps {
28
+ /** 描述列表配置项,与 data 配合使用 */
29
+ columns?: DescriptionsColumnItem[]
30
+ /** 详情数据(与 columns 配合,按 value 取字段) */
31
+ data?: Record<string, any>
32
+ /** 是否带边框 */
33
+ border?: boolean
34
+ /** 一行 Descriptions Item 的数量 */
35
+ column?: number
36
+ /** 排列方向 */
37
+ direction?: 'vertical' | 'horizontal'
38
+ /** 列表尺寸 */
39
+ size?: 'large' | 'default' | 'small'
40
+ /** 标题文本,显示在左上方,也可用 title 插槽 */
41
+ title?: string
42
+ /** 操作区,显示在右上方,也可用 extra 插槽 */
43
+ extra?: string
44
+ }
@@ -12,6 +12,7 @@ declare module 'vue' {
12
12
  GiCard: typeof import('./components/card/src/card.vue')['default']
13
13
  GiDialog: typeof import('./components/dialog/src/dialog.vue')['default']
14
14
  GiDialogContent: typeof import('./components/dialog/src/dialog-content.vue')['default']
15
+ GiDescriptions: typeof import('./components/descriptions/src/descriptions.vue')['default']
15
16
  GiDot: typeof import('./components/dot/src/dot.vue')['default']
16
17
  GiDrawer: typeof import('./components/drawer/src/drawer.vue')['default']
17
18
  GiEditTable: typeof import('./components/edit-table/src/edit-table.vue')['default']
package/packages/index.ts CHANGED
@@ -2,6 +2,7 @@ import type { App, Component } from 'vue'
2
2
 
3
3
  import Button from './components/button'
4
4
  import Card from './components/card'
5
+ import Descriptions from './components/descriptions'
5
6
  import DialogComponent, { Dialog as DialogFunction } from './components/dialog'
6
7
  import Dot from './components/dot'
7
8
  import Drawer from './components/drawer'
@@ -21,6 +22,7 @@ import './styles/index.scss'
21
22
  // 防止打包时 tree-shake 掉 Dialog.info/success/warning/error(内部只用到 Dialog.open)
22
23
  void [DialogFunction.info, DialogFunction.success, DialogFunction.warning, DialogFunction.error]
23
24
 
25
+ export * from './components/descriptions'
24
26
  export * from './components/dialog'
25
27
  export * from './components/drawer'
26
28
  export * from './components/edit-table'
@@ -33,6 +35,7 @@ export * from './utils'
33
35
  const components = {
34
36
  Button,
35
37
  Card,
38
+ Descriptions,
36
39
  Drawer,
37
40
  Dot,
38
41
  Tabs,
@@ -52,6 +55,7 @@ const components = {
52
55
  // 导出Gi前缀的组件并添加明确类型注解
53
56
  export const GiButton: typeof Button = Button
54
57
  export const GiCard: typeof Card = Card
58
+ export const GiDescriptions: typeof Descriptions = Descriptions
55
59
  export const GiDrawer: typeof Drawer = Drawer
56
60
  export const GiDot: typeof Dot = Dot
57
61
  export const GiTabs: typeof Tabs = Tabs