af-mobile-client-vue3 1.6.2 → 1.6.4

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.6.2",
4
+ "version": "1.6.4",
5
5
  "packageManager": "pnpm@10.13.1",
6
6
  "description": "Vue + Vite component lib",
7
7
  "engines": {
@@ -170,6 +170,8 @@ const elapsedSeconds = ref(0)
170
170
  const timerDisplay = ref('00:00')
171
171
 
172
172
  const signatureAllInfo = ref(null)
173
+ // 是否显示保存按钮
174
+ const hideSaveButton = ref(false)
173
175
 
174
176
  // 启动计时器
175
177
  function startTimer() {
@@ -446,6 +448,8 @@ onBeforeMount(() => {
446
448
  safeCheckPaperId.value = route.query.paperId as string
447
449
  // 临时保存类型
448
450
  draftType.value = route.query.draftType as string
451
+ // 是否隐藏保存按钮
452
+ hideSaveButton.value = route.query.hideSaveButton as string === 'true'
449
453
  // 将路由中的extData参数存储到安检单的f_data中
450
454
  try {
451
455
  const ext = JSON.parse(route.query.extData as string)
@@ -2724,7 +2728,7 @@ provide('provideParent', {
2724
2728
  <VanButton icon="passed" type="primary" class="submit-btn" @click="onSubmit">
2725
2729
  上传
2726
2730
  </VanButton>
2727
- <VanButton v-if="!safeCheckPaperId" icon="bookmark" type="warning" class="save-btn" @click="saveDraftData">
2731
+ <VanButton v-if="(!hideSaveButton) && (!safeCheckPaperId)" icon="bookmark" type="warning" class="save-btn" @click="saveDraftData">
2728
2732
  保存
2729
2733
  </VanButton>
2730
2734
  <!-- 测试 -->
@@ -12,8 +12,8 @@
12
12
  */
13
13
  import { mobileUtil } from '@af-mobile-client-vue3/utils/mobileUtil'
14
14
  import { Icon } from '@iconify/vue'
15
- import { showFailToast, Button as VanButton, Icon as VanIcon } from 'vant'
16
- import { inject } from 'vue'
15
+ import { ActionSheet, showFailToast, Button as VanButton, Icon as VanIcon } from 'vant'
16
+ import { inject, ref } from 'vue'
17
17
 
18
18
  /**
19
19
  * 组件 Props 接口定义
@@ -23,6 +23,7 @@ const props = defineProps<{
23
23
  currentCount: number // 当前已拍摄的照片数量
24
24
  maxCount: number // 该步骤允许的最大拍照数量
25
25
  isLast: boolean // 是否为最后一个步骤
26
+ enableUpload?: boolean // 是否启用上传功能(true时点击拍照按钮先弹出选择)
26
27
  }>()
27
28
 
28
29
  /**
@@ -54,6 +55,73 @@ const parentData: any = inject('provideParent', null)
54
55
  // 核心业务方法
55
56
  // ========================================
56
57
 
58
+ /** 操作选择菜单(拍照/上传) */
59
+ const showActionSheet = ref(false)
60
+ const uploadActionOptions = [
61
+ { name: '拍照', key: 'camera' },
62
+ { name: '上传', key: 'upload' },
63
+ ]
64
+
65
+ /**
66
+ * 点击拍照按钮时的处理函数
67
+ *
68
+ * 功能说明:
69
+ * - 如果 enableUpload 为 true,则弹出选择菜单(拍照/上传)
70
+ * - 否则直接触发相机拍照(原有逻辑)
71
+ */
72
+ function handleCaptureClick() {
73
+ if (props.maxCount > 0 && props.currentCount >= props.maxCount) {
74
+ showFailToast(`最多拍摄${props.maxCount}张`)
75
+ return
76
+ }
77
+
78
+ if (props.enableUpload) {
79
+ showActionSheet.value = true
80
+ }
81
+ else {
82
+ triggerCamera()
83
+ }
84
+ }
85
+
86
+ /**
87
+ * 操作选择菜单回调
88
+ * @param option - 选中的操作项
89
+ */
90
+ function handleActionSelect(option: any) {
91
+ showActionSheet.value = false
92
+ if (option.key === 'camera') {
93
+ triggerCamera()
94
+ }
95
+ else if (option.key === 'upload') {
96
+ triggerAlbumUpload()
97
+ }
98
+ }
99
+
100
+ /**
101
+ * 从手机相册选择照片上传(仅限手机,不支持浏览器)
102
+ *
103
+ * 功能说明:
104
+ * 1. 调用Native方法打开手机相册
105
+ * 2. 选择照片后通过 queueUpload 上传到服务器
106
+ * 3. 选择失败时仅提示错误,不降级到浏览器上传
107
+ */
108
+ function triggerAlbumUpload() {
109
+ mobileUtil.execute({
110
+ funcName: 'photoAlbum',
111
+ param: {},
112
+ callbackFunc: (result: any) => {
113
+ if (result.status === 'success') {
114
+ result.data?.photos?.forEach((photo: any) => {
115
+ queueUpload(photo)
116
+ })
117
+ }
118
+ else {
119
+ showFailToast(result?.message || '选择照片失败')
120
+ }
121
+ },
122
+ })
123
+ }
124
+
57
125
  /**
58
126
  * 触发相机拍照
59
127
  *
@@ -193,7 +261,7 @@ function queueUpload(photoData: any) {
193
261
  class="icon-btn"
194
262
  round
195
263
  type="primary"
196
- @click="triggerCamera"
264
+ @click="handleCaptureClick"
197
265
  >
198
266
  <VanIcon name="photograph" />
199
267
  </VanButton>
@@ -228,6 +296,14 @@ function queueUpload(photoData: any) {
228
296
  <VanIcon name="down" class="rotate-left" />
229
297
  </VanButton>
230
298
  </div>
299
+ <!-- 拍照/上传选择菜单 -->
300
+ <ActionSheet
301
+ v-model:show="showActionSheet"
302
+ :actions="uploadActionOptions"
303
+ cancel-text="取消"
304
+ teleport="body"
305
+ @select="handleActionSelect"
306
+ />
231
307
  </div>
232
308
  </template>
233
309
 
@@ -30,6 +30,7 @@ interface PhotoStep {
30
30
  minAcceptCount?: number // 该步骤最少要求的照片数量
31
31
  acceptCount?: number // 该步骤最多允许的照片数量
32
32
  params?: any // AI识别参数配置
33
+ enableUpload?: boolean // 是否启用上传功能(true时拍照按钮显示拍照/上传选择)
33
34
  }
34
35
 
35
36
  /**
@@ -192,6 +193,7 @@ function init() {
192
193
  minAcceptCount: 0,
193
194
  acceptCount: Number(item.picNum) || 0,
194
195
  params: item.params,
196
+ enableUpload: !!item.enableUpload,
195
197
  }))
196
198
  photoAiRecognitionConfig.value = { formJson }
197
199
  normalizeFormDataBySteps()
@@ -202,7 +204,13 @@ function init() {
202
204
  else {
203
205
  getConfigByName(fromConfig, (res: any) => {
204
206
  console.warn('>>>>res', res)
205
- photoAiRecognitionConfig.value = res
207
+ photoAiRecognitionConfig.value = {
208
+ ...res,
209
+ formJson: (res?.formJson || []).map((item: any) => ({
210
+ ...item,
211
+ enableUpload: !!item.enableUpload,
212
+ })),
213
+ }
206
214
  console.warn('>>>>stepColumns', stepColumns)
207
215
  // 根据步骤配置初始化/重置表单数据
208
216
  normalizeFormDataBySteps()
@@ -733,6 +741,7 @@ defineExpose({
733
741
  :current-count="getStepPhotoCount(step.model)"
734
742
  :max-count="Number(step.acceptCount ?? 0)"
735
743
  :is-last="step.model === stepColumns[stepColumns.length - 1]?.model"
744
+ :enable-upload="step.enableUpload"
736
745
  @capture="(file) => handleCaptureSuccess(step, file)"
737
746
  @next="handleNextStep"
738
747
  @prev="handlePrevStep"