|
| 1 | +## Cube-AcitionSheet |
| 2 | + |
| 3 | +<card> |
| 4 | + |
| 5 | +## 介绍 |
| 6 | + |
| 7 | +ActionSheet操作列表提供了两种常见的样式,灵活可控内容。 |
| 8 | + |
| 9 | + |
| 10 | +</card> |
| 11 | + |
| 12 | +### 示例 |
| 13 | + |
| 14 | +<card> |
| 15 | + |
| 16 | +### 基本用法 |
| 17 | + |
| 18 | +配置标题 title 和 data 数据项,data 中内容是 content,一段 HTML 字符串,额外还可以配置自定义 class:class 和方向:align(值可以是 left、right)。 |
| 19 | + |
| 20 | +<collapse-wrapper> |
| 21 | + |
| 22 | +```vue |
| 23 | +<template> |
| 24 | + <view> |
| 25 | + <cube-button bindtap="showActionSheet">action-sheet</cube-button> |
| 26 | + <cube-action-sheet |
| 27 | + wx:ref="actionSheet" |
| 28 | + title="{{title}}" |
| 29 | + inputData="{{inputData}}" |
| 30 | + bindselect="onSelect" |
| 31 | + /> |
| 32 | + </view> |
| 33 | +</template> |
| 34 | +
|
| 35 | +<script> |
| 36 | + import { createComponent } from '@mpxjs/core' |
| 37 | + createComponent({ |
| 38 | + data() { |
| 39 | + return { |
| 40 | + inputData: [ |
| 41 | + { |
| 42 | + content: 'align-center', |
| 43 | + class: 'cube-foo' |
| 44 | + }, |
| 45 | + { |
| 46 | + content: 'align-left', |
| 47 | + align: 'left' |
| 48 | + }, |
| 49 | + { |
| 50 | + content: 'align-right', |
| 51 | + align: 'right' |
| 52 | + } |
| 53 | + ], |
| 54 | + selectContent: '', |
| 55 | + title: '我是标题' |
| 56 | + } |
| 57 | + }, |
| 58 | + methods: { |
| 59 | + onSelect(selectData) { |
| 60 | + const { item } = selectData.detail |
| 61 | + this.selectContent = `Clicked: ${item.content}` |
| 62 | + this.$refs.selectToast.show() |
| 63 | + }, |
| 64 | + showActionSheet() { |
| 65 | + this.$refs.actionSheet.show() |
| 66 | + } |
| 67 | + } |
| 68 | + }) |
| 69 | +</script> |
| 70 | +``` |
| 71 | +</collapse-wrapper> |
| 72 | + |
| 73 | + |
| 74 | +</card> |
| 75 | + |
| 76 | +<card> |
| 77 | + |
| 78 | +### 高亮设置 |
| 79 | + |
| 80 | +通过设置 active 属性来控制高亮的是第几个。 |
| 81 | + |
| 82 | +<collapse-wrapper> |
| 83 | + |
| 84 | +```vue |
| 85 | +<template> |
| 86 | + <view> |
| 87 | + <cube-button bindtap="showActionSheet">action-sheet-active</cube-button> |
| 88 | + <cube-action-sheet |
| 89 | + wx:ref="actionSheet" |
| 90 | + title="{{title}}" |
| 91 | + inputData="{{inputData}}" |
| 92 | + active="{{active}}" |
| 93 | + bind:select="onSelect" |
| 94 | + bind:cancel="onCancel" |
| 95 | + /> |
| 96 | + <cube-toast |
| 97 | + txt="{{ selectContent }}" |
| 98 | + wx:ref="selectToast"> |
| 99 | + </cube-toast> |
| 100 | + </view> |
| 101 | +</template> |
| 102 | +
|
| 103 | +<script> |
| 104 | + import { createComponent } from '@mpxjs/core' |
| 105 | + createComponent({ |
| 106 | + data: { |
| 107 | + inputData: [ |
| 108 | + { |
| 109 | + content: '舒适型' |
| 110 | + }, |
| 111 | + { |
| 112 | + content: '七座商务' |
| 113 | + }, |
| 114 | + { |
| 115 | + content: '豪华型' |
| 116 | + } |
| 117 | + ], |
| 118 | + active: 0, |
| 119 | + selectContent: '', |
| 120 | + title: '我是标题' |
| 121 | + }, |
| 122 | + methods: { |
| 123 | + onSelect(selectData) { |
| 124 | + const { item, index } = selectData.detail |
| 125 | + this.selectContent = `Clicked ${item.content}` |
| 126 | + this.active = index |
| 127 | + this.$refs.selectToast.show() |
| 128 | + }, |
| 129 | + onCancel() { |
| 130 | + this.selectContent = 'Clicked canceled ' |
| 131 | + this.$refs.selectToast.show() |
| 132 | + }, |
| 133 | + showActionSheet() { |
| 134 | + this.$refs.actionSheet.show() |
| 135 | + }, |
| 136 | + } |
| 137 | + }) |
| 138 | +</script> |
| 139 | +``` |
| 140 | +</collapse-wrapper> |
| 141 | + |
| 142 | + |
| 143 | +</card> |
| 144 | + |
| 145 | +<card> |
| 146 | + |
| 147 | +### Picker 样式设定 |
| 148 | + |
| 149 | +pickerStyle 属性决定是否使用 Picker 样式。 |
| 150 | + |
| 151 | + |
| 152 | +<collapse-wrapper> |
| 153 | + |
| 154 | +```vue |
| 155 | +<template> |
| 156 | + <view> |
| 157 | + <cube-button bindtap="showActionSheet">action-sheet-picker</cube-button> |
| 158 | + <cube-action-sheet |
| 159 | + wx:ref="actionSheet" |
| 160 | + title="{{ title }}" |
| 161 | + inputData="{{inputData}}" |
| 162 | + pickerStyle="{{true}}" |
| 163 | + bind:select="onSelect" |
| 164 | + bind:cancel="onCancel" |
| 165 | + /> |
| 166 | + <cube-toast |
| 167 | + txt="{{ selectContent }}" |
| 168 | + wx:ref="selectToast"> |
| 169 | + </cube-toast> |
| 170 | + </view> |
| 171 | +</template> |
| 172 | +
|
| 173 | +<script> |
| 174 | + import { createComponent } from '@mpxjs/core' |
| 175 | + createComponent({ |
| 176 | + data: { |
| 177 | + inputData: [ |
| 178 | + { |
| 179 | + content: '舒适型' |
| 180 | + }, |
| 181 | + { |
| 182 | + content: '七座商务' |
| 183 | + }, |
| 184 | + { |
| 185 | + content: '豪华型' |
| 186 | + } |
| 187 | + ], |
| 188 | + selectContent: '', |
| 189 | + title: '我是标题' |
| 190 | + }, |
| 191 | + methods: { |
| 192 | + onSelect(selectData) { |
| 193 | + const { item } = selectData.detail |
| 194 | + this.selectContent = `Clicked ${item.content}` |
| 195 | + this.$refs.selectToast.show() |
| 196 | + }, |
| 197 | + onCancel() { |
| 198 | + this.selectContent = 'Clicked canceled ' |
| 199 | + this.$refs.selectToast.show() |
| 200 | + }, |
| 201 | + showActionSheet() { |
| 202 | + this.$refs.actionSheet.show() |
| 203 | + } |
| 204 | + } |
| 205 | + }) |
| 206 | +</script> |
| 207 | +
|
| 208 | +<style lang="stylus"> |
| 209 | +.rate-item-demo |
| 210 | + width: 100% |
| 211 | + height: 100% |
| 212 | + background-size: 100% |
| 213 | + background-color: grey |
| 214 | +.cube-rate-item_active |
| 215 | + .cube-rate-item-demo |
| 216 | + background-color: orange |
| 217 | +.cube-rate-item_half_active |
| 218 | + .cube-rate-item-demo |
| 219 | + background-color: blue |
| 220 | +</style> |
| 221 | +
|
| 222 | +``` |
| 223 | +</collapse-wrapper> |
| 224 | + |
| 225 | +</card> |
| 226 | + |
0 commit comments