refactor: 确立独立子工程架构 (backend, admin, mpuniapp) 并同步更新 AGENTS.md 规范
这个提交包含在:
@@ -0,0 +1,279 @@
|
||||
<template>
|
||||
<!-- #ifdef APP && !VUE3-VAPOR -->
|
||||
<scroll-view style="flex: 1">
|
||||
<!-- #endif -->
|
||||
<view style="flex-grow: 1;">
|
||||
<view class="uni-common-mb">
|
||||
<text class="uni-title-text">bottom: 20px (距离底部 20px) - 右侧:拍平</text>
|
||||
<view class="test-container">
|
||||
<view class="example-box">
|
||||
<view class="common" style="bottom: 20px;"></view>
|
||||
</view>
|
||||
<view class="example-box">
|
||||
<view class="common" style="bottom: 20px;" flatten></view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="uni-common-mb">
|
||||
<text class="uni-title-text">bottom: 20rpx (距离底部 20rpx) - 右侧:拍平</text>
|
||||
<view class="test-container">
|
||||
<view class="example-box">
|
||||
<view class="common" style="bottom: 20rpx;"></view>
|
||||
</view>
|
||||
<view class="example-box">
|
||||
<view class="common" style="bottom: 20rpx;" flatten></view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="uni-common-mb">
|
||||
<text class="uni-title-text">bottom: 20% (距离底部 20%) - 右侧:拍平</text>
|
||||
<view class="test-container">
|
||||
<view class="example-box">
|
||||
<view class="common" style="bottom: 20%;"></view>
|
||||
</view>
|
||||
<view class="example-box">
|
||||
<view class="common" style="bottom: 20%;" flatten></view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="uni-common-mb">
|
||||
<text class="uni-title-text">bottom: auto (自动,默认顶部对齐) - 右侧:拍平</text>
|
||||
<view class="test-container">
|
||||
<view class="example-box">
|
||||
<view class="common" style="bottom: auto;"></view>
|
||||
</view>
|
||||
<view class="example-box">
|
||||
<view class="common" style="bottom: auto;" flatten></view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<text class="uni-title-text uni-common-mt">scroll-view 组件</text>
|
||||
|
||||
<view class="uni-common-mb">
|
||||
<text class="uni-subtitle-text">bottom: 10% 和 bottom: 30px</text>
|
||||
<view class="test-container">
|
||||
<view class="example-box">
|
||||
<scroll-view class="common" style="bottom: 10%;"></scroll-view>
|
||||
</view>
|
||||
<view class="example-box">
|
||||
<scroll-view class="common" style="bottom: 30px;"></scroll-view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="uni-common-mt">
|
||||
<text class="uni-title-text">setProperty 设置与 getPropertyValue 获取</text>
|
||||
</view>
|
||||
|
||||
<!-- 普通版本 -->
|
||||
<view class="test-container">
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">view 组件</text>
|
||||
<text class="uni-info">设置值: {{data.bottom}}</text>
|
||||
<text class="uni-info">获取值: {{data.bottomActual}}</text>
|
||||
<view class="test-box">
|
||||
<view ref="viewRef" class="common test-view" :style="{ bottom: data.bottom }">
|
||||
<text class="common-text">view</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">text 组件</text>
|
||||
<text class="uni-info">设置值: {{data.bottom}}</text>
|
||||
<text class="uni-info">获取值: {{data.bottomActualText}}</text>
|
||||
<view class="test-box">
|
||||
<text ref="textRef" class="common common-text test-text" :style="{ bottom: data.bottom }">text</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">image 组件</text>
|
||||
<text class="uni-info">设置值: {{data.bottom}}</text>
|
||||
<text class="uni-info">获取值: {{data.bottomActualImage}}</text>
|
||||
<view class="test-box">
|
||||
<image ref="imageRef" class="common test-image" :style="{ bottom: data.bottom }" src="/static/test-image/logo.png"></image>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 拍平版本 -->
|
||||
<view class="test-container">
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">view 组件拍平</text>
|
||||
<text class="uni-info">设置值: {{data.bottom}}</text>
|
||||
<text class="uni-info">获取值: {{data.bottomActualFlat}}</text>
|
||||
<view class="test-box">
|
||||
<view ref="viewRefFlat" class="common test-view-flatten" :style="{ bottom: data.bottom }" flatten>
|
||||
<text class="common-text">view</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">text 组件拍平</text>
|
||||
<text class="uni-info">设置值: {{data.bottom}}</text>
|
||||
<text class="uni-info">获取值: {{data.bottomActualTextFlat}}</text>
|
||||
<view class="test-box">
|
||||
<text ref="textRefFlat" class="common common-text test-text-flatten" :style="{ bottom: data.bottom }" flatten>text</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">image 组件拍平</text>
|
||||
<text class="uni-info">设置值: {{data.bottom}}</text>
|
||||
<text class="uni-info">获取值: {{data.bottomActualImageFlat}}</text>
|
||||
<view class="test-box">
|
||||
<image ref="imageRefFlat" class="common test-image-flatten" :style="{ bottom: data.bottom }" flatten src="/static/test-image/logo.png"></image>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="uni-common-mt uni-common-mb">
|
||||
<text class="uni-tips">第一个枚举值,'' (空字符串) - 空值情况</text>
|
||||
<enum-data :items="bottomEnum" title="bottom 枚举值" @change="radioChangeBottom" :compact="true"></enum-data>
|
||||
<input-data :defaultValue="data.bottom" title="bottom 自定义值" type="text" @confirm="inputChangeBottom"></input-data>
|
||||
</view>
|
||||
|
||||
<view class="uni-common-mb">
|
||||
<text>native-view组件: bottom: 10% 和 bottom: 30px</text>
|
||||
<view class="test-container">
|
||||
<view class="example-box">
|
||||
<test-native-view class="common-native" style="bottom: 10%;"></test-native-view>
|
||||
</view>
|
||||
<view class="example-box">
|
||||
<test-native-view class="common-native" style="bottom: 30px;"></test-native-view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<!-- #ifdef APP && !VUE3-VAPOR -->
|
||||
</scroll-view>
|
||||
<!-- #endif -->
|
||||
</template>
|
||||
|
||||
<script setup lang="uts">
|
||||
import { ItemType } from '@/components/enum-data/enum-data-types'
|
||||
|
||||
const bottomEnum : ItemType[] = [
|
||||
{ value: 0, name: '' },
|
||||
{ value: 1, name: '0' },
|
||||
{ value: 2, name: '0px' },
|
||||
{ value: 3, name: '10px' },
|
||||
{ value: 4, name: '20rpx' },
|
||||
{ value: 5, name: '0%' },
|
||||
{ value: 6, name: '20%' },
|
||||
{ value: 7, name: 'auto' }
|
||||
]
|
||||
|
||||
const data = reactive({
|
||||
bottom: '10px',
|
||||
bottomActual: '',
|
||||
bottomActualText: '',
|
||||
bottomActualImage: '',
|
||||
bottomActualFlat: '',
|
||||
bottomActualTextFlat: '',
|
||||
bottomActualImageFlat: ''
|
||||
})
|
||||
const viewRef = ref(null as UniElement | null)
|
||||
const textRef = ref(null as UniTextElement | null)
|
||||
const imageRef = ref(null as UniImageElement | null)
|
||||
const viewRefFlat = ref(null as UniElement | null)
|
||||
const textRefFlat = ref(null as UniTextElement | null)
|
||||
const imageRefFlat = ref(null as UniImageElement | null)
|
||||
|
||||
const getPropertyValues = () => {
|
||||
data.bottomActual = viewRef.value?.style.getPropertyValue('bottom') ?? ''
|
||||
data.bottomActualFlat = viewRefFlat.value?.style.getPropertyValue('bottom') ?? ''
|
||||
data.bottomActualText = textRef.value?.style.getPropertyValue('bottom') ?? ''
|
||||
data.bottomActualTextFlat = textRefFlat.value?.style.getPropertyValue('bottom') ?? ''
|
||||
data.bottomActualImage = imageRef.value?.style.getPropertyValue('bottom') ?? ''
|
||||
data.bottomActualImageFlat = imageRefFlat.value?.style.getPropertyValue('bottom') ?? ''
|
||||
}
|
||||
|
||||
|
||||
const changeBottom = (value : string) => {
|
||||
data.bottom = value
|
||||
viewRef.value?.style.setProperty('bottom', value)
|
||||
viewRefFlat.value?.style.setProperty('bottom', value)
|
||||
textRef.value?.style.setProperty('bottom', value)
|
||||
textRefFlat.value?.style.setProperty('bottom', value)
|
||||
imageRef.value?.style.setProperty('bottom', value)
|
||||
imageRefFlat.value?.style.setProperty('bottom', value)
|
||||
// 使用 nextTick 确保样式已应用后再获取值
|
||||
nextTick(() => {
|
||||
getPropertyValues()
|
||||
})
|
||||
}
|
||||
|
||||
const radioChangeBottom = (index : number) => {
|
||||
const selectedItem = bottomEnum.find((item) : boolean => item.value === index)
|
||||
if (selectedItem != null) {
|
||||
changeBottom(selectedItem.name)
|
||||
}
|
||||
}
|
||||
|
||||
const inputChangeBottom = (value : string) => {
|
||||
changeBottom(value)
|
||||
}
|
||||
|
||||
onReady(() => {
|
||||
getPropertyValues()
|
||||
})
|
||||
|
||||
defineExpose({
|
||||
radioChangeBottom,
|
||||
data
|
||||
})
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.example-box {
|
||||
position: relative;
|
||||
flex: 1;
|
||||
height: 100px;
|
||||
background-color: #f5f5f5;
|
||||
border: 1px solid #ddd;
|
||||
margin: 0 5px;
|
||||
}
|
||||
|
||||
.common {
|
||||
position: absolute;
|
||||
width: 60px;
|
||||
height: 60px;
|
||||
background-color: cyan;
|
||||
}
|
||||
|
||||
.common-text {
|
||||
width: 50px;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.test-container {
|
||||
flex-direction: row;
|
||||
justify-content: space-between;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.test-item {
|
||||
flex: 1;
|
||||
margin: 0 5px;
|
||||
}
|
||||
|
||||
.test-box {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
height: 100px;
|
||||
background-color: #e0e0e0;
|
||||
}
|
||||
|
||||
.common-native {
|
||||
position: absolute;
|
||||
width: 60px;
|
||||
height: 60px;
|
||||
background-color: rgba(255,0,0,0.5);
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,11 @@
|
||||
<template>
|
||||
<view id="child_box" class="box child_box"></view>
|
||||
</template>
|
||||
|
||||
<style>
|
||||
.box {
|
||||
width: 100px;
|
||||
height: 100px;
|
||||
background-color: red;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,251 @@
|
||||
<template>
|
||||
<!-- #ifdef APP && !VUE3-VAPOR -->
|
||||
<scroll-view style="flex: 1">
|
||||
<!-- #endif -->
|
||||
<view style="flex-grow: 1;">
|
||||
<text class="uni-tips">说明:左边是正常版本,右边是拍平版本</text>
|
||||
<view>
|
||||
<text>height: 100px</text>
|
||||
<view class="demo-box">
|
||||
<view class="common" style="height: 100px;"></view>
|
||||
<view class="common" style="height: 100px;" flatten></view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view >
|
||||
<text>height: 50%</text>
|
||||
<view class="demo-box" style="height: 100px;">
|
||||
<view class="common" style="height: 50%;"></view>
|
||||
<view class="common" style="height: 50%;" flatten></view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="uni-common-mt">
|
||||
<text class="uni-title-text">scroll-view 组件</text>
|
||||
</view>
|
||||
|
||||
<view class="demo-box">
|
||||
<scroll-view style="width: 100px; height: 80px; background-color: cyan;">
|
||||
<text class="scroll-view-label">height: 80px</text>
|
||||
</scroll-view>
|
||||
<scroll-view style="width: 100px; height: 120px; background-color: cyan;">
|
||||
<text class="scroll-view-label">height: 120px</text>
|
||||
</scroll-view>
|
||||
</view>
|
||||
|
||||
<view class="uni-common-mt">
|
||||
<text class="uni-title-text">setProperty 设置与 getPropertyValue 获取</text>
|
||||
</view>
|
||||
|
||||
<!-- 普通版本 -->
|
||||
<view class="test-container">
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">view 组件</text>
|
||||
<text class="uni-info">设置值: {{data.height}}</text>
|
||||
<text class="uni-info">获取值: {{data.heightActual}}</text>
|
||||
<view class="test-box">
|
||||
<view ref="viewRef" class="common-dynamic test-view" :style="{ height: data.height }">
|
||||
<text>view</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">text 组件</text>
|
||||
<text class="uni-info">设置值: {{data.height}}</text>
|
||||
<text class="uni-info">获取值: {{data.heightActualText}}</text>
|
||||
<view class="test-box">
|
||||
<text ref="textRef" class="common-dynamic test-text" :style="{ height: data.height }">text</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">image 组件</text>
|
||||
<text class="uni-info">设置值: {{data.height}}</text>
|
||||
<text class="uni-info">获取值: {{data.heightActualImage}}</text>
|
||||
<view class="test-box">
|
||||
<image ref="imageRef" class="common-dynamic test-image" :style="{ height: data.height }" src="/static/test-image/logo.png"></image>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 拍平版本 -->
|
||||
<view class="test-container">
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">view 组件拍平</text>
|
||||
<text class="uni-info">设置值: {{data.height}}</text>
|
||||
<text class="uni-info">获取值: {{data.heightActualFlat}}</text>
|
||||
<view class="test-box">
|
||||
<view ref="viewRefFlat" class="common-dynamic test-view-flatten" :style="{ height: data.height }" flatten>
|
||||
<text>view</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">text 组件拍平</text>
|
||||
<text class="uni-info">设置值: {{data.height}}</text>
|
||||
<text class="uni-info">获取值: {{data.heightActualTextFlat}}</text>
|
||||
<view class="test-box">
|
||||
<text ref="textRefFlat" class="common-dynamic test-text-flatten" :style="{ height: data.height }" flatten>text</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">image 组件拍平</text>
|
||||
<text class="uni-info">设置值: {{data.height}}</text>
|
||||
<text class="uni-info">获取值: {{data.heightActualImageFlat}}</text>
|
||||
<view class="test-box">
|
||||
<image ref="imageRefFlat" class="common-dynamic test-image-flatten" :style="{ height: data.height }" flatten src="/static/test-image/logo.png"></image>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="uni-common-mt uni-common-mb">
|
||||
<text class="uni-tips">第一个枚举值,'' (空字符串) - 空值情况</text>
|
||||
<enum-data :items="heightEnum" title="height 枚举值" @change="radioChangeHeight" :compact="true"></enum-data>
|
||||
<input-data :defaultValue="data.height" title="height 自定义值" type="text" @confirm="inputChangeHeight"></input-data>
|
||||
</view>
|
||||
|
||||
<view class="uni-common-mb">
|
||||
<text>native-view组件: height: 80px 和 height: 120px</text>
|
||||
<view class="demo-box-native">
|
||||
<view class="container-native">
|
||||
<native-view style="width: 100px;height: 80px;"></native-view>
|
||||
</view>
|
||||
<view class="container-native">
|
||||
<native-view style="width: 100px;height: 120px;"></native-view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<!-- #ifdef APP && !VUE3-VAPOR -->
|
||||
</scroll-view>
|
||||
<!-- #endif -->
|
||||
</template>
|
||||
|
||||
<script setup lang="uts">
|
||||
import { ItemType } from '@/components/enum-data/enum-data-types'
|
||||
|
||||
const heightEnum: ItemType[] = [
|
||||
{ value: 0, name: '' },
|
||||
{ value: 1, name: '0' },
|
||||
{ value: 2, name: '0px' },
|
||||
{ value: 3, name: '50px' },
|
||||
{ value: 4, name: '150px' },
|
||||
{ value: 5, name: '0%' },
|
||||
{ value: 6, name: '50%' },
|
||||
{ value: 7, name: 'auto' }
|
||||
]
|
||||
|
||||
const data = reactive({
|
||||
height: '100px',
|
||||
heightActual: '',
|
||||
heightActualText: '',
|
||||
heightActualImage: '',
|
||||
heightActualFlat: '',
|
||||
heightActualTextFlat: '',
|
||||
heightActualImageFlat: ''
|
||||
})
|
||||
const viewRef = ref(null as UniElement | null)
|
||||
const textRef = ref(null as UniTextElement | null)
|
||||
const imageRef = ref(null as UniImageElement | null)
|
||||
const viewRefFlat = ref(null as UniElement | null)
|
||||
const textRefFlat = ref(null as UniTextElement | null)
|
||||
const imageRefFlat = ref(null as UniImageElement | null)
|
||||
|
||||
const getPropertyValues = () => {
|
||||
data.heightActual = viewRef.value?.style.getPropertyValue('height') ?? ''
|
||||
data.heightActualFlat = viewRefFlat.value?.style.getPropertyValue('height') ?? ''
|
||||
data.heightActualText = textRef.value?.style.getPropertyValue('height') ?? ''
|
||||
data.heightActualTextFlat = textRefFlat.value?.style.getPropertyValue('height') ?? ''
|
||||
data.heightActualImage = imageRef.value?.style.getPropertyValue('height') ?? ''
|
||||
data.heightActualImageFlat = imageRefFlat.value?.style.getPropertyValue('height') ?? ''
|
||||
}
|
||||
|
||||
|
||||
const changeHeight = (value: string) => {
|
||||
data.height = value
|
||||
viewRef.value?.style.setProperty('height', value)
|
||||
viewRefFlat.value?.style.setProperty('height', value)
|
||||
textRef.value?.style.setProperty('height', value)
|
||||
textRefFlat.value?.style.setProperty('height', value)
|
||||
imageRef.value?.style.setProperty('height', value)
|
||||
imageRefFlat.value?.style.setProperty('height', value)
|
||||
// 使用 nextTick 确保样式已应用后再获取值
|
||||
nextTick(() => {
|
||||
getPropertyValues()
|
||||
})
|
||||
}
|
||||
|
||||
const radioChangeHeight = (index: number) => {
|
||||
const selectedItem = heightEnum.find((item): boolean => item.value === index)
|
||||
if (selectedItem != null) {
|
||||
changeHeight(selectedItem.name)
|
||||
}
|
||||
}
|
||||
|
||||
const inputChangeHeight = (value: string) => {
|
||||
changeHeight(value)
|
||||
}
|
||||
|
||||
onReady(() => {
|
||||
getPropertyValues()
|
||||
})
|
||||
|
||||
defineExpose({
|
||||
radioChangeHeight,
|
||||
data
|
||||
})
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.common {
|
||||
flex: 1;
|
||||
margin:0 10px;
|
||||
background-color: cyan;
|
||||
}
|
||||
.demo-box {
|
||||
flex-direction: row;
|
||||
margin-top: 10px;
|
||||
justify-content: space-around;
|
||||
}
|
||||
|
||||
.common-dynamic {
|
||||
width: 100px;
|
||||
background-color: cyan;
|
||||
}
|
||||
|
||||
.test-container {
|
||||
flex-direction: row;
|
||||
justify-content: space-between;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.test-item {
|
||||
flex: 1;
|
||||
margin: 0 5px;
|
||||
}
|
||||
|
||||
.test-box {
|
||||
width: 100%;
|
||||
height: 150px;
|
||||
background-color: gray;
|
||||
}
|
||||
|
||||
.scroll-view-label {
|
||||
font-size: 12px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.demo-box-native {
|
||||
flex-direction: row;
|
||||
margin-top: 10px;
|
||||
justify-content: space-around;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.container-native {
|
||||
background-color: cyan;
|
||||
}
|
||||
</style>
|
||||
280
mpuniapp/pages/CSS/layout/left.uvue
普通文件
280
mpuniapp/pages/CSS/layout/left.uvue
普通文件
@@ -0,0 +1,280 @@
|
||||
<template>
|
||||
<!-- #ifdef APP && !VUE3-VAPOR -->
|
||||
<scroll-view style="flex: 1">
|
||||
<!-- #endif -->
|
||||
<view style="flex-grow: 1;">
|
||||
<view class="uni-common-mb">
|
||||
<text class="uni-title-text">left: 20px (距离左边 20px) - 右侧:拍平</text>
|
||||
<view class="test-container">
|
||||
<view class="example-box">
|
||||
<view class="common" style="left: 20px;"></view>
|
||||
</view>
|
||||
<view class="example-box">
|
||||
<view class="common" style="left: 20px;" flatten></view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="uni-common-mb">
|
||||
<text class="uni-title-text">left: 20rpx (距离左边 20rpx) - 右侧:拍平</text>
|
||||
<view class="test-container">
|
||||
<view class="example-box">
|
||||
<view class="common" style="left: 20rpx;"></view>
|
||||
</view>
|
||||
<view class="example-box">
|
||||
<view class="common" style="left: 20rpx;" flatten></view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="uni-common-mb">
|
||||
<text class="uni-title-text">left: 20% (距离左边 20%) - 右侧:拍平</text>
|
||||
<view class="test-container">
|
||||
<view class="example-box">
|
||||
<view class="common" style="left: 20%;"></view>
|
||||
</view>
|
||||
<view class="example-box">
|
||||
<view class="common" style="left: 20%;" flatten></view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="uni-common-mb">
|
||||
<text class="uni-title-text">left: auto (自动,默认左边对齐) - 右侧:拍平</text>
|
||||
<view class="test-container">
|
||||
<view class="example-box">
|
||||
<view class="common" style="left: auto;"></view>
|
||||
</view>
|
||||
<view class="example-box">
|
||||
<view class="common" style="left: auto;" flatten></view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<text class="uni-title-text uni-common-mt">scroll-view 组件</text>
|
||||
|
||||
<view class="uni-common-mb">
|
||||
<text class="uni-subtitle-text">left: 10% 和 left: 30px</text>
|
||||
<view class="test-container">
|
||||
<view class="example-box">
|
||||
<scroll-view class="common" style="left: 10%;"></scroll-view>
|
||||
</view>
|
||||
<view class="example-box">
|
||||
<scroll-view class="common" style="left: 30px;"></scroll-view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="uni-common-mt">
|
||||
<text class="uni-title-text">setProperty 设置与 getPropertyValue 获取</text>
|
||||
</view>
|
||||
|
||||
<!-- 普通版本 -->
|
||||
<view class="test-container">
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">view 组件</text>
|
||||
<text class="uni-info">设置值: {{data.left}}</text>
|
||||
<text class="uni-info">获取值: {{data.leftActual}}</text>
|
||||
<view class="test-box">
|
||||
<view ref="viewRef" class="common test-view" :style="{ left: data.left }">
|
||||
<text class="common-text">view</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">text 组件</text>
|
||||
<text class="uni-info">设置值: {{data.left}}</text>
|
||||
<text class="uni-info">获取值: {{data.leftActualText}}</text>
|
||||
<view class="test-box">
|
||||
<text ref="textRef" class="common common-text test-text" :style="{ left: data.left }">text</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">image 组件</text>
|
||||
<text class="uni-info">设置值: {{data.left}}</text>
|
||||
<text class="uni-info">获取值: {{data.leftActualImage}}</text>
|
||||
<view class="test-box">
|
||||
<image ref="imageRef" class="common test-image" :style="{ left: data.left }" src="/static/test-image/logo.png"></image>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 拍平版本 -->
|
||||
<view class="test-container">
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">view 组件拍平</text>
|
||||
<text class="uni-info">设置值: {{data.left}}</text>
|
||||
<text class="uni-info">获取值: {{data.leftActualFlat}}</text>
|
||||
<view class="test-box">
|
||||
<view ref="viewRefFlat" class="common test-view-flatten" :style="{ left: data.left }" flatten>
|
||||
<text class="common-text">view</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">text 组件拍平</text>
|
||||
<text class="uni-info">设置值: {{data.left}}</text>
|
||||
<text class="uni-info">获取值: {{data.leftActualTextFlat}}</text>
|
||||
<view class="test-box">
|
||||
<text ref="textRefFlat" class="common common-text test-text-flatten" :style="{ left: data.left }" flatten>text</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">image 组件拍平</text>
|
||||
<text class="uni-info">设置值: {{data.left}}</text>
|
||||
<text class="uni-info">获取值: {{data.leftActualImageFlat}}</text>
|
||||
<view class="test-box">
|
||||
<image ref="imageRefFlat" class="common test-image-flatten" :style="{ left: data.left }" flatten src="/static/test-image/logo.png"></image>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="uni-common-mt uni-common-mb">
|
||||
<text class="uni-tips">第一个枚举值,'' (空字符串) - 空值情况</text>
|
||||
<enum-data :items="leftEnum" title="left 枚举值" @change="radioChangeLeft" :compact="true"></enum-data>
|
||||
<input-data :defaultValue="data.left" title="left 自定义值" type="text" @confirm="inputChangeLeft"></input-data>
|
||||
</view>
|
||||
|
||||
<view class="uni-common-mb">
|
||||
<text>native-view组件: left: 10% 和 left: 30px</text>
|
||||
<view class="test-container">
|
||||
<view class="example-box">
|
||||
<test-native-view class="common-native" style="left: 10%;"></test-native-view>
|
||||
</view>
|
||||
<view class="example-box">
|
||||
<test-native-view class="common-native" style="left: 30px;"></test-native-view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<!-- #ifdef APP && !VUE3-VAPOR -->
|
||||
</scroll-view>
|
||||
<!-- #endif -->
|
||||
</template>
|
||||
|
||||
<script setup lang="uts">
|
||||
import { ItemType } from '@/components/enum-data/enum-data-types'
|
||||
|
||||
const leftEnum : ItemType[] = [
|
||||
{ value: 0, name: '' },
|
||||
{ value: 1, name: '0' },
|
||||
{ value: 2, name: '0px' },
|
||||
{ value: 3, name: '10px' },
|
||||
{ value: 4, name: '20rpx' },
|
||||
{ value: 5, name: '0%' },
|
||||
{ value: 6, name: '20%' },
|
||||
{ value: 7, name: 'auto' }
|
||||
]
|
||||
|
||||
const data = reactive({
|
||||
left: '10px',
|
||||
leftActual: '',
|
||||
leftActualText: '',
|
||||
leftActualImage: '',
|
||||
leftActualFlat: '',
|
||||
leftActualTextFlat: '',
|
||||
leftActualImageFlat: ''
|
||||
})
|
||||
const viewRef = ref(null as UniElement | null)
|
||||
const textRef = ref(null as UniTextElement | null)
|
||||
const imageRef = ref(null as UniImageElement | null)
|
||||
const viewRefFlat = ref(null as UniElement | null)
|
||||
const textRefFlat = ref(null as UniTextElement | null)
|
||||
const imageRefFlat = ref(null as UniImageElement | null)
|
||||
|
||||
const getPropertyValues = () => {
|
||||
data.leftActual = viewRef.value?.style.getPropertyValue('left') ?? ''
|
||||
data.leftActualFlat = viewRefFlat.value?.style.getPropertyValue('left') ?? ''
|
||||
data.leftActualText = textRef.value?.style.getPropertyValue('left') ?? ''
|
||||
data.leftActualTextFlat = textRefFlat.value?.style.getPropertyValue('left') ?? ''
|
||||
data.leftActualImage = imageRef.value?.style.getPropertyValue('left') ?? ''
|
||||
data.leftActualImageFlat = imageRefFlat.value?.style.getPropertyValue('left') ?? ''
|
||||
}
|
||||
|
||||
|
||||
const changeLeft = (value : string) => {
|
||||
data.left = value
|
||||
viewRef.value?.style.setProperty('left', value)
|
||||
viewRefFlat.value?.style.setProperty('left', value)
|
||||
textRef.value?.style.setProperty('left', value)
|
||||
textRefFlat.value?.style.setProperty('left', value)
|
||||
imageRef.value?.style.setProperty('left', value)
|
||||
imageRefFlat.value?.style.setProperty('left', value)
|
||||
// 使用 nextTick 确保样式已应用后再获取值
|
||||
nextTick(() => {
|
||||
getPropertyValues()
|
||||
})
|
||||
}
|
||||
|
||||
const radioChangeLeft = (index : number) => {
|
||||
const selectedItem = leftEnum.find((item) : boolean => item.value === index)
|
||||
if (selectedItem != null) {
|
||||
changeLeft(selectedItem.name)
|
||||
}
|
||||
}
|
||||
|
||||
const inputChangeLeft = (value : string) => {
|
||||
changeLeft(value)
|
||||
}
|
||||
|
||||
onReady(() => {
|
||||
getPropertyValues()
|
||||
})
|
||||
|
||||
defineExpose({
|
||||
radioChangeLeft,
|
||||
data
|
||||
})
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.example-box {
|
||||
position: relative;
|
||||
flex: 1;
|
||||
height: 60px;
|
||||
background-color: #f5f5f5;
|
||||
border: 1px solid #ddd;
|
||||
margin: 0 5px;
|
||||
}
|
||||
|
||||
.common {
|
||||
position: absolute;
|
||||
width: 60px;
|
||||
height: 60px;
|
||||
background-color: cyan;
|
||||
}
|
||||
|
||||
.common-text {
|
||||
width: 50px;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.test-container {
|
||||
flex-direction: row;
|
||||
justify-content: space-between;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.test-item {
|
||||
flex: 1;
|
||||
margin: 0 5px;
|
||||
}
|
||||
|
||||
.test-box {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
height: 60px;
|
||||
background-color: #e0e0e0;
|
||||
}
|
||||
|
||||
.common-native {
|
||||
position: absolute;
|
||||
width: 60px;
|
||||
height: 60px;
|
||||
background-color: #00FFFF;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,254 @@
|
||||
<template>
|
||||
<!-- #ifdef APP && !VUE3-VAPOR -->
|
||||
<scroll-view style="flex: 1">
|
||||
<!-- #endif -->
|
||||
<view style="flex-grow: 1;">
|
||||
<view>
|
||||
<text>max-height: 100px</text>
|
||||
<view class="common" style="max-height: 100px;">
|
||||
<text>height: 400px</text>
|
||||
</view>
|
||||
<text>拍平</text>
|
||||
<view class="common" style="max-height: 100px;" flatten>
|
||||
<text>height: 400px</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="uni-common-mt">
|
||||
<text class="uni-title-text">scroll-view 组件</text>
|
||||
</view>
|
||||
|
||||
<view class="demo-box">
|
||||
<scroll-view class="common" style="max-height: 80px; background-color: cyan;width:100px;">
|
||||
<text class="scroll-view-label">max-height: 80px</text>
|
||||
</scroll-view>
|
||||
<scroll-view class="common" style="max-height: 120px; background-color: cyan;width:100px;">
|
||||
<text class="scroll-view-label">max-height: 120px</text>
|
||||
</scroll-view>
|
||||
</view>
|
||||
|
||||
<view class="uni-common-mt">
|
||||
<text class="uni-title-text">setProperty 设置与 getPropertyValue 获取</text>
|
||||
</view>
|
||||
|
||||
<!-- 普通版本 -->
|
||||
<view class="test-container">
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">view 组件</text>
|
||||
<text class="uni-info">设置值: {{data.maxHeight}}</text>
|
||||
<text class="uni-info">获取值: {{data.maxHeightActual}}</text>
|
||||
<view class="test-box">
|
||||
<view ref="viewRef" class="common-dynamic test-view" :style="{ maxHeight: data.maxHeight }">
|
||||
<text style="font-size: 12px;">view</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">text 组件</text>
|
||||
<text class="uni-info">设置值: {{data.maxHeight}}</text>
|
||||
<text class="uni-info">获取值: {{data.maxHeightActualText}}</text>
|
||||
<view class="test-box">
|
||||
<text ref="textRef" class="common-dynamic test-text" :style="{ maxHeight: data.maxHeight }">text</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">image 组件</text>
|
||||
<text class="uni-info">设置值: {{data.maxHeight}}</text>
|
||||
<text class="uni-info">获取值: {{data.maxHeightActualImage}}</text>
|
||||
<view class="test-box">
|
||||
<image ref="imageRef" class="common-dynamic test-image" :style="{ maxHeight: data.maxHeight }"
|
||||
src="/static/test-image/logo.png"></image>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 拍平版本 -->
|
||||
<view class="test-container">
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">view 组件拍平</text>
|
||||
<text class="uni-info">设置值: {{data.maxHeight}}</text>
|
||||
<text class="uni-info">获取值: {{data.maxHeightActualFlat}}</text>
|
||||
<view class="test-box">
|
||||
<view ref="viewRefFlat" class="common-dynamic test-view-flatten" :style="{ maxHeight: data.maxHeight }"
|
||||
flatten>
|
||||
<text style="font-size: 12px;">view</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">text 组件拍平</text>
|
||||
<text class="uni-info">设置值: {{data.maxHeight}}</text>
|
||||
<text class="uni-info">获取值: {{data.maxHeightActualTextFlat}}</text>
|
||||
<view class="test-box">
|
||||
<text ref="textRefFlat" class="common-dynamic test-text-flatten" :style="{ maxHeight: data.maxHeight }"
|
||||
flatten>text</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">image 组件拍平</text>
|
||||
<text class="uni-info">设置值: {{data.maxHeight}}</text>
|
||||
<text class="uni-info">获取值: {{data.maxHeightActualImageFlat}}</text>
|
||||
<view class="test-box">
|
||||
<image ref="imageRefFlat" class="common-dynamic test-image-flatten" :style="{ maxHeight: data.maxHeight }"
|
||||
flatten src="/static/test-image/logo.png"></image>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="uni-common-mt uni-common-mb">
|
||||
<text class="uni-tips">第一个枚举值,'' (空字符串) - 空值情况</text>
|
||||
<enum-data :items="maxHeightEnum" title="max-height 枚举值" @change="radioChangeMaxHeight"
|
||||
:compact="true"></enum-data>
|
||||
<input-data :defaultValue="data.maxHeight" title="max-height 自定义值" type="text"
|
||||
@confirm="inputChangeMaxHeight"></input-data>
|
||||
</view>
|
||||
|
||||
<view class="uni-common-mb">
|
||||
<text>native-view组件: max-height: 80px 和 max-height: 120px</text>
|
||||
<view class="demo-box-native">
|
||||
<view class="container-native">
|
||||
<native-view style="max-height: 80px; width:100px; height: 400px;"></native-view>
|
||||
</view>
|
||||
<view class="container-native">
|
||||
<native-view style="max-height: 120px; width:100px; height: 400px;"></native-view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<!-- #ifdef APP && !VUE3-VAPOR -->
|
||||
</scroll-view>
|
||||
<!-- #endif -->
|
||||
</template>
|
||||
|
||||
<script setup lang="uts">
|
||||
import { ItemType } from '@/components/enum-data/enum-data-types'
|
||||
|
||||
const maxHeightEnum : ItemType[] = [
|
||||
{ value: 0, name: '' },
|
||||
{ value: 1, name: '0' },
|
||||
{ value: 2, name: '0px' },
|
||||
{ value: 3, name: '100px' },
|
||||
{ value: 4, name: '150px' },
|
||||
{ value: 5, name: '80rpx' },
|
||||
{ value: 6, name: 'none' }
|
||||
]
|
||||
|
||||
const data = reactive({
|
||||
maxHeight: '50px',
|
||||
maxHeightActual: '',
|
||||
maxHeightActualText: '',
|
||||
maxHeightActualImage: '',
|
||||
maxHeightActualFlat: '',
|
||||
maxHeightActualTextFlat: '',
|
||||
maxHeightActualImageFlat: ''
|
||||
})
|
||||
const viewRef = ref(null as UniElement | null)
|
||||
const textRef = ref(null as UniTextElement | null)
|
||||
const imageRef = ref(null as UniImageElement | null)
|
||||
const viewRefFlat = ref(null as UniElement | null)
|
||||
const textRefFlat = ref(null as UniTextElement | null)
|
||||
const imageRefFlat = ref(null as UniImageElement | null)
|
||||
|
||||
const getPropertyValues = () => {
|
||||
data.maxHeightActual = viewRef.value?.style.getPropertyValue('max-height') ?? ''
|
||||
data.maxHeightActualFlat = viewRefFlat.value?.style.getPropertyValue('max-height') ?? ''
|
||||
data.maxHeightActualText = textRef.value?.style.getPropertyValue('max-height') ?? ''
|
||||
data.maxHeightActualTextFlat = textRefFlat.value?.style.getPropertyValue('max-height') ?? ''
|
||||
data.maxHeightActualImage = imageRef.value?.style.getPropertyValue('max-height') ?? ''
|
||||
data.maxHeightActualImageFlat = imageRefFlat.value?.style.getPropertyValue('max-height') ?? ''
|
||||
}
|
||||
|
||||
|
||||
const changeMaxHeight = (value : string) => {
|
||||
data.maxHeight = value
|
||||
viewRef.value?.style.setProperty('max-height', value)
|
||||
viewRefFlat.value?.style.setProperty('max-height', value)
|
||||
textRef.value?.style.setProperty('max-height', value)
|
||||
textRefFlat.value?.style.setProperty('max-height', value)
|
||||
imageRef.value?.style.setProperty('max-height', value)
|
||||
imageRefFlat.value?.style.setProperty('max-height', value)
|
||||
// 使用 nextTick 确保样式已应用后再获取值
|
||||
nextTick(() => {
|
||||
getPropertyValues()
|
||||
})
|
||||
}
|
||||
|
||||
const radioChangeMaxHeight = (index : number) => {
|
||||
const selectedItem = maxHeightEnum.find((item) : boolean => item.value === index)
|
||||
if (selectedItem != null) {
|
||||
changeMaxHeight(selectedItem.name)
|
||||
}
|
||||
}
|
||||
|
||||
const inputChangeMaxHeight = (value : string) => {
|
||||
changeMaxHeight(value)
|
||||
}
|
||||
|
||||
onReady(() => {
|
||||
getPropertyValues()
|
||||
})
|
||||
|
||||
defineExpose({
|
||||
radioChangeMaxHeight,
|
||||
data
|
||||
})
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.common {
|
||||
width: 200px;
|
||||
height: 400px;
|
||||
background-color: cyan;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.common-dynamic {
|
||||
width: 100px;
|
||||
height: 150px;
|
||||
background-color: cyan;
|
||||
}
|
||||
|
||||
.test-container {
|
||||
flex-direction: row;
|
||||
justify-content: space-between;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.test-item {
|
||||
flex: 1;
|
||||
margin: 0 5px;
|
||||
}
|
||||
|
||||
.test-box {
|
||||
width: 100%;
|
||||
height: 150px;
|
||||
background-color: gray;
|
||||
}
|
||||
|
||||
.demo-box {
|
||||
flex-direction: row;
|
||||
margin-top: 10px;
|
||||
justify-content: space-around;
|
||||
}
|
||||
|
||||
.scroll-view-label {
|
||||
font-size: 12px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.demo-box-native {
|
||||
flex-direction: row;
|
||||
margin-top: 10px;
|
||||
justify-content: space-around;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.container-native {
|
||||
background-color: cyan;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,265 @@
|
||||
<template>
|
||||
<!-- #ifdef APP && !VUE3-VAPOR -->
|
||||
<scroll-view style="flex: 1">
|
||||
<!-- #endif -->
|
||||
<view style="flex-grow: 1;">
|
||||
<view>
|
||||
<text>max-width: 200px</text>
|
||||
<view class="common" style="max-width: 200px;">
|
||||
<text>width: 400px</text>
|
||||
</view>
|
||||
<text>拍平</text>
|
||||
<view class="common" style="max-width: 200px;" flatten>
|
||||
<text>width: 400px</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="uni-common-mt">
|
||||
<text class="uni-title-text">scroll-view 组件</text>
|
||||
</view>
|
||||
|
||||
<view class="demo-box">
|
||||
<scroll-view class="common" style="max-width: 100px; background-color: cyan;">
|
||||
<text class="scroll-view-label">max-width: 100px</text>
|
||||
</scroll-view>
|
||||
<scroll-view class="common" style="max-width: 200px; background-color: cyan;">
|
||||
<text class="scroll-view-label">max-width: 200px</text>
|
||||
</scroll-view>
|
||||
</view>
|
||||
|
||||
<view class="uni-common-mt">
|
||||
<text class="uni-title-text">setProperty 设置与 getPropertyValue 获取</text>
|
||||
</view>
|
||||
|
||||
<!-- 普通版本 -->
|
||||
<view class="test-container">
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">view 组件</text>
|
||||
<text class="uni-info">设置值: {{data.maxWidth}}</text>
|
||||
<text class="uni-info">获取值: {{data.maxWidthActual}}</text>
|
||||
<view class="test-box">
|
||||
<view ref="viewRef" class="common-dynamic test-view" :style="{ maxWidth: data.maxWidth }">
|
||||
<text>view</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">text 组件</text>
|
||||
<text class="uni-info">设置值: {{data.maxWidth}}</text>
|
||||
<text class="uni-info">获取值: {{data.maxWidthActualText}}</text>
|
||||
<view class="test-box">
|
||||
<text ref="textRef" class="common-dynamic test-text" :style="{ maxWidth: data.maxWidth }">text</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">image 组件</text>
|
||||
<text class="uni-info">设置值: {{data.maxWidth}}</text>
|
||||
<text class="uni-info">获取值: {{data.maxWidthActualImage}}</text>
|
||||
<view class="test-box">
|
||||
<image ref="imageRef" class="common-dynamic test-image" :style="{ maxWidth: data.maxWidth }"
|
||||
src="/static/test-image/logo.png"></image>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 拍平版本 -->
|
||||
<view class="test-container">
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">view 组件拍平</text>
|
||||
<text class="uni-info">设置值: {{data.maxWidth}}</text>
|
||||
<text class="uni-info">获取值: {{data.maxWidthActualFlat}}</text>
|
||||
<view class="test-box">
|
||||
<view ref="viewRefFlat" class="common-dynamic test-view-flatten" :style="{ maxWidth: data.maxWidth }"
|
||||
flatten>
|
||||
<text class="common-text">view</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">text 组件拍平</text>
|
||||
<text class="uni-info">设置值: {{data.maxWidth}}</text>
|
||||
<text class="uni-info">获取值: {{data.maxWidthActualTextFlat}}</text>
|
||||
<view class="test-box">
|
||||
<text ref="textRefFlat" class="common-dynamic test-text-flatten" :style="{ maxWidth: data.maxWidth }"
|
||||
flatten>text</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">image 组件拍平</text>
|
||||
<text class="uni-info">设置值: {{data.maxWidth}}</text>
|
||||
<text class="uni-info">获取值: {{data.maxWidthActualImageFlat}}</text>
|
||||
<view class="test-box">
|
||||
<image ref="imageRefFlat" class="common-dynamic test-image-flatten" :style="{ maxWidth: data.maxWidth }"
|
||||
flatten src="/static/test-image/logo.png"></image>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="uni-common-mt uni-common-mb">
|
||||
<text class="uni-tips">第一个枚举值,'' (空字符串) - 空值情况</text>
|
||||
<enum-data :items="maxWidthEnum" title="max-width 枚举值" @change="radioChangeMaxWidth"
|
||||
:compact="true"></enum-data>
|
||||
<input-data :defaultValue="data.maxWidth" title="max-width 自定义值" type="text"
|
||||
@confirm="inputChangeMaxWidth"></input-data>
|
||||
</view>
|
||||
|
||||
<view class="uni-common-mb">
|
||||
<text>native-view组件: max-width: 100px 和 max-width: 200px</text>
|
||||
<view class="demo-box-native">
|
||||
<view class="container-native">
|
||||
<native-view style="max-width: 100px; height: 100px;"></native-view>
|
||||
</view>
|
||||
<view class="container-native">
|
||||
<native-view style="max-width: 200px; height: 100px;"></native-view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
</view>
|
||||
<!-- #ifdef APP && !VUE3-VAPOR -->
|
||||
</scroll-view>
|
||||
<!-- #endif -->
|
||||
</template>
|
||||
|
||||
<script setup lang="uts">
|
||||
import { ItemType } from '@/components/enum-data/enum-data-types'
|
||||
|
||||
const maxWidthEnum : ItemType[] = [
|
||||
{ value: 0, name: '' },
|
||||
{ value: 1, name: '0' },
|
||||
{ value: 2, name: '0px' },
|
||||
{ value: 3, name: '50px' },
|
||||
{ value: 4, name: '120px' },
|
||||
{ value: 5, name: '80rpx' },
|
||||
{ value: 6, name: 'none' }
|
||||
]
|
||||
|
||||
const data = reactive({
|
||||
maxWidth: '100px',
|
||||
maxWidthActual: '',
|
||||
maxWidthActualText: '',
|
||||
maxWidthActualImage: '',
|
||||
maxWidthActualFlat: '',
|
||||
maxWidthActualTextFlat: '',
|
||||
maxWidthActualImageFlat: ''
|
||||
})
|
||||
const viewRef = ref(null as UniElement | null)
|
||||
const textRef = ref(null as UniTextElement | null)
|
||||
const imageRef = ref(null as UniImageElement | null)
|
||||
const viewRefFlat = ref(null as UniElement | null)
|
||||
const textRefFlat = ref(null as UniTextElement | null)
|
||||
const imageRefFlat = ref(null as UniImageElement | null)
|
||||
|
||||
const getPropertyValues = () => {
|
||||
data.maxWidthActual = viewRef.value?.style.getPropertyValue('max-width') ?? ''
|
||||
data.maxWidthActualFlat = viewRefFlat.value?.style.getPropertyValue('max-width') ?? ''
|
||||
data.maxWidthActualText = textRef.value?.style.getPropertyValue('max-width') ?? ''
|
||||
data.maxWidthActualTextFlat = textRefFlat.value?.style.getPropertyValue('max-width') ?? ''
|
||||
data.maxWidthActualImage = imageRef.value?.style.getPropertyValue('max-width') ?? ''
|
||||
data.maxWidthActualImageFlat = imageRefFlat.value?.style.getPropertyValue('max-width') ?? ''
|
||||
}
|
||||
|
||||
|
||||
const changeMaxWidth = (value : string) => {
|
||||
data.maxWidth = value
|
||||
viewRef.value?.style.setProperty('max-width', value)
|
||||
viewRefFlat.value?.style.setProperty('max-width', value)
|
||||
textRef.value?.style.setProperty('max-width', value)
|
||||
textRefFlat.value?.style.setProperty('max-width', value)
|
||||
imageRef.value?.style.setProperty('max-width', value)
|
||||
imageRefFlat.value?.style.setProperty('max-width', value)
|
||||
// 使用 nextTick 确保样式已应用后再获取值
|
||||
nextTick(() => {
|
||||
getPropertyValues()
|
||||
})
|
||||
}
|
||||
|
||||
const radioChangeMaxWidth = (index : number) => {
|
||||
const selectedItem = maxWidthEnum.find((item) : boolean => item.value === index)
|
||||
if (selectedItem != null) {
|
||||
changeMaxWidth(selectedItem.name)
|
||||
}
|
||||
}
|
||||
|
||||
function inputChangeMaxWidth(value : string) {
|
||||
changeMaxWidth(value)
|
||||
}
|
||||
|
||||
onReady(() => {
|
||||
getPropertyValues()
|
||||
})
|
||||
|
||||
defineExpose({
|
||||
radioChangeMaxWidth,
|
||||
data
|
||||
})
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.common {
|
||||
width: 400px;
|
||||
height: 80px;
|
||||
background-color: cyan;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.common-view {
|
||||
width: 400px;
|
||||
height: 80px;
|
||||
background-color: cyan;
|
||||
}
|
||||
|
||||
.common-text {
|
||||
width: 50px;
|
||||
}
|
||||
|
||||
.common-dynamic {
|
||||
width: 100px;
|
||||
height: 80px;
|
||||
background-color: cyan;
|
||||
}
|
||||
|
||||
.test-container {
|
||||
flex-direction: row;
|
||||
justify-content: space-between;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.test-item {
|
||||
flex: 1;
|
||||
margin: 0 5px;
|
||||
}
|
||||
|
||||
.test-box {
|
||||
width: 100%;
|
||||
height: 80px;
|
||||
background-color: gray;
|
||||
}
|
||||
|
||||
.demo-box {
|
||||
flex-direction: row;
|
||||
margin-top: 10px;
|
||||
justify-content: space-around;
|
||||
}
|
||||
|
||||
.scroll-view-label {
|
||||
font-size: 12px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.demo-box-native {
|
||||
flex-direction: row;
|
||||
margin-top: 10px;
|
||||
justify-content: space-around;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.container-native {
|
||||
background-color: cyan;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,253 @@
|
||||
<template>
|
||||
<!-- #ifdef APP && !VUE3-VAPOR -->
|
||||
<scroll-view style="flex: 1">
|
||||
<!-- #endif -->
|
||||
<view style="flex-grow: 1;">
|
||||
<view>
|
||||
<text>min-height: 150px</text>
|
||||
<view class="common" style="min-height: 150px;">
|
||||
<text>height: 50px</text>
|
||||
</view>
|
||||
<text>拍平</text>
|
||||
<view class="common" style="min-height: 150px;" flatten>
|
||||
<text>height: 50px</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="uni-common-mt">
|
||||
<text class="uni-title-text">scroll-view 组件</text>
|
||||
</view>
|
||||
|
||||
<view class="demo-box">
|
||||
<scroll-view class="common" style="min-height: 100px; background-color: cyan;width:100px;">
|
||||
<text class="scroll-view-label">min-height: 100px</text>
|
||||
</scroll-view>
|
||||
<scroll-view class="common" style="min-height: 150px; background-color: cyan;width:100px;">
|
||||
<text class="scroll-view-label">min-height: 150px</text>
|
||||
</scroll-view>
|
||||
</view>
|
||||
|
||||
<view class="uni-common-mt">
|
||||
<text class="uni-title-text">setProperty 设置与 getPropertyValue 获取</text>
|
||||
</view>
|
||||
|
||||
<!-- 普通版本 -->
|
||||
<view class="test-container">
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">view 组件</text>
|
||||
<text class="uni-info">设置值: {{data.minHeight}}</text>
|
||||
<text class="uni-info">获取值: {{data.minHeightActual}}</text>
|
||||
<view class="test-box">
|
||||
<view ref="viewRef" class="common-dynamic test-view" :style="{ minHeight: data.minHeight }">
|
||||
<text>view</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">text 组件</text>
|
||||
<text class="uni-info">设置值: {{data.minHeight}}</text>
|
||||
<text class="uni-info">获取值: {{data.minHeightActualText}}</text>
|
||||
<view class="test-box">
|
||||
<text ref="textRef" class="common-dynamic test-text" :style="{ minHeight: data.minHeight }">text</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">image 组件</text>
|
||||
<text class="uni-info">设置值: {{data.minHeight}}</text>
|
||||
<text class="uni-info">获取值: {{data.minHeightActualImage}}</text>
|
||||
<view class="test-box">
|
||||
<image ref="imageRef" class="common-dynamic test-image" :style="{ minHeight: data.minHeight }"
|
||||
src="/static/test-image/logo.png"></image>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 拍平版本 -->
|
||||
<view class="test-container">
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">view 组件拍平</text>
|
||||
<text class="uni-info">设置值: {{data.minHeight}}</text>
|
||||
<text class="uni-info">获取值: {{data.minHeightActualFlat}}</text>
|
||||
<view class="test-box">
|
||||
<view ref="viewRefFlat" class="common-dynamic test-view-flatten" :style="{ minHeight: data.minHeight }"
|
||||
flatten>
|
||||
<text>view</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">text 组件拍平</text>
|
||||
<text class="uni-info">设置值: {{data.minHeight}}</text>
|
||||
<text class="uni-info">获取值: {{data.minHeightActualTextFlat}}</text>
|
||||
<view class="test-box">
|
||||
<text ref="textRefFlat" class="common-dynamic test-text-flatten" :style="{ minHeight: data.minHeight }"
|
||||
flatten>text</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">image 组件拍平</text>
|
||||
<text class="uni-info">设置值: {{data.minHeight}}</text>
|
||||
<text class="uni-info">获取值: {{data.minHeightActualImageFlat}}</text>
|
||||
<view class="test-box">
|
||||
<image ref="imageRefFlat" class="common-dynamic test-image-flatten" :style="{ minHeight: data.minHeight }"
|
||||
flatten src="/static/test-image/logo.png"></image>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="uni-common-mt uni-common-mb">
|
||||
<text class="uni-tips">第一个枚举值,'' (空字符串) - 空值情况</text>
|
||||
<enum-data :items="minHeightEnum" title="min-height 枚举值" @change="radioChangeMinHeight"
|
||||
:compact="true"></enum-data>
|
||||
<input-data :defaultValue="data.minHeight" title="min-height 自定义值" type="text"
|
||||
@confirm="inputChangeMinHeight"></input-data>
|
||||
</view>
|
||||
|
||||
<view class="uni-common-mb">
|
||||
<text>native-view组件: min-height: 100px 和 min-height: 150px</text>
|
||||
<view class="demo-box-native">
|
||||
<view class="container-native">
|
||||
<native-view style="min-height: 100px; width:100px; height: 50px;"></native-view>
|
||||
</view>
|
||||
<view class="container-native">
|
||||
<native-view style="min-height: 150px; width:100px; height: 50px;"></native-view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<!-- #ifdef APP && !VUE3-VAPOR -->
|
||||
</scroll-view>
|
||||
<!-- #endif -->
|
||||
</template>
|
||||
|
||||
<script setup lang="uts">
|
||||
import { ItemType } from '@/components/enum-data/enum-data-types'
|
||||
|
||||
const minHeightEnum : ItemType[] = [
|
||||
{ value: 0, name: '' },
|
||||
{ value: 1, name: '0' },
|
||||
{ value: 2, name: '0px' },
|
||||
{ value: 3, name: '50px' },
|
||||
{ value: 4, name: '150px' },
|
||||
{ value: 5, name: '80rpx' },
|
||||
]
|
||||
|
||||
const data = reactive({
|
||||
minHeight: '100px',
|
||||
minHeightActual: '',
|
||||
minHeightActualText: '',
|
||||
minHeightActualImage: '',
|
||||
minHeightActualFlat: '',
|
||||
minHeightActualTextFlat: '',
|
||||
minHeightActualImageFlat: ''
|
||||
})
|
||||
const viewRef = ref(null as UniElement | null)
|
||||
const textRef = ref(null as UniTextElement | null)
|
||||
const imageRef = ref(null as UniImageElement | null)
|
||||
const viewRefFlat = ref(null as UniElement | null)
|
||||
const textRefFlat = ref(null as UniTextElement | null)
|
||||
const imageRefFlat = ref(null as UniImageElement | null)
|
||||
|
||||
const getPropertyValues = () => {
|
||||
data.minHeightActual = viewRef.value?.style.getPropertyValue('min-height') ?? ''
|
||||
data.minHeightActualFlat = viewRefFlat.value?.style.getPropertyValue('min-height') ?? ''
|
||||
data.minHeightActualText = textRef.value?.style.getPropertyValue('min-height') ?? ''
|
||||
data.minHeightActualTextFlat = textRefFlat.value?.style.getPropertyValue('min-height') ?? ''
|
||||
data.minHeightActualImage = imageRef.value?.style.getPropertyValue('min-height') ?? ''
|
||||
data.minHeightActualImageFlat = imageRefFlat.value?.style.getPropertyValue('min-height') ?? ''
|
||||
}
|
||||
|
||||
|
||||
const changeMinHeight = (value : string) => {
|
||||
data.minHeight = value
|
||||
viewRef.value?.style.setProperty('min-height', value)
|
||||
viewRefFlat.value?.style.setProperty('min-height', value)
|
||||
textRef.value?.style.setProperty('min-height', value)
|
||||
textRefFlat.value?.style.setProperty('min-height', value)
|
||||
imageRef.value?.style.setProperty('min-height', value)
|
||||
imageRefFlat.value?.style.setProperty('min-height', value)
|
||||
// 使用 nextTick 确保样式已应用后再获取值
|
||||
nextTick(() => {
|
||||
getPropertyValues()
|
||||
})
|
||||
}
|
||||
|
||||
const radioChangeMinHeight = (index : number) => {
|
||||
const selectedItem = minHeightEnum.find((item) : boolean => item.value === index)
|
||||
if (selectedItem != null) {
|
||||
changeMinHeight(selectedItem.name)
|
||||
}
|
||||
}
|
||||
|
||||
const inputChangeMinHeight = (value : string) => {
|
||||
changeMinHeight(value)
|
||||
}
|
||||
|
||||
onReady(() => {
|
||||
getPropertyValues()
|
||||
})
|
||||
|
||||
defineExpose({
|
||||
radioChangeMinHeight,
|
||||
data
|
||||
})
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.common {
|
||||
width: 200px;
|
||||
height: 50px;
|
||||
background-color: cyan;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.common-dynamic {
|
||||
width: 100px;
|
||||
height: 50px;
|
||||
background-color: cyan;
|
||||
}
|
||||
|
||||
.test-container {
|
||||
flex-direction: row;
|
||||
justify-content: space-between;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.test-item {
|
||||
flex: 1;
|
||||
margin: 0 5px;
|
||||
}
|
||||
|
||||
.test-box {
|
||||
width: 100%;
|
||||
height: 150px;
|
||||
background-color: gray;
|
||||
}
|
||||
|
||||
.demo-box {
|
||||
flex-direction: row;
|
||||
margin-top: 10px;
|
||||
justify-content: space-around;
|
||||
}
|
||||
|
||||
.scroll-view-label {
|
||||
font-size: 12px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.demo-box-native {
|
||||
flex-direction: row;
|
||||
margin-top: 10px;
|
||||
justify-content: space-around;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.container-native {
|
||||
background-color: cyan;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,254 @@
|
||||
<template>
|
||||
<!-- #ifdef APP && !VUE3-VAPOR -->
|
||||
<scroll-view style="flex: 1">
|
||||
<!-- #endif -->
|
||||
<view style="flex-grow: 1;">
|
||||
<view>
|
||||
<text>min-width: 250px</text>
|
||||
<view class="common" style="min-width: 250px;">
|
||||
<text>width: 50px</text>
|
||||
</view>
|
||||
<text>拍平</text>
|
||||
<view class="common" style="min-width: 250px;" flatten>
|
||||
<text>width: 50px</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="uni-common-mt">
|
||||
<text class="uni-title-text">scroll-view 组件</text>
|
||||
</view>
|
||||
|
||||
<view class="demo-box">
|
||||
<scroll-view class="common" style="min-width: 100px; background-color: cyan;">
|
||||
<text class="scroll-view-label">min-width: 100px</text>
|
||||
</scroll-view>
|
||||
<scroll-view class="common" style="min-width: 200px; background-color: cyan;">
|
||||
<text class="scroll-view-label">min-width: 200px</text>
|
||||
</scroll-view>
|
||||
</view>
|
||||
|
||||
<view class="uni-common-mt">
|
||||
<text class="uni-title-text">setProperty 设置与 getPropertyValue 获取</text>
|
||||
</view>
|
||||
|
||||
<!-- 普通版本 -->
|
||||
<view class="test-container">
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">view 组件</text>
|
||||
<text class="uni-info">设置值: {{data.minWidth}}</text>
|
||||
<text class="uni-info">获取值: {{data.minWidthActual}}</text>
|
||||
<view class="test-box">
|
||||
<view ref="viewRef" class="common-dynamic test-view" :style="{ minWidth: data.minWidth }">
|
||||
<text>view</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">text 组件</text>
|
||||
<text class="uni-info">设置值: {{data.minWidth}}</text>
|
||||
<text class="uni-info">获取值: {{data.minWidthActualText}}</text>
|
||||
<view class="test-box">
|
||||
<text ref="textRef" class="common-dynamic test-text" :style="{ minWidth: data.minWidth }">text</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">image 组件</text>
|
||||
<text class="uni-info">设置值: {{data.minWidth}}</text>
|
||||
<text class="uni-info">获取值: {{data.minWidthActualImage}}</text>
|
||||
<view class="test-box">
|
||||
<image ref="imageRef" class="common-dynamic test-image" :style="{ minWidth: data.minWidth }"
|
||||
src="/static/test-image/logo.png"></image>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 拍平版本 -->
|
||||
<view class="test-container">
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">view 组件拍平</text>
|
||||
<text class="uni-info">设置值: {{data.minWidth}}</text>
|
||||
<text class="uni-info">获取值: {{data.minWidthActualFlat}}</text>
|
||||
<view class="test-box">
|
||||
<view ref="viewRefFlat" class="common-dynamic test-view-flatten" :style="{ minWidth: data.minWidth }"
|
||||
flatten>
|
||||
<text>view</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">text 组件拍平</text>
|
||||
<text class="uni-info">设置值: {{data.minWidth}}</text>
|
||||
<text class="uni-info">获取值: {{data.minWidthActualTextFlat}}</text>
|
||||
<view class="test-box">
|
||||
<text ref="textRefFlat" class="common-dynamic test-text-flatten" :style="{ minWidth: data.minWidth }"
|
||||
flatten>text</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">image 组件拍平</text>
|
||||
<text class="uni-info">设置值: {{data.minWidth}}</text>
|
||||
<text class="uni-info">获取值: {{data.minWidthActualImageFlat}}</text>
|
||||
<view class="test-box">
|
||||
<image ref="imageRefFlat" class="common-dynamic test-image-flatten" :style="{ minWidth: data.minWidth }"
|
||||
flatten src="/static/test-image/logo.png"></image>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="uni-common-mt uni-common-mb">
|
||||
<text class="uni-tips">第一个枚举值,'' (空字符串) - 空值情况</text>
|
||||
<enum-data :items="minWidthEnum" title="min-width 枚举值" @change="radioChangeMinWidth"
|
||||
:compact="true"></enum-data>
|
||||
<input-data :defaultValue="data.minWidth" title="min-width 自定义值" type="text"
|
||||
@confirm="inputChangeMinWidth"></input-data>
|
||||
</view>
|
||||
|
||||
<view class="uni-common-mb">
|
||||
<text>native-view组件: min-width: 100px 和 min-width: 200px</text>
|
||||
<view class="demo-box-native">
|
||||
<view class="container-native" style="background-color: green;">
|
||||
<native-view style="min-width: 100px; height: 100px;"></native-view>
|
||||
</view>
|
||||
<view class="container-native" style="background-color: red;">
|
||||
<native-view style="min-width: 200px; height: 100px;"></native-view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<!-- #ifdef APP && !VUE3-VAPOR -->
|
||||
</scroll-view>
|
||||
<!-- #endif -->
|
||||
</template>
|
||||
|
||||
<script setup lang="uts">
|
||||
import { ItemType } from '@/components/enum-data/enum-data-types'
|
||||
|
||||
const minWidthEnum : ItemType[] = [
|
||||
{ value: 0, name: '' },
|
||||
{ value: 1, name: '0' },
|
||||
{ value: 2, name: '0px' },
|
||||
{ value: 3, name: '80px' },
|
||||
{ value: 4, name: '120px' },
|
||||
{ value: 5, name: '80rpx' },
|
||||
]
|
||||
|
||||
const data = reactive({
|
||||
minWidth: '100px',
|
||||
minWidthActual: '',
|
||||
minWidthActualText: '',
|
||||
minWidthActualImage: '',
|
||||
minWidthActualFlat: '',
|
||||
minWidthActualTextFlat: '',
|
||||
minWidthActualImageFlat: ''
|
||||
})
|
||||
const viewRef = ref(null as UniElement | null)
|
||||
const textRef = ref(null as UniTextElement | null)
|
||||
const imageRef = ref(null as UniImageElement | null)
|
||||
const viewRefFlat = ref(null as UniElement | null)
|
||||
const textRefFlat = ref(null as UniTextElement | null)
|
||||
const imageRefFlat = ref(null as UniImageElement | null)
|
||||
|
||||
const getPropertyValues = () => {
|
||||
data.minWidthActual = viewRef.value?.style.getPropertyValue('min-width') ?? ''
|
||||
data.minWidthActualFlat = viewRefFlat.value?.style.getPropertyValue('min-width') ?? ''
|
||||
data.minWidthActualText = textRef.value?.style.getPropertyValue('min-width') ?? ''
|
||||
data.minWidthActualTextFlat = textRefFlat.value?.style.getPropertyValue('min-width') ?? ''
|
||||
data.minWidthActualImage = imageRef.value?.style.getPropertyValue('min-width') ?? ''
|
||||
data.minWidthActualImageFlat = imageRefFlat.value?.style.getPropertyValue('min-width') ?? ''
|
||||
}
|
||||
|
||||
|
||||
const changeMinWidth = (value : string) => {
|
||||
data.minWidth = value
|
||||
viewRef.value?.style.setProperty('min-width', value)
|
||||
viewRefFlat.value?.style.setProperty('min-width', value)
|
||||
textRef.value?.style.setProperty('min-width', value)
|
||||
textRefFlat.value?.style.setProperty('min-width', value)
|
||||
imageRef.value?.style.setProperty('min-width', value)
|
||||
imageRefFlat.value?.style.setProperty('min-width', value)
|
||||
// 使用 nextTick 确保样式已应用后再获取值
|
||||
nextTick(() => {
|
||||
getPropertyValues()
|
||||
})
|
||||
}
|
||||
|
||||
const radioChangeMinWidth = (index : number) => {
|
||||
console.log('index', index)
|
||||
const selectedItem = minWidthEnum.find((item) : boolean => item.value === index)
|
||||
if (selectedItem != null) {
|
||||
changeMinWidth(selectedItem.name)
|
||||
}
|
||||
}
|
||||
|
||||
const inputChangeMinWidth = (value : string) => {
|
||||
changeMinWidth(value)
|
||||
}
|
||||
|
||||
onReady(() => {
|
||||
getPropertyValues()
|
||||
})
|
||||
|
||||
defineExpose({
|
||||
radioChangeMinWidth,
|
||||
data
|
||||
})
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.common {
|
||||
width: 50px;
|
||||
height: 80px;
|
||||
background-color: cyan;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.common-dynamic {
|
||||
width: 50px;
|
||||
height: 80px;
|
||||
background-color: cyan;
|
||||
}
|
||||
|
||||
.test-container {
|
||||
flex-direction: row;
|
||||
justify-content: space-between;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.test-item {
|
||||
flex: 1;
|
||||
margin: 0 5px;
|
||||
}
|
||||
|
||||
.test-box {
|
||||
width: 100%;
|
||||
height: 80px;
|
||||
background-color: gray;
|
||||
}
|
||||
|
||||
.demo-box {
|
||||
flex-direction: row;
|
||||
margin-top: 10px;
|
||||
justify-content: space-around;
|
||||
}
|
||||
|
||||
.scroll-view-label {
|
||||
font-size: 12px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.demo-box-native {
|
||||
flex-direction: row;
|
||||
margin-top: 10px;
|
||||
justify-content: space-around;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.container-native {
|
||||
background-color: cyan;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,277 @@
|
||||
<template>
|
||||
<!-- #ifdef APP && !VUE3-VAPOR -->
|
||||
<scroll-view style="flex: 1">
|
||||
<!-- #endif -->
|
||||
<view style="flex-grow: 1;">
|
||||
<view class="demo-row">
|
||||
<view class="demo-item">
|
||||
<text>opacity: 1 (默认值)</text>
|
||||
<view class="common" style="opacity: 1;"></view>
|
||||
</view>
|
||||
<view class="demo-item">
|
||||
<text>拍平</text>
|
||||
<view class="common" style="opacity: 1;" flatten></view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="demo-row uni-common-mt">
|
||||
<view class="demo-item">
|
||||
<text>opacity: 0.8</text>
|
||||
<view class="common" style="opacity: 0.8;"></view>
|
||||
</view>
|
||||
<view class="demo-item">
|
||||
<text>拍平</text>
|
||||
<view class="common" style="opacity: 0.8;" flatten></view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="demo-row uni-common-mt">
|
||||
<view class="demo-item">
|
||||
<text>opacity: 0.5</text>
|
||||
<view class="common" style="opacity: 0.5;"></view>
|
||||
</view>
|
||||
<view class="demo-item">
|
||||
<text>拍平</text>
|
||||
<view class="common" style="opacity: 0.5;" flatten></view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="demo-row uni-common-mt">
|
||||
<view class="demo-item">
|
||||
<text>opacity: 0.2</text>
|
||||
<view class="common" style="opacity: 0.2;"></view>
|
||||
</view>
|
||||
<view class="demo-item">
|
||||
<text>拍平</text>
|
||||
<view class="common" style="opacity: 0.2;" flatten></view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="demo-row uni-common-mt">
|
||||
<view class="demo-item">
|
||||
<text>opacity: 0</text>
|
||||
<view class="common" style="opacity: 0;"></view>
|
||||
</view>
|
||||
<view class="demo-item">
|
||||
<text>拍平</text>
|
||||
<view class="common" style="opacity: 0;" flatten></view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<text class="uni-title-text uni-common-mt">scroll-view 组件</text>
|
||||
|
||||
<view class="demo-row uni-common-mt">
|
||||
<view class="demo-item">
|
||||
<text>opacity: 0.5</text>
|
||||
<scroll-view class="common" style="opacity: 0.5;"></scroll-view>
|
||||
</view>
|
||||
<view class="demo-item">
|
||||
<text>opacity: 0.2</text>
|
||||
<scroll-view class="common" style="opacity: 0.2;"></scroll-view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="uni-common-mt">
|
||||
<text class="uni-title-text">setProperty 设置与 getPropertyValue 获取</text>
|
||||
</view>
|
||||
|
||||
<!-- 普通版本 -->
|
||||
<view class="test-container">
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">view 组件</text>
|
||||
<text class="uni-info">设置值: {{data.opacity}}</text>
|
||||
<text class="uni-info">获取值: {{data.opacityActual}}</text>
|
||||
<view class="test-box">
|
||||
<view ref="viewRef" class="common test-view" :style="{ opacity: data.opacity }">
|
||||
<text class="common-text">view</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">text 组件</text>
|
||||
<text class="uni-info">设置值: {{data.opacity}}</text>
|
||||
<text class="uni-info">获取值: {{data.opacityActualText}}</text>
|
||||
<view class="test-box">
|
||||
<text ref="textRef" class="common test-text" :style="{ opacity: data.opacity }">text</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">image 组件</text>
|
||||
<text class="uni-info">设置值: {{data.opacity}}</text>
|
||||
<text class="uni-info">获取值: {{data.opacityActualImage}}</text>
|
||||
<view class="test-box">
|
||||
<image ref="imageRef" class="common test-image" :style="{ opacity: data.opacity }" src="/static/test-image/logo.png"></image>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 拍平版本 -->
|
||||
<view class="test-container">
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">view 组件拍平</text>
|
||||
<text class="uni-info">设置值: {{data.opacity}}</text>
|
||||
<text class="uni-info">获取值: {{data.opacityActualFlat}}</text>
|
||||
<view class="test-box">
|
||||
<view ref="viewRefFlat" class="common test-view-flatten" :style="{ opacity: data.opacity }" flatten>
|
||||
<text class="common-text">view</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">text 组件拍平</text>
|
||||
<text class="uni-info">设置值: {{data.opacity}}</text>
|
||||
<text class="uni-info">获取值: {{data.opacityActualTextFlat}}</text>
|
||||
<view class="test-box">
|
||||
<text ref="textRefFlat" class="common test-text-flatten" :style="{ opacity: data.opacity }" flatten>text</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">image 组件拍平</text>
|
||||
<text class="uni-info">设置值: {{data.opacity}}</text>
|
||||
<text class="uni-info">获取值: {{data.opacityActualImageFlat}}</text>
|
||||
<view class="test-box">
|
||||
<image ref="imageRefFlat" class="common test-image-flatten" :style="{ opacity: data.opacity }" flatten src="/static/test-image/logo.png"></image>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="uni-common-mt uni-common-mb">
|
||||
<text class="uni-tips">第一个枚举值,'' (空字符串) - 空值情况</text>
|
||||
<enum-data :items="opacityEnum" title="opacity 枚举值" @change="radioChangeOpacity" :compact="true"></enum-data>
|
||||
<input-data :defaultValue="data.opacity" title="opacity 自定义值" type="text" @confirm="inputChangeOpacity"></input-data>
|
||||
</view>
|
||||
|
||||
<view class="uni-common-mb">
|
||||
<text>native-view组件: opacity: 0.5 和 opacity: 0.2</text>
|
||||
<view class="demo-row uni-common-mt">
|
||||
<view class="demo-item">
|
||||
<text>opacity: 0.5</text>
|
||||
<test-native-view class="common" style="opacity: 0.5;"></test-native-view>
|
||||
</view>
|
||||
<view class="demo-item">
|
||||
<text>opacity: 0.2</text>
|
||||
<test-native-view class="common" style="opacity: 0.2;"></test-native-view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<!-- #ifdef APP && !VUE3-VAPOR -->
|
||||
</scroll-view>
|
||||
<!-- #endif -->
|
||||
</template>
|
||||
|
||||
<script setup lang="uts">
|
||||
import { ItemType } from '@/components/enum-data/enum-data-types'
|
||||
|
||||
const opacityEnum : ItemType[] = [
|
||||
{ value: 0, name: '' },
|
||||
{ value: 1, name: '0' },
|
||||
{ value: 2, name: '0.2' },
|
||||
{ value: 3, name: '0.5' },
|
||||
{ value: 4, name: '0.8' },
|
||||
{ value: 5, name: '1' }
|
||||
]
|
||||
|
||||
const data = reactive({
|
||||
opacity: '1',
|
||||
opacityActual: '',
|
||||
opacityActualText: '',
|
||||
opacityActualImage: '',
|
||||
opacityActualFlat: '',
|
||||
opacityActualTextFlat: '',
|
||||
opacityActualImageFlat: ''
|
||||
})
|
||||
const viewRef = ref(null as UniElement | null)
|
||||
const textRef = ref(null as UniTextElement | null)
|
||||
const imageRef = ref(null as UniImageElement | null)
|
||||
const viewRefFlat = ref(null as UniElement | null)
|
||||
const textRefFlat = ref(null as UniTextElement | null)
|
||||
const imageRefFlat = ref(null as UniImageElement | null)
|
||||
|
||||
const getPropertyValues = () => {
|
||||
data.opacityActual = viewRef.value?.style.getPropertyValue('opacity') ?? ''
|
||||
data.opacityActualFlat = viewRefFlat.value?.style.getPropertyValue('opacity') ?? ''
|
||||
data.opacityActualText = textRef.value?.style.getPropertyValue('opacity') ?? ''
|
||||
data.opacityActualTextFlat = textRefFlat.value?.style.getPropertyValue('opacity') ?? ''
|
||||
data.opacityActualImage = imageRef.value?.style.getPropertyValue('opacity') ?? ''
|
||||
data.opacityActualImageFlat = imageRefFlat.value?.style.getPropertyValue('opacity') ?? ''
|
||||
}
|
||||
|
||||
|
||||
const changeOpacity = (value : string) => {
|
||||
data.opacity = value
|
||||
viewRef.value?.style.setProperty('opacity', value)
|
||||
viewRefFlat.value?.style.setProperty('opacity', value)
|
||||
textRef.value?.style.setProperty('opacity', value)
|
||||
textRefFlat.value?.style.setProperty('opacity', value)
|
||||
imageRef.value?.style.setProperty('opacity', value)
|
||||
imageRefFlat.value?.style.setProperty('opacity', value)
|
||||
// 使用 nextTick 确保样式已应用后再获取值
|
||||
nextTick(() => {
|
||||
getPropertyValues()
|
||||
})
|
||||
}
|
||||
|
||||
const radioChangeOpacity = (index : number) => {
|
||||
const selectedItem = opacityEnum.find((item) : boolean => item.value === index)
|
||||
if (selectedItem != null) {
|
||||
changeOpacity(selectedItem.name)
|
||||
}
|
||||
}
|
||||
|
||||
const inputChangeOpacity = (value : string) => {
|
||||
changeOpacity(value)
|
||||
}
|
||||
|
||||
onReady(() => {
|
||||
getPropertyValues()
|
||||
})
|
||||
|
||||
defineExpose({
|
||||
radioChangeOpacity,
|
||||
data
|
||||
})
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.demo-row {
|
||||
flex-direction: row;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.demo-item {
|
||||
flex: 1;
|
||||
margin: 0 5px;
|
||||
}
|
||||
|
||||
.common {
|
||||
width: 80px;
|
||||
height: 80px;
|
||||
background-color: blue;
|
||||
}
|
||||
|
||||
.common-text {
|
||||
width: 50px;
|
||||
}
|
||||
|
||||
.test-container {
|
||||
flex-direction: row;
|
||||
justify-content: space-between;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.test-item {
|
||||
flex: 1;
|
||||
margin: 0 5px;
|
||||
}
|
||||
|
||||
.test-box {
|
||||
width: 100%;
|
||||
height: 80px;
|
||||
background-color: gray;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,414 @@
|
||||
<template>
|
||||
<!-- #ifdef APP && !VUE3-VAPOR -->
|
||||
<scroll-view style="flex: 1">
|
||||
<!-- #endif -->
|
||||
<view style="flex-grow: 1">
|
||||
<view class="common-box">
|
||||
<view>
|
||||
<view class="title-container">
|
||||
<text class="uni-title-text uni-common-mt">position: fixed</text>
|
||||
</view>
|
||||
<scroll-view class="test-scroll-view">
|
||||
<view class="test-block red"></view>
|
||||
<view class="common fixed" style="position: fixed">
|
||||
<text class="text">fixed</text>
|
||||
</view>
|
||||
<view class="common fixed" style="position: fixed" flatten>
|
||||
<text class="text">fixed(拍平)</text>
|
||||
</view>
|
||||
<view class="test-block blue"></view>
|
||||
<view class="test-block red"></view>
|
||||
<view class="test-block green"></view>
|
||||
<view class="test-block blue"></view>
|
||||
<view class="test-block red"></view>
|
||||
<view class="test-block green"></view>
|
||||
<view class="test-block blue"></view>
|
||||
</scroll-view>
|
||||
</view>
|
||||
<view>
|
||||
<view class="title-container">
|
||||
<text class="uni-subtitle-text">(四方向组合: top + left + bottom + right)</text>
|
||||
</view>
|
||||
<scroll-view class="test-scroll-view">
|
||||
<view class="test-block red"></view>
|
||||
<view class="common combo-all-sides fixed-combo" style="position: fixed">
|
||||
<text class="text">fixed 四方向</text>
|
||||
</view>
|
||||
<view class="common combo-all-sides fixed-combo" style="position: fixed" flatten>
|
||||
<text class="text">fixed 四方向(拍平)</text>
|
||||
</view>
|
||||
<view class="test-block blue"></view>
|
||||
<view class="test-block red"></view>
|
||||
<view class="test-block green"></view>
|
||||
<view class="test-block blue"></view>
|
||||
<view class="test-block red"></view>
|
||||
<view class="test-block green"></view>
|
||||
<view class="test-block blue"></view>
|
||||
</scroll-view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="common-box">
|
||||
<view>
|
||||
<view class="title-container">
|
||||
<text class="uni-title-text uni-common-mt">position: absolute</text>
|
||||
</view>
|
||||
<scroll-view class="test-scroll-view">
|
||||
<view class="test-block red"></view>
|
||||
<view class="common" style="position: absolute">
|
||||
<text class="text">absolute</text>
|
||||
</view>
|
||||
<view class="common" style="position: absolute" flatten>
|
||||
<text class="text">absolute(拍平)</text>
|
||||
</view>
|
||||
<view class="test-block blue"></view>
|
||||
<view class="test-block red"></view>
|
||||
<view class="test-block green"></view>
|
||||
<view class="test-block blue"></view>
|
||||
<view class="test-block red"></view>
|
||||
<view class="test-block green"></view>
|
||||
<view class="test-block blue"></view>
|
||||
</scroll-view>
|
||||
</view>
|
||||
<view>
|
||||
<view class="title-container">
|
||||
<text class="uni-subtitle-text">(四方向组合: top + left + bottom + right)</text>
|
||||
</view>
|
||||
<scroll-view class="test-scroll-view">
|
||||
<view class="test-block red"></view>
|
||||
<view class="common combo-all-sides-container" style="position: absolute">
|
||||
<text class="text">absolute 四方向</text>
|
||||
</view>
|
||||
<view class="common combo-all-sides-container" style="position: absolute" flatten>
|
||||
<text class="text">absolute 四方向(拍平)</text>
|
||||
</view>
|
||||
<view class="test-block blue"></view>
|
||||
<view class="test-block red"></view>
|
||||
<view class="test-block green"></view>
|
||||
<view class="test-block blue"></view>
|
||||
<view class="test-block red"></view>
|
||||
<view class="test-block green"></view>
|
||||
<view class="test-block blue"></view>
|
||||
</scroll-view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="common-box">
|
||||
<view>
|
||||
<view class="title-container">
|
||||
<text class="uni-title-text uni-common-mt">position: relative</text>
|
||||
</view>
|
||||
<scroll-view class="test-scroll-view">
|
||||
<view class="test-block red"></view>
|
||||
<view class="common" style="position: relative">
|
||||
<text class="text">relative</text>
|
||||
</view>
|
||||
<view class="common" style="position: relative" flatten>
|
||||
<text class="text">relative(拍平)</text>
|
||||
</view>
|
||||
<view class="test-block blue"></view>
|
||||
<view class="test-block red"></view>
|
||||
<view class="test-block green"></view>
|
||||
<view class="test-block blue"></view>
|
||||
<view class="test-block red"></view>
|
||||
<view class="test-block green"></view>
|
||||
<view class="test-block blue"></view>
|
||||
</scroll-view>
|
||||
</view>
|
||||
<view>
|
||||
<view class="title-container">
|
||||
<text class="uni-subtitle-text uni-common-mt">(四方向组合: top + left + bottom + right)</text>
|
||||
</view>
|
||||
<scroll-view class="test-scroll-view">
|
||||
<view class="test-block red"></view>
|
||||
<view class="common combo-all-sides-container" style="position: relative">
|
||||
<text class="text">relative 四方向</text>
|
||||
</view>
|
||||
<view class="common combo-all-sides-container" style="position: relative" flatten>
|
||||
<text class="text">relative 四方向(拍平)</text>
|
||||
</view>
|
||||
<view class="test-block blue"></view>
|
||||
<view class="test-block red"></view>
|
||||
<view class="test-block green"></view>
|
||||
<view class="test-block blue"></view>
|
||||
<view class="test-block red"></view>
|
||||
<view class="test-block green"></view>
|
||||
<view class="test-block blue"></view>
|
||||
</scroll-view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="uni-common-mb">
|
||||
<text class="uni-title-text uni-common-mt">scroll-view 组件</text>
|
||||
<text class="uni-subtitle-text">position: relative 和 position: absolute</text>
|
||||
<view class="position-test-box">
|
||||
<scroll-view class="scroll-view-common" style="position: relative; top: 20px; left: 20px; background-color: cyan;">
|
||||
<text>relative</text>
|
||||
</scroll-view>
|
||||
<scroll-view class="scroll-view-common" style="position: absolute; top: 65px; left: 65px; background-color: green;">
|
||||
<text>absolute</text>
|
||||
</scroll-view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="uni-common-mt">
|
||||
<text class="uni-title-text">setProperty 设置与 getPropertyValue 获取</text>
|
||||
</view>
|
||||
|
||||
<view class="test-container">
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">view 组件</text>
|
||||
<text class="uni-info">设置值: {{data.position}}</text>
|
||||
<text class="uni-info">获取值: {{data.positionActual}}</text>
|
||||
<view class="test-box">
|
||||
<view class="test-block-small red"></view>
|
||||
<view ref="viewRef" class="common-dynamic test-view" style="top: 10px; left: 10px;" :style="{ position: data.position }">
|
||||
<text style="font-size: 10px;">view</text>
|
||||
</view>
|
||||
<view class="test-block-small blue"></view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">text 组件</text>
|
||||
<text class="uni-info">设置值: {{data.position}}</text>
|
||||
<text class="uni-info">获取值: {{data.positionActualText}}</text>
|
||||
<view class="test-box">
|
||||
<text class="test-block-small red test-block-small-text">红</text>
|
||||
<text ref="textRef" class="common-dynamic common-text-dynamic test-text" style="top: 10px; left: 10px;" :style="{ position: data.position }">text</text>
|
||||
<text class="test-block-small blue test-block-small-text">蓝</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">image 组件</text>
|
||||
<text class="uni-info">设置值: {{data.position}}</text>
|
||||
<text class="uni-info">获取值: {{data.positionActualImage}}</text>
|
||||
<view class="test-box">
|
||||
<image class="common-image-static" src="/static/test-image/logo.png"></image>
|
||||
<image ref="imageRef" class="common-dynamic test-image" style="top: 10px; left: 10px;" :style="{ position: data.position }" src="/static/test-image/logo.png"></image>
|
||||
<image class="common-image-static" src="/static/test-image/logo.png"></image>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="uni-common-mt uni-common-mb">
|
||||
<text class="uni-tips">第一个枚举值,'' (空字符串) - 空值情况</text>
|
||||
<enum-data :items="positionEnum" title="position 枚举值" @change="radioChangePosition" :compact="true"></enum-data>
|
||||
<input-data :defaultValue="data.position" title="position 自定义值" type="text" @confirm="inputChangePosition"></input-data>
|
||||
</view>
|
||||
|
||||
<view class="uni-common-mb">
|
||||
<text>native-view组件: position: relative 和 position: absolute</text>
|
||||
<view class="position-test-box">
|
||||
<test-native-view class="scroll-view-common" style="position: relative; top: 20px; left: 20px; background-color: cyan;"></test-native-view>
|
||||
<test-native-view class="scroll-view-common" style="position: absolute; top: 65px; left: 65px; background-color: green;"></test-native-view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<!-- #ifdef APP && !VUE3-VAPOR -->
|
||||
</scroll-view>
|
||||
<!-- #endif -->
|
||||
|
||||
</template>
|
||||
|
||||
<script setup lang="uts">
|
||||
import { ItemType } from '@/components/enum-data/enum-data-types'
|
||||
|
||||
const positionEnum : ItemType[] = [
|
||||
{ value: 0, name: '' },
|
||||
{ value: 1, name: 'static' },
|
||||
{ value: 2, name: 'relative' },
|
||||
{ value: 3, name: 'absolute' },
|
||||
{ value: 4, name: 'fixed' }
|
||||
]
|
||||
|
||||
const data = reactive({
|
||||
position: 'relative',
|
||||
positionActual: '',
|
||||
positionActualText: '',
|
||||
positionActualImage: ''
|
||||
})
|
||||
const viewRef = ref(null as UniElement | null)
|
||||
const textRef = ref(null as UniTextElement | null)
|
||||
const imageRef = ref(null as UniImageElement | null)
|
||||
|
||||
const getPropertyValues = () => {
|
||||
data.positionActual = viewRef.value?.style.getPropertyValue('position') ?? ''
|
||||
data.positionActualText = textRef.value?.style.getPropertyValue('position') ?? ''
|
||||
data.positionActualImage = imageRef.value?.style.getPropertyValue('position') ?? ''
|
||||
}
|
||||
|
||||
|
||||
const changePosition = (value : string) => {
|
||||
data.position = value
|
||||
viewRef.value?.style.setProperty('position', value)
|
||||
textRef.value?.style.setProperty('position', value)
|
||||
imageRef.value?.style.setProperty('position', value)
|
||||
// 使用 nextTick 确保样式已应用后再获取值
|
||||
nextTick(() => {
|
||||
getPropertyValues()
|
||||
})
|
||||
}
|
||||
|
||||
const radioChangePosition = (index : number) => {
|
||||
const selectedItem = positionEnum.find((item) : boolean => item.value === index)
|
||||
if (selectedItem != null) {
|
||||
changePosition(selectedItem.name)
|
||||
}
|
||||
}
|
||||
|
||||
const inputChangePosition = (value : string) => {
|
||||
changePosition(value)
|
||||
}
|
||||
|
||||
onReady(() => {
|
||||
getPropertyValues()
|
||||
})
|
||||
|
||||
defineExpose({
|
||||
radioChangePosition,
|
||||
data
|
||||
})
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.common-box {
|
||||
flex-direction: row;
|
||||
justify-content: space-around;
|
||||
}
|
||||
|
||||
.title-container {
|
||||
width: 180px;
|
||||
height: 45px;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.common {
|
||||
width: 80px;
|
||||
height: 50px;
|
||||
background-color: green;
|
||||
top: 60px;
|
||||
left: 30px;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.fixed {
|
||||
/* #ifdef WEB*/
|
||||
top: calc(var(--uni-safe-area-inset-top) + 60px);
|
||||
left: calc(var(--uni-safe-area-inset-left) + 30px);
|
||||
/* #endif */
|
||||
}
|
||||
|
||||
.text {
|
||||
width: 100%;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.test-block {
|
||||
width: 50px;
|
||||
height: 50px;
|
||||
}
|
||||
|
||||
.test-block-small {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
}
|
||||
|
||||
.test-block-small-text {
|
||||
font-size: 10px;
|
||||
}
|
||||
|
||||
.red {
|
||||
background-color: red;
|
||||
}
|
||||
|
||||
.blue {
|
||||
background-color: blue;
|
||||
}
|
||||
|
||||
.green {
|
||||
background-color: green;
|
||||
}
|
||||
|
||||
.test-scroll-view {
|
||||
width: 180px;
|
||||
height: 200px;
|
||||
background-color: gray;
|
||||
}
|
||||
|
||||
.combo-all-sides {
|
||||
top: 60px;
|
||||
left: 45%;
|
||||
bottom: 40px;
|
||||
right: 40px;
|
||||
}
|
||||
|
||||
.fixed-combo {
|
||||
/* #ifdef WEB*/
|
||||
top: calc(var(--uni-safe-area-inset-top) + 60px);
|
||||
left: calc(var(--uni-safe-area-inset-left) + 45%);
|
||||
bottom: calc(var(--uni-safe-area-inset-bottom) + 40px);
|
||||
right: calc(var(--uni-safe-area-inset-right) + 40px);
|
||||
/* #endif */
|
||||
}
|
||||
|
||||
.combo-all-sides-container {
|
||||
top: 60px;
|
||||
left: 30px;
|
||||
bottom: 40px;
|
||||
right: 30px;
|
||||
}
|
||||
|
||||
.common-dynamic {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
background-color: green;
|
||||
}
|
||||
|
||||
.common-text-dynamic {
|
||||
background-color: green;
|
||||
color: white;
|
||||
font-size: 10px;
|
||||
padding: 5px;
|
||||
}
|
||||
|
||||
.common-image-static {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
background-color: rgba(255, 0, 0, 0.3);
|
||||
}
|
||||
|
||||
.test-container {
|
||||
flex-direction: row;
|
||||
justify-content: space-between;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.test-item {
|
||||
flex: 1;
|
||||
margin: 0 5px;
|
||||
}
|
||||
|
||||
.test-box {
|
||||
width: 100%;
|
||||
height: 120px;
|
||||
background-color: gray;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.position-test-box {
|
||||
position: relative;
|
||||
width: 200px;
|
||||
height: 150px;
|
||||
background-color: #f5f5f5;
|
||||
border: 1px solid #ddd;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.scroll-view-common {
|
||||
width: 80px;
|
||||
height: 60px;
|
||||
}
|
||||
</style>
|
||||
280
mpuniapp/pages/CSS/layout/right.uvue
普通文件
280
mpuniapp/pages/CSS/layout/right.uvue
普通文件
@@ -0,0 +1,280 @@
|
||||
<template>
|
||||
<!-- #ifdef APP && !VUE3-VAPOR -->
|
||||
<scroll-view style="flex: 1">
|
||||
<!-- #endif -->
|
||||
<view style="flex-grow: 1;">
|
||||
<view class="uni-common-mb">
|
||||
<text class="uni-title-text">right: 20px (距离右边 20px) - 右侧:拍平</text>
|
||||
<view class="test-container">
|
||||
<view class="example-box">
|
||||
<view class="common" style="right: 20px;"></view>
|
||||
</view>
|
||||
<view class="example-box">
|
||||
<view class="common" style="right: 20px;" flatten></view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="uni-common-mb">
|
||||
<text class="uni-title-text">right: 20rpx (距离右边 20rpx) - 右侧:拍平</text>
|
||||
<view class="test-container">
|
||||
<view class="example-box">
|
||||
<view class="common" style="right: 20rpx;"></view>
|
||||
</view>
|
||||
<view class="example-box">
|
||||
<view class="common" style="right: 20rpx;" flatten></view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="uni-common-mb">
|
||||
<text class="uni-title-text">right: 20% (距离右边 20%) - 右侧:拍平</text>
|
||||
<view class="test-container">
|
||||
<view class="example-box">
|
||||
<view class="common" style="right: 20%;"></view>
|
||||
</view>
|
||||
<view class="example-box">
|
||||
<view class="common" style="right: 20%;" flatten></view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="uni-common-mb">
|
||||
<text class="uni-title-text">right: auto (自动,默认左边对齐) - 右侧:拍平</text>
|
||||
<view class="test-container">
|
||||
<view class="example-box">
|
||||
<view class="common" style="right: auto;"></view>
|
||||
</view>
|
||||
<view class="example-box">
|
||||
<view class="common" style="right: auto;" flatten></view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<text class="uni-title-text uni-common-mt">scroll-view 组件</text>
|
||||
|
||||
<view class="uni-common-mb">
|
||||
<text class="uni-subtitle-text">right: 10% 和 right: 30px</text>
|
||||
<view class="test-container">
|
||||
<view class="example-box">
|
||||
<scroll-view class="common" style="right: 10%;"></scroll-view>
|
||||
</view>
|
||||
<view class="example-box">
|
||||
<scroll-view class="common" style="right: 30px;"></scroll-view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="uni-common-mt">
|
||||
<text class="uni-title-text">setProperty 设置与 getPropertyValue 获取</text>
|
||||
</view>
|
||||
|
||||
<!-- 普通版本 -->
|
||||
<view class="test-container">
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">view 组件</text>
|
||||
<text class="uni-info">设置值: {{data.right}}</text>
|
||||
<text class="uni-info">获取值: {{data.rightActual}}</text>
|
||||
<view class="test-box">
|
||||
<view ref="viewRef" class="common test-view" :style="{ right: data.right }">
|
||||
<text class="common-text">view</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">text 组件</text>
|
||||
<text class="uni-info">设置值: {{data.right}}</text>
|
||||
<text class="uni-info">获取值: {{data.rightActualText}}</text>
|
||||
<view class="test-box">
|
||||
<text ref="textRef" class="common common-text test-text" :style="{ right: data.right }">text</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">image 组件</text>
|
||||
<text class="uni-info">设置值: {{data.right}}</text>
|
||||
<text class="uni-info">获取值: {{data.rightActualImage}}</text>
|
||||
<view class="test-box">
|
||||
<image ref="imageRef" class="common test-image" :style="{ right: data.right }" src="/static/test-image/logo.png"></image>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 拍平版本 -->
|
||||
<view class="test-container">
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">view 组件拍平</text>
|
||||
<text class="uni-info">设置值: {{data.right}}</text>
|
||||
<text class="uni-info">获取值: {{data.rightActualFlat}}</text>
|
||||
<view class="test-box">
|
||||
<view ref="viewRefFlat" class="common test-view-flatten" :style="{ right: data.right }" flatten>
|
||||
<text class="common-text">view</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">text 组件拍平</text>
|
||||
<text class="uni-info">设置值: {{data.right}}</text>
|
||||
<text class="uni-info">获取值: {{data.rightActualTextFlat}}</text>
|
||||
<view class="test-box">
|
||||
<text ref="textRefFlat" class="common common-text test-text-flatten" :style="{ right: data.right }" flatten>text</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">image 组件拍平</text>
|
||||
<text class="uni-info">设置值: {{data.right}}</text>
|
||||
<text class="uni-info">获取值: {{data.rightActualImageFlat}}</text>
|
||||
<view class="test-box">
|
||||
<image ref="imageRefFlat" class="common test-image-flatten" :style="{ right: data.right }" flatten src="/static/test-image/logo.png"></image>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="uni-common-mt uni-common-mb">
|
||||
<text class="uni-tips">第一个枚举值,'' (空字符串) - 空值情况</text>
|
||||
<enum-data :items="rightEnum" title="right 枚举值" @change="radioChangeRight" :compact="true"></enum-data>
|
||||
<input-data :defaultValue="data.right" title="right 自定义值" type="text" @confirm="inputChangeRight"></input-data>
|
||||
</view>
|
||||
|
||||
<view class="uni-common-mb">
|
||||
<text>native-view组件: right: 10% 和 right: 30px</text>
|
||||
<view class="test-container">
|
||||
<view class="example-box">
|
||||
<test-native-view class="common-native" style="right: 10%;"></test-native-view>
|
||||
</view>
|
||||
<view class="example-box">
|
||||
<test-native-view class="common-native" style="right: 30px;"></test-native-view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<!-- #ifdef APP && !VUE3-VAPOR -->
|
||||
</scroll-view>
|
||||
<!-- #endif -->
|
||||
</template>
|
||||
|
||||
<script setup lang="uts">
|
||||
import { ItemType } from '@/components/enum-data/enum-data-types'
|
||||
|
||||
const rightEnum : ItemType[] = [
|
||||
{ value: 0, name: '' },
|
||||
{ value: 1, name: '0' },
|
||||
{ value: 2, name: '0px' },
|
||||
{ value: 3, name: '20px' },
|
||||
{ value: 4, name: '40rpx' },
|
||||
{ value: 5, name: '0%' },
|
||||
{ value: 6, name: '50%' },
|
||||
{ value: 7, name: 'auto' }
|
||||
]
|
||||
|
||||
const data = reactive({
|
||||
right: '10px',
|
||||
rightActual: '',
|
||||
rightActualText: '',
|
||||
rightActualImage: '',
|
||||
rightActualFlat: '',
|
||||
rightActualTextFlat: '',
|
||||
rightActualImageFlat: ''
|
||||
})
|
||||
const viewRef = ref(null as UniElement | null)
|
||||
const textRef = ref(null as UniTextElement | null)
|
||||
const imageRef = ref(null as UniImageElement | null)
|
||||
const viewRefFlat = ref(null as UniElement | null)
|
||||
const textRefFlat = ref(null as UniTextElement | null)
|
||||
const imageRefFlat = ref(null as UniImageElement | null)
|
||||
|
||||
const getPropertyValues = () => {
|
||||
data.rightActual = viewRef.value?.style.getPropertyValue('right') ?? ''
|
||||
data.rightActualFlat = viewRefFlat.value?.style.getPropertyValue('right') ?? ''
|
||||
data.rightActualText = textRef.value?.style.getPropertyValue('right') ?? ''
|
||||
data.rightActualTextFlat = textRefFlat.value?.style.getPropertyValue('right') ?? ''
|
||||
data.rightActualImage = imageRef.value?.style.getPropertyValue('right') ?? ''
|
||||
data.rightActualImageFlat = imageRefFlat.value?.style.getPropertyValue('right') ?? ''
|
||||
}
|
||||
|
||||
|
||||
const changeRight = (value : string) => {
|
||||
data.right = value
|
||||
viewRef.value?.style.setProperty('right', value)
|
||||
viewRefFlat.value?.style.setProperty('right', value)
|
||||
textRef.value?.style.setProperty('right', value)
|
||||
textRefFlat.value?.style.setProperty('right', value)
|
||||
imageRef.value?.style.setProperty('right', value)
|
||||
imageRefFlat.value?.style.setProperty('right', value)
|
||||
// 使用 nextTick 确保样式已应用后再获取值
|
||||
nextTick(() => {
|
||||
getPropertyValues()
|
||||
})
|
||||
}
|
||||
|
||||
const radioChangeRight = (index : number) => {
|
||||
const selectedItem = rightEnum.find((item) : boolean => item.value === index)
|
||||
if (selectedItem != null) {
|
||||
changeRight(selectedItem.name)
|
||||
}
|
||||
}
|
||||
|
||||
const inputChangeRight = (value : string) => {
|
||||
changeRight(value)
|
||||
}
|
||||
|
||||
onReady(() => {
|
||||
getPropertyValues()
|
||||
})
|
||||
|
||||
defineExpose({
|
||||
radioChangeRight,
|
||||
data
|
||||
})
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.example-box {
|
||||
position: relative;
|
||||
flex: 1;
|
||||
height: 60px;
|
||||
background-color: #f5f5f5;
|
||||
border: 1px solid #ddd;
|
||||
margin: 0 5px;
|
||||
}
|
||||
|
||||
.common {
|
||||
position: absolute;
|
||||
width: 60px;
|
||||
height: 60px;
|
||||
background-color: cyan;
|
||||
}
|
||||
|
||||
.common-text {
|
||||
width: 50px;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.test-container {
|
||||
flex-direction: row;
|
||||
justify-content: space-between;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.test-item {
|
||||
flex: 1;
|
||||
margin: 0 5px;
|
||||
}
|
||||
|
||||
.test-box {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
height: 60px;
|
||||
background-color: #e0e0e0;
|
||||
}
|
||||
|
||||
.common-native {
|
||||
position: absolute;
|
||||
width: 60px;
|
||||
height: 60px;
|
||||
background-color: #00FFFF;
|
||||
}
|
||||
</style>
|
||||
278
mpuniapp/pages/CSS/layout/top.uvue
普通文件
278
mpuniapp/pages/CSS/layout/top.uvue
普通文件
@@ -0,0 +1,278 @@
|
||||
<template>
|
||||
<!-- #ifdef APP && !VUE3-VAPOR -->
|
||||
<scroll-view style="flex: 1">
|
||||
<!-- #endif -->
|
||||
<view style="flex-grow: 1;">
|
||||
<view class="uni-common-mb">
|
||||
<text class="uni-title-text">top: 20px (距离顶部 20px) - 右侧:拍平</text>
|
||||
<view class="test-container">
|
||||
<view class="example-box">
|
||||
<view class="common" style="top: 20px;"></view>
|
||||
</view>
|
||||
<view class="example-box">
|
||||
<view class="common" style="top: 20px;" flatten></view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="uni-common-mb">
|
||||
<text class="uni-title-text">top: 20rpx (距离顶部 20rpx) - 右侧:拍平</text>
|
||||
<view class="test-container">
|
||||
<view class="example-box">
|
||||
<view class="common" style="top: 20rpx;"></view>
|
||||
</view>
|
||||
<view class="example-box">
|
||||
<view class="common" style="top: 20rpx;" flatten></view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="uni-common-mb">
|
||||
<text class="uni-title-text">top: 20% (距离顶部 20%) - 右侧:拍平</text>
|
||||
<view class="test-container">
|
||||
<view class="example-box">
|
||||
<view class="common" style="top: 20%;"></view>
|
||||
</view>
|
||||
<view class="example-box">
|
||||
<view class="common" style="top: 20%;" flatten></view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="uni-common-mb">
|
||||
<text class="uni-title-text">top: auto (自动,默认顶部对齐) - 右侧:拍平</text>
|
||||
<view class="test-container">
|
||||
<view class="example-box">
|
||||
<view class="common" style="top: auto;"></view>
|
||||
</view>
|
||||
<view class="example-box">
|
||||
<view class="common" style="top: auto;" flatten></view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<text class="uni-title-text uni-common-mt">scroll-view 组件</text>
|
||||
<view class="uni-common-mb">
|
||||
<text class="uni-subtitle-text">top: 10% 和 top: 30px</text>
|
||||
<view class="test-container">
|
||||
<view class="example-box">
|
||||
<scroll-view class="common" style="top: 10%;"></scroll-view>
|
||||
</view>
|
||||
<view class="example-box">
|
||||
<scroll-view class="common" style="top: 30px;"></scroll-view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="uni-common-mt">
|
||||
<text class="uni-title-text">setProperty 设置与 getPropertyValue 获取</text>
|
||||
</view>
|
||||
|
||||
<!-- 普通版本 -->
|
||||
<view class="test-container">
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">view 组件</text>
|
||||
<text class="uni-info">设置值: {{data.top}}</text>
|
||||
<text class="uni-info">获取值: {{data.topActual}}</text>
|
||||
<view class="test-box">
|
||||
<view ref="viewRef" class="common test-view" :style="{ top: data.top }">
|
||||
<text class="common-text">view</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">text 组件</text>
|
||||
<text class="uni-info">设置值: {{data.top}}</text>
|
||||
<text class="uni-info">获取值: {{data.topActualText}}</text>
|
||||
<view class="test-box">
|
||||
<text ref="textRef" class="common common-text test-text" :style="{ top: data.top }">text</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">image 组件</text>
|
||||
<text class="uni-info">设置值: {{data.top}}</text>
|
||||
<text class="uni-info">获取值: {{data.topActualImage}}</text>
|
||||
<view class="test-box">
|
||||
<image ref="imageRef" class="common test-image" :style="{ top: data.top }" src="/static/test-image/logo.png"></image>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 拍平版本 -->
|
||||
<view class="test-container">
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">view 组件拍平</text>
|
||||
<text class="uni-info">设置值: {{data.top}}</text>
|
||||
<text class="uni-info">获取值: {{data.topActualFlat}}</text>
|
||||
<view class="test-box">
|
||||
<view ref="viewRefFlat" class="common test-view-flatten" :style="{ top: data.top }" flatten>
|
||||
<text class="common-text">view</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">text 组件拍平</text>
|
||||
<text class="uni-info">设置值: {{data.top}}</text>
|
||||
<text class="uni-info">获取值: {{data.topActualTextFlat}}</text>
|
||||
<view class="test-box">
|
||||
<text ref="textRefFlat" class="common common-text test-text-flatten" :style="{ top: data.top }" flatten>text</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">image 组件拍平</text>
|
||||
<text class="uni-info">设置值: {{data.top}}</text>
|
||||
<text class="uni-info">获取值: {{data.topActualImageFlat}}</text>
|
||||
<view class="test-box">
|
||||
<image ref="imageRefFlat" class="common test-image-flatten" :style="{ top: data.top }" flatten src="/static/test-image/logo.png"></image>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="uni-common-mt uni-common-mb">
|
||||
<text class="uni-tips">第一个枚举值,'' (空字符串) - 空值情况</text>
|
||||
<enum-data :items="topEnum" title="top 枚举值" @change="radioChangeTop" :compact="true"></enum-data>
|
||||
<input-data :defaultValue="data.top" title="top 自定义值" type="text" @confirm="inputChangeTop"></input-data>
|
||||
</view>
|
||||
|
||||
<view class="uni-common-mb">
|
||||
<text>native-view组件: top: 10% 和 top: 30px</text>
|
||||
<view class="test-container">
|
||||
<view class="example-box">
|
||||
<test-native-view class="common-native" style="top: 10%;"></test-native-view>
|
||||
</view>
|
||||
<view class="example-box">
|
||||
<test-native-view class="common-native" style="top: 30px;"></test-native-view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<!-- #ifdef APP && !VUE3-VAPOR -->
|
||||
</scroll-view>
|
||||
<!-- #endif -->
|
||||
</template>
|
||||
|
||||
<script setup lang="uts">
|
||||
import { ItemType } from '@/components/enum-data/enum-data-types'
|
||||
|
||||
const topEnum : ItemType[] = [
|
||||
{ value: 0, name: '' },
|
||||
{ value: 1, name: '0' },
|
||||
{ value: 2, name: '0px' },
|
||||
{ value: 3, name: '10px' },
|
||||
{ value: 4, name: '20rpx' },
|
||||
{ value: 5, name: '0%' },
|
||||
{ value: 6, name: '50%' },
|
||||
{ value: 7, name: 'auto' }
|
||||
]
|
||||
|
||||
const data = reactive({
|
||||
top: '10px',
|
||||
topActual: '',
|
||||
topActualText: '',
|
||||
topActualImage: '',
|
||||
topActualFlat: '',
|
||||
topActualTextFlat: '',
|
||||
topActualImageFlat: ''
|
||||
})
|
||||
const viewRef = ref(null as UniElement | null)
|
||||
const textRef = ref(null as UniTextElement | null)
|
||||
const imageRef = ref(null as UniImageElement | null)
|
||||
const viewRefFlat = ref(null as UniElement | null)
|
||||
const textRefFlat = ref(null as UniTextElement | null)
|
||||
const imageRefFlat = ref(null as UniImageElement | null)
|
||||
|
||||
const getPropertyValues = () => {
|
||||
data.topActual = viewRef.value?.style.getPropertyValue('top') ?? ''
|
||||
data.topActualFlat = viewRefFlat.value?.style.getPropertyValue('top') ?? ''
|
||||
data.topActualText = textRef.value?.style.getPropertyValue('top') ?? ''
|
||||
data.topActualTextFlat = textRefFlat.value?.style.getPropertyValue('top') ?? ''
|
||||
data.topActualImage = imageRef.value?.style.getPropertyValue('top') ?? ''
|
||||
data.topActualImageFlat = imageRefFlat.value?.style.getPropertyValue('top') ?? ''
|
||||
}
|
||||
|
||||
|
||||
const changeTop = (value : string) => {
|
||||
data.top = value
|
||||
viewRef.value?.style.setProperty('top', value)
|
||||
viewRefFlat.value?.style.setProperty('top', value)
|
||||
textRef.value?.style.setProperty('top', value)
|
||||
textRefFlat.value?.style.setProperty('top', value)
|
||||
imageRef.value?.style.setProperty('top', value)
|
||||
imageRefFlat.value?.style.setProperty('top', value)
|
||||
// 使用 nextTick 确保样式已应用后再获取值
|
||||
nextTick(() => {
|
||||
getPropertyValues()
|
||||
})
|
||||
}
|
||||
|
||||
const radioChangeTop = (index : number) => {
|
||||
const selectedItem = topEnum.find((item) : boolean => item.value === index)
|
||||
if (selectedItem != null) {
|
||||
changeTop(selectedItem.name)
|
||||
}
|
||||
}
|
||||
|
||||
const inputChangeTop = (value : string) => {
|
||||
changeTop(value)
|
||||
}
|
||||
|
||||
onReady(() => {
|
||||
getPropertyValues()
|
||||
})
|
||||
|
||||
defineExpose({
|
||||
radioChangeTop,
|
||||
data
|
||||
})
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.example-box {
|
||||
position: relative;
|
||||
flex: 1;
|
||||
height: 100px;
|
||||
background-color: #f5f5f5;
|
||||
border: 1px solid #ddd;
|
||||
margin: 0 5px;
|
||||
}
|
||||
|
||||
.common {
|
||||
position: absolute;
|
||||
width: 60px;
|
||||
height: 60px;
|
||||
background-color: cyan;
|
||||
}
|
||||
|
||||
.common-text {
|
||||
width: 50px;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.test-container {
|
||||
flex-direction: row;
|
||||
justify-content: space-between;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.test-item {
|
||||
flex: 1;
|
||||
margin: 0 5px;
|
||||
}
|
||||
|
||||
.test-box {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
height: 100px;
|
||||
background-color: #e0e0e0;
|
||||
}
|
||||
|
||||
.common-native {
|
||||
position: absolute;
|
||||
width: 60px;
|
||||
height: 60px;
|
||||
background-color: #00FFFF;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,204 @@
|
||||
<template>
|
||||
<!-- #ifdef APP && !VUE3-VAPOR -->
|
||||
<scroll-view style="flex: 1">
|
||||
<!-- #endif -->
|
||||
<view style="flex-grow: 1;">
|
||||
<text class="uni-tips">visibility: {{data.visibility}} ,说明:点击切换</text>
|
||||
<view class="demo-box">
|
||||
<view @click="changeVisibility">
|
||||
<text>view组件: {{data.visibility}}</text>
|
||||
<view class="common" :style="{'visibility': data.visibility}"></view>
|
||||
</view>
|
||||
<view @click="changeVisibility">
|
||||
<text>text组件: {{data.visibility}}</text>
|
||||
<text class="common" :style="{'visibility': data.visibility}">文本</text>
|
||||
</view>
|
||||
<view @click="changeVisibility">
|
||||
<text>image组件: {{data.visibility}}</text>
|
||||
<image class="common" :style="{'visibility': data.visibility}" src="/static/test-image/logo.png"></image>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="uni-common-mb">
|
||||
<text class="uni-title-text uni-common-mt">scroll-view 组件</text>
|
||||
<view class="demo-box">
|
||||
<view>
|
||||
<text>scroll-view: visible</text>
|
||||
<scroll-view class="common" style="visibility: visible;"></scroll-view>
|
||||
</view>
|
||||
<view>
|
||||
<text>scroll-view: hidden</text>
|
||||
<scroll-view class="common" style="visibility: hidden;"></scroll-view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="uni-common-mt">
|
||||
<text class="uni-title-text">setProperty 设置与 getPropertyValue 获取</text>
|
||||
</view>
|
||||
|
||||
<!-- 普通版本 -->
|
||||
<view class="test-container">
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">view 组件</text>
|
||||
<text class="uni-info">设置值: {{data.visibilityValue}}</text>
|
||||
<text class="uni-info">获取值: {{data.visibilityActual}}</text>
|
||||
<view class="test-box">
|
||||
<view ref="viewRef" class="common-dynamic test-view" :style="{ visibility: data.visibilityValue }">
|
||||
<text>view</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">text 组件</text>
|
||||
<text class="uni-info">设置值: {{data.visibilityValue}}</text>
|
||||
<text class="uni-info">获取值: {{data.visibilityActualText}}</text>
|
||||
<view class="test-box">
|
||||
<text ref="textRef" class="common-dynamic test-text" :style="{ visibility: data.visibilityValue }">text</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">image 组件</text>
|
||||
<text class="uni-info">设置值: {{data.visibilityValue}}</text>
|
||||
<text class="uni-info">获取值: {{data.visibilityActualImage}}</text>
|
||||
<view class="test-box">
|
||||
<image ref="imageRef" class="common-dynamic test-image" :style="{ visibility: data.visibilityValue }" src="/static/test-image/logo.png"></image>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="uni-common-mt uni-common-mb">
|
||||
<text class="uni-tips">第一个枚举值,'' (空字符串) - 空值情况</text>
|
||||
<enum-data :items="visibilityEnum" title="visibility 枚举值" @change="radioChangeVisibility" :compact="true"></enum-data>
|
||||
<input-data :defaultValue="data.visibilityValue" title="visibility 自定义值" type="text" @confirm="inputChangeVisibility"></input-data>
|
||||
</view>
|
||||
|
||||
<view class="uni-common-mb">
|
||||
<text>native-view 组件</text>
|
||||
<view class="demo-box">
|
||||
<view>
|
||||
<text>native-view: visible</text>
|
||||
<test-native-view class="common" style="visibility: visible;"></test-native-view>
|
||||
</view>
|
||||
<view>
|
||||
<text>native-view: hidden</text>
|
||||
<test-native-view class="common" style="visibility: hidden;"></test-native-view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<!-- #ifdef APP && !VUE3-VAPOR -->
|
||||
</scroll-view>
|
||||
<!-- #endif -->
|
||||
</template>
|
||||
|
||||
<script setup lang="uts">
|
||||
import { ItemType } from '@/components/enum-data/enum-data-types'
|
||||
|
||||
let flag = true
|
||||
const data = reactive({
|
||||
visibility: 'visible',
|
||||
visibilityValue: 'visible',
|
||||
visibilityActual: '',
|
||||
visibilityActualText: '',
|
||||
visibilityActualImage: ''
|
||||
})
|
||||
|
||||
|
||||
const changeVisibility = () => {
|
||||
flag = !flag
|
||||
if (flag) {
|
||||
data.visibility = 'visible'
|
||||
} else {
|
||||
data.visibility = 'hidden'
|
||||
}
|
||||
}
|
||||
|
||||
const visibilityEnum : ItemType[] = [
|
||||
{ value: 0, name: '' },
|
||||
{ value: 1, name: 'visible' },
|
||||
{ value: 2, name: 'hidden' }
|
||||
]
|
||||
|
||||
const viewRef = ref(null as UniElement | null)
|
||||
const textRef = ref(null as UniTextElement | null)
|
||||
const imageRef = ref(null as UniImageElement | null)
|
||||
|
||||
const getPropertyValues = () => {
|
||||
data.visibilityActual = viewRef.value?.style.getPropertyValue('visibility') ?? ''
|
||||
data.visibilityActualText = textRef.value?.style.getPropertyValue('visibility') ?? ''
|
||||
data.visibilityActualImage = imageRef.value?.style.getPropertyValue('visibility') ?? ''
|
||||
}
|
||||
|
||||
const changeVisibilityProperty = (value : string) => {
|
||||
data.visibilityValue = value
|
||||
viewRef.value?.style.setProperty('visibility', value)
|
||||
textRef.value?.style.setProperty('visibility', value)
|
||||
imageRef.value?.style.setProperty('visibility', value)
|
||||
// 使用 nextTick 确保样式已应用后再获取值
|
||||
nextTick(() => {
|
||||
getPropertyValues()
|
||||
})
|
||||
}
|
||||
|
||||
const radioChangeVisibility = (index : number) => {
|
||||
const selectedItem = visibilityEnum.find((item) : boolean => item.value === index)
|
||||
if (selectedItem != null) {
|
||||
changeVisibilityProperty(selectedItem.name)
|
||||
}
|
||||
}
|
||||
|
||||
const inputChangeVisibility = (value : string) => {
|
||||
changeVisibilityProperty(value)
|
||||
}
|
||||
|
||||
onReady(() => {
|
||||
getPropertyValues()
|
||||
})
|
||||
|
||||
defineExpose({
|
||||
radioChangeVisibility,
|
||||
data
|
||||
})
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.common {
|
||||
width: 100px;
|
||||
height: 100px;
|
||||
background-color: cyan;
|
||||
}
|
||||
|
||||
.demo-box {
|
||||
flex-direction: row;
|
||||
margin-top: 10px;
|
||||
justify-content: space-around;
|
||||
}
|
||||
|
||||
.common-dynamic {
|
||||
width: 100px;
|
||||
height: 100px;
|
||||
background-color: cyan;
|
||||
}
|
||||
|
||||
.test-container {
|
||||
flex-direction: row;
|
||||
justify-content: space-between;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.test-item {
|
||||
flex: 1;
|
||||
margin: 0 5px;
|
||||
}
|
||||
|
||||
.test-box {
|
||||
width: 100%;
|
||||
height: 100px;
|
||||
background-color: gray;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,55 @@
|
||||
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
|
||||
const isWeb = platformInfo.startsWith('web')
|
||||
const isHarmony = platformInfo.startsWith('harmony')
|
||||
const isiOS = platformInfo.startsWith('ios')
|
||||
const isAndroid = platformInfo.startsWith('android')
|
||||
const isDom2 = process.env.UNI_APP_X_DOM2 === "true"
|
||||
describe('/pages/CSS/layout/width.uvue', () => {
|
||||
let page;
|
||||
beforeAll(async () => {
|
||||
page = await program.reLaunch('/pages/CSS/layout/width');
|
||||
await page.waitFor('view');
|
||||
});
|
||||
|
||||
it('test nest components width', async () => {
|
||||
if(isWeb){
|
||||
const element = await page.$('.child_box');
|
||||
const size = await element.size()
|
||||
expect(size.width).toBe(150)
|
||||
expect(size.height).toBe(100)
|
||||
}
|
||||
})
|
||||
|
||||
it('test width height', async () => {
|
||||
const emptyValues = await page.data('emptyElementValues')
|
||||
if(isDom2 && (isHarmony || isiOS || isAndroid)){
|
||||
expect(emptyValues).toMatchObject({
|
||||
emptyViewWidth: 'auto',
|
||||
emptyViewHeight: 'auto',
|
||||
emptyTextWidth: 'auto',
|
||||
emptyTextHeight: 'auto',
|
||||
emptyImageWidth: '320px',
|
||||
emptyImageHeight: '240px',
|
||||
emptyScrollViewWidth: 'auto',
|
||||
emptyScrollViewHeight: 'auto',
|
||||
emptyNativeViewWidth: 'auto',
|
||||
emptyNativeViewHeight: 'auto'
|
||||
})
|
||||
}
|
||||
else{
|
||||
expect(emptyValues).toMatchObject({
|
||||
emptyViewWidth: '',
|
||||
emptyViewHeight: '',
|
||||
emptyTextWidth: '',
|
||||
emptyTextHeight: '',
|
||||
emptyImageWidth: '',
|
||||
emptyImageHeight: '',
|
||||
emptyScrollViewWidth: '',
|
||||
emptyScrollViewHeight: '',
|
||||
emptyNativeViewWidth: '',
|
||||
emptyNativeViewHeight: ''
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
});
|
||||
368
mpuniapp/pages/CSS/layout/width.uvue
普通文件
368
mpuniapp/pages/CSS/layout/width.uvue
普通文件
@@ -0,0 +1,368 @@
|
||||
<template>
|
||||
<!-- #ifdef APP && !VUE3-VAPOR -->
|
||||
<scroll-view style="flex: 1">
|
||||
<!-- #endif -->
|
||||
<view style="flex-grow: 1;">
|
||||
<text class="uni-tips">说明:左边是正常版本,右边是拍平版本</text>
|
||||
<view>
|
||||
<text>width: 100px</text>
|
||||
<view class="demo-box">
|
||||
<view class="common" style="width: 100px;"></view>
|
||||
<view class="common" style="width: 100px;" flatten></view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view>
|
||||
<text>width: 200rpx</text>
|
||||
<view class="demo-box">
|
||||
<view class="common" style="width: 200rpx;"></view>
|
||||
<view class="common" style="width: 200rpx;" flatten></view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view>
|
||||
<text>width: 30%</text>
|
||||
<view class="demo-box">
|
||||
<view class="common" style="width: 30%;"></view>
|
||||
<view class="common" style="width: 30%;" flatten></view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="uni-common-mt">
|
||||
<text class="uni-title-text">scroll-view 组件</text>
|
||||
</view>
|
||||
|
||||
<view class="demo-box">
|
||||
<scroll-view style="width: 100px; height: 100px; background-color: cyan;">
|
||||
<text class="scroll-view-label">width: 100px</text>
|
||||
</scroll-view>
|
||||
<scroll-view style="width: 200px; height: 100px; background-color: cyan;">
|
||||
<text class="scroll-view-label">width: 200px</text>
|
||||
</scroll-view>
|
||||
</view>
|
||||
|
||||
<view class="uni-common-mt">
|
||||
<text class="uni-title-text">setProperty 设置与 getPropertyValue 获取</text>
|
||||
</view>
|
||||
|
||||
<!-- 普通版本 -->
|
||||
<view class="test-container">
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">view 组件</text>
|
||||
<text class="uni-info">设置值: {{data.width}}</text>
|
||||
<text class="uni-info">获取值: {{data.widthActual}}</text>
|
||||
<view class="test-box">
|
||||
<view ref="viewRef" class="common test-view" :style="{ width: data.width }">
|
||||
<text>view</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">text 组件</text>
|
||||
<text class="uni-info">设置值: {{data.width}}</text>
|
||||
<text class="uni-info">获取值: {{data.widthActualText}}</text>
|
||||
<view class="test-box">
|
||||
<text ref="textRef" class="common test-text" :style="{ width: data.width }">text</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">image 组件</text>
|
||||
<text class="uni-info">设置值: {{data.width}}</text>
|
||||
<text class="uni-info">获取值: {{data.widthActualImage}}</text>
|
||||
<view class="test-box">
|
||||
<image ref="imageRef" class="common test-image" :style="{ width: data.width }" src="/static/test-image/logo.png"></image>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 拍平版本 -->
|
||||
<view class="test-container">
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">view 组件拍平</text>
|
||||
<text class="uni-info">设置值: {{data.width}}</text>
|
||||
<text class="uni-info">获取值: {{data.widthActualFlat}}</text>
|
||||
<view class="test-box">
|
||||
<view ref="viewRefFlat" class="common test-view-flatten" :style="{ width: data.width }" flatten>
|
||||
<text>view</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">text 组件拍平</text>
|
||||
<text class="uni-info">设置值: {{data.width}}</text>
|
||||
<text class="uni-info">获取值: {{data.widthActualTextFlat}}</text>
|
||||
<view class="test-box">
|
||||
<text ref="textRefFlat" class="common test-text-flatten" :style="{ width: data.width }" flatten>text</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">image 组件拍平</text>
|
||||
<text class="uni-info">设置值: {{data.width}}</text>
|
||||
<text class="uni-info">获取值: {{data.widthActualImageFlat}}</text>
|
||||
<view class="test-box">
|
||||
<image ref="imageRefFlat" class="common test-image-flatten" :style="{ width: data.width }" flatten src="/static/test-image/logo.png"></image>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="uni-common-mt uni-common-mb">
|
||||
<text class="uni-tips">第一个枚举值,'' (空字符串) - 空值情况</text>
|
||||
<enum-data :items="widthEnum" title="width 枚举值" @change="radioChangeWidth" :compact="true"></enum-data>
|
||||
<input-data :defaultValue="data.width" title="width 自定义值" type="text" @confirm="inputChangeWidth"></input-data>
|
||||
</view>
|
||||
|
||||
<view class="uni-common-mt uni-common-mb">
|
||||
<text class="uni-title-text">默认宽高规则 (无宽高会不显示或使用默认值)</text>
|
||||
</view>
|
||||
|
||||
<view>
|
||||
<text>空 view - 无宽高,有背景色 (预期不显示)</text>
|
||||
<text class="uni-info">getPropertyValue: width={{emptyElementValues.emptyViewWidth}}, height={{emptyElementValues.emptyViewHeight}}</text>
|
||||
<view class="demo-box">
|
||||
<view ref="emptyViewRef" style="background-color: cyan;"></view>
|
||||
<view ref="emptyViewFlatRef" style="background-color: cyan;" flatten></view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view>
|
||||
<text>空 text - 无文字、无宽高,有背景色</text>
|
||||
<text class="uni-info">getPropertyValue: width={{emptyElementValues.emptyTextWidth}}, height={{emptyElementValues.emptyTextHeight}}</text>
|
||||
<view class="demo-box">
|
||||
<text ref="emptyTextRef" style="background-color: cyan;"></text>
|
||||
<text ref="emptyTextFlatRef" style="background-color: cyan;" flatten></text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view>
|
||||
<text>空 image - 无 src、无宽高,有背景色 (image 有默认宽高)</text>
|
||||
<text class="uni-info">getPropertyValue: width={{emptyElementValues.emptyImageWidth}}, height={{emptyElementValues.emptyImageHeight}}</text>
|
||||
<view class="demo-box">
|
||||
<image ref="emptyImageRef" style="background-color: cyan;"></image>
|
||||
<image ref="emptyImageFlatRef" style="background-color: cyan;" flatten></image>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view>
|
||||
<text>空 scroll-view - 无宽高,有背景色</text>
|
||||
<text class="uni-info">getPropertyValue: width={{emptyElementValues.emptyScrollViewWidth}}, height={{emptyElementValues.emptyScrollViewHeight}}</text>
|
||||
<view class="demo-box">
|
||||
<scroll-view ref="emptyScrollViewRef" style="background-color: cyan;"></scroll-view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- #ifdef APP-ANDROID || APP-IOS || APP-HARMONY -->
|
||||
<view class="uni-common-mb">
|
||||
<text>空 native-view - 无宽高,有背景色</text>
|
||||
<text class="uni-info">getPropertyValue: width={{emptyElementValues.emptyNativeViewWidth}}, height={{emptyElementValues.emptyNativeViewHeight}}</text>
|
||||
<view class="demo-box">
|
||||
<native-view ref="emptyNativeViewRef" style="background-color: cyan;"></native-view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="uni-common-mb">
|
||||
<text>native-view组件: width: 100px 和 width: 200px</text>
|
||||
<view class="demo-box-native">
|
||||
<view class="container-native">
|
||||
<native-view style="width: 100px; height: 100px;"></native-view>
|
||||
</view>
|
||||
<view class="container-native">
|
||||
<native-view style="width: 200px; height: 100px;"></native-view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<!-- #endif -->
|
||||
|
||||
<!-- #ifdef WEB -->
|
||||
<view class="container">
|
||||
<text>嵌套子元素 v-deep width: 150rpx</text>
|
||||
<child-width-uvue></child-width-uvue>
|
||||
</view>
|
||||
<!-- #endif -->
|
||||
</view>
|
||||
<!-- #ifdef APP && !VUE3-VAPOR -->
|
||||
</scroll-view>
|
||||
<!-- #endif -->
|
||||
</template>
|
||||
|
||||
<script setup lang="uts">
|
||||
import childWidthUvue from "./child-width.uvue"
|
||||
import { ItemType } from '@/components/enum-data/enum-data-types'
|
||||
|
||||
const widthEnum: ItemType[] = [
|
||||
{ value: 0, name: '' },
|
||||
{ value: 1, name: '0' },
|
||||
{ value: 2, name: '0px' },
|
||||
{ value: 3, name: '50px' },
|
||||
{ value: 4, name: '0%' },
|
||||
{ value: 5, name: '50%' },
|
||||
{ value: 6, name: 'auto' }
|
||||
]
|
||||
|
||||
const data = reactive({
|
||||
width: '100px',
|
||||
widthActual: '',
|
||||
widthActualText: '',
|
||||
widthActualImage: '',
|
||||
widthActualFlat: '',
|
||||
widthActualTextFlat: '',
|
||||
widthActualImageFlat: ''
|
||||
})
|
||||
const viewRef = ref(null as UniElement | null)
|
||||
const textRef = ref(null as UniTextElement | null)
|
||||
const imageRef = ref(null as UniImageElement | null)
|
||||
const viewRefFlat = ref(null as UniElement | null)
|
||||
const textRefFlat = ref(null as UniTextElement | null)
|
||||
const imageRefFlat = ref(null as UniImageElement | null)
|
||||
|
||||
// 空元素 ref
|
||||
const emptyViewRef = ref(null as UniElement | null)
|
||||
const emptyViewFlatRef = ref(null as UniElement | null)
|
||||
const emptyTextRef = ref(null as UniTextElement | null)
|
||||
const emptyTextFlatRef = ref(null as UniTextElement | null)
|
||||
const emptyImageRef = ref(null as UniImageElement | null)
|
||||
const emptyImageFlatRef = ref(null as UniImageElement | null)
|
||||
const emptyScrollViewRef = ref(null as UniElement | null)
|
||||
const emptyNativeViewRef = ref(null as UniElement | null)
|
||||
|
||||
// 空元素宽高值
|
||||
const emptyElementValues = reactive({
|
||||
emptyViewWidth: '',
|
||||
emptyViewHeight: '',
|
||||
emptyTextWidth: '',
|
||||
emptyTextHeight: '',
|
||||
emptyImageWidth: '',
|
||||
emptyImageHeight: '',
|
||||
emptyScrollViewWidth: '',
|
||||
emptyScrollViewHeight: '',
|
||||
emptyNativeViewWidth: '',
|
||||
emptyNativeViewHeight: ''
|
||||
})
|
||||
|
||||
const getEmptyElementValues = () => {
|
||||
nextTick(() => {
|
||||
if (emptyViewRef.value != null) {
|
||||
emptyElementValues.emptyViewWidth = emptyViewRef.value.style.getPropertyValue('width') ?? ''
|
||||
emptyElementValues.emptyViewHeight = emptyViewRef.value.style.getPropertyValue('height') ?? ''
|
||||
}
|
||||
if (emptyTextRef.value != null) {
|
||||
emptyElementValues.emptyTextWidth = emptyTextRef.value.style.getPropertyValue('width') ?? ''
|
||||
emptyElementValues.emptyTextHeight = emptyTextRef.value.style.getPropertyValue('height') ?? ''
|
||||
}
|
||||
if (emptyImageRef.value != null) {
|
||||
emptyElementValues.emptyImageWidth = emptyImageRef.value.style.getPropertyValue('width') ?? ''
|
||||
emptyElementValues.emptyImageHeight = emptyImageRef.value.style.getPropertyValue('height') ?? ''
|
||||
}
|
||||
if (emptyScrollViewRef.value != null) {
|
||||
emptyElementValues.emptyScrollViewWidth = emptyScrollViewRef.value.style.getPropertyValue('width') ?? ''
|
||||
emptyElementValues.emptyScrollViewHeight = emptyScrollViewRef.value.style.getPropertyValue('height') ?? ''
|
||||
}
|
||||
if (emptyNativeViewRef.value != null) {
|
||||
emptyElementValues.emptyNativeViewWidth = emptyNativeViewRef.value.style.getPropertyValue('width') ?? ''
|
||||
emptyElementValues.emptyNativeViewHeight = emptyNativeViewRef.value.style.getPropertyValue('height') ?? ''
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const getPropertyValues = () => {
|
||||
data.widthActual = viewRef.value?.style.getPropertyValue('width') ?? ''
|
||||
data.widthActualFlat = viewRefFlat.value?.style.getPropertyValue('width') ?? ''
|
||||
data.widthActualText = textRef.value?.style.getPropertyValue('width') ?? ''
|
||||
data.widthActualTextFlat = textRefFlat.value?.style.getPropertyValue('width') ?? ''
|
||||
data.widthActualImage = imageRef.value?.style.getPropertyValue('width') ?? ''
|
||||
data.widthActualImageFlat = imageRefFlat.value?.style.getPropertyValue('width') ?? ''
|
||||
}
|
||||
|
||||
|
||||
const changeWidth = (value: string) => {
|
||||
data.width = value
|
||||
viewRef.value?.style.setProperty('width', value)
|
||||
viewRefFlat.value?.style.setProperty('width', value)
|
||||
textRef.value?.style.setProperty('width', value)
|
||||
textRefFlat.value?.style.setProperty('width', value)
|
||||
imageRef.value?.style.setProperty('width', value)
|
||||
imageRefFlat.value?.style.setProperty('width', value)
|
||||
// 使用 nextTick 确保样式已应用后再获取值
|
||||
nextTick(() => {
|
||||
getPropertyValues()
|
||||
})
|
||||
}
|
||||
|
||||
const radioChangeWidth = (index: number) => {
|
||||
const selectedItem = widthEnum.find((item): boolean => item.value === index)
|
||||
if (selectedItem != null) {
|
||||
changeWidth(selectedItem.name)
|
||||
}
|
||||
}
|
||||
|
||||
const inputChangeWidth = (value: string) => {
|
||||
changeWidth(value)
|
||||
}
|
||||
|
||||
onReady(() => {
|
||||
getPropertyValues()
|
||||
getEmptyElementValues()
|
||||
})
|
||||
|
||||
defineExpose({
|
||||
radioChangeWidth,
|
||||
emptyElementValues,
|
||||
data
|
||||
})
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.common {
|
||||
height: 80px;
|
||||
background-color: cyan;
|
||||
}
|
||||
.demo-box {
|
||||
flex-direction: row;
|
||||
margin-top: 10px;
|
||||
justify-content: space-around;
|
||||
}
|
||||
|
||||
.test-container {
|
||||
flex-direction: row;
|
||||
justify-content: space-between;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.test-item {
|
||||
flex: 1;
|
||||
margin: 0 5px;
|
||||
}
|
||||
|
||||
.test-box {
|
||||
width: 100%;
|
||||
height: 80px;
|
||||
background-color: gray;
|
||||
}
|
||||
|
||||
.scroll-view-label {
|
||||
font-size: 12px;
|
||||
line-height: 100px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.demo-box-native {
|
||||
flex-direction: row;
|
||||
margin-top: 10px;
|
||||
justify-content: space-around;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.container-native {
|
||||
background-color: cyan;
|
||||
}
|
||||
|
||||
/* #ifdef WEB */
|
||||
.container ::v-deep .box {
|
||||
width: 150px;
|
||||
height: 100px;
|
||||
}
|
||||
/* #endif */
|
||||
</style>
|
||||
@@ -0,0 +1,44 @@
|
||||
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
|
||||
const isAndroid = platformInfo.startsWith('android')
|
||||
const isWeb = platformInfo.startsWith('web')
|
||||
const isAppWebView = process.env.UNI_AUTOMATOR_APP_WEBVIEW == 'true'
|
||||
|
||||
describe('css-z-index', () => {
|
||||
let page;
|
||||
beforeAll(async () => {
|
||||
page = await program.reLaunch('/pages/CSS/layout/z-index');
|
||||
await page.waitFor('view');
|
||||
await page.waitFor(isWeb ? 4000 : 2000);
|
||||
});
|
||||
|
||||
if (isAndroid) {
|
||||
it('test crash', async () => {
|
||||
await page.setData({
|
||||
data: {
|
||||
autoTest: true
|
||||
}
|
||||
});
|
||||
const elements = await page.$$('view');
|
||||
expect(elements.length).toBeGreaterThan(0);
|
||||
await page.setData({
|
||||
data: {
|
||||
autoTest: false
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
// web 与 app 在某种情况下表现不同,不进行 app-webview 截图对比
|
||||
if (!isAppWebView) {
|
||||
it('screenshot', async () => {
|
||||
const windowInfo = await program.callUniMethod('getWindowInfo');
|
||||
const image = await program.screenshot({
|
||||
deviceShot: true,
|
||||
area: {
|
||||
x: 0,
|
||||
y: windowInfo.safeAreaInsets.top + 44
|
||||
}
|
||||
});
|
||||
expect(image).toSaveImageSnapshot();
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,321 @@
|
||||
<template>
|
||||
<!-- #ifdef APP && !VUE3-VAPOR -->
|
||||
<scroll-view style="flex: 1">
|
||||
<!-- #endif -->
|
||||
<view style="flex-grow: 1;">
|
||||
<view style="position:absolute;z-index:0;">
|
||||
<view class="common fixed default">
|
||||
<text>position: fixed</text>
|
||||
<text>z-index: 10</text>
|
||||
</view>
|
||||
<view class="common fixed specified">
|
||||
<text>position: fixed</text>
|
||||
<text>z-index: 5</text>
|
||||
</view>
|
||||
<view class="common fixed floor">
|
||||
<text>position: fixed</text>
|
||||
<text>z-index: -1</text>
|
||||
</view>
|
||||
</view>
|
||||
<view style="top: 170px;">
|
||||
<view class="common" style="background-color: cyan;z-index: 10;">
|
||||
<text>z-index: 10</text>
|
||||
</view>
|
||||
<view ref="view" class="common" style="background-color: green;z-index: 5;top: -100px;left: 100px;"
|
||||
@click="changeZIndex(20)">
|
||||
<text>z-index: {{data.zIndex}}</text>
|
||||
<text>点击修改z-index</text>
|
||||
</view>
|
||||
<view class="common" style="background-color: blue;top: -120px;left: 175px;">
|
||||
<text>z-index: 0</text>
|
||||
</view>
|
||||
</view>
|
||||
<view>
|
||||
<view>
|
||||
<view class="common fixed popup" style="background-color: yellow;z-index: 5;">
|
||||
<text>position: fixed</text>
|
||||
<text>z-index: 5</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view v-if="data.autoTest">
|
||||
<view style="z-index: 1;position: fixed;">111</view>
|
||||
<view style="width: 750rpx;">222</view>
|
||||
</view>
|
||||
<view style="top: 50px;">
|
||||
<text class="uni-title-text uni-common-mt">text 组件</text>
|
||||
<text class="common-text" style="background-color: cyan;z-index: 10;text-align: right;">text组件: z-index: 10</text>
|
||||
<text class="common-text" style="background-color: green;top: -37px;left: 87px;z-index: 5;text-align: right;">text组件: z-index: 5</text>
|
||||
<text class="common-text" style="background-color: blue;top: -75px;left: 175px;z-index: 0;text-align: right;">text组件: z-index: 0</text>
|
||||
</view>
|
||||
<view style="top: 50px;">
|
||||
<text class="uni-title-text uni-common-mt">image 组件</text>
|
||||
<image class="common-text image-zindex" style="background-color: cyan;z-index: 10;" src="/static/test-image/logo.png"></image>
|
||||
<image class="common-text image-zindex" style="background-color: green;top: -37px;left: 87px;z-index: 5;" src="/static/test-image/logo.png"></image>
|
||||
<image class="common-text image-zindex" style="background-color: blue;top: -75px;left: 175px;z-index: 0;" src="/static/test-image/logo.png"></image>
|
||||
</view>
|
||||
|
||||
<view class="uni-common-mb" style="top: 50px;">
|
||||
<text class="uni-title-text uni-common-mt">scroll-view 组件</text>
|
||||
<text class="uni-subtitle-text">z-index: 10 和 z-index: 5</text>
|
||||
<scroll-view class="common" style="z-index: 10; background-color: cyan;">
|
||||
<text>z-index: 10</text>
|
||||
</scroll-view>
|
||||
<scroll-view class="common" style="top: -40px;left: 30px;z-index: 5;background-color: green;">
|
||||
<text style="line-height: 100px;">z-index: 5</text>
|
||||
</scroll-view>
|
||||
</view>
|
||||
|
||||
<view class="uni-common-mt" style="top:100px;">
|
||||
<text class="uni-title-text">setProperty 设置与 getPropertyValue 获取</text>
|
||||
<view class="test-container">
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">view 组件</text>
|
||||
<text class="uni-info">设置值: {{data.zIndexValue}}</text>
|
||||
<text class="uni-info">获取值: {{data.zIndexActual}}</text>
|
||||
<view class="test-box">
|
||||
<view class="common-bg" style="background-color: blue; z-index: 1;">
|
||||
<text class="common-text-bg">蓝色view</text>
|
||||
</view>
|
||||
<view ref="viewRef" class="common-dynamic test-view" style="background-color: cyan;" :style="{ zIndex: data.zIndexValue }">
|
||||
<text class="common-text-bg">青色view</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">text 组件</text>
|
||||
<text class="uni-info">设置值: {{data.zIndexValue}}</text>
|
||||
<text class="uni-info">获取值: {{data.zIndexActualText}}</text>
|
||||
<view class="test-box">
|
||||
<text class="common-bg common-text-bg" style="background-color: blue; z-index: 1;">蓝色text</text>
|
||||
<text ref="textRef" class="common-dynamic common-text-bg test-text" style="background-color: cyan;" :style="{ zIndex: data.zIndexValue }">青色text</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">image 组件</text>
|
||||
<text class="uni-info">设置值: {{data.zIndexValue}}</text>
|
||||
<text class="uni-info">获取值: {{data.zIndexActualImage}}</text>
|
||||
<view class="test-box">
|
||||
<image class="common-bg common-image-bg" style="z-index: 1;" src="/static/test-image/logo.png"></image>
|
||||
<image ref="imageRef" class="common-dynamic common-image-bg test-image" :style="{ zIndex: data.zIndexValue }" src="/static/test-image/logo.png"></image>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="uni-common-mt uni-common-mb">
|
||||
<text class="uni-tips">第一个枚举值,'' (空字符串) - 空值情况</text>
|
||||
<enum-data :items="zIndexEnum" title="z-index 枚举值" @change="radioChangeZIndex" :compact="true"></enum-data>
|
||||
<input-data :defaultValue="data.zIndexValue.toString()" title="z-index 自定义值" type="number" @confirm="inputChangeZIndex"></input-data>
|
||||
</view>
|
||||
|
||||
<view class="uni-common-mb" style="top: 50px;">
|
||||
<text>native-view组件: z-index: 10 和 z-index: 5</text>
|
||||
<test-native-view class="common-text" style="z-index: 10; background-color: cyan;"></test-native-view>
|
||||
<test-native-view class="common-text" style="top: -40px;left: 30px;z-index: 5;background-color: green;"></test-native-view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- #ifdef APP && !VUE3-VAPOR -->
|
||||
</scroll-view>
|
||||
<!-- #endif -->
|
||||
</template>
|
||||
|
||||
<script setup lang="uts">
|
||||
import { ItemType } from '@/components/enum-data/enum-data-types'
|
||||
|
||||
type DataType = {
|
||||
zIndex : number
|
||||
autoTest : boolean
|
||||
zIndexValue : number
|
||||
zIndexActual : string
|
||||
zIndexActualText : string
|
||||
zIndexActualImage : string
|
||||
}
|
||||
|
||||
const data = reactive({
|
||||
zIndex: 5,
|
||||
autoTest: false,
|
||||
zIndexValue: 5,
|
||||
zIndexActual: '',
|
||||
zIndexActualText: '',
|
||||
zIndexActualImage: ''
|
||||
} as DataType)
|
||||
|
||||
const view = ref(null as UniElement | null)
|
||||
|
||||
const changeZIndex = (zIndexValue : number) => {
|
||||
data.zIndex = 20
|
||||
view.value?.style.setProperty('z-index', zIndexValue)
|
||||
}
|
||||
|
||||
const zIndexEnum : ItemType[] = [
|
||||
{ value: 0, name: '' },
|
||||
{ value: 1, name: '-1' },
|
||||
{ value: 2, name: '0' },
|
||||
{ value: 3, name: '1' },
|
||||
{ value: 4, name: '10' },
|
||||
]
|
||||
|
||||
const viewRef = ref(null as UniElement | null)
|
||||
const textRef = ref(null as UniTextElement | null)
|
||||
const imageRef = ref(null as UniImageElement | null)
|
||||
|
||||
const getPropertyValues = () => {
|
||||
data.zIndexActual = viewRef.value?.style.getPropertyValue('z-index') ?? ''
|
||||
data.zIndexActualText = textRef.value?.style.getPropertyValue('z-index') ?? ''
|
||||
data.zIndexActualImage = imageRef.value?.style.getPropertyValue('z-index') ?? ''
|
||||
}
|
||||
|
||||
const changeZIndexProperty = (value : number) => {
|
||||
data.zIndexValue = value
|
||||
viewRef.value?.style.setProperty('z-index', value)
|
||||
textRef.value?.style.setProperty('z-index', value.toString())
|
||||
imageRef.value?.style.setProperty('z-index', value.toString())
|
||||
// 使用 nextTick 确保样式已应用后再获取值
|
||||
nextTick(() => {
|
||||
getPropertyValues()
|
||||
})
|
||||
}
|
||||
|
||||
const radioChangeZIndex = (index : number) => {
|
||||
const selectedItem = zIndexEnum.find((item) : boolean => item.value === index)
|
||||
if (selectedItem != null) {
|
||||
const value = selectedItem.name === '' ? 0 : parseInt(selectedItem.name)
|
||||
changeZIndexProperty(value)
|
||||
}
|
||||
}
|
||||
|
||||
const inputChangeZIndex = (value : string) => {
|
||||
const numValue = parseInt(value)
|
||||
if (!isNaN(numValue)) {
|
||||
changeZIndexProperty(numValue)
|
||||
}
|
||||
}
|
||||
|
||||
onReady(() => {
|
||||
getPropertyValues()
|
||||
})
|
||||
|
||||
defineExpose({
|
||||
data,
|
||||
changeZIndex,
|
||||
radioChangeZIndex
|
||||
})
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.common {
|
||||
width: 125px;
|
||||
height: 125px;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.common-text {
|
||||
width: 125px;
|
||||
height: 125px;
|
||||
}
|
||||
|
||||
.fixed {
|
||||
position: fixed;
|
||||
}
|
||||
|
||||
.default {
|
||||
background-color: yellow;
|
||||
z-index: 10;
|
||||
top: var(--uni-safe-area-inset-top);
|
||||
left: var(--uni-safe-area-inset-left);
|
||||
}
|
||||
|
||||
.specified {
|
||||
background-color: yellowgreen;
|
||||
z-index: 5;
|
||||
/* #ifdef APP || MP */
|
||||
top: 87px;
|
||||
left: 87px;
|
||||
/* #endif */
|
||||
/* #ifdef WEB */
|
||||
top: calc(var(--uni-safe-area-inset-top) + 87px);
|
||||
left: calc(var(--uni-safe-area-inset-left) + 87px);
|
||||
/* #endif */
|
||||
}
|
||||
|
||||
.floor {
|
||||
background-color: chocolate;
|
||||
/* #ifdef APP || MP */
|
||||
top: 250px;
|
||||
left: 175px;
|
||||
/* #endif */
|
||||
/* #ifdef WEB */
|
||||
top: calc(var(--uni-safe-area-inset-top) + 250px);
|
||||
left: calc(var(--uni-safe-area-inset-left) + 175px);
|
||||
/* #endif */
|
||||
z-index: -1;
|
||||
}
|
||||
|
||||
.popup {
|
||||
/* #ifdef APP || MP */
|
||||
top: 320px;
|
||||
left: 87px;
|
||||
/* #endif */
|
||||
/* #ifdef WEB */
|
||||
top: calc(var(--uni-safe-area-inset-top) + 320px);
|
||||
left: calc(var(--uni-safe-area-inset-left) + 87px);
|
||||
/* #endif */
|
||||
height: 40px;
|
||||
}
|
||||
|
||||
.image-zindex {
|
||||
width: 125px;
|
||||
height: 125px;
|
||||
background-color: rgba(255, 255, 255, 0.5);
|
||||
}
|
||||
|
||||
.common-dynamic {
|
||||
width: 80px;
|
||||
height: 80px;
|
||||
position: absolute;
|
||||
top: 20px;
|
||||
left: 20px;
|
||||
}
|
||||
|
||||
.common-bg {
|
||||
width: 80px;
|
||||
height: 80px;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
}
|
||||
|
||||
.common-text-bg {
|
||||
color: white;
|
||||
font-size: 12px;
|
||||
padding: 5px;
|
||||
}
|
||||
|
||||
.common-image-bg {
|
||||
width: 80px;
|
||||
height: 80px;
|
||||
}
|
||||
|
||||
.test-container {
|
||||
flex-direction: row;
|
||||
justify-content: space-between;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.test-item {
|
||||
flex: 1;
|
||||
margin: 0 5px;
|
||||
}
|
||||
|
||||
.test-box {
|
||||
width: 100%;
|
||||
height: 120px;
|
||||
background-color: gray;
|
||||
position: relative;
|
||||
}
|
||||
</style>
|
||||
在新工单中引用
屏蔽一个用户