|
|
|
@ -1,23 +1,31 @@
|
|
|
|
<script setup lang="ts">
|
|
|
|
<script lang="tsx">
|
|
|
|
import { ElCollapseTransition, ElDescriptions, ElDescriptionsItem, ElTooltip } from 'element-plus'
|
|
|
|
import { ElCollapseTransition, ElDescriptions, ElDescriptionsItem, ElTooltip } from 'element-plus'
|
|
|
|
import { useDesign } from '@/hooks/web/useDesign'
|
|
|
|
import { useDesign } from '@/hooks/web/useDesign'
|
|
|
|
import { propTypes } from '@/utils/propTypes'
|
|
|
|
import { propTypes } from '@/utils/propTypes'
|
|
|
|
import { ref, unref, PropType, computed, useAttrs, useSlots } from 'vue'
|
|
|
|
import { ref, unref, PropType, computed, defineComponent } from 'vue'
|
|
|
|
import { useAppStore } from '@/store/modules/app'
|
|
|
|
import { useAppStore } from '@/store/modules/app'
|
|
|
|
import { DescriptionsSchema } from './types'
|
|
|
|
import { DescriptionsSchema } from './types'
|
|
|
|
|
|
|
|
import { Icon } from '@/components/Icon'
|
|
|
|
|
|
|
|
|
|
|
|
const appStore = useAppStore()
|
|
|
|
const appStore = useAppStore()
|
|
|
|
|
|
|
|
|
|
|
|
const mobile = computed(() => appStore.getMobile)
|
|
|
|
const mobile = computed(() => appStore.getMobile)
|
|
|
|
|
|
|
|
|
|
|
|
const attrs = useAttrs()
|
|
|
|
const { getPrefixCls } = useDesign()
|
|
|
|
|
|
|
|
|
|
|
|
const slots = useSlots()
|
|
|
|
const prefixCls = getPrefixCls('descriptions')
|
|
|
|
|
|
|
|
|
|
|
|
const props = defineProps({
|
|
|
|
export default defineComponent({
|
|
|
|
|
|
|
|
name: 'Descriptions',
|
|
|
|
|
|
|
|
props: {
|
|
|
|
title: propTypes.string.def(''),
|
|
|
|
title: propTypes.string.def(''),
|
|
|
|
message: propTypes.string.def(''),
|
|
|
|
message: propTypes.string.def(''),
|
|
|
|
collapse: propTypes.bool.def(true),
|
|
|
|
collapse: propTypes.bool.def(true),
|
|
|
|
|
|
|
|
border: propTypes.bool.def(true),
|
|
|
|
|
|
|
|
column: propTypes.number.def(2),
|
|
|
|
|
|
|
|
size: propTypes.oneOf(['large', 'default', 'small']).def('default'),
|
|
|
|
|
|
|
|
direction: propTypes.oneOf(['horizontal', 'vertical']).def('horizontal'),
|
|
|
|
|
|
|
|
extra: propTypes.string.def(''),
|
|
|
|
schema: {
|
|
|
|
schema: {
|
|
|
|
type: Array as PropType<DescriptionsSchema[]>,
|
|
|
|
type: Array as PropType<DescriptionsSchema[]>,
|
|
|
|
default: () => []
|
|
|
|
default: () => []
|
|
|
|
@ -26,13 +34,9 @@ const props = defineProps({
|
|
|
|
type: Object as PropType<any>,
|
|
|
|
type: Object as PropType<any>,
|
|
|
|
default: () => ({})
|
|
|
|
default: () => ({})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
setup(props, { slots, attrs }) {
|
|
|
|
const { getPrefixCls } = useDesign()
|
|
|
|
const getBindValue = computed((): any => {
|
|
|
|
|
|
|
|
|
|
|
|
const prefixCls = getPrefixCls('descriptions')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const getBindValue = computed(() => {
|
|
|
|
|
|
|
|
const delArr: string[] = ['title', 'message', 'collapse', 'schema', 'data', 'class']
|
|
|
|
const delArr: string[] = ['title', 'message', 'collapse', 'schema', 'data', 'class']
|
|
|
|
const obj = { ...attrs, ...props }
|
|
|
|
const obj = { ...attrs, ...props }
|
|
|
|
for (const key in obj) {
|
|
|
|
for (const key in obj) {
|
|
|
|
@ -40,10 +44,13 @@ const getBindValue = computed(() => {
|
|
|
|
delete obj[key]
|
|
|
|
delete obj[key]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (unref(mobile)) {
|
|
|
|
|
|
|
|
obj.direction = 'vertical'
|
|
|
|
|
|
|
|
}
|
|
|
|
return obj
|
|
|
|
return obj
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
const getBindItemValue = (item: DescriptionsSchema) => {
|
|
|
|
const getBindItemValue = (item: DescriptionsSchema) => {
|
|
|
|
const delArr: string[] = ['field']
|
|
|
|
const delArr: string[] = ['field']
|
|
|
|
const obj = { ...item }
|
|
|
|
const obj = { ...item }
|
|
|
|
for (const key in obj) {
|
|
|
|
for (const key in obj) {
|
|
|
|
@ -52,79 +59,77 @@ const getBindItemValue = (item: DescriptionsSchema) => {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return obj
|
|
|
|
return obj
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 折叠
|
|
|
|
// 折叠
|
|
|
|
const show = ref(true)
|
|
|
|
const show = ref(true)
|
|
|
|
|
|
|
|
|
|
|
|
const toggleClick = () => {
|
|
|
|
const toggleClick = () => {
|
|
|
|
if (props.collapse) {
|
|
|
|
if (props.collapse) {
|
|
|
|
show.value = !unref(show)
|
|
|
|
show.value = !unref(show)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<template>
|
|
|
|
return () => {
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
<div
|
|
|
|
:class="[
|
|
|
|
class={[
|
|
|
|
prefixCls,
|
|
|
|
prefixCls,
|
|
|
|
'bg-[var(--el-color-white)] dark:bg-[var(--el-bg-color)] dark:border-[var(--el-border-color)] dark:border-1px'
|
|
|
|
'bg-[var(--el-color-white)] dark:bg-[var(--el-bg-color)] dark:border-[var(--el-border-color)] dark:border-1px'
|
|
|
|
]"
|
|
|
|
]}
|
|
|
|
>
|
|
|
|
>
|
|
|
|
|
|
|
|
{props.title ? (
|
|
|
|
<div
|
|
|
|
<div
|
|
|
|
v-if="title"
|
|
|
|
class={[
|
|
|
|
:class="[
|
|
|
|
|
|
|
|
`${prefixCls}-header`,
|
|
|
|
`${prefixCls}-header`,
|
|
|
|
'h-50px flex justify-between items-center b-b-1 border-solid border-[var(--tags-view-border-color)] px-10px cursor-pointer dark:border-[var(--el-border-color)]'
|
|
|
|
'relative h-50px flex justify-between items-center layout-border__bottom px-10px cursor-pointer'
|
|
|
|
]"
|
|
|
|
]}
|
|
|
|
@click="toggleClick"
|
|
|
|
onClick={toggleClick}
|
|
|
|
>
|
|
|
|
>
|
|
|
|
<div :class="[`${prefixCls}-header__title`, 'relative font-18px font-bold ml-10px']">
|
|
|
|
<div class={[`${prefixCls}-header__title`, 'relative font-18px font-bold ml-10px']}>
|
|
|
|
<div class="flex items-center">
|
|
|
|
<div class="flex items-center">
|
|
|
|
{{ title }}
|
|
|
|
{props.title}
|
|
|
|
<ElTooltip v-if="message" :content="message" placement="right">
|
|
|
|
{props.message ? (
|
|
|
|
<Icon icon="ep:warning" class="ml-5px" />
|
|
|
|
<ElTooltip content={props.message} placement="right">
|
|
|
|
|
|
|
|
<Icon icon="bi:question-circle-fill" class="ml-5px" size={14} />
|
|
|
|
</ElTooltip>
|
|
|
|
</ElTooltip>
|
|
|
|
|
|
|
|
) : null}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<Icon v-if="collapse" :icon="show ? 'ep:arrow-down' : 'ep:arrow-up'" />
|
|
|
|
{props.collapse ? <Icon icon={show.value ? 'ep:arrow-down' : 'ep:arrow-up'} /> : null}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
) : null}
|
|
|
|
|
|
|
|
|
|
|
|
<ElCollapseTransition>
|
|
|
|
<ElCollapseTransition>
|
|
|
|
<div v-show="show" :class="[`${prefixCls}-content`, 'p-10px']">
|
|
|
|
<div v-show={unref(show)} class={[`${prefixCls}-content`, 'p-10px']}>
|
|
|
|
<ElDescriptions
|
|
|
|
<ElDescriptions {...unref(getBindValue)}>
|
|
|
|
:column="2"
|
|
|
|
{{
|
|
|
|
border
|
|
|
|
extra: () => (slots['extra'] ? slots['extra']() : props.extra),
|
|
|
|
:direction="mobile ? 'vertical' : 'horizontal'"
|
|
|
|
default: () => {
|
|
|
|
v-bind="getBindValue"
|
|
|
|
return props.schema.map((item) => {
|
|
|
|
>
|
|
|
|
return (
|
|
|
|
<template v-if="slots['extra']" #extra>
|
|
|
|
<ElDescriptionsItem key={item.field} {...getBindItemValue(item)}>
|
|
|
|
<slot name="extra"></slot>
|
|
|
|
{{
|
|
|
|
</template>
|
|
|
|
label: () => (item.slots?.label ? item.slots?.label(item) : item.label),
|
|
|
|
<ElDescriptionsItem
|
|
|
|
default: () =>
|
|
|
|
v-for="item in schema"
|
|
|
|
item.slots?.default
|
|
|
|
:key="item.field"
|
|
|
|
? item.slots?.default(item)
|
|
|
|
v-bind="getBindItemValue(item)"
|
|
|
|
: props.data[item.field]
|
|
|
|
>
|
|
|
|
}}
|
|
|
|
<template #label>
|
|
|
|
|
|
|
|
<slot
|
|
|
|
|
|
|
|
:name="`${item.field}-label`"
|
|
|
|
|
|
|
|
:row="{
|
|
|
|
|
|
|
|
label: item.label
|
|
|
|
|
|
|
|
}"
|
|
|
|
|
|
|
|
>{{ item.label }}</slot
|
|
|
|
|
|
|
|
>
|
|
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<template #default>
|
|
|
|
|
|
|
|
<slot :name="item.field" :row="data">{{ data[item.field] }}</slot>
|
|
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
</ElDescriptionsItem>
|
|
|
|
</ElDescriptionsItem>
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}}
|
|
|
|
</ElDescriptions>
|
|
|
|
</ElDescriptions>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</ElCollapseTransition>
|
|
|
|
</ElCollapseTransition>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style lang="less" scoped>
|
|
|
|
<style lang="less" scoped>
|
|
|
|
@prefix-cls: ~'@{namespace}-descriptions';
|
|
|
|
@prefix-cls: ~'@{namespace}-descriptions';
|
|
|
|
|