af-mobile-client-vue3 1.1.21 → 1.1.23

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.21",
4
+ "version": "1.1.23",
5
5
  "description": "Vue + Vite component lib",
6
6
  "license": "MIT",
7
7
  "engines": {
@@ -1,163 +1,163 @@
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
- console.log('>>>> 拍照 后 上传', result)
34
- if (result.status === 'success') {
35
- handlePhotoUpload(result.data)
36
- }
37
- },
38
- })
39
- }
40
-
41
- // 处理拍照后的上传
42
- function handlePhotoUpload(photoData: any) {
43
- const formData = new FormData()
44
- formData.append('resUploadMode', props.uploadMode)
45
- formData.append('pathKey', 'Default')
46
- formData.append('formType', 'image')
47
- formData.append('useType', 'Default')
48
- formData.append('resUploadStock', '1')
49
- formData.append('filename', photoData.name)
50
- formData.append('filesize', (photoData.size / 1024 / 1024).toFixed(4))
51
- formData.append('f_operator', 'server')
52
- formData.append('imgPath', photoData.filePath)
53
- formData.append('urlPath', '/api/af-revenue/resource/upload')
54
-
55
- // 添加临时预览
56
- const tempFile = {
57
- uid: Date.now() + Math.random().toString(36).substr(2, 5),
58
- name: photoData.name,
59
- status: 'uploading',
60
- message: '上传中...',
61
- url: `data:image/png;base64,${photoData.content}`,
62
- }
63
-
64
- if (!imageList.value) {
65
- imageList.value = [tempFile]
66
- }
67
- else {
68
- imageList.value.push(tempFile)
69
- }
70
-
71
- const param = {
72
- resUploadMode: props.uploadMode,
73
- pathKey: 'Default',
74
- formType: 'image',
75
- useType: 'Default',
76
- resUploadStock: '1',
77
- filename: photoData.name,
78
- filesize: photoData.size,
79
- f_operator: 'server',
80
- imgPath: photoData.filePath,
81
- urlPath: '/api/af-revenue/resource/upload',
82
- }
83
- console.log('>>>> 上传 param: ', JSON.stringify(param))
84
- // 上传到服务器
85
- mobileUtil.execute({
86
- funcName: 'uploadResource',
87
- param,
88
- callbackFunc: (result: any) => {
89
- console.log('>>>> 上传结果: ', result)
90
- if (result.status === 'success') {
91
- const index = imageList.value.findIndex(item => item.uid === tempFile.uid)
92
- if (index !== -1) {
93
- imageList.value[index].uid = result.data.id
94
- imageList.value[index].id = result.data.id
95
- delete imageList.value[index].message
96
- imageList.value[index].status = 'done'
97
- imageList.value[index].url = result.data.f_downloadpath
98
- }
99
- }
100
- else {
101
- const index = imageList.value.findIndex(item => item.uid === tempFile.uid)
102
- if (index !== -1) {
103
- imageList.value[index].status = 'failed'
104
- imageList.value[index].message = '上传失败'
105
- }
106
- }
107
-
108
- if (props.outerIndex !== undefined)
109
- emit('updateFileList', imageList.value.filter(item => item.status === 'done'), props.outerIndex)
110
- else
111
- emit('updateFileList', imageList.value.filter(item => item.status === 'done'))
112
- },
113
- })
114
- }
115
-
116
- // 删除图片
117
- function deleteFileFunction(file: any) {
118
- if (file.id) {
119
- deleteFile({ ids: [file.id], f_state: '删除' }).then((res: any) => {
120
- if (res.msg !== undefined) {
121
- const targetIndex = imageList.value.findIndex(item => item.id === file.id)
122
- if (targetIndex !== -1) {
123
- imageList.value.splice(targetIndex, 1)
124
- if (props.outerIndex !== undefined)
125
- emit('updateFileList', imageList.value.filter(item => item.status === 'done'), props.outerIndex)
126
- else
127
- emit('updateFileList', imageList.value.filter(item => item.status === 'done'))
128
- }
129
- }
130
- })
131
- }
132
- }
133
- </script>
134
-
135
- <template>
136
- <div class="uploader-container">
137
- <van-button
138
- v-if="props.attr?.addOrEdit !== 'readonly'"
139
- icon="photograph"
140
- type="primary"
141
- @click="triggerCamera"
142
- >
143
- 拍照
144
- </van-button>
145
-
146
- <van-uploader
147
- v-model="imageList"
148
- :show-upload="false"
149
- :deletable="props.attr?.addOrEdit !== 'readonly' && props.authority === 'admin'"
150
- :multiple="props.authority === 'admin'"
151
- :preview-image="true"
152
- :before-delete="props.attr?.addOrEdit !== 'readonly' && props.authority === 'admin' ? deleteFileFunction : undefined"
153
- />
154
- </div>
155
- </template>
156
-
157
- <style scoped lang="less">
158
- .uploader-container {
159
- display: flex;
160
- flex-direction: column;
161
- gap: 16px;
162
- }
163
- </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
+ console.log('>>>> 拍照 后 上传', result)
34
+ if (result.status === 'success') {
35
+ handlePhotoUpload(result.data)
36
+ }
37
+ },
38
+ })
39
+ }
40
+
41
+ // 处理拍照后的上传
42
+ function handlePhotoUpload(photoData: any) {
43
+ const formData = new FormData()
44
+ formData.append('resUploadMode', props.uploadMode)
45
+ formData.append('pathKey', 'Default')
46
+ formData.append('formType', 'image')
47
+ formData.append('useType', 'Default')
48
+ formData.append('resUploadStock', '1')
49
+ formData.append('filename', photoData.name)
50
+ formData.append('filesize', (photoData.size / 1024 / 1024).toFixed(4))
51
+ formData.append('f_operator', 'server')
52
+ formData.append('imgPath', photoData.filePath)
53
+ formData.append('urlPath', '/api/af-revenue/resource/upload')
54
+
55
+ // 添加临时预览
56
+ const tempFile = {
57
+ uid: Date.now() + Math.random().toString(36).substr(2, 5),
58
+ name: photoData.name,
59
+ status: 'uploading',
60
+ message: '上传中...',
61
+ url: `data:image/png;base64,${photoData.content}`,
62
+ }
63
+
64
+ if (!imageList.value) {
65
+ imageList.value = [tempFile]
66
+ }
67
+ else {
68
+ imageList.value.push(tempFile)
69
+ }
70
+
71
+ const param = {
72
+ resUploadMode: props.uploadMode,
73
+ pathKey: 'Default',
74
+ formType: 'image',
75
+ useType: 'Default',
76
+ resUploadStock: '1',
77
+ filename: photoData.name,
78
+ filesize: photoData.size,
79
+ f_operator: 'server',
80
+ imgPath: photoData.filePath,
81
+ urlPath: '/api/af-revenue/resource/upload',
82
+ }
83
+ console.log('>>>> 上传 param: ', JSON.stringify(param))
84
+ // 上传到服务器
85
+ mobileUtil.execute({
86
+ funcName: 'uploadResource',
87
+ param,
88
+ callbackFunc: (result: any) => {
89
+ console.log('>>>> 上传结果: ', result)
90
+ if (result.status === 'success') {
91
+ const index = imageList.value.findIndex(item => item.uid === tempFile.uid)
92
+ if (index !== -1) {
93
+ imageList.value[index].uid = result.data.id
94
+ imageList.value[index].id = result.data.id
95
+ delete imageList.value[index].message
96
+ imageList.value[index].status = 'done'
97
+ imageList.value[index].url = result.data.f_downloadpath
98
+ }
99
+ }
100
+ else {
101
+ const index = imageList.value.findIndex(item => item.uid === tempFile.uid)
102
+ if (index !== -1) {
103
+ imageList.value[index].status = 'failed'
104
+ imageList.value[index].message = '上传失败'
105
+ }
106
+ }
107
+
108
+ if (props.outerIndex !== undefined)
109
+ emit('updateFileList', imageList.value.filter(item => item.status === 'done'), props.outerIndex)
110
+ else
111
+ emit('updateFileList', imageList.value.filter(item => item.status === 'done'))
112
+ },
113
+ })
114
+ }
115
+
116
+ // 删除图片
117
+ function deleteFileFunction(file: any) {
118
+ if (file.id) {
119
+ deleteFile({ ids: [file.id], f_state: '删除' }).then((res: any) => {
120
+ if (res.msg !== undefined) {
121
+ const targetIndex = imageList.value.findIndex(item => item.id === file.id)
122
+ if (targetIndex !== -1) {
123
+ imageList.value.splice(targetIndex, 1)
124
+ if (props.outerIndex !== undefined)
125
+ emit('updateFileList', imageList.value.filter(item => item.status === 'done'), props.outerIndex)
126
+ else
127
+ emit('updateFileList', imageList.value.filter(item => item.status === 'done'))
128
+ }
129
+ }
130
+ })
131
+ }
132
+ }
133
+ </script>
134
+
135
+ <template>
136
+ <div class="uploader-container">
137
+ <van-button
138
+ v-if="props.attr?.addOrEdit !== 'readonly'"
139
+ icon="photograph"
140
+ type="primary"
141
+ @click="triggerCamera"
142
+ >
143
+ 拍照
144
+ </van-button>
145
+
146
+ <van-uploader
147
+ v-model="imageList"
148
+ :show-upload="false"
149
+ :deletable="props.attr?.addOrEdit !== 'readonly' && props.authority === 'admin'"
150
+ :multiple="props.authority === 'admin'"
151
+ :preview-image="true"
152
+ :before-delete="props.attr?.addOrEdit !== 'readonly' && props.authority === 'admin' ? deleteFileFunction : undefined"
153
+ />
154
+ </div>
155
+ </template>
156
+
157
+ <style scoped lang="less">
158
+ .uploader-container {
159
+ display: flex;
160
+ flex-direction: column;
161
+ gap: 16px;
162
+ }
163
+ </style>
@@ -2,6 +2,7 @@
2
2
  import XBadge from '@af-mobile-client-vue3/components/data/XBadge/index.vue'
