123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- Component({
- externalClasses: ['l-class', 'l-class-self', 'l-self-class'],
- properties: {
- // 红点模式
- dot: {
- type: Boolean,
- value: false
- },
- shape: {
- type: String,
- value: 'horn'
- },
- value: {
- type: String,
- value: '0'
- },
- mode: {
- type: String,
- value: 'number'
- },
- // 数字最大值
- maxCount: {
- type: Number,
- value: 99
- },
- // 数字形式
- numberType: {
- type: String,
- value: 'overflow'
- },
- show: {
- type: Boolean,
- value: true
- }
- },
- data: {
- finalCount: 0
- },
- observers: {
- 'value': function () {
- this.finalCount();
- }
- },
- methods: {
- // 最终数字
- finalCount() {
- if (isNaN(Number(this.data.value)) || (this.data.mode === 'text')) {
- this.setData({
- finalCount: this.data.value
- });
- } else {
- this.switchType();
- }
- },
- switchType() {
- switch (this.data.numberType) {
- case 'overflow':
- this.setData({
- finalCount: Number(this.data.value) > Number(this.data.maxCount) ? `${this.data.maxCount}+` : this.data.value
- });
- break;
- case 'ellipsis':
- this.setData({
- finalCount: Number(this.data.value) > Number(this.data.maxCount) ? `...` : this.data.value
- });
- break;
- case 'limit':
- this.setData({
- finalCount: Number(this.data.value) > 999 ? `${ Number.isInteger(this.data.value / 1000)? (this.data.value/1000) : (this.data.value/1000).toFixed(1) }k` : this.data.value
- });
- break;
- default:
- this.setData({
- finalCount: Number(this.data.value)
- });
- break;
- }
- },
- // 点击事件
- handleTap() {
- this.triggerEvent('lintap', {}, {
- bubbles: true,
- composed: true
- });
- },
- }
- });
|