Files
Neo-ZQYY/apps/miniprogram - 副本/miniprogram/components/metric-card/metric-card.ts

68 lines
1.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
Component({
properties: {
/** 指标名称 */
title: {
type: String,
value: '',
},
/** 指标数值(已格式化字符串) */
value: {
type: String,
value: null,
},
/** 单位(元/次/人) */
unit: {
type: String,
value: '',
},
/** 环比趋势 */
trend: {
type: String,
value: 'flat', // 'up' | 'down' | 'flat'
},
/** 环比数值(如 "+12.5%" */
trendValue: {
type: String,
value: '',
},
/** 帮助说明文字 */
helpText: {
type: String,
value: '',
},
},
observers: {
value(val: string | null | undefined) {
// null/undefined 显示 "--"
this.setData({
displayValue: val == null || val === '' ? '--' : val,
})
},
},
data: {
displayValue: '--',
},
lifetimes: {
attached() {
const val = this.data.value
this.setData({
displayValue: val == null || val === '' ? '--' : val,
})
},
},
methods: {
onTap() {
this.triggerEvent('tap')
},
onHelpTap(e: WechatMiniprogram.TouchEvent) {
// 阻止冒泡到卡片 tap
e.stopPropagation?.()
this.triggerEvent('helpTap')
},
},
})