xianniu-ui 0.8.39 → 0.8.40
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/lib/xianniu-ui.common.js +51 -25
- package/lib/xianniu-ui.umd.js +51 -25
- package/lib/xianniu-ui.umd.min.js +2 -2
- package/package.json +1 -1
- package/src/utils/utils.js +27 -1
package/package.json
CHANGED
package/src/utils/utils.js
CHANGED
|
@@ -198,7 +198,32 @@ export const toCamelCase = (string)=> {
|
|
|
198
198
|
return camelCaseString;
|
|
199
199
|
}
|
|
200
200
|
|
|
201
|
+
export function assignValues(form, apiResponse) {
|
|
202
|
+
function isEmpty(value) {
|
|
203
|
+
return (
|
|
204
|
+
(Array.isArray(value) && value.length === 0) ||
|
|
205
|
+
(typeof value === 'object' && Object.keys(value).length === 0)
|
|
206
|
+
)
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
const updatedForm = Array.isArray(form) ? [...form] : { ...form }
|
|
210
|
+
|
|
211
|
+
for (const key in form) {
|
|
212
|
+
if (Object.hasOwnProperty.call(form, key)) {
|
|
213
|
+
const apiValue = apiResponse[key]
|
|
214
|
+
|
|
215
|
+
// 检查 apiValue 是否是一个对象,如果是,则递归
|
|
216
|
+
if (typeof apiValue === 'object' && apiValue !== null && !Array.isArray(apiValue)) {
|
|
217
|
+
updatedForm[key] = assignValues(form[key], apiValue)
|
|
218
|
+
} else if (apiValue !== null && apiValue !== undefined && apiValue !== '' && !isEmpty(apiValue)) {
|
|
219
|
+
// 如果 apiValue 不是空值及不是空的对象或数组,更新 updatedForm
|
|
220
|
+
updatedForm[key] = apiValue
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
201
224
|
|
|
225
|
+
return updatedForm
|
|
226
|
+
}
|
|
202
227
|
export default {
|
|
203
228
|
isEmpty,
|
|
204
229
|
isImg,
|
|
@@ -209,5 +234,6 @@ export default {
|
|
|
209
234
|
isBlank,
|
|
210
235
|
toCamelCase,
|
|
211
236
|
checkFile,
|
|
212
|
-
isAV
|
|
237
|
+
isAV,
|
|
238
|
+
assignValues
|
|
213
239
|
}
|