Skip to content

Commit 74c90be

Browse files
author
xuqingkai
committed
fix: 🐛 修复Fab初始化时存在初始位置闪现的问题
1 parent de81f40 commit 74c90be

File tree

1 file changed

+14
-18
lines changed
  • src/uni_modules/wot-design-uni/components/wd-fab

1 file changed

+14
-18
lines changed

src/uni_modules/wot-design-uni/components/wd-fab/wd-fab.vue

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
:style="rootStyle"
88
@click.stop=""
99
>
10-
<view @click.stop="">
10+
<view @click.stop="" v-if="inited">
1111
<wd-button @click="handleClick" custom-class="wd-fab__trigger" round :type="type" :disabled="disabled">
1212
<wd-icon custom-class="wd-fab__icon" :name="isActive ? activeIcon : inactiveIcon"></wd-icon>
1313
</wd-button>
@@ -44,11 +44,11 @@ import { isDef, isH5, objToStyle } from '../common/util'
4444
import { type Queue, queueKey } from '../composables/useQueue'
4545
import { closeOther, pushToQueue, removeFromQueue } from '../common/clickoutside'
4646
import { fabProps, type FabExpose } from './types'
47-
import { onMounted, reactive } from 'vue'
47+
import { reactive } from 'vue'
4848
4949
const props = defineProps(fabProps)
5050
const emit = defineEmits(['update:active'])
51-
51+
const inited = ref<boolean>(false) // 是否初始化完成
5252
const isActive = ref<boolean>(false) // 是否激活状态
5353
const queue = inject<Queue | null>(queueKey, null)
5454
const { proxy } = getCurrentInstance() as any
@@ -86,28 +86,26 @@ watch(
8686
() => initPosition()
8787
)
8888
89-
const top = ref(0)
90-
const left = ref(0)
89+
const top = ref<number>(0)
90+
const left = ref<number>(0)
9191
const screen = reactive({ width: 0, height: 0 })
92-
const fabSize = ref(56)
92+
const fabSize = ref<number>(56)
9393
const bounding = reactive({
9494
minTop: 0,
9595
minLeft: 0,
9696
maxTop: 0,
9797
maxLeft: 0
9898
})
99+
const fabGap: number = 16 // fab默认与边缘的间距
99100
100101
function getBounding() {
101102
const sysInfo = uni.getSystemInfoSync()
102-
const gap = 16
103-
104103
screen.width = sysInfo.windowWidth
105104
screen.height = isH5 ? sysInfo.windowTop + sysInfo.windowHeight : sysInfo.windowHeight
106-
107-
bounding.minTop = isH5 ? sysInfo.windowTop + gap : gap
108-
bounding.minLeft = gap
109-
bounding.maxLeft = screen.width - fabSize.value - gap
110-
bounding.maxTop = screen.height - fabSize.value - gap
105+
bounding.minTop = isH5 ? sysInfo.windowTop + fabGap : fabGap
106+
bounding.minLeft = fabGap
107+
bounding.maxLeft = screen.width - fabSize.value - fabGap
108+
bounding.maxTop = screen.height - fabSize.value - fabGap
111109
}
112110
113111
function initPosition() {
@@ -128,13 +126,9 @@ function initPosition() {
128126
}
129127
}
130128
131-
onMounted(() => {
132-
initPosition()
133-
})
134-
135129
// 按下时坐标相对于元素的偏移量
136130
const touchOffset = reactive({ x: 0, y: 0 })
137-
const attractTransition = ref(false)
131+
const attractTransition = ref<boolean>(false)
138132
function handleTouchStart(e: TouchEvent) {
139133
if (props.draggable === false) return
140134
@@ -191,6 +185,8 @@ const rootStyle = computed(() => {
191185
192186
onBeforeMount(() => {
193187
getBounding()
188+
initPosition()
189+
inited.value = true
194190
if (queue && queue.pushToQueue) {
195191
queue.pushToQueue(proxy)
196192
} else {

0 commit comments

Comments
 (0)