CNCEC_APP/uni_modules/uview-pro/components/u-row/u-row.vue

106 lines
2.4 KiB
Vue
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.

<template>
<view
class="u-row"
:style="
$u.toStyle(
{
alignItems: uAlignItem,
justifyContent: uJustify
},
customStyle
)
"
@tap="onClick"
>
<slot />
</view>
</template>
<script lang="ts">
export default {
name: 'u-row',
options: {
addGlobalClass: true,
// #ifndef MP-TOUTIAO
virtualHost: true,
// #endif
styleIsolation: 'shared'
}
};
</script>
<script setup lang="ts">
import { computed } from 'vue';
import { RowProps } from './types';
import { $u, useParent } from '../../';
/**
* row 行布局
* @description 通过基础的 12 分栏,迅速简便地创建布局。
* @tutorial https://uviewpro.cn/zh/components/layout.html#row-props
* @property {String|Number} gutter 栅格间隔左右各为此值的一半单位rpx默认0
* @property {String} justify 水平排列方式(微信小程序暂不支持)默认start(或flex-start)
* @property {String} align 垂直排列方式默认center
* @example <u-row gutter="16"></u-row>
*/
const emit = defineEmits<{ (e: 'click'): void }>();
const props = defineProps(RowProps);
useParent('u-row');
/**
* 计算水平排列方式
* @returns {string}
*/
const uJustify = computed(() => {
if (props.justify === 'end' || props.justify === 'start') return 'flex-' + props.justify;
else if (props.justify === 'around' || props.justify === 'between') return 'space-' + props.justify;
else return props.justify;
});
/**
* 计算垂直对齐方式
* @returns {string}
*/
const uAlignItem = computed(() => {
if (props.align === 'top') return 'flex-start';
if (props.align === 'bottom') return 'flex-end';
else return props.align;
});
/**
* 点击事件
* @param e 事件对象
*/
function onClick(e: Event) {
// 触发 click 事件
emit('click');
}
defineExpose({
props
});
</script>
<style lang="scss">
@import '../../libs/css/style.components.scss';
.u-row {
// 由于微信小程序编译后奇怪的页面结构只能使用float布局实现flex无法实现
/* #ifndef MP-WEIXIN || MP-QQ || MP-TOUTIAO */
@include vue-flex;
/* #endif */
flex-wrap: wrap;
}
.u-row:after {
/* #ifdef MP-WEIXIN || MP-QQ || MP-TOUTIAO */
display: table;
clear: both;
content: '';
/* #endif */
}
</style>