123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431 |
- <!-- 悬浮按钮 -->
- <template>
- <view class="nobody fulled"
- :class="[absolute?'fulled':'',fixed?'d-inline-block':'',absolute&&position=='bottom'?'flex-end-center height100':'']">
- <view
- :class="[absolute?'fulled':'',absolute?'relative':'',absolute&&position=='top'?'flex-center':'',absolute&&position=='bottom'?'flex-end-center height100':'',fixed?'d-inline-block':'']">
- <view class="flotbtnId" :style="pos" :class="[absolute?'absolute':'',fixed?'fixed':'']">
- <slot name="default">
- <tm-button
- v-if="isRender"
- @contact="$emit('contact', $event)"
- @error="$emit('error', $event)"
- @getphonenumber="$emit('getphonenumber', $event)"
- @getuserinfo="$emit('getuserinfo', $event)"
- @launchapp="$emit('launchapp', $event)"
- @opensetting="$emit('opensetting', $event)"
- @longpress="$emit('longpress', $event)"
- @touchcancel="$emit('touchcancel', $event)"
- :open-type="openType"
- @click="click"
- :showValue="showText" vertical :label="label" :fontSize="fontSize"
- :iconSize="iconSize" :theme="color_tmeme" round="rouned" :font-color="fontColor" :bgcolor="bgcolor"
- :size="size" :width="width" :height="width" :icon="icon" fab>
- </tm-button>
- </slot>
- <view v-if="(show || showActions)&&actions.length>0" class="menulistAction" :class="[actionsPos]">
- <view class="menulistAction_item" v-for="(item,index) in actions" :key="index">
- <tm-button :fllowTheme="false" fab @click="itemChange(index)" iconSize="40" :icon="item.icon" :theme="item.color" size="m"></tm-button>
- </view>
- </view>
- </view>
- </view>
- </view>
- </template>
- <script>
-
- import tmButton from "@/tm-vuetify/components/tm-button/tm-button.vue"
- export default {
- name:"tm-flotbutton",
- components:{tmButton},
- props: {
-
- actions: {
- type: Array,
- default: () => {
- return [];
- }
- },
-
- openType: {
- type: String,
- default: ''
- },
-
- actionsPos: {
- type: String,
- default: 'top'
- },
-
- showActions: {
- type: String | Boolean,
- default: false
- },
-
- clickActionsHiden: {
- type: String | Boolean,
- default: true
- },
-
- size: {
- type: String,
- default: 'n'
- },
- width: {
- type: String | Number,
- default: 100
- },
- height: {
- type: String | Number,
- default: 100
- },
-
- showText: {
- type: String | Boolean,
- default: false
- },
-
- label: {
- type: String,
- default: ''
- },
- icon: {
- type: String,
- default: 'icon-plus'
- },
-
- bgcolor: {
- type: String | Array,
- default: ''
- },
-
- fontSize: {
- type: Number | String,
- default: 22
- },
-
- fontColor: {
- type: String,
- default: 'white'
- },
-
- iconSize: {
- type: Number | String,
- default: 36
- },
-
- color: {
- type: String,
- default: 'primary'
- },
-
- absolute: {
- type: String | Boolean,
- default: false
- },
-
- safe:{
- type: String | Boolean,
- default: true
- },
-
- fixed: {
- type: String | Boolean,
- default: true
- },
-
- position: {
- type: String,
- default: 'bottomRight'
- },
-
- offset: {
- type: Array,
- default: () => {
- return [16, 16];
- }
- },
-
- fllowTheme:{
- type:Boolean|String,
- default:true
- }
- },
- computed: {
- offsets: {
- get: function() {
- return this.offset;
- },
- set: function() {
- try {
- this.offset = [uni.upx2px(this.offset[0]), uni.upx2px(this.offset[1])];
- } catch (e) {
- this.offset = [0, 0];
- }
- }
- },
- color_tmeme:function(){
- if(this.$tm.vx.state().tmVuetify.color!==null&&this.$tm.vx.state().tmVuetify.color && this.fllowTheme){
- return this.$tm.vx.state().tmVuetify.color;
- }
- return this.color;
- },
- pos: {
- get: function() {
-
- return this.thisPos;
- },
- set:function(){
- this.thisPos = this.posfun();
- }
-
- }
- },
- data() {
- return {
- position_info: [],
- show: false,
- isRender:false,
- thisPos:''
- };
- },
-
- async mounted() {
- this.init();
-
- },
- methods: {
- init(){
- let t = this;
- this.$nextTick(function(){
- t.isRender=true;
- t.position_info = [{width:uni.upx2px(this.width),height:uni.upx2px(this.height)}];
- t.thisPos = t.posfun();
- })
-
-
- window.addEventListener('scroll',function(){
- t.thisPos = t.posfun();
-
- })
-
- },
- getsafeJl(){
- let sy = uni.getSystemInfoSync();
-
- return Math.abs(sy.screenHeight - sy.safeArea.bottom);
-
-
- return Math.abs(sy.windowHeight - sy.safeArea.height);
-
-
- return Math.abs(sy.safeArea.bottom - sy.safeArea.height);
-
- return 24;
- },
- posfun(){
- if (this.absolute && !this.fixed) {
- if (this.position == 'topLeft') {
- return `transform:translateY(${this.offset[1]}px);left:${this.offset[0]}px`;
- } else if (this.position == 'topRight') {
- return `transform:translateY(${this.offset[1]}px);right:${this.offset[0]}px;`
- } else if (this.position == 'bottomRight') {
-
- return `transform:translateY(${this.offset[1]}px);right:${this.offset[0]}px;`;
- } else if (this.position == 'bottomLeft') {
- return `btransform:translateY(${this.offset[1]}px);left:${this.offset[0]}px`;
- } else if (this.position == 'top') {
- return `transform:translateX(${this.offset[0]}px) translateY(${this.offset[1]}px)`
- } else if (this.position == 'bottom') {
- return `transform:translateX(${this.offset[0]}px) translateY(${this.offset[1]}px)`
- }
-
- }
- if (!this.absolute && this.fixed) {
-
- if (this.position == 'topLeft') {
- return `top:${ this.offset[1]}px;left:${this.offset[0]}px`;
- } else if (this.position == 'topRight') {
- return `top: ${this.offset[1]}px;right: ${this.offset[0]}px`;
- } else if (this.position == 'bottomRight') {
-
- let safbo = this.getsafeJl()
- if(!this.safe) safbo=0
- return `bottom: ${this.offset[1]+safbo}px;right: ${this.offset[0]}px;`;
-
- } else if (this.position == 'bottomLeft') {
- let sy = uni.getSystemInfoSync();
-
- let safbo = this.getsafeJl()
- if(!this.safe) safbo=0
-
- return `bottom:${ this.offset[1]+safbo}px;left:${this.offset[0]}px;`;
- } else if (this.position == 'top') {
-
- let js = uni.getSystemInfoSync();
- let left = js.windowWidth;
-
- if (this.position_info.length > 0) {
- let w = this.position_info[0].width;
- return `transform:translateX(${this.offset[0]}px) translateY(${this.offset[1]}px);top:0;left:${(left-w)/2}px;`;
- }
-
- } else if (this.position == 'bottom') {
- let safbo = this.getsafeJl()
- if(!this.safe) safbo=0
- let js = uni.getSystemInfoSync();
- let left = js.windowWidth;
- if (this.position_info.length > 0) {
- let w = this.position_info[0].width;
- console.log(w);
- return `transform:translateX(${this.offset[0]}px) translateY(${this.offset[1]}px);bottom:${safbo}px;left:${(left-w)/2}px`;
-
- } else if (this.position == 'left') {
- let js = uni.getSystemInfoSync();
- let left = js.windowHeight;
- if (this.position_info.length > 0) {
- let w = this.position_info[0].height;
- return `transform:translateX(${this.offset[0]}px) translateY(${this.offset[1]}px);left:0;top:${(left-w)/2}px`;
-
- }
-
- } else if (this.position == 'right') {
- let js = uni.getSystemInfoSync();
- let left = js.windowHeight;
- if (this.position_info.length > 0) {
- let w = this.position_info[0].height;
- return {
- transform: `translateX(${this.offset[0]}px) translateY(${this.offset[1]}px)`,
- right: 0,
- top: (left - w) / 2 + 'px',
- };
- `transform:translateX(${this.offset[0]}px) translateY(${this.offset[1]}px);right:0;top:{(left-w)/2}px`;
- }
-
- }
- }
- }
-
- },
- click(e) {
- this.$emit('click', e);
- this.show = !this.show;
-
- },
- itemChange(index) {
-
- this.$emit('change', index);
- if (!this.clickActionsHiden) return;
- this.show = !this.show;
- }
- },
- }
- </script>
- <style lang="scss" scoped>
- .nobody {
- .menulistAction {
- .menulistAction_item {
- position: relative;
-
- animation: sscsl 0.5s;
-
- }
- &.top {
- position: absolute;
- bottom: 130upx;
- left: 10upx;
- .menulistAction_item {
-
- margin-bottom: 10px;
- }
- }
- &.left {
- position: absolute;
- bottom: 10upx;
- display: flex;
- flex-flow: row;
- right: 140upx;
- .menulistAction_item {
- margin-left: 10px;
- }
- }
- &.bottom {
- position: absolute;
- top: 140upx;
- display: flex;
- flex-flow: column;
- left: 10upx;
- .menulistAction_item {
- margin-top: 10px;
- }
- }
- &.right {
- position: absolute;
- bottom: 10upx;
- display: flex;
- flex-flow: row;
- left: 140upx;
-
- .menulistAction_item {
- margin-left: 10px;
- }
- }
- }
- }
- @keyframes sscsl {
- from {
- transform: scale(0.5);
- }
- to {
- transform: scale(1);
- }
- }
- .height100 {
- height: 100%;
- }
- .fixed,
- .absolute {
- z-index: 400;
- bottom: 0;
- }
- </style>
|