| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- import { ref as u, reactive as S, onMounted as _, onBeforeUnmount as k, openBlock as d, createElementBlock as T, Fragment as E, createElementVNode as m, createBlock as H, Teleport as x, createVNode as p, Transition as B, withCtx as O, withDirectives as R, normalizeStyle as z, unref as C, vShow as M } from "vue";
- import { n as N, U as L } from "./index2.js";
- const U = ["title"], Y = /* @__PURE__ */ Object.assign({ name: "SBackTop" }, {
- __name: "SBackTop",
- props: {
- /**
- * 滚动容器:CSS 选择器或 DOM 元素。
- * 不传时自动向上找最近的滚动祖先(如 SPanelLayout 的内容区),找不到则监听 window。
- */
- target: {
- type: [String, Object],
- default: null
- },
- /** 滚动超过该距离才出现;可滚动距离本身更短时按比例下调,避免按钮永不出现 */
- visibilityHeight: {
- type: Number,
- default: 200
- },
- /** 距滚动容器右边缘的距离(px);容器铺满窗口时即距窗口右边缘 */
- right: {
- type: Number,
- default: 30
- },
- /** 距滚动容器下边缘的距离(px) */
- bottom: {
- type: Number,
- default: 40
- }
- },
- setup(f) {
- const o = f, s = u(null), a = u(!1), l = S({ right: o.right, bottom: o.bottom });
- let e = null, r = null;
- const w = (t) => {
- if (!t || t.nodeType !== 1) return !1;
- const n = window.getComputedStyle(t);
- return /(auto|scroll|overlay)/.test(n.overflowY) && t.scrollHeight > t.clientHeight + 1;
- }, h = () => {
- if (o.target)
- return typeof o.target == "string" ? document.querySelector(o.target) || window : o.target;
- let t = s.value ? s.value.parentElement : null, n = null;
- for (; t && t !== document.body && t !== document.documentElement; ) {
- if (w(t)) return t;
- !n && /(auto|scroll|overlay)/.test(window.getComputedStyle(t).overflowY) && (n = t), t = t.parentElement;
- }
- return n || window;
- }, g = () => !e || e === window ? window.pageYOffset || document.documentElement.scrollTop || 0 : e.scrollTop, b = () => !e || e === window ? document.documentElement.scrollHeight - window.innerHeight : e.scrollHeight - e.clientHeight, i = () => {
- const t = e;
- if (!t || t === window) {
- l.right = o.right, l.bottom = o.bottom;
- return;
- }
- const n = t.getBoundingClientRect();
- l.right = Math.max(0, window.innerWidth - n.right) + o.right, l.bottom = Math.max(0, window.innerHeight - n.bottom) + o.bottom;
- }, c = () => {
- const t = b(), n = Math.min(o.visibilityHeight, Math.max(40, t * 0.15));
- a.value = g() > n, i();
- }, v = () => {
- e = h(), i(), c(), r && r.disconnect(), e && e !== window && typeof ResizeObserver != "undefined" && (r = new ResizeObserver(() => {
- i(), c();
- }), r.observe(e));
- }, y = () => {
- const t = { top: 0, behavior: "smooth" };
- if (!e || e === window) {
- window.scrollTo(t);
- return;
- }
- e.scrollTo(t);
- };
- return _(() => {
- v(), document.addEventListener("scroll", c, !0), window.addEventListener("resize", i);
- }), k(() => {
- document.removeEventListener("scroll", c, !0), window.removeEventListener("resize", i), r && r.disconnect(), r = null, e = null;
- }), (t, n) => (d(), T(E, null, [
- m("span", {
- ref_key: "anchorRef",
- ref: s,
- class: "s-back-top-anchor",
- "aria-hidden": "true"
- }, null, 512),
- (d(), H(x, { to: "body" }, [
- p(B, { name: "s-back-top-fade" }, {
- default: O(() => [
- R(m("button", {
- class: "s-back-top",
- type: "button",
- title: t.$l("回到顶部"),
- style: z({ right: l.right + "px", bottom: l.bottom + "px" }),
- onClick: y
- }, [
- p(C(L))
- ], 12, U), [
- [M, a.value]
- ])
- ]),
- _: 1
- })
- ]))
- ], 64));
- }
- }), D = /* @__PURE__ */ N(Y, [["__scopeId", "data-v-6a267305"]]);
- export {
- D as default
- };
|