WebApp【公共组件库】@前端(For Git Submodule)
Tevin
2023-04-10 b33f28d69b4c26bb8b0415be0bca4fc69a0f6fac
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/**
 * CNumerical - 数值显示
 * @author Tevin
 */
 
<template>
    <view class="c-numerical at-row at-row--wrap">
        <view
            class="at-col"
            v-for="(item,index) in values2"
            :key="index"
            :class="'at-col-' + valueFlex[index]"
        >
            <view class="c-numerical-value">
                <text :class="item.textType?('m-text-'+item.textType):''">{{item.integer}}</text>
                <text
                    class="c-numerical-decimal"
                    :class="item.integer.length>6?'small':''"
                    v-if="item.decimal.length>0"
                >.{{item.decimal}}</text>
            </view>
            <view class="c-numerical-title">{{item.title}}</view>
        </view>
    </view>
</template>
 
<script>
import Taro from '@tarojs/taro';
import {} from 'taro-ui-vue';
import './cNumerical.scss';
 
export default {
    name: 'CNumerical',
    components: {},
    props: {
        // 数值集合,格式为:[{title, value, textType}]
        values: Array,
    },
    computed: {
        values2() {
            return (
                this.values.map(item => ({
                    ...item,
                    integer: (item.value + '').split('.')[0] || '',
                    decimal: (item.value + '').split('.')[1] || '',
                })) || []
            );
        },
        valueFlex() {
            return this.values.map((item, index) => {
                const surplus = this.values.length % 3;
                if (surplus === 0) {
                    return 4;
                } else if (surplus === 1) {
                    if (index === this.values.length - 1) {
                        return 12;
                    } else {
                        return 4;
                    }
                } else if (surplus === 2) {
                    if (index >= this.values.length - 2) {
                        return 6;
                    } else {
                        return 4;
                    }
                }
            });
        },
    },
    data() {
        return {};
    },
    methods: {},
};
</script>