gi-component 0.0.13 → 0.0.15

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.13",
4
+ "version": "0.0.15",
5
5
  "description": "Vue3中基于Element Plus二次封装基础组件库",
6
6
  "author": "lin",
7
7
  "license": "MIT",
@@ -0,0 +1,27 @@
1
+ <template>
2
+ <div class="el-message-box__container">
3
+ <el-icon class="el-message-box__status" :class="`el-message-box-icon--${props.type}`">
4
+ <InfoFilled v-if="props.type === 'info'" />
5
+ <SuccessFilled v-else-if="props.type === 'success'" />
6
+ <WarningFilled v-else-if="props.type === 'warning'" />
7
+ <CircleCloseFilled v-else-if="props.type === 'error'" />
8
+ </el-icon>
9
+ <div class="el-message-box__message">
10
+ <p>{{ props.content }}</p>
11
+ </div>
12
+ </div>
13
+ </template>
14
+
15
+ <script setup lang="ts">
16
+ import { CircleCloseFilled, InfoFilled, SuccessFilled, WarningFilled } from '@element-plus/icons-vue'
17
+
18
+ interface Props {
19
+ type?: 'info' | 'success' | 'warning' | 'error'
20
+ content?: string
21
+ }
22
+
23
+ const props = withDefaults(defineProps<Props>(), {
24
+ type: 'info',
25
+ content: ''
26
+ })
27
+ </script>
@@ -1,8 +1,10 @@
1
1
  import type { DialogInstance } from '../index'
2
2
  import ElementPlus from 'element-plus'
3
- import { createApp, h, ref } from 'vue'
3
+ import { createApp, defineAsyncComponent, h, ref } from 'vue'
4
4
  import GiDialog from './dialog.vue'
5
5
 
6
+ const DialogContent = defineAsyncComponent(() => import('./dialog-content.vue'))
7
+
6
8
  export type DialogOptions = Partial<DialogInstance['$props']>
7
9
 
