| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271 |
- import { computed as M, ref as r, watch as z, resolveComponent as L, openBlock as c, createElementBlock as f, createElementVNode as i, toDisplayString as P, createCommentVNode as h, createVNode as v, unref as u, normalizeStyle as R, withCtx as S, withDirectives as K, createBlock as x, vShow as j } from "vue";
- import { d as H } from "./vuedraggable.js";
- import { b as q, d as G } from "./upload.js";
- import { n as J, ak as Q, al as W, am as X, an as Y, $ as Z, a0 as ee } from "./index2.js";
- const le = { class: "s-file-upload-common" }, te = {
- key: 0,
- class: "head"
- }, ae = { class: "label" }, ne = ["onMouseover", "onMouseleave"], ie = ["src"], oe = { class: "tool-wrap" }, se = { class: "left" }, ue = { class: "right move" }, de = { class: "plus-wrap" }, re = ["accept", "disabled"], ce = { class: "preview-content" }, ve = ["src"], me = {
- __name: "SDraggerUpload",
- props: {
- /**
- * 文件列表(同 PictureUpload 的 data)
- * @list
- */
- list: {
- type: Array,
- default: () => []
- },
- /**
- * 标题
- * @label
- */
- label: {
- type: String,
- default: ""
- },
- /**
- * 只读(同 PictureUpload 的 disabled)
- * @readonly
- */
- readonly: {
- type: Boolean,
- default: !1
- },
- /**
- * 是否显示新增(isAdd=false 等价 PictureUpload 的 ishiddenAdd=true:隐藏添加框且不可删除/拖拽)
- * @isAdd
- */
- isAdd: {
- type: Boolean,
- default: !0
- },
- /**
- * 文件类型
- * @accept
- */
- accept: {
- type: String,
- default: "image/*"
- },
- // 最多可上传数量(同 PictureUpload 的 maxSize)
- maxFileCount: {
- type: Number,
- default: 5
- },
- // 单文件大小上限,单位 KB(同 PictureUpload 的 fileSize)
- fileSize: {
- type: Number,
- default: 200
- },
- // FTP 上传目录(同 PictureUpload 的 path),不传时回退 businessTableName
- path: {
- type: String,
- default: void 0
- },
- // 是否隐藏拖拽排序图标(同 PictureUpload 的 noDrag)
- noDrag: {
- type: Boolean,
- default: !1
- },
- // 图片列表容器样式(同 PictureUpload 的 picStyle)
- picStyle: {
- type: Object,
- default: () => {
- }
- },
- // 兼容保留:不传 path 时作为 FTP 目录名
- businessTableName: {
- type: String,
- default: "sapit-ui-plus-components-upload"
- },
- businessKey: {
- type: String,
- default: void 0
- },
- // 兼容保留(PictureUpload 无上传列表概念,仅声明避免外部传参告警)
- showUploadList: {
- type: Boolean,
- default: !0
- },
- // 兼容保留( PictureUpload 无此概念,仅声明)
- listType: {
- type: String,
- default: "picture-card"
- },
- showRemoveIcon: {
- type: Boolean,
- default: !1
- }
- },
- emits: ["change", "handChange", "dragChange"],
- setup(o, { emit: B }) {
- const w = B, s = o, m = M(() => s.readonly), $ = () => s.path || s.businessTableName, a = r([]), g = r(!1), y = r(""), C = r(""), d = r(0);
- z(
- () => s.list,
- (l) => {
- a.value = l || [];
- },
- { immediate: !0, deep: !0 }
- );
- const b = () => {
- w("change", a.value), w("handChange", a.value);
- }, D = (l) => {
- }, A = (l) => {
- a.value && a.value.length > 1 && a.value.forEach((e, n) => {
- e.sort = n;
- }), w("dragChange", a.value), b();
- }, E = () => {
- p.value.click();
- }, p = r(null), N = (l) => {
- const e = l.target.files;
- if (e && e.length && a.value.length + e.length > s.maxFileCount) {
- window.$message.warning(window.$l("上传图片,最多可上传") + s.maxFileCount + window.$l("张"));
- return;
- }
- if (e && e.length) {
- for (let n = 0; n < e.length; n++)
- if (e[n].size > s.fileSize * 1024) {
- window.$message.warning(
- `${window.$l("上传图片大小不能大于")}${s.fileSize}KB`
- );
- return;
- }
- }
- q($(), e).then((n) => {
- if (n && n.length)
- for (let t = 0; t < n.length; t++)
- a.value.push({
- sort: t,
- imageUrl: n[t].imageUrl,
- uid: n[t].imageUrl,
- url: n[t].imageUrl
- });
- b();
- }).finally(() => {
- p.value && (p.value.value = "");
- });
- }, O = (l) => {
- l.showTool = !0;
- }, T = (l) => {
- l.showTool = !1;
- }, V = (l, e) => {
- a.value.splice(l, 1), G($(), e.imageUrl || e.uid), b();
- }, F = (l = {}) => {
- d.value = a.value.findIndex((e) => e === l), g.value = !0, C.value = l.name || window.$l("预览"), y.value = l.imageUrl || l.url;
- }, I = () => {
- g.value = !1;
- }, _ = (l) => {
- d.value = d.value + l < 0 ? 0 : d.value + l > a.value.length - 1 ? a.value.length - 1 : d.value + l;
- const e = a.value[d.value];
- e && (C.value = e.name || window.$l("预览"), y.value = e.imageUrl || e.url);
- };
- return (l, e) => {
- const n = L("s-modal");
- return c(), f("div", le, [
- o.label ? (c(), f("div", te, [
- i("div", ae, P(o.label), 1)
- ])) : h("", !0),
- v(u(H), {
- modelValue: a.value,
- "onUpdate:modelValue": e[0] || (e[0] = (t) => a.value = t),
- onStart: D,
- onEnd: A,
- handle: ".move",
- class: "img-list-wrap",
- style: R(o.picStyle),
- disabled: m.value,
- "item-key": "uid"
- }, {
- item: S(({ element: t, index: U }) => [
- (c(), f("div", {
- class: "img-item-wrap",
- key: t.uid || U,
- onMouseover: (k) => O(t),
- onMouseleave: (k) => T(t)
- }, [
- i("img", {
- class: "upload-img-wrap",
- src: t.imageUrl || t.url
- }, null, 8, ie),
- K(i("div", oe, [
- i("div", se, [
- v(u(W), {
- class: "tool-icon-wrap",
- style: { "margin-right": "8px" },
- onClick: (k) => F(t)
- }, null, 8, ["onClick"]),
- o.isAdd && !m.value ? (c(), x(u(X), {
- key: 0,
- class: "tool-icon-wrap",
- onClick: (k) => V(U, t)
- }, null, 8, ["onClick"])) : h("", !0)
- ]),
- i("div", ue, [
- o.isAdd && !m.value && !o.noDrag ? (c(), x(u(Y), { key: 0 })) : h("", !0)
- ])
- ], 512), [
- [j, t.showTool]
- ])
- ], 40, ne))
- ]),
- footer: S(() => [
- a.value.length < o.maxFileCount && o.isAdd ? (c(), f("div", {
- key: 0,
- class: "img-add-wrap",
- onClick: E
- }, [
- i("div", de, [
- v(u(Q), { class: "plus-icon" }),
- i("input", {
- accept: o.accept || "image/*",
- multiple: !0,
- type: "file",
- disabled: m.value,
- ref_key: "fileInput",
- ref: p,
- style: { display: "none" },
- onChange: N
- }, null, 40, re)
- ])
- ])) : h("", !0)
- ]),
- _: 1
- }, 8, ["modelValue", "style", "disabled"]),
- v(n, {
- value: g.value,
- "onUpdate:value": e[3] || (e[3] = (t) => g.value = t),
- title: C.value,
- onHandCancel: I,
- width: "800px"
- }, {
- default: S(() => [
- i("div", ce, [
- i("div", {
- class: "prev",
- onClick: e[1] || (e[1] = (t) => _(-1))
- }, [
- v(u(Z))
- ]),
- i("img", {
- alt: "example",
- class: "view",
- src: y.value
- }, null, 8, ve),
- i("div", {
- class: "next",
- onClick: e[2] || (e[2] = (t) => _(1))
- }, [
- v(u(ee))
- ])
- ])
- ]),
- _: 1
- }, 8, ["value", "title"])
- ]);
- };
- }
- }, we = /* @__PURE__ */ J(me, [["__scopeId", "data-v-d094bfa6"]]);
- export {
- we as default
- };
|