271 行
8.3 KiB
Plaintext
271 行
8.3 KiB
Plaintext
<template>
|
|
<!-- #ifdef APP && !VUE3-VAPOR -->
|
|
<scroll-view style="flex: 1">
|
|
<!-- #endif -->
|
|
<view style="flex-grow: 1">
|
|
<text class="uni-tips">说明:左边是正常版本,右边是拍平版本</text>
|
|
<view>
|
|
<text>align-items: center</text>
|
|
<view class="demo-box">
|
|
<view class="common" style="align-items: center">
|
|
<view class="flex-item red"></view>
|
|
<view class="flex-item green"></view>
|
|
<view class="flex-item blue"></view>
|
|
</view>
|
|
<view class="common" style="align-items: center" flatten>
|
|
<view class="flex-item red"></view>
|
|
<view class="flex-item green"></view>
|
|
<view class="flex-item blue"></view>
|
|
</view>
|
|
</view>
|
|
</view>
|
|
|
|
<view>
|
|
<text>align-items: flex-start</text>
|
|
<view class="demo-box">
|
|
<view class="common" style="align-items: flex-start">
|
|
<view class="flex-item red"></view>
|
|
<view class="flex-item green"></view>
|
|
<view class="flex-item blue"></view>
|
|
</view>
|
|
<view class="common" style="align-items: flex-start" flatten>
|
|
<view class="flex-item red"></view>
|
|
<view class="flex-item green"></view>
|
|
<view class="flex-item blue"></view>
|
|
</view>
|
|
</view>
|
|
</view>
|
|
|
|
<view>
|
|
<text>align-items: flex-end</text>
|
|
<view class="demo-box">
|
|
<view class="common" style="align-items: flex-end">
|
|
<view class="flex-item red"></view>
|
|
<view class="flex-item green"></view>
|
|
<view class="flex-item blue"></view>
|
|
</view>
|
|
<view class="common" style="align-items: flex-end" flatten>
|
|
<view class="flex-item red"></view>
|
|
<view class="flex-item green"></view>
|
|
<view class="flex-item blue"></view>
|
|
</view>
|
|
</view>
|
|
</view>
|
|
|
|
<view>
|
|
<text>align-items: stretch</text>
|
|
<view class="demo-box">
|
|
<view class="common" style="align-items: stretch">
|
|
<view class="flex-item-stretch red"></view>
|
|
<view class="flex-item-stretch green"></view>
|
|
<view class="flex-item-stretch blue"></view>
|
|
</view>
|
|
<view class="common" style="align-items: stretch" flatten>
|
|
<view class="flex-item-stretch red"></view>
|
|
<view class="flex-item-stretch green"></view>
|
|
<view class="flex-item-stretch blue"></view>
|
|
</view>
|
|
</view>
|
|
</view>
|
|
</view>
|
|
|
|
<view>
|
|
<text>text组件 align-items: center</text>
|
|
<view class="demo-box">
|
|
<view class="common" style="align-items: center">
|
|
<text class="flex-item red">text1</text>
|
|
<text class="flex-item green">text2</text>
|
|
<text class="flex-item blue">text3</text>
|
|
</view>
|
|
<view class="common" style="align-items: center" flatten>
|
|
<text class="flex-item red">text1</text>
|
|
<text class="flex-item green">text2</text>
|
|
<text class="flex-item blue">text3</text>
|
|
</view>
|
|
</view>
|
|
</view>
|
|
|
|
<view class="uni-common-mt">
|
|
<text class="uni-title-text">scroll-view 组件</text>
|
|
</view>
|
|
|
|
<view>
|
|
<text class="uni-subtitle-text">align-items: center; 和 align-items: flex-start;</text>
|
|
<view class="demo-box">
|
|
<scroll-view class="common" style="align-items: center;" direction="horizontal">
|
|
<view class="flex-item red"></view>
|
|
<view class="flex-item green"></view>
|
|
<view class="flex-item blue"></view>
|
|
</scroll-view>
|
|
<scroll-view class="common" style="align-items: flex-start;" direction="horizontal">
|
|
<view class="flex-item red"></view>
|
|
<view class="flex-item green"></view>
|
|
<view class="flex-item blue"></view>
|
|
</scroll-view>
|
|
</view>
|
|
</view>
|
|
|
|
<view class="uni-common-mt">
|
|
<text class="uni-title-text">setProperty 设置与 getPropertyValue 获取</text>
|
|
</view>
|
|
|
|
<view class="common-box">
|
|
<!-- 普通版本 -->
|
|
<view class="uni-common-mt">
|
|
<text class="uni-title-text">align-items</text>
|
|
<text class="uni-info">设置值: {{data.alignItems}}</text>
|
|
<text class="uni-info">获取值: {{data.alignItemsActual}}</text>
|
|
<view class="test-box">
|
|
<view ref="viewRef" class="test-flex-container test-view" :style="{ alignItems: data.alignItems }">
|
|
<view class="test-item-small red"></view>
|
|
<view class="test-item-small green"></view>
|
|
<view class="test-item-small blue"></view>
|
|
</view>
|
|
</view>
|
|
</view>
|
|
|
|
<!-- 拍平版本 -->
|
|
<view class="uni-common-mt">
|
|
<text class="uni-title-text">拍平</text>
|
|
<text class="uni-info">设置值: {{data.alignItems}}</text>
|
|
<text class="uni-info">获取值: {{data.alignItemsActualFlat}}</text>
|
|
<view class="test-box">
|
|
<view ref="viewRefFlat" class="test-flex-container test-view-flatten" :style="{ alignItems: data.alignItems }" flatten>
|
|
<view class="test-item-small red"></view>
|
|
<view class="test-item-small green"></view>
|
|
<view class="test-item-small blue"></view>
|
|
</view>
|
|
</view>
|
|
</view>
|
|
</view>
|
|
|
|
<view class="uni-common-mt uni-common-mb">
|
|
<text class="uni-tips">第一个枚举值,'' (空字符串) - 空值情况</text>
|
|
<enum-data :items="alignItemsEnum" title="align-items 枚举值" @change="radioChangeAlignItems" :compact="true"></enum-data>
|
|
<input-data :defaultValue="data.alignItems" title="align-items 自定义值" type="text" @confirm="inputChangeAlignItems"></input-data>
|
|
</view>
|
|
<!-- #ifdef APP && !VUE3-VAPOR -->
|
|
</scroll-view>
|
|
<!-- #endif -->
|
|
</template>
|
|
|
|
<script setup lang="uts">
|
|
import { ItemType } from '@/components/enum-data/enum-data-types'
|
|
|
|
const alignItemsEnum: ItemType[] = [
|
|
{ value: 0, name: '' },
|
|
{ value: 1, name: 'flex-start' },
|
|
{ value: 2, name: 'flex-end' },
|
|
{ value: 3, name: 'center' },
|
|
{ value: 4, name: 'stretch' }
|
|
]
|
|
|
|
const data = reactive({
|
|
alignItems: 'center',
|
|
alignItemsActual: '',
|
|
alignItemsActualFlat: ''
|
|
})
|
|
const viewRef = ref(null as UniElement | null)
|
|
const viewRefFlat = ref(null as UniElement | null)
|
|
|
|
const getPropertyValues = () => {
|
|
data.alignItemsActual = viewRef.value?.style.getPropertyValue('align-items') ?? ''
|
|
data.alignItemsActualFlat = viewRefFlat.value?.style.getPropertyValue('align-items') ?? ''
|
|
}
|
|
|
|
const changeAlignItems = (value: string) => {
|
|
data.alignItems = value
|
|
viewRef.value?.style.setProperty('align-items', value)
|
|
viewRefFlat.value?.style.setProperty('align-items', value)
|
|
// 使用 nextTick 确保样式已应用后再获取值
|
|
nextTick(() => {
|
|
getPropertyValues()
|
|
})
|
|
}
|
|
|
|
const radioChangeAlignItems = (index: number) => {
|
|
const selectedItem = alignItemsEnum.find((item): boolean => item.value === index)
|
|
if (selectedItem != null) {
|
|
changeAlignItems(selectedItem.name)
|
|
}
|
|
}
|
|
|
|
const inputChangeAlignItems = (value: string) => {
|
|
changeAlignItems(value)
|
|
}
|
|
|
|
onReady(() => {
|
|
getPropertyValues()
|
|
})
|
|
|
|
defineExpose({
|
|
radioChangeAlignItems,
|
|
data
|
|
})
|
|
</script>
|
|
|
|
<style>
|
|
.demo-box {
|
|
flex-direction: row;
|
|
margin-top: 10px;
|
|
justify-content: space-around;
|
|
}
|
|
|
|
.flex-item {
|
|
width: 40px;
|
|
height: 40px;
|
|
}
|
|
|
|
.flex-item-stretch {
|
|
width: 40px;
|
|
}
|
|
.red {
|
|
background-color: red;
|
|
}
|
|
.green {
|
|
background-color: green;
|
|
}
|
|
.blue {
|
|
background-color: blue;
|
|
}
|
|
.common {
|
|
flex: 1;
|
|
margin: 0 10px;
|
|
height: 100px;
|
|
background-color: gray;
|
|
flex-direction: row;
|
|
}
|
|
|
|
.common-scroll {
|
|
flex: 1;
|
|
margin: 0 10px;
|
|
height: 100px;
|
|
background-color: gray;
|
|
flex-direction: row;
|
|
}
|
|
|
|
.common-box{
|
|
flex-direction: row;
|
|
justify-content: space-around;
|
|
}
|
|
|
|
.test-box {
|
|
width: 180px;
|
|
height: 150px;
|
|
background-color: gray;
|
|
}
|
|
|
|
|
|
.test-flex-container {
|
|
width: 100%;
|
|
height: 100%;
|
|
background-color: gray;
|
|
flex-direction: row;
|
|
}
|
|
|
|
.test-item-small {
|
|
width: 30px;
|
|
height: 30px;
|
|
}
|
|
</style>
|