1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
| <template>
| <view
| class="u-float-button" :style="{
| position: 'fixed',
| top: top,
| bottom: bottom,
| right: right,
| }">
| <view class="u-float-button__main" @click="clickHandler" :style="{
| backgroundColor: backgroundColor,
| color: color,
| flexDirection: 'row',
| justifyContent: 'center',
| alignItems: 'center',
| width: width,
| height: height,
| borderRadius: '50%',
| borderColor: borderColor,
| }">
| <slot :showList="showList">
| <up-icon class="cursor-pointer" :class="{'show-list': showList}" name="plus" :color="color"></up-icon>
| </slot>
| <view v-if="showList" class="u-float-button__list" :style="{
| bottom: height
| }">
| <slot name="list">
| <template v-for="item in list">
| <view class="u-float-button__item" :style="{
| backgroundColor: item?.backgroundColor ? item?.backgroundColor : backgroundColor,
| color: item?.color ? item?.color : color,
| flexDirection: 'row',
| justifyContent: 'center',
| alignItems: 'center',
| width: width,
| height: height,
| borderRadius: '50%',
| borderColor: item?.borderColor ? item?.borderColor : borderColor,
| }" @click="itemClick(item, index)">
| <up-icon :name="item.name" :color="item?.color ? item?.color : color"></up-icon>
| </view>
| </template>
| </slot>
| </view>
| </view>
| </view>
| </template>
|
| <script>
| import { mpMixin } from '../../libs/mixin/mpMixin';
| import { mixin } from '../../libs/mixin/mixin';
| import { addStyle, addUnit, deepMerge } from '../../libs/function/index';
| /**
| * FloatButton 悬浮按钮
| * @description 悬浮按钮常用于屏幕右下角点击展开的操作菜单
| * @tutorial https://ijry.github.io/uview-plus/components/floatButton.html
| * @property {String} backgroundColor 背景颜色
| * @event {Function} click 点击触发事件
| * @example <up-float-button></up-float-button>
| */
| export default {
| name: 'u-float-button',
| // #ifdef MP
| mixins: [mpMixin, mixin],
| // #endif
| // #ifndef MP
| mixins: [mpMixin, mixin],
| // #endif
| emits: ['click', 'item-click'],
| computed: {
| },
| props: {
| // 背景颜色
| backgroundColor: {
| type: String,
| default: '#2979ff'
| },
| // 文字颜色
| color: {
| type: String,
| default: '#fff'
| },
| // 宽度
| width: {
| type: String,
| default: '50px'
| },
| // 高度
| height: {
| type: String,
| default: '50px'
| },
| // 边框颜色,默认为空字符串表示无边框
| borderColor: {
| type: String,
| default: ''
| },
| // 右侧偏移量
| right: {
| type: [String, Number],
| default: '30px'
| },
| // 顶部偏移量,未提供默认值,可能需要根据具体情况设置
| top: {
| type: [String, Number],
| default: '',
| },
| // 底部偏移量
| bottom: {
| type: String,
| default: ''
| },
| // 是否为菜单项
| isMenu: {
| type: Boolean,
| default: false
| },
| list: {
| type: Array,
| default: () => {
| return []
| }
| }
| },
| data() {
| return {
| showList: false
| }
| },
| methods: {
| addStyle,
| clickHandler(e) {
| if (this.isMenu) {
| this.showList = !this.showList
| this.$emit('click', e)
| } else {
| this.$emit('click', e)
| }
| },
| itemClick(item, index) {
| this.$emit('item-click', {
| ...item,
| index
| })
| }
| }
| }
| </script>
|
| <style lang="scss" scoped>
| @import '../../libs/css/components.scss';
|
| .u-float-button {
| z-index: 999;
| .show-list {
| transform: rotate(45deg);
| }
| &__list {
| position: absolute;
| bottom: 0px;
| display: flex;
| flex-direction: column;
| >view {
| margin: 5px 0px;
| }
| }
| }
| </style>
|
|