提交 1be73da7 作者: 方治民

chore: 优化 hook 暴露方法的参数默认处理方式

上级 6fdd2839
...@@ -15,23 +15,25 @@ ...@@ -15,23 +15,25 @@
// 高度 // 高度
height: { height: {
type: Number, type: Number,
default: 100, default: 0,
}, },
// 最高高度 // 最高高度
maxHeight: { maxHeight: {
type: Number, type: Number,
default: 200, default: 0,
}, },
}) })
const emits = defineEmits(['register']) const emits = defineEmits(['register'])
const iHeight = computed(() => `${props.height}rpx`) const iHeight = computed(() => `${data.height}rpx`)
const iMaxHeight = computed(() => `${props.maxHeight}rpx`) const iMaxHeight = computed(() => `${data.maxHeight}rpx`)
const data = reactive({ const data = reactive({
show: props.show, show: props.show,
expand: props.expand, expand: props.expand,
height: props.height,
maxHeight: props.maxHeight,
}) })
function toggleShow(show?: boolean) { function toggleShow(show?: boolean) {
...@@ -50,7 +52,8 @@ ...@@ -50,7 +52,8 @@
setProps, setProps,
toggleShow, toggleShow,
toggleExpand, toggleExpand,
height: computed(() => (data.show ? `${(data.expand ? props.maxHeight : props.height) + 60}rpx` : '1rpx')), // TODO: 此处高度还需考虑底部安全区
height: computed(() => (data.show ? `${(data.expand ? data.maxHeight : data.height) + 60}rpx` : '1rpx')),
}) })
</script> </script>
...@@ -127,6 +130,8 @@ ...@@ -127,6 +130,8 @@
align-items: center; align-items: center;
width: 100%; width: 100%;
height: calc(100% - 60rpx - 20rpx); height: calc(100% - 60rpx - 20rpx);
overflow: hidden;
position: relative;
} }
} }
</style> </style>
import { getBooleanOrDefault } from '../../utils'
import type { BottomBarInstance, BottomBarProps } from './types' import type { BottomBarInstance, BottomBarProps } from './types'
import { isProdMode } from '/@/utils/env' import { isProdMode } from '/@/utils/env'
...@@ -41,10 +42,10 @@ export function useBottomBarWidget<T extends BottomBarInstance>(props: BottomBar ...@@ -41,10 +42,10 @@ export function useBottomBarWidget<T extends BottomBarInstance>(props: BottomBar
getInstance()?.setProps(props) getInstance()?.setProps(props)
}, },
toggleShow: (show?: boolean) => { toggleShow: (show?: boolean) => {
getInstance()?.toggleShow(show) getInstance()?.toggleShow(getBooleanOrDefault(show))
}, },
toggleExpand: (expand?: boolean) => { toggleExpand: (expand?: boolean) => {
getInstance()?.toggleExpand(expand) getInstance()?.toggleExpand(getBooleanOrDefault(expand))
}, },
} as T, } as T,
] ]
......
import { getBooleanOrDefault } from '../../utils'
import type { LegendInstance, LegendProps, Option } from './types' import type { LegendInstance, LegendProps, Option } from './types'
import { isProdMode } from '/@/utils/env' import { isProdMode } from '/@/utils/env'
...@@ -45,10 +46,10 @@ export function useLegendWidget<T extends LegendInstance>(props: LegendProps): [ ...@@ -45,10 +46,10 @@ export function useLegendWidget<T extends LegendInstance>(props: LegendProps): [
getInstance()?.setOption(option) getInstance()?.setOption(option)
}, },
toggleShow: (show?: boolean) => { toggleShow: (show?: boolean) => {
getInstance()?.toggleShow(show) getInstance()?.toggleShow(getBooleanOrDefault(show))
}, },
toggleExpand: (expand?: boolean) => { toggleExpand: (expand?: boolean) => {
getInstance()?.toggleExpand(expand) getInstance()?.toggleExpand(getBooleanOrDefault(expand))
}, },
} as T, } as T,
] ]
......
import { getBooleanOrDefault } from '../../utils'
import type { SwitchControlInstance, SwitchControlProps } from './types' import type { SwitchControlInstance, SwitchControlProps } from './types'
import { isProdMode } from '/@/utils/env' import { isProdMode } from '/@/utils/env'
...@@ -41,7 +42,7 @@ export function useSwitchControlWidget<T extends SwitchControlInstance>( ...@@ -41,7 +42,7 @@ export function useSwitchControlWidget<T extends SwitchControlInstance>(
getInstance()?.setProps(props) getInstance()?.setProps(props)
}, },
toggleShow: (show?: boolean) => { toggleShow: (show?: boolean) => {
getInstance()?.toggleShow(show) getInstance()?.toggleShow(getBooleanOrDefault(show))
}, },
prev: () => { prev: () => {
getInstance()?.prev() getInstance()?.prev()
......
import { isBoolean } from 'lodash-es'
export function getBooleanOrDefault(value: any, def = null): boolean {
return isBoolean(value) ? value : def
}
...@@ -36,21 +36,17 @@ ...@@ -36,21 +36,17 @@
const [registerBottomBarWidget, { height }] = useBottomBarWidget({ const [registerBottomBarWidget, { height }] = useBottomBarWidget({
show: true, show: true,
expand: true, expand: true,
height: 100, height: 150,
maxHeight: 200, maxHeight: 240,
}) })
function testPackUp() {
toggleLegendWidgetExpand()
}
</script> </script>
<template> <template>
<view class="bg-white h-100vh rain"> <view class="page h-100vh bg-white">
<!-- 地图组件 --> <!-- 地图组件 -->
<Mapbox :config="config" /> <Mapbox :config="config" />
<!-- 交互组件集 --> <!-- 地图上方所有小部件 -->
<view class="widgets"> <view class="widgets">
<!-- --> <!-- -->
...@@ -63,7 +59,7 @@ ...@@ -63,7 +59,7 @@
<!-- 底部 Bar 小部件 --> <!-- 底部 Bar 小部件 -->
<BottomBarWidget @register="registerBottomBarWidget"> <BottomBarWidget @register="registerBottomBarWidget">
<!-- 内容 Slot --> <!-- 内容 Slot -->
<view class="c-coolGray" @tap="testPackUp">底部交互控件/展示内容</view> <view class="c-coolGray" @tap="toggleLegendWidgetExpand">底部交互控件/展示内容</view>
</BottomBarWidget> </BottomBarWidget>
</view> </view>
</view> </view>
...@@ -71,21 +67,30 @@ ...@@ -71,21 +67,30 @@
<style lang="scss" scoped> <style lang="scss" scoped>
.widgets { .widgets {
// 覆盖图例小部件的默认样式
:deep(.legend) { :deep(.legend) {
bottom: calc(30rpx + v-bind(height)); bottom: calc(30rpx + v-bind(height));
// 如果底部使用 bottom-left attribution 则需要加上 80rpx,默认显示在右侧,不会冲突 // 如果底部使用 bottom-left attribution 则需要加上 80rpx,默认显示在右侧,不会冲突
// bottom: calc(30rpx + 80rpx + v-bind(height)); // bottom: calc(30rpx + 80rpx + v-bind(height));
} }
// 覆盖底部 Bar 小部件的默认样式
// :deep(.bottom-bar) {
// }
// 前后切换小部件
// :deep(.switch-control) {
// }
} }
.rain { .page {
// #ifdef H5 // #ifdef H5
:deep(.mapboxgl-ctrl-bottom-right) { :deep(.mapboxgl-ctrl-bottom-right) {
bottom: calc(30rpx + 50rpx + v-bind(height)); bottom: calc(80rpx + v-bind(height));
} }
:deep(.mapboxgl-ctrl-bottom-left) { :deep(.mapboxgl-ctrl-bottom-left) {
bottom: calc(30rpx + 50rpx + v-bind(height)); bottom: calc(80rpx + v-bind(height));
} }
// #endif // #endif
// #ifdef APP-PLUS // #ifdef APP-PLUS
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论