231 行
8.0 KiB
Plaintext
231 行
8.0 KiB
Plaintext
<template>
|
|
<!-- #ifdef APP && !VUE3-VAPOR -->
|
|
<scroll-view style="flex: 1">
|
|
<!-- #endif -->
|
|
<view style="flex-grow: 1;">
|
|
<view>
|
|
<text>border-bottom: 5px dashed blue</text>
|
|
<view class="demo-box">
|
|
<view class="common" style="border-bottom: 5px dashed blue;"></view>
|
|
<view class="common" style="border-bottom: 5px dashed blue;" flatten></view>
|
|
</view>
|
|
</view>
|
|
|
|
<view>
|
|
<text>border-bottom: 6rpx dashed #0000ff80</text>
|
|
<view class="demo-box">
|
|
<view class="common" style="border-bottom: 6rpx dashed #0000ff80;"></view>
|
|
<view class="common" style="border-bottom: 6rpx dashed #0000ff80;" flatten></view>
|
|
</view>
|
|
</view>
|
|
|
|
<text class="uni-title-text uni-common-mt">scroll-view 组件</text>
|
|
|
|
<view class="demo-box">
|
|
<scroll-view class="common" style="border-bottom: 5px dashed blue;">
|
|
<text class="common-text">border-bottom: 5px dashed blue</text>
|
|
</scroll-view>
|
|
<scroll-view class="common" style="border-bottom: 10px solid green;">
|
|
<text class="common-text">border-bottom: 10px solid green</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.borderBottom}}</text>
|
|
<text class="uni-info">获取值: {{data.borderBottomActual}}</text>
|
|
<view class="test-box">
|
|
<view ref="viewRef" class="common-dynamic test-view" :style="{ borderBottom: data.borderBottom }">
|
|
<text>view</text>
|
|
</view>
|
|
</view>
|
|
</view>
|
|
|
|
<view class="test-item">
|
|
<text class="uni-subtitle-text">text 组件</text>
|
|
<text class="uni-info">设置值: {{data.borderBottom}}</text>
|
|
<text class="uni-info">获取值: {{data.borderBottomActualText}}</text>
|
|
<view class="test-box">
|
|
<text ref="textRef" class="common-dynamic test-text" :style="{ borderBottom: data.borderBottom }">text</text>
|
|
</view>
|
|
</view>
|
|
|
|
<view class="test-item">
|
|
<text class="uni-subtitle-text">image 组件</text>
|
|
<text class="uni-info">设置值: {{data.borderBottom}}</text>
|
|
<text class="uni-info">获取值: {{data.borderBottomActualImage}}</text>
|
|
<view class="test-box">
|
|
<image ref="imageRef" class="common-image test-image" :style="{ borderBottom: data.borderBottom }" 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.borderBottom}}</text>
|
|
<text class="uni-info">获取值: {{data.borderBottomActualFlat}}</text>
|
|
<view class="test-box">
|
|
<view ref="viewRefFlat" class="common-dynamic test-view-flatten" :style="{ borderBottom: data.borderBottom }" flatten>
|
|
<text>view</text>
|
|
</view>
|
|
</view>
|
|
</view>
|
|
|
|
<view class="test-item">
|
|
<text class="uni-subtitle-text">text 组件拍平</text>
|
|
<text class="uni-info">设置值: {{data.borderBottom}}</text>
|
|
<text class="uni-info">获取值: {{data.borderBottomActualTextFlat}}</text>
|
|
<view class="test-box">
|
|
<text ref="textRefFlat" class="common-dynamic test-text-flatten" :style="{ borderBottom: data.borderBottom }" flatten>text</text>
|
|
</view>
|
|
</view>
|
|
|
|
<view class="test-item">
|
|
<text class="uni-subtitle-text">image 组件拍平</text>
|
|
<text class="uni-info">设置值: {{data.borderBottom}}</text>
|
|
<text class="uni-info">获取值: {{data.borderBottomActualImageFlat}}</text>
|
|
<view class="test-box">
|
|
<image ref="imageRefFlat" class="common-image test-image-flatten" :style="{ borderBottom: data.borderBottom }" 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="borderBottomEnum" title="border-bottom 枚举值" @change="radioChangeBorderBottom" :compact="true"></enum-data>
|
|
<input-data :defaultValue="data.borderBottom" title="border-bottom 自定义值" type="text" @confirm="inputChangeBorderBottom"></input-data>
|
|
</view>
|
|
|
|
</view>
|
|
<!-- #ifdef APP && !VUE3-VAPOR -->
|
|
</scroll-view>
|
|
<!-- #endif -->
|
|
</template>
|
|
|
|
<script setup>
|
|
import { ItemType } from '@/components/enum-data/enum-data-types'
|
|
|
|
const borderBottomEnum: ItemType[] = [
|
|
{ value: 0, name: '' },
|
|
{ value: 1, name: 'none' },
|
|
{ value: 2, name: '1px solid black' },
|
|
{ value: 3, name: '2px dashed blue' },
|
|
{ value: 4, name: '3px dotted green' },
|
|
{ value: 5, name: '8rpx solid #0000ff80' },
|
|
]
|
|
|
|
const data = reactive({
|
|
borderBottom: '6rpx dashed #0000ff80',
|
|
borderBottomActual: '',
|
|
borderBottomActualText: '',
|
|
borderBottomActualImage: '',
|
|
borderBottomActualFlat: '',
|
|
borderBottomActualTextFlat: '',
|
|
borderBottomActualImageFlat: ''
|
|
})
|
|
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.borderBottomActual = viewRef.value?.style.getPropertyValue('border-bottom') ?? ''
|
|
data.borderBottomActualFlat = viewRefFlat.value?.style.getPropertyValue('border-bottom') ?? ''
|
|
data.borderBottomActualText = textRef.value?.style.getPropertyValue('border-bottom') ?? ''
|
|
data.borderBottomActualTextFlat = textRefFlat.value?.style.getPropertyValue('border-bottom') ?? ''
|
|
data.borderBottomActualImage = imageRef.value?.style.getPropertyValue('border-bottom') ?? ''
|
|
data.borderBottomActualImageFlat = imageRefFlat.value?.style.getPropertyValue('border-bottom') ?? ''
|
|
}
|
|
|
|
const changeBorderBottom = (value: string) => {
|
|
data.borderBottom = value
|
|
viewRef.value?.style.setProperty('border-bottom', value)
|
|
viewRefFlat.value?.style.setProperty('border-bottom', value)
|
|
textRef.value?.style.setProperty('border-bottom', value)
|
|
textRefFlat.value?.style.setProperty('border-bottom', value)
|
|
imageRef.value?.style.setProperty('border-bottom', value)
|
|
imageRefFlat.value?.style.setProperty('border-bottom', value)
|
|
// 使用 nextTick 确保样式已应用后再获取值
|
|
nextTick(() => {
|
|
getPropertyValues()
|
|
})
|
|
}
|
|
|
|
const radioChangeBorderBottom = (index: number) => {
|
|
const selectedItem = borderBottomEnum.find((item): boolean => item.value === index)
|
|
if (selectedItem != null) {
|
|
changeBorderBottom(selectedItem.name)
|
|
}
|
|
}
|
|
|
|
const inputChangeBorderBottom = (value: string) => {
|
|
changeBorderBottom(value)
|
|
}
|
|
|
|
onReady(() => {
|
|
getPropertyValues()
|
|
})
|
|
|
|
defineExpose({
|
|
radioChangeBorderBottom,
|
|
data
|
|
})
|
|
</script>
|
|
|
|
<style>
|
|
.common {
|
|
width: 150px;
|
|
height: 50px;
|
|
background-color: gray;
|
|
}
|
|
|
|
.demo-box {
|
|
flex-direction: row;
|
|
margin-top: 10px;
|
|
justify-content: space-between;
|
|
}
|
|
|
|
.common-dynamic {
|
|
height: 50px;
|
|
background-color: gray;
|
|
}
|
|
|
|
.common-image {
|
|
width: 50px;
|
|
height: 50px;
|
|
background-color: gray;
|
|
}
|
|
|
|
.test-container {
|
|
flex-direction: row;
|
|
justify-content: space-between;
|
|
margin-top: 10px;
|
|
}
|
|
|
|
.test-item {
|
|
flex: 1;
|
|
margin: 0 5px;
|
|
}
|
|
|
|
.test-box {
|
|
width: 100%;
|
|
height: 60px;
|
|
background-color: lightgray;
|
|
}
|
|
|
|
.common-text {
|
|
font-size: 12px;
|
|
}
|
|
|
|
</style>
|