SFilePreview.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. import { computed as i, ref as y, watch as U, resolveComponent as b, openBlock as k, createBlock as I, withCtx as S, createElementVNode as a, createVNode as m, unref as f } from "vue";
  2. import { n as B, a0 as F, a1 as N } from "./index2.js";
  3. const O = { class: "preview-content" }, $ = { class: "view-content" }, M = ["src"], P = {
  4. __name: "SFilePreview",
  5. props: {
  6. /**
  7. * 是否显示,配合 v-model:value 使用
  8. */
  9. value: {
  10. type: Boolean,
  11. default: !1
  12. },
  13. /**
  14. * 文件列表,用于左右翻页
  15. */
  16. list: {
  17. type: Array,
  18. default: () => []
  19. },
  20. /**
  21. * 初始预览项下标,弹窗打开时生效
  22. */
  23. active: {
  24. type: Number,
  25. default: 0
  26. },
  27. /**
  28. * 自定义标题,为空时取文件名
  29. */
  30. title: {
  31. type: String,
  32. default: ""
  33. }
  34. },
  35. emits: ["update:value", "change"],
  36. setup(_, { emit: w }) {
  37. const n = _, u = w, r = i({
  38. get: () => n.value,
  39. set: (t) => u("update:value", t)
  40. }), g = (t = {}) => t.imageUrl || t.url || t.uid || "", x = (t = "") => {
  41. const e = String(t).split("?")[0].split("#")[0], s = e.substring(e.lastIndexOf("/") + 1);
  42. try {
  43. return decodeURIComponent(s);
  44. } catch (o) {
  45. return s;
  46. }
  47. }, l = y(0), c = (t) => {
  48. const e = (n.list || []).length;
  49. return e ? Math.min(Math.max(t, 0), e - 1) : 0;
  50. };
  51. U(
  52. () => n.value,
  53. (t) => {
  54. t && (l.value = c(n.active));
  55. },
  56. { immediate: !0 }
  57. );
  58. const v = i(() => (n.list || [])[l.value] || {}), d = i(() => g(v.value)), h = i(
  59. () => n.title || v.value.name || x(d.value) || window.$l("预览")
  60. ), p = (t) => {
  61. const e = c(l.value + t);
  62. e !== l.value && (l.value = e, u("change", e));
  63. }, C = () => {
  64. r.value = !1;
  65. };
  66. return (t, e) => {
  67. const s = b("s-modal");
  68. return k(), I(s, {
  69. value: r.value,
  70. "onUpdate:value": e[2] || (e[2] = (o) => r.value = o),
  71. title: h.value,
  72. width: "800px",
  73. onHandCancel: C
  74. }, {
  75. default: S(() => [
  76. a("div", O, [
  77. a("div", {
  78. class: "prev",
  79. onClick: e[0] || (e[0] = (o) => p(-1))
  80. }, [
  81. m(f(F))
  82. ]),
  83. a("div", $, [
  84. a("img", {
  85. alt: "preview",
  86. class: "view",
  87. src: d.value
  88. }, null, 8, M)
  89. ]),
  90. a("div", {
  91. class: "next",
  92. onClick: e[1] || (e[1] = (o) => p(1))
  93. }, [
  94. m(f(N))
  95. ])
  96. ])
  97. ]),
  98. _: 1
  99. }, 8, ["value", "title"]);
  100. };
  101. }
  102. }, A = /* @__PURE__ */ B(P, [["__scopeId", "data-v-58b32905"]]);
  103. export {
  104. A as default
  105. };