el-plus-crud 0.0.39 → 0.0.41
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/.eslintrc.js +78 -78
- package/.prettierrc.js +39 -39
- package/CHANGELOG.md +5 -1
- package/build.js +31 -31
- package/dist/el-plus-crud.mjs +1803 -1801
- package/dist/el-plus-crud.umd.js +7 -7
- package/dist/style.css +1 -1
- package/example/App.vue +67 -67
- package/example/main.js +18 -18
- package/index.html +13 -13
- package/lib/components/el-plus-form/ElPlusForm.vue +771 -774
- package/lib/components/el-plus-form/ElPlusFormDialog.vue +90 -90
- package/lib/components/el-plus-form/ElPlusFormGroup.vue +116 -116
- package/lib/components/el-plus-form/components/ElPlusFormArea.vue +61 -61
- package/lib/components/el-plus-form/components/ElPlusFormAutocomplete.vue +49 -49
- package/lib/components/el-plus-form/components/ElPlusFormBtn.vue +102 -102
- package/lib/components/el-plus-form/components/ElPlusFormBtns.vue +133 -133
- package/lib/components/el-plus-form/components/ElPlusFormCascader.vue +63 -63
- package/lib/components/el-plus-form/components/ElPlusFormCascaderPanel.vue +53 -53
- package/lib/components/el-plus-form/components/ElPlusFormCheckbox.vue +44 -44
- package/lib/components/el-plus-form/components/ElPlusFormCheckboxButton.vue +44 -44
- package/lib/components/el-plus-form/components/ElPlusFormColor.vue +38 -38
- package/lib/components/el-plus-form/components/ElPlusFormDate.vue +39 -39
- package/lib/components/el-plus-form/components/ElPlusFormDaterange.vue +46 -46
- package/lib/components/el-plus-form/components/ElPlusFormDatetime.vue +40 -40
- package/lib/components/el-plus-form/components/ElPlusFormFile.vue +47 -47
- package/lib/components/el-plus-form/components/ElPlusFormImage.vue +113 -113
- package/lib/components/el-plus-form/components/ElPlusFormLink.vue +281 -281
- package/lib/components/el-plus-form/components/ElPlusFormLkuser.vue +489 -489
- package/lib/components/el-plus-form/components/ElPlusFormNbinput.vue +53 -53
- package/lib/components/el-plus-form/components/ElPlusFormNumber.vue +146 -146
- package/lib/components/el-plus-form/components/ElPlusFormQuickInput.vue +94 -94
- package/lib/components/el-plus-form/components/ElPlusFormRadio.vue +42 -42
- package/lib/components/el-plus-form/components/ElPlusFormRate.vue +38 -38
- package/lib/components/el-plus-form/components/ElPlusFormSelect.vue +161 -161
- package/lib/components/el-plus-form/components/ElPlusFormSlider.vue +38 -38
- package/lib/components/el-plus-form/components/ElPlusFormSwitch.vue +38 -38
- package/lib/components/el-plus-form/components/ElPlusFormTag.vue +78 -78
- package/lib/components/el-plus-form/components/ElPlusFormText.vue +99 -99
- package/lib/components/el-plus-form/components/ElPlusFormTextarea.vue +49 -49
- package/lib/components/el-plus-form/components/ElPlusFormTransfer.vue +44 -44
- package/lib/components/el-plus-form/components/ElPlusFormTree.vue +76 -76
- package/lib/components/el-plus-form/components/ElPlusFormTreeSelect.vue +59 -59
- package/lib/components/el-plus-form/components/ElPlusFormUpload.vue +368 -368
- package/lib/components/el-plus-form/components/components/file-icons/FileIcons.vue +135 -135
- package/lib/components/el-plus-form/components/components/file-icons/data/index.ts +27 -27
- package/lib/components/el-plus-form/components/components/file-icons/images/doc.svg +12 -12
- package/lib/components/el-plus-form/components/components/file-icons/images/file.svg +18 -18
- package/lib/components/el-plus-form/components/components/file-icons/images/jpg.svg +13 -13
- package/lib/components/el-plus-form/components/components/file-icons/images/pdf.svg +12 -12
- package/lib/components/el-plus-form/components/components/file-icons/images/png.svg +12 -12
- package/lib/components/el-plus-form/components/components/file-icons/images/ppt.svg +12 -12
- package/lib/components/el-plus-form/components/components/file-icons/images/xls.svg +12 -12
- package/lib/components/el-plus-form/components/index.ts +17 -17
- package/lib/components/el-plus-form/data/file.ts +74 -74
- package/lib/components/el-plus-form/mixins/index.ts +115 -113
- package/lib/components/el-plus-form/util/index.ts +257 -257
- package/lib/components/el-plus-form/util/validate.ts +332 -332
- package/lib/components/el-plus-table/components/columnItem.vue +205 -205
- package/lib/components/el-plus-table/components/header.vue +240 -240
- package/lib/components/el-plus-table/components/statisticInfo.vue +47 -47
- package/lib/components/el-plus-table/util/index.ts +147 -147
- package/lib/config/index.ts +30 -30
- package/lib/index.d.ts +4 -4
- package/lib/index.ts +51 -51
- package/package.json +1 -1
- package/types/axios.d.ts +13 -13
- package/types/formList.d.ts +440 -440
- package/types/layout.d.ts +57 -57
- package/types/mitt.d.ts +38 -38
- package/types/pinia.d.ts +149 -149
- package/types/views.d.ts +329 -329
- package/vite.config.ts +78 -78
|
@@ -1,368 +1,368 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<div class="ele-form-upload-image" :class="{ 'ele-form-upload-file': desc.upType === 'file' }">
|
|
3
|
-
<el-upload class="ele-image-upload" v-bind="attrs" v-on="onEvents" :fileList="currentValue || []" :class="{ 'over-limit': currentValue?.length >= attrs.limit, 'upload-disabled': attrs.disabled }">
|
|
4
|
-
<div class="upload-panel-icon">
|
|
5
|
-
<i v-if="desc.icon" :class="desc.icon" :style="{ fontSize: desc.fontSize || '14px', color: desc.color || '#C0C4CC' }"></i>
|
|
6
|
-
<el-icon v-else :style="{ fontSize: desc.fontSize || '14px', color: desc.color || '#C0C4CC' }"><Plus /></el-icon>
|
|
7
|
-
<div class="el-upload__text2" v-if="desc.upType === 'file' && desc.text2">
|
|
8
|
-
{{ desc.text2 }}
|
|
9
|
-
</div>
|
|
10
|
-
<div class="el-upload__text" v-if="desc.upType === 'file'">
|
|
11
|
-
{{ desc.text || '拖拽/点击上传' }}
|
|
12
|
-
</div>
|
|
13
|
-
</div>
|
|
14
|
-
<!-- <template #file="file">
|
|
15
|
-
<UploadShowIcon :file="file"></UploadShowIcon>
|
|
16
|
-
</template> -->
|
|
17
|
-
</el-upload>
|
|
18
|
-
|
|
19
|
-
<!-- 图片查看的站位标签 -->
|
|
20
|
-
<el-image-viewer v-if="showPreview" @close="showPreview = false" teleported :initialIndex="previewIndex" :url-list="previewList" />
|
|
21
|
-
<div v-if="!attrs.autoUpload" class="upload-hands-submit">
|
|
22
|
-
<el-button style="margin-left: 10px" size="small" type="success" @click="submit"> 上传到服务器 </el-button>
|
|
23
|
-
</div>
|
|
24
|
-
</div>
|
|
25
|
-
</template>
|
|
26
|
-
<script lang="ts">
|
|
27
|
-
export default {
|
|
28
|
-
name: 'ElPlusFormUpload',
|
|
29
|
-
inheritAttrs: false,
|
|
30
|
-
typeName: 'upload',
|
|
31
|
-
customOptions: {}
|
|
32
|
-
}
|
|
33
|
-
</script>
|
|
34
|
-
<script lang="ts" setup>
|
|
35
|
-
import { ref, computed, useAttrs, onBeforeMount, watch, inject } from 'vue'
|
|
36
|
-
import { getAttrs, getEvents } from '../mixins'
|
|
37
|
-
import { ElMessage, UploadUserFile } from 'element-plus'
|
|
38
|
-
import { Plus } from '@element-plus/icons-vue'
|
|
39
|
-
|
|
40
|
-
import * as fileTypes from '../data/file'
|
|
41
|
-
|
|
42
|
-
// 引入图标
|
|
43
|
-
import excel from '../images/icon/excel.png'
|
|
44
|
-
import pdf from '../images/icon/pdf.png'
|
|
45
|
-
import file from '../images/icon/file.png'
|
|
46
|
-
import txt from '../images/icon/txt.png'
|
|
47
|
-
import word from '../images/icon/word.png'
|
|
48
|
-
import zip from '../images/icon/zip.png'
|
|
49
|
-
import ppt from '../images/icon/ppt.png'
|
|
50
|
-
|
|
51
|
-
const defaultConf = inject('defaultConf') as ICRUDConfig
|
|
52
|
-
|
|
53
|
-
// 图标Map
|
|
54
|
-
const iconMap = { excel, pdf, file, txt, word, zip, ppt }
|
|
55
|
-
|
|
56
|
-
const props = defineProps<{
|
|
57
|
-
modelValue?: Array<IOssInfo>
|
|
58
|
-
field: string
|
|
59
|
-
loading?: boolean
|
|
60
|
-
desc: { [key: string]: any }
|
|
61
|
-
formData: { [key: string]: any }
|
|
62
|
-
}>()
|
|
63
|
-
|
|
64
|
-
const emits = defineEmits(['update:modelValue', 'validateThis'])
|
|
65
|
-
const currentValue = ref((typeof props.modelValue === 'string' ? [{ url: props.modelValue }] : props.modelValue) || [])
|
|
66
|
-
|
|
67
|
-
emits('update:modelValue', currentValue)
|
|
68
|
-
|
|
69
|
-
const attrs = ref({} as any)
|
|
70
|
-
const onEvents = ref(getEvents(props))
|
|
71
|
-
|
|
72
|
-
const showPreview = ref(false)
|
|
73
|
-
const previewIndex = ref(0)
|
|
74
|
-
const previewList = computed(() =>
|
|
75
|
-
currentValue.value
|
|
76
|
-
.map((item: any) => {
|
|
77
|
-
if (['.png', '.jpg', '.gif', '.jpeg'].indexOf(item.raw?.suffix || item.suffix) >= 0) {
|
|
78
|
-
return item.url
|
|
79
|
-
}
|
|
80
|
-
})
|
|
81
|
-
.filter((url) => url)
|
|
82
|
-
)
|
|
83
|
-
|
|
84
|
-
onBeforeMount(async () => {
|
|
85
|
-
// // 如果没有配置,则抛出一个警告
|
|
86
|
-
if (!defaultConf.upload || (!defaultConf.upload.action && !defaultConf.upload.minio?.getObjectAuthUrl)) {
|
|
87
|
-
console.warn('缺少文件上传配置,无法使用upload组件~')
|
|
88
|
-
}
|
|
89
|
-
attrs.value = await getAttrs(props, {
|
|
90
|
-
drag: true,
|
|
91
|
-
listType: props.desc.upType === 'file' ? 'text' : 'picture-card',
|
|
92
|
-
multiple: !!props.desc.multiple,
|
|
93
|
-
limit: props.desc.multiple ? props.desc.limit || 20 : 1,
|
|
94
|
-
autoUpload: props.desc.autoUpload ?? true,
|
|
95
|
-
accept: props.desc.accept || fileTypes[`${props.desc.upType || 'image'}Types`].join(','),
|
|
96
|
-
maxSize: props.desc.maxSize || (props.desc.upType === 'file' ? defaultConf.upload?.maxFSize : defaultConf.upload?.maxISize),
|
|
97
|
-
beforeUpload: handelUploadBefore,
|
|
98
|
-
onRemove: handelUploadRemove,
|
|
99
|
-
onSuccess: handelUploadSuccess,
|
|
100
|
-
onExceed: handleOutOfLimit,
|
|
101
|
-
onPreview: handelPreview,
|
|
102
|
-
httpRequest: handelRequest,
|
|
103
|
-
...useAttrs()
|
|
104
|
-
})
|
|
105
|
-
})
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* 处理删除
|
|
109
|
-
* @param file
|
|
110
|
-
* @param fileList
|
|
111
|
-
*/
|
|
112
|
-
function handelUploadRemove(file: UploadUserFile) {
|
|
113
|
-
handelListChange(file, 0)
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* 上传成功回调
|
|
118
|
-
* @param _
|
|
119
|
-
* @param file
|
|
120
|
-
* @param fileList
|
|
121
|
-
*/
|
|
122
|
-
async function handelUploadSuccess(_: any, file: any) {
|
|
123
|
-
const { objectUrl, previewUrl } = await defaultConf.upload?.minio?.getObjectAuthUrl(file.raw.uploadId)
|
|
124
|
-
file.raw.shareUrl = objectUrl
|
|
125
|
-
file.raw.previewUrl = previewUrl
|
|
126
|
-
file.url = getFileIcon(file.raw)
|
|
127
|
-
// console.log('handelUploadSuccess: file: ', file)
|
|
128
|
-
handelListChange(file, 1)
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* 获取文件Icon
|
|
133
|
-
* @param file
|
|
134
|
-
*/
|
|
135
|
-
function getFileIcon(file?: any): string {
|
|
136
|
-
if (file) {
|
|
137
|
-
const suffix = (file?.suffix || '') as string
|
|
138
|
-
if (suffix) {
|
|
139
|
-
if (['.png', '.jpg', '.gif', '.jpeg'].indexOf(suffix) >= 0) {
|
|
140
|
-
// return (props.desc.upType === 'file' ? file.previewUrl : file.shareUrl) || file.furl || file.path
|
|
141
|
-
return file.shareUrl || file.furl || file.path
|
|
142
|
-
}
|
|
143
|
-
for (let i = 0; i < fileTypes.suffixTypes.length; i++) {
|
|
144
|
-
for (let j = 0; j < fileTypes.suffixTypes[i].suffixes.length; j++) {
|
|
145
|
-
if (fileTypes.suffixTypes[i].suffixes[j] === suffix) {
|
|
146
|
-
return iconMap[fileTypes.suffixTypes[i].type]
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
return iconMap.file
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* 处理图片列表的修改
|
|
157
|
-
* @param file
|
|
158
|
-
* @param type 0 : 删除; 1: 新增
|
|
159
|
-
*/
|
|
160
|
-
function handelListChange(item: UploadUserFile, type: 0 | 1) {
|
|
161
|
-
if (type === 1) {
|
|
162
|
-
currentValue.value.push({
|
|
163
|
-
name: item.name,
|
|
164
|
-
furl: (item.raw as any)?.path || item.url,
|
|
165
|
-
url: getFileIcon(item.raw),
|
|
166
|
-
fsize: item.size,
|
|
167
|
-
uid: item.uid,
|
|
168
|
-
mimeType: item.raw?.type,
|
|
169
|
-
suffix: (item.raw as any).suffix,
|
|
170
|
-
busId: props.desc.busId,
|
|
171
|
-
busType: props.desc.busType
|
|
172
|
-
})
|
|
173
|
-
} else {
|
|
174
|
-
const index = currentValue.value.findIndex((file) => file.uid === item.uid)
|
|
175
|
-
if (index >= 0) {
|
|
176
|
-
currentValue.value.splice(index, 1)
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
emits('validateThis')
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* 上传之前,校验文件大小以及类型
|
|
184
|
-
* @param file
|
|
185
|
-
*/
|
|
186
|
-
async function handelUploadBefore(file: any) {
|
|
187
|
-
file.suffix = (file.name as string).substring(file.name.lastIndexOf('.'))
|
|
188
|
-
const message = validateFile(file, fileTypes[`${props.desc.upType || 'image'}Suffixes`], attrs.value.maxSize)
|
|
189
|
-
if (message !== true) {
|
|
190
|
-
ElMessage.warning(message)
|
|
191
|
-
return false
|
|
192
|
-
}
|
|
193
|
-
// 获取文件上传的路径
|
|
194
|
-
const uploadInfo = (await defaultConf.upload?.minio?.getUploadUrl(file.name)) as any
|
|
195
|
-
file.action = uploadInfo.uploadUrl
|
|
196
|
-
file.path = uploadInfo.objectUrl
|
|
197
|
-
file.previewUrl = uploadInfo.previewUrl
|
|
198
|
-
file.uploadId = uploadInfo.uploadId
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
/**
|
|
202
|
-
* 浏览图片
|
|
203
|
-
* @param file
|
|
204
|
-
*/
|
|
205
|
-
function handelPreview(file: any) {
|
|
206
|
-
if (['.png', '.jpg', '.gif', '.jpeg'].indexOf(file.raw?.suffix || file.suffix) >= 0) {
|
|
207
|
-
previewIndex.value = previewList.value.findIndex((item) => item === (file.raw?.shareUrl || file.raw?.path || file.furl))
|
|
208
|
-
if (previewIndex.value < 0) {
|
|
209
|
-
previewIndex.value = 0
|
|
210
|
-
}
|
|
211
|
-
showPreview.value = true
|
|
212
|
-
} else {
|
|
213
|
-
window.open(file.raw?.previewUrl || file.previewUrl, '_blank')
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
/**
|
|
218
|
-
* 超出上传数量
|
|
219
|
-
*/
|
|
220
|
-
function handleOutOfLimit() {
|
|
221
|
-
ElMessage.error('数量最多只能上传' + attrs.value.limit + '个图片/文件!!!')
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
/**
|
|
225
|
-
* 处理自定义请求
|
|
226
|
-
* @param param
|
|
227
|
-
*/
|
|
228
|
-
async function handelRequest(param: any) {
|
|
229
|
-
await defaultConf.upload?.minio?.doElUpload(param)
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
// 手动调用上传的方法
|
|
233
|
-
function submit() {
|
|
234
|
-
// this.$refs[this.ref].submit()
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
/**
|
|
238
|
-
* 校验文件
|
|
239
|
-
* @param file
|
|
240
|
-
* @param types
|
|
241
|
-
* @param maxSize
|
|
242
|
-
*/
|
|
243
|
-
function validateFile(file: any, types: Array<any>, maxSize: number) {
|
|
244
|
-
// 校验文件大小
|
|
245
|
-
if (file.size > maxSize) {
|
|
246
|
-
return '上传文件大小不能超过 ' + (maxSize / 1024 / 1024).toFixed(2) + 'M~'
|
|
247
|
-
}
|
|
248
|
-
// 开始校验文件类型
|
|
249
|
-
if (types && types.length > 0) {
|
|
250
|
-
if (types.every((type) => type !== file.suffix)) {
|
|
251
|
-
return '上传文件类型错误,请重新选择~'
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
return true
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
watch(
|
|
258
|
-
() => props.modelValue,
|
|
259
|
-
(data: Array<IOssInfo> | undefined, oldData: any) => {
|
|
260
|
-
if (JSON.stringify(data) !== JSON.stringify(oldData)) {
|
|
261
|
-
// 这里初始化一下
|
|
262
|
-
currentValue.value =
|
|
263
|
-
data?.map((item: IOssInfo) => {
|
|
264
|
-
item.url = getFileIcon(item)
|
|
265
|
-
return item
|
|
266
|
-
}) || []
|
|
267
|
-
}
|
|
268
|
-
},
|
|
269
|
-
{ immediate: true }
|
|
270
|
-
)
|
|
271
|
-
</script>
|
|
272
|
-
<style lang="scss">
|
|
273
|
-
.ele-form-upload-image {
|
|
274
|
-
width: 100%;
|
|
275
|
-
display: flex;
|
|
276
|
-
|
|
277
|
-
.ele-image-upload {
|
|
278
|
-
display: flex;
|
|
279
|
-
justify-content: flex-start;
|
|
280
|
-
width: 100%;
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
.upload-panel-icon {
|
|
284
|
-
margin: auto;
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
.upload-disabled {
|
|
288
|
-
.el-upload--picture-card {
|
|
289
|
-
cursor: not-allowed !important;
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
.el-icon-close-tip {
|
|
294
|
-
display: none !important;
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
.el-upload--picture-card {
|
|
298
|
-
margin-bottom: 12px;
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
.over-limit {
|
|
302
|
-
.el-upload--picture-card {
|
|
303
|
-
display: none !important;
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
.el-upload--picture-card,
|
|
308
|
-
.el-upload-list--picture-card .el-upload-list__item {
|
|
309
|
-
width: 100px !important;
|
|
310
|
-
height: 100px !important;
|
|
311
|
-
border: none !important;
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
.el-upload-dragger {
|
|
315
|
-
display: flex;
|
|
316
|
-
padding: 0 !important;
|
|
317
|
-
min-height: 100px;
|
|
318
|
-
// height: 100px !important;
|
|
319
|
-
|
|
320
|
-
.el-upload__text {
|
|
321
|
-
font-size: 12px !important;
|
|
322
|
-
color: #999999;
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
.el-upload__text2 {
|
|
326
|
-
font-size: 16px;
|
|
327
|
-
color: #303133;
|
|
328
|
-
line-height: 22px;
|
|
329
|
-
margin-top: 16px;
|
|
330
|
-
margin-bottom: 16px;
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
.el-progress-circle {
|
|
335
|
-
width: 90px !important;
|
|
336
|
-
height: 90px !important;
|
|
337
|
-
margin: auto;
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
.el-upload-list--picture-card .el-upload-list__item-thumbnail {
|
|
341
|
-
object-fit: cover !important;
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
.el-icon--close-tip {
|
|
345
|
-
display: none !important;
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
.ele-form-upload-file {
|
|
350
|
-
.ele-image-upload {
|
|
351
|
-
flex-direction: column;
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
.el-upload-list__item {
|
|
355
|
-
margin: 0 !important;
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
.el-form-item--default .el-form-item__content {
|
|
359
|
-
line-height: 20px !important;
|
|
360
|
-
font-size: 12px !important;
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
.el-upload-list__item-name {
|
|
364
|
-
line-height: 20px !important;
|
|
365
|
-
font-size: 12px !important;
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
</style>
|
|
1
|
+
<template>
|
|
2
|
+
<div class="ele-form-upload-image" :class="{ 'ele-form-upload-file': desc.upType === 'file' }">
|
|
3
|
+
<el-upload class="ele-image-upload" v-bind="attrs" v-on="onEvents" :fileList="currentValue || []" :class="{ 'over-limit': currentValue?.length >= attrs.limit, 'upload-disabled': attrs.disabled }">
|
|
4
|
+
<div class="upload-panel-icon">
|
|
5
|
+
<i v-if="desc.icon" :class="desc.icon" :style="{ fontSize: desc.fontSize || '14px', color: desc.color || '#C0C4CC' }"></i>
|
|
6
|
+
<el-icon v-else :style="{ fontSize: desc.fontSize || '14px', color: desc.color || '#C0C4CC' }"><Plus /></el-icon>
|
|
7
|
+
<div class="el-upload__text2" v-if="desc.upType === 'file' && desc.text2">
|
|
8
|
+
{{ desc.text2 }}
|
|
9
|
+
</div>
|
|
10
|
+
<div class="el-upload__text" v-if="desc.upType === 'file'">
|
|
11
|
+
{{ desc.text || '拖拽/点击上传' }}
|
|
12
|
+
</div>
|
|
13
|
+
</div>
|
|
14
|
+
<!-- <template #file="file">
|
|
15
|
+
<UploadShowIcon :file="file"></UploadShowIcon>
|
|
16
|
+
</template> -->
|
|
17
|
+
</el-upload>
|
|
18
|
+
|
|
19
|
+
<!-- 图片查看的站位标签 -->
|
|
20
|
+
<el-image-viewer v-if="showPreview" @close="showPreview = false" teleported :initialIndex="previewIndex" :url-list="previewList" />
|
|
21
|
+
<div v-if="!attrs.autoUpload" class="upload-hands-submit">
|
|
22
|
+
<el-button style="margin-left: 10px" size="small" type="success" @click="submit"> 上传到服务器 </el-button>
|
|
23
|
+
</div>
|
|
24
|
+
</div>
|
|
25
|
+
</template>
|
|
26
|
+
<script lang="ts">
|
|
27
|
+
export default {
|
|
28
|
+
name: 'ElPlusFormUpload',
|
|
29
|
+
inheritAttrs: false,
|
|
30
|
+
typeName: 'upload',
|
|
31
|
+
customOptions: {}
|
|
32
|
+
}
|
|
33
|
+
</script>
|
|
34
|
+
<script lang="ts" setup>
|
|
35
|
+
import { ref, computed, useAttrs, onBeforeMount, watch, inject } from 'vue'
|
|
36
|
+
import { getAttrs, getEvents } from '../mixins'
|
|
37
|
+
import { ElMessage, UploadUserFile } from 'element-plus'
|
|
38
|
+
import { Plus } from '@element-plus/icons-vue'
|
|
39
|
+
|
|
40
|
+
import * as fileTypes from '../data/file'
|
|
41
|
+
|
|
42
|
+
// 引入图标
|
|
43
|
+
import excel from '../images/icon/excel.png'
|
|
44
|
+
import pdf from '../images/icon/pdf.png'
|
|
45
|
+
import file from '../images/icon/file.png'
|
|
46
|
+
import txt from '../images/icon/txt.png'
|
|
47
|
+
import word from '../images/icon/word.png'
|
|
48
|
+
import zip from '../images/icon/zip.png'
|
|
49
|
+
import ppt from '../images/icon/ppt.png'
|
|
50
|
+
|
|
51
|
+
const defaultConf = inject('defaultConf') as ICRUDConfig
|
|
52
|
+
|
|
53
|
+
// 图标Map
|
|
54
|
+
const iconMap = { excel, pdf, file, txt, word, zip, ppt }
|
|
55
|
+
|
|
56
|
+
const props = defineProps<{
|
|
57
|
+
modelValue?: Array<IOssInfo>
|
|
58
|
+
field: string
|
|
59
|
+
loading?: boolean
|
|
60
|
+
desc: { [key: string]: any }
|
|
61
|
+
formData: { [key: string]: any }
|
|
62
|
+
}>()
|
|
63
|
+
|
|
64
|
+
const emits = defineEmits(['update:modelValue', 'validateThis'])
|
|
65
|
+
const currentValue = ref((typeof props.modelValue === 'string' ? [{ url: props.modelValue }] : props.modelValue) || [])
|
|
66
|
+
|
|
67
|
+
emits('update:modelValue', currentValue)
|
|
68
|
+
|
|
69
|
+
const attrs = ref({} as any)
|
|
70
|
+
const onEvents = ref(getEvents(props))
|
|
71
|
+
|
|
72
|
+
const showPreview = ref(false)
|
|
73
|
+
const previewIndex = ref(0)
|
|
74
|
+
const previewList = computed(() =>
|
|
75
|
+
currentValue.value
|
|
76
|
+
.map((item: any) => {
|
|
77
|
+
if (['.png', '.jpg', '.gif', '.jpeg'].indexOf(item.raw?.suffix || item.suffix) >= 0) {
|
|
78
|
+
return item.url
|
|
79
|
+
}
|
|
80
|
+
})
|
|
81
|
+
.filter((url) => url)
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
onBeforeMount(async () => {
|
|
85
|
+
// // 如果没有配置,则抛出一个警告
|
|
86
|
+
if (!defaultConf.upload || (!defaultConf.upload.action && !defaultConf.upload.minio?.getObjectAuthUrl)) {
|
|
87
|
+
console.warn('缺少文件上传配置,无法使用upload组件~')
|
|
88
|
+
}
|
|
89
|
+
attrs.value = await getAttrs(props, {
|
|
90
|
+
drag: true,
|
|
91
|
+
listType: props.desc.upType === 'file' ? 'text' : 'picture-card',
|
|
92
|
+
multiple: !!props.desc.multiple,
|
|
93
|
+
limit: props.desc.multiple ? props.desc.limit || 20 : 1,
|
|
94
|
+
autoUpload: props.desc.autoUpload ?? true,
|
|
95
|
+
accept: props.desc.accept || fileTypes[`${props.desc.upType || 'image'}Types`].join(','),
|
|
96
|
+
maxSize: props.desc.maxSize || (props.desc.upType === 'file' ? defaultConf.upload?.maxFSize : defaultConf.upload?.maxISize),
|
|
97
|
+
beforeUpload: handelUploadBefore,
|
|
98
|
+
onRemove: handelUploadRemove,
|
|
99
|
+
onSuccess: handelUploadSuccess,
|
|
100
|
+
onExceed: handleOutOfLimit,
|
|
101
|
+
onPreview: handelPreview,
|
|
102
|
+
httpRequest: handelRequest,
|
|
103
|
+
...useAttrs()
|
|
104
|
+
})
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* 处理删除
|
|
109
|
+
* @param file
|
|
110
|
+
* @param fileList
|
|
111
|
+
*/
|
|
112
|
+
function handelUploadRemove(file: UploadUserFile) {
|
|
113
|
+
handelListChange(file, 0)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* 上传成功回调
|
|
118
|
+
* @param _
|
|
119
|
+
* @param file
|
|
120
|
+
* @param fileList
|
|
121
|
+
*/
|
|
122
|
+
async function handelUploadSuccess(_: any, file: any) {
|
|
123
|
+
const { objectUrl, previewUrl } = await defaultConf.upload?.minio?.getObjectAuthUrl(file.raw.uploadId)
|
|
124
|
+
file.raw.shareUrl = objectUrl
|
|
125
|
+
file.raw.previewUrl = previewUrl
|
|
126
|
+
file.url = getFileIcon(file.raw)
|
|
127
|
+
// console.log('handelUploadSuccess: file: ', file)
|
|
128
|
+
handelListChange(file, 1)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* 获取文件Icon
|
|
133
|
+
* @param file
|
|
134
|
+
*/
|
|
135
|
+
function getFileIcon(file?: any): string {
|
|
136
|
+
if (file) {
|
|
137
|
+
const suffix = (file?.suffix || '') as string
|
|
138
|
+
if (suffix) {
|
|
139
|
+
if (['.png', '.jpg', '.gif', '.jpeg'].indexOf(suffix) >= 0) {
|
|
140
|
+
// return (props.desc.upType === 'file' ? file.previewUrl : file.shareUrl) || file.furl || file.path
|
|
141
|
+
return file.shareUrl || file.furl || file.path
|
|
142
|
+
}
|
|
143
|
+
for (let i = 0; i < fileTypes.suffixTypes.length; i++) {
|
|
144
|
+
for (let j = 0; j < fileTypes.suffixTypes[i].suffixes.length; j++) {
|
|
145
|
+
if (fileTypes.suffixTypes[i].suffixes[j] === suffix) {
|
|
146
|
+
return iconMap[fileTypes.suffixTypes[i].type]
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return iconMap.file
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* 处理图片列表的修改
|
|
157
|
+
* @param file
|
|
158
|
+
* @param type 0 : 删除; 1: 新增
|
|
159
|
+
*/
|
|
160
|
+
function handelListChange(item: UploadUserFile, type: 0 | 1) {
|
|
161
|
+
if (type === 1) {
|
|
162
|
+
currentValue.value.push({
|
|
163
|
+
name: item.name,
|
|
164
|
+
furl: (item.raw as any)?.path || item.url,
|
|
165
|
+
url: getFileIcon(item.raw),
|
|
166
|
+
fsize: item.size,
|
|
167
|
+
uid: item.uid,
|
|
168
|
+
mimeType: item.raw?.type,
|
|
169
|
+
suffix: (item.raw as any).suffix,
|
|
170
|
+
busId: props.desc.busId,
|
|
171
|
+
busType: props.desc.busType
|
|
172
|
+
})
|
|
173
|
+
} else {
|
|
174
|
+
const index = currentValue.value.findIndex((file) => file.uid === item.uid)
|
|
175
|
+
if (index >= 0) {
|
|
176
|
+
currentValue.value.splice(index, 1)
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
emits('validateThis')
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* 上传之前,校验文件大小以及类型
|
|
184
|
+
* @param file
|
|
185
|
+
*/
|
|
186
|
+
async function handelUploadBefore(file: any) {
|
|
187
|
+
file.suffix = (file.name as string).substring(file.name.lastIndexOf('.'))
|
|
188
|
+
const message = validateFile(file, fileTypes[`${props.desc.upType || 'image'}Suffixes`], attrs.value.maxSize)
|
|
189
|
+
if (message !== true) {
|
|
190
|
+
ElMessage.warning(message)
|
|
191
|
+
return false
|
|
192
|
+
}
|
|
193
|
+
// 获取文件上传的路径
|
|
194
|
+
const uploadInfo = (await defaultConf.upload?.minio?.getUploadUrl(file.name)) as any
|
|
195
|
+
file.action = uploadInfo.uploadUrl
|
|
196
|
+
file.path = uploadInfo.objectUrl
|
|
197
|
+
file.previewUrl = uploadInfo.previewUrl
|
|
198
|
+
file.uploadId = uploadInfo.uploadId
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* 浏览图片
|
|
203
|
+
* @param file
|
|
204
|
+
*/
|
|
205
|
+
function handelPreview(file: any) {
|
|
206
|
+
if (['.png', '.jpg', '.gif', '.jpeg'].indexOf(file.raw?.suffix || file.suffix) >= 0) {
|
|
207
|
+
previewIndex.value = previewList.value.findIndex((item) => item === (file.raw?.shareUrl || file.raw?.path || file.furl))
|
|
208
|
+
if (previewIndex.value < 0) {
|
|
209
|
+
previewIndex.value = 0
|
|
210
|
+
}
|
|
211
|
+
showPreview.value = true
|
|
212
|
+
} else {
|
|
213
|
+
window.open(file.raw?.previewUrl || file.previewUrl, '_blank')
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* 超出上传数量
|
|
219
|
+
*/
|
|
220
|
+
function handleOutOfLimit() {
|
|
221
|
+
ElMessage.error('数量最多只能上传' + attrs.value.limit + '个图片/文件!!!')
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* 处理自定义请求
|
|
226
|
+
* @param param
|
|
227
|
+
*/
|
|
228
|
+
async function handelRequest(param: any) {
|
|
229
|
+
await defaultConf.upload?.minio?.doElUpload(param)
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
// 手动调用上传的方法
|
|
233
|
+
function submit() {
|
|
234
|
+
// this.$refs[this.ref].submit()
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* 校验文件
|
|
239
|
+
* @param file
|
|
240
|
+
* @param types
|
|
241
|
+
* @param maxSize
|
|
242
|
+
*/
|
|
243
|
+
function validateFile(file: any, types: Array<any>, maxSize: number) {
|
|
244
|
+
// 校验文件大小
|
|
245
|
+
if (file.size > maxSize) {
|
|
246
|
+
return '上传文件大小不能超过 ' + (maxSize / 1024 / 1024).toFixed(2) + 'M~'
|
|
247
|
+
}
|
|
248
|
+
// 开始校验文件类型
|
|
249
|
+
if (types && types.length > 0) {
|
|
250
|
+
if (types.every((type) => type !== file.suffix)) {
|
|
251
|
+
return '上传文件类型错误,请重新选择~'
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
return true
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
watch(
|
|
258
|
+
() => props.modelValue,
|
|
259
|
+
(data: Array<IOssInfo> | undefined, oldData: any) => {
|
|
260
|
+
if (JSON.stringify(data) !== JSON.stringify(oldData)) {
|
|
261
|
+
// 这里初始化一下
|
|
262
|
+
currentValue.value =
|
|
263
|
+
data?.map((item: IOssInfo) => {
|
|
264
|
+
item.url = getFileIcon(item)
|
|
265
|
+
return item
|
|
266
|
+
}) || []
|
|
267
|
+
}
|
|
268
|
+
},
|
|
269
|
+
{ immediate: true }
|
|
270
|
+
)
|
|
271
|
+
</script>
|
|
272
|
+
<style lang="scss">
|
|
273
|
+
.ele-form-upload-image {
|
|
274
|
+
width: 100%;
|
|
275
|
+
display: flex;
|
|
276
|
+
|
|
277
|
+
.ele-image-upload {
|
|
278
|
+
display: flex;
|
|
279
|
+
justify-content: flex-start;
|
|
280
|
+
width: 100%;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
.upload-panel-icon {
|
|
284
|
+
margin: auto;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
.upload-disabled {
|
|
288
|
+
.el-upload--picture-card {
|
|
289
|
+
cursor: not-allowed !important;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
.el-icon-close-tip {
|
|
294
|
+
display: none !important;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
.el-upload--picture-card {
|
|
298
|
+
margin-bottom: 12px;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
.over-limit {
|
|
302
|
+
.el-upload--picture-card {
|
|
303
|
+
display: none !important;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
.el-upload--picture-card,
|
|
308
|
+
.el-upload-list--picture-card .el-upload-list__item {
|
|
309
|
+
width: 100px !important;
|
|
310
|
+
height: 100px !important;
|
|
311
|
+
border: none !important;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
.el-upload-dragger {
|
|
315
|
+
display: flex;
|
|
316
|
+
padding: 0 !important;
|
|
317
|
+
min-height: 100px;
|
|
318
|
+
// height: 100px !important;
|
|
319
|
+
|
|
320
|
+
.el-upload__text {
|
|
321
|
+
font-size: 12px !important;
|
|
322
|
+
color: #999999;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
.el-upload__text2 {
|
|
326
|
+
font-size: 16px;
|
|
327
|
+
color: #303133;
|
|
328
|
+
line-height: 22px;
|
|
329
|
+
margin-top: 16px;
|
|
330
|
+
margin-bottom: 16px;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
.el-progress-circle {
|
|
335
|
+
width: 90px !important;
|
|
336
|
+
height: 90px !important;
|
|
337
|
+
margin: auto;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
.el-upload-list--picture-card .el-upload-list__item-thumbnail {
|
|
341
|
+
object-fit: cover !important;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
.el-icon--close-tip {
|
|
345
|
+
display: none !important;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
.ele-form-upload-file {
|
|
350
|
+
.ele-image-upload {
|
|
351
|
+
flex-direction: column;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
.el-upload-list__item {
|
|
355
|
+
margin: 0 !important;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
.el-form-item--default .el-form-item__content {
|
|
359
|
+
line-height: 20px !important;
|
|
360
|
+
font-size: 12px !important;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
.el-upload-list__item-name {
|
|
364
|
+
line-height: 20px !important;
|
|
365
|
+
font-size: 12px !important;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
</style>
|