8
10
  export interface DialogReturnObject {
@@ -77,6 +79,46 @@ export function createDialog() {
77
79
  /** 对话框-打开 */
78
80
  open(options: DialogOptions) {
79
81
  return this.create(options)
82
+ },
83
+
84
+ info(options: DialogOptions) {
85
+ return this.create({
86
+ ...options,
87
+ content: () => h(DialogContent, { type: 'info', content: options.content as string }),
88
+ simple: true,
89
+ style: { maxWidth: '420px', ...options.style },
90
+ lockScroll: false
91
+ })
92
+ },
93
+
94
+ success(options: DialogOptions) {
95
+ return this.create({
96
+ ...options,
97
+ content: () => h(DialogContent, { type: 'success', content: options.content as string }),
98
+ simple: true,
99
+ style: { maxWidth: '420px', ...options.style },
100
+ lockScroll: false
101
+ })
102
+ },
103
+
104
+ warning(options: DialogOptions) {
105
+ return this.create({
106
+ ...options,
107
+ content: () => h(DialogContent, { type: 'warning', content: options.content as string }),
108
+ simple: true,
109
+ style: { maxWidth: '420px', ...options.style },
110
+ lockScroll: false
111
+ })
112
+ },
113
+
114
+ error(options: DialogOptions) {
115
+ return this.create({
116
+ ...options,
117
+ content: () => h(DialogContent, { type: 'error', content: options.content as string }),
118
+ simple: true,
119
+ style: { maxWidth: '420px', ...options.style },
120
+ lockScroll: false
121
+ })
80
122
  }
81
123
  }
82
124
 
@@ -194,6 +194,36 @@ onMounted(() => {
194
194
  loadDictData()
195
195
  })
196
196
 
197
+ /** 获取占位文本 */
198
+ const getPlaceholder = (item: FormColumnItem) => {
199
+ if (!item.type) return undefined
200
+ if (['input', 'input-number', 'input-tag'].includes(item.type)) {
201
+ return `请输入${item.label}`
202
+ }
203
+ if (['textarea'].includes(item.type)) {
204
+ return `请填写${item.label}`
205
+ }
206
+ if (
207
+ [
208
+ 'select',
209
+ 'select-v2',
210
+ 'tree-select',
211
+ 'cascader',
212
+ 'time-select',
213
+ 'input-search'
214
+ ].includes(item.type)
215
+ ) {
216
+ return `请选择${item.label}`
217
+ }
218
+ if (['date-picker'].includes(item.type)) {
219
+ return `请选择日期`
220
+ }
221
+ if (['time-picker'].includes(item.type)) {
222
+ return `请选择时间`
223
+ }
224
+ return undefined
225
+ }
226
+
197
227
  // 组件的默认props配置
198
228
  function getComponentBindProps(item: FormColumnItem) {
199
229
  // 获取默认配置
@@ -263,36 +293,6 @@ const CompMap: Record<Exclude<FormColumnType, 'slot'>, any> = {
263
293
 
264
294
  const formRef = ref<FormInstance>()
265
295
 
266
- /** 获取占位文本 */
267
- const getPlaceholder = (item: FormColumnItem) => {
268
- if (!item.type) return undefined
269
- if (['input', 'input-number', 'input-tag'].includes(item.type)) {
270
- return `请输入${item.label}`
271
- }
272
- if (['textarea'].includes(item.type)) {
273
- return `请填写${item.label}`
274
- }
275
- if (
276
- [
277
- 'select',
278
- 'select-v2',
279
- 'tree-select',
280
- 'cascader',
281
- 'time-select',
282
- 'input-search'
283
- ].includes(item.type)
284
- ) {
285
- return `请选择${item.label}`
286
- }
287
- if (['date-picker'].includes(item.type)) {
288
- return `请选择日期`
289
- }
290
- if (['time-picker'].includes(item.type)) {
291
- return `请选择时间`
292
- }
293
- return undefined
294
- }
295
-
296
296
  /** 表单项校验规则 */
297
297
  function getFormItemRules(item: FormColumnItem) {
298
298
  if (item.required) {
@@ -332,9 +332,10 @@ function isDisabled(item: FormColumnItem) {
332
332
 
333
333
  /** 表单数据更新 */
334
334
  function updateModelValue(value: any, item: FormColumnItem) {
335
+ const val = item?.format ? item.format(value) : value
335
336
  emit(
336
337
  'update:modelValue',
337
- Object.assign(props.modelValue, { [item.field]: value })
338
+ Object.assign(props.modelValue, { [item.field]: val })
338
339
  )
339
340
  }
340
341
 
@@ -7,30 +7,30 @@ import type { InputSearchInstance } from '../../input-search'
7
7
 
8
8
  export type FormColumnType
9
9
  = | 'input'
10
- | 'textarea'
11
- | 'input-number'
12
- | 'input-tag'
13
- | 'input-search'
14
- | 'select'
15
- | 'select-v2'
16
- | 'tree-select'
17
- | 'cascader'
18
- | 'slider'
19
- | 'switch'
20
- | 'rate'
21
- | 'checkbox-group'
22
- | 'checkbox'
23
- | 'radio-group'
24
- | 'radio'
25
- | 'date-picker'
26
- | 'time-picker'
27
- | 'time-select'
28
- | 'color-picker'
29
- | 'transfer'
30
- | 'autocomplete'
31
- | 'upload'
32
- | 'title'
33
- | 'slot'
10
+ | 'textarea'
11
+ | 'input-number'
12
+ | 'input-tag'
13
+ | 'input-search'
14
+ | 'select'
15
+ | 'select-v2'
16
+ | 'tree-select'
17
+ | 'cascader'
18
+ | 'slider'
19
+ | 'switch'
20
+ | 'rate'
21
+ | 'checkbox-group'
22
+ | 'checkbox'
23
+ | 'radio-group'
24
+ | 'radio'
25
+ | 'date-picker'
26
+ | 'time-picker'
27
+ | 'time-select'
28
+ | 'color-picker'
29
+ | 'transfer'
30
+ | 'autocomplete'
31
+ | 'upload'
32
+ | 'title'
33
+ | 'slot'
34
34
 
35
35
  /**
36
36
  * 表单列属性类型,根据组件类型使用对应的属性类型
@@ -69,6 +69,7 @@ export interface FormColumnItem<F = any> {
69
69
  slotName?: string
70
70
  slots?: FormColumnSlots
71
71
  extra?: string | (() => VNode) // 右侧额外内容
72
+ format?: (value: string) => string | number
72
73
  }
73
74
 
74
75
  export interface FormProps extends Partial<ElFormProps> {
@@ -194,6 +194,11 @@ body {
194
194
  border-bottom: none;
195
195
  }
196
196
 
197
+ .el-dialog__body {
198
+ padding-top: 0;
199
+ padding-bottom: 0;
200
+ }
201
+
197
202
  .el-dialog__footer {
198
203
  border-top: none;
199
204
  }