el-plus-crud 0.0.2

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.
Files changed (86) hide show
  1. package/.eslintignore +18 -0
  2. package/.eslintrc.js +78 -0
  3. package/.lintstagedrc +3 -0
  4. package/.prettierrc.js +39 -0
  5. package/CHANGELOG.md +5 -0
  6. package/LICENSE +21 -0
  7. package/README.md +15 -0
  8. package/example/App.vue +79 -0
  9. package/example/assets/vue.svg +1 -0
  10. package/example/main.js +18 -0
  11. package/example/style.css +5 -0
  12. package/index.html +13 -0
  13. package/lib/components/el-plus-form/ElPlusForm.vue +744 -0
  14. package/lib/components/el-plus-form/ElPlusFormDialog.vue +107 -0
  15. package/lib/components/el-plus-form/components/ElPlusFormAutocomplete.vue +49 -0
  16. package/lib/components/el-plus-form/components/ElPlusFormBtn.vue +96 -0
  17. package/lib/components/el-plus-form/components/ElPlusFormBtns.vue +133 -0
  18. package/lib/components/el-plus-form/components/ElPlusFormCascader.vue +38 -0
  19. package/lib/components/el-plus-form/components/ElPlusFormCascaderPanel.vue +51 -0
  20. package/lib/components/el-plus-form/components/ElPlusFormCheckbox.vue +42 -0
  21. package/lib/components/el-plus-form/components/ElPlusFormCheckboxButton.vue +42 -0
  22. package/lib/components/el-plus-form/components/ElPlusFormColor.vue +38 -0
  23. package/lib/components/el-plus-form/components/ElPlusFormDate.vue +37 -0
  24. package/lib/components/el-plus-form/components/ElPlusFormDaterange.vue +44 -0
  25. package/lib/components/el-plus-form/components/ElPlusFormDatetime.vue +38 -0
  26. package/lib/components/el-plus-form/components/ElPlusFormFile.vue +47 -0
  27. package/lib/components/el-plus-form/components/ElPlusFormImage.vue +113 -0
  28. package/lib/components/el-plus-form/components/ElPlusFormInput.vue +56 -0
  29. package/lib/components/el-plus-form/components/ElPlusFormLink.vue +271 -0
  30. package/lib/components/el-plus-form/components/ElPlusFormNbinput.vue +51 -0
  31. package/lib/components/el-plus-form/components/ElPlusFormNumber.vue +107 -0
  32. package/lib/components/el-plus-form/components/ElPlusFormPassword.vue +39 -0
  33. package/lib/components/el-plus-form/components/ElPlusFormRadio.vue +42 -0
  34. package/lib/components/el-plus-form/components/ElPlusFormRate.vue +38 -0
  35. package/lib/components/el-plus-form/components/ElPlusFormSelect.vue +149 -0
  36. package/lib/components/el-plus-form/components/ElPlusFormSlider.vue +38 -0
  37. package/lib/components/el-plus-form/components/ElPlusFormStatus.vue +67 -0
  38. package/lib/components/el-plus-form/components/ElPlusFormSwitch.vue +38 -0
  39. package/lib/components/el-plus-form/components/ElPlusFormTag.vue +78 -0
  40. package/lib/components/el-plus-form/components/ElPlusFormText.vue +115 -0
  41. package/lib/components/el-plus-form/components/ElPlusFormTextarea.vue +45 -0
  42. package/lib/components/el-plus-form/components/ElPlusFormTransfer.vue +44 -0
  43. package/lib/components/el-plus-form/components/ElPlusFormTree.vue +53 -0
  44. package/lib/components/el-plus-form/components/ElPlusFormTreeSelect.vue +36 -0
  45. package/lib/components/el-plus-form/components/components/IconSelectorList.vue +92 -0
  46. package/lib/components/el-plus-form/components/components/file-icons/FileIcons.vue +135 -0
  47. package/lib/components/el-plus-form/components/components/file-icons/data/index.ts +27 -0
  48. package/lib/components/el-plus-form/components/components/file-icons/images/doc.svg +13 -0
  49. package/lib/components/el-plus-form/components/components/file-icons/images/file.svg +19 -0
  50. package/lib/components/el-plus-form/components/components/file-icons/images/jpg.svg +14 -0
  51. package/lib/components/el-plus-form/components/components/file-icons/images/pdf.svg +13 -0
  52. package/lib/components/el-plus-form/components/components/file-icons/images/png.svg +13 -0
  53. package/lib/components/el-plus-form/components/components/file-icons/images/ppt.svg +13 -0
  54. package/lib/components/el-plus-form/components/components/file-icons/images/xls.svg +13 -0
  55. package/lib/components/el-plus-form/components/index.ts +17 -0
  56. package/lib/components/el-plus-form/data/file.ts +74 -0
  57. package/lib/components/el-plus-form/images/icon/excel.png +0 -0
  58. package/lib/components/el-plus-form/images/icon/file.png +0 -0
  59. package/lib/components/el-plus-form/images/icon/pdf.png +0 -0
  60. package/lib/components/el-plus-form/images/icon/ppt.png +0 -0
  61. package/lib/components/el-plus-form/images/icon/txt.png +0 -0
  62. package/lib/components/el-plus-form/images/icon/word.png +0 -0
  63. package/lib/components/el-plus-form/images/icon/zip.png +0 -0
  64. package/lib/components/el-plus-form/mixins/index.ts +113 -0
  65. package/lib/components/el-plus-form/util/index.ts +266 -0
  66. package/lib/components/el-plus-form/util/validate.ts +310 -0
  67. package/lib/components/el-plus-table/ElPlusTable.vue +723 -0
  68. package/lib/components/el-plus-table/components/columnItem.vue +185 -0
  69. package/lib/components/el-plus-table/components/header.vue +185 -0
  70. package/lib/components/el-plus-table/components/settingColumn.vue +168 -0
  71. package/lib/components/el-plus-table/components/statisticInfo.vue +47 -0
  72. package/lib/components/el-plus-table/util/index.ts +123 -0
  73. package/lib/config/form.ts +12 -0
  74. package/lib/config/index.ts +9 -0
  75. package/lib/index.ts +29 -0
  76. package/package.json +65 -0
  77. package/public/vite.svg +1 -0
  78. package/tsconfig.json +68 -0
  79. package/types/axios.d.ts +13 -0
  80. package/types/formList.d.ts +365 -0
  81. package/types/global.d.ts +145 -0
  82. package/types/layout.d.ts +57 -0
  83. package/types/mitt.d.ts +38 -0
  84. package/types/pinia.d.ts +149 -0
  85. package/types/views.d.ts +329 -0
  86. package/vite.config.ts +68 -0
