Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
saas
/
supervise-wecom
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 71898bd2
authored
Jun 01, 2026
by
Jaxon
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
feat: 封装 tooltip 组件
1 parent
ff2902c1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
155 additions
and
0 deletions
src/components/tooltip/index.vue
src/components/tooltip/index.vue
0 → 100644
View file @
71898bd
<
template
>
<FloatingTooltip
ref=
"tooltip"
v-bind=
"tooltipProps"
v-on=
"mergedListeners"
@
click
.
native
.
stop
>
<slot
/>
<template
#
popper
>
<slot
name=
"content"
>
<span
v-if=
"hasTooltipContent"
class=
"tool-tips-content-label"
>
{{
tooltipContent
}}
</span>
</slot>
</
template
>
</FloatingTooltip>
</template>
<
script
>
import
{
Tooltip
as
FloatingTooltip
}
from
"floating-vue"
;
export
default
{
name
:
"BaseTooltip"
,
components
:
{
FloatingTooltip
,
},
inheritAttrs
:
false
,
props
:
{
content
:
{
type
:
[
String
,
Number
],
default
:
null
,
},
options
:
{
type
:
[
Object
,
String
,
Number
],
default
:
null
,
},
hideAfter
:
{
type
:
[
Number
,
String
],
default
:
0
,
},
},
data
()
{
return
{
hideTimer
:
null
,
};
},
computed
:
{
tooltipProps
()
{
const
attrs
=
{
...
this
.
$attrs
,
};
delete
attrs
.
content
;
if
(
typeof
this
.
options
===
"string"
||
typeof
this
.
options
===
"number"
)
{
return
{
...
attrs
,
theme
:
attrs
.
theme
||
"white-tooltip"
,
};
}
return
{
...(
this
.
options
||
{}),
...
attrs
,
theme
:
(
this
.
options
||
{}).
theme
||
attrs
.
theme
||
"white-tooltip"
,
};
},
tooltipContent
()
{
if
(
this
.
content
!==
null
&&
this
.
content
!==
undefined
)
return
this
.
content
;
if
(
typeof
this
.
options
===
"string"
||
typeof
this
.
options
===
"number"
)
return
this
.
options
;
if
(
this
.
options
&&
Object
.
prototype
.
hasOwnProperty
.
call
(
this
.
options
,
"content"
))
return
this
.
options
.
content
;
return
null
;
},
hasTooltipContent
()
{
return
this
.
tooltipContent
!==
null
&&
this
.
tooltipContent
!==
undefined
&&
this
.
tooltipContent
!==
""
;
},
mergedListeners
()
{
return
{
...
this
.
$listeners
,
"apply-show"
:
this
.
handleApplyShow
,
"apply-hide"
:
this
.
handleApplyHide
,
};
},
hideAfterMs
()
{
const
value
=
Number
(
this
.
hideAfter
);
return
Number
.
isFinite
(
value
)
&&
value
>
0
?
value
:
0
;
},
},
beforeDestroy
()
{
this
.
clearHideTimer
();
},
methods
:
{
show
(...
args
)
{
return
this
.
$refs
.
tooltip
?.
show
(...
args
);
},
hide
(...
args
)
{
this
.
clearHideTimer
();
return
this
.
$refs
.
tooltip
?.
hide
(...
args
);
},
dispose
(...
args
)
{
this
.
clearHideTimer
();
return
this
.
$refs
.
tooltip
?.
dispose
(...
args
);
},
handleApplyShow
(...
args
)
{
this
.
emitListener
(
"apply-show"
,
args
);
this
.
startAutoHide
();
},
handleApplyHide
(...
args
)
{
this
.
clearHideTimer
();
this
.
emitListener
(
"apply-hide"
,
args
);
},
startAutoHide
()
{
this
.
clearHideTimer
();
if
(
!
this
.
hideAfterMs
)
return
;
this
.
hideTimer
=
setTimeout
(()
=>
{
this
.
hide
();
},
this
.
hideAfterMs
);
},
clearHideTimer
()
{
if
(
this
.
hideTimer
)
{
clearTimeout
(
this
.
hideTimer
);
this
.
hideTimer
=
null
;
}
},
emitListener
(
name
,
args
)
{
const
listener
=
this
.
$listeners
[
name
];
if
(
typeof
listener
===
"function"
)
{
listener
(...
args
);
return
;
}
if
(
Array
.
isArray
(
listener
))
{
listener
.
forEach
(
fn
=>
typeof
fn
===
"function"
&&
fn
(...
args
));
}
},
},
};
</
script
>
<
style
lang=
"scss"
>
.v-popper--theme-white-tooltip
.v-popper__inner
{
background
:
#ffffff
;
color
:
rgba
(
0
,
0
,
0
,
0.88
);
border-radius
:
8px
;
padding
:
8px
12px
;
box-shadow
:
0
4px
16px
rgba
(
0
,
0
,
0
,
0.12
);
border
:
1px
solid
rgba
(
0
,
0
,
0
,
0.06
);
}
.v-popper--theme-white-tooltip
.v-popper__arrow-outer
{
border-color
:
#ffffff
;
}
.tool-tips-content-label
{
font-weight
:
400
;
font-size
:
12px
;
line-height
:
20px
;
color
:
#000000
e5
;
}
</
style
>
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment