-
Notifications
You must be signed in to change notification settings - Fork 4
/
UploadImageMain.tsx
158 lines (143 loc) · 4.29 KB
/
UploadImageMain.tsx
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
import { NIcon, NImageGroup, NInput, NMenu, NSpace } from 'naive-ui';
import { defineComponent, PropType, provide } from 'vue';
import UploadMain from '../UploadMain';
import { NBaseIcon } from 'naive-ui/lib/_internal';
import { AddIcon } from 'naive-ui/lib/_internal/icons';
import { FileInfo } from 'naive-ui/lib/upload/src/interface';
import { createInjectionKey } from 'naive-ui/lib/_utils';
import FileList from './FileList';
import UploadImage from './UploadImage';
import { SearchOutline } from '@vicons/ionicons5';
import UploadLIst from './UploadLIst';
import { useMain } from '../hooks/main';
export const uploadMainImageProps = {
fileList: {
type: Array as PropType<FileInfo[]>,
default: () => []
},
max: {
type: Number,
default: 0,
},
onUpdateFileList: Function as PropType<(files: FileInfo[]) => void>,
'onUpdate:fileList': Function as PropType<(files: FileInfo[]) => void>,
onSelect: Function as PropType<(files: FileInfo[]) => void>,
};
interface UploadImageMainInjection {
handleRemove: (index: number) => void;
}
export const uploadImageMainInjectionKey = createInjectionKey<UploadImageMainInjection>('upload-image-main');
export default defineComponent({
name: 'UploadImageMain',
props: uploadMainImageProps,
setup (props) {
const {
mainRef,
fileListRef,
cssVarsRef,
mergedClsPrefixRef,
mainMax,
groupOptions,
renderCount,
handleSelect,
handleRemove,
handleSelectChange,
} = useMain(props);
provide(uploadImageMainInjectionKey, {
handleRemove
});
return {
mainRef,
mergedClsPrefix: mergedClsPrefixRef,
cssVars: cssVarsRef,
handleSelect,
fileList: fileListRef,
mainMax,
handleRemove,
groupOptions,
renderCount,
handleSelectChange,
};
},
render () {
const {
mergedClsPrefix,
handleSelect,
fileList,
max,
mainMax,
groupOptions,
renderCount,
handleSelectChange,
$slots
} = this;
return (
<UploadMain ref="mainRef" max={mainMax} title='我的图片' onSelected={handleSelect}>
{{
default: ({ toggle }: { toggle: () => void }) => (
$slots.default ? $slots.default({ toggle }) : <div
class={[
`${mergedClsPrefix}-upload`,
]}
style={this.cssVars as any}
>
<div
class={[
`${mergedClsPrefix}-upload-file-list`,
`${mergedClsPrefix}-upload-file-list--grid`,
]}
>
<NImageGroup>
{fileList.map((file, index) => (
<FileList clsPrefix={mergedClsPrefix} file={file} index={index} />
))}
{!max || max > fileList.length ? (
<div
class={[
`${mergedClsPrefix}-upload-trigger`,
`${mergedClsPrefix}-upload-trigger--image-card`
]}
>
<div
class={[
`${mergedClsPrefix}-upload-dragger`,
]}
onClick={toggle}
>
<NBaseIcon clsPrefix={mergedClsPrefix}>
{{ default: () => <AddIcon /> }}
</NBaseIcon>
</div>
</div>
) : null }
</NImageGroup>
</div>
</div>
),
header: () => (
<UploadImage />
),
sider: () => (
<NSpace vertical>
<NInput
placeholder="搜索分组名称"
>
{{
suffix: () => (
<NIcon>
<SearchOutline />
</NIcon>
)
}}
</NInput>
<NMenu options={groupOptions} rootIndent={12} defaultValue={1} renderExtra={renderCount} />
</NSpace>
),
lists: () => (
<UploadLIst max={max} type='image' onChange={handleSelectChange} />
)
}}
</UploadMain>
);
}
});