@@ -0,0 +1,39 @@
1
+ <template>
2
+ <el-input :class="desc.class" :show-password="true" v-bind="attrs" v-on="onEvents" v-model="currentValue">
3
+ <!-- 组件内部插槽 -->
4
+ <template v-for="(item, key, index) in slots" #[key]="data" :key="index">
5
+ <slot :name="key" :data="data" />
6
+ </template>
7
+ </el-input>
8
+ </template>
9
+ <script lang="ts">
10
+ export default {
11
+ name: 'ElPlusFormPassword',
12
+ inheritAttrs: false,
13
+ typeName: 'password',
14
+ customOptions: {}
15
+ }
16
+ </script>
17
+ <script lang="ts" setup>
18
+ import { ref, useAttrs, useSlots, onBeforeMount } from 'vue'
19
+ import { getAttrs, getEvents } from '../mixins'
20
+
21
+ const props = defineProps<{
22
+ modelValue?: string | number | '' | null
23
+ field: string
24
+ loading?: boolean
25
+ desc: { [key: string]: any }
26
+ formData: { [key: string]: any }
27
+ }>()
28
+ const emits = defineEmits(['update:modelValue'])
29
+ const currentValue = ref(props.modelValue)
30
+ emits('update:modelValue', currentValue)
31
+
32
+ const slots = ref(Object.assign({}, useSlots(), props.desc.slots))
33
+ const attrs = ref({} as any)
34
+ const onEvents = ref(getEvents(props))
35
+
36
+ onBeforeMount(async () => {
37
+ attrs.value = await getAttrs(props, { autocomplete: 'new-password', maxlength: 20, ...useAttrs() })
38
+ })
39
+ </script>
@@ -0,0 +1,42 @@
1
+ <template>
2
+ <el-radio-group class="ElPlusFormRadio-panel" v-bind="attrs" v-on="onEvents" v-model="currentValue">
3
+ <el-radio v-for="option of attrs.options" :key="option.value" :label="option.value">
4
+ {{ option.l || option.label }}
5
+ </el-radio>
6
+ </el-radio-group>
7
+ </template>
8
+ <script lang="ts">
9
+ export default {
10
+ name: 'ElPlusFormRadio',
11
+ inheritAttrs: false,
12
+ typeName: 'radio',
13
+ customOptions: {}
14
+ }
15
+ </script>
16
+ <script lang="ts" setup>
17
+ import { ref, useAttrs, onBeforeMount } from 'vue'
18
+ import { getAttrs, getEvents } from '../mixins'
19
+
20
+ const props = defineProps<{
21
+ modelValue?: string | number | '' | null
22
+ field: string
23
+ desc: { [key: string]: any }
24
+ formData: { [key: string]: any }
25
+ }>()
26
+
27
+ const emits = defineEmits(['update:modelValue'])
28
+ const currentValue = ref(props.modelValue)
29
+ emits('update:modelValue', currentValue)
30
+
31
+ const attrs = ref({} as any)
32
+ const onEvents = ref(getEvents(props))
33
+
34
+ onBeforeMount(async () => {
35
+ attrs.value = await getAttrs(props, { ...useAttrs() })
36
+ })
37
+ </script>
38
+ <style lang="scss" scoped>
39
+ .ElPlusFormRadio-panel {
40
+ display: flex;
41
+ }
42
+ </style>
@@ -0,0 +1,38 @@
1
+ <template>
2
+ <el-rate class="ElPlusFormRate-panel" v-bind="attrs" v-on="onEvents" v-model="currentValue" />
3
+ </template>
4
+ <script lang="ts">
5
+ export default {
6
+ name: 'ElPlusFormRate',
7
+ inheritAttrs: false,
8
+ typeName: 'rate',
9
+ customOptions: {}
10
+ }
11
+ </script>
12
+ <script lang="ts" setup>
13
+ import { ref, useAttrs, onBeforeMount } from 'vue'
14
+ import { getAttrs, getEvents } from '../mixins'
15
+
16
+ const props = defineProps<{
17
+ modelValue?: string | number | '' | null
18
+ field: string
19
+ desc: { [key: string]: any }
20
+ formData: { [key: string]: any }
21
+ }>()
22
+
23
+ const emits = defineEmits(['update:modelValue'])
24
+ const currentValue = ref(props.modelValue)
25
+ emits('update:modelValue', currentValue)
26
+
27
+ const attrs = ref({} as any)
28
+ const onEvents = ref(getEvents(props))
29
+
30
+ onBeforeMount(async () => {
31
+ attrs.value = await getAttrs(props, { ...useAttrs() })
32
+ })
33
+ </script>
34
+ <style lang="scss" scoped>
35
+ .ElPlusFormRate-panel {
36
+ display: flex;
37
+ }
38
+ </style>
@@ -0,0 +1,149 @@
1
+ <template>
2
+ <el-select v-if="isInit" class="el-plus-form-select" :class="desc.class" :style="desc.style" v-bind="attrs" v-model="currentValue" :loading="loading" v-on="onEvents">
3
+ <el-option v-for="option in options" :key="option.value || option.v" v-bind="option">
4
+ <div class="el-plus-form-select-options">
5
+ <span>{{ option.label || option.l }}</span>
6
+ <div v-if="desc.optionTip">{{ tip(option) }}</div>
7
+ </div>
8
+ </el-option>
9
+ </el-select>
10
+ </template>
11
+ <script lang="ts">
12
+ export default {
13
+ name: 'ElPlusFormSelect',
14
+ inheritAttrs: false,
15
+ typeName: 'select',
16
+ customOptions: {}
17
+ }
18
+ </script>
19
+ <script lang="ts" setup>
20
+ import { ref, reactive, computed, onBeforeMount, useAttrs, watch, inject } from 'vue'
21
+ import { ElMessage } from 'element-plus'
22
+ import { getAttrs } from '../mixins'
23
+ import { isEqual } from 'lodash'
24
+
25
+ const globalData = inject('globalData') as any
26
+
27
+ const props = defineProps<{
28
+ modelValue?: number | string | Array<string>
29
+ field: string
30
+ loading?: boolean
31
+ desc: { [key: string]: any }
32
+ formData: { [key: string]: any }
33
+ rowIndex?: number
34
+ }>()
35
+ const emits = defineEmits(['update:modelValue'])
36
+
37
+ const currentValue = ref(props.modelValue || (props.desc.multiple ? [] : ''))
38
+ emits('update:modelValue', currentValue)
39
+
40
+ const attrs = ref({} as any)
41
+ const options = reactive([] as any[])
42
+ const oldQuery = ref(null) as any
43
+ const tempAttr = { clearable: true, ...useAttrs() } as any
44
+ const isInit = ref(false)
45
+
46
+ if (props.desc.allowCreate) {
47
+ tempAttr.filterable = true
48
+ }
49
+
50
+ // 如果是远程加载
51
+ if (props.desc.remote) {
52
+ tempAttr.remote = true
53
+ tempAttr.filterable = true
54
+ tempAttr.remoteShowSuffix = true
55
+ tempAttr.loadingText = '远程查询中...'
56
+ tempAttr.remoteMethod = async (query: string) => {
57
+ if (query !== undefined && query !== null) {
58
+ if (oldQuery.value !== query) {
59
+ oldQuery.value = query
60
+ options.splice(0, options.length, ...(await props.desc.remote(query)))
61
+ }
62
+ }
63
+ }
64
+ }
65
+
66
+ /**
67
+ * 这里单独处理下事件
68
+ */
69
+ const onEvents = computed(() => {
70
+ const tempOn = {} as any
71
+ if (props.desc?.on) {
72
+ Object.keys(props.desc.on).map((key: string) => {
73
+ tempOn[key] = () => {
74
+ props.desc.on[key](
75
+ props.formData,
76
+ options.find((item) => item.value === currentValue.value),
77
+ props.rowIndex
78
+ )
79
+ }
80
+ })
81
+ }
82
+ return tempOn
83
+ })
84
+
85
+ // 如果options为空,则默认执行一次查询
86
+ if (options.length <= 0 && props.desc.remote && (props.desc.initLoad ?? true)) {
87
+ tempAttr.remoteMethod('')
88
+ }
89
+
90
+ // 这里处理下tip
91
+ const tip = computed(() => (optionItem: any) => {
92
+ return props.desc.optionTip(optionItem)
93
+ })
94
+
95
+ onBeforeMount(async () => {
96
+ attrs.value = await getAttrs(props, tempAttr)
97
+ isInit.value = true
98
+ })
99
+
100
+ watch(
101
+ () => props.desc.options,
102
+ async (data) => {
103
+ if (typeof data === 'string') {
104
+ // 从全局数据中获取options
105
+ options.splice(0, options.length, ...globalData[data])
106
+ } else if (typeof data === 'function') {
107
+ options.splice(0, options.length, ...(await data(props.formData)))
108
+ } else if (Array.isArray(data)) {
109
+ if (data && options && !isEqual(data, options)) {
110
+ options.splice(0, options.length, ...data)
111
+ }
112
+ } else {
113
+ options.splice(0, options.length)
114
+ }
115
+ },
116
+ { immediate: true }
117
+ )
118
+
119
+ watch(
120
+ () => currentValue.value,
121
+ (val: any) => {
122
+ if (attrs.value.allowCreate) {
123
+ if (val && Array.isArray(val) && (val as Array<any>).some((item) => typeof item === 'string' && item.length > 20)) {
124
+ ElMessage.warning('最大长度为: ' + 20)
125
+ currentValue.value = (val as Array<string>).filter((item) => typeof item !== 'string' || item.length <= 20)
126
+ }
127
+ }
128
+ }
129
+ )
130
+ </script>
131
+ <style lang="scss">
132
+ .el-plus-form-select-options {
133
+ width: 100%;
134
+ display: flex;
135
+ justify-content: space-between;
136
+ align-items: center;
137
+ & > div {
138
+ // text-align: right;
139
+ color: #aaaaaa;
140
+ max-width: 40%;
141
+ font-size: 12px;
142
+ word-break: break-all;
143
+ }
144
+ }
145
+ .el-select-dropdown__item {
146
+ height: auto;
147
+ white-space: break-spaces;
148
+ }
149
+ </style>
@@ -0,0 +1,38 @@
1
+ <template>
2
+ <el-slider class="ElPlusFormSlider-panel" v-bind="attrs" v-on="onEvents" v-model="currentValue" />
3
+ </template>
4
+ <script lang="ts">
5
+ export default {
6
+ name: 'ElPlusFormSlider',
7
+ inheritAttrs: false,
8
+ typeName: 'slider',
9
+ customOptions: {}
10
+ }
11
+ </script>
12
+ <script lang="ts" setup>
13
+ import { ref, useAttrs, onBeforeMount } from 'vue'
14
+ import { getAttrs, getEvents } from '../mixins'
15
+
16
+ const props = defineProps<{
17
+ modelValue?: string | number | '' | null
18
+ field: string
19
+ desc: { [key: string]: any }
20
+ formData: { [key: string]: any }
21
+ }>()
22
+
23
+ const emits = defineEmits(['update:modelValue'])
24
+ const currentValue = ref(props.modelValue)
25
+ emits('update:modelValue', currentValue)
26
+
27
+ const attrs = ref({} as any)
28
+ const onEvents = ref(getEvents(props))
29
+
30
+ onBeforeMount(async () => {
31
+ attrs.value = await getAttrs(props, { ...useAttrs() })
32
+ })
33
+ </script>
34
+ <style lang="scss" scoped>
35
+ .ElPlusFormSlider-panel {
36
+ display: flex;
37
+ }
38
+ </style>
@@ -0,0 +1,67 @@
1
+ <template>
2
+ <div class="ElPlusFormStatus-panel">
3
+ <i v-if="currentValue === 0" class="status-danger" />
4
+ <i v-else-if="currentValue === 1" class="status-success" />
5
+ <i v-else-if="currentValue === 2" class="status-warning" />
6
+ <i v-else-if="currentValue === 3" class="status-info" />
7
+ <div :class="desc.class" :style="desc.style" v-bind="attrs" v-on="onEvents">
8
+ {{ attrs.formatedValue || currentValue }}
9
+ </div>
10
+ </div>
11
+ </template>
12
+ <script lang="ts">
13
+ export default {
14
+ name: 'ElPlusFormStatus',
15
+ inheritAttrs: false,
16
+ typeName: 'status',
17
+ customOptions: {}
18
+ }
19
+ </script>
20
+ <script lang="ts" setup>
21
+ import { ref, useAttrs, onBeforeMount } from 'vue'
22
+ import { getAttrs, getEvents } from '../mixins'
23
+
24
+ const props = defineProps<{
25
+ modelValue?: string | number | '' | null
26
+ field: string
27
+ desc: { [key: string]: any }
28
+ formData: { [key: string]: any }
29
+ }>()
30
+
31
+ const emits = defineEmits(['update:modelValue'])
32
+ const currentValue = ref(props.modelValue)
33
+ emits('update:modelValue', currentValue)
34
+
35
+ const attrs = ref({} as any)
36
+ const onEvents = ref(getEvents(props))
37
+
38
+ onBeforeMount(async () => {
39
+ attrs.value = await getAttrs(props, { ...useAttrs() })
40
+ })
41
+ </script>
42
+ <style lang="scss" scoped>
43
+ .ElPlusFormStatus-panel {
44
+ display: flex;
45
+ line-height: 25px;
46
+ align-items: center;
47
+ i {
48
+ display: inline-block;
49
+ min-width: 10px;
50
+ min-height: 10px;
51
+ border-radius: 50%;
52
+ margin-right: 5px;
53
+ }
54
+ .status-danger {
55
+ background: #f56c6c;
56
+ }
57
+ .status-success {
58
+ background: #67c23a;
59
+ }
60
+ .status-warning {
61
+ background: #e6a23c;
62
+ }
63
+ .status-info {
64
+ background: #909399;
65
+ }
66
+ }
67
+ </style>
@@ -0,0 +1,38 @@
1
+ <template>
2
+ <div class="el-plus-form-switch">
3
+ <el-switch v-if="isInit" v-bind="attrs" v-on="onEvents" v-model="currentValue" />
4
+ </div>
5
+ </template>
6
+ <script lang="ts">
7
+ export default {
8
+ name: 'ElPlusFormSwitch',
9
+ inheritAttrs: false,
10
+ typeName: 'switch',
11
+ customOptions: {}
12
+ }
13
+ </script>
14
+ <script lang="ts" setup>
15
+ import { ref, useAttrs, onBeforeMount } from 'vue'
16
+ import { getAttrs, getEvents } from '../mixins'
17
+
18
+ const props = defineProps<{
19
+ modelValue?: number | null
20
+ field: string
21
+ loading?: boolean
22
+ desc: { [key: string]: any }
23
+ formData: { [key: string]: any }
24
+ }>()
25
+ const emits = defineEmits(['update:modelValue'])
26
+
27
+ const currentValue = ref(props.modelValue)
28
+ emits('update:modelValue', currentValue)
29
+
30
+ const isInit = ref(false)
31
+ const attrs = ref({} as any)
32
+ const onEvents = ref(getEvents(props))
33
+
34
+ onBeforeMount(async () => {
35
+ attrs.value = await getAttrs(props, { activeValue: 1, inactiveValue: 0, clearable: true, ...useAttrs() })
36
+ isInit.value = true
37
+ })
38
+ </script>
@@ -0,0 +1,78 @@
1
+ <template>
2
+ <div>
3
+ <el-tag v-bind="attrs" :size="attrs.size || 'small'" :type="tagType !== '--' ? tagType : ''" v-on="onEvents">
4
+ {{ formatValue || modelValue }}
5
+ </el-tag>
6
+ </div>
7
+ </template>
8
+ <script lang="ts">
9
+ export default {
10
+ name: 'ElPlusFormTag',
11
+ inheritAttrs: false,
12
+ typeName: 'tag',
13
+ customOptions: {}
14
+ }
15
+ </script>
16
+ <script lang="ts" setup>
17
+ import { ref, watch, useAttrs, onBeforeMount, inject } from 'vue'
18
+ import { getAttrs, getEvents } from '../mixins'
19
+
20
+ const format = inject('format') as any
21
+
22
+ const props = defineProps<{
23
+ modelValue?: string | number | '' | null
24
+ field: string
25
+ loading?: boolean
26
+ desc: { [key: string]: any }
27
+ formData: { [key: string]: any }
28
+ }>()
29
+
30
+ const attrs = ref({} as any)
31
+ const onEvents = ref(getEvents(props))
32
+
33
+ const formatValue = ref('' as any)
34
+ // 格式化Type类型
35
+ const tagType = ref('' as any)
36
+
37
+ onBeforeMount(async () => {
38
+ attrs.value = await getAttrs(props, { ...useAttrs() })
39
+ })
40
+
41
+ watch(
42
+ () => props.modelValue,
43
+ async () => {
44
+ if (!props.desc.tagType) {
45
+ tagType.value = ''
46
+ } else {
47
+ if (typeof props.desc.tagType === 'function') {
48
+ // 如果有方法类型的判断,则需要启用动态监测
49
+ tagType.value = await props.desc.tagType(props.modelValue, props.formData, props.field)
50
+ } else if (typeof props.desc.tagType === 'string') {
51
+ tagType.value = (await format)[props.desc.tagType](props.modelValue, props.formData, props.field)
52
+ } else {
53
+ tagType.value = ''
54
+ }
55
+ }
56
+ },
57
+ { immediate: true }
58
+ )
59
+
60
+ watch(
61
+ () => props.modelValue,
62
+ async () => {
63
+ if (!props.desc.format) {
64
+ formatValue.value = props.modelValue === '' ? '—' : props.modelValue ?? '—'
65
+ } else {
66
+ if (typeof props.desc.format === 'function') {
67
+ // 如果有方法类型的判断,则需要启用动态监测
68
+ formatValue.value = await props.desc.format(props.modelValue, props.formData, props.field)
69
+ } else if (typeof props.desc.format === 'string') {
70
+ formatValue.value = (await format)[props.desc.format](props.modelValue, props.formData, props.field)
71
+ } else {
72
+ formatValue.value = props.modelValue || '—'
73
+ }
74
+ }
75
+ },
76
+ { immediate: true }
77
+ )
78
+ </script>
@@ -0,0 +1,115 @@
1
+ <template>
2
+ <div class="ele-form-text" :class="[...(desc.class || []), desc.linkType ? 'ele-form-text-click' : '']" :style="desc.style" v-bind="attrs" v-on="onEvents">
3
+ <span v-if="desc.title">{{ desc.title + ': ' }}</span>
4
+ <i v-if="desc.icon" :class="[formData.icon]"></i>
5
+ {{ formatValue }}
6
+ <el-popover v-if="desc.content && popoverContent" placement="bottom" :width="200" trigger="hover" effect="dark" :content="popoverContent">
7
+ <template #reference>
8
+ <el-icon style="color: #f56c6c; font-size: 16px; margin-left: 10px"><WarningFilled /></el-icon>
9
+ </template>
10
+ </el-popover>
11
+ </div>
12
+ </template>
13
+ <script lang="ts">
14
+ export default {
15
+ name: 'ElPlusFormText',
16
+ inheritAttrs: false,
17
+ typeName: 'text',
18
+ customOptions: {}
19
+ }
20
+ </script>
21
+ <script lang="ts" setup>
22
+ import { ref, watch, computed, onBeforeMount, useAttrs, inject } from 'vue'
23
+ import { getEvents, getAttrs } from '../mixins'
24
+ import { WarningFilled } from '@element-plus/icons-vue'
25
+
26
+ const showInfo = inject('showInfo') as Function
27
+ const format = inject('format') as any
28
+
29
+ const props = defineProps<{
30
+ modelValue?: any
31
+ field: string
32
+ loading?: boolean
33
+ desc: { [key: string]: any }
34
+ formData: { [key: string]: any }
35
+ }>()
36
+
37
+ const attrs = ref({} as any)
38
+
39
+ const onEvents = computed(() => {
40
+ const tempOn = getEvents(props)
41
+
42
+ // 如果这里有linkType,则会替换点击事件
43
+ let linkId = props.desc.linkId || 'id'
44
+ if (typeof linkId === 'function') {
45
+ linkId = linkId(props.modelValue, props.formData)
46
+ } else {
47
+ linkId = props.formData[linkId]
48
+ }
49
+ if (props.desc.linkType && linkId) {
50
+ let linkType = props.desc.linkType
51
+ let linkLabel = props.desc.linkLabel || ''
52
+ if (typeof linkType === 'function') {
53
+ linkType = linkType(props.modelValue, props.formData)
54
+ }
55
+ if (typeof linkLabel === 'function') {
56
+ linkLabel = linkLabel(props.modelValue, props.formData)
57
+ } else {
58
+ linkLabel = props.formData[linkLabel]
59
+ }
60
+ tempOn.click = () => {
61
+ // 显示详情
62
+ showInfo(linkId, linkType, linkLabel)
63
+ }
64
+ }
65
+ return tempOn
66
+ })
67
+
68
+ const formatValue = ref('' as any)
69
+
70
+ onBeforeMount(async () => {
71
+ attrs.value = await getAttrs(props, useAttrs())
72
+ })
73
+
74
+ // 鼠标悬浮
75
+ const popoverContent = computed(() => {
76
+ if (typeof props.desc.content === 'function') {
77
+ // 如果有方法类型的判断,则需要启用动态监测
78
+ return props.desc.content(props.modelValue, props.formData, props.field)
79
+ } else {
80
+ return props.desc.content || ''
81
+ }
82
+ })
83
+
84
+ watch(
85
+ () => props.modelValue,
86
+ async () => {
87
+ if (!props.desc.format) {
88
+ formatValue.value = props.modelValue === '' ? '—' : props.modelValue ?? '—'
89
+ } else {
90
+ if (typeof props.desc.format === 'function') {
91
+ // 如果有方法类型的判断,则需要启用动态监测
92
+ formatValue.value = await props.desc.format(props.modelValue, props.formData, props.field)
93
+ } else if (typeof props.desc.format === 'string') {
94
+ formatValue.value = format[props.desc.format] ? format[props.desc.format](props.modelValue, props.formData, props.field) : '--'
95
+ } else {
96
+ formatValue.value = props.modelValue || '—'
97
+ }
98
+ }
99
+ },
100
+ { immediate: true }
101
+ )
102
+ </script>
103
+ <style lang="scss" scoped>
104
+ .ele-form-text {
105
+ color: #606266;
106
+ word-break: break-all;
107
+ display: flex;
108
+ align-items: center;
109
+ }
110
+
111
+ .ele-form-text-click {
112
+ color: #1890ff;
113
+ cursor: pointer;
114
+ }
115
+ </style>
@@ -0,0 +1,45 @@
1
+ <template>
2
+ <el-input :class="desc.class" :style="desc.style" type="textarea" v-bind="attrs" v-model="currentValue" v-on="onEvents"> </el-input>
3
+ </template>
4
+ <script lang="ts">
5
+ export default {
6
+ name: 'ElPlusFormTextarea',
7
+ inheritAttrs: false,
8
+ typeName: 'textarea',
9
+ customOptions: {}
10
+ }
11
+ </script>
12
+ <script lang="ts" setup>
13
+ import { ref, useAttrs, watch, onBeforeMount } from 'vue'
14
+ import { getAttrs, getEvents } from '../mixins'
15
+
16
+ const props = defineProps<{
17
+ modelValue?: string | null
18
+ field: string
19
+ loading?: boolean
20
+ desc: { [key: string]: any }
21
+ formData: { [key: string]: any }
22
+ }>()
23
+ const emits = defineEmits(['update:modelValue', 'validateThis'])
24
+ const attrs = ref({} as any)
25
+ const onEvents = ref(getEvents(props))
26
+
27
+ const currentValue = ref(props.modelValue)
28
+ emits('update:modelValue', currentValue)
29
+
30
+ onBeforeMount(async () => {
31
+ attrs.value = await getAttrs(props, { maxlength: 100, showWordLimit: true, rows: 3, ...useAttrs() })
32
+ })
33
+
34
+ watch(
35
+ () => props.modelValue,
36
+ (data: string | null | undefined) => {
37
+ // 这里要截取一下字符串长度
38
+ if (data && data.length > attrs.value.maxlength) {
39
+ data = data.substring(0, attrs.value.maxlength)
40
+ }
41
+ currentValue.value = data
42
+ },
43
+ { immediate: true }
44
+ )
45
+ </script>