123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- <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';
- export default {
- name: 'u-float-button',
-
- mixins: [mpMixin, mixin],
-
-
- mixins: [mpMixin, mixin],
-
- 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>
|