!74 tooltip,table

Merge pull request !74 from 莫名点/next
This commit is contained in:
就眠儀式 2022-05-24 15:45:50 +00:00 committed by Gitee
commit 36097784e6
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
7 changed files with 72 additions and 13 deletions

View File

@ -35,6 +35,7 @@ export interface LayPopperProps {
isDark?: boolean; isDark?: boolean;
disabled?: boolean; disabled?: boolean;
isCanHide?: boolean; isCanHide?: boolean;
isAutoShow?: boolean;
} }
const props = withDefaults(defineProps<LayPopperProps>(), { const props = withDefaults(defineProps<LayPopperProps>(), {
@ -43,6 +44,7 @@ const props = withDefaults(defineProps<LayPopperProps>(), {
disabled: false, disabled: false,
enterable: true, enterable: true,
isCanHide: true, isCanHide: true,
isAutoShow: false,
trigger: "hover", trigger: "hover",
}); });

View File

@ -354,13 +354,9 @@ onMounted(() => {
<lay-tooltip <lay-tooltip
v-if="column.ellipsisTooltip" v-if="column.ellipsisTooltip"
:content="data[column.key]" :content="data[column.key]"
:isAutoShow="true"
> >
<div class="layui-table-call-ellipsis"> <slot :name="column.customSlot" :data="data"></slot>
<slot
:name="column.customSlot"
:data="data"
></slot>
</div>
</lay-tooltip> </lay-tooltip>
<slot <slot
v-else v-else
@ -388,10 +384,9 @@ onMounted(() => {
<lay-tooltip <lay-tooltip
v-if="column.ellipsisTooltip" v-if="column.ellipsisTooltip"
:content="data[column.key]" :content="data[column.key]"
:isAutoShow="true"
> >
<div class="layui-table-call-ellipsis"> {{ data[column.key] }}
{{ data[column.key] }}
</div>
</lay-tooltip> </lay-tooltip>
<span v-else> {{ data[column.key] }} </span> <span v-else> {{ data[column.key] }} </span>
</td> </td>

View File

@ -0,0 +1,6 @@
.lay-tooltip-content{
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
cursor: pointer;
}

View File

@ -1,9 +1,13 @@
<template> <template>
<slot></slot> <div v-if="isAutoShow" class="lay-tooltip-content" ref="refTooltip">
<span><slot></slot></span>
</div>
<slot v-else></slot>
<lay-popper v-if="isMounted" v-bind="innerProps"></lay-popper> <lay-popper v-if="isMounted" v-bind="innerProps"></lay-popper>
</template> </template>
<script lang="ts"> <script lang="ts">
import "./index.less";
import LayPopper from "../popper/index.vue"; import LayPopper from "../popper/index.vue";
import { defineComponent, ref } from "vue"; import { defineComponent, ref } from "vue";
export default defineComponent({ export default defineComponent({
@ -32,11 +36,17 @@ export default defineComponent({
type: Boolean, type: Boolean,
default: true, default: true,
}, },
isAutoShow: {
type: Boolean,
default: false,
},
}, },
setup() { setup() {
const isMounted = ref(false); const isMounted = ref(false);
const refTooltip = ref(null);
return { return {
isMounted, isMounted,
refTooltip,
}; };
}, },
computed: { computed: {
@ -45,7 +55,19 @@ export default defineComponent({
}, },
}, },
mounted() { mounted() {
this.$nextTick(() => (this.isMounted = true)); this.$nextTick(() => {
if (this.refTooltip) {
if (
this.refTooltip.offsetWidth >= this.refTooltip.firstChild.offsetWidth
) {
this.isMounted = false;
} else {
this.isMounted = true;
}
} else {
this.isMounted = true;
}
});
}, },
}); });
</script> </script>

View File

@ -39,6 +39,7 @@ export default {
title:"备注", title:"备注",
width: "180px", width: "180px",
key:"remark", key:"remark",
ellipsisTooltip: true,
} }
] ]

View File

@ -6,6 +6,38 @@
::: demo ::: demo
<template>
<div style="width: 125px; ">
<lay-tooltip content="假装这里有文字提示" ref="tooltip" :isAutoShow="true">
假装这里有文字提示
</lay-tooltip>
</div>
<div style="width: 126px; margin-top: 20px">
<lay-tooltip content="假装这里有文字提示" ref="tooltip" :isAutoShow="true">
假装这里有文字提示
</lay-tooltip>
</div>
</template>
<script>
import { ref } from 'vue';
export default {
setup() {
}
}
</script>
<style>
</style>
:::
::: title 基础使用
:::
::: demo
<template> <template>
<lay-tooltip content="假装这里有文字提示"> <lay-tooltip content="假装这里有文字提示">
<lay-button>tooltip</lay-button> <lay-button>tooltip</lay-button>
@ -125,6 +157,7 @@
| isDark | 是否为黑色主题 | `true`(默认值)、`false`(浅色) | | isDark | 是否为黑色主题 | `true`(默认值)、`false`(浅色) |
| disabled | 是否禁用 | `false`(默认值)、`true`(禁用) || | disabled | 是否禁用 | `false`(默认值)、`true`(禁用) ||
| isCanHide | 控制是否可以隐藏,可参考`lay-slider`组件 | `true`(默认值)、`false` || | isCanHide | 控制是否可以隐藏,可参考`lay-slider`组件 | `true`(默认值)、`false` ||
| isAutoShow | 控制超出文本 `...` 时自动展示, 没有 `...` 时不展示 | `false`(默认值)、`true` ||
::: :::

View File

@ -71,8 +71,8 @@ importers:
package/component: package/component:
specifiers: specifiers:
'@layui/icons-vue': ^1.0.8 '@layui/icons-vue': ^1.0.9
'@layui/layer-vue': ^1.3.13 '@layui/layer-vue': ^1.3.14
'@vueuse/core': ^8.5.0 '@vueuse/core': ^8.5.0
animate.css: ^4.1.1 animate.css: ^4.1.1
async-validator: ^4.1.1 async-validator: ^4.1.1