139 行
4.3 KiB
Plaintext
139 行
4.3 KiB
Plaintext
<template>
|
|
<!-- #ifdef APP && !VUE3-VAPOR -->
|
|
<scroll-view style="flex: 1">
|
|
<!-- #endif -->
|
|
<view style="flex-grow: 1;">
|
|
<text class="uni-tips">说明:左边是正常版本,右边是拍平版本</text>
|
|
<view class="demo-box">
|
|
<view class="common">
|
|
<text class="common-size" style="font-style: italic;">font-style: italic</text>
|
|
<text class="common-size" style="font-style: normal;">font-style: normal</text>
|
|
</view>
|
|
<view class="common">
|
|
<text class="common-size" style="font-style: italic;" flatten>font-style: italic</text>
|
|
<text class="common-size" style="font-style: normal;" flatten>font-style: normal</text>
|
|
</view>
|
|
</view>
|
|
|
|
<view class="uni-common-mt">
|
|
<text class="uni-title-text">setProperty 设置与 getPropertyValue 获取</text>
|
|
</view>
|
|
|
|
<view class="common-box">
|
|
<!-- 普通版本 -->
|
|
<view class="uni-common-mt">
|
|
<text class="uni-title-text">font-style</text>
|
|
<text class="uni-info">设置值: {{data.fontStyle}}</text>
|
|
<text class="uni-info">获取值: {{data.fontStyleActual}}</text>
|
|
<view class="test-box">
|
|
<text ref="textRef" class="common-size test-text" :style="{ fontStyle: data.fontStyle }">当前 font-style: {{data.fontStyle}}</text>
|
|
</view>
|
|
</view>
|
|
|
|
<!-- 拍平版本 -->
|
|
<view class="uni-common-mt">
|
|
<text class="uni-title-text">测试拍平</text>
|
|
<text class="uni-info">设置值: {{data.fontStyle}}</text>
|
|
<text class="uni-info">获取值: {{data.fontStyleActualFlat}}</text>
|
|
<view class="test-box">
|
|
<text ref="textRefFlat" class="common-size test-text-flatten" :style="{ fontStyle: data.fontStyle }" flatten>当前 font-style: {{data.fontStyle}}</text>
|
|
</view>
|
|
</view>
|
|
</view>
|
|
|
|
<view class="uni-common-mt uni-common-mb">
|
|
<text class="uni-tips">第一个枚举值,'' (空字符串) - 空值情况</text>
|
|
<enum-data :items="fontStyleEnum" title="font-style 枚举值" @change="radioChangeFontStyle" :compact="true"></enum-data>
|
|
<input-data :defaultValue="data.fontStyle" title="font-style 自定义值" type="text" @confirm="inputChangeFontStyle"></input-data>
|
|
</view>
|
|
</view>
|
|
<!-- #ifdef APP && !VUE3-VAPOR -->
|
|
</scroll-view>
|
|
<!-- #endif -->
|
|
</template>
|
|
|
|
<script setup lang="uts">
|
|
import { ItemType } from '@/components/enum-data/enum-data-types'
|
|
|
|
const fontStyleEnum: ItemType[] = [
|
|
{ value: 0, name: '' },
|
|
{ value: 1, name: 'normal' },
|
|
{ value: 2, name: 'italic' }
|
|
]
|
|
|
|
const data = reactive({
|
|
fontStyle: 'normal',
|
|
fontStyleActual: '',
|
|
fontStyleActualFlat: ''
|
|
})
|
|
const textRef = ref(null as UniTextElement | null)
|
|
const textRefFlat = ref(null as UniTextElement | null)
|
|
|
|
const getPropertyValues = () => {
|
|
data.fontStyleActual = textRef.value?.style.getPropertyValue('font-style') ?? ''
|
|
data.fontStyleActualFlat = textRefFlat.value?.style.getPropertyValue('font-style') ?? ''
|
|
}
|
|
|
|
|
|
const changeFontStyle = (value: string) => {
|
|
data.fontStyle = value
|
|
textRef.value?.style.setProperty('font-style', value)
|
|
textRefFlat.value?.style.setProperty('font-style', value)
|
|
// 使用 nextTick 确保样式已应用后再获取值
|
|
nextTick(() => {
|
|
getPropertyValues()
|
|
})
|
|
}
|
|
|
|
const radioChangeFontStyle = (index: number) => {
|
|
const selectedItem = fontStyleEnum.find((item): boolean => item.value === index)
|
|
if (selectedItem != null) {
|
|
changeFontStyle(selectedItem.name)
|
|
}
|
|
}
|
|
|
|
const inputChangeFontStyle = (value: string) => {
|
|
changeFontStyle(value)
|
|
}
|
|
|
|
onReady(() => {
|
|
getPropertyValues()
|
|
})
|
|
|
|
defineExpose({
|
|
radioChangeFontStyle,
|
|
data
|
|
})
|
|
</script>
|
|
|
|
<style>
|
|
.common-size {
|
|
font-size: 20px;
|
|
}
|
|
.common{
|
|
height: 100px;
|
|
background-color: gray;
|
|
justify-content: center;
|
|
align-items: center;
|
|
flex:1;
|
|
}
|
|
.demo-box {
|
|
flex-direction: row;
|
|
margin-top: 10px;
|
|
justify-content: space-around;
|
|
}
|
|
.common-box{
|
|
flex-direction: row;
|
|
justify-content: space-around;
|
|
}
|
|
|
|
.test-box {
|
|
width: 180px;
|
|
height: 80px;
|
|
background-color: gray;
|
|
justify-content: center;
|
|
align-items: center;
|
|
}
|
|
|
|
</style>
|