-
Notifications
You must be signed in to change notification settings - Fork 4
/
UploadImage.tsx
216 lines (203 loc) · 5.5 KB
/
UploadImage.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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
import { FormRules, NButton, NDivider, NForm, NFormItem, NInput, NModal, NRadio, NRadioGroup, NSelect, NSpace, NUpload } from 'naive-ui';
import NA from '../a';
import { defineComponent, ref } from 'vue';
import { RouterLink } from 'vue-router';
import '../styles/upload.scss';
interface UploadTypeSchema {
label: string;
value: string;
}
const uploadTypes: UploadTypeSchema[] = [
{
label: '本地上传',
value: 'local',
},
{
label: '扫码上传',
value: 'scan',
},
{
label: '网络图片',
value: 'net',
}
];
export default defineComponent({
name: 'UploadImage',
setup () {
const showModal = ref(false);
const formRef = ref();
const modelRef = ref({
type: 'local',
group_id: null,
image: '',
});
const rules: FormRules = {
type: [
{
required: true,
message: '请选择上传方式',
}
],
group_id: [
{
required: true,
message: '请选择分组',
}
],
images: [
{
required: true,
message: '请上传图片',
}
],
image: [
{
required: true,
message: '请填写网络图片地址',
}
]
};
const confirm = () => {
showModal.value = false;
};
const cancel = () => {
showModal.value = false;
};
const handleHide = () => {
modelRef.value = {
type: 'local',
group_id: null,
image: '',
};
};
return {
uploadTypes,
confirm,
cancel,
handleHide,
rules,
form: formRef,
model: modelRef,
showModal,
style: {
minWidth: '620px',
width: '828px',
},
headerStyle: {
padding: '15px 16px',
borderBottom: '1px solid var(--n-border-color)'
},
contentStyle: {
padding: '16px',
},
footerStyle: {
padding: '0 16px 16px',
}
};
},
render () {
const {
uploadTypes,
handleHide,
confirm,
cancel,
rules,
model,
style,
headerStyle,
contentStyle,
footerStyle,
} = this;
return (
<>
<NButton onClick={() => this.showModal = !this.showModal}>
上传图片
</NButton>
<NModal
class="upload-modal"
show={this.showModal}
maskClosable={false}
style={style}
headerStyle={headerStyle}
contentStyle={contentStyle}
footerStyle={footerStyle}
preset="card"
title="上传图片"
size="huge"
bordered={false}
onEsc={() => {}}
onClose={() => this.showModal = false}
onBeforeLeave={handleHide}
>
{{
default: () => (
<div class="upload-main">
<NForm
ref={this.form}
labelPlacement="left"
labelWidth="120"
model={model}
rules={rules}
requireMarkPlacement="left"
>
<NFormItem label='上传方式:' path='type'>
<NRadioGroup v-model:value={model.type}>
<NSpace>
{uploadTypes.map(type => (
<NRadio key={type.value} value={type.value}>
{type.label}
</NRadio>
))}
</NSpace>
</NRadioGroup>
</NFormItem>
{
['local', 'net'].includes(model.type) ? (
<NFormItem label='所在分组:' path='group_id'>
<NSpace align='center'>
<NSelect style={{width: '300px'}} v-model:value={model.group_id} placeholder="请选择分组" />
<div>
<RouterLink
to="/"
custom>
<NA href="/" target="_blank">新建</NA>
</RouterLink>
<NDivider vertical />
<NA>刷新</NA>
</div>
</NSpace>
</NFormItem>
) : ''
}
{model.type === 'local' ? (
<NFormItem label='本地图片:' path='images'>
<NUpload listType="image-card" />
</NFormItem>
) : ''}
{model.type === 'net' ? (
<NFormItem label='网络图片:' path='image'>
<NSpace>
<NInput style={{width: '300px'}} placeholder="请填写网络图片地址" v-model:value={model.image} />
<NButton>提取</NButton>
</NSpace>
</NFormItem>
) : ''}
</NForm>
</div>
),
footer: () => (
<NSpace style={{flexDirection: 'row-reverse'}}>
<NSpace>
<NButton onClick={cancel}>返回</NButton>
{
model.type === 'local' ? <NButton type='primary' onClick={confirm}>确定</NButton> : ''
}
</NSpace>
</NSpace>
),
}}
</NModal>
</>
);
}
});