refactor: 确立独立子工程架构 (backend, admin, mpuniapp) 并同步更新 AGENTS.md 规范
这个提交包含在:
@@ -0,0 +1,353 @@
|
||||
<template>
|
||||
<!-- #ifdef APP && !VUE3-VAPOR -->
|
||||
<scroll-view style="flex:1;">
|
||||
<!-- #endif -->
|
||||
<view style="flex-grow: 1;">
|
||||
<text class="uni-tips">说明:左边是正常版本,右边是拍平版本</text>
|
||||
<view>
|
||||
<text>margin-left: auto (元素会靠右)</text>
|
||||
<view class="demo-box">
|
||||
<view class="demo-item">
|
||||
<view class="common" style="width: 150px; margin-left: auto;"></view>
|
||||
</view>
|
||||
<view class="demo-item">
|
||||
<view class="common" style="width: 150px; margin-left: auto;" flatten></view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view>
|
||||
<text>margin-right: auto (元素会靠左)</text>
|
||||
<view class="demo-box">
|
||||
<view class="demo-item">
|
||||
<view class="common" style="width: 150px; margin-right: auto;"></view>
|
||||
</view>
|
||||
<view class="demo-item">
|
||||
<view class="common" style="width: 150px; margin-right: auto;" flatten></view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view>
|
||||
<text>margin-left: auto; margin-right: auto (水平居中)</text>
|
||||
<view class="demo-box">
|
||||
<view class="demo-item">
|
||||
<view class="common" style="width: 150px; margin-left: auto; margin-right: auto;"></view>
|
||||
</view>
|
||||
<view class="demo-item">
|
||||
<view class="common" style="width: 150px; margin-left: auto; margin-right: auto;" flatten></view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view>
|
||||
<text>margin: 0 auto (常用的水平居中写法)</text>
|
||||
<view class="demo-box">
|
||||
<view class="demo-item">
|
||||
<view class="common" style="width: 150px; margin: 0 auto;"></view>
|
||||
</view>
|
||||
<view class="demo-item">
|
||||
<view class="common" style="width: 150px; margin: 0 auto;" flatten></view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view>
|
||||
<text>margin: auto (所有方向auto)</text>
|
||||
<view class="demo-box">
|
||||
<view class="demo-item demo-item-tall">
|
||||
<view class="common" style="width: 150px; height: 80px; margin: auto;"></view>
|
||||
</view>
|
||||
<view class="demo-item demo-item-tall">
|
||||
<view class="common" style="width: 150px; height: 80px; margin: auto;" flatten></view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view>
|
||||
<text>margin: 10px auto (垂直固定,水平auto)</text>
|
||||
<view class="demo-box">
|
||||
<view class="demo-item demo-item-medium">
|
||||
<view class="common" style="width: 150px; margin: 10px auto;"></view>
|
||||
</view>
|
||||
<view class="demo-item demo-item-medium">
|
||||
<view class="common" style="width: 150px; margin: 10px auto;" flatten></view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view>
|
||||
<text>margin: auto 20px (垂直auto,水平固定)</text>
|
||||
<view class="demo-box">
|
||||
<view class="demo-item">
|
||||
<view class="common" style="width: 150px; margin: auto 20px;"></view>
|
||||
</view>
|
||||
<view class="demo-item">
|
||||
<view class="common" style="width: 150px; margin: auto 20px;" flatten></view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view>
|
||||
<text>对比: 无margin (默认左对齐)</text>
|
||||
<view class="demo-box">
|
||||
<view class="demo-item">
|
||||
<view class="common" style="width: 150px;"></view>
|
||||
</view>
|
||||
<view class="demo-item">
|
||||
<view class="common" style="width: 150px;" flatten></view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="uni-common-mt">
|
||||
<text class="uni-title-text">scroll-view 组件</text>
|
||||
</view>
|
||||
|
||||
<view>
|
||||
<text class="uni-subtitle-text">margin-left: auto (元素会靠右) 和 margin-right: auto (元素会靠左)</text>
|
||||
<view class="demo-box">
|
||||
<view class="demo-item">
|
||||
<scroll-view class="scroll-view-test" style="margin-left: auto;"></scroll-view>
|
||||
</view>
|
||||
<view class="demo-item">
|
||||
<scroll-view class="scroll-view-test" style="margin-right: auto;"></scroll-view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view>
|
||||
<text class="uni-subtitle-text">margin: auto 20px (垂直auto,水平固定) 和 margin: auto;(水平居中)</text>
|
||||
<view class="demo-box">
|
||||
<view class="demo-item">
|
||||
<scroll-view class="scroll-view-test" style="margin: auto 20px;"></scroll-view>
|
||||
</view>
|
||||
<view class="demo-item">
|
||||
<scroll-view class="scroll-view-test" style="margin: auto;"></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.margin}}</text>
|
||||
<text class="uni-info">获取值: {{data.marginActual}}</text>
|
||||
<view class="test-box">
|
||||
<view ref="viewRef" class="common test-view" style="width: 100px;" :style="{ margin: data.margin }">
|
||||
<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.margin}}</text>
|
||||
<text class="uni-info">获取值: {{data.marginActualText}}</text>
|
||||
<view class="test-box">
|
||||
<text ref="textRef" class="common-text test-text" style="width: 100px;" :style="{ margin: data.margin }">text</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">image 组件</text>
|
||||
<text class="uni-info">设置值: {{data.margin}}</text>
|
||||
<text class="uni-info">获取值: {{data.marginActualImage}}</text>
|
||||
<view class="test-box">
|
||||
<image ref="imageRef" class="common-image test-image" :style="{ margin: data.margin }" 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.margin}}</text>
|
||||
<text class="uni-info">获取值: {{data.marginActualFlat}}</text>
|
||||
<view class="test-box">
|
||||
<view ref="viewRefFlat" class="common test-view-flatten" style="width: 100px;" :style="{ margin: data.margin }" 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.margin}}</text>
|
||||
<text class="uni-info">获取值: {{data.marginActualTextFlat}}</text>
|
||||
<view class="test-box">
|
||||
<text ref="textRefFlat" class="common-text test-text-flatten" style="width: 100px;" :style="{ margin: data.margin }" flatten>text</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">image 组件拍平</text>
|
||||
<text class="uni-info">设置值: {{data.margin}}</text>
|
||||
<text class="uni-info">获取值: {{data.marginActualImageFlat}}</text>
|
||||
<view class="test-box">
|
||||
<image ref="imageRefFlat" class="common-image test-image-flatten" :style="{ margin: data.margin }" 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="marginAutoEnum" title="margin 枚举值" @change="radioChangeMargin" :compact="true"></enum-data>
|
||||
<input-data :defaultValue="data.margin" title="margin 自定义值" type="text" @confirm="inputChangeMargin"></input-data>
|
||||
</view>
|
||||
|
||||
<view class="uni-common-mb">
|
||||
<text>native-view组件: margin-left: auto 和 margin: auto</text>
|
||||
<view class="demo-box">
|
||||
<view class="demo-item">
|
||||
<test-native-view class="common" style="width: 150px; margin-left: auto;"></test-native-view>
|
||||
</view>
|
||||
<view class="demo-item">
|
||||
<test-native-view class="common" style="width: 150px; margin: auto;"></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 data = reactive({
|
||||
margin: '0 auto',
|
||||
marginActual: '',
|
||||
marginActualText: '',
|
||||
marginActualImage: '',
|
||||
marginActualFlat: '',
|
||||
marginActualTextFlat: '',
|
||||
marginActualImageFlat: ''
|
||||
})
|
||||
|
||||
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 marginAutoEnum: ItemType[] = [
|
||||
{ value: 0, name: '' },
|
||||
{ value: 1, name: 'auto' },
|
||||
{ value: 2, name: '0' },
|
||||
{ value: 3, name: '20px' },
|
||||
{ value: 4, name: '10%' }
|
||||
]
|
||||
|
||||
const getPropertyValues = () => {
|
||||
data.marginActual = viewRef.value?.style.getPropertyValue('margin') ?? ''
|
||||
data.marginActualFlat = viewRefFlat.value?.style.getPropertyValue('margin') ?? ''
|
||||
data.marginActualText = textRef.value?.style.getPropertyValue('margin') ?? ''
|
||||
data.marginActualTextFlat = textRefFlat.value?.style.getPropertyValue('margin') ?? ''
|
||||
data.marginActualImage = imageRef.value?.style.getPropertyValue('margin') ?? ''
|
||||
data.marginActualImageFlat = imageRefFlat.value?.style.getPropertyValue('margin') ?? ''
|
||||
}
|
||||
|
||||
|
||||
const changeMargin = (value: string) => {
|
||||
data.margin = value
|
||||
viewRef.value?.style.setProperty('margin', value)
|
||||
viewRefFlat.value?.style.setProperty('margin', value)
|
||||
textRef.value?.style.setProperty('margin', value)
|
||||
textRefFlat.value?.style.setProperty('margin', value)
|
||||
imageRef.value?.style.setProperty('margin', value)
|
||||
imageRefFlat.value?.style.setProperty('margin', value)
|
||||
// 使用 nextTick 确保样式已应用后再获取值
|
||||
nextTick(() => {
|
||||
getPropertyValues()
|
||||
})
|
||||
}
|
||||
|
||||
const radioChangeMargin = (index: number) => {
|
||||
const selectedItem = marginAutoEnum.find((item): boolean => item.value === index)
|
||||
if (selectedItem != null) {
|
||||
changeMargin(selectedItem.name)
|
||||
}
|
||||
}
|
||||
|
||||
const inputChangeMargin = (value: string) => {
|
||||
changeMargin(value)
|
||||
}
|
||||
|
||||
onReady(() => {
|
||||
getPropertyValues()
|
||||
})
|
||||
|
||||
defineExpose({
|
||||
radioChangeMargin,
|
||||
data
|
||||
})
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.common {
|
||||
height: 50px;
|
||||
background-color: green;
|
||||
}
|
||||
.demo-box {
|
||||
flex-direction: row;
|
||||
margin-top: 10px;
|
||||
justify-content: space-around;
|
||||
}
|
||||
.demo-item {
|
||||
flex: 1;
|
||||
margin:0 10px;
|
||||
height: 100px;
|
||||
background-color: gray;
|
||||
}
|
||||
|
||||
.demo-item-medium {
|
||||
height: 120px;
|
||||
}
|
||||
|
||||
.demo-item-tall {
|
||||
height: 150px;
|
||||
}
|
||||
|
||||
.scroll-view-test {
|
||||
width: 100px;
|
||||
height: 100px;
|
||||
background-color: green;
|
||||
}
|
||||
|
||||
.common-text {
|
||||
height: 50px;
|
||||
background-color: green;
|
||||
font-size: 14px;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.common-image {
|
||||
width: 50px;
|
||||
height: 50px;
|
||||
background-color: green;
|
||||
}
|
||||
|
||||
.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;
|
||||
}
|
||||
|
||||
</style>
|
||||
@@ -0,0 +1,303 @@
|
||||
<template>
|
||||
<!-- #ifdef APP && !VUE3-VAPOR -->
|
||||
<scroll-view style="flex: 1">
|
||||
<!-- #endif -->
|
||||
<view style="flex-grow: 1;">
|
||||
<text class="uni-tips">说明:左边是正常版本,右边是拍平版本</text>
|
||||
<view>
|
||||
<text>margin-bottom: 25px</text>
|
||||
<view class="demo-box">
|
||||
<view class="demo-container">
|
||||
<view class="common red"></view>
|
||||
<view class="common" style="margin-bottom: 25px;"></view>
|
||||
<view class="common blue"></view>
|
||||
</view>
|
||||
<view class="demo-container">
|
||||
<view class="common red"></view>
|
||||
<view class="common" style="margin-bottom: 25px;" flatten></view>
|
||||
<view class="common blue"></view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view>
|
||||
<text>margin-bottom: 10%</text>
|
||||
<view class="demo-box">
|
||||
<view class="demo-container">
|
||||
<view class="common red"></view>
|
||||
<view class="common" style="margin-bottom: 10%;"></view>
|
||||
<view class="common blue"></view>
|
||||
</view>
|
||||
<view class="demo-container">
|
||||
<view class="common red"></view>
|
||||
<view class="common" style="margin-bottom: 10%;" flatten></view>
|
||||
<view class="common blue"></view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="uni-common-mt">
|
||||
<text class="uni-title-text">scroll-view 组件</text>
|
||||
</view>
|
||||
<view>
|
||||
<text class="uni-subtitle-text">margin-bottom: 10% 和 margin-bottom: 30px</text>
|
||||
<view class="demo-box">
|
||||
<view class="demo-container">
|
||||
<view class="common red"></view>
|
||||
<scroll-view class="common" style="margin-bottom: 10%;"></scroll-view>
|
||||
<view class="common blue"></view>
|
||||
</view>
|
||||
<view class="demo-container">
|
||||
<view class="common red"></view>
|
||||
<scroll-view class="common" style="margin-bottom: 30px;"></scroll-view>
|
||||
<view class="common blue"></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.marginBottom}}</text>
|
||||
<text class="uni-info">获取值: {{data.marginBottomActual}}</text>
|
||||
<view class="test-box">
|
||||
<view class="common-view" style="background-color: red;"></view>
|
||||
<view ref="viewRef" class="common-view test-view" :style="{ marginBottom: data.marginBottom }">
|
||||
<text class="common-text">view</text>
|
||||
</view>
|
||||
<view class="common-view" style="background-color: blue;"></view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">text 组件</text>
|
||||
<text class="uni-info">设置值: {{data.marginBottom}}</text>
|
||||
<text class="uni-info">获取值: {{data.marginBottomActualText}}</text>
|
||||
<view class="test-box">
|
||||
<text class="common-view common-text" style="background-color: red;">红色</text>
|
||||
<text ref="textRef" class="common-view common-text test-text" :style="{ marginBottom: data.marginBottom }">text</text>
|
||||
<text class="common-view common-text" style="background-color: blue;">蓝色</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">image 组件</text>
|
||||
<text class="uni-info">设置值: {{data.marginBottom}}</text>
|
||||
<text class="uni-info">获取值: {{data.marginBottomActualImage}}</text>
|
||||
<view class="test-box">
|
||||
<image class="common-image" style="background-color: red;" src="/static/test-image/logo.png"></image>
|
||||
<image ref="imageRef" class="common-image test-image" :style="{ marginBottom: data.marginBottom }" src="/static/test-image/logo.png"></image>
|
||||
<image class="common-image" style="background-color: blue;" 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.marginBottom}}</text>
|
||||
<text class="uni-info">获取值: {{data.marginBottomActualFlat}}</text>
|
||||
<view class="test-box">
|
||||
<view class="common-view" style="background-color: red;"></view>
|
||||
<view ref="viewRefFlat" class="common-view test-view-flatten" :style="{ marginBottom: data.marginBottom }" flatten>
|
||||
<text class="common-text">view</text>
|
||||
</view>
|
||||
<view class="common-view" style="background-color: blue;"></view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">text 组件拍平</text>
|
||||
<text class="uni-info">设置值: {{data.marginBottom}}</text>
|
||||
<text class="uni-info">获取值: {{data.marginBottomActualTextFlat}}</text>
|
||||
<view class="test-box">
|
||||
<text class="common-view common-text" style="background-color: red;">红色</text>
|
||||
<text ref="textRefFlat" class="common-view common-text test-text-flatten" :style="{ marginBottom: data.marginBottom }" flatten>text</text>
|
||||
<text class="common-view common-text" style="background-color: blue;">蓝色</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">image 组件拍平</text>
|
||||
<text class="uni-info">设置值: {{data.marginBottom}}</text>
|
||||
<text class="uni-info">获取值: {{data.marginBottomActualImageFlat}}</text>
|
||||
<view class="test-box">
|
||||
<image class="common-image" style="background-color: red;" src="/static/test-image/logo.png"></image>
|
||||
<image ref="imageRefFlat" class="common-image test-image-flatten" :style="{ marginBottom: data.marginBottom }" flatten src="/static/test-image/logo.png"></image>
|
||||
<image class="common-image" style="background-color: blue;" 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="marginBottomEnum" title="margin-bottom 枚举值" @change="radioChangeMarginBottom" :compact="true"></enum-data>
|
||||
<input-data :defaultValue="data.marginBottom" title="margin-bottom 自定义值" type="text" @confirm="inputChangeMarginBottom"></input-data>
|
||||
</view>
|
||||
|
||||
<view class="uni-common-mb">
|
||||
<text>native-view组件: margin-bottom: 25px 和 10%</text>
|
||||
<view class="demo-box">
|
||||
<view class="demo-container">
|
||||
<view class="common red"></view>
|
||||
<test-native-view class="common" style="margin-bottom: 25px;"></test-native-view>
|
||||
<view class="common blue"></view>
|
||||
</view>
|
||||
<view class="demo-container">
|
||||
<view class="common red"></view>
|
||||
<test-native-view class="common" style="margin-bottom: 10%;"></test-native-view>
|
||||
<view class="common blue"></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 data = reactive({
|
||||
marginBottom: '25px',
|
||||
marginBottomActual: '',
|
||||
marginBottomActualText: '',
|
||||
marginBottomActualImage: '',
|
||||
marginBottomActualFlat: '',
|
||||
marginBottomActualTextFlat: '',
|
||||
marginBottomActualImageFlat: ''
|
||||
})
|
||||
|
||||
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 marginBottomEnum: ItemType[] = [
|
||||
{ value: 0, name: '' },
|
||||
{ value: 1, name: '0' },
|
||||
{ value: 2, name: '0px' },
|
||||
{ value: 3, name: '20px' },
|
||||
{ value: 4, name: '0%' },
|
||||
{ value: 5, name: '10%' },
|
||||
{ value: 6, name: 'auto' }
|
||||
]
|
||||
|
||||
const getPropertyValues = () => {
|
||||
data.marginBottomActual = viewRef.value?.style.getPropertyValue('margin-bottom') ?? ''
|
||||
data.marginBottomActualFlat = viewRefFlat.value?.style.getPropertyValue('margin-bottom') ?? ''
|
||||
data.marginBottomActualText = textRef.value?.style.getPropertyValue('margin-bottom') ?? ''
|
||||
data.marginBottomActualTextFlat = textRefFlat.value?.style.getPropertyValue('margin-bottom') ?? ''
|
||||
data.marginBottomActualImage = imageRef.value?.style.getPropertyValue('margin-bottom') ?? ''
|
||||
data.marginBottomActualImageFlat = imageRefFlat.value?.style.getPropertyValue('margin-bottom') ?? ''
|
||||
}
|
||||
|
||||
|
||||
const changeMarginBottom = (value: string) => {
|
||||
data.marginBottom = value
|
||||
viewRef.value?.style.setProperty('margin-bottom', value)
|
||||
viewRefFlat.value?.style.setProperty('margin-bottom', value)
|
||||
textRef.value?.style.setProperty('margin-bottom', value)
|
||||
textRefFlat.value?.style.setProperty('margin-bottom', value)
|
||||
imageRef.value?.style.setProperty('margin-bottom', value)
|
||||
imageRefFlat.value?.style.setProperty('margin-bottom', value)
|
||||
// 使用 nextTick 确保样式已应用后再获取值
|
||||
nextTick(() => {
|
||||
getPropertyValues()
|
||||
})
|
||||
}
|
||||
|
||||
const radioChangeMarginBottom = (index: number) => {
|
||||
const selectedItem = marginBottomEnum.find((item): boolean => item.value === index)
|
||||
if (selectedItem != null) {
|
||||
changeMarginBottom(selectedItem.name)
|
||||
}
|
||||
}
|
||||
|
||||
const inputChangeMarginBottom = (value: string) => {
|
||||
changeMarginBottom(value)
|
||||
}
|
||||
|
||||
onReady(() => {
|
||||
getPropertyValues()
|
||||
})
|
||||
|
||||
defineExpose({
|
||||
radioChangeMarginBottom,
|
||||
data
|
||||
})
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.demo-container {
|
||||
flex: 1;
|
||||
margin:0 10px;
|
||||
height: 220px;
|
||||
background-color: gray;
|
||||
}
|
||||
.demo-box {
|
||||
flex-direction: row;
|
||||
margin-top: 10px;
|
||||
justify-content: space-around;
|
||||
}
|
||||
.common {
|
||||
height: 50px;
|
||||
background-color: green;
|
||||
}
|
||||
|
||||
.red {
|
||||
background-color: red;
|
||||
}
|
||||
|
||||
.blue {
|
||||
background-color: blue;
|
||||
}
|
||||
|
||||
.green {
|
||||
background-color: green;
|
||||
}
|
||||
|
||||
.scroll-view-test {
|
||||
height: 50px;
|
||||
}
|
||||
|
||||
.common-view {
|
||||
height: 30px;
|
||||
background-color: green;
|
||||
}
|
||||
|
||||
.common-text {
|
||||
font-size: 12px;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.common-image {
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
background-color: green;
|
||||
}
|
||||
|
||||
.test-container {
|
||||
flex-direction: row;
|
||||
justify-content: space-between;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.test-item {
|
||||
flex: 1;
|
||||
margin: 0 5px;
|
||||
}
|
||||
|
||||
.test-box {
|
||||
width: 100%;
|
||||
height: 140px;
|
||||
background-color: gray;
|
||||
}
|
||||
|
||||
</style>
|
||||
@@ -0,0 +1,303 @@
|
||||
<template>
|
||||
<!-- #ifdef APP && !VUE3-VAPOR -->
|
||||
<scroll-view style="flex: 1">
|
||||
<!-- #endif -->
|
||||
<view style="flex-grow: 1;">
|
||||
<text class="uni-tips">说明:左边是正常版本,右边是拍平版本</text>
|
||||
<view>
|
||||
<text>margin-left: 25px</text>
|
||||
<view class="demo-box">
|
||||
<view class="demo-container">
|
||||
<view class="common red"></view>
|
||||
<view class="common" style="margin-left: 25px;"></view>
|
||||
<view class="common blue"></view>
|
||||
</view>
|
||||
<view class="demo-container">
|
||||
<view class="common red"></view>
|
||||
<view class="common" style="margin-left: 25px;" flatten></view>
|
||||
<view class="common blue"></view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view>
|
||||
<text>margin-left: 10%</text>
|
||||
<view class="demo-box">
|
||||
<view class="demo-container">
|
||||
<view class="common red"></view>
|
||||
<view class="common" style="margin-left: 10%;"></view>
|
||||
<view class="common blue"></view>
|
||||
</view>
|
||||
<view class="demo-container">
|
||||
<view class="common red"></view>
|
||||
<view class="common" style="margin-left: 10%;" flatten></view>
|
||||
<view class="common blue"></view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="uni-common-mt">
|
||||
<text class="uni-title-text">scroll-view 组件</text>
|
||||
</view>
|
||||
<view>
|
||||
<text class="uni-subtitle-text">margin-left: 10% 和 margin-left: 30px</text>
|
||||
<view class="demo-box">
|
||||
<view class="demo-container">
|
||||
<view class="common red"></view>
|
||||
<scroll-view class="common" style="margin-left: 10%;"></scroll-view>
|
||||
<view class="common blue"></view>
|
||||
</view>
|
||||
<view class="demo-container">
|
||||
<view class="common red"></view>
|
||||
<scroll-view class="common" style="margin-left: 30px;"></scroll-view>
|
||||
<view class="common blue"></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.marginLeft}}</text>
|
||||
<text class="uni-info">获取值: {{data.marginLeftActual}}</text>
|
||||
<view class="test-box">
|
||||
<view class="common-view" style="background-color: red;"></view>
|
||||
<view ref="viewRef" class="common-view test-view" :style="{ marginLeft: data.marginLeft }">
|
||||
<text class="common-text">view</text>
|
||||
</view>
|
||||
<view class="common-view" style="background-color: blue;"></view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">text 组件</text>
|
||||
<text class="uni-info">设置值: {{data.marginLeft}}</text>
|
||||
<text class="uni-info">获取值: {{data.marginLeftActualText}}</text>
|
||||
<view class="test-box">
|
||||
<text class="common-view common-text" style="background-color: red;">红色</text>
|
||||
<text ref="textRef" class="common-view common-text test-text" :style="{ marginLeft: data.marginLeft }">text</text>
|
||||
<text class="common-view common-text" style="background-color: blue;">蓝色</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">image 组件</text>
|
||||
<text class="uni-info">设置值: {{data.marginLeft}}</text>
|
||||
<text class="uni-info">获取值: {{data.marginLeftActualImage}}</text>
|
||||
<view class="test-box">
|
||||
<image class="common-image" style="background-color: red;" src="/static/test-image/logo.png"></image>
|
||||
<image ref="imageRef" class="common-image test-image" :style="{ marginLeft: data.marginLeft }" src="/static/test-image/logo.png"></image>
|
||||
<image class="common-image" style="background-color: blue;" 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.marginLeft}}</text>
|
||||
<text class="uni-info">获取值: {{data.marginLeftActualFlat}}</text>
|
||||
<view class="test-box">
|
||||
<view class="common-view" style="background-color: red;"></view>
|
||||
<view ref="viewRefFlat" class="common-view test-view-flatten" :style="{ marginLeft: data.marginLeft }" flatten>
|
||||
<text class="common-text">view</text>
|
||||
</view>
|
||||
<view class="common-view" style="background-color: blue;"></view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">text 组件拍平</text>
|
||||
<text class="uni-info">设置值: {{data.marginLeft}}</text>
|
||||
<text class="uni-info">获取值: {{data.marginLeftActualTextFlat}}</text>
|
||||
<view class="test-box">
|
||||
<text class="common-view common-text" style="background-color: red;">红色</text>
|
||||
<text ref="textRefFlat" class="common-view common-text test-text-flatten" :style="{ marginLeft: data.marginLeft }" flatten>text</text>
|
||||
<text class="common-view common-text" style="background-color: blue;">蓝色</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">image 组件拍平</text>
|
||||
<text class="uni-info">设置值: {{data.marginLeft}}</text>
|
||||
<text class="uni-info">获取值: {{data.marginLeftActualImageFlat}}</text>
|
||||
<view class="test-box">
|
||||
<image class="common-image" style="background-color: red;" src="/static/test-image/logo.png"></image>
|
||||
<image ref="imageRefFlat" class="common-image test-image-flatten" :style="{ marginLeft: data.marginLeft }" flatten src="/static/test-image/logo.png"></image>
|
||||
<image class="common-image" style="background-color: blue;" 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="marginLeftEnum" title="margin-left 枚举值" @change="radioChangeMarginLeft" :compact="true"></enum-data>
|
||||
<input-data :defaultValue="data.marginLeft" title="margin-left 自定义值" type="text" @confirm="inputChangeMarginLeft"></input-data>
|
||||
</view>
|
||||
|
||||
<view class="uni-common-mb">
|
||||
<text>native-view组件: margin-left: 25px 和 10%</text>
|
||||
<view class="demo-box">
|
||||
<view class="demo-container">
|
||||
<view class="common red"></view>
|
||||
<test-native-view class="common" style="margin-left: 25px;"></test-native-view>
|
||||
<view class="common blue"></view>
|
||||
</view>
|
||||
<view class="demo-container">
|
||||
<view class="common red"></view>
|
||||
<test-native-view class="common" style="margin-left: 10%;"></test-native-view>
|
||||
<view class="common blue"></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 data = reactive({
|
||||
marginLeft: '25px',
|
||||
marginLeftActual: '',
|
||||
marginLeftActualText: '',
|
||||
marginLeftActualImage: '',
|
||||
marginLeftActualFlat: '',
|
||||
marginLeftActualTextFlat: '',
|
||||
marginLeftActualImageFlat: ''
|
||||
})
|
||||
|
||||
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 marginLeftEnum: ItemType[] = [
|
||||
{ value: 0, name: '' },
|
||||
{ value: 1, name: '0' },
|
||||
{ value: 2, name: '0px' },
|
||||
{ value: 3, name: '20px' },
|
||||
{ value: 4, name: '0%' },
|
||||
{ value: 5, name: '10%' },
|
||||
{ value: 6, name: 'auto' }
|
||||
]
|
||||
|
||||
const getPropertyValues = () => {
|
||||
data.marginLeftActual = viewRef.value?.style.getPropertyValue('margin-left') ?? ''
|
||||
data.marginLeftActualFlat = viewRefFlat.value?.style.getPropertyValue('margin-left') ?? ''
|
||||
data.marginLeftActualText = textRef.value?.style.getPropertyValue('margin-left') ?? ''
|
||||
data.marginLeftActualTextFlat = textRefFlat.value?.style.getPropertyValue('margin-left') ?? ''
|
||||
data.marginLeftActualImage = imageRef.value?.style.getPropertyValue('margin-left') ?? ''
|
||||
data.marginLeftActualImageFlat = imageRefFlat.value?.style.getPropertyValue('margin-left') ?? ''
|
||||
}
|
||||
|
||||
|
||||
const changeMarginLeft = (value: string) => {
|
||||
data.marginLeft = value
|
||||
viewRef.value?.style.setProperty('margin-left', value)
|
||||
viewRefFlat.value?.style.setProperty('margin-left', value)
|
||||
textRef.value?.style.setProperty('margin-left', value)
|
||||
textRefFlat.value?.style.setProperty('margin-left', value)
|
||||
imageRef.value?.style.setProperty('margin-left', value)
|
||||
imageRefFlat.value?.style.setProperty('margin-left', value)
|
||||
// 使用 nextTick 确保样式已应用后再获取值
|
||||
nextTick(() => {
|
||||
getPropertyValues()
|
||||
})
|
||||
}
|
||||
|
||||
const radioChangeMarginLeft = (index: number) => {
|
||||
const selectedItem = marginLeftEnum.find((item): boolean => item.value === index)
|
||||
if (selectedItem != null) {
|
||||
changeMarginLeft(selectedItem.name)
|
||||
}
|
||||
}
|
||||
|
||||
const inputChangeMarginLeft = (value: string) => {
|
||||
changeMarginLeft(value)
|
||||
}
|
||||
|
||||
onReady(() => {
|
||||
getPropertyValues()
|
||||
})
|
||||
|
||||
defineExpose({
|
||||
radioChangeMarginLeft,
|
||||
data
|
||||
})
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.demo-container {
|
||||
flex: 1;
|
||||
margin:0 10px;
|
||||
height: 180px;
|
||||
background-color: gray;
|
||||
}
|
||||
.demo-box {
|
||||
flex-direction: row;
|
||||
margin-top: 10px;
|
||||
justify-content: space-around;
|
||||
}
|
||||
.common {
|
||||
height: 50px;
|
||||
background-color: green;
|
||||
}
|
||||
|
||||
.red {
|
||||
background-color: red;
|
||||
}
|
||||
|
||||
.blue {
|
||||
background-color: blue;
|
||||
}
|
||||
|
||||
.green {
|
||||
background-color: green;
|
||||
}
|
||||
|
||||
.scroll-view-test {
|
||||
height: 50px;
|
||||
}
|
||||
|
||||
.common-view {
|
||||
height: 30px;
|
||||
background-color: green;
|
||||
}
|
||||
|
||||
.common-text {
|
||||
font-size: 12px;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.common-image {
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
background-color: green;
|
||||
}
|
||||
|
||||
.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;
|
||||
}
|
||||
|
||||
</style>
|
||||
@@ -0,0 +1,300 @@
|
||||
<template>
|
||||
<!-- #ifdef APP && !VUE3-VAPOR -->
|
||||
<scroll-view style="flex: 1">
|
||||
<!-- #endif -->
|
||||
<view style="flex-grow: 1;">
|
||||
<text class="uni-tips">说明:左边是正常版本,右边是拍平版本</text>
|
||||
<view>
|
||||
<text>margin-right: 25px</text>
|
||||
<view class="demo-box">
|
||||
<view class="demo-container">
|
||||
<view class="common red"></view>
|
||||
<view class="common" style="margin-right: 25px;"></view>
|
||||
<view class="common blue"></view>
|
||||
</view>
|
||||
<view class="demo-container">
|
||||
<view class="common red"></view>
|
||||
<view class="common" style="margin-right: 25px;" flatten></view>
|
||||
<view class="common blue"></view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view>
|
||||
<text>margin-right: 10%</text>
|
||||
<view class="demo-box">
|
||||
<view class="demo-container">
|
||||
<view class="common red"></view>
|
||||
<view class="common" style="margin-right: 10%;"></view>
|
||||
<view class="common blue"></view>
|
||||
</view>
|
||||
<view class="demo-container">
|
||||
<view class="common red"></view>
|
||||
<view class="common" style="margin-right: 10%;" flatten></view>
|
||||
<view class="common blue"></view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="uni-common-mt">
|
||||
<text class="uni-title-text">scroll-view 组件</text>
|
||||
</view>
|
||||
<view>
|
||||
<text class="uni-subtitle-text">margin-right: 10% 和 margin-right: 30px</text>
|
||||
<view class="demo-box">
|
||||
<view class="demo-container">
|
||||
<view class="common red"></view>
|
||||
<scroll-view class="common" style="margin-right: 10%;"></scroll-view>
|
||||
<view class="common blue"></view>
|
||||
</view>
|
||||
<view class="demo-container">
|
||||
<view class="common red"></view>
|
||||
<scroll-view class="common" style="margin-right: 30px;"></scroll-view>
|
||||
<view class="common blue"></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.marginRight}}</text>
|
||||
<text class="uni-info">获取值: {{data.marginRightActual}}</text>
|
||||
<view class="test-box">
|
||||
<view class="common-view" style="background-color: red;"></view>
|
||||
<view ref="viewRef" class="common-view test-view" :style="{ marginRight: data.marginRight }">
|
||||
<text class="common-text">view</text>
|
||||
</view>
|
||||
<view class="common-view" style="background-color: blue;"></view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">text 组件</text>
|
||||
<text class="uni-info">设置值: {{data.marginRight}}</text>
|
||||
<text class="uni-info">获取值: {{data.marginRightActualText}}</text>
|
||||
<view class="test-box">
|
||||
<text class="common-view common-text" style="background-color: red;">红色</text>
|
||||
<text ref="textRef" class="common-view common-text test-text" :style="{ marginRight: data.marginRight }">text</text>
|
||||
<text class="common-view common-text" style="background-color: blue;">蓝色</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">image 组件</text>
|
||||
<text class="uni-info">设置值: {{data.marginRight}}</text>
|
||||
<text class="uni-info">获取值: {{data.marginRightActualImage}}</text>
|
||||
<view class="test-box row">
|
||||
<image class="common-image" style="background-color: red;" src="/static/test-image/logo.png"></image>
|
||||
<image ref="imageRef" class="common-image test-image" :style="{ marginRight: data.marginRight }" src="/static/test-image/logo.png"></image>
|
||||
<image class="common-image" style="background-color: blue;" 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.marginRight}}</text>
|
||||
<text class="uni-info">获取值: {{data.marginRightActualFlat}}</text>
|
||||
<view class="test-box">
|
||||
<view class="common-view" style="background-color: red;"></view>
|
||||
<view ref="viewRefFlat" class="common-view test-view-flatten" :style="{ marginRight: data.marginRight }" flatten>
|
||||
<text class="common-text">view</text>
|
||||
</view>
|
||||
<view class="common-view" style="background-color: blue;"></view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">text 组件拍平</text>
|
||||
<text class="uni-info">设置值: {{data.marginRight}}</text>
|
||||
<text class="uni-info">获取值: {{data.marginRightActualTextFlat}}</text>
|
||||
<view class="test-box">
|
||||
<text class="common-view common-text" style="background-color: red;">红色</text>
|
||||
<text ref="textRefFlat" class="common-view common-text test-text-flatten" :style="{ marginRight: data.marginRight }" flatten>text</text>
|
||||
<text class="common-view common-text" style="background-color: blue;">蓝色</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">image 组件拍平</text>
|
||||
<text class="uni-info">设置值: {{data.marginRight}}</text>
|
||||
<text class="uni-info">获取值: {{data.marginRightActualImageFlat}}</text>
|
||||
<view class="test-box row">
|
||||
<image class="common-image" style="background-color: red;" src="/static/test-image/logo.png"></image>
|
||||
<image ref="imageRefFlat" class="common-image test-image-flatten" :style="{ marginRight: data.marginRight }" flatten src="/static/test-image/logo.png"></image>
|
||||
<image class="common-image" style="background-color: blue;" 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="marginRightEnum" title="margin-right 枚举值" @change="radioChangeMarginRight" :compact="true"></enum-data>
|
||||
<input-data :defaultValue="data.marginRight" title="margin-right 自定义值" type="text" @confirm="inputChangeMarginRight"></input-data>
|
||||
</view>
|
||||
|
||||
<view class="uni-common-mb">
|
||||
<text>native-view组件: margin-right: 25px 和 10%</text>
|
||||
<view class="demo-box">
|
||||
<view class="demo-container">
|
||||
<view class="common red"></view>
|
||||
<test-native-view class="common" style="margin-right: 25px;"></test-native-view>
|
||||
<view class="common blue"></view>
|
||||
</view>
|
||||
<view class="demo-container">
|
||||
<view class="common red"></view>
|
||||
<test-native-view class="common" style="margin-right: 10%;"></test-native-view>
|
||||
<view class="common blue"></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 data = reactive({
|
||||
marginRight: '25px',
|
||||
marginRightActual: '',
|
||||
marginRightActualText: '',
|
||||
marginRightActualImage: '',
|
||||
marginRightActualFlat: '',
|
||||
marginRightActualTextFlat: '',
|
||||
marginRightActualImageFlat: ''
|
||||
})
|
||||
|
||||
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 marginRightEnum: ItemType[] = [
|
||||
{ value: 0, name: '' },
|
||||
{ value: 1, name: '0' },
|
||||
{ value: 2, name: '0px' },
|
||||
{ value: 3, name: '20px' },
|
||||
{ value: 4, name: '0%' },
|
||||
{ value: 5, name: '10%' },
|
||||
{ value: 6, name: 'auto' }
|
||||
]
|
||||
|
||||
const getPropertyValues = () => {
|
||||
data.marginRightActual = viewRef.value?.style.getPropertyValue('margin-right') ?? ''
|
||||
data.marginRightActualFlat = viewRefFlat.value?.style.getPropertyValue('margin-right') ?? ''
|
||||
data.marginRightActualText = textRef.value?.style.getPropertyValue('margin-right') ?? ''
|
||||
data.marginRightActualTextFlat = textRefFlat.value?.style.getPropertyValue('margin-right') ?? ''
|
||||
data.marginRightActualImage = imageRef.value?.style.getPropertyValue('margin-right') ?? ''
|
||||
data.marginRightActualImageFlat = imageRefFlat.value?.style.getPropertyValue('margin-right') ?? ''
|
||||
}
|
||||
|
||||
|
||||
const changeMarginRight = (value: string) => {
|
||||
data.marginRight = value
|
||||
viewRef.value?.style.setProperty('margin-right', value)
|
||||
viewRefFlat.value?.style.setProperty('margin-right', value)
|
||||
textRef.value?.style.setProperty('margin-right', value)
|
||||
textRefFlat.value?.style.setProperty('margin-right', value)
|
||||
imageRef.value?.style.setProperty('margin-right', value)
|
||||
imageRefFlat.value?.style.setProperty('margin-right', value)
|
||||
// 使用 nextTick 确保样式已应用后再获取值
|
||||
nextTick(() => {
|
||||
getPropertyValues()
|
||||
})
|
||||
}
|
||||
|
||||
const radioChangeMarginRight = (index: number) => {
|
||||
const selectedItem = marginRightEnum.find((item): boolean => item.value === index)
|
||||
if (selectedItem != null) {
|
||||
changeMarginRight(selectedItem.name)
|
||||
}
|
||||
}
|
||||
|
||||
const inputChangeMarginRight = (value: string) => {
|
||||
changeMarginRight(value)
|
||||
}
|
||||
|
||||
onReady(() => {
|
||||
getPropertyValues()
|
||||
})
|
||||
|
||||
defineExpose({
|
||||
radioChangeMarginRight,
|
||||
data
|
||||
})
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.demo-container {
|
||||
flex: 1;
|
||||
margin:0 10px;
|
||||
height: 180px;
|
||||
background-color: gray;
|
||||
}
|
||||
.demo-box {
|
||||
flex-direction: row;
|
||||
margin-top: 10px;
|
||||
justify-content: space-around;
|
||||
}
|
||||
.common {
|
||||
height: 50px;
|
||||
background-color: green;
|
||||
}
|
||||
|
||||
.red {
|
||||
background-color: red;
|
||||
}
|
||||
|
||||
.blue {
|
||||
background-color: blue;
|
||||
}
|
||||
|
||||
.common-view {
|
||||
height: 30px;
|
||||
background-color: green;
|
||||
}
|
||||
|
||||
.common-text {
|
||||
font-size: 12px;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.common-image {
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
background-color: green;
|
||||
}
|
||||
|
||||
.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;
|
||||
}
|
||||
|
||||
.row{
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
</style>
|
||||
@@ -0,0 +1,296 @@
|
||||
<template>
|
||||
<!-- #ifdef APP && !VUE3-VAPOR -->
|
||||
<scroll-view style="flex: 1">
|
||||
<!-- #endif -->
|
||||
<view style="flex-grow: 1;">
|
||||
<text class="uni-tips">说明:左边是正常版本,右边是拍平版本</text>
|
||||
<view>
|
||||
<text>margin-top: 25px</text>
|
||||
<view class="demo-box">
|
||||
<view class="demo-container">
|
||||
<view class="common red"></view>
|
||||
<view class="common" style="margin-top: 25px;"></view>
|
||||
<view class="common blue"></view>
|
||||
</view>
|
||||
<view class="demo-container">
|
||||
<view class="common red"></view>
|
||||
<view class="common" style="margin-top: 25px;" flatten></view>
|
||||
<view class="common blue"></view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view>
|
||||
<text>margin-top: 10%</text>
|
||||
<view class="demo-box">
|
||||
<view class="demo-container">
|
||||
<view class="common red"></view>
|
||||
<view class="common" style="margin-top: 10%;"></view>
|
||||
<view class="common blue"></view>
|
||||
</view>
|
||||
<view class="demo-container">
|
||||
<view class="common red"></view>
|
||||
<view class="common" style="margin-top: 10%;" flatten></view>
|
||||
<view class="common blue"></view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="uni-common-mt">
|
||||
<text class="uni-title-text">scroll-view 组件</text>
|
||||
</view>
|
||||
<view>
|
||||
<text class="uni-subtitle-text">margin-top: 10% 和 margin-top: 30px</text>
|
||||
<view class="demo-box">
|
||||
<view class="demo-container">
|
||||
<view class="common red"></view>
|
||||
<scroll-view class="common" style="margin-top: 10%;"></scroll-view>
|
||||
<view class="common blue"></view>
|
||||
</view>
|
||||
<view class="demo-container">
|
||||
<view class="common red"></view>
|
||||
<scroll-view class="common" style="margin-top: 30px;"></scroll-view>
|
||||
<view class="common blue"></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.marginTop}}</text>
|
||||
<text class="uni-info">获取值: {{data.marginTopActual}}</text>
|
||||
<view class="test-box">
|
||||
<view class="common-view" style="background-color: red;"></view>
|
||||
<view ref="viewRef" class="common-view test-view" :style="{ marginTop: data.marginTop }">
|
||||
<text class="common-text">view</text>
|
||||
</view>
|
||||
<view class="common-view" style="background-color: blue;"></view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">text 组件</text>
|
||||
<text class="uni-info">设置值: {{data.marginTop}}</text>
|
||||
<text class="uni-info">获取值: {{data.marginTopActualText}}</text>
|
||||
<view class="test-box">
|
||||
<text class="common-view common-text" style="background-color: red;">红色</text>
|
||||
<text ref="textRef" class="common-view common-text test-text" :style="{ marginTop: data.marginTop }">text</text>
|
||||
<text class="common-view common-text" style="background-color: blue;">蓝色</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">image 组件</text>
|
||||
<text class="uni-info">设置值: {{data.marginTop}}</text>
|
||||
<text class="uni-info">获取值: {{data.marginTopActualImage}}</text>
|
||||
<view class="test-box">
|
||||
<image class="common-image" style="background-color: red;" src="/static/test-image/logo.png"></image>
|
||||
<image ref="imageRef" class="common-image test-image" :style="{ marginTop: data.marginTop }" src="/static/test-image/logo.png"></image>
|
||||
<image class="common-image" style="background-color: blue;" 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.marginTop}}</text>
|
||||
<text class="uni-info">获取值: {{data.marginTopActualFlat}}</text>
|
||||
<view class="test-box">
|
||||
<view class="common-view" style="background-color: red;"></view>
|
||||
<view ref="viewRefFlat" class="common-view test-view-flatten" :style="{ marginTop: data.marginTop }" flatten>
|
||||
<text class="common-text">view</text>
|
||||
</view>
|
||||
<view class="common-view" style="background-color: blue;"></view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">text 组件拍平</text>
|
||||
<text class="uni-info">设置值: {{data.marginTop}}</text>
|
||||
<text class="uni-info">获取值: {{data.marginTopActualTextFlat}}</text>
|
||||
<view class="test-box">
|
||||
<text class="common-view common-text" style="background-color: red;">红色</text>
|
||||
<text ref="textRefFlat" class="common-view common-text test-text-flatten" :style="{ marginTop: data.marginTop }" flatten>text</text>
|
||||
<text class="common-view common-text" style="background-color: blue;">蓝色</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">image 组件拍平</text>
|
||||
<text class="uni-info">设置值: {{data.marginTop}}</text>
|
||||
<text class="uni-info">获取值: {{data.marginTopActualImageFlat}}</text>
|
||||
<view class="test-box">
|
||||
<image class="common-image" style="background-color: red;" src="/static/test-image/logo.png"></image>
|
||||
<image ref="imageRefFlat" class="common-image test-image-flatten" :style="{ marginTop: data.marginTop }" flatten src="/static/test-image/logo.png"></image>
|
||||
<image class="common-image" style="background-color: blue;" 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="marginTopEnum" title="margin-top 枚举值" @change="radioChangeMarginTop" :compact="true"></enum-data>
|
||||
<input-data :defaultValue="data.marginTop" title="margin-top 自定义值" type="text" @confirm="inputChangeMarginTop"></input-data>
|
||||
</view>
|
||||
|
||||
<view class="uni-common-mb">
|
||||
<text>native-view组件: margin-top: 25px 和 10%</text>
|
||||
<view class="demo-box">
|
||||
<view class="demo-container">
|
||||
<view class="common red"></view>
|
||||
<test-native-view class="common" style="margin-top: 25px;"></test-native-view>
|
||||
<view class="common blue"></view>
|
||||
</view>
|
||||
<view class="demo-container">
|
||||
<view class="common red"></view>
|
||||
<test-native-view class="common" style="margin-top: 10%;"></test-native-view>
|
||||
<view class="common blue"></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 data = reactive({
|
||||
marginTop: '25px',
|
||||
marginTopActual: '',
|
||||
marginTopActualText: '',
|
||||
marginTopActualImage: '',
|
||||
marginTopActualFlat: '',
|
||||
marginTopActualTextFlat: '',
|
||||
marginTopActualImageFlat: ''
|
||||
})
|
||||
|
||||
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 marginTopEnum: ItemType[] = [
|
||||
{ value: 0, name: '' },
|
||||
{ value: 1, name: '0' },
|
||||
{ value: 2, name: '0px' },
|
||||
{ value: 3, name: '20px' },
|
||||
{ value: 4, name: '0%' },
|
||||
{ value: 5, name: '10%' },
|
||||
{ value: 6, name: 'auto' }
|
||||
]
|
||||
|
||||
const getPropertyValues = () => {
|
||||
data.marginTopActual = viewRef.value?.style.getPropertyValue('margin-top') ?? ''
|
||||
data.marginTopActualFlat = viewRefFlat.value?.style.getPropertyValue('margin-top') ?? ''
|
||||
data.marginTopActualText = textRef.value?.style.getPropertyValue('margin-top') ?? ''
|
||||
data.marginTopActualTextFlat = textRefFlat.value?.style.getPropertyValue('margin-top') ?? ''
|
||||
data.marginTopActualImage = imageRef.value?.style.getPropertyValue('margin-top') ?? ''
|
||||
data.marginTopActualImageFlat = imageRefFlat.value?.style.getPropertyValue('margin-top') ?? ''
|
||||
}
|
||||
|
||||
|
||||
const changeMarginTop = (value: string) => {
|
||||
data.marginTop = value
|
||||
viewRef.value?.style.setProperty('margin-top', value)
|
||||
viewRefFlat.value?.style.setProperty('margin-top', value)
|
||||
textRef.value?.style.setProperty('margin-top', value)
|
||||
textRefFlat.value?.style.setProperty('margin-top', value)
|
||||
imageRef.value?.style.setProperty('margin-top', value)
|
||||
imageRefFlat.value?.style.setProperty('margin-top', value)
|
||||
// 使用 nextTick 确保样式已应用后再获取值
|
||||
nextTick(() => {
|
||||
getPropertyValues()
|
||||
})
|
||||
}
|
||||
|
||||
const radioChangeMarginTop = (index: number) => {
|
||||
const selectedItem = marginTopEnum.find((item): boolean => item.value === index)
|
||||
if (selectedItem != null) {
|
||||
changeMarginTop(selectedItem.name)
|
||||
}
|
||||
}
|
||||
|
||||
const inputChangeMarginTop = (value: string) => {
|
||||
changeMarginTop(value)
|
||||
}
|
||||
|
||||
onReady(() => {
|
||||
getPropertyValues()
|
||||
})
|
||||
|
||||
defineExpose({
|
||||
radioChangeMarginTop,
|
||||
data
|
||||
})
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.demo-container {
|
||||
flex:1;
|
||||
margin:0 10px;
|
||||
height: 220px;
|
||||
background-color: gray;
|
||||
}
|
||||
.demo-box {
|
||||
flex-direction: row;
|
||||
margin-top: 10px;
|
||||
justify-content: space-around;
|
||||
}
|
||||
.common {
|
||||
height: 50px;
|
||||
background-color: green;
|
||||
}
|
||||
|
||||
.red {
|
||||
background-color: red;
|
||||
}
|
||||
|
||||
.blue {
|
||||
background-color: blue;
|
||||
}
|
||||
|
||||
.common-view {
|
||||
height: 30px;
|
||||
background-color: green;
|
||||
}
|
||||
|
||||
.common-text {
|
||||
font-size: 12px;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.common-image {
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
background-color: green;
|
||||
}
|
||||
|
||||
.test-container {
|
||||
flex-direction: row;
|
||||
justify-content: space-between;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.test-item {
|
||||
flex: 1;
|
||||
margin: 0 5px;
|
||||
}
|
||||
|
||||
.test-box {
|
||||
width: 100%;
|
||||
height: 140px;
|
||||
background-color: gray;
|
||||
}
|
||||
|
||||
</style>
|
||||
@@ -0,0 +1,334 @@
|
||||
<template>
|
||||
<!-- #ifdef APP && !VUE3-VAPOR -->
|
||||
<scroll-view style="flex: 1">
|
||||
<!-- #endif -->
|
||||
<view style="flex-grow: 1;">
|
||||
<text class="uni-tips">说明:左边是正常版本,右边是拍平版本</text>
|
||||
<view>
|
||||
<text>margin: 25px</text>
|
||||
<view class="demo-box">
|
||||
<view class="demo-container">
|
||||
<view class="common red"></view>
|
||||
<view class="common" style="margin: 25px;"></view>
|
||||
<view class="common blue"></view>
|
||||
</view>
|
||||
<view class="demo-container">
|
||||
<view class="common red"></view>
|
||||
<view class="common" style="margin: 25px;" flatten></view>
|
||||
<view class="common blue"></view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view>
|
||||
<text>margin: 10%</text>
|
||||
<view class="demo-box">
|
||||
<view class="demo-container">
|
||||
<view class="common red"></view>
|
||||
<view class="common" style="margin: 10%;"></view>
|
||||
<view class="common blue"></view>
|
||||
</view>
|
||||
<view class="demo-container">
|
||||
<view class="common red"></view>
|
||||
<view class="common" style="margin: 10%;" flatten></view>
|
||||
<view class="common blue"></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.margin}}</text>
|
||||
<text class="uni-info">获取值: {{data.marginActual}}</text>
|
||||
<view class="test-box">
|
||||
<view class="common-view" style="background-color: red;"></view>
|
||||
<view ref="viewRef" class="common-view test-view" :style="{ margin: data.margin }">
|
||||
<text class="common-text">view</text>
|
||||
</view>
|
||||
<view class="common-view" style="background-color: blue;"></view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">text 组件</text>
|
||||
<text class="uni-info">设置值: {{data.margin}}</text>
|
||||
<text class="uni-info">获取值: {{data.marginActualText}}</text>
|
||||
<view class="test-box">
|
||||
<text class="common-view common-text" style="background-color: red;">红色</text>
|
||||
<text ref="textRef" class="common-view common-text test-text" :style="{ margin: data.margin }">text</text>
|
||||
<text class="common-view common-text" style="background-color: blue;">蓝色</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">image 组件</text>
|
||||
<text class="uni-info">设置值: {{data.margin}}</text>
|
||||
<text class="uni-info">获取值: {{data.marginActualImage}}</text>
|
||||
<view class="test-box">
|
||||
<image class="common-image" style="background-color: red;" src="/static/test-image/logo.png"></image>
|
||||
<image ref="imageRef" class="common-image test-image" :style="{ margin: data.margin }" src="/static/test-image/logo.png"></image>
|
||||
<image class="common-image" style="background-color: blue;" 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.margin}}</text>
|
||||
<text class="uni-info">获取值: {{data.marginActualFlat}}</text>
|
||||
<view class="test-box">
|
||||
<view class="common-view" style="background-color: red;"></view>
|
||||
<view ref="viewRefFlat" class="common-view test-view-flatten" :style="{ margin: data.margin }" flatten>
|
||||
<text class="common-text">view</text>
|
||||
</view>
|
||||
<view class="common-view" style="background-color: blue;"></view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">text 组件拍平</text>
|
||||
<text class="uni-info">设置值: {{data.margin}}</text>
|
||||
<text class="uni-info">获取值: {{data.marginActualTextFlat}}</text>
|
||||
<view class="test-box">
|
||||
<text class="common-view common-text" style="background-color: red;">红色</text>
|
||||
<text ref="textRefFlat" class="common-view common-text test-text-flatten" :style="{ margin: data.margin }" flatten>text</text>
|
||||
<text class="common-view common-text" style="background-color: blue;">蓝色</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="test-item">
|
||||
<text class="uni-subtitle-text">image 组件拍平</text>
|
||||
<text class="uni-info">设置值: {{data.margin}}</text>
|
||||
<text class="uni-info">获取值: {{data.marginActualImageFlat}}</text>
|
||||
<view class="test-box">
|
||||
<image class="common-image" style="background-color: red;" src="/static/test-image/logo.png"></image>
|
||||
<image ref="imageRefFlat" class="common-image test-image-flatten" :style="{ margin: data.margin }" flatten src="/static/test-image/logo.png"></image>
|
||||
<image class="common-image" style="background-color: blue;" src="/static/test-image/logo.png"></image>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="uni-common-mt">
|
||||
<text class="uni-title-text">scroll-view 组件 margin </text>
|
||||
</view>
|
||||
|
||||
<view class="test-container">
|
||||
<view class="test-item">
|
||||
<text class="uni-info">设置值: {{data.margin}}</text>
|
||||
<text class="uni-info">获取值: {{data.marginActualScrollView}}</text>
|
||||
<view class="test-box" style="height: 180px;">
|
||||
<view class="common-view" style="background-color: red;"></view>
|
||||
<scroll-view ref="scrollViewRef" class="common-scroll-view" :style="{ margin: data.margin }">
|
||||
<view class="scroll-view-content">
|
||||
<text class="common-text">scroll-view1</text>
|
||||
</view>
|
||||
<view class="scroll-view-content">
|
||||
<text class="common-text">scroll-view2</text>
|
||||
</view>
|
||||
<view class="scroll-view-content">
|
||||
<text class="common-text">scroll-view3</text>
|
||||
</view>
|
||||
</scroll-view>
|
||||
<view class="common-view" style="background-color: blue;"></view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="uni-common-mt uni-common-mb">
|
||||
<text class="uni-tips">第一个枚举值,'' (空字符串) - 空值情况</text>
|
||||
<enum-data :compact="true" :items="marginEnum" title="margin 枚举值" @change="radioChangeMargin"></enum-data>
|
||||
<input-data :defaultValue="data.margin" title="margin 自定义值" type="text" @confirm="inputChangeMargin"></input-data>
|
||||
</view>
|
||||
|
||||
<view class="uni-common-mb">
|
||||
<text>native-view组件: margin: 25px 和 5%</text>
|
||||
<view class="demo-box">
|
||||
<view class="demo-container">
|
||||
<view class="common red"></view>
|
||||
<test-native-view class="common" style="margin: 25px;"></test-native-view>
|
||||
<view class="common blue"></view>
|
||||
</view>
|
||||
<view class="demo-container">
|
||||
<view class="common red"></view>
|
||||
<test-native-view class="common" style="margin: 10%;"></test-native-view>
|
||||
<view class="common blue"></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 data = reactive({
|
||||
margin: '25px',
|
||||
marginActual: '',
|
||||
marginActualText: '',
|
||||
marginActualImage: '',
|
||||
marginActualFlat: '',
|
||||
marginActualTextFlat: '',
|
||||
marginActualImageFlat: '',
|
||||
marginActualScrollView: ''
|
||||
})
|
||||
|
||||
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 scrollViewRef = ref(null as UniElement | null)
|
||||
|
||||
const marginEnum: ItemType[] = [
|
||||
{ value: 0, name: '' },
|
||||
{ value: 1, name: '0' },
|
||||
{ value: 2, name: '0px' },
|
||||
{ value: 3, name: '20px' },
|
||||
{ value: 4, name: '0%' },
|
||||
{ value: 5, name: '10%' },
|
||||
{ value: 6, name: 'auto' }
|
||||
]
|
||||
|
||||
const getPropertyValues = () => {
|
||||
data.marginActual = viewRef.value?.style.getPropertyValue('margin') ?? ''
|
||||
data.marginActualFlat = viewRefFlat.value?.style.getPropertyValue('margin') ?? ''
|
||||
data.marginActualText = textRef.value?.style.getPropertyValue('margin') ?? ''
|
||||
data.marginActualTextFlat = textRefFlat.value?.style.getPropertyValue('margin') ?? ''
|
||||
data.marginActualImage = imageRef.value?.style.getPropertyValue('margin') ?? ''
|
||||
data.marginActualImageFlat = imageRefFlat.value?.style.getPropertyValue('margin') ?? ''
|
||||
data.marginActualScrollView = scrollViewRef.value?.style.getPropertyValue('margin') ?? ''
|
||||
}
|
||||
|
||||
|
||||
const changeMargin = (value: string) => {
|
||||
data.margin = value
|
||||
viewRef.value?.style.setProperty('margin', value)
|
||||
viewRefFlat.value?.style.setProperty('margin', value)
|
||||
textRef.value?.style.setProperty('margin', value)
|
||||
textRefFlat.value?.style.setProperty('margin', value)
|
||||
imageRef.value?.style.setProperty('margin', value)
|
||||
imageRefFlat.value?.style.setProperty('margin', value)
|
||||
scrollViewRef.value?.style.setProperty('margin', value)
|
||||
// 使用 nextTick 确保样式已应用后再获取值
|
||||
nextTick(() => {
|
||||
getPropertyValues()
|
||||
})
|
||||
}
|
||||
|
||||
const radioChangeMargin = (index: number) => {
|
||||
const selectedItem = marginEnum.find((item): boolean => item.value === index)
|
||||
if (selectedItem != null) {
|
||||
changeMargin(selectedItem.name)
|
||||
}
|
||||
}
|
||||
|
||||
const inputChangeMargin = (value: string) => {
|
||||
changeMargin(value)
|
||||
}
|
||||
|
||||
onReady(() => {
|
||||
getPropertyValues()
|
||||
})
|
||||
|
||||
defineExpose({
|
||||
radioChangeMargin,
|
||||
data
|
||||
})
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.demo-container {
|
||||
flex: 1;
|
||||
margin:0 10px;
|
||||
height: 220px;
|
||||
background-color: gray;
|
||||
}
|
||||
.demo-box {
|
||||
flex-direction: row;
|
||||
margin-top: 10px;
|
||||
justify-content: space-around;
|
||||
}
|
||||
.common {
|
||||
height: 50px;
|
||||
background-color: green;
|
||||
}
|
||||
|
||||
.red {
|
||||
background-color: red;
|
||||
}
|
||||
|
||||
.blue {
|
||||
background-color: blue;
|
||||
}
|
||||
|
||||
.common-view {
|
||||
height: 30px;
|
||||
background-color: green;
|
||||
}
|
||||
|
||||
.common-text {
|
||||
font-size: 12px;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.common-image {
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
background-color: green;
|
||||
}
|
||||
|
||||
.test-container {
|
||||
flex-direction: row;
|
||||
justify-content: space-between;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.test-item {
|
||||
flex: 1;
|
||||
margin: 0 5px;
|
||||
}
|
||||
|
||||
.test-box {
|
||||
width: 100%;
|
||||
height: 140px;
|
||||
background-color: gray;
|
||||
}
|
||||
|
||||
|
||||
.common-scroll-view {
|
||||
height: 30px;
|
||||
background-color: green;
|
||||
}
|
||||
|
||||
.scroll-view-content {
|
||||
width: 100%;
|
||||
height: 30px;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border: cyan solid 2px;
|
||||
}
|
||||
|
||||
.native-view-container {
|
||||
width: 100px;
|
||||
height: 100px;
|
||||
background-color: #e0e0e0;
|
||||
border: 1px solid #999;
|
||||
}
|
||||
|
||||
.native-view {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background-color: cyan;
|
||||
}
|
||||
</style>
|
||||
在新工单中引用
屏蔽一个用户