af-mobile-client-vue3 1.2.12 → 1.2.14
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/package.json
CHANGED
|
@@ -717,7 +717,7 @@ defineExpose({
|
|
|
717
717
|
flex-direction: column;
|
|
718
718
|
--van-search-padding: 3px;
|
|
719
719
|
--van-dropdown-menu-title-padding: 3px;
|
|
720
|
-
--van-cell-
|
|
720
|
+
--van-cell-horizontal-padding: 0px;
|
|
721
721
|
--van-text-color-2: rgb(75, 85, 99);
|
|
722
722
|
--van-button-normal-font-size: 13px;
|
|
723
723
|
.main {
|
|
@@ -822,7 +822,7 @@ defineExpose({
|
|
|
822
822
|
|
|
823
823
|
.tag-item {
|
|
824
824
|
width: auto;
|
|
825
|
-
font-size: var(--van-font-size-
|
|
825
|
+
font-size: var(--van-font-size-md);
|
|
826
826
|
margin: 4px 4px;
|
|
827
827
|
:deep(.van-tag) {
|
|
828
828
|
width: fit-content;
|
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
import type { FormInstance } from 'vant'
|
|
3
3
|
import XFormItem from '@af-mobile-client-vue3/components/data/XFormItem/index.vue'
|
|
4
4
|
import XOlMap from '@af-mobile-client-vue3/components/data/XOlMap/index.vue'
|
|
5
|
-
import {
|
|
5
|
+
import { formatDate } from '@af-mobile-client-vue3/hooks/useCommon'
|
|
6
|
+
import { addOrModifyEntity, runLogic } from '@af-mobile-client-vue3/services/api/common'
|
|
6
7
|
import { post } from '@af-mobile-client-vue3/services/restTools'
|
|
8
|
+
import { useUserStore } from '@af-mobile-client-vue3/stores'
|
|
7
9
|
import {
|
|
8
10
|
showFailToast,
|
|
9
11
|
showSuccessToast,
|
|
@@ -20,6 +22,11 @@ interface FormItem {
|
|
|
20
22
|
model?: string
|
|
21
23
|
}
|
|
22
24
|
|
|
25
|
+
interface SilenceAddFormItem extends FormItem {
|
|
26
|
+
silencePurpose: string
|
|
27
|
+
silenceSource?: string
|
|
28
|
+
}
|
|
29
|
+
|
|
23
30
|
interface GroupFormItems {
|
|
24
31
|
btnName?: string
|
|
25
32
|
formJson: any[] // 根据实际类型调整
|
|
@@ -45,6 +52,7 @@ const props = withDefaults(defineProps<{
|
|
|
45
52
|
submitButton: true,
|
|
46
53
|
})
|
|
47
54
|
const emits = defineEmits(['onSubmit'])
|
|
55
|
+
const userStore = useUserStore()
|
|
48
56
|
const formRef = ref<FormInstance>()
|
|
49
57
|
const myFormItems = ref<FormItem[]>([])
|
|
50
58
|
const rules = reactive({})
|
|
@@ -68,6 +76,16 @@ const realJsonData = computed(() => {
|
|
|
68
76
|
})
|
|
69
77
|
})
|
|
70
78
|
|
|
79
|
+
// 是否处理表单Key值
|
|
80
|
+
const isHandleFormKey = ref(true)
|
|
81
|
+
|
|
82
|
+
// 过滤出用于静默新增场景的表单项
|
|
83
|
+
const silenceAddJsonData = computed(() => {
|
|
84
|
+
return myFormItems.value.filter((item) => {
|
|
85
|
+
return item.addOrEdit === 'silenceAdd'
|
|
86
|
+
}) as SilenceAddFormItem[]
|
|
87
|
+
})
|
|
88
|
+
|
|
71
89
|
const resolvedSubmitButton = computed(() => {
|
|
72
90
|
if (props.configName && internalSubmitButton.value !== undefined) {
|
|
73
91
|
return internalSubmitButton.value
|
|
@@ -242,20 +260,128 @@ function setForm(obj) {
|
|
|
242
260
|
}
|
|
243
261
|
|
|
244
262
|
// 获取表单字段实际值
|
|
245
|
-
function getRealKey(
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
263
|
+
function getRealKey(key, mustHandleKey = false) {
|
|
264
|
+
if (key === 'selected_id')
|
|
265
|
+
return key
|
|
266
|
+
if (isHandleFormKey.value || mustHandleKey) {
|
|
267
|
+
return key.substring(key.indexOf('_') + 1)
|
|
268
|
+
}
|
|
269
|
+
else {
|
|
270
|
+
return key
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
async function asyncSubmit() {
|
|
275
|
+
return new Promise((resolve, reject) => {
|
|
276
|
+
validate().then(async () => {
|
|
277
|
+
const requestForm = prepareForm()
|
|
278
|
+
await appendSilenceAddFields(requestForm)
|
|
279
|
+
const realForm = handleFormKeys(requestForm)
|
|
280
|
+
resolve({
|
|
281
|
+
realForm,
|
|
282
|
+
mode: props.mode,
|
|
283
|
+
serviceName: props.serviceName,
|
|
284
|
+
currUserName: userStore.getUserInfo().name,
|
|
285
|
+
currUserId: userStore.getUserInfo().id,
|
|
286
|
+
orgId: userStore.getUserInfo().orgid,
|
|
287
|
+
})
|
|
288
|
+
}).catch((error) => {
|
|
289
|
+
reject(error)
|
|
290
|
+
})
|
|
291
|
+
})
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
function handleFormKeys(form, mustHandleKey = false) {
|
|
295
|
+
const realForm = {}
|
|
296
|
+
for (const key of Object.keys(form)) {
|
|
297
|
+
const value = form[key]
|
|
298
|
+
const extraFormKeyTagIndex = key.indexOf('@')
|
|
299
|
+
if (extraFormKeyTagIndex !== -1) {
|
|
300
|
+
const extraFormKey = key.substring(0, extraFormKeyTagIndex)
|
|
301
|
+
const realKey = key.substring(extraFormKeyTagIndex + 1)
|
|
302
|
+
if (!realForm[extraFormKey]) {
|
|
303
|
+
realForm[extraFormKey] = {}
|
|
304
|
+
}
|
|
305
|
+
realForm[extraFormKey][realKey] = value
|
|
306
|
+
}
|
|
307
|
+
else {
|
|
308
|
+
const realKey = isHandleFormKey.value || mustHandleKey ? getRealKey(key, mustHandleKey) : key
|
|
309
|
+
// 如果发生重名,不覆盖,把key的别名带上
|
|
310
|
+
if (realForm[realKey]) {
|
|
311
|
+
realForm[key] = value
|
|
312
|
+
}
|
|
313
|
+
else {
|
|
314
|
+
realForm[realKey] = value
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
return realForm
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
async function appendSilenceAddFields(form) {
|
|
322
|
+
if (props.mode === '新增') {
|
|
323
|
+
for (const item of silenceAddJsonData.value) {
|
|
324
|
+
switch (item.silencePurpose) {
|
|
325
|
+
case 'createTime':
|
|
326
|
+
form[item.model] = formatDate(new Date())
|
|
327
|
+
break
|
|
328
|
+
case 'operator':
|
|
329
|
+
form[item.model] = userStore.getUserInfo().name
|
|
330
|
+
break
|
|
331
|
+
case 'operatorId':
|
|
332
|
+
form[item.model] = userStore.getUserInfo().id
|
|
333
|
+
break
|
|
334
|
+
case 'orgId':
|
|
335
|
+
form[item.model] = userStore.getUserInfo().orgid
|
|
336
|
+
break
|
|
337
|
+
case 'orgName':
|
|
338
|
+
form[item.model] = userStore.getUserInfo().orgs
|
|
339
|
+
break
|
|
340
|
+
case 'depId':
|
|
341
|
+
form[item.model] = userStore.getUserInfo().depids
|
|
342
|
+
break
|
|
343
|
+
case 'depName':
|
|
344
|
+
form[item.model] = userStore.getUserInfo().deps
|
|
345
|
+
break
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
for (const item of silenceAddJsonData.value.filter(item => item.silencePurpose === 'customize')) {
|
|
349
|
+
const result: any = await runLogic(item.silenceSource, form, props.serviceName)
|
|
350
|
+
if (result) {
|
|
351
|
+
const keys = Object.keys(result)
|
|
352
|
+
if (keys.length === 1 && keys[0] === 'value') {
|
|
353
|
+
form[item.model] = result.value
|
|
354
|
+
}
|
|
355
|
+
else {
|
|
356
|
+
form[item.model] = result
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
else {
|
|
360
|
+
form[item.model] = result
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
function prepareForm() {
|
|
367
|
+
const formObj = { ...form.value }
|
|
368
|
+
for (const key of Object.keys(formObj)) {
|
|
369
|
+
const value = formObj[key]
|
|
370
|
+
if (value === null || (typeof value === 'object' && Object.keys(value).length === 0)) {
|
|
371
|
+
formObj[key] = undefined
|
|
372
|
+
}
|
|
249
373
|
}
|
|
250
|
-
return
|
|
374
|
+
return formObj
|
|
251
375
|
}
|
|
252
376
|
|
|
253
|
-
function onSubmit() {
|
|
377
|
+
async function onSubmit() {
|
|
254
378
|
if (!props.configName && props.groupFormItems) {
|
|
255
379
|
// 只有单表才可以成功,多表关联或者自定义sql不行
|
|
256
|
-
const
|
|
380
|
+
const requestForm = prepareForm()
|
|
381
|
+
await appendSilenceAddFields(requestForm)
|
|
382
|
+
const realForm = handleFormKeys(requestForm)
|
|
257
383
|
try {
|
|
258
|
-
addOrModifyEntity(
|
|
384
|
+
addOrModifyEntity(realForm, tableName.value, props.serviceName || import.meta.env.VITE_APP_SYSTEM_NAME).then(() => {
|
|
259
385
|
showSuccessToast('提交成功!')
|
|
260
386
|
})
|
|
261
387
|
}
|
|
@@ -278,7 +404,7 @@ async function validate() {
|
|
|
278
404
|
watch(() => props.formData, (_val) => {
|
|
279
405
|
form.value = _val
|
|
280
406
|
})
|
|
281
|
-
defineExpose({ init, form, formGroupName, validate })
|
|
407
|
+
defineExpose({ init, form, formGroupName, validate, asyncSubmit })
|
|
282
408
|
</script>
|
|
283
409
|
|
|
284
410
|
<template>
|
|
@@ -166,7 +166,7 @@ function getDefaultValue() {
|
|
|
166
166
|
if (mode === '查询')
|
|
167
167
|
return props.modelValue !== undefined ? props.modelValue : querySelectDefaultValue.value
|
|
168
168
|
else
|
|
169
|
-
return props.modelValue !== undefined ? props.modelValue : formSelectDefaultValue.value
|
|
169
|
+
return props.modelValue !== undefined && props.modelValue ? props.modelValue : formSelectDefaultValue.value
|
|
170
170
|
case 'switch':
|
|
171
171
|
return props.modelValue !== undefined ? props.modelValue : false
|
|
172
172
|
case 'radio':
|