205 行
6.4 KiB
Plaintext
205 行
6.4 KiB
Plaintext
<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>
|