gi-component 0.0.10 → 0.0.11

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.10",
4
+ "version": "0.0.11",
5
5
  "description": "Vue3中基于Element Plus二次封装基础组件库",
6
6
  "author": "lin",
7
7
  "license": "MIT",
@@ -0,0 +1,5 @@
1
+ import Drawer from './src/drawer.vue'
2
+
3
+ export type DrawerInstance = InstanceType<typeof Drawer>
4
+ export * from './src/type'
5
+ export default Drawer
@@ -0,0 +1,114 @@
1
+ <template>
2
+ <ElDrawer v-bind="dialogProps" v-model="visible" :class="getClass" :title="props.title" :style="{ ...props.style }">
3
+ <slot>
4
+ <template v-if="typeof props.content === 'string'">
5
+ <p>{{ props.content }}</p>
6
+ </template>
7
+ <template v-if="typeof props.content === 'function'">
8
+ <component :is="props?.content?.()"></component>
9
+ </template>
10
+ </slot>
11
+ <template v-if="props.footer" #footer>
12
+ <slot name="footer">
13
+ <template v-if="typeof props.footer === 'boolean'">
14
+ <ElSpace :size="10">
15
+ <ElButton v-bind="props.cancelButtonProps" @click="handleCancel">
16
+ {{ props.cancelText }}
17
+ </ElButton>
18
+ <ElButton type="primary" v-bind="props.okButtonProps" :loading="okLoading" @click="handleOk">
19
+ {{ props.okText }}
20
+ </ElButton>
21
+ </ElSpace>
22
+ </template>
23
+ <template v-else>
24
+ <component :is="props.footer()"></component>
25
+ </template>
26
+ </slot>
27
+ </template>
28
+ </ElDrawer>
29
+ </template>
30
+
31
+ <script lang="ts" setup>
32
+ import type { VNode } from 'vue'
33
+ import type { DrawerProps } from './type'
34
+ import { ElButton, ElDrawer, ElSpace } from 'element-plus'
35
+ import { computed, defineProps, defineSlots, ref } from 'vue'
36
+ import { useBemClass } from '../../../hooks'
37
+
38
+ const visible = defineModel('modelValue', {
39
+ type: Boolean,
40
+ default: false
41
+ })
42
+
43
+ const props = withDefaults(defineProps<DrawerProps>(), {
44
+ title: '',
45
+ withHeader: true,
46
+ closeOnClickModal: true,
47
+ closeOnPressEscape: true,
48
+ lockScroll: true,
49
+ modal: true,
50
+ showClose: true,
51
+ footer: true,
52
+ okText: '确认',
53
+ cancelText: '取消',
54
+ size: '300px',
55
+ appendTo: 'body'
56
+ })
57
+
58
+ defineSlots<{
59
+ title: () => VNode
60
+ footer: () => VNode
61
+ default: () => VNode
62
+ }>()
63
+
64
+ const { b } = useBemClass()
65
+
66
+ const getClass = computed(() => {
67
+ const arr: string[] = [b('drawer')]
68
+ return arr.join(' ')
69
+ })
70
+
71
+ const dialogProps = computed(() => {
72
+ return {
73
+ ...props,
74
+ content: undefined,
75
+ footer: undefined,
76
+ okText: undefined,
77
+ cancelText: undefined,
78
+ okButtonProps: undefined,
79
+ cancelButtonProps: undefined,
80
+ onOk: undefined,
81
+ onBeforeOk: undefined,
82
+ onCancel: undefined,
83
+ simple: undefined
84
+ }
85
+ })
86
+
87
+ const okLoading = ref(false)
88
+
89
+ const handleCancel = () => {
90
+ props.onCancel?.()
91
+ visible.value = false
92
+ }
93
+
94
+ const handleOk = async () => {
95
+ if (props.onBeforeOk) {
96
+ try {
97
+ okLoading.value = true
98
+ const flag = await props.onBeforeOk()
99
+ okLoading.value = false
100
+ if (flag) {
101
+ visible.value = false
102
+ }
103
+ } catch (error) {
104
+ console.error('error', error)
105
+ okLoading.value = false
106
+ }
107
+ } else {
108
+ props.onOk?.()
109
+ visible.value = false
110
+ }
111
+ }
112
+ </script>
113
+
114
+ <style lang="scss" scoped></style>
@@ -0,0 +1,15 @@
1
+ import type { ButtonProps, DrawerProps as ElDrawerProps } from 'element-plus'
2
+ import type { CSSProperties, VNode } from 'vue'
3
+
4
+ export interface DrawerProps extends Partial<ElDrawerProps> {
5
+ content?: string | (() => VNode)
6
+ footer?: boolean | (() => VNode)
7
+ okText?: string
8
+ cancelText?: string
9
+ okButtonProps?: Partial<ButtonProps>
10
+ cancelButtonProps?: Partial<ButtonProps>
11
+ style?: CSSProperties
12
+ onOk?: () => void
13
+ onBeforeOk?: () => Promise<boolean>
14
+ onCancel?: () => void
15
+ }
@@ -11,6 +11,7 @@ declare module 'vue' {
11
11
  GiButton: typeof import('./components/button/src/button.vue')['default']
12
12
  GiCard: typeof import('./components/card/src/card.vue')['default']
13
13
  GiDialog: typeof import('./components/dialog/src/dialog.vue')['default']
14
+ GiDrawer: typeof import('./components/drawer/src/drawer.vue')['default']
14
15
  GiEditTable: typeof import('./components/edit-table/src/edit-table.vue')['default']
15
16
  GiForm: typeof import('./components/form/src/form.vue')['default']
16
17
  GiGrid: typeof import('./components/grid/src/grid.vue')['default']
package/packages/index.ts CHANGED
@@ -3,6 +3,7 @@ import type { App } from 'vue'
3
3
  import Button from './components/button'
4
4
  import Card from './components/card'
5
5
  import Dialog from './components/dialog'
6
+ import Drawer from './components/drawer'
6
7
  import EditTable from './components/edit-table'
7
8
  import Form from './components/form'
8
9
  import GridItem from './components/grid/src/grid-item.vue'
@@ -16,6 +17,7 @@ import TreeTransfer from './components/tree-transfer'
16
17
  import './styles/index.scss'
17
18
 
18
19
  export * from './components/dialog'
20
+ export * from './components/drawer'
19
21
  export * from './components/edit-table'
20
22
  export * from './components/form'
21
23
  export * from './components/table'
@@ -26,6 +28,7 @@ export * from './utils'
26
28
  const components = {
27
29
  Button,
28
30
  Card,
31
+ Drawer,
29
32
  Tabs,
30
33
  InputGroup,
31
34
  InputSearch,
@@ -42,6 +45,7 @@ const components = {
42
45
  // 导出Gi前缀的组件并添加明确类型注解
43
46
  export const GiButton: typeof Button = Button
44
47
  export const GiCard: typeof Card = Card
48
+ export const GiDrawer: typeof Drawer = Drawer
45
49
  export const GiTabs: typeof Tabs = Tabs
46
50
  export const GiInputGroup: typeof InputGroup = InputGroup
47
51
  export const GiInputSearch: typeof InputSearch = InputSearch
@@ -51,12 +51,6 @@ body {
51
51
  }
52
52
  }
53
53
 
54
- .el-dialog__headerbtn {
55
- display: flex;
56
- justify-content: center;
57
- align-items: center;
58
- }
59
-
60
54
  .gi-w-full {
61
55
  width: 100%;
62
56
  }
@@ -203,4 +197,27 @@ body {
203
197
  .el-dialog__footer {
204
198
  border-top: none;
205
199
  }
200
+ }
201
+
202
+ .el-drawer[role=dialog] {
203
+ --el-drawer-padding-primary: 16px;
204
+ }
205
+
206
+ .el-drawer {
207
+ .el-drawer__header {
208
+ height: 48px;
209
+ margin-bottom: 0;
210
+ padding-top: 0;
211
+ border-bottom: 1px solid var(--el-border-color);
212
+ display: flex;
213
+ justify-content: space-between;
214
+ align-items: center;
215
+ box-sizing: border-box;
216
+ }
217
+
218
+ .el-drawer__footer {
219
+ padding-top: 12px;
220
+ padding-bottom: 12px;
221
+ border-top: 1px solid var(--el-border-color);
222
+ }
206
223
  }