af-mobile-client-vue3 1.3.66 → 1.3.68

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.3.66",
4
+ "version": "1.3.68",
5
5
  "packageManager": "pnpm@10.13.1",
6
6
  "description": "Vue + Vite component lib",
7
7
  "engines": {
@@ -195,7 +195,7 @@ function handlePhotoUpload(photoData: any) {
195
195
  if (index !== -1) {
196
196
  delete imageList.value[index].message
197
197
  imageList.value[index].status = 'done'
198
- imageList.value[index].pthotoName = photoData.name
198
+ imageList.value[index].photo_name = photoData.name
199
199
  imageList.value[index].type = mimeType
200
200
  }
201
201
  else {
@@ -210,7 +210,7 @@ function handlePhotoUpload(photoData: any) {
210
210
 
211
211
  const doneIds = Object.values(imageList.value)
212
212
  .filter(item => item.status === 'done')
213
- .map(item => item.pthotoName)
213
+ .map(item => item.photo_name)
214
214
 
215
215
  if (props.outerIndex !== undefined)
216
216
  emit('updateFileList', doneIds, props.outerIndex)
@@ -273,7 +273,7 @@ function deleteFileFunction(file: any) {
273
273
  if (props.isAsyncUpload) {
274
274
  doneIds.value = Object.values(imageList.value)
275
275
  .filter(item => item.status === 'done')
276
- .map(item => item.pthotoName)
276
+ .map(item => item.photo_name)
277
277
  }
278
278
  else {
279
279
  doneIds.value = Object.values(imageList.value)
@@ -300,7 +300,7 @@ function deleteFileFunction(file: any) {
300
300
  if (props.isAsyncUpload) {
301
301
  doneIds.value = Object.values(imageList.value)
302
302
  .filter(item => item.status === 'done')
303
- .map(item => item.pthotoName)
303
+ .map(item => item.photo_name)
304
304
  }
305
305
  else {
306
306
  doneIds.value = Object.values(imageList.value)
@@ -1,11 +1,14 @@
1
1
  <script setup lang="ts">
2
2
  import { getDictItemByValue } from '@af-mobile-client-vue3/utils/dictUtil'
3
+ import dayjs from 'dayjs/esm/index'
3
4
  import { ref } from 'vue'
4
5
 
5
- const { serviceName, dictName, dictValue } = defineProps<{
6
+ const { serviceName, dictName, dictValue, dictType } = defineProps<{
6
7
  serviceName: string
7
8
  dictName: string | null | undefined
8
- dictValue: string | null | undefined
9
+ dictValue: string | number | null | undefined
10
+ // 用于非字典型的格式化展示:如日期/小数/整数等
11
+ dictType?: 'date' | 'dateTime' | 'towDecimal' | 'fourDecimal' | 'int' | string
9
12
  }>()
10
13
 
11
14
  // 字面值
@@ -18,23 +21,86 @@ initComponent()
18
21
 
19
22
  // 组件初始化
20
23
  function initComponent() {
21
- if (dictValue === null || dictValue === undefined) {
24
+ if (dictValue === null || dictValue === undefined || dictValue === '') {
22
25
  label.value = '--'
26
+ className.value = ''
23
27
  return
24
28
  }
25
- if (!dictName || dictName === '') {
26
- label.value = dictValue.toString()
29
+
30
+ // 1) 优先使用字典映射
31
+ if (dictName && dictName !== '') {
32
+ getDictItemByValue(dictName, serviceName, String(dictValue), (result) => {
33
+ if (result == null) {
34
+ // 字典未命中,退回到格式化/原值
35
+ applyFormatFallback()
36
+ }
37
+ else {
38
+ label.value = result.label
39
+ className.value = `badge-${result.status}`
40
+ }
41
+ })
27
42
  return
28
43
  }
29
- getDictItemByValue(dictName, serviceName, dictValue, (result) => {
30
- if (result == null) {
31
- label.value = dictValue.toString()
32
- }
33
- else {
34
- label.value = result.label
35
- className.value = `badge-${result.status}`
36
- }
37
- })
44
+
45
+ // 2) 无字典名时,按 dictType 做格式化
46
+ applyFormatFallback()
47
+ }
48
+
49
+ function applyFormatFallback() {
50
+ className.value = ''
51
+ if (!dictType || dictType === '') {
52
+ label.value = String(dictValue)
53
+ return
54
+ }
55
+ switch (dictType) {
56
+ case 'date':
57
+ label.value = formatDateLike(dictValue, 'YYYY-MM-DD')
58
+ break
59
+ case 'dateTime':
60
+ label.value = formatDateLike(dictValue, 'YYYY-MM-DD HH:mm:ss')
61
+ break
62
+ case 'towDecimal':
63
+ label.value = formatNumberLike(dictValue, 2)
64
+ break
65
+ case 'fourDecimal':
66
+ label.value = formatNumberLike(dictValue, 4)
67
+ break
68
+ case 'int':
69
+ label.value = formatNumberLike(dictValue, 0)
70
+ break
71
+ default:
72
+ label.value = String(dictValue)
73
+ break
74
+ }
75
+ }
76
+
77
+ function pad2(num: number): string {
78
+ return String(num).padStart(2, '0')
79
+ }
80
+
81
+ function formatDateLike(val: string | number, pattern: string): string {
82
+ // 1️⃣ 先判断时间是否合法
83
+ const date = dayjs(val)
84
+ if (!date.isValid()) {
85
+ console.warn('时间字符串不合法:', val)
86
+ return val as string
87
+ }
88
+
89
+ // 2️⃣ 判断格式字符串是否有效(简单校验,格式字符串非空)
90
+ if (!pattern || typeof pattern !== 'string') {
91
+ console.warn('格式字符串不合法:', pattern)
92
+ return val as string
93
+ }
94
+
95
+ // 3️⃣ 使用 dayjs 格式化
96
+ return date.format(pattern)
97
+ }
98
+
99
+ function formatNumberLike(val: string | number, digits: number): string {
100
+ const num = typeof val === 'number' ? val : Number(val)
101
+ if (Number.isNaN(num))
102
+ return String(val)
103
+ return num.toFixed(digits)
38
104
  }
39
105
  </script>
40
106
 
@@ -841,7 +841,13 @@ function handleCheckboxChange(item: any, checked: boolean) {
841
841
  :class="{ 'selectable-title': isMultiSelectMode }"
842
842
  @click="handleTitleClick(item, $event)"
843
843
  >
844
- {{ item[column.dataIndex] ?? '--' }}
844
+ <XBadge
845
+ :style="handleFunctionStyle(column.styleFunctionForValue, item)"
846
+ :dict-name="column.dictName"
847
+ :dict-value="item[column.dataIndex]"
848
+ :dict-type="column.slotType"
849
+ :service-name="serviceName"
850
+ />
845
851
  </p>
846
852
  </div>
847
853
  <div v-for="(column) in subTitleColumns" :key="`subtitle_${column.dataIndex}`" class="sub-title">
@@ -851,7 +857,9 @@ function handleCheckboxChange(item: any, checked: boolean) {
851
857
  >
852
858
  <XBadge
853
859
  :style="handleFunctionStyle(column.styleFunctionForValue, item)"
854
- :dict-name="column.dictName" :dict-value="item[column.dataIndex]"
860
+ :dict-name="column.dictName"
861
+ :dict-value="item[column.dataIndex]"
862
+ :dict-type="column.slotType"
855
863
  :service-name="serviceName"
856
864
  />
857
865
  </p>
@@ -876,7 +884,9 @@ function handleCheckboxChange(item: any, checked: boolean) {
876
884
  {{ (column.showLabel === undefined || column.showLabel) ? `${column.title}: ` : '' }}
877
885
  <XBadge
878
886
  :style="handleFunctionStyle(column.styleFunctionForValue, item)"
879
- :dict-name="column.dictName" :dict-value="item[column.dataIndex]"
887
+ :dict-name="column.dictName"
888
+ :dict-value="item[column.dataIndex]"
889
+ :dict-type="column.slotType"
880
890
  :service-name="serviceName"
881
891
  />
882
892
  </p>
@@ -924,7 +934,9 @@ function handleCheckboxChange(item: any, checked: boolean) {
924
934
  </span>
925
935
  <XBadge
926
936
  :style="handleFunctionStyle(column.styleFunctionForValue, item)"
927
- :dict-name="column.dictName" :dict-value="item[column.dataIndex]"
937
+ :dict-name="column.dictName"
938
+ :dict-value="item[column.dataIndex]"
939
+ :dict-type="column.slotType"
928
940
  :service-name="serviceName"
929
941
  />
930
942
  </p>
@@ -426,8 +426,8 @@ function updateFile(files, _index) {
426
426
  function formTypeCheck(attr, value) {
427
427
  if (mode === '查询')
428
428
  return
429
- if (!attr.rule || !attr.rule.required || attr.rule.required === 'false')
430
- return
429
+ // if (!attr.rule || !attr.rule.required || attr.rule.required === 'false')
430
+ // return
431
431
  switch (attr.rule.type) {
432
432
  case 'string':
433
433
  if (value.length === 0) {