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
package/hooks/form.js
CHANGED
|
@@ -1,188 +1,188 @@
|
|
|
1
|
-
import { cloneDeep, isArray, isBoolean, isDate, isFunction, isObject, isString, isUndefined } from "lodash-es"
|
|
2
|
-
import { STATUS } from "./network"
|
|
3
|
-
import { showFailToast, showSuccessToast } from "vant"
|
|
4
|
-
import dayjs from "dayjs"
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* 创建一个隐藏的表单
|
|
8
|
-
*
|
|
9
|
-
* @param {Object} options
|
|
10
|
-
* @param {string} options.url
|
|
11
|
-
* @param {Object} options.data
|
|
12
|
-
* @param {string} [options.method]
|
|
13
|
-
* @param {string} options.csrfToken
|
|
14
|
-
* @returns {HTMLFormElement}
|
|
15
|
-
*/
|
|
16
|
-
export function useHiddenForm(options) {
|
|
17
|
-
const { url, data, csrfToken } = options
|
|
18
|
-
let { method } = options
|
|
19
|
-
|
|
20
|
-
method = method || "post"
|
|
21
|
-
|
|
22
|
-
const form = document.createElement("form")
|
|
23
|
-
form.action = url
|
|
24
|
-
form.method = method
|
|
25
|
-
form.target = "_blank"
|
|
26
|
-
form.style.display = "none"
|
|
27
|
-
|
|
28
|
-
Object.keys(data).forEach((key) => {
|
|
29
|
-
const input = document.createElement("input")
|
|
30
|
-
input.type = "hidden"
|
|
31
|
-
input.name = key
|
|
32
|
-
input.value = data[key]
|
|
33
|
-
form.appendChild(input)
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
if (!csrfToken) {
|
|
37
|
-
const input = document.createElement("input")
|
|
38
|
-
input.type = "hidden"
|
|
39
|
-
input.name = "_token"
|
|
40
|
-
input.value = document.querySelector('meta[name="csrf-token"]').getAttribute("content")
|
|
41
|
-
form.appendChild(input)
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
document.body.appendChild(form)
|
|
45
|
-
|
|
46
|
-
return form
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* 处理请求结果
|
|
51
|
-
*
|
|
52
|
-
* @param {object} res 请求结果
|
|
53
|
-
* @param {string|number} res.status 请求结果状态
|
|
54
|
-
* @param {*} res.result 请求结果信息
|
|
55
|
-
* @param {Object.<string, string|function>} ops 状态的处理对象
|
|
56
|
-
*/
|
|
57
|
-
export function useProcessStatus(res, ops) {
|
|
58
|
-
const { status } = res
|
|
59
|
-
const msg = res.result
|
|
60
|
-
const predefined = {}
|
|
61
|
-
predefined.default = "请求失败, 请检查数据并重试"
|
|
62
|
-
predefined[STATUS.STATE_CODE_FAIL] = "系统错误,请稍候再试"
|
|
63
|
-
predefined[STATUS.STATE_CODE_NOT_FOUND] = "请求的内容不存在"
|
|
64
|
-
predefined[STATUS.STATE_CODE_INFO_NOT_COMPLETE] = "信息不完整"
|
|
65
|
-
predefined[STATUS.STATE_CODE_NOT_ALLOWED] = "没有权限"
|
|
66
|
-
|
|
67
|
-
// 有几个常用的自定义名称
|
|
68
|
-
const special = {
|
|
69
|
-
[STATUS.STATE_CODE_SUCCESS]: "success",
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const op = ops[status] || ops[special[status]] || predefined[status] || predefined.default
|
|
73
|
-
|
|
74
|
-
if (isString(op)) {
|
|
75
|
-
if (status === STATUS.STATE_CODE_SUCCESS) {
|
|
76
|
-
showSuccessToast(op)
|
|
77
|
-
} else {
|
|
78
|
-
showFailToast(msg || op)
|
|
79
|
-
}
|
|
80
|
-
} else if (isFunction(op)) {
|
|
81
|
-
op()
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* 处理正确请求结果
|
|
87
|
-
*
|
|
88
|
-
* @param {object} res 请求结果
|
|
89
|
-
* @param {string} res.status 请求结果状态
|
|
90
|
-
* @param {*} res.result 请求结果信息
|
|
91
|
-
* @param {string|function} success 状态的处理对象
|
|
92
|
-
*/
|
|
93
|
-
export function useProcessStatusSuccess(res, success) {
|
|
94
|
-
useProcessStatus(res, { success })
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* 处理表单提交失败
|
|
99
|
-
* @param {*} e
|
|
100
|
-
*/
|
|
101
|
-
export function useFormFail(e) {
|
|
102
|
-
if (e && e.errorFields) {
|
|
103
|
-
e.errorFields.forEach((item) => {
|
|
104
|
-
showFailToast(item.errors.join(" "))
|
|
105
|
-
})
|
|
106
|
-
} else if (!(e && e.response)) {
|
|
107
|
-
showFailToast("请检查填写项")
|
|
108
|
-
} else {
|
|
109
|
-
showFailToast("网络异常")
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* 处理表单数据
|
|
115
|
-
* @param {Object} form
|
|
116
|
-
* @param {Object} [format] 需要处理的类型
|
|
117
|
-
* @param {boolean|string|Function} [format.date] `true`: 转成时间戳,`string`: 为 Format 格式, 如 `"YYYY-MM-DD"`, `function`: 自定义处理函数, 参数为 dayjs 对象
|
|
118
|
-
* @param {boolean} [format.boolean] 布尔值处理, 如果开启则 `true` 转成 1, `false` 转成 0
|
|
119
|
-
* @param {string|Function} [format.attachment] `string`: 附件字段名, `function`: 自定义处理函数, 参数为附件对象
|
|
120
|
-
* @return {Object}
|
|
121
|
-
*/
|
|
122
|
-
export function useFormFormat(form, format) {
|
|
123
|
-
//必须先 Copy form, 否则会改变 vm model 里的引用值而导致出错
|
|
124
|
-
const newForm = cloneDeep(form)
|
|
125
|
-
format = format || {}
|
|
126
|
-
const formatter = (obj) => {
|
|
127
|
-
for (let key in obj) {
|
|
128
|
-
//日期处理
|
|
129
|
-
|
|
130
|
-
let date
|
|
131
|
-
if (dayjs.isDayjs(obj[key])) {
|
|
132
|
-
date = obj[key]
|
|
133
|
-
} else if (isDate(obj[key])) {
|
|
134
|
-
date = dayjs(obj[key])
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
if (date && format.date) {
|
|
138
|
-
if (isString(format.date)) {
|
|
139
|
-
obj[key] = date.format(format.date)
|
|
140
|
-
} else if (isFunction(format.date)) {
|
|
141
|
-
obj[key] = format.date(date)
|
|
142
|
-
} else {
|
|
143
|
-
obj[key] = date.unix()
|
|
144
|
-
}
|
|
145
|
-
continue
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
//布尔值处理
|
|
149
|
-
if (isBoolean(obj[key]) && format.boolean) {
|
|
150
|
-
if (format.boolean === true) {
|
|
151
|
-
obj[key] = obj[key] ? 1 : 0
|
|
152
|
-
} else if (Array.isArray(format.boolean)) {
|
|
153
|
-
obj[key] = obj[key] ? format.boolean?.[0] || 1 : format.boolean?.[1] || 0
|
|
154
|
-
}
|
|
155
|
-
continue
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
//附件处理
|
|
159
|
-
if (format.attachment) {
|
|
160
|
-
const checker = format.attachment
|
|
161
|
-
if (isObject(obj[key]) && obj[key]._type === "file" && isString(checker) && !isUndefined(obj[key][checker])) {
|
|
162
|
-
obj[key] = obj[key][checker]
|
|
163
|
-
continue
|
|
164
|
-
} else if (isObject(obj[key]) && isFunction(checker) && obj[key]._type === "file") {
|
|
165
|
-
obj[key] = checker(obj[key])
|
|
166
|
-
continue
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
//数组处理
|
|
171
|
-
if (isArray(obj[key])) {
|
|
172
|
-
obj[key] = formatter(obj[key])
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
return obj
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
return formatter(newForm)
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
export default {
|
|
183
|
-
useHiddenForm,
|
|
184
|
-
useProcessStatus,
|
|
185
|
-
useProcessStatusSuccess,
|
|
186
|
-
useFormFail,
|
|
187
|
-
useFormFormat,
|
|
188
|
-
}
|
|
1
|
+
import { cloneDeep, isArray, isBoolean, isDate, isFunction, isObject, isString, isUndefined } from "lodash-es"
|
|
2
|
+
import { STATUS } from "./network"
|
|
3
|
+
import { showFailToast, showSuccessToast } from "vant"
|
|
4
|
+
import dayjs from "dayjs"
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* 创建一个隐藏的表单
|
|
8
|
+
*
|
|
9
|
+
* @param {Object} options
|
|
10
|
+
* @param {string} options.url
|
|
11
|
+
* @param {Object} options.data
|
|
12
|
+
* @param {string} [options.method]
|
|
13
|
+
* @param {string} options.csrfToken
|
|
14
|
+
* @returns {HTMLFormElement}
|
|
15
|
+
*/
|
|
16
|
+
export function useHiddenForm(options) {
|
|
17
|
+
const { url, data, csrfToken } = options
|
|
18
|
+
let { method } = options
|
|
19
|
+
|
|
20
|
+
method = method || "post"
|
|
21
|
+
|
|
22
|
+
const form = document.createElement("form")
|
|
23
|
+
form.action = url
|
|
24
|
+
form.method = method
|
|
25
|
+
form.target = "_blank"
|
|
26
|
+
form.style.display = "none"
|
|
27
|
+
|
|
28
|
+
Object.keys(data).forEach((key) => {
|
|
29
|
+
const input = document.createElement("input")
|
|
30
|
+
input.type = "hidden"
|
|
31
|
+
input.name = key
|
|
32
|
+
input.value = data[key]
|
|
33
|
+
form.appendChild(input)
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
if (!csrfToken) {
|
|
37
|
+
const input = document.createElement("input")
|
|
38
|
+
input.type = "hidden"
|
|
39
|
+
input.name = "_token"
|
|
40
|
+
input.value = document.querySelector('meta[name="csrf-token"]').getAttribute("content")
|
|
41
|
+
form.appendChild(input)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
document.body.appendChild(form)
|
|
45
|
+
|
|
46
|
+
return form
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* 处理请求结果
|
|
51
|
+
*
|
|
52
|
+
* @param {object} res 请求结果
|
|
53
|
+
* @param {string|number} res.status 请求结果状态
|
|
54
|
+
* @param {*} res.result 请求结果信息
|
|
55
|
+
* @param {Object.<string, string|function>} ops 状态的处理对象
|
|
56
|
+
*/
|
|
57
|
+
export function useProcessStatus(res, ops) {
|
|
58
|
+
const { status } = res
|
|
59
|
+
const msg = res.result
|
|
60
|
+
const predefined = {}
|
|
61
|
+
predefined.default = "请求失败, 请检查数据并重试"
|
|
62
|
+
predefined[STATUS.STATE_CODE_FAIL] = "系统错误,请稍候再试"
|
|
63
|
+
predefined[STATUS.STATE_CODE_NOT_FOUND] = "请求的内容不存在"
|
|
64
|
+
predefined[STATUS.STATE_CODE_INFO_NOT_COMPLETE] = "信息不完整"
|
|
65
|
+
predefined[STATUS.STATE_CODE_NOT_ALLOWED] = "没有权限"
|
|
66
|
+
|
|
67
|
+
// 有几个常用的自定义名称
|
|
68
|
+
const special = {
|
|
69
|
+
[STATUS.STATE_CODE_SUCCESS]: "success",
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const op = ops[status] || ops[special[status]] || predefined[status] || predefined.default
|
|
73
|
+
|
|
74
|
+
if (isString(op)) {
|
|
75
|
+
if (status === STATUS.STATE_CODE_SUCCESS) {
|
|
76
|
+
showSuccessToast(op)
|
|
77
|
+
} else {
|
|
78
|
+
showFailToast(msg || op)
|
|
79
|
+
}
|
|
80
|
+
} else if (isFunction(op)) {
|
|
81
|
+
op()
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* 处理正确请求结果
|
|
87
|
+
*
|
|
88
|
+
* @param {object} res 请求结果
|
|
89
|
+
* @param {string} res.status 请求结果状态
|
|
90
|
+
* @param {*} res.result 请求结果信息
|
|
91
|
+
* @param {string|function} success 状态的处理对象
|
|
92
|
+
*/
|
|
93
|
+
export function useProcessStatusSuccess(res, success) {
|
|
94
|
+
useProcessStatus(res, { success })
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* 处理表单提交失败
|
|
99
|
+
* @param {*} e
|
|
100
|
+
*/
|
|
101
|
+
export function useFormFail(e) {
|
|
102
|
+
if (e && e.errorFields) {
|
|
103
|
+
e.errorFields.forEach((item) => {
|
|
104
|
+
showFailToast(item.errors.join(" "))
|
|
105
|
+
})
|
|
106
|
+
} else if (!(e && e.response)) {
|
|
107
|
+
showFailToast("请检查填写项")
|
|
108
|
+
} else {
|
|
109
|
+
showFailToast("网络异常")
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* 处理表单数据
|
|
115
|
+
* @param {Object} form
|
|
116
|
+
* @param {Object} [format] 需要处理的类型
|
|
117
|
+
* @param {boolean|string|Function} [format.date] `true`: 转成时间戳,`string`: 为 Format 格式, 如 `"YYYY-MM-DD"`, `function`: 自定义处理函数, 参数为 dayjs 对象
|
|
118
|
+
* @param {boolean} [format.boolean] 布尔值处理, 如果开启则 `true` 转成 1, `false` 转成 0
|
|
119
|
+
* @param {string|Function} [format.attachment] `string`: 附件字段名, `function`: 自定义处理函数, 参数为附件对象
|
|
120
|
+
* @return {Object}
|
|
121
|
+
*/
|
|
122
|
+
export function useFormFormat(form, format) {
|
|
123
|
+
//必须先 Copy form, 否则会改变 vm model 里的引用值而导致出错
|
|
124
|
+
const newForm = cloneDeep(form)
|
|
125
|
+
format = format || {}
|
|
126
|
+
const formatter = (obj) => {
|
|
127
|
+
for (let key in obj) {
|
|
128
|
+
//日期处理
|
|
129
|
+
|
|
130
|
+
let date
|
|
131
|
+
if (dayjs.isDayjs(obj[key])) {
|
|
132
|
+
date = obj[key]
|
|
133
|
+
} else if (isDate(obj[key])) {
|
|
134
|
+
date = dayjs(obj[key])
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (date && format.date) {
|
|
138
|
+
if (isString(format.date)) {
|
|
139
|
+
obj[key] = date.format(format.date)
|
|
140
|
+
} else if (isFunction(format.date)) {
|
|
141
|
+
obj[key] = format.date(date)
|
|
142
|
+
} else {
|
|
143
|
+
obj[key] = date.unix()
|
|
144
|
+
}
|
|
145
|
+
continue
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
//布尔值处理
|
|
149
|
+
if (isBoolean(obj[key]) && format.boolean) {
|
|
150
|
+
if (format.boolean === true) {
|
|
151
|
+
obj[key] = obj[key] ? 1 : 0
|
|
152
|
+
} else if (Array.isArray(format.boolean)) {
|
|
153
|
+
obj[key] = obj[key] ? format.boolean?.[0] || 1 : format.boolean?.[1] || 0
|
|
154
|
+
}
|
|
155
|
+
continue
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
//附件处理
|
|
159
|
+
if (format.attachment) {
|
|
160
|
+
const checker = format.attachment
|
|
161
|
+
if (isObject(obj[key]) && obj[key]._type === "file" && isString(checker) && !isUndefined(obj[key][checker])) {
|
|
162
|
+
obj[key] = obj[key][checker]
|
|
163
|
+
continue
|
|
164
|
+
} else if (isObject(obj[key]) && isFunction(checker) && obj[key]._type === "file") {
|
|
165
|
+
obj[key] = checker(obj[key])
|
|
166
|
+
continue
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
//数组处理
|
|
171
|
+
if (isArray(obj[key])) {
|
|
172
|
+
obj[key] = formatter(obj[key])
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
return obj
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
return formatter(newForm)
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export default {
|
|
183
|
+
useHiddenForm,
|
|
184
|
+
useProcessStatus,
|
|
185
|
+
useProcessStatusSuccess,
|
|
186
|
+
useFormFail,
|
|
187
|
+
useFormFormat,
|
|
188
|
+
}
|