3
3
  import XCellListFilter from '@af-mobile-client-vue3/components/data/XCellListFilter/index.vue'
4
4
  import { getConfigByName, query } from '@af-mobile-client-vue3/services/api/common'
5
+ import { getRangeByType } from '@af-mobile-client-vue3/utils/queryFormDefaultRangePicker'
5
6
  import LoadError from '@af-mobile-client-vue3/views/common/LoadError.vue'
6
7
  import {
7
8
  showConfirmDialog,
@@ -108,8 +109,12 @@ const finishedText = ref('加载完成')
108
109
  // 避免查询多次
109
110
  const isLastPage = ref(false)
110
111
 
112
+ // 条件参数(查询框)
111
113
  const conditionParams = ref(undefined)
112
114
 
115
+ // 查询参数(配置自带的默认值)
116
+ const queryDefaultParams = ref({})
117
+
113
118
  // 主要按钮的状态
114
119
  const buttonState = ref(undefined)
115
120
 
@@ -178,9 +183,47 @@ function initComponent() {
178
183
  allActions.value.push({ text: '删除', func: 'deleteRow' })
179
184
  }
180
185
  splitArrayAt(allActions.value, 3)
186
+
187
+ // 初始化条件参数(从表单默认值中获取)
188
+ initConditionParams(result.formJson)
181
189
  }, serviceName)
