af-mobile-client-vue3 1.5.80 → 1.5.81

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
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "af-mobile-client-vue3",
3
3
  "type": "module",
4
- "version": "1.5.80",
4
+ "version": "1.5.81",
5
5
  "packageManager": "pnpm@10.13.1",
6
6
  "description": "Vue + Vite component lib",
7
7
  "engines": {
@@ -71,6 +71,8 @@ const props = withDefaults(defineProps<{
71
71
  labelAlign?: string
72
72
  // 表单文本对齐方式 left、center、right
73
73
  inputAlign?: string
74
+ /** 是否启用提交按钮 loading(默认不启用,保持历史行为) */
75
+ enableSubmitLoading?: boolean
74
76
  }>(), {
75
77
  configName: undefined,
76
78
  groupTitle: undefined,
@@ -88,6 +90,7 @@ const props = withDefaults(defineProps<{
88
90
  watermarkCustomLines: () => [],
89
91
  labelAlign: undefined,
90
92
  inputAlign: undefined,
93
+ enableSubmitLoading: false,
91
94
  })
92
95
 
93
96
  const emits = defineEmits(['onSubmit', 'xFormItemEmitFunc'])
@@ -103,6 +106,7 @@ const form = ref({})
103
106
  const rules = reactive({})
104
107
  const myGetDataParams = ref({})
105
108
  const isKeyHandle = ref(false)
109
+ const submitLoading = ref(false)
106
110
 
107
111
  // 配置相关状态
108
112
  const formConfig = ref<GroupFormItems | null>(null)
@@ -658,33 +662,44 @@ function getFormData() {
658
662
  }
659
663
 
660
664
  async function onSubmit() {
661
- await validate()
662
- // 清理表单数据
663
- let realForm = prepareForm()
664
- await appendSilenceAddFields(realForm)
665
- if (!props.configName && props.groupFormItems) {
666
- // 只有单表才可以成功,多表关联或者自定义sql不行
667
- realForm = handleFormKeys(realForm)
668
-
669
- try {
670
- addOrModifyEntity(realForm, tableName.value, props.serviceName || import.meta.env.VITE_APP_SYSTEM_NAME).then(() => {
671
- showSuccessToast('提交成功!!')
672
- })
673
- }
674
- catch (error) {
675
- showFailToast('提交失败!!')
665
+ if (props.enableSubmitLoading) {
666
+ if (submitLoading.value)
667
+ return
668
+ submitLoading.value = true
669
+ }
670
+ try {
671
+ await validate()
672
+ // 清理表单数据
673
+ let realForm = prepareForm()
674
+ await appendSilenceAddFields(realForm)
675
+ if (!props.configName && props.groupFormItems) {
676
+ // 只有单表才可以成功,多表关联或者自定义sql不行
677
+ realForm = handleFormKeys(realForm)
678
+
679
+ try {
680
+ addOrModifyEntity(realForm, tableName.value, props.serviceName || import.meta.env.VITE_APP_SYSTEM_NAME).then(() => {
681
+ showSuccessToast('提交成功!!')
682
+ })
683
+ }
684
+ catch (error) {
685
+ showFailToast('提交失败!!')
686
+ }
687
+ finally {
688
+ setTimeout(() => {
689
+ history.back()
690
+ }, 1000)
691
+ }
676
692
  }
677
- finally {
678
- setTimeout(() => {
679
- history.back()
680
- }, 1000)
693
+ else {
694
+ if (isKeyHandle.value)
695
+ realForm = handleFormKeys(realForm)
696
+ // 使用清理后的数据
697
+ emits('onSubmit', realForm)
681
698
  }
682
699
  }
683
- else {
684
- if (isKeyHandle.value)
685
- realForm = handleFormKeys(realForm)
686
- // 使用清理后的数据
687
- emits('onSubmit', realForm)
700
+ catch {
701
+ if (props.enableSubmitLoading)
702
+ submitLoading.value = false
688
703
  }
689
704
  }
690
705
  async function validate() {
@@ -695,7 +710,17 @@ function emitFunc(func: any, data: any, value: any, attr: any) {
695
710
  emits('xFormItemEmitFunc', func, data, value, attr)
696
711
  }
697
712
 
698
- defineExpose({ init, form, formGroupName, validate, asyncSubmit, setForm, getFormData, setFormData })
713
+ function openLoading() {
714
+ if (props.enableSubmitLoading)
715
+ submitLoading.value = true
716
+ }
717
+
718
+ function closeLoading() {
719
+ if (props.enableSubmitLoading)
720
+ submitLoading.value = false
721
+ }
722
+
723
+ defineExpose({ init, form, formGroupName, validate, asyncSubmit, setForm, getFormData, setFormData, openLoading, closeLoading })
699
724
  </script>
700
725
 
701
726
  <template>
@@ -733,7 +758,15 @@ defineExpose({ init, form, formGroupName, validate, asyncSubmit, setForm, getFor
733
758
  </div>
734
759
  </div>
735
760
  <div v-if="resolvedSubmitButton && props.mode !== '预览' && !props.formReadonly" class="form-footer-fixed">
736
- <VanButton class="action-btn" round block type="primary" native-type="submit">
761
+ <VanButton
762
+ class="action-btn"
763
+ round
764
+ block
765
+ type="primary"
766
+ native-type="submit"
767
+ :loading="props.enableSubmitLoading && submitLoading"
768
+ :disabled="props.enableSubmitLoading && submitLoading"
769
+ >
737
770
  {{ props.groupFormItems?.btnName ? props.groupFormItems.btnName : '提交' }}
738
771
  </VanButton>
739
772
  <slot />
@@ -12,6 +12,8 @@ const props = withDefaults(defineProps<{
12
12
  isScrollspy?: boolean
13
13
  formShow?: any
14
14
  showTabHeader?: boolean
15
+ /** 是否启用提交按钮 loading(默认不启用,保持历史行为) */
16
+ enableSubmitLoading?: boolean
15
17
  }>(), {
16
18
  configName: '',
17
19
  serviceName: undefined,
@@ -20,6 +22,7 @@ const props = withDefaults(defineProps<{
20
22
  isScrollspy: true,
21
23
  formShow: undefined,
22
24
  showTabHeader: true,
25
+ enableSubmitLoading: false,
23
26
  })
24
27
  const emit = defineEmits(['submit', 'xFormItemEmitFunc'])
25
28
 
@@ -28,6 +31,7 @@ const formData = ref({})
28
31
  const submitGroup = ref(false)
29
32
  const submitSimple = ref(false)
30
33
  const isInit = ref(false)
34
+ const submitLoading = ref(false)
31
35
 
32
36
  const slots = useSlots()
33
37
  const renderableGroupItems = computed(() => {
@@ -93,13 +97,30 @@ function removeRef(refValue: XFormLike) {
93
97
  }
94
98
 
95
99
  async function submit() {
100
+ if (props.enableSubmitLoading) {
101
+ if (submitLoading.value)
102
+ return
103
+ submitLoading.value = true
104
+ }
96
105
  console.log(props.groupFormData)
97
106
  const groupFormData = await getGroupFormData()
98
107
  if (!groupFormData) {
108
+ if (props.enableSubmitLoading)
109
+ submitLoading.value = false
99
110
  return
100
111
  }
101
112
  emit('submit', formData.value)
102
113
  }
114
+
115
+ function openLoading() {
116
+ if (props.enableSubmitLoading)
117
+ submitLoading.value = true
118
+ }
119
+
120
+ function closeLoading() {
121
+ if (props.enableSubmitLoading)
122
+ submitLoading.value = false
123
+ }
103
124
  async function getGroupFormData(isValidate = true) {
104
125
  for (const res of xFormListRef.value) {
105
126
  try {
@@ -129,7 +150,7 @@ onMounted(() => {
129
150
  offsetTop.value = Number.parseInt(navBarHeight, 10) || 60 + 10
130
151
  })
131
152
 
132
- defineExpose({ init, removeRef, xFormListRef, getGroupFormData })
153
+ defineExpose({ init, removeRef, xFormListRef, getGroupFormData, openLoading, closeLoading })
133
154
  </script>
134
155
 
135
156
  <template>
@@ -175,7 +196,15 @@ defineExpose({ init, removeRef, xFormListRef, getGroupFormData })
175
196
  </VanTab>
176
197
  </VanTabs>
177
198
  <div class="form-footer-fixed">
178
- <VanButton v-if="submitGroup" round block type="primary" @click="submit">
199
+ <VanButton
200
+ v-if="submitGroup"
201
+ round
202
+ block
203
+ type="primary"
204
+ :loading="props.enableSubmitLoading && submitLoading"
205
+ :disabled="props.enableSubmitLoading && submitLoading"
206
+ @click="submit"
207
+ >
179
208
  提交
180
209
  </VanButton>
181
210
  </div>
@@ -9,52 +9,18 @@ import { useRoute } from 'vue-router'
9
9
  const configName = ref('form_check_test')
10
10
  const serviceName = ref('af-system')
11
11
 
12
- // const configName = ref("计划下发Form")
13
- // const serviceName = ref("af-linepatrol")
14
-
15
- // 表单组
16
- // const configName = ref('lngChargeAuditMobileFormGroup')
17
- // const serviceName = ref('af-gaslink')
18
-
19
12
  const formData = ref({})
20
- const formGroup = ref(null)
13
+ const formGroup = ref<any>(null)
21
14
  const route = useRoute()
22
15
  const isInit = ref(false)
23
16
  function submit(_result) {
24
17
  showDialog({ message: '提交成功' }).then(() => {
18
+ formGroup.value?.closeLoading?.()
25
19
  history.back()
20
+ }).catch(() => {
21
+ formGroup.value?.closeLoading?.()
26
22
  })
27
23
  }
28
-
29
- // 表单组——数据
30
- // function initComponents () {
31
- // runLogic('getlngChargeAuditMobileFormGroupData', {id: 29}, 'af-gaslink').then((res) => {
32
- // formData.value = {...res}
33
- // })
34
- // }
35
-
36
- // 纯表单——数据
37
- // function initComponents() {
38
- // formData.value = { plan_name: 'af-llllll', plan_point: '1号点位', plan_single: '1号点位', plan_range: '2024-12-12' }
39
- // }
40
-
41
- // function initComponents() {
42
- // runLogic('getlngChargeAuditMobileFormGroupData', { id: route.query?.id, o_id: route.query?.o_id }, 'af-gaslink').then((res) => {
43
- // console.log('res------', res)
44
- // formData.value = { ...res }
45
- // formGroup.value.init({
46
- // configName: configName.value,
47
- // serviceName: serviceName.value,
48
- // groupFormData: { ...res },
49
- // mode: "新增"
50
- // })
51
- // isInit.value = true
52
- // })
53
- // }
54
-
55
- // onBeforeMount(() => {
56
- // initComponents()
57
- // })
58
24
  </script>
59
25
 
60
26
  <template>
@@ -66,6 +32,7 @@ function submit(_result) {
66
32
  :config-name="configName"
67
33
  :service-name="serviceName"
68
34
  :group-form-data="formData"
35
+ :enable-submit-loading="true"
69
36
  mode="新增"
70
37
  @submit="submit"
71
38
  />
@@ -8,13 +8,22 @@ import { ref } from 'vue'
8
8
  const configName = ref('AddConstructionForm')
9
9
  const serviceName = ref('af-linepatrol')
10
10
 
11
- const formGroupAddConstruction = ref(null)
12
-
11
+ const formGroupAddConstruction = ref<any>(null)
12
+ function sleep(ms) {
13
+ return new Promise(resolve => setTimeout(resolve, ms))
14
+ }
13
15
  // 地图预览相关
14
16
  const previewMapRef = ref(null)
15
- function onSubmit(data: any) {
16
- console.warn('提交表单', data)
17
- router.back()
17
+
18
+ async function onSubmit(data: any) {
19
+ try {
20
+ console.warn('提交表单', data)
21
+ await sleep(1000) // 暂停10秒
22
+ router.back()
23
+ }
24
+ finally {
25
+ formGroupAddConstruction.value?.closeLoading?.()
26
+ }
18
27
  }
19
28
  function onAddressChange(data: any) {
20
29
  console.warn('表单新增数据变化', data)
@@ -33,6 +42,7 @@ function onRegionChange(data: any) {
33
42
  mode="新增"
34
43
  :config-name="configName"
35
44
  :service-name="serviceName"
45
+ :enable-submit-loading="true"
36
46
  @address-change="onAddressChange"
37
47
  @region-change="onRegionChange"
38
48
  @on-submit="onSubmit"