提交 f8cca341 作者: test

feat: 优化 Widgets 的高度或定位响应式计算方式,AffixFilter 完善

上级 db7ad0bf
<!-- 吸附过滤器组件 --> <!-- 吸附过滤器组件 -->
<script setup lang="ts"> <script setup lang="ts">
import type { Option } from './types' import type { Option, OptionItem } from './types'
const props = defineProps({ const props = defineProps({
// 是否显示 // 是否显示
...@@ -21,13 +21,13 @@ ...@@ -21,13 +21,13 @@
}, },
// 距离顶部的距离 // 距离顶部的距离
top: { top: {
type: String, type: Number,
default: '125rpx', default: 125,
}, },
// 距离左侧的距离 // 距离左侧的距离
left: { left: {
type: String, type: Number,
default: '30rpx', default: 30,
}, },
// 选项 // 选项
options: { options: {
...@@ -38,8 +38,8 @@ ...@@ -38,8 +38,8 @@
const emits = defineEmits(['register']) const emits = defineEmits(['register'])
const positionTop = computed(() => data.top) const positionTop = computed(() => `${data.top}rpx`)
const positionLeft = computed(() => data.left) const positionLeft = computed(() => `${data.left}rpx`)
const data = reactive({ const data = reactive({
show: props.show, show: props.show,
layout: props.layout, layout: props.layout,
...@@ -57,6 +57,27 @@ ...@@ -57,6 +57,27 @@
Object.assign(data, value) Object.assign(data, value)
} }
function setOptionItems(key: string, items: OptionItem[]) {
data.options = data.options.map((option) => {
if (option.key === key) {
option.items = items
}
return option
})
}
function setOptionItemChecked(key: string, value: string) {
data.options = data.options.map((option) => {
if (option.key === key) {
option.items = option.items.map((item) => {
item.checked = item.value === value
return item
})
}
return option
})
}
const zIndex = computed(() => (model.show ? 200 : 110)) const zIndex = computed(() => (model.show ? 200 : 110))
const model = reactive({ const model = reactive({
show: false, show: false,
...@@ -114,6 +135,8 @@ ...@@ -114,6 +135,8 @@
emits('register', { emits('register', {
setProps, setProps,
toggleShow, toggleShow,
setOptionItems,
setOptionItemChecked,
}) })
</script> </script>
......
...@@ -39,12 +39,12 @@ export interface AffixFilterProps extends BasicWidgetProps { ...@@ -39,12 +39,12 @@ export interface AffixFilterProps extends BasicWidgetProps {
* 距离顶部的距离 rpx * 距离顶部的距离 rpx
* @default 130rpx * @default 130rpx
*/ */
top?: string top?: number
/** /**
* 距离左侧的距离 rpx * 距离左侧的距离 rpx
* @default 30rpx * @default 30rpx
*/ */
left?: string left?: number
/** /**
* 过滤选项集合,仅支持 Select * 过滤选项集合,仅支持 Select
*/ */
...@@ -55,7 +55,13 @@ export interface AffixFilterInstance extends BasicWidgetInstance<AffixFilterProp ...@@ -55,7 +55,13 @@ export interface AffixFilterInstance extends BasicWidgetInstance<AffixFilterProp
/** /**
* 设置选项 * 设置选项
* @param key 选项标识 * @param key 选项标识
* @param item 选项可选 options * @param items 选项可选 options
*/ */
setOptionItem: (key: string, item: OptionItem) => void setOptionItems: (key: string, items: OptionItem[]) => void
/**
* 设置选项选中
* @param key 选项标识
* @param value 选项值
*/
setOptionItemChecked: (key: string, value: string) => void
} }
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
// 展开按钮标题 // 展开按钮标题
expandTitle: { expandTitle: {
type: String, type: String,
default: '',
}, },
// 是否有展开按钮 // 是否有展开按钮
showExpandButton: { showExpandButton: {
...@@ -73,7 +72,7 @@ ...@@ -73,7 +72,7 @@
toggleShow, toggleShow,
toggleExpand, toggleExpand,
// TODO: 此处高度还需考虑底部安全区 // TODO: 此处高度还需考虑底部安全区
height: computed(() => (data.show ? `${(data.expand ? data.maxHeight : data.height) + 30}rpx` : '1rpx')), height: computed(() => (data.show ? (data.expand ? data.maxHeight : data.height) : 0)),
}) })
</script> </script>
......
...@@ -21,7 +21,7 @@ export function useBottomBarWidget<T extends BottomBarInstance, P extends Bottom ...@@ -21,7 +21,7 @@ export function useBottomBarWidget<T extends BottomBarInstance, P extends Bottom
{ {
...fns, ...fns,
toggleExpand: (expand?: boolean) => get()?.toggleExpand(getBooleanOrDefault(expand)), toggleExpand: (expand?: boolean) => get()?.toggleExpand(getBooleanOrDefault(expand)),
height: computed(() => instanceRef?.value?.height) as unknown as ComputedRef<string>, height: computed(() => instanceRef?.value?.height) as unknown as ComputedRef<number>,
}, },
] ]
} }
import type { BasicWidgetInstance, BasicWidgetProps } from '../../utils' import type { BasicWidgetInstance, BasicWidgetProps } from '../../utils'
export interface BottomBarProps extends BasicWidgetProps { export interface BottomBarProps extends BasicWidgetProps {
// 是否展开 /**
* 是否展开
* @default false
*/
expand?: boolean expand?: boolean
// 展开标题 /**
* 展开标题
*/
expandTitle?: string expandTitle?: string
// 是否有展开按钮 /**
* 是否有展开按钮
* @default true
*/
showExpandButton?: boolean showExpandButton?: boolean
// 是否有展开边框 /**
* 是否有展开边框
* @default false
*/
showExpandBorder?: boolean showExpandBorder?: boolean
// 高度 rpx /**
* 高度 rpx
* @default 0 rpx
*/
height: number height: number
// 最大高度 rpx /**
* 最大高度 rpx
* @default 0 rpx
*/
maxHeight?: number maxHeight?: number
} }
...@@ -19,7 +36,7 @@ export interface BottomBarInstance extends BasicWidgetInstance<BottomBarProps> { ...@@ -19,7 +36,7 @@ export interface BottomBarInstance extends BasicWidgetInstance<BottomBarProps> {
/** /**
* 响应式组件当前高度,单位 rpx * 响应式组件当前高度,单位 rpx
*/ */
height: ComputedRef<string> height: ComputedRef<number>
/** /**
* 切换展开状态 * 切换展开状态
* @param expand 是否展开 * @param expand 是否展开
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
import { isArray } from 'lodash-es' import { isArray } from 'lodash-es'
import { createReusableTemplate } from '@vueuse/core' import { createReusableTemplate } from '@vueuse/core'
import type { Option } from './types' import type { Option } from './types'
import { cssAdditionCalc } from '@/components/Map/Widgets/utils'
const props = defineProps({ const props = defineProps({
// 显示 // 显示
...@@ -19,12 +20,11 @@ ...@@ -19,12 +20,11 @@
// 标题 // 标题
title: { title: {
type: String, type: String,
default: '',
}, },
// 底部距离 rpx // 底部距离 rpx
bottom: { bottom: {
type: String, type: Number,
default: '30rpx', default: 0,
}, },
// JSON 数据 // JSON 数据
option: { option: {
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
// 定义复用渲染组件 // 定义复用渲染组件
const [DefineTemplate, ReuseTemplate] = createReusableTemplate<{ item: Recordable; sub?: boolean }>() const [DefineTemplate, ReuseTemplate] = createReusableTemplate<{ item: Recordable; sub?: boolean }>()
const positionBottom = computed(() => `calc(${data.bottom})`) const positionBottom = computed(() => cssAdditionCalc(30, data.bottom))
const data = reactive({ const data = reactive({
show: props.show, show: props.show,
expand: props.expand, expand: props.expand,
......
...@@ -21,14 +21,24 @@ export interface Option { ...@@ -21,14 +21,24 @@ export interface Option {
} }
export interface LegendProps extends BasicWidgetProps { export interface LegendProps extends BasicWidgetProps {
// 是否展开 /**
* 是否展开
* @default false
*/
expand?: boolean expand?: boolean
// 标题 /**
* 标题
*/
title: string title: string
// 选项 /**
* 选项
*/
option: Option option: Option
// 底部距离 rpx /**
bottom?: string * 底部距离 rpx
* @default 0
*/
bottom?: number
} }
export interface LegendInstance extends BasicWidgetInstance<LegendProps> { export interface LegendInstance extends BasicWidgetInstance<LegendProps> {
......
...@@ -9,14 +9,14 @@ ...@@ -9,14 +9,14 @@
}, },
// 底部距离 rpx // 底部距离 rpx
bottom: { bottom: {
type: String, type: Number,
default: '1rpx', default: 0,
}, },
}) })
const emits = defineEmits(['register', 'prev', 'next']) const emits = defineEmits(['register', 'prev', 'next'])
const height = computed(() => `calc(50% - 60rpx - ${Number(data.bottom.replace('rpx', '')) / 2}rpx)`) const height = computed(() => `calc(50% - 60rpx${data.bottom ? ` - ${data.bottom / 2}rpx` : ''})`)
const data = reactive({ const data = reactive({
show: props.show, show: props.show,
bottom: props.bottom, bottom: props.bottom,
......
...@@ -2,7 +2,7 @@ import type { BasicWidgetInstance, BasicWidgetProps } from '../../utils' ...@@ -2,7 +2,7 @@ import type { BasicWidgetInstance, BasicWidgetProps } from '../../utils'
export interface SwitchControlProps extends BasicWidgetProps { export interface SwitchControlProps extends BasicWidgetProps {
// 底部距离 rpx // 底部距离 rpx
bottom?: string bottom?: number
// 上一个 // 上一个
prev?: () => void prev?: () => void
// 下一个 // 下一个
......
...@@ -44,15 +44,28 @@ export interface TimeBarButton { ...@@ -44,15 +44,28 @@ export interface TimeBarButton {
} }
export interface TimeBarProps extends BasicWidgetProps { export interface TimeBarProps extends BasicWidgetProps {
// 是否只读 /**
* 是否只读
* @default false
*/
readonly?: boolean readonly?: boolean
// 对齐方式 /**
* 对齐方式
* @default left
*/
align?: 'left' | 'center' | 'right' align?: 'left' | 'center' | 'right'
// 标题 /**
* 标题
* @default { text: '时间' }
*/
label?: TimeBarLabel label?: TimeBarLabel
// 时间 /**
* 时间
*/
time: TimeBarTime time: TimeBarTime
// 扩展按钮 /**
* 扩展按钮
*/
buttons?: TimeBarButton[] buttons?: TimeBarButton[]
} }
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
<script setup lang="ts"> <script setup lang="ts">
import { createReusableTemplate } from '@vueuse/core' import { createReusableTemplate } from '@vueuse/core'
import type { ToolBoxButton, ToolBoxButtonGroup } from './types' import type { ToolBoxButton, ToolBoxButtonGroup } from './types'
import { cssAdditionCalc } from '@/components/Map/Widgets/utils'
const props = defineProps({ const props = defineProps({
// 显示 // 显示
...@@ -22,18 +23,18 @@ ...@@ -22,18 +23,18 @@
}, },
// 顶部距离 rpx // 顶部距离 rpx
top: { top: {
type: String, type: Number,
default: '1rpx', default: 0,
}, },
// 底部距离 rpx // 底部距离 rpx
bottom: { bottom: {
type: String, type: Number,
default: '1rpx', default: 0,
}, },
// 底部内边距 rpx (用于避免遮挡) // 底部内边距 rpx (用于避免遮挡)
bottomPadding: { bottomPadding: {
type: String, type: Number,
default: '1rpx', default: 0,
}, },
// 工具集 // 工具集
tools: { tools: {
...@@ -47,9 +48,8 @@ ...@@ -47,9 +48,8 @@
// 定义复用渲染组件 // 定义复用渲染组件
const [DefineTemplate, ReuseTemplate] = createReusableTemplate<{ items: ToolBoxButton[] }>() const [DefineTemplate, ReuseTemplate] = createReusableTemplate<{ items: ToolBoxButton[] }>()
const positionTop = computed(() => `calc(125rpx + ${data.top})`) const positionTop = computed(() => cssAdditionCalc(95, 30, data.top))
// BottomBar 改为 border-box 宽高不再计算padding const height = computed(() => cssAdditionCalc(30, data.bottom, data.bottomPadding))
const height = computed(() => `calc(${data.bottomPadding} + ${data.bottom})`)
const data = reactive({ const data = reactive({
show: props.show, show: props.show,
expand: props.expand, expand: props.expand,
......
...@@ -50,17 +50,34 @@ export interface ToolBoxButtonGroup { ...@@ -50,17 +50,34 @@ export interface ToolBoxButtonGroup {
} }
export interface ToolBoxProps extends BasicWidgetProps { export interface ToolBoxProps extends BasicWidgetProps {
// 是否展开 /**
* 是否展开
* @default true
*/
expand?: boolean expand?: boolean
// 是否显示是否展开按钮 /**
* 是否显示是否展开按钮
* @default true
*/
showExpandButton?: boolean showExpandButton?: boolean
// 顶部距离 rpx /**
top?: string * 顶部距离 rpx
// 底部距离 rpx * @default 0
bottom?: string */
// 底部内边距 rpx top?: number
bottomPadding?: string /**
// 工具集 * 底部距离 rpx
* @default 0
*/
bottom?: number
/**
* 底部内边距 rpx
* @default 0
*/
bottomPadding?: number
/**
* 工具集
*/
tools?: ToolBoxButtonGroup[] tools?: ToolBoxButtonGroup[]
} }
......
...@@ -2,7 +2,10 @@ import { isBoolean } from 'lodash-es' ...@@ -2,7 +2,10 @@ import { isBoolean } from 'lodash-es'
import { isProdMode } from '@/utils/env' import { isProdMode } from '@/utils/env'
export interface BasicWidgetProps { export interface BasicWidgetProps {
// 是否显示 /**
* 是否显示
* @default true
*/
show?: boolean show?: boolean
} }
...@@ -95,3 +98,21 @@ export function unpackWidgetInstance<T extends BasicWidgetInstance, P extends Ba ...@@ -95,3 +98,21 @@ export function unpackWidgetInstance<T extends BasicWidgetInstance, P extends Ba
toggleShow: (show?: boolean) => get()?.toggleShow(getBooleanOrDefault(show)), toggleShow: (show?: boolean) => get()?.toggleShow(getBooleanOrDefault(show)),
} as T & { get: () => T } } as T & { get: () => T }
} }
/**
* css calc 加法计算函数
* @param values rpx 数值
* @returns css calc 函数或 rpx 数值
*/
export function cssAdditionCalc(...values: number[]): string {
const result = values
.filter((item) => item)
.map((item) => `${item}rpx`)
.join(' + ')
if (result.includes('+')) {
return `calc(${result})`
} else {
return result
}
}
...@@ -252,7 +252,7 @@ ...@@ -252,7 +252,7 @@
// 当底部 Bar 小部件高度变化时,重新设置地图的中心点,使界面显示效果更好 // 当底部 Bar 小部件高度变化时,重新设置地图的中心点,使界面显示效果更好
if (map.isReady.value) { if (map.isReady.value) {
if (value === '210rpx') { if (value === 150) {
map.flyTo({ map.flyTo({
center: [111.6, 26.770844], center: [111.6, 26.770844],
speed: 0.2, speed: 0.2,
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论