182
190
  }
183
191
 
192
+ // 初始化条件参数
193
+ function initConditionParams(formItems) {
194
+ if (!formItems || !Array.isArray(formItems) || formItems.length === 0)
195
+ return
196
+
197
+ const defaultParams = {}
198
+ let hasDefaults = false
199
+
200
+ // 从表单配置中获取所有默认值
201
+ formItems.forEach((item) => {
202
+ if (item.model) {
203
+ // 根据查询模式获取对应的默认值
204
+ if (item.queryFormDefault !== undefined && item.queryFormDefault !== null) {
205
+ if (item.type === 'rangePicker' && item.queryType === 'BETWEEN') {
206
+ defaultParams[item.model] = getRangeByType(item.queryFormDefault, false)
207
+ }
208
+ else {
209
+ defaultParams[item.model] = item.queryFormDefault
210
+ }
211
+ hasDefaults = true
212
+ }
213
+ }
214
+ })
215
+
216
+ // 如果有默认值,则设置到条件参数中并立即执行查询
217
+ if (hasDefaults) {
218
+ queryDefaultParams.value = defaultParams
219
+
220
+ // 延迟执行第一次查询,确保组件完全加载
221
+ setTimeout(() => {
222
+ onRefresh()
223
+ }, 100)
224
+ }
225
+ }
226
+
184
227
  // 刷新数据
