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'
4444import { type Queue , queueKey } from ' ../composables/useQueue'
4545import { closeOther , pushToQueue , removeFromQueue } from ' ../common/clickoutside'
4646import { fabProps , type FabExpose } from ' ./types'
47- import { onMounted , reactive } from ' vue'
47+ import { reactive } from ' vue'
4848
4949const props = defineProps (fabProps )
5050const emit = defineEmits ([' update:active' ])
51-
51+ const inited = ref < boolean >( false ) // 是否初始化完成
5252const isActive = ref <boolean >(false ) // 是否激活状态
5353const queue = inject <Queue | null >(queueKey , null )
5454const { 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 )
9191const screen = reactive ({ width: 0 , height: 0 })
92- const fabSize = ref (56 )
92+ const fabSize = ref < number > (56 )
9393const bounding = reactive ({
9494 minTop: 0 ,
9595 minLeft: 0 ,
9696 maxTop: 0 ,
9797 maxLeft: 0
9898})
99+ const fabGap: number = 16 // fab默认与边缘的间距
99100
100101function 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
113111function initPosition() {
@@ -128,13 +126,9 @@ function initPosition() {
128126 }
129127}
130128
131- onMounted (() => {
132- initPosition ()
133- })
134-
135129// 按下时坐标相对于元素的偏移量
136130const touchOffset = reactive ({ x: 0 , y: 0 })
137- const attractTransition = ref (false )
131+ const attractTransition = ref < boolean > (false )
138132function handleTouchStart(e : TouchEvent ) {
139133 if (props .draggable === false ) return
140134
@@ -191,6 +185,8 @@ const rootStyle = computed(() => {
191185
192186onBeforeMount (() => {
193187 getBounding ()
188+ initPosition ()
189+ inited .value = true
194190 if (queue && queue .pushToQueue ) {
195191 queue .pushToQueue (proxy )
196192 } else {
0 commit comments