123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224 |
- <template>
- <view class="uni-fab-box">
- <view class="uni-padding-wrap">
- <view class="word-btn" hover-class="word-btn--hover" :hover-start-time="20" :hover-stay-time="70" @click="switchBtn(0)"><text class="word-btn-white">切换菜单({{ directionStr }}显示)</text></view>
- <view class="word-btn" hover-class="word-btn--hover" :hover-start-time="20" :hover-stay-time="70" @click="switchBtn('left', 'bottom')"><text class="word-btn-white">左下角显示</text></view>
- <view class="word-btn" hover-class="word-btn--hover" :hover-start-time="20" :hover-stay-time="70" @click="switchBtn('right', 'bottom')"><text class="word-btn-white">右下角显示</text></view>
- <view class="word-btn" hover-class="word-btn--hover" :hover-start-time="20" :hover-stay-time="70" @click="switchBtn('left', 'top')"><text class="word-btn-white">左上角显示</text></view>
- <view class="word-btn" hover-class="word-btn--hover" :hover-start-time="20" :hover-stay-time="70" @click="switchBtn('right', 'top')"><text class="word-btn-white">右上角显示</text></view>
- </view>
- <uni-fab ref="fab" :pattern="pattern" :content="content" :horizontal="horizontal" :vertical="vertical" :direction="direction" @trigger="trigger" @fabClick="fabClick" />
- </view>
- </template>
- <script>
- export default {
- components: {},
- data() {
- return {
- title: 'uni-fab',
- directionStr: '垂直',
- horizontal: 'left',
- vertical: 'bottom',
- direction: 'horizontal',
- pattern: {
- color: '#7A7E83',
- backgroundColor: '#fff',
- selectedColor: '#007AFF',
- },
- content: [{
- iconPath: '/static/component.png',
- selectedIconPath: '/static/componentHL.png',
- text: '组件',
- active: false
- },
- {
- iconPath: '/static/api.png',
- selectedIconPath: '/static/apiHL.png',
- text: 'API',
- active: false
- },
- {
- iconPath: '/static/template.png',
- selectedIconPath: '/static/templateHL.png',
- text: '模版',
- active: false
- }
- ]
- }
- },
- onBackPress() {
- if (this.$refs.fab.isShow) {
- this.$refs.fab.close()
- return true
- }
- return false
- },
- methods: {
- trigger(e) {
- console.log(e)
- this.content[e.index].active = !e.item.active
- uni.showModal({
- title: '提示',
- content: `您${this.content[e.index].active ? '选中了' : '取消了'}${e.item.text}`,
- success: function(res) {
- if (res.confirm) {
- console.log('用户点击确定')
- } else if (res.cancel) {
- console.log('用户点击取消')
- }
- }
- })
- },
- fabClick() {
- uni.showToast({
- title: '点击了悬浮按钮',
- icon: 'none'
- })
- },
- switchBtn(hor, ver) {
- if (hor === 0) {
- this.direction = this.direction === 'horizontal' ? 'vertical' : 'horizontal'
- this.directionStr = this.direction === 'horizontal' ? '垂直' : '水平'
- } else {
- this.horizontal = hor
- this.vertical = ver
- }
- this.$forceUpdate()
- }
- }
- }
- </script>
- <style>
- @charset "UTF-8";
- /* 头条小程序组件内不能引入字体 */
- /* #ifdef MP-TOUTIAO */
- @font-face {
- font-family: uniicons;
- font-weight: normal;
- font-style: normal;
- src: url("~@/static/uni.ttf") format("truetype");
- }
- /* #endif */
- /* #ifndef APP-NVUE */
- page {
- display: flex;
- flex-direction: column;
- box-sizing: border-box;
- background-color: #efeff4;
- min-height: 100%;
- height: auto;
- }
- view {
- font-size: 14px;
- line-height: inherit;
- }
- .example {
- padding: 0 15px 15px;
- }
- .example-info {
- padding: 15px;
- color: #3b4144;
- background: #ffffff;
- }
- .example-body {
- /* #ifndef APP-NVUE */
- display: flex;
- /* #endif */
- flex-direction: row;
- flex-wrap: wrap;
- justify-content: center;
- padding: 0;
- font-size: 14px;
- background-color: #ffffff;
- }
- /* #endif */
- .example {
- padding: 0 15px;
- }
- .example-info {
- /* #ifndef APP-NVUE */
- display: block;
- /* #endif */
- padding: 15px;
- color: #3b4144;
- background-color: #ffffff;
- font-size: 14px;
- line-height: 20px;
- }
- .example-info-text {
- font-size: 14px;
- line-height: 20px;
- color: #3b4144;
- }
- .example-body {
- flex-direction: column;
- padding: 15px;
- background-color: #ffffff;
- }
- .word-btn-white {
- font-size: 18px;
- color: #FFFFFF;
- }
- .word-btn {
- /* #ifndef APP-NVUE */
- display: flex;
- /* #endif */
- flex-direction: row;
- align-items: center;
- justify-content: center;
- border-radius: 6px;
- height: 48px;
- margin: 15px;
- background-color: #007AFF;
- }
- .word-btn--hover {
- background-color: #4ca2ff;
- }
- /* #ifndef APP-NVUE */
- page {
- height: 100vh;
- }
- /* #endif */
- .uni-fab-box {
- /* #ifndef APP-NVUE */
- display: flex;
- /* #endif */
- flex-direction: row;
- justify-content: center;
- position: absolute;
- top: 0;
- bottom: 0;
- left: 0;
- right: 0;
- }
- .uni-padding-wrap {
- /* #ifndef APP-NVUE */
- display: flex;
- /* #endif */
- flex-direction: column;
- justify-content: center;
- align-items: center;
- }
- .word-btn {
- width: 250px;
- }
- </style>
|