jobsys-explore 4.6.21 → 4.7.0
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/.eslintignore +3 -3
- package/CHANGELOG.md +542 -542
- package/README.md +41 -41
- package/TODOs.md +8 -8
- package/business-components/survey/ExSurvey.jsx +193 -193
- package/business-components/survey/index.js +5 -5
- package/business-components/survey/index.less +36 -36
- package/components/button/ExButton.jsx +120 -120
- package/components/button/index.js +4 -4
- package/components/button/index.less +7 -7
- package/components/decorator/ExDecorator.jsx +31 -31
- package/components/decorator/index.js +5 -5
- package/components/decorator/index.less +76 -76
- package/components/form/ExAddress.jsx +195 -195
- package/components/form/ExCascader.jsx +171 -171
- package/components/form/ExCheckbox.jsx +59 -59
- package/components/form/ExDate.jsx +143 -143
- package/components/form/ExDatetime.jsx +166 -166
- package/components/form/ExField.jsx +138 -138
- package/components/form/ExFieldUploader.jsx +50 -50
- package/components/form/ExForm.jsx +544 -544
- package/components/form/ExMatrixCheckbox.jsx +99 -99
- package/components/form/ExMatrixRadio.jsx +86 -86
- package/components/form/ExMatrixScale.jsx +97 -97
- package/components/form/ExNumber.jsx +51 -51
- package/components/form/ExRadio.jsx +58 -58
- package/components/form/ExRate.jsx +51 -51
- package/components/form/ExSelect.jsx +251 -251
- package/components/form/ExSlider.jsx +55 -55
- package/components/form/ExSwitch.jsx +51 -51
- package/components/form/ExTime.jsx +99 -99
- package/components/form/FormItem.jsx +307 -307
- package/components/form/PickerWrapper.jsx +120 -120
- package/components/form/index.js +46 -46
- package/components/form/index.less +178 -178
- package/components/form/utils.js +62 -62
- package/components/grid/ExGrid.jsx +53 -53
- package/components/grid/index.js +4 -4
- package/components/grid/index.less +2 -2
- package/components/index.js +12 -12
- package/components/pagination/ExPagination.jsx +457 -440
- package/components/pagination/index.js +5 -5
- package/components/pagination/index.less +3 -3
- package/components/provider/ExProvider.jsx +173 -173
- package/components/qrcode/ExQrcode.jsx +86 -86
- package/components/qrcode/index.js +5 -5
- package/components/qrcode/index.less +8 -8
- package/components/result/ExResult.jsx +122 -122
- package/components/result/index.js +5 -5
- package/components/result/index.less +59 -59
- package/components/search/ExSearch.jsx +370 -326
- package/components/search/components/Expand.jsx +77 -77
- package/components/search/components/Field.jsx +27 -27
- package/components/search/components/Quick.jsx +57 -57
- package/components/search/components/index.js +5 -5
- package/components/search/index.js +5 -5
- package/components/search/index.less +118 -118
- package/components/search/utils.js +30 -30
- package/components/sector/ExSector.jsx +52 -52
- package/components/sector/README.md +26 -26
- package/components/sector/index.js +5 -5
- package/components/sector/index.less +122 -122
- package/components/theme/ExTheme.jsx +10 -10
- package/components/theme/index.js +4 -4
- package/components/theme/index.less +98 -98
- package/components/uploader/ExUploader.jsx +293 -293
- package/components/uploader/index.js +5 -5
- package/components/utils.js +187 -187
- package/directives/auth.js +113 -113
- package/directives/index.js +4 -4
- package/dist/cipher-98df1050.cjs.map +1 -1
- package/dist/cipher-f2ed5ee6.js.map +1 -1
- package/dist/directives.cjs.map +1 -1
- package/dist/directives.js.map +1 -1
- package/dist/hooks.cjs.map +1 -1
- package/dist/hooks.js.map +1 -1
- package/dist/jobsys-explore.cjs +6 -6
- package/dist/jobsys-explore.cjs.map +1 -1
- package/dist/jobsys-explore.js +464 -407
- package/dist/jobsys-explore.js.map +1 -1
- package/docgen.config.js +15 -15
- package/docs/.vuepress/.cache/deps/_metadata.json +52 -52
- package/docs/.vuepress/.cache/deps/lodash-es.js +8442 -8442
- package/docs/.vuepress/.cache/deps/lodash-es.js.map +7 -7
- package/docs/.vuepress/.temp/internal/clientConfigs.js +17 -17
- package/docs/.vuepress/.temp/internal/pagesComponents.js +24 -24
- package/docs/.vuepress/.temp/internal/pagesData.js +22 -22
- package/docs/.vuepress/.temp/internal/pagesRoutes.js +12 -12
- package/docs/.vuepress/.temp/internal/themeData.js +1 -1
- package/docs/.vuepress/.temp/pages/components/decorator/ExDecorator.html.js +1 -1
- package/docs/.vuepress/.temp/pages/components/decorator/ExDecorator.html.vue +37 -37
- package/docs/.vuepress/.temp/pages/components/sector/ExSector.html.js +1 -1
- package/docs/.vuepress/.temp/pages/components/sector/ExSector.html.vue +71 -71
- package/docs/.vuepress/.temp/styles/index.scss +1 -1
- package/docs/.vuepress/config.js +61 -61
- package/docs/.vuepress/dist/404.html +33 -33
- package/docs/.vuepress/dist/assets/404.html-a0ce2184.js +1 -1
- package/docs/.vuepress/dist/assets/ExButton.html-ad283101.js +1 -1
- package/docs/.vuepress/dist/assets/ExDecorator.html-42d09114.js +1 -1
- package/docs/.vuepress/dist/assets/ExDecorator.html-c82c5fe8.js +1 -1
- package/docs/.vuepress/dist/assets/ExForm.html-9e3f8000.js +1 -1
- package/docs/.vuepress/dist/assets/ExProvider.html-78fdc6cd.js +1 -1
- package/docs/.vuepress/dist/assets/ExSearch.html-103f6f34.js +1 -1
- package/docs/.vuepress/dist/assets/ExSector.html-a1e24c3a.js +7 -7
- package/docs/.vuepress/dist/assets/ExSector.html-cff3fefd.js +1 -1
- package/docs/.vuepress/dist/assets/ExUploader.html-8310e424.js +1 -1
- package/docs/.vuepress/dist/assets/app-29fe8d1e.js +10 -10
- package/docs/.vuepress/dist/assets/hooks.html-90ccbc1a.js +1 -1
- package/docs/.vuepress/dist/assets/index.html-85b79c97.js +43 -43
- package/docs/.vuepress/dist/assets/style-46d7e227.css +1 -1
- package/docs/.vuepress/dist/components/button/ExButton.html +33 -33
- package/docs/.vuepress/dist/components/decorator/ExDecorator.html +33 -33
- package/docs/.vuepress/dist/components/form/ExForm.html +33 -33
- package/docs/.vuepress/dist/components/provider/ExProvider.html +33 -33
- package/docs/.vuepress/dist/components/search/ExSearch.html +33 -33
- package/docs/.vuepress/dist/components/sector/ExSector.html +39 -39
- package/docs/.vuepress/dist/components/uploader/ExUploader.html +33 -33
- package/docs/.vuepress/dist/hooks.html +33 -33
- package/docs/.vuepress/dist/index.html +75 -75
- package/docs/.vuepress/styles/index.scss +7 -7
- package/docs/components/decorator/ExDecorator.md +14 -14
- package/docs/components/sector/ExSector.md +43 -43
- package/docs/index.md +82 -82
- package/hooks/cipher.js +44 -44
- package/hooks/datetime.js +69 -69
- package/hooks/form.js +188 -188
- package/hooks/utils.js +282 -282
- package/index.html +17 -17
- package/package.json +1 -1
- package/playground/App.vue +191 -191
- package/playground/TestButton.vue +61 -61
- package/playground/TestCascader.vue +2442 -2442
- package/playground/TestDecorator.vue +14 -14
- package/playground/TestForm.vue +429 -429
- package/playground/TestFormItem.vue +110 -110
- package/playground/TestGrid.vue +22 -22
- package/playground/TestPagination.vue +1250 -1248
- package/playground/TestQrcode.vue +7 -7
- package/playground/TestResult.vue +12 -12
- package/playground/TestSearch.vue +115 -115
- package/playground/TestSector.vue +15 -15
- package/playground/TestSurvey.vue +27 -27
- package/playground/TestUploader.vue +14 -14
- package/playground/main.js +22 -22
- package/utils/style.js +13 -13
- package/vite.config.js +54 -54
- package/.changeset/blue-spiders-roll.md +0 -5
- package/.changeset/cyan-monkeys-draw.md +0 -5
- package/.changeset/dry-feet-float.md +0 -5
- package/.changeset/empty-mice-share.md +0 -5
- package/.changeset/famous-yaks-doubt.md +0 -5
- package/.changeset/five-fans-type.md +0 -5
- package/.changeset/funny-hats-drop.md +0 -5
- package/.changeset/khaki-cobras-bathe.md +0 -5
- package/.changeset/khaki-forks-shave.md +0 -5
- package/.changeset/lazy-yaks-crash.md +0 -5
- package/.changeset/light-cycles-flow.md +0 -5
- package/.changeset/loud-mirrors-explain.md +0 -5
- package/.changeset/lovely-balloons-protect.md +0 -5
- package/.changeset/mean-pens-travel.md +0 -5
- package/.changeset/moody-doors-grow.md +0 -5
- package/.changeset/moody-laws-change.md +0 -5
- package/.changeset/nasty-goats-joke.md +0 -5
- package/.changeset/odd-forks-drop.md +0 -5
- package/.changeset/olive-windows-suffer.md +0 -5
- package/.changeset/popular-carpets-jog.md +0 -5
- package/.changeset/popular-planets-play.md +0 -5
- package/.changeset/rare-gorillas-boil.md +0 -5
- package/.changeset/rare-moose-teach.md +0 -5
- package/.changeset/sharp-tools-hope.md +0 -5
- package/.changeset/slimy-sloths-refuse.md +0 -5
- package/.changeset/slow-boats-search.md +0 -5
- package/.changeset/small-experts-bake.md +0 -5
- package/.changeset/smooth-horses-tie.md +0 -5
- package/.changeset/tame-feet-reply.md +0 -5
- package/.changeset/tidy-items-reflect.md +0 -5
- package/.changeset/weak-chicken-admire.md +0 -5
- package/.changeset/weak-rockets-compare.md +0 -5
- package/.changeset/wild-glasses-bathe.md +0 -5
- package/.changeset/wise-ears-turn.md +0 -5
|
@@ -1,293 +1,293 @@
|
|
|
1
|
-
import { computed, defineComponent, inject, onMounted, reactive, watch } from "vue"
|
|
2
|
-
import { Button, showToast, Uploader } from "vant"
|
|
3
|
-
import { findIndex, isArray, isEqual, isFunction, map, pick, random } from "lodash-es"
|
|
4
|
-
import { STATUS, useFetch } from "../../hooks"
|
|
5
|
-
import { EX_UPLOADER } from "../provider/ExProvider.jsx"
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* ExUploader 文件上传
|
|
9
|
-
* @version 1.0.0
|
|
10
|
-
*/
|
|
11
|
-
export default defineComponent({
|
|
12
|
-
name: "ExUploader",
|
|
13
|
-
props: {
|
|
14
|
-
modelValue: { type: [Object, Array], default: () => ({}) },
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* 上传文件字段名
|
|
18
|
-
*/
|
|
19
|
-
name: { type: String, default: "file" },
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* 接受上传的文件类型, 详见 [input accept Attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file#accept)
|
|
23
|
-
*/
|
|
24
|
-
accept: { type: String, default: "" },
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* 设置上传的请求头部,IE10 以上有效
|
|
28
|
-
*/
|
|
29
|
-
headers: { type: Object, default: () => ({}) },
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* 上传列表的基本样式 text, picture
|
|
33
|
-
*
|
|
34
|
-
* @values text, picture
|
|
35
|
-
*/
|
|
36
|
-
type: { type: String, default: "picture" },
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* 是否禁用
|
|
40
|
-
*/
|
|
41
|
-
disabled: { type: Boolean, default: false },
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* 是否只读
|
|
45
|
-
*/
|
|
46
|
-
readonly: { type: Boolean, default: false },
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* 单个文件大小上限,单位为 MB
|
|
50
|
-
*/
|
|
51
|
-
maxSize: { type: Number, default: 10 },
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* 上传文件个数上限
|
|
55
|
-
*/
|
|
56
|
-
maxNum: { type: Number, default: 1 },
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* 是否支持多选文件
|
|
60
|
-
*/
|
|
61
|
-
multiple: { type: Boolean, default: false },
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* 上传文件的服务器地址
|
|
65
|
-
*/
|
|
66
|
-
action: { type: String, default: "" },
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* 上传后的数据处理回调
|
|
70
|
-
*/
|
|
71
|
-
afterUpload: { type: Function, default: null },
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* 上传时的附加参数
|
|
75
|
-
*/
|
|
76
|
-
extraData: { type: Object, default: () => ({}) },
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* 上传按钮文本
|
|
80
|
-
*/
|
|
81
|
-
uploadText: { type: String, default: "上传" },
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* 上传区域图标名称或图片链接,等同于 Icon 组件的 name 属性
|
|
85
|
-
*/
|
|
86
|
-
uploadIcon: { type: String, default: "photograph" },
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* 上传盘符标志,可以灵活配合后台使用
|
|
90
|
-
*/
|
|
91
|
-
disk: { type: String, default: "" },
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* [原生配置](https://vant-contrib.gitee.io/vant/#/zh-CN/uploader)
|
|
95
|
-
*/
|
|
96
|
-
uploaderProps: {
|
|
97
|
-
type: Object,
|
|
98
|
-
default: () => ({}),
|
|
99
|
-
},
|
|
100
|
-
},
|
|
101
|
-
emits: ["update:modelValue", "success", "change"],
|
|
102
|
-
setup(props, { emit, slots }) {
|
|
103
|
-
const uploaderProvider = inject(EX_UPLOADER, () => ({}))
|
|
104
|
-
const defaultUploadUrl = uploaderProvider.uploadUrl || ""
|
|
105
|
-
const defaultFileItem = uploaderProvider.defaultFileItem || {}
|
|
106
|
-
|
|
107
|
-
const { url: urlKey, path: pathKey, name: nameKey } = defaultFileItem
|
|
108
|
-
|
|
109
|
-
const state = reactive({
|
|
110
|
-
fileList: [],
|
|
111
|
-
})
|
|
112
|
-
|
|
113
|
-
const maxSize = computed(() => props.maxSize * 1024 * 1024)
|
|
114
|
-
|
|
115
|
-
const isImage = computed(() => props.type === "picture")
|
|
116
|
-
|
|
117
|
-
const isSingle = computed(() => props.maxNum === 1)
|
|
118
|
-
|
|
119
|
-
const processFileList = (fileList) => {
|
|
120
|
-
if (!fileList) {
|
|
121
|
-
return []
|
|
122
|
-
}
|
|
123
|
-
fileList = isArray(fileList) ? fileList : [fileList]
|
|
124
|
-
|
|
125
|
-
fileList = fileList.filter((item) => item.status === "done" || !!item[nameKey] || !!item[pathKey])
|
|
126
|
-
fileList = fileList.map((item) => ({
|
|
127
|
-
...pick(item, Object.values(defaultFileItem)),
|
|
128
|
-
_type: "file",
|
|
129
|
-
_disk: props.disk,
|
|
130
|
-
}))
|
|
131
|
-
if (isSingle.value) {
|
|
132
|
-
return (
|
|
133
|
-
fileList[0] || {
|
|
134
|
-
[pathKey]: "",
|
|
135
|
-
[urlKey]: "",
|
|
136
|
-
_type: "file",
|
|
137
|
-
}
|
|
138
|
-
)
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
const submitFile = () => {
|
|
143
|
-
const fileList = processFileList(state.fileList)
|
|
144
|
-
emit("update:modelValue", fileList)
|
|
145
|
-
emit("change", fileList)
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
const prepareFileList = (fileList) => {
|
|
149
|
-
if (!fileList) {
|
|
150
|
-
return []
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
fileList = isArray(fileList) ? fileList : [fileList]
|
|
154
|
-
|
|
155
|
-
state.fileList = fileList
|
|
156
|
-
.filter((item) => item[urlKey] || item[pathKey])
|
|
157
|
-
.map((item) => ({
|
|
158
|
-
uid: random(1, 10000000),
|
|
159
|
-
url: item[urlKey],
|
|
160
|
-
status: "done",
|
|
161
|
-
isImage: isImage.value,
|
|
162
|
-
_type: "file",
|
|
163
|
-
...item,
|
|
164
|
-
}))
|
|
165
|
-
|
|
166
|
-
//由于初始值可能不符合文件结构,处理后再次触发更新
|
|
167
|
-
emit("update:modelValue", processFileList(state.fileList))
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
onMounted(() => prepareFileList(props.modelValue))
|
|
171
|
-
|
|
172
|
-
watch(
|
|
173
|
-
() => props.modelValue,
|
|
174
|
-
(fileList) => {
|
|
175
|
-
if (fileList && !isArray(fileList)) {
|
|
176
|
-
fileList = [fileList]
|
|
177
|
-
}
|
|
178
|
-
fileList = fileList.filter((item) => item[urlKey] || item[pathKey])
|
|
179
|
-
if (!isEqual(map(fileList, pathKey).sort(), map(state.fileList, pathKey).sort())) {
|
|
180
|
-
prepareFileList(fileList)
|
|
181
|
-
}
|
|
182
|
-
},
|
|
183
|
-
)
|
|
184
|
-
|
|
185
|
-
const onOversize = () => {
|
|
186
|
-
showToast(`文件大小不能超过 ${props.maxSize}mb`)
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
const onSuccess = (file, result) => {
|
|
190
|
-
file.status = "done"
|
|
191
|
-
file.message = "上传成功"
|
|
192
|
-
file = { ...file, ...pick(result, Object.values(defaultFileItem)) }
|
|
193
|
-
file.url = file[urlKey]
|
|
194
|
-
|
|
195
|
-
const fileIndex = findIndex(state.fileList, { uid: file.uid })
|
|
196
|
-
|
|
197
|
-
state.fileList[fileIndex] = file
|
|
198
|
-
|
|
199
|
-
submitFile()
|
|
200
|
-
|
|
201
|
-
emit("success", { file, response: result })
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
const onError = (file, result) => {
|
|
205
|
-
file.status = "failed"
|
|
206
|
-
file.message = result || "上传失败"
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
const onDelete = () => {
|
|
210
|
-
submitFile()
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
const onSubmit = async (files) => {
|
|
214
|
-
if (!isArray(files)) {
|
|
215
|
-
files = [files]
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
for (let file of files) {
|
|
219
|
-
file.uid = random(1, 10000000)
|
|
220
|
-
file.status = "uploading"
|
|
221
|
-
file.message = "上传中..."
|
|
222
|
-
|
|
223
|
-
const formData = new FormData()
|
|
224
|
-
Object.keys(props.extraData).forEach((key) => {
|
|
225
|
-
formData.append(key, props.extraData[key])
|
|
226
|
-
})
|
|
227
|
-
|
|
228
|
-
if (props.disk) {
|
|
229
|
-
formData.append("_disk", props.disk)
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
formData.append(props.name, file.file)
|
|
233
|
-
|
|
234
|
-
try {
|
|
235
|
-
let res = await useFetch().post(props.action || defaultUploadUrl, formData, {
|
|
236
|
-
withCredentials: true,
|
|
237
|
-
headers: props.headers,
|
|
238
|
-
})
|
|
239
|
-
|
|
240
|
-
let result = res.result
|
|
241
|
-
|
|
242
|
-
if (res.status !== STATUS.STATE_CODE_SUCCESS) {
|
|
243
|
-
onError(file, result)
|
|
244
|
-
return
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
if (props.afterUpload && isFunction(props.afterUpload)) {
|
|
248
|
-
result = props.afterUpload(res)
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
onSuccess(file, result)
|
|
252
|
-
} catch (e) {
|
|
253
|
-
onError(file)
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
const customSlot = () => {
|
|
259
|
-
if (!isImage.value) {
|
|
260
|
-
slots.default = () => (
|
|
261
|
-
<Button icon="plus" type="primary" size={"small"}>
|
|
262
|
-
{props.uploadText}
|
|
263
|
-
</Button>
|
|
264
|
-
)
|
|
265
|
-
}
|
|
266
|
-
return slots
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
return () => (
|
|
270
|
-
<div class={"ex-uploader"}>
|
|
271
|
-
<Uploader
|
|
272
|
-
v-model={state.fileList}
|
|
273
|
-
maxCount={props.maxNum}
|
|
274
|
-
maxSize={maxSize.value}
|
|
275
|
-
accetp={props.accept}
|
|
276
|
-
uploadText={props.uploadText}
|
|
277
|
-
uploadIcon={props.uploadIcon}
|
|
278
|
-
disabled={props.disabled}
|
|
279
|
-
readonly={props.readonly}
|
|
280
|
-
deletable={!(props.readonly || props.disabled)}
|
|
281
|
-
showUpload={!props.readonly && !props.disabled}
|
|
282
|
-
afterRead={onSubmit}
|
|
283
|
-
onOversize={onOversize}
|
|
284
|
-
onDelete={onDelete}
|
|
285
|
-
multiple={props.multiple}
|
|
286
|
-
{...props.uploaderProps}
|
|
287
|
-
>
|
|
288
|
-
{customSlot()}
|
|
289
|
-
</Uploader>
|
|
290
|
-
</div>
|
|
291
|
-
)
|
|
292
|
-
},
|
|
293
|
-
})
|
|
1
|
+
import { computed, defineComponent, inject, onMounted, reactive, watch } from "vue"
|
|
2
|
+
import { Button, showToast, Uploader } from "vant"
|
|
3
|
+
import { findIndex, isArray, isEqual, isFunction, map, pick, random } from "lodash-es"
|
|
4
|
+
import { STATUS, useFetch } from "../../hooks"
|
|
5
|
+
import { EX_UPLOADER } from "../provider/ExProvider.jsx"
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* ExUploader 文件上传
|
|
9
|
+
* @version 1.0.0
|
|
10
|
+
*/
|
|
11
|
+
export default defineComponent({
|
|
12
|
+
name: "ExUploader",
|
|
13
|
+
props: {
|
|
14
|
+
modelValue: { type: [Object, Array], default: () => ({}) },
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* 上传文件字段名
|
|
18
|
+
*/
|
|
19
|
+
name: { type: String, default: "file" },
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* 接受上传的文件类型, 详见 [input accept Attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file#accept)
|
|
23
|
+
*/
|
|
24
|
+
accept: { type: String, default: "" },
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* 设置上传的请求头部,IE10 以上有效
|
|
28
|
+
*/
|
|
29
|
+
headers: { type: Object, default: () => ({}) },
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* 上传列表的基本样式 text, picture
|
|
33
|
+
*
|
|
34
|
+
* @values text, picture
|
|
35
|
+
*/
|
|
36
|
+
type: { type: String, default: "picture" },
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* 是否禁用
|
|
40
|
+
*/
|
|
41
|
+
disabled: { type: Boolean, default: false },
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* 是否只读
|
|
45
|
+
*/
|
|
46
|
+
readonly: { type: Boolean, default: false },
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* 单个文件大小上限,单位为 MB
|
|
50
|
+
*/
|
|
51
|
+
maxSize: { type: Number, default: 10 },
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* 上传文件个数上限
|
|
55
|
+
*/
|
|
56
|
+
maxNum: { type: Number, default: 1 },
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* 是否支持多选文件
|
|
60
|
+
*/
|
|
61
|
+
multiple: { type: Boolean, default: false },
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* 上传文件的服务器地址
|
|
65
|
+
*/
|
|
66
|
+
action: { type: String, default: "" },
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* 上传后的数据处理回调
|
|
70
|
+
*/
|
|
71
|
+
afterUpload: { type: Function, default: null },
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* 上传时的附加参数
|
|
75
|
+
*/
|
|
76
|
+
extraData: { type: Object, default: () => ({}) },
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* 上传按钮文本
|
|
80
|
+
*/
|
|
81
|
+
uploadText: { type: String, default: "上传" },
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* 上传区域图标名称或图片链接,等同于 Icon 组件的 name 属性
|
|
85
|
+
*/
|
|
86
|
+
uploadIcon: { type: String, default: "photograph" },
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* 上传盘符标志,可以灵活配合后台使用
|
|
90
|
+
*/
|
|
91
|
+
disk: { type: String, default: "" },
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* [原生配置](https://vant-contrib.gitee.io/vant/#/zh-CN/uploader)
|
|
95
|
+
*/
|
|
96
|
+
uploaderProps: {
|
|
97
|
+
type: Object,
|
|
98
|
+
default: () => ({}),
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
emits: ["update:modelValue", "success", "change"],
|
|
102
|
+
setup(props, { emit, slots }) {
|
|
103
|
+
const uploaderProvider = inject(EX_UPLOADER, () => ({}))
|
|
104
|
+
const defaultUploadUrl = uploaderProvider.uploadUrl || ""
|
|
105
|
+
const defaultFileItem = uploaderProvider.defaultFileItem || {}
|
|
106
|
+
|
|
107
|
+
const { url: urlKey, path: pathKey, name: nameKey } = defaultFileItem
|
|
108
|
+
|
|
109
|
+
const state = reactive({
|
|
110
|
+
fileList: [],
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
const maxSize = computed(() => props.maxSize * 1024 * 1024)
|
|
114
|
+
|
|
115
|
+
const isImage = computed(() => props.type === "picture")
|
|
116
|
+
|
|
117
|
+
const isSingle = computed(() => props.maxNum === 1)
|
|
118
|
+
|
|
119
|
+
const processFileList = (fileList) => {
|
|
120
|
+
if (!fileList) {
|
|
121
|
+
return []
|
|
122
|
+
}
|
|
123
|
+
fileList = isArray(fileList) ? fileList : [fileList]
|
|
124
|
+
|
|
125
|
+
fileList = fileList.filter((item) => item.status === "done" || !!item[nameKey] || !!item[pathKey])
|
|
126
|
+
fileList = fileList.map((item) => ({
|
|
127
|
+
...pick(item, Object.values(defaultFileItem)),
|
|
128
|
+
_type: "file",
|
|
129
|
+
_disk: props.disk,
|
|
130
|
+
}))
|
|
131
|
+
if (isSingle.value) {
|
|
132
|
+
return (
|
|
133
|
+
fileList[0] || {
|
|
134
|
+
[pathKey]: "",
|
|
135
|
+
[urlKey]: "",
|
|
136
|
+
_type: "file",
|
|
137
|
+
}
|
|
138
|
+
)
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const submitFile = () => {
|
|
143
|
+
const fileList = processFileList(state.fileList)
|
|
144
|
+
emit("update:modelValue", fileList)
|
|
145
|
+
emit("change", fileList)
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const prepareFileList = (fileList) => {
|
|
149
|
+
if (!fileList) {
|
|
150
|
+
return []
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
fileList = isArray(fileList) ? fileList : [fileList]
|
|
154
|
+
|
|
155
|
+
state.fileList = fileList
|
|
156
|
+
.filter((item) => item[urlKey] || item[pathKey])
|
|
157
|
+
.map((item) => ({
|
|
158
|
+
uid: random(1, 10000000),
|
|
159
|
+
url: item[urlKey],
|
|
160
|
+
status: "done",
|
|
161
|
+
isImage: isImage.value,
|
|
162
|
+
_type: "file",
|
|
163
|
+
...item,
|
|
164
|
+
}))
|
|
165
|
+
|
|
166
|
+
//由于初始值可能不符合文件结构,处理后再次触发更新
|
|
167
|
+
emit("update:modelValue", processFileList(state.fileList))
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
onMounted(() => prepareFileList(props.modelValue))
|
|
171
|
+
|
|
172
|
+
watch(
|
|
173
|
+
() => props.modelValue,
|
|
174
|
+
(fileList) => {
|
|
175
|
+
if (fileList && !isArray(fileList)) {
|
|
176
|
+
fileList = [fileList]
|
|
177
|
+
}
|
|
178
|
+
fileList = fileList.filter((item) => item[urlKey] || item[pathKey])
|
|
179
|
+
if (!isEqual(map(fileList, pathKey).sort(), map(state.fileList, pathKey).sort())) {
|
|
180
|
+
prepareFileList(fileList)
|
|
181
|
+
}
|
|
182
|
+
},
|
|
183
|
+
)
|
|
184
|
+
|
|
185
|
+
const onOversize = () => {
|
|
186
|
+
showToast(`文件大小不能超过 ${props.maxSize}mb`)
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
const onSuccess = (file, result) => {
|
|
190
|
+
file.status = "done"
|
|
191
|
+
file.message = "上传成功"
|
|
192
|
+
file = { ...file, ...pick(result, Object.values(defaultFileItem)) }
|
|
193
|
+
file.url = file[urlKey]
|
|
194
|
+
|
|
195
|
+
const fileIndex = findIndex(state.fileList, { uid: file.uid })
|
|
196
|
+
|
|
197
|
+
state.fileList[fileIndex] = file
|
|
198
|
+
|
|
199
|
+
submitFile()
|
|
200
|
+
|
|
201
|
+
emit("success", { file, response: result })
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const onError = (file, result) => {
|
|
205
|
+
file.status = "failed"
|
|
206
|
+
file.message = result || "上传失败"
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
const onDelete = () => {
|
|
210
|
+
submitFile()
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
const onSubmit = async (files) => {
|
|
214
|
+
if (!isArray(files)) {
|
|
215
|
+
files = [files]
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
for (let file of files) {
|
|
219
|
+
file.uid = random(1, 10000000)
|
|
220
|
+
file.status = "uploading"
|
|
221
|
+
file.message = "上传中..."
|
|
222
|
+
|
|
223
|
+
const formData = new FormData()
|
|
224
|
+
Object.keys(props.extraData).forEach((key) => {
|
|
225
|
+
formData.append(key, props.extraData[key])
|
|
226
|
+
})
|
|
227
|
+
|
|
228
|
+
if (props.disk) {
|
|
229
|
+
formData.append("_disk", props.disk)
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
formData.append(props.name, file.file)
|
|
233
|
+
|
|
234
|
+
try {
|
|
235
|
+
let res = await useFetch().post(props.action || defaultUploadUrl, formData, {
|
|
236
|
+
withCredentials: true,
|
|
237
|
+
headers: props.headers,
|
|
238
|
+
})
|
|
239
|
+
|
|
240
|
+
let result = res.result
|
|
241
|
+
|
|
242
|
+
if (res.status !== STATUS.STATE_CODE_SUCCESS) {
|
|
243
|
+
onError(file, result)
|
|
244
|
+
return
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
if (props.afterUpload && isFunction(props.afterUpload)) {
|
|
248
|
+
result = props.afterUpload(res)
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
onSuccess(file, result)
|
|
252
|
+
} catch (e) {
|
|
253
|
+
onError(file)
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
const customSlot = () => {
|
|
259
|
+
if (!isImage.value) {
|
|
260
|
+
slots.default = () => (
|
|
261
|
+
<Button icon="plus" type="primary" size={"small"}>
|
|
262
|
+
{props.uploadText}
|
|
263
|
+
</Button>
|
|
264
|
+
)
|
|
265
|
+
}
|
|
266
|
+
return slots
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
return () => (
|
|
270
|
+
<div class={"ex-uploader"}>
|
|
271
|
+
<Uploader
|
|
272
|
+
v-model={state.fileList}
|
|
273
|
+
maxCount={props.maxNum}
|
|
274
|
+
maxSize={maxSize.value}
|
|
275
|
+
accetp={props.accept}
|
|
276
|
+
uploadText={props.uploadText}
|
|
277
|
+
uploadIcon={props.uploadIcon}
|
|
278
|
+
disabled={props.disabled}
|
|
279
|
+
readonly={props.readonly}
|
|
280
|
+
deletable={!(props.readonly || props.disabled)}
|
|
281
|
+
showUpload={!props.readonly && !props.disabled}
|
|
282
|
+
afterRead={onSubmit}
|
|
283
|
+
onOversize={onOversize}
|
|
284
|
+
onDelete={onDelete}
|
|
285
|
+
multiple={props.multiple}
|
|
286
|
+
{...props.uploaderProps}
|
|
287
|
+
>
|
|
288
|
+
{customSlot()}
|
|
289
|
+
</Uploader>
|
|
290
|
+
</div>
|
|
291
|
+
)
|
|
292
|
+
},
|
|
293
|
+
})
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import _ExUploader from "./ExUploader.jsx"
|
|
2
|
-
import withInstall from "../../utils/withInstall"
|
|
3
|
-
|
|
4
|
-
export const ExUploader = withInstall(_ExUploader)
|
|
5
|
-
export default ExUploader
|
|
1
|
+
import _ExUploader from "./ExUploader.jsx"
|
|
2
|
+
import withInstall from "../../utils/withInstall"
|
|
3
|
+
|
|
4
|
+
export const ExUploader = withInstall(_ExUploader)
|
|
5
|
+
export default ExUploader
|