wangzhibo
4 天以前 10595d8632f959d0954d1939243196f4eed02372
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
76
77
78
79
<template>
    <view
        class="cl-row"
        :class="[
            `cl-row--${type}`,
            `is-justify-${justify}`,
            `is-align-${align}`,
            {
                'is-wrap': wrap,
            },
        ]"
        :style="[
            baseStyle,
            {
                height: parseRpx(height),
                width: parseRpx(width),
                margin,
                border,
            },
        ]"
        @click="tap"
    >
        <slot></slot>
    </view>
</template>
 
<script lang="ts">
import { computed, defineComponent, type PropType } from "vue";
import { useStyle, useTap } from "../../hooks";
import { parseRpx } from "/@/cool/utils";
 
export default defineComponent({
    name: "cl-row",
 
    props: {
        // 类型
        type: String,
        // 是否换行
        wrap: Boolean,
        // 带边框
        border: String,
        // 列间距
        gutter: {
            type: Number,
            default: 0,
        },
        // 高度
        height: [String, Number],
        // 宽度
        width: [String, Number],
        // 外间距
        margin: [String, Number, Array],
        // 水平对齐
        justify: {
            type: String as PropType<"start" | "center" | "end" | "space-between" | "space-around">,
            default: "start",
        },
        // 垂直对齐
        align: {
            type: String as PropType<"top" | "center" | "bottom">,
            default: "center",
        },
    },
 
    setup(props, { emit }) {
        const { tap } = useTap(emit);
 
        const margin = computed(() => {
            return props.margin ? parseRpx(props.margin) : `0 -${props.gutter / 2}rpx`;
        });
 
        return {
            margin,
            tap,
            ...useStyle(),
        };
    },
});
</script>