upload.vue
1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<template>
<CInput ref="label" :label="label">
<slot>
<Upload
:max="max"
:multiple="multiple"
:action="action"
:simultaneous-uploads="1"
:value="file"
@file-submitted="fileAdd"
@file-error="fileError"
>
</Upload>
</slot>
</CInput>
</template>
<script>
import Input from './input';
import {Upload} from 'cube-ui';
import {createNamespacedHelpers} from 'vuex';
const {mapState, mapActions, mapMutations} = createNamespacedHelpers('license/form');
export default {
name: 'CUpload',
props: {
value: {
type: Array,
default() {
return [];
}
},
label: {
type: String
}
},
data() {
return {
max: 1,
multiple: false,
action: {
target: 'http://upload.qiniup.com/',
data: {
token: '',
key: ''
}
},
file: this.value
};
},
methods: {
fileAdd(file) {
this.action.data.token = this.token;
this.action.data.key = file.name;
},
fileError() {
this.$createToast({
txt: '上传失败,请重新上传',
type: 'error',
mask: true,
time: 2000
}).show();
},
validate() {
if (!this.value.length) {
this.$refs.label.setShowError();
return false;
} else {
this.$refs.label.setShowError(false);
return true;
}
}
},
computed: {
...mapState(['token'])
},
components: {
CInput: Input,
Upload
}
};
</script>
<style lang="scss" scoped>
.cube-upload {
/deep/ .cube-upload-btn {
margin: 0 0;
}
/deep/ .cube-upload-btn-def {
background-color: #eee;
}
/deep/ .cube-upload-file-status {
font-size: 30px !important;
}
}
</style>