Commit 69194fe9 authored by Facius's avatar Facius

feat: 悬浮窗

parent 4b3d990f
Pipeline #2778 canceled with stages
<template>
<view class="fab-view">
<view
id="_drag_button"
class="suspension"
@touchstart.capture="touchstart"
@touchend.capture="touchend"
@touchmove.capture="touchmove"
:style="{
opacity: opacity,
left: left + 'px',
top: top + 'px',
}"
@click.stop="handleClick"
>
<image v-if="icon" :src="imageUrl" class="image-icon" mode="widthFix" hover-class="u-hover-class"></image>
<view v-if="text" class="content-text">{{ text }}</view>
</view>
</view>
</template>
<script>
const sys = uni.getSystemInfoSync()
export default {
props: {
// 是否启用自动停靠
isDock: {
type: Boolean,
default: false,
},
// 当前页面是否包含tabbar
existTabBar: {
type: Boolean,
default: false,
},
text: {
type: String,
default: '维修记账',
},
icon: {
type: String,
default: '',
},
canMove: {
type: Boolean,
default: true,
}
},
data() {
return {
clicked: 1,
top: sys.windowHeight - 58,
left: sys.windowWidth - 58,
width: 0,
height: 0,
offsetWidth: 0,
offsetHeight: 0,
windowWidth: 0,
windowHeight: 0,
isMove: true,
edge: 10,
}
},
computed: {
baseUrl() {
return process.uniEnv.qn_base_url
},
imageUrl() {
console.log('---------', this.baseUrl + this.icon)
return this.baseUrl + this.icon
},
opacity() {
return this.clicked == 0 ? '0.6' : '1'
},
},
created() {
this.windowWidth = sys.windowWidth
this.windowHeight = sys.windowHeight
// #ifdef APP-PLUS
this.existTabBar && (this.windowHeight -= 50)
// #endif
if (sys.windowTop) {
this.windowHeight += sys.windowTop
}
const query = uni.createSelectorQuery().in(this)
query
.select('#_drag_button')
.boundingClientRect((data) => {
this.width = data.width
this.height = data.height
this.offsetWidth = data.width / 2
this.offsetHeight = data.height / 2
// this.left = this.windowWidth - this.width - this.edge
// this.top = this.windowHeight - this.height - this.edge
})
.exec()
this.clickedMinus()
},
mounted() {},
methods: {
handleClick() {
this.$emit('click')
},
touchstart(e) {
this.clicked += 1
},
touchend(e) {
if (this.isDock) {
let edgeRigth = this.windowWidth - this.width - this.edge
if (this.left < this.windowWidth / 2 - this.offsetWidth) {
this.left = this.edge
} else {
this.left = edgeRigth
}
}
this.isMove = false
this.clickedMinus()
},
touchmove(e) {
if (!this.canMove) {
return false
}
// 单指触摸
if (e.touches.length !== 1) {
return false
}
this.isMove = true
let clientY = e.touches[0].clientY - this.offsetHeight
// #ifdef H5
clientY += this.height
// #endif
let edgeBottom = this.windowHeight - 58
// 上下触及边界
if (clientY < this.edge) {
this.top = this.edge
} else if (clientY > edgeBottom) {
this.top = edgeBottom
} else {
this.top = clientY
}
let clientX = e.touches[0].clientX - this.offsetWidth
// #ifdef H5
clientX += this.width
// #endif
let edgeLeft = this.windowWidth - this.width - this.edge
// 左右触及边界
if (clientX < this.edge) {
this.left = this.edge
} else if (clientX > edgeLeft) {
this.left = edgeLeft
} else {
this.left = clientX
}
},
clickedMinus() {
setTimeout(() => {
// 三秒不点击,算失去活跃
this.clicked = Math.max(0, this.clicked - 1)
}, 3000)
},
},
}
</script>
<style lang="scss">
.fab-view {
// width: 100%;
// height: 100%;
.suspension {
position: fixed;
height: 96rpx;
width: 96rpx;
border-radius: 50%;
background-color: #02A074;
// background: linear-gradient(to right, #fff100, #ffde00);
z-index: 999;
display: flex;
justify-content: center;
align-items: center;
color: #ffffff;
font-size: 24rpx;
font-weight: bold;
box-shadow: 0px 6px 12px 0px rgba(2, 160, 116, 0.3500);
// padding-right: 4rpx;
.image-icon {
width: 96rpx;
height: 96rpx;
}
.content-text {
width: 96rpx;
text-align: center;
padding: 0 16rpx;
}
}
}
</style>
...@@ -70,7 +70,7 @@ ...@@ -70,7 +70,7 @@
<u-time-line-item <u-time-line-item
v-for="(item, index) in info.records" v-for="(item, index) in info.records"
:key="index" :key="index"
nodeTop="12" nodeTop="10"
> >
<template v-slot:node> <template v-slot:node>
<view class="node-view"> </view> <view class="node-view"> </view>
......
...@@ -78,6 +78,7 @@ ...@@ -78,6 +78,7 @@
<NoData v-else-if="!loading" customStyle="margin-top:100rpx" :image="currentNoData.image" :text="currentNoData.text"/> <NoData v-else-if="!loading" customStyle="margin-top:100rpx" :image="currentNoData.image" :text="currentNoData.text"/>
</view> </view>
<PopNormal title="操作提醒" :visible.sync="visible" @confirm="handleClickConfirm" cancelText="取消" confirmText="导出" content="确认导出账单吗?"/> <PopNormal title="操作提醒" :visible.sync="visible" @confirm="handleClickConfirm" cancelText="取消" confirmText="导出" content="确认导出账单吗?"/>
<FabView/>
</view> </view>
</template> </template>
...@@ -85,6 +86,7 @@ ...@@ -85,6 +86,7 @@
import NavbarRight from '@/components/navbar-right' import NavbarRight from '@/components/navbar-right'
import DateRangePicker from '@/components/date-range-picker/uni-datetime-picker.vue' import DateRangePicker from '@/components/date-range-picker/uni-datetime-picker.vue'
import CellMaintainBill from '@/components/cell-maintain-bill' import CellMaintainBill from '@/components/cell-maintain-bill'
import FabView from '@/components/fab-view'
import NoData from '@/components/no-data' import NoData from '@/components/no-data'
import PopNormal from '@/components/pop-normal' import PopNormal from '@/components/pop-normal'
...@@ -94,7 +96,8 @@ export default { ...@@ -94,7 +96,8 @@ export default {
DateRangePicker, DateRangePicker,
CellMaintainBill, CellMaintainBill,
NoData, NoData,
PopNormal PopNormal,
FabView
}, },
data() { data() {
return { return {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment