qtsk-vue3 0.0.22 → 0.0.23
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/component.js
CHANGED
@@ -21,6 +21,7 @@ import Area from './components/Area/index.vue'
|
|
21
21
|
import Radio from './components/Radio/index.vue'
|
22
22
|
import Number from './components/Number/index.vue'
|
23
23
|
import Checkbox from './components/CheckBox/index.vue'
|
24
|
+
import Upload from './components/Upload/index.vue'
|
24
25
|
const components =
|
25
26
|
[
|
26
27
|
CommonButton,
|
@@ -45,6 +46,7 @@ const components =
|
|
45
46
|
Area,
|
46
47
|
Radio,
|
47
48
|
Number,
|
48
|
-
Checkbox
|
49
|
+
Checkbox,
|
50
|
+
Upload
|
49
51
|
]
|
50
52
|
export default components
|
@@ -1,5 +1,5 @@
|
|
1
1
|
<template>
|
2
|
-
<el-icon :size="size">
|
2
|
+
<el-icon :size="size" :color="color">
|
3
3
|
<component :is='iconComponent'></component>
|
4
4
|
</el-icon>
|
5
5
|
</template>
|
@@ -20,7 +20,8 @@ const props = defineProps({
|
|
20
20
|
size: {
|
21
21
|
type: Number,
|
22
22
|
default: 18
|
23
|
-
}
|
23
|
+
},
|
24
|
+
color: String
|
24
25
|
})
|
25
26
|
//根据传入的类型使用图标
|
26
27
|
const iconComponent = computed(() => Icons[props.type])
|
@@ -0,0 +1,88 @@
|
|
1
|
+
<template>
|
2
|
+
<div class="normalClass">
|
3
|
+
<el-upload
|
4
|
+
class="upload-demo"
|
5
|
+
drag
|
6
|
+
accept=".xls,.xlsx,.csv"
|
7
|
+
:name="name"
|
8
|
+
:limit="1"
|
9
|
+
:file-list="fileList"
|
10
|
+
:before-upload="beforeUpload"
|
11
|
+
:on-success="handleSuccess"
|
12
|
+
:action="url">
|
13
|
+
<Icons :type="'Plus'" :size="30"></Icons>
|
14
|
+
<div class="el-upload__text">
|
15
|
+
点击或者拖动文件到虚线框内上传
|
16
|
+
<p class="next-upload-drag-hint">支持xls,xlsx,csv类型的文件<br>单次上传不超过1000行,大小不超过5M</p>
|
17
|
+
</div>
|
18
|
+
</el-upload>
|
19
|
+
</div>
|
20
|
+
</template>
|
21
|
+
|
22
|
+
<script setup>
|
23
|
+
import { ref } from 'vue'
|
24
|
+
import { ElUpload } from 'element-plus'
|
25
|
+
import Icons from '../Icons/index.vue'
|
26
|
+
import { Message } from '../Message/index.js'
|
27
|
+
|
28
|
+
defineOptions({
|
29
|
+
name: 'Upload',
|
30
|
+
})
|
31
|
+
defineProps({
|
32
|
+
url: String, // 请求url
|
33
|
+
name: {
|
34
|
+
type: String,
|
35
|
+
default: 'file'
|
36
|
+
}
|
37
|
+
})
|
38
|
+
|
39
|
+
const fileList = ref([{name: '1234.xsl (20K)'}])
|
40
|
+
const emits = defineEmits(['successUpload'])
|
41
|
+
const beforeUpload = (file) => {
|
42
|
+
const isAllowedType = /\.(xls|xlsx|csv)$/.test(file.name);
|
43
|
+
const isAllowedSize = file.size / 1024 / 1024 < 5;;
|
44
|
+
|
45
|
+
if (!isAllowedType) {
|
46
|
+
Message.error('只能上传xls/xlsx/csv文件!');
|
47
|
+
}
|
48
|
+
if (!isAllowedSize) {
|
49
|
+
Message.error('上传文件不能超过 5M');
|
50
|
+
}
|
51
|
+
return isAllowedType && isAllowedSize;
|
52
|
+
}
|
53
|
+
|
54
|
+
const handleSuccess = (res, file, fileList) => {
|
55
|
+
if (res.code === 200) {
|
56
|
+
const size = (file.size / 1024).toFixed(2)
|
57
|
+
const name = `${file.name} (${size}K)`
|
58
|
+
if (fileList.value.length === 1) {
|
59
|
+
fileList.value = [{
|
60
|
+
name
|
61
|
+
}];
|
62
|
+
} else {
|
63
|
+
fileList.value.push(
|
64
|
+
{
|
65
|
+
name
|
66
|
+
}
|
67
|
+
);
|
68
|
+
}
|
69
|
+
emits('successUpload', res)
|
70
|
+
} else {
|
71
|
+
Message.error(res.msg || res.data.msg || res.message || '上传失败')
|
72
|
+
}
|
73
|
+
}
|
74
|
+
</script>
|
75
|
+
|
76
|
+
<style lang="less" scoped>
|
77
|
+
.normalClass {
|
78
|
+
margin: 0px;
|
79
|
+
|
80
|
+
.el-upload__text {
|
81
|
+
margin: 10px auto;
|
82
|
+
|
83
|
+
p {
|
84
|
+
font-size: 12px;
|
85
|
+
}
|
86
|
+
}
|
87
|
+
}
|
88
|
+
</style>
|