除了支持通用属性以外,还支持如下属性。
名称 |
类型 |
默认值 |
是否必填 |
描述 |
|---|---|---|---|---|
edge |
left | right |
right |
否 |
按钮位置靠左还是靠右。 |
enableslide |
boolean |
true |
否 |
是否允许侧滑。 |
isopen |
boolean |
false |
否 |
是否启用按钮区域。 |
layer |
same | above |
above |
否 |
按钮组与主体的层级关系。
|
buttons |
array |
- |
是 |
按钮组,超过三项时,仅显示前三项。总宽度不超过侧滑操作容器宽度的2/3。 |
buttons属性说明:
名称 |
类型 |
默认值 |
是否必填 |
描述 |
|---|---|---|---|---|
id |
string |
- |
是 |
按钮ID,由buttonClick事件返回。 |
buttonWidth |
length |
- |
否 |
按钮宽度。 |
icon |
uri |
- |
否 |
按钮图标。 |
iconWidth |
length |
75px |
否 |
按钮图标宽度。 |
iconHeight |
length |
75px |
否 |
按钮图标高度。 |
iconBackgroundColor |
color |
#F2F2F2 |
否 |
图标圆形背景区域颜色,在backgroundType设置为icon时有效。 |
text |
string |
- |
否 |
按钮文字。 |
textSize |
number |
15px |
否 |
文字大小。 |
textColor |
color |
#000000 |
否 |
文字颜色。 |
backgroundColor |
color |
#F2F2F2 |
否 |
背景色。 |
backgroundType |
fill | icon |
fill |
否 |
背景样式。
说明:
如果icon和text均设置,则图标在上,文本在下,居中显示。如果仅设置icon或text,则居中显示。 |
secondaryConfirm |
object |
- |
否 |
按钮二次确认状态。留空表示无此状态。
说明:
如果设置了二次确认,点击对应按钮则显示二次确认文本,背景色和按钮背景色相同。 |
secondaryConfirm属性说明:
名称 |
类型 |
默认值 |
是否必填 |
描述 |
|---|---|---|---|---|
text |
string |
- |
是 |
二次确认文本。 |
textSize |
number |
15px |
否 |
二次确认文本的大小。 |
textColor |
color |
#000000 |
否 |
二次确认文本的颜色。 |
除了支持 通用事件 以外,还支持如下事件。
名称 |
参数 |
描述 |
|---|---|---|
open |
- |
打开按钮组区域时触发。 |
close |
- |
关闭按钮组区域时触发。 |
slide |
{offset: offsetValue} |
在按钮组区域滑动时触发。 offset:表示当前滑动距离。 |
buttonClick |
{id: idValue isSecondaryConfirm: isSecondaryConfirmValue} |
点击按钮组时触发。
|
名称 |
参数 |
描述 |
|---|---|---|
open |
- |
打开按钮组区域。 |
close |
- |
关闭按钮组区域。 |
open方法参数说明:
名称 |
类型 |
默认值 |
是否必填 |
描述 |
|---|---|---|---|---|
animation |
boolean |
true |
否 |
是否启用打开动画。 |
close方法参数说明:
名称 |
类型 |
默认值 |
是否必填 |
描述 |
|---|---|---|---|---|
animation |
boolean |
true |
否 |
是否启用关闭动画。 |
<template>
<!-- Only one root node is allowed in template. -->
<div class="container">
<text class="title">Left Slide</text>
<div class="item-container">
<slide-view class="slide-view" onButtonClick="buttonClick" buttons="{{slideButtons}}" layer="same" edge="left" enableslide="true">
<div class="inner-div">
<text class="text-div">左滑可以删除</text>
</div>
</slide-view>
</div>
<text class="title">enableslide = false</text>
<slide-view class="slide-view" buttons="{{slideButtons}}" layer="same" isopen="false" edge="right" enableslide="false">
<div class="inner-div">
<text class="text-div">左滑可以删除</text>
</div>
</slide-view>
<text class="title">isopen = true</text>
<slide-view class="slide-view" buttons="{{slideButtons}}" layer="same" isopen="true" edge="left" enableslide="true">
<div class="inner-div">
<text class="text-div">左滑可以删除</text>
</div>
</slide-view>
<text class="title">Right Slide</text>
<slide-view class="slide-view" buttons="{{slideButtons}}" layer="same" isopen="false" edge="right" enableslide="true">
<div class="inner-div">
<text class="text-div">左滑可以删除</text>
</div>
</slide-view>
<text class="title">Right Above Slide</text>
<slide-view class="slide-view" buttons="{{slideButtons}}" layer="above" isopen="false" edge="right" enableslide="true">
<div class="inner-div">
<text class="text-div">左滑可以删除</text>
</div>
</slide-view>
<text class="title">With Static Buttons</text>
<slide-view id="slideview" class="slide-view" buttons="{{slideButtons}}" layer="same" isopen="false" edge="left" enableslide="true">
<div class="inner-div">
<text class="text-div">左滑可以删除</text>
</div>
</slide-view>
<input type="button" value="Open" onclick="clickButton" />
<input type="button" value="Close" onclick="closeclickButton" />
</div>
</template>
<style>
.container {
flex-direction: column;
justify-content: center;
align-content: center;
align-items: center;
}
.title {
font-size: 50px;
margin-top: 40px;
}
.buttons {
margin: 10px;
border-radius: 15px;
padding: 15px;
}
.surfaceContainer {
border-width: 2px;
background-color: #d2691e;
width: 100%;
height: 150px;
text-align: center;
display: flex;
align-items: center;
justify-content: center;
}
.buttonHolder {
width: 750px;
height: 150px;
display: flex;
flex-direction: row;
align-items: center;
text-align: center;
background-color: #00ced1;
justify-content: center;
}
.buttonHolder input {
height: 100px;
}
.slide-view {
width: 100%;
height: 150px;
background-color: #00008b;
}
.inner-div {
height: 100px;
}
.text-div {
color: #f0fff0;
}
</style>
<script>
import prompt from '@system.prompt'
module.exports = {
data: {
title: 'World',
slideButtons: [
{
id: "0",
buttonWidth: '120px',
clickButton: false,
icon: '../Common/ic_update.png',
text: 'Update',
backgroundColor: '#FBD4FF',
iconWidth: '50px',
iconHeight: '50px',
backgroundType: 'fill',
secondaryConfirm: {
text: "update ?",
textSize: "12px",
textColor: "#008000"
}
},
{
id: "1",
buttonWidth: '150px',
icon: '../Common/ic_delete.png',
//clickButton : true,
iconBackgroundColor: "#ff0000",
backgroundColor: '#ff0000',
backgroundType: 'icon',
iconWidth: '70px',
iconHeight: '65px',
secondaryConfirm: {
text: "delete ?",
textSize: "12px",
textColor: "#008000"
}
},
{
id: "2",
buttonWidth: '180px',
backgroundColor: '#ff0555',
backgroundType: 'fill',
text: 'Setting',
textSize: '15px',
textColor: '#f0f0f0'
}
]
},
clickButton: function () {
this.$element('slideview').open(true)
},
buttonClick(data) {
const { id, isSecondaryConfirm } = data
console.info(`### button:${id} is click, data is ${data} ###`)
if (isSecondaryConfirm) {
prompt.showToast({
message: '第二次点击触发'
})
} else {
prompt.showToast({
message: '第一次点击触发'
})
}
},
closeclickButton: function () { this.$element('slideview').close(true) }
}
</script>