af-mobile-client-vue3 1.1.37 → 1.1.39

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.1.37",
4
+ "version": "1.1.39",
5
5
  "description": "Vue + Vite component lib",
6
6
  "license": "MIT",
7
7
  "engines": {
@@ -1,160 +1,160 @@
1
- <script setup lang="ts">
2
- import { deleteFile } from '@af-mobile-client-vue3/services/api/common'
3
- import { mobileUtil } from '@af-mobile-client-vue3/utils/mobileUtil'
4
- import {
5
- Button as vanButton,
6
- Uploader as vanUploader,
7
- } from 'vant'
8
- import { ref, watch } from 'vue'
9
-
10
- const props = defineProps({
11
- imageList: Array<any>,
12
- outerIndex: { default: undefined },
13
- authority: { default: 'user' },
14
- uploadMode: { default: 'server' },
15
- attr: { type: Object as () => { addOrEdit?: string }, default: () => ({}) },
16
- })
17
- const emit = defineEmits(['updateFileList'])
18
-
19
- const imageList = ref<Array<any>>(props.imageList ?? [])
20
-
21
- // 同步 props.imageList 到内部 imageList,保证每次变化都响应
22
- watch(() => props.imageList, (newVal) => {
23
- imageList.value = Array.isArray(newVal) ? [...newVal] : []
24
- }, { immediate: true })
25
-
26
- // 触发拍照
27
- function triggerCamera() {
28
- console.log('>>>> uploader 上传111')
29
- mobileUtil.execute({
30
- funcName: 'takePicture',
31
- param: {},
32
- callbackFunc: (result: any) => {
33
- if (result.status === 'success') {
34
- handlePhotoUpload(result.data)
35
- }
36
- },
37
- })
38
- }
39
-
40
- // 处理拍照后的上传
41
- function handlePhotoUpload(photoData: any) {
42
- const formData = new FormData()
43
- formData.append('resUploadMode', props.uploadMode)
44
- formData.append('pathKey', 'Default')
45
- formData.append('formType', 'image')
46
- formData.append('useType', 'Default')
47
- formData.append('resUploadStock', '1')
48
- formData.append('filename', photoData.name)
49
- formData.append('filesize', (photoData.size / 1024 / 1024).toFixed(4))
50
- formData.append('f_operator', 'server')
51
- formData.append('imgPath', photoData.filePath)
52
- formData.append('urlPath', `/api/${import.meta.env.VITE_APP_SYSTEM_NAME}/resource/upload`)
53
-
54
- // 添加临时预览
55
- const tempFile = {
56
- uid: Date.now() + Math.random().toString(36).substr(2, 5),
57
- name: photoData.name,
58
- status: 'uploading',
59
- message: '上传中...',
60
- url: `data:image/png;base64,${photoData.content}`,
61
- }
62
-
63
- if (!imageList.value) {
64
- imageList.value = [tempFile]
65
- }
66
- else {
67
- imageList.value.push(tempFile)
68
- }
69
-
70
- const param = {
71
- resUploadMode: props.uploadMode,
72
- pathKey: 'Default',
73
- formType: 'image',
74
- useType: 'Default',
75
- resUploadStock: '1',
76
- filename: photoData.name,
77
- filesize: photoData.size,
78
- f_operator: 'server',
79
- imgPath: photoData.filePath,
80
- urlPath: `/api/${import.meta.env.VITE_APP_SYSTEM_NAME}/resource/upload`,
81
- }
82
- // 上传到服务器
83
- mobileUtil.execute({
84
- funcName: 'uploadResource',
85
- param,
86
- callbackFunc: (result: any) => {
87
- if (result.status === 'success') {
88
- const index = imageList.value.findIndex(item => item.uid === tempFile.uid)
89
- if (index !== -1) {
90
- imageList.value[index].uid = result.data.id
91
- imageList.value[index].id = result.data.id
92
- delete imageList.value[index].message
93
- imageList.value[index].status = 'done'
94
- imageList.value[index].url = result.data.f_downloadpath
95
- }
96
- }
97
- else {
98
- const index = imageList.value.findIndex(item => item.uid === tempFile.uid)
99
- if (index !== -1) {
100
- imageList.value[index].status = 'failed'
101
- imageList.value[index].message = '上传失败'
102
- }
103
- }
104
-
105
- if (props.outerIndex !== undefined)
106
- emit('updateFileList', imageList.value.filter(item => item.status === 'done'), props.outerIndex)
107
- else
108
- emit('updateFileList', imageList.value.filter(item => item.status === 'done'))
109
- },
110
- })
111
- }
112
-
113
- // 删除图片
114
- function deleteFileFunction(file: any) {
115
- if (file.id) {
116
- deleteFile({ ids: [file.id], f_state: '删除' }).then((res: any) => {
117
- if (res.msg !== undefined) {
118
- const targetIndex = imageList.value.findIndex(item => item.id === file.id)
119
- if (targetIndex !== -1) {
120
- imageList.value.splice(targetIndex, 1)
121
- if (props.outerIndex !== undefined)
122
- emit('updateFileList', imageList.value.filter(item => item.status === 'done'), props.outerIndex)
123
- else
124
- emit('updateFileList', imageList.value.filter(item => item.status === 'done'))
125
- }
126
- }
127
- })
128
- }
129
- }
130
- </script>
131
-
132
- <template>
133
- <div class="uploader-container">
134
- <van-button
135
- v-if="props.attr?.addOrEdit !== 'readonly'"
136
- icon="photograph"
137
- type="primary"
138
- @click="triggerCamera"
139
- >
140
- 拍照
141
- </van-button>
142
-
143
- <van-uploader
144
- v-model="imageList"
145
- :show-upload="false"
146
- :deletable="props.attr?.addOrEdit !== 'readonly' && props.authority === 'admin'"
147
- :multiple="props.authority === 'admin'"
148
- :preview-image="true"
149
- :before-delete="props.attr?.addOrEdit !== 'readonly' && props.authority === 'admin' ? deleteFileFunction : undefined"
150
- />
151
- </div>
152
- </template>
153
-
154
- <style scoped lang="less">
155
- .uploader-container {
156
- display: flex;
157
- flex-direction: column;
158
- gap: 16px;
159
- }
160
- </style>
1
+ <script setup lang="ts">
2
+ import { deleteFile } from '@af-mobile-client-vue3/services/api/common'
3
+ import { mobileUtil } from '@af-mobile-client-vue3/utils/mobileUtil'
4
+ import {
5
+ Button as vanButton,
6
+ Uploader as vanUploader,
7
+ } from 'vant'
8
+ import { ref, watch } from 'vue'
9
+
10
+ const props = defineProps({
11
+ imageList: Array<any>,
12
+ outerIndex: { default: undefined },
13
+ authority: { default: 'user' },
14
+ uploadMode: { default: 'server' },
15
+ attr: { type: Object as () => { addOrEdit?: string }, default: () => ({}) },
16
+ })
17
+ const emit = defineEmits(['updateFileList'])
18
+
19
+ const imageList = ref<Array<any>>(props.imageList ?? [])
20
+
21
+ // 同步 props.imageList 到内部 imageList,保证每次变化都响应
22
+ watch(() => props.imageList, (newVal) => {
23
+ imageList.value = Array.isArray(newVal) ? [...newVal] : []
24
+ }, { immediate: true })
25
+
26
+ // 触发拍照
27
+ function triggerCamera() {
28
+ console.log('>>>> uploader 上传111')
29
+ mobileUtil.execute({
30
+ funcName: 'takePicture',
31
+ param: {},
32
+ callbackFunc: (result: any) => {
33
+ if (result.status === 'success') {
34
+ handlePhotoUpload(result.data)
35
+ }
36
+ },
37
+ })
38
+ }
39
+
40
+ // 处理拍照后的上传
41
+ function handlePhotoUpload(photoData: any) {
42
+ const formData = new FormData()
43
+ formData.append('resUploadMode', props.uploadMode)
44
+ formData.append('pathKey', 'Default')
45
+ formData.append('formType', 'image')
46
+ formData.append('useType', 'Default')
47
+ formData.append('resUploadStock', '1')
48
+ formData.append('filename', photoData.name)
49
+ formData.append('filesize', (photoData.size / 1024 / 1024).toFixed(4))
50
+ formData.append('f_operator', 'server')
51
+ formData.append('imgPath', photoData.filePath)
52
+ formData.append('urlPath', `/api/${import.meta.env.VITE_APP_SYSTEM_NAME}/resource/upload`)
53
+
54
+ // 添加临时预览
55
+ const tempFile = {
56
+ uid: Date.now() + Math.random().toString(36).substr(2, 5),
57
+ name: photoData.name,
58
+ status: 'uploading',
59
+ message: '上传中...',
60
+ url: `data:image/png;base64,${photoData.content}`,
61
+ }
62
+
63
+ if (!imageList.value) {
64
+ imageList.value = [tempFile]
65
+ }
66
+ else {
67
+ imageList.value.push(tempFile)
68
+ }
69
+
70
+ const param = {
71
+ resUploadMode: props.uploadMode,
72
+ pathKey: 'Default',
73
+ formType: 'image',
74
+ useType: 'Default',
75
+ resUploadStock: '1',
76
+ filename: photoData.name,
77
+ filesize: photoData.size,
78
+ f_operator: 'server',
79
+ imgPath: photoData.filePath,
80
+ urlPath: `/api/${import.meta.env.VITE_APP_SYSTEM_NAME}/resource/upload`,
81
+ }
82
+ // 上传到服务器
83
+ mobileUtil.execute({
84
+ funcName: 'uploadResource',
85
+ param,
86
+ callbackFunc: (result: any) => {
87
+ if (result.status === 'success') {
88
+ const index = imageList.value.findIndex(item => item.uid === tempFile.uid)
89
+ if (index !== -1) {
90
+ imageList.value[index].uid = result.data.id
91
+ imageList.value[index].id = result.data.id
92
+ delete imageList.value[index].message
93
+ imageList.value[index].status = 'done'
94
+ imageList.value[index].url = result.data.f_downloadpath
95
+ }
96
+ }
97
+ else {
98
+ const index = imageList.value.findIndex(item => item.uid === tempFile.uid)
99
+ if (index !== -1) {
100
+ imageList.value[index].status = 'failed'
101
+ imageList.value[index].message = '上传失败'
102
+ }
103
+ }
104
+
105
+ if (props.outerIndex !== undefined)
106
+ emit('updateFileList', imageList.value.filter(item => item.status === 'done'), props.outerIndex)
107
+ else
108
+ emit('updateFileList', imageList.value.filter(item => item.status === 'done'))
109
+ },
110
+ })
111
+ }
112
+
113
+ // 删除图片
114
+ function deleteFileFunction(file: any) {
115
+ if (file.id) {
116
+ deleteFile({ ids: [file.id], f_state: '删除' }).then((res: any) => {
117
+ if (res.msg !== undefined) {
118
+ const targetIndex = imageList.value.findIndex(item => item.id === file.id)
119
+ if (targetIndex !== -1) {
120
+ imageList.value.splice(targetIndex, 1)
121
+ if (props.outerIndex !== undefined)
122
+ emit('updateFileList', imageList.value.filter(item => item.status === 'done'), props.outerIndex)
123
+ else
124
+ emit('updateFileList', imageList.value.filter(item => item.status === 'done'))
125
+ }
126
+ }
127
+ })
128
+ }
129
+ }
130
+ </script>
131
+
132
+ <template>
133
+ <div class="uploader-container">
134
+ <van-button
135
+ v-if="props.attr?.addOrEdit !== 'readonly'"
136
+ icon="photograph"
137
+ type="primary"
138
+ @click="triggerCamera"
139
+ >
140
+ 拍照
141
+ </van-button>
142
+
143
+ <van-uploader
144
+ v-model="imageList"
145
+ :show-upload="false"
146
+ :deletable="props.attr?.addOrEdit !== 'readonly' && props.authority === 'admin'"
147
+ :multiple="props.authority === 'admin'"
148
+ :preview-image="true"
149
+ :before-delete="props.attr?.addOrEdit !== 'readonly' && props.authority === 'admin' ? deleteFileFunction : undefined"
150
+ />
151
+ </div>
152
+ </template>
153
+
154
+ <style scoped lang="less">
155
+ .uploader-container {
156
+ display: flex;
157
+ flex-direction: column;
158
+ gap: 16px;
159
+ }
160
+ </style>
@@ -211,11 +211,8 @@ function initComponent() {
211
211
 
212
212
  // 初始化条件参数
213
213
  function initConditionParams(formItems, isQuery) {
214
- if (!formItems || !Array.isArray(formItems) || formItems.length === 0)
215
- return
216
-
217
214
  const defaultParams = {}
218
- let hasDefaults = false
215
+ let hasDefaults: boolean
219
216
 
220
217
  // 从表单配置中获取所有默认值
221
218
  formItems.forEach((item) => {
@@ -239,12 +236,11 @@ function initConditionParams(formItems, isQuery) {
239
236
  else {
240
237
  defaultParams[item.model] = item.queryFormDefault
241
238
  }
242
- hasDefaults = true
243
239
  }
244
- hasDefaults = true
245
240
  }
246
- hasDefaults = true
247
241
  })
242
+ // eslint-disable-next-line prefer-const
243
+ hasDefaults = true
248
244
 
249
245
  // 如果有默认值,则设置到条件参数中并立即执行查询
250
246
  queryDefaultParams.value = defaultParams
@@ -351,6 +347,19 @@ function splitArrayAt<T>(array: T[], index: number) {
351
347
  otherActions.value = array.slice(index)
352
348
  }
353
349
 
350
+ // 新增:动态获取按钮分组
351
+ function getActionGroups(item: any, index: number) {
352
+ // 先过滤出当前行可见的按钮
353
+ const visibleActions = allActions.value.filter(action =>
354
+ evaluateCustomFunction(action.customFunction, item, index),
355
+ )
356
+ // 前3个为主按钮,其余为更多按钮,保持逆序
357
+ return {
358
+ main: visibleActions.slice(0, 3).reverse(),
359
+ more: visibleActions.slice(3).reverse(),
360
+ }
361
+ }
362
+
354
363
  watch(() => searchValue.value, (newVal) => {
355
364
  if (newVal === '')
356
365
  onRefresh()
@@ -679,16 +688,16 @@ defineExpose({
679
688
  <VanRow v-if="allActions.length > 0" gutter="20" class="card_item_bottom">
680
689
  <VanCol span="4">
681
690
  <VanPopover
682
- v-if="otherActions && otherActions.length !== 0 && otherActions.some(action => evaluateCustomFunction(action.customFunction, item, index))"
691
+ v-if="getActionGroups(item, index).more.length"
683
692
  v-model:show="showPopover[index]"
684
693
  placement="bottom-start"
685
- :actions="otherActions.filter(action => evaluateCustomFunction(action.customFunction, item, index))"
694
+ theme="dark"
695
+ overlay
696
+ :actions="getActionGroups(item, index).more"
686
697
  @select="onSelectMenu(item, $event)"
687
698
  >
688
699
  <template #reference>
689
- <div
690
- class="more-button"
691
- >
700
+ <div class="more-button">
692
701
  <span>⋯</span>
693
702
  </div>
694
703
  </template>
@@ -698,8 +707,7 @@ defineExpose({
698
707
  <VanRow justify="end">
699
708
  <VanSpace>
700
709
  <VanButton
701
- v-for="button in reversedMainActions"
702
- v-show="evaluateCustomFunction(button.customFunction, item, index)"
710
+ v-for="button in getActionGroups(item, index).main"
703
711
  :key="button.func"
704
712
  type="primary"
705
713
  size="small"