185
228
  function onRefresh() {
186
229
  isError.value = false
@@ -197,6 +240,8 @@ function onRefresh() {
197
240
 
198
241
  // 加载数据
199
242
  function onLoad() {
243
+ if (!refreshing.value)
244
+ return
200
245
  if (refreshing.value) {
201
246
  list.value = []
202
247
  pageNo.value = 1
@@ -206,6 +251,23 @@ function onLoad() {
206
251
  let searchVal = searchValue.value
207
252
  if (searchVal === '')
208
253
  searchVal = undefined
254
+
255
+ // 确保conditionParams不是undefined
256
+ if (conditionParams.value === undefined)
257
+ conditionParams.value = {}
258
+ const mergedParams = mergeParams(queryDefaultParams.value, conditionParams.value)
259
+
260
+ // 输出查询条件,便于调试
261
+ console.log('查询条件:', {
262
+ pageNo: pageNo.value,
263
+ pageSize,
264
+ conditionParams: {
265
+ $queryValue: searchVal,
266
+ ...fixQueryForm,
267
+ ...mergedParams,
268
+ },
269
+ })
270
+
209
271
  query({
210
272
  queryParamsName: configName,
211
273
  pageNo: pageNo.value,
@@ -213,7 +275,7 @@ function onLoad() {
213
275
  conditionParams: {
214
276
  $queryValue: searchVal,
215
277
  ...fixQueryForm,
216
- ...conditionParams.value,
278
+ ...mergedParams,
217
279
  },
218
280
  sortField: orderVal?.value,
219
281
  sortOrder: sortordVal?.value,
@@ -240,6 +302,18 @@ function onLoad() {
240
302
  }
241
303
  }
242
304
 
305
+ // 合并参数
306
+ function mergeParams(defaultParams: object, overrideParams: object) {
307
+ const result = { ...defaultParams }
308
+ for (const [key, value] of Object.entries(overrideParams)) {
309
+ // 只有当overrideParams中的值不是undefined或空字符串时才覆盖
310
+ if (value !== undefined) {
311
+ result[key] = value
312
+ }
313
+ }
314
+ return result
315
+ }
316
+
243
317
  // 区分主要操作列与其他操作列
244
318
  function splitArrayAt<T>(array: T[], index: number) {
245
319
  mainActions.value = array.slice(0, index)
@@ -11,6 +11,7 @@ import { runLogic } from '@af-mobile-client-vue3/services/api/common'
11
11
  import { searchToListOption, searchToOption } from '@af-mobile-client-vue3/services/v3Api'
12
12
  import { useUserStore } from '@af-mobile-client-vue3/stores/modules/user'
13
13
  import { getDict } from '@af-mobile-client-vue3/utils/dictUtil'
14
+ import { getRangeByType } from '@af-mobile-client-vue3/utils/queryFormDefaultRangePicker'
14
15
  import { executeStrFunctionByContext } from '@af-mobile-client-vue3/utils/runEvalFunction'
15
16
  import { areaList } from '@vant/area-data'
16
17
  import { debounce } from 'lodash-es'
@@ -187,7 +188,7 @@ function getDefaultValue() {
187
188
  if (props.modelValue && Array.isArray(props.modelValue) && props.modelValue.length > 1)
188
189
  return `${props.modelValue[0]} ~ ${props.modelValue[1]}`
189
190
  else
190
- return props.modelValue
191
+ return props.modelValue !== undefined ? props.modelValue : querySelectDefaultValue.value
191
192
  case 'addressSearch':
192
193
  return props.modelValue
193
194
  default:
@@ -205,9 +206,14 @@ watch(() => props.modelValue, (newVal) => {
205
206
  localValue.value = Array.isArray(newVal) ? newVal : []
206
207
  }
207
208
  else {
208
- localValue.value = newVal !== undefined ? newVal : getDefaultValue()
209
209
  if (attr.type === 'rangePicker') {
210
- pickerValue.value = newVal !== undefined ? `${newVal[0]} ~ ${newVal[1]}` : ''
210
+ console.log('newVal', newVal)
211
+ pickerValue.value = newVal !== undefined ? `${newVal[0]} ~ ${newVal[1]}` : getDefaultValue()
212
+ console.log('11111111111', getDefaultValue())
213
+ }
214
+ else {
215
+ console.log('newVal', newVal)
216
+ localValue.value = newVal !== undefined ? newVal : getDefaultValue()
211
217
  }
212
218
  }
213
219
  })
@@ -459,6 +465,16 @@ function init() {
459
465
  // querySelectDefaultValue.value = attr.queryFormDefault
460
466
  }
461
467
  }
468
+
469
+ if (attr.type === 'rangePicker') {
470
+ if (attr.formDefault)
471
+ formSelectDefaultValue.value = attr.formDefault
472
+ if (attr.queryFormDefault) {
473
+ const dateArray = getRangeByType(attr.queryFormDefault, true)
474
+ pickerValue.value = `${dateArray[0]} ~ ${dateArray[1]}`
475
+ querySelectDefaultValue.value = pickerValue.value
476
+ }
477
+ }
462
478
  }
463
479
 
464
480
  function getDataCallback(res) {