gi-component 0.0.10 → 0.0.12
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 +1 -1
- package/packages/components/drawer/index.ts +6 -0
- package/packages/components/drawer/src/drawer.ts +84 -0
- package/packages/components/drawer/src/drawer.vue +114 -0
- package/packages/components/drawer/src/type.ts +15 -0
- package/packages/components.d.ts +1 -0
- package/packages/index.ts +4 -0
- package/packages/styles/index.scss +27 -6
package/package.json
CHANGED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type { DrawerInstance } from '../index'
|
|
2
|
+
import ElementPlus from 'element-plus'
|
|
3
|
+
import { createApp, h, ref } from 'vue'
|
|
4
|
+
import GiDrawer from './drawer.vue'
|
|
5
|
+
|
|
6
|
+
export type DrawerOptions = Partial<DrawerInstance['$props']>
|
|
7
|
+
|
|
8
|
+
export interface DrawerReturnObject {
|
|
9
|
+
close: () => void
|
|
10
|
+
update: (newProps?: Record<string, any>) => void
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const DEF_OPTIONS: DrawerOptions = {
|
|
14
|
+
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function createDrawer() {
|
|
18
|
+
const Drawer = {
|
|
19
|
+
_context: {},
|
|
20
|
+
// 核心创建方法
|
|
21
|
+
create(options: DrawerOptions): DrawerReturnObject {
|
|
22
|
+
const mergedOptions = { ...DEF_OPTIONS, ...options }
|
|
23
|
+
// 创建容器
|
|
24
|
+
const container = document.createElement('div')
|
|
25
|
+
document.body.appendChild(container)
|
|
26
|
+
|
|
27
|
+
// 状态管理
|
|
28
|
+
const visible = ref(true)
|
|
29
|
+
const dialogOptions = ref(mergedOptions || {})
|
|
30
|
+
|
|
31
|
+
// 创建弹窗应用
|
|
32
|
+
const drawerApp = createApp({
|
|
33
|
+
setup() {
|
|
34
|
+
// 关闭处理
|
|
35
|
+
const closed = () => {
|
|
36
|
+
drawerApp.unmount()
|
|
37
|
+
container.remove()
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return () =>
|
|
41
|
+
h(GiDrawer, {
|
|
42
|
+
...dialogOptions.value,
|
|
43
|
+
'modelValue': visible.value,
|
|
44
|
+
'onUpdate:modelValue': (val: boolean) => (visible.value = val),
|
|
45
|
+
'onClosed': () => closed()
|
|
46
|
+
})
|
|
47
|
+
}
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
drawerApp.use(ElementPlus)
|
|
51
|
+
|
|
52
|
+
// 继承主应用的上下文
|
|
53
|
+
Object.assign(drawerApp._context, Drawer._context)
|
|
54
|
+
|
|
55
|
+
// 挂载
|
|
56
|
+
drawerApp.mount(container)
|
|
57
|
+
|
|
58
|
+
return {
|
|
59
|
+
/** 关闭抽屉 */
|
|
60
|
+
close: () => {
|
|
61
|
+
visible.value = false
|
|
62
|
+
setTimeout(() => {
|
|
63
|
+
drawerApp.unmount()
|
|
64
|
+
container.remove()
|
|
65
|
+
}, 300)
|
|
66
|
+
},
|
|
67
|
+
/** 更新抽屉 */
|
|
68
|
+
update: (newProps?: Record<string, any>) => {
|
|
69
|
+
dialogOptions.value = { ...dialogOptions.value, ...newProps }
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
|
|
74
|
+
/** 抽屉-打开 */
|
|
75
|
+
open(options: DrawerOptions) {
|
|
76
|
+
return this.create(options)
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return Drawer
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// 默认导出实例
|
|
84
|
+
export const Drawer = createDrawer()
|
|
@@ -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
|
+
}
|
package/packages/components.d.ts
CHANGED
|
@@ -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,31 @@ 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__body {
|
|
219
|
+
font-size: 14px;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
.el-drawer__footer {
|
|
223
|
+
padding-top: 12px;
|
|
224
|
+
padding-bottom: 12px;
|
|
225
|
+
border-top: 1px solid var(--el-border-color);
|
|
226
|
+
}
|
|
206
227
|
}
|