240 行
7.5 KiB
Plaintext
240 行
7.5 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>flex-direction: row</text>
|
||
<view class="demo-box">
|
||
<view class="common" style="flex-direction: row">
|
||
<view class="flex-item red"></view>
|
||
<view class="flex-item green"></view>
|
||
<view class="flex-item blue"></view>
|
||
</view>
|
||
<view class="common" style="flex-direction: row" flatten>
|
||
<view class="flex-item red"></view>
|
||
<view class="flex-item green"></view>
|
||
<view class="flex-item blue"></view>
|
||
</view>
|
||
</view>
|
||
</view>
|
||
|
||
<view>
|
||
<text>flex-direction: row-reverse</text>
|
||
<view class="demo-box">
|
||
<view class="common" style="flex-direction: row-reverse">
|
||
<view class="flex-item red"></view>
|
||
<view class="flex-item green"></view>
|
||
<view class="flex-item blue"></view>
|
||
</view>
|
||
<view class="common" style="flex-direction: row-reverse" flatten>
|
||
<view class="flex-item red"></view>
|
||
<view class="flex-item green"></view>
|
||
<view class="flex-item blue"></view>
|
||
</view>
|
||
</view>
|
||
</view>
|
||
|
||
<view>
|
||
<text>flex-direction: column</text>
|
||
<view class="demo-box">
|
||
<view class="common" style="flex-direction: column">
|
||
<view class="flex-item red"></view>
|
||
<view class="flex-item green"></view>
|
||
<view class="flex-item blue"></view>
|
||
</view>
|
||
<view class="common" style="flex-direction: column" flatten>
|
||
<view class="flex-item red"></view>
|
||
<view class="flex-item green"></view>
|
||
<view class="flex-item blue"></view>
|
||
</view>
|
||
</view>
|
||
</view>
|
||
|
||
<view>
|
||
<text>flex-direction: column-reverse</text>
|
||
<view class="demo-box">
|
||
<view class="common" style="flex-direction: column-reverse">
|
||
<view class="flex-item red"></view>
|
||
<view class="flex-item green"></view>
|
||
<view class="flex-item blue"></view>
|
||
</view>
|
||
<view class="common" style="flex-direction: column-reverse" flatten>
|
||
<view class="flex-item red"></view>
|
||
<view class="flex-item green"></view>
|
||
<view class="flex-item blue"></view>
|
||
</view>
|
||
</view>
|
||
</view>
|
||
|
||
<view class="uni-common-mt">
|
||
<text class="uni-title-text">scroll-view 组件</text>
|
||
</view>
|
||
|
||
<view>
|
||
<text class="uni-subtitle-text">flex-direction:row 和 column</text>
|
||
<view class="demo-box">
|
||
<scroll-view class="common" style="flex-direction: row;" 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="flex-direction: column;" 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">flex-direction</text>
|
||
<text class="uni-info">设置值: {{data.flexDirection}}</text>
|
||
<text class="uni-info">获取值: {{data.flexDirectionActual}}</text>
|
||
<view class="test-box">
|
||
<view ref="viewRef" class="test-flex-container test-view" :style="{ flexDirection: data.flexDirection }">
|
||
<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.flexDirection}}</text>
|
||
<text class="uni-info">获取值: {{data.flexDirectionActualFlat}}</text>
|
||
<view class="test-box">
|
||
<view ref="viewRefFlat" class="test-flex-container test-view-flatten" :style="{ flexDirection: data.flexDirection }" 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="flexDirectionEnum" title="flex-direction 枚举值" @change="radioChangeFlexDirection" :compact="true"></enum-data>
|
||
<input-data :defaultValue="data.flexDirection" title="flex-direction 自定义值" type="text" @confirm="inputChangeFlexDirection"></input-data>
|
||
</view>
|
||
</view>
|
||
<!-- #ifdef APP && !VUE3-VAPOR -->
|
||
</scroll-view>
|
||
<!-- #endif -->
|
||
</template>
|
||
|
||
<script setup lang="uts">
|
||
import { ItemType } from '@/components/enum-data/enum-data-types'
|
||
|
||
const flexDirectionEnum: ItemType[] = [
|
||
{ value: 0, name: '' },
|
||
{ value: 1, name: 'row' },
|
||
{ value: 2, name: 'row-reverse' },
|
||
{ value: 3, name: 'column' },
|
||
{ value: 4, name: 'column-reverse' }
|
||
]
|
||
|
||
const data = reactive({
|
||
flexDirection: 'row',
|
||
flexDirectionActual: '',
|
||
flexDirectionActualFlat: ''
|
||
})
|
||
const viewRef = ref(null as UniElement | null)
|
||
const viewRefFlat = ref(null as UniElement | null)
|
||
|
||
const getPropertyValues = () => {
|
||
data.flexDirectionActual = viewRef.value?.style.getPropertyValue('flex-direction') ?? ''
|
||
data.flexDirectionActualFlat = viewRefFlat.value?.style.getPropertyValue('flex-direction') ?? ''
|
||
}
|
||
|
||
const changeFlexDirection = (value: string) => {
|
||
data.flexDirection = value
|
||
viewRef.value?.style.setProperty('flex-direction', value)
|
||
viewRefFlat.value?.style.setProperty('flex-direction', value)
|
||
// 使用 nextTick 确保样式已应用后再获取值
|
||
nextTick(() => {
|
||
getPropertyValues()
|
||
})
|
||
}
|
||
|
||
const radioChangeFlexDirection = (index: number) => {
|
||
const selectedItem = flexDirectionEnum.find((item): boolean => item.value === index)
|
||
if (selectedItem != null) {
|
||
changeFlexDirection(selectedItem.name)
|
||
}
|
||
}
|
||
|
||
const inputChangeFlexDirection = (value: string) => {
|
||
changeFlexDirection(value)
|
||
}
|
||
|
||
onReady(() => {
|
||
getPropertyValues()
|
||
})
|
||
|
||
defineExpose({
|
||
radioChangeFlexDirection,
|
||
data
|
||
})
|
||
</script>
|
||
|
||
<style>
|
||
.demo-box {
|
||
flex-direction: row;
|
||
margin-top: 10px;
|
||
justify-content: space-around;
|
||
}
|
||
|
||
.flex-item {
|
||
width: 40px;
|
||
height: 40px;
|
||
}
|
||
.red {
|
||
background-color: red;
|
||
}
|
||
.green {
|
||
background-color: green;
|
||
}
|
||
.blue {
|
||
background-color: blue;
|
||
}
|
||
.common {
|
||
flex: 1;
|
||
margin: 0 10px;
|
||
height: 220px;
|
||
background-color: gray;
|
||
}
|
||
.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;
|
||
}
|
||
|
||
.test-item-small {
|
||
width: 30px;
|
||
height: 30px;
|
||
}
|
||
</style>
|