t20-common-lib 0.9.9 → 0.9.11

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,6 +1,6 @@
1
1
  {
2
2
  "name": "t20-common-lib",
3
- "version": "0.9.9",
3
+ "version": "0.9.11",
4
4
  "description": "T20",
5
5
  "private": false,
6
6
  "main": "dist/index.js",
@@ -29,8 +29,24 @@
29
29
  <div class="content-item-title">{{ conItem.title }}
30
30
  <i v-if="conItem.tips" v-title="conItem.tips" class="n20-icon-xinxitishi"></i>
31
31
  </div>
32
- <div v-if="conItem.amountFormat" class="content-item-val" @click="$emit('click', conItem)">{{ conItem.value | cardFormatAmount('value') }}<span class="content-item-unit">{{ conItem.value | cardFormatAmount('unit') }}</span></div>
33
- <div v-else class="content-item-val" @click="$emit('click', conItem)">{{ conItem.value }}<span class="content-item-unit">{{ conItem.unit }}</span></div>
32
+ <!-- 支持三种情况:
33
+ 1) 同时存在金额和笔数(优先使用 conItem.amount,如无则使用 conItem.value -> 在一行显示:金额(格式化) / 笔数(单位)
34
+ 2) 只有金额(conItem.amountFormat 为 true 或 amount/value 为数字) -> 使用过滤器格式化
35
+ 3) 只有普通值 -> 直接显示 value + unit
36
+ -->
37
+ <div class="content-item-val" @click="$emit('click', conItem)">
38
+ <template v-if="hasAmountAndCount(conItem)">
39
+ {{ formatAmount(conItem, 'value') }}<span class="content-item-unit">{{ formatAmount(conItem, 'unit') }}</span>
40
+ <span class="divider-inline"></span>
41
+ <span class="count-val">{{ conItem.count }}<span class="content-item-unit">{{ conItem.countUnit || conItem.unit || '笔' }}</span></span>
42
+ </template>
43
+ <template v-else-if="conItem.amountFormat">
44
+ {{ formatAmount(conItem, 'value') }}<span class="content-item-unit">{{ formatAmount(conItem, 'unit') }}</span>
45
+ </template>
46
+ <template v-else>
47
+ {{ conItem.value }}<span class="content-item-unit">{{ conItem.unit }}</span>
48
+ </template>
49
+ </div>
34
50
  </div>
35
51
  <div
36
52
  v-if="index !== item.subList.length - 1"
@@ -113,6 +129,40 @@ export default {
113
129
  return '';
114
130
  }
115
131
  }
132
+ ,
133
+ /**
134
+ * 判断是否同时包含金额和笔数
135
+ * 支持两种字段表示:优先使用 item.amount,其次使用 item.value
136
+ */
137
+ hasAmountAndCount(item) {
138
+ if (!item) return false;
139
+ const amount = item.amount !== undefined && item.amount !== null ? item.amount : item.value;
140
+ // amount 必须是数字(或能被转为数字),count 存在(0 也认为有效)
141
+ const hasAmount = amount !== undefined && amount !== null && !isNaN(Number(amount));
142
+ const hasCount = item.count !== undefined && item.count !== null;
143
+ return hasAmount && hasCount;
144
+ },
145
+ /**
146
+ * 统一走过滤器来格式化金额/单位(保持与现有过滤器行为一致)
147
+ */
148
+ formatAmount(item, type = 'value') {
149
+ const amount = item.amount !== undefined && item.amount !== null ? item.amount : item.value;
150
+ // 通过 this.$options.filters 调用组件内定义的过滤器
151
+ // 如果是请求单位并且调用方显式传了 unit 且标记了 amountFormat,优先返回该 unit(恢复原先逻辑)
152
+ if (type === 'unit' && item && item.amountFormat && item.unit) {
153
+ return item.unit;
154
+ }
155
+
156
+ if (this.$options && this.$options.filters && typeof this.$options.filters.cardFormatAmount === 'function') {
157
+ try {
158
+ return this.$options.filters.cardFormatAmount(amount, type);
159
+ } catch (e) {
160
+ // 兜底返回原值或空字符串
161
+ return type === 'value' ? amount : '';
162
+ }
163
+ }
164
+ return type === 'value' ? amount : '';
165
+ }
116
166
  }
117
167
  }
118
168
  </script>
@@ -170,6 +220,15 @@ export default {
170
220
  font-size: 20px;
171
221
  text-align: center;
172
222
  }
223
+
224
+ .divider-inline {
225
+ margin: 0 6px;
226
+ color: rgba(255,255,255,0.9);
227
+ }
228
+
229
+ .count-val {
230
+ font-size: 20px;
231
+ }
173
232
 
174
233
  &-unit {
175
234
  font-size: 14px;