mirror of
https://gitee.com/wot-design-uni/wot-design-uni.git
synced 2025-12-07 09:38:44 +08:00
parent
fad777dfa8
commit
bb5b19325f
@ -190,8 +190,9 @@ const tab = ref('Design')
|
|||||||
| 参数 | 说明 | 类型 | 可选值 | 默认值 | 最低版本 |
|
| 参数 | 说明 | 类型 | 可选值 | 默认值 | 最低版本 |
|
||||||
| -------- | ---------- | ------- | ------ | ------ | -------- |
|
| -------- | ---------- | ------- | ------ | ------ | -------- |
|
||||||
| name | 标签页名称 | string | - | - | - |
|
| name | 标签页名称 | string | - | - | - |
|
||||||
| title | 标题 | string | - | - | - |
|
| title | 标题 | string | - | - | - |
|
||||||
| disabled | 禁用 | boolean | - | false | - |
|
| disabled | 禁用 | boolean | - | false | - |
|
||||||
|
| lazy | 延迟渲染,默认开启,开启`animated`后此选项始终为`false` | boolean | - | true | $LOWEST_VERSION$ |
|
||||||
|
|
||||||
## Tabs Events
|
## Tabs Events
|
||||||
|
|
||||||
|
|||||||
@ -14,7 +14,12 @@ export const tabProps = {
|
|||||||
/**
|
/**
|
||||||
* 是否禁用,无法点击
|
* 是否禁用,无法点击
|
||||||
*/
|
*/
|
||||||
disabled: makeBooleanProp(false)
|
disabled: makeBooleanProp(false),
|
||||||
|
/**
|
||||||
|
* 是否懒加载,切换到该tab时才加载内容
|
||||||
|
* @default true
|
||||||
|
*/
|
||||||
|
lazy: makeBooleanProp(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
export type TabProps = ExtractPropTypes<typeof tabProps>
|
export type TabProps = ExtractPropTypes<typeof tabProps>
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<view :class="`wd-tab ${customClass}`" :style="customStyle">
|
<view :class="`wd-tab ${customClass}`" :style="customStyle">
|
||||||
<view v-if="painted" class="wd-tab__body" :style="tabBodyStyle">
|
<view class="wd-tab__body" v-if="shouldBeRender" :style="tabBodyStyle">
|
||||||
<slot />
|
<slot />
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
@ -25,24 +25,30 @@ import { tabProps } from './types'
|
|||||||
|
|
||||||
const props = defineProps(tabProps)
|
const props = defineProps(tabProps)
|
||||||
|
|
||||||
const painted = ref<boolean>(false) // 初始状态tab不会渲染,必须通过tabs来设置painted使tab渲染
|
|
||||||
const isShow = ref<boolean>(false)
|
|
||||||
const { proxy } = getCurrentInstance() as any
|
const { proxy } = getCurrentInstance() as any
|
||||||
const { parent: tabs, index } = useParent(TABS_KEY)
|
const { parent: tabs, index } = useParent(TABS_KEY)
|
||||||
|
|
||||||
// 激活项下标
|
// 激活项下标
|
||||||
const activeIndex = computed(() => {
|
const active = computed(() => {
|
||||||
return isDef(tabs) ? tabs.state.activeIndex : 0
|
return isDef(tabs) ? tabs.state.activeIndex === index.value : false
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const painted = ref<boolean>(active.value) // 初始状态tab不会渲染,必须通过tabs来设置painted使tab渲染
|
||||||
|
|
||||||
const tabBodyStyle = computed(() => {
|
const tabBodyStyle = computed(() => {
|
||||||
const style: CSSProperties = {}
|
const style: CSSProperties = {}
|
||||||
if (!isShow.value && (!isDef(tabs) || !tabs.props.animated)) {
|
if (!active.value && (!isDef(tabs) || !tabs.props.animated)) {
|
||||||
style.display = 'none'
|
style.display = 'none'
|
||||||
}
|
}
|
||||||
return objToStyle(style)
|
return objToStyle(style)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const shouldBeRender = computed(() => !props.lazy || painted.value || active.value)
|
||||||
|
|
||||||
|
watch(active, (val) => {
|
||||||
|
if (val) painted.value = true
|
||||||
|
})
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => props.name,
|
() => props.name,
|
||||||
(newValue) => {
|
(newValue) => {
|
||||||
@ -60,18 +66,6 @@ watch(
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
watch(
|
|
||||||
() => activeIndex.value,
|
|
||||||
(newValue) => {
|
|
||||||
if (newValue === index.value) {
|
|
||||||
setShow(true, true)
|
|
||||||
} else {
|
|
||||||
setShow(painted.value, false)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{ deep: true, immediate: true }
|
|
||||||
)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description 检测tab绑定的name是否和其它tab的name冲突
|
* @description 检测tab绑定的name是否和其它tab的name冲突
|
||||||
* @param {Object} self 自身
|
* @param {Object} self 自身
|
||||||
@ -88,21 +82,6 @@ function checkName(self: any) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 设置子组件展示
|
|
||||||
* @param setPainted
|
|
||||||
* @param setIsShow
|
|
||||||
*/
|
|
||||||
function setShow(setPainted: boolean, setIsShow: boolean) {
|
|
||||||
painted.value = setPainted
|
|
||||||
isShow.value = setIsShow
|
|
||||||
}
|
|
||||||
|
|
||||||
defineExpose({
|
|
||||||
setShow,
|
|
||||||
painted
|
|
||||||
})
|
|
||||||
</script>
|
</script>
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
@import './index.scss';
|
@import './index.scss';
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user