UNPKG

@farris/ui-vue

Version:

Farris Vue, a Farris Design based Vue3 component library.

1,659 lines (1,658 loc) 62.9 kB
var Ie = Object.defineProperty; var Ue = (t, e, n) => e in t ? Ie(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n; var j = (t, e, n) => Ue(t, typeof e != "symbol" ? e + "" : e, n); import { defineComponent as K, toRefs as fe, createVNode as l, Fragment as G, createTextVNode as F, ref as B, watch as q, inject as J, getCurrentInstance as ze, onMounted as ve, onUnmounted as me, computed as O, reactive as je, createApp as Le, Transition as qe, mergeProps as $e, provide as Ve, resolveComponent as Q, onBeforeMount as _e } from "vue"; import { resolveAppearance as Qe, createPropsResolver as Ke } from "../dynamic-resolver/index.esm.js"; import { useDateFormat as We, withInstall as Ye } from "../common/index.esm.js"; import { LocaleService as ce } from "../locale/index.esm.js"; import { useDesignerComponent as Xe } from "../designer-canvas/index.esm.js"; const Ge = { // 是否被选中 checked: { type: Boolean, default: !1 }, // 进度条状态 默认'normal' id: { type: String, default: "" }, // 禁用 disabled: { type: Boolean, default: !1 } }, Je = { // 是否显示进度条信息 showInfo: { type: Boolean, default: !0 }, // 进度条状态 默认'normal' status: { type: String, default: "normal" }, // 已完成的分段百分比 percent: { type: Number, default: 0 }, maxWidth: { type: Number, default: 0 } }, Ze = { /** * 按钮文本 */ selectText: { type: String, default: "选择文件" }, /** * 禁用 */ disabled: { type: Boolean, default: !1 }, /** * 启用多选 */ enableMulti: { type: Boolean, default: !0 }, /** * 允许上传类型 */ accept: { type: String, default: "*" }, /** * 配置对象 */ options: { type: Object, default: {} }, /** * 已上传附件个数 */ uploadedCount: { type: Number, default: 0 }, /** * 发起服务器端请求,某个组件使用的特殊的参数 */ extendConfig: { type: Object, default: {} }, /** * 附件服务器端服务注入的Token */ uploadServerToken: { type: String, default: "" } }, et = /* @__PURE__ */ K({ name: "FUploadProgress", props: Je, setup(t, e) { const { showInfo: n, status: i, maxWidth: a, percent: s } = fe(t); return () => l("div", { class: ["f-progress upload-progress", "upload-progress-status-" + i.value, "f-progress-status-" + i.value, "upload-progress-line", n.value ? "upload-progress-show-info" : ""] }, [l("div", { class: "upload-progress-outer", style: { "max-width": a.value > 0 ? a.value + "px" : "auto" } }, [l("div", { class: "upload-progress-inner" }, [l("div", { class: "upload-progress-bg f-progress-bg", style: { width: s.value + "%" } }, null)])]), n.value ? l("span", { class: "upload-progress-text" }, [i.value === "error" || i.value === "success" ? l("span", { class: ["upload-progress-text-icon f-icon", "f-icon-" + i.value] }, null) : l(G, null, [s.value, F("%")])]) : ""]); } }), Te = /* @__PURE__ */ K({ name: "FPreviewCheckbox", props: Ge, emits: ["checkedChange"], setup(t, e) { const { disabled: n } = fe(t), i = B(t.checked), a = (s) => { s.stopPropagation(), n.value || (i.value = !i.value, e.emit("checkedChange", { checked: i.value, id: t.id })); }; return q(() => t.checked, (s) => { i.value = s; }), () => l("div", { class: "preview-checkbox d-inline-flex align-middle" }, [l("div", { class: "custom-control custom-checkbox f-checkradio-single m-0" }, [l("input", { title: "custom-control-input", class: "custom-control-input", type: "checkbox", disabled: n.value, checked: i.value }, null), l("label", { class: "custom-control-label", onClick: (s) => a(s), onMousedown: (s) => s.stopPropagation() }, null)])]); } }), Ee = /* @__PURE__ */ K({ name: "FFileSelect", props: Ze, emits: ["change", "stateChange"], setup(t, e) { const n = J("uploaderService"); n.setUploadContext(e); const i = ze(), a = B("*"); let s; const d = () => { s.files && (e.emit("change", s.files), n.handleFiles(s.files), s.value = null); }; function u() { s.value = null, n.reset(); } q(() => t.disabled, () => { u(); }), q(() => t.uploadedCount, (f) => { n.setOptions({ uploadedCount: f }); }), q(() => t.extendConfig, (f) => { n.setExtendServerConfig(f); }), q(() => t.options, (f) => { n.setOptions(f); }, { deep: !0 }); function v(f) { f && f.stopPropagation(), s.click(); } function x(f) { n.handleUploadEvent(f); } return ve(() => { var f, T; s = (f = i == null ? void 0 : i.proxy) == null ? void 0 : f.$refs.uploadInput, u(), n.setOptions(t.options), n.setExtendServerConfig(t.extendConfig), a.value = (((T = t.options) == null ? void 0 : T.allowedContentTypes) || ["*"]).join(","); }), me(() => { }), e.expose({ handleUploadEvent: x }), () => l(G, null, [l("input", { ref: "uploadInput", type: "file", class: "ffileupload--browser", disabled: t.disabled, multiple: t.enableMulti, accept: a.value, onChange: () => d(), style: "width: 10px", title: "uploadInput" }, null), l("div", { class: ["upload-container", t.disabled ? "f-state-disabled" : ""], onClick: (f) => v(f), title: t.selectText }, [l("i", { class: "f-icon f-icon-upload upload-icon", style: "top: 2px;position: relative;" }, null), t.selectText])]); } }), tt = "https://json-schema.org/draft/2020-12/schema", lt = "https://farris-design.gitee.io/uploader.schema.json", nt = "uploader", it = "A Farris Component", st = "object", at = { id: { description: "The unique identifier for uploader", type: "string" }, type: { description: "The type string of uploader", type: "string", default: "uploader" }, appearance: { description: "", type: "object", properties: { class: { type: "string" }, style: { type: "string" } }, default: {} }, binding: { description: "", type: "object", default: {} }, disable: { type: "boolean", default: !1 }, placeholder: { description: "", type: "string", default: "" }, readonly: { description: "", type: "boolean", default: !1 }, tabindex: { description: "", type: "number", default: -1 }, visible: { description: "", type: "boolean", default: !0 } }, ot = [ "id", "type" ], rt = { $schema: tt, $id: lt, title: nt, description: it, type: st, properties: at, required: ot }, ut = /* @__PURE__ */ new Map([ ["appearance", Qe] ]); function dt(t, e, n) { return e; } const ct = "uploader", pt = "A Farris Component", ft = "object", vt = { basic: { description: "Basic Infomation", title: "基本信息", properties: { id: { description: "组件标识", title: "标识", type: "string", readonly: !0 }, type: { description: "组件类型", title: "控件类型", type: "select", editor: { type: "waiting for modification", enum: [] } } } }, appearance: { description: "外观", title: "外观", properties: { contentFill: { description: "内容填充", title: "内容填充", type: "boolean" } } }, server: { description: "服务器配置", title: "服务器配置", properties: { rootId: { description: "附件服务器根目录", title: "附件服务器根目录", type: "string" }, formId: { description: "必填,根据【附件信息】业务字段所在位置区分:1、在子表,二级目录建议绑定主表ID。2:在主表:二级目录建议填写当前表数据ID", title: "二级目录", type: "string" } } }, upload: { description: "上传配置", title: "上传配置", properties: { uploadVisible: { description: "上传按钮是否可见", title: "上传是否可见", type: "boolean" }, uploadDisabled: { description: "禁用时,上传按钮可见,但不可用", title: "上传是否禁用", type: "boolean" }, allowEmpty: { description: "运行时是否允许不上传附件", title: "是否允许为空", type: "boolean" }, uploadSelectText: { description: "选择文件按钮文本", title: "选择文件按钮文本", type: "string" }, uploadOptions: { description: "附件上传配置", title: "附件上传配置", type: "cascade", isExpand: !0, properties: { maxUploads: { description: "值为0时表示不限制上传个数", title: "最大上传个数", type: "number" }, maxFileSize: { description: "单个附件最大值(MB)", title: "单个附件最大值(MB)", type: "number" }, allowedContentTypes: { description: "允许上传附件类型", title: "允许上传附件类型", type: "string" }, notAllowedCharsInFileName: { description: "文件名禁用字符", title: "文件名禁用字符", type: "string" } } }, enableUploadedCount: { description: "是否启用已上传个数限制", title: "是否启用已上传个数限制", type: "select", editor: { type: "waiting for modification", enum: [] } }, uploadEnableMulti: { description: "是否启用多选附件上传", title: "是否启用多选附件上传", type: "select", editor: { type: "waiting for modification", enum: [] } }, enableSliceUpload: { description: "是否启用分片上传", title: "是否启用分片上传", type: "select", editor: { type: "waiting for modification", enum: [] } }, chunkSize: { description: "分片上传时,每片的大小。单位:M", title: "分片大小(M)", type: "number" } } }, preview: { description: "附件预览", title: "附件预览", properties: { previewVisible: { description: "预览是否可见", title: "预览是否可见", type: "boolean" }, previewReadonly: { description: "预览是否只读", title: "预览是否只读", type: "boolean" }, fieldIdKey: { description: "附件ID字段", title: "附件ID字段", type: "string", editor: { type: "field-selector" } }, fileNameKey: { description: "附件名称字段", title: "附件名称字段", type: "string", editor: { type: "field-selector" } }, previewEnableMulti: { description: "是否启用批量操作", title: "是否启用批量操作", type: "boolean" }, noDelete: { description: "是否禁止删除附件", title: "是否禁止删除附件", type: "boolean" }, noPreview: { description: "是否禁止预览", title: "是否禁止预览", type: "boolean" }, previewDateFormat: { description: "附件上传时间字段的格式化设置,请注意此属性仅针对附件上传时间一个字段,若有自定义预览列,请在预览列编辑器中单独设置时间格式。", title: "附件上传时间格式化", type: "select", editor: { type: "waiting for modification", enum: [] } }, fileSortOrderKey: { description: "排序字段", title: "排序字段", type: "string" }, orderType: { description: "排序类型", title: "排序类型", type: "select", editor: { type: "waiting for modification", enum: [] } } } } }, mt = { title: ct, description: pt, type: ft, categories: vt }, he = { /** 内容区域填充 */ contentFill: { type: Boolean, default: !1 }, /** 排序字段 */ orderField: { type: String, default: "createTime" }, previewColumns: { type: Array, default: [ { field: "name", width: 200, title: "文件名", checkbox: !0 }, { field: "size", width: 100, title: "大小" }, { field: "createTime", width: 100, title: "日期" }, { field: "state", width: 100, title: "状态" }, { field: "action", width: 100, title: "操作" } ] }, previewVisible: { type: Boolean, default: !0 }, /** 是否启用批量操作 */ previewEnableMulti: { type: Boolean, default: !0 }, /** 默认重命名 */ previewDefaultRename: { type: String, default: "" }, /** 附件上传部分禁用状态 */ uploadDisabled: { type: Boolean, default: !1 }, // 附件上传部分是否可见 uploadVisible: { type: Boolean, default: !0 }, // 需要重置,通过不断的赋值来改变 // @Input() uploadNeedReset: Observable<any> = new Subject(); /** 选择文件按钮上的文字 */ uploadSelectText: { type: String, default: "选择文件" }, /** 启用多选 */ uploadEnableMulti: { type: Boolean, default: !0 }, /** 已经上传文件 */ uploadedCount: { type: Number, default: 0 }, /** 整个控件禁用 */ disabled: { type: Boolean, default: !1 }, /** 下载按钮是否禁用 */ downloadButtonDisable: { type: Boolean, default: !1 }, /** 预览按钮是否禁用 */ previewButtonDisable: { type: Boolean, default: !1 }, /** 删除按钮是否禁用 */ deleteButtonDisable: { type: Boolean, default: !1 }, /** * 自定义展示信息 */ customInfo: { type: String, default: "" }, /** * 处理传递预览的数据 */ fileInfos: { type: Array, default: [] }, /** * 上传配置 */ uploadOptions: { type: Object, default: null }, /** * 发起服务器端请求,某个组件使用的特殊的参数 */ extendConfig: { type: Object, default: {} }, /** * 附件服务器端服务注入的Token */ uploadServerToken: { type: String, default: "" }, /** * 提示服务注入的Token */ notifyServiceToken: { type: String, default: "" } }, Be = Ke(he, rt, ut, dt, mt); var L = /* @__PURE__ */ ((t) => (t[t.Queue = 0] = "Queue", t[t.Uploading = 1] = "Uploading", t[t.Done = 2] = "Done", t[t.Cancelled = 3] = "Cancelled", t[t.Remove = 4] = "Remove", t[t.Error = 5] = "Error", t))(L || {}); class ht { constructor(e = {}, n = {}) { /** * 上传配置 */ j(this, "uploadConfig"); /** * 删除配置 */ j(this, "removeConfig"); const i = { type: "config", url: "", timeout: 0, headers: null, data: {} }; this.uploadConfig = Object.assign({}, i, e), this.removeConfig = Object.assign({}, i, n); } } function ge(t, e) { const { formatTo: n } = We(); return n(t, e); } function be(t, e) { if (!e) return ""; let n = ""; return t.indexOf(".") === -1 && e.hasOwnProperty(t) ? n = e[t] : n = t.split(".").reduce((i, a) => i ? i[a] : null, e), n; } function gt(t) { return (e, n) => { if (!e.hasOwnProperty(t) || e[t] === void 0 || e[t] === null) return 1; if (!n.hasOwnProperty(t) || n[t] === void 0 || n[t] === null) return -1; if (t !== "createTime") { let s = "", d = ""; return t.indexOf(".") > -1 ? (s = be(t, e), d = be(t, n)) : (s = e[t], d = n[t]), s > d ? 1 : -1; } const i = new Date(e[t]), a = new Date(n[t]); return i.getTime() > a.getTime() ? -1 : 1; }; } function He(t) { return (t || []).findIndex((n) => n === "*") === -1; } function De(t) { return t !== "0 Byte"; } function se(t) { if (t === 0) return "0 Byte"; const e = 1024, n = ["Bytes", "KB", "MB", "GB", "TB", "PB"], i = Math.floor(Math.log(t) / Math.log(e)); return parseFloat((t / e ** i).toFixed(2)) + " " + n[i]; } function Ae(t, e) { return t && (t.hasOwnProperty("allowedContentTypes") && (e.allowedContentTypes = t.allowedContentTypes || ["*"], e.allowedContentTypes = e.allowedContentTypes && e.allowedContentTypes.length > 0 ? e.allowedContentTypes : ["*"]), t.hasOwnProperty("maxUploads") && (e.maxUploads = t.maxUploads || 0), t.hasOwnProperty("maxFileSize") && (e.maxFileSize = se(1024 * 1024 * (parseInt(String(t.maxFileSize), 10) || 1)))), e; } function xe(t) { let e = "ffilepreview--filetype"; if (!t) return e + "-any"; const n = t.lastIndexOf("."); let i = ""; switch (n > -1 && (i = t.substring(n + 1).toLocaleLowerCase()), i) { case "pdf": e += "-pdf"; break; case "jpeg": case "jpg": case "gif": case "svg": case "png": case "bmp": e += "-img"; break; case "ppt": case "pptx": e += "-ppt"; break; case "doc": case "docx": e += "-doc"; break; case "xls": case "xlsx": e += "-xls"; break; case "txt": e += "-txt"; break; case "zip": e += "-zip"; break; case "wps": e += "-wps"; break; case "wpt": e += "-wpt"; break; default: e += "-any"; } return e; } function Ce(t) { var e; if (t.type === "done") return 100; if (t.file && t.file.progress) { if (t.file.progress.status === L.Uploading) { const n = ((e = t.file.progress.data) == null ? void 0 : e.percentage) || 5; return n > 5 ? n : 5; } return 5; } return 5; } function wt(t) { let e = t; return t ? (typeof t == "string" && (e = parseInt(t, 10)), se(e)) : "0 Byte"; } const yt = () => Math.random().toString(36).substring(7); function Fe(t, e) { return { fileIndex: e, id: yt(), name: t.name, size: t.size, type: t.type, form: new FormData(), progress: { status: L.Queue, data: { percentage: 0, speed: 0, speedHuman: `${se(0)}/s`, startTime: null, endTime: null, eta: null, etaHuman: null } }, lastModifiedDate: ge(new Date(t.lastModified), "yyyy-MM-dd HH:mm:ss"), nativeFile: t }; } function Se(t) { const e = []; return t.forEach((n) => { const i = { id: "", name: "", size: 0, type: "", extend: null, extendHeaders: null, createTime: "" }; for (const a in i) { const s = a.replace("extend", "response").replace("createTime", "lastModifiedDate"); n.hasOwnProperty(s) && (s === "lastModifiedDate" ? i[a] = ge(n[s], "yyyy-MM-dd HH:mm:ss") : i[a] = n[s]); } e.push(i); }), e; } function bt(t, e) { return t ? e <= t * 1024 * 1024 : !0; } function xt(t) { return t.find((e) => e === "*") !== void 0; } function Ct(t, e) { if (!t || t.length === 0 || xt(t)) return !0; if (e.lastIndexOf(".") < 0) return !1; const n = e.substr(e.lastIndexOf(".")); return t.findIndex( (i) => i.toLowerCase() === n.toLowerCase() ) > -1; } function Ft(t) { if (t) return t.split(` `).map((e) => e.split(/: */, 2)).filter((e) => e[0]).reduce((e, n) => (e[n[0]] = n[1], e), {}); } function ke(t) { return new Date(t * 1e3).toISOString().substr(11, 8); } class St extends ht { upload(e, n, i, a) { const s = e[0]; return new Promise((d, u) => { var M, y; const v = n.url || i.url || "", x = n.method || "POST", f = n.data || {}, T = n.headers || {}, g = new XMLHttpRequest(), D = (/* @__PURE__ */ new Date()).getTime(); let E = ((M = s.progress) == null ? void 0 : M.data) && s.progress.data.startTime || D, H = 0, w = null; g.upload.addEventListener("progress", (b) => { var A; if (b.lengthComputable) { const k = Math.round(b.loaded * 100 / b.total), z = (/* @__PURE__ */ new Date()).getTime() - D; H = Math.round(b.loaded / z * 1e3), E = ((A = s.progress) == null ? void 0 : A.data) && s.progress.data.startTime || (/* @__PURE__ */ new Date()).getTime(), w = Math.ceil((b.total - b.loaded) / H), s.progress = { status: L.Uploading, data: { percentage: k, speed: H, speedHuman: `${se(H)}/s`, startTime: E, endTime: null, eta: w, etaHuman: ke(w) } }, a({ type: "uploading", files: [s] }); } }, !1), g.upload.addEventListener("error", (b) => { u(b); }), g.onreadystatechange = () => { if (g.readyState === XMLHttpRequest.DONE) { const b = Math.round(s.size / ((/* @__PURE__ */ new Date()).getTime() - E) * 1e3); s.progress = { status: L.Done, data: { percentage: 100, speed: b, speedHuman: `${se(b)}/s`, startTime: E, endTime: (/* @__PURE__ */ new Date()).getTime(), eta: w, etaHuman: ke(w || 0) } }, s.responseStatus = g.status; try { s.response = JSON.parse(g.response); } catch { s.response = g.response; } s.responseHeaders = Ft(g.getAllResponseHeaders()), d({ type: "done", files: [s] }); } }, g.open(x, v, !0), g.withCredentials = !!n.withCredentials; try { const b = s.nativeFile; Object.keys(T).forEach((k) => g.setRequestHeader(k, T[k])); let A; n.includeWebKitFormBoundary !== !1 ? (Object.keys(f).forEach((k) => { var z; return (z = s.form) == null ? void 0 : z.append(k, f[k]); }), (y = s.form) == null || y.append(n.fieldName || "file", b, b.name), A = s.form) : A = b, g.send(A); } catch (b) { u(b); } return () => { g.abort(); }; }); } // 删除附件 remove(e, n, i, a) { return new Promise((s, d) => { s({ type: "removed", files: e }); }); } } const kt = { showCloseButton: { type: Boolean, default: !0 }, position: { type: String, default: "top-center" }, timeout: { type: Number, default: 3e3 }, theme: { type: String, default: "bootstrap" }, left: { type: Number }, right: { type: Number }, top: { type: Number }, bottom: { type: Number }, id: { type: String }, animate: { type: String, default: "fadeIn" }, options: { type: Object }, safeHtml: { type: Boolean, default: !0 } }, Tt = { showCloseButton: { type: Boolean, default: !0 }, animate: { type: String, default: "fadeIn" }, options: { type: Object } }, pe = /* @__PURE__ */ K({ name: "Toast", props: Tt, emits: ["close", "click"], setup: (t, e) => { const n = B(t.animate), i = "fadeOut", a = O(() => t.options), s = B(!1), d = O(() => a.value.title && a.value.message), u = O(() => !a.value.title && a.value.message), v = O(() => { const y = { animated: s.value, toast: !0, "toast--only-content": !d.value }; return y[t.animate] = !1, y[i] = s.value, y["toasty-type-" + a.value.type] = !0, a.value.theme && (y[a.value.theme] = !0), y; }), x = O(() => { const A = `f-icon-${a.value && a.value.type ? a.value.type.replace("toasty-type-", "") : "default"}`, k = { "f-icon": !0 }; return k[A] = !0, k; }), f = O(() => a.value.title || a.value.message), T = O(() => t.showCloseButton), g = O(() => !!a.value.buttons || !!e.slots.default), D = O(() => ce.getLocale() === "en" ? { wordBreak: "keep-all", overflowWrap: "break-word" } : {}); function E(y) { y.stopPropagation(), y.preventDefault(), s.value = !1, setTimeout(() => { e.emit("close", a.value); }, 200); } function H(y, b) { } function w(y) { return `f-preten-link ${y.customClass ? y.customClass : ""}`; } q(n, () => { n.value; }); const M = () => { var y; return l(G, null, [l("div", { class: "after-toast-msg text-right" }, [!e.slots.default && ((y = a.value.buttons) == null ? void 0 : y.map((b) => l("span", { class: w(b), onClick: (A) => void 0 }, [b.text]))), e.slots.default && e.slots.default()])]); }; return () => l("div", { class: v.value, style: "min-height:44px" }, [T.value && l("button", { title: ce.getLocaleValue("messageBox.close"), class: "toast-close f-btn-icon f-bare", onClick: E }, [l("span", { class: "f-icon modal_close" }, null)]), f.value && l("section", { class: "modal-tips" }, [!d.value && l("div", { class: "float-left modal-tips-iconwrap" }, [l("span", { class: x.value }, null)]), l("div", { class: "modal-tips-content" }, [d.value && l(G, null, [l("h5", { class: "toast-title modal-tips-title", innerHTML: a.value.title }, null), l("p", { class: "toast-msg", innerHTML: a.value.message, style: D.value }, null), g.value && M()]), u.value && (a.value.buttons ? l("div", { class: "toast-title-btns-wrapper d-flex" }, [l("h5", { class: "toast-title modal-tips-title only-toast-msg", style: D.value, innerHTML: a.value.message }, null), l("div", { class: "after-toast-title text-right ml-auto" }, [M()])]) : l("h5", { class: "toast-title modal-tips-title only-toast-msg", style: D.value, innerHTML: a.value.message }, null))])])]); } }), re = /* @__PURE__ */ K({ name: "Notify", props: kt, emits: ["close", "empty"], setup(t, e) { const n = O(() => ({ "farris-notify": !0 })), i = { left: 12, right: 12, top: 20, bottom: 12 }, a = B(), s = B(t.options), d = B(t.showCloseButton), u = O(() => t.position || "bottom-right"), v = O(() => t.timeout != null ? t.timeout : 3e3), x = O(() => { const g = t.bottom ? t.bottom : i.bottom, D = t.top ? t.top : i.top, E = { transition: "all 0.2s ease", left: u.value.indexOf("left") > -1 ? `${t.left ? t.left : i.left}px` : "", right: u.value.indexOf("right") > -1 ? `${t.right ? t.right : i.right}px` : "", top: u.value.indexOf("top") > -1 ? `${D}px` : "", bottom: u.value.indexOf("bottom") > -1 ? `${g}px` : "" }; return u.value.indexOf("center") > -1 && (E.left = "50%", E.marginLeft = "calc(-24rem / 2)", u.value === "center-center" && (E.top = "50%", E.transform = "translate(-50%, -50%)")), E; }); function f(g) { e.emit("close"); } v.value && setTimeout(() => { f(); }, v.value), e.expose({ closeToast: f, container: a, notifyPosition: u }); function T(g, D) { f(); } return () => l("div", { class: n.value, style: x.value, ref: a }, [l(pe, { options: s.value, showCloseButton: d.value, animate: t.animate, onClose: (g) => T(g, s.value) }, null)]); } }); class Me { constructor() { j(this, "notifyRefs", []); j(this, "globalConfig", je({})); } escapeAllHtml(e) { if (typeof e != "string" || !e) return ""; const n = document.createElement("div"); return n.textContent = e || "", n.innerHTML.replace(/\\n/g, "<br>").replace(/\\t/g, "&nbsp;&nbsp;&nbsp;&nbsp;").replace(/\\r/g, ""); } createNotifyInstance(e) { const n = this, a = Object.assign({ timeout: 3e3, position: "bottom-right", showCloseButton: !0, safeHtml: !0 }, this.globalConfig, { ...e }), s = document.createElement("div"); s.style.display = "contents"; const d = Le({ setup() { var x; const u = B(); function v() { u.value.container.style.transform = "scale(0)", setTimeout(() => { n.updateNotifyPositionForClose(a, u), d.unmount(); }, 220); } if (a.position.indexOf("top") > -1) { const f = n.getNotifyInstances(a.position), T = f[f.length - 1]; if (T) { const g = T.value.container.getBoundingClientRect(); a.top = g.bottom; } } return a.safeHtml && ((x = a.options) != null && x.message) && (a.options.message = n.escapeAllHtml(a.options.message)), me(() => { document.body.removeChild(s); }), ve(() => { n.updateNotifyPositionForCreate(a, u); }), () => l(qe, { mode: "out-in", name: "fade", appear: !0 }, { default: () => [l(re, $e({ ref: u }, a, { onClose: v }), null)] }); } }); return d.provide("NotifyService", this), document.body.appendChild(s), d.use(ce.i18n), d.mount(s), d; } getNotifyInstances(e) { return this.notifyRefs.filter((n) => n.value.notifyPosition === e); } updateNotifyPositionForCreate(e, n) { if (this.notifyRefs && this.notifyRefs.length) { const i = window.innerHeight; e.position.indexOf("bottom") > -1 && this.getNotifyInstances(e.position).forEach((a) => { const s = a.value.container.getBoundingClientRect(); a.value.container.style.bottom = s.height + i - s.bottom + "px"; }); } this.notifyRefs = [...this.notifyRefs, n]; } updateNotifyPositionForClose(e, n) { const i = this.notifyRefs.indexOf(n); if (e.position.indexOf("top") > -1) { const a = this.getNotifyInstances(e.position), s = a.indexOf(n); a.slice(s + 1).forEach((d) => { d.value.container.style.top = d.value.container.offsetTop - d.value.container.offsetHeight + "px"; }); } i > -1 && this.notifyRefs.splice(i, 1); } show(e) { return this.createNotifyInstance(e); } buildNotifyProps(e, n) { let i = "", a = "", s, d, u; typeof n == "string" ? i = n : n && (i = n.message || "", a = n.title || "", d = n.position || null, u = n.showCloseButton != null ? n.showCloseButton : null, s = n.timeout != null ? n.timeout : null); const x = { options: { type: e, message: i, title: a } }; return d != null && (x.position = d), u != null && (x.showCloseButton = u), s != null && (x.timeout = s), x; } info(e) { const n = this.buildNotifyProps("info", e); return this.show(n); } success(e) { const n = this.buildNotifyProps("success", e); return this.show(n); } warning(e) { const n = this.buildNotifyProps("warning", e); return this.show(n); } error(e) { const n = this.buildNotifyProps("error", e); return this.show(n); } close(e) { e && e.unmount(); } closeAll() { this.notifyRefs.forEach((e) => { e == null || e.value.closeToast(); }), this.notifyRefs.length = 0; } } const Et = Symbol("NOTIFY_SERVICE_TOKEN"); re.install = (t) => { t.component(re.name, re), t.component(pe.name, pe); const e = new Me(); t.provide(Et, e), t.provide("FNotifyService", e); }; const Bt = (t = "") => { let e; return t && J(t, null) && (e = J(t)), e || (e = new Me()), e; }, Ht = (t = "") => { let e; if (t && J(t, null)) { const n = J(t); n && n() && (e = n()); } return e || (e = new St()), e; }, Pe = { getNotify: Bt, getServerAPI: Ht }; function Oe(t, e, n) { const i = Pe.getNotify(t.notifyServiceToken), a = B(t.fileInfos), { disabled: s, uploadVisible: d, uploadDisabled: u, previewVisible: v, orderField: x, previewEnableMulti: f, downloadButtonDisable: T, previewColumns: g, uploadEnableMulti: D, previewButtonDisable: E } = fe(t), H = B(!1), w = B([]), M = O(() => w.value.length), y = B([]), b = B(""); function A(o) { (!o.length || w.value.length !== o.length) && (H.value = !1); const h = [...o.map((C) => (C.hasOwnProperty("size") || (C.size = void 0), C.hasOwnProperty("createTime") || (C.createTime = void 0), f.value && (C.checked = !!w.value.find((R) => R.id === C.id) || H.value), C))]; return h.sort(gt(x.value)), f.value && (w.value = [...h].filter((C) => C.checked)), h; } const k = B(A(a.value)); q(() => t.fileInfos, (o) => { k.value = A(o); }); const z = (o, c) => { o.stopImmediatePropagation(), e.emit("fileDownloadEvent", { fileInfos: [c], name: "" }); }, Z = (o, c) => { o.stopImmediatePropagation(), !E.value && e.emit("filePreviewEvent", c); }, ee = (o, c, h) => { c.checked && (w.value = w.value.filter((C) => C.id !== c.id)), e.emit("fileRemoveEvent", c), h.handleUploadEvent({ type: "remove", file: c }); }, te = (o, c = "preview") => o.formatter ? !0 : c === "preview" ? ["state", "name", "action", "size", "createTime"].findIndex((C) => C === o.field) > -1 : c === "upload" ? ["state", "name", "size"].findIndex((C) => C === o.field) > -1 : !1, W = (o) => !(o.field === "state" && (u.value || !d.value)), Y = (o) => o.lastIndexOf(".") > 0 ? o.substring(0, o.lastIndexOf(".")) : "", le = (o) => { if (o.stopImmediatePropagation(), M.value > 1) { let c = ""; c = Y(w.value[0].name), e.emit("fileDownloadEvent", { fileInfos: w.value, name: c }); } }, $ = (o) => { o.stopImmediatePropagation(), e.emit("fileRemoveEvent", w.value); }, ne = (o) => { const c = k.value; o.checked ? (c.forEach((h) => { h.checked = !0; }), w.value = [...k.value], H.value = !0) : (w.value = [], c.forEach((h) => { h.checked = !1; }), H.value = !1), e.emit("previewMultiSelectedEvent", w.value); }, V = (o, c) => { o && (o.stopImmediatePropagation(), o.stopPropagation()), (!b.value || c.id !== b.value) && (b.value = c.id, e.emit("selectedEvent", c)); }, m = (o) => { const c = w.value.findIndex((R) => R.id === o.id), h = c > -1, C = k.value.find((R) => R.id === o.id); C && (C.checked = o.checked), o.checked && !h && C && w.value.push(C), !o.checked && h && w.value.splice(c, 1), k.value.length > 0 && (w.value.length === k.value.length ? H.value = !0 : H.value = !1), V(null, C), e.emit("previewMultiSelectedEvent", w.value); }, N = (o) => { var c; (c = n == null ? void 0 : n.value) == null || c.handleUploadEvent(o); }, ie = (o) => { N({ type: "upload", file: o }); }, U = (o, c) => { let h = []; o.files && o.files.length > 0 ? h = o.files : typeof o.file < "u" && (h = [o.file]), c = c || o.type, h.map((C) => { const R = y.value.findIndex((_) => { var oe; return typeof C < "u" && ((oe = _ == null ? void 0 : _.file) == null ? void 0 : oe.id) === C.id; }); R > -1 && (y.value[R] = { type: c, file: C }); }); }, X = (o) => { if (o.files) { const c = o.files.map((h) => h.id); y.value = y.value.filter((h) => !(c.findIndex((R) => { var _; return R === ((_ = h == null ? void 0 : h.file) == null ? void 0 : _.id); }) > -1)), N({ type: "hide", id: c.join(",") }); } }, ae = (o) => { let c = "warning"; (o.type === "cancelled" || o.type === "removed") && (c = "success"); const h = o.hasOwnProperty("message") ? o.message : ""; i.show({ options: { type: c, message: h }, position: "top-center" }); }, de = (o) => { if (o.type === "addedToQueue" && typeof o.file < "u") y.value.push({ type: o.type, file: o.file }), ie(o.file); else if (o.type === "start") U(o, "start"); else if (o.type === "done") { U(o, "done"); const c = (o.files || []).map((h) => ({ checked: !1, id: h.id, name: h.name, size: h.size, createTime: ge(/* @__PURE__ */ new Date(), "yyyy-MM-dd HH:mm:ss") })); a.value = [...c, ...k.value], X(o), e.emit("fUploadDoneEvent", Se(o.files || [])), e.emit("uploadDoneEvent", Se(o.files || [])); } else if (o.type === "cancelled" || o.type === "removed" || o.type === "error") { const c = a.value.filter((h) => o.files && o.files.findIndex((C) => h.id === C.id) < 0); a.value = [...c], ae(o); } else o.type === "rejected" && typeof o.file < "u" && ae(o); }; return me(() => { }), { disabled: s, uploadVisible: d, uploadDisabled: u, downloadButtonDisable: T, previewVisible: v, previewColumns: g, uploadFiles: y, innerFileInfos: k, previewEnableMulti: f, previewMultiSelectedLength: M, previewSelectAllBtnChecked: H, uploadEnableMulti: D, previewCurrentId: b, multiFileRemoveHandler: $, previewMultiSelectChangeHandler: m, fileMultiDownloadHandler: le, selectOrCancelAllHandler: ne, hasColumnHtmlFunc: te, showPreviewStateColumn: W, rowSelectedHandler: V, fileDownloadHandler: z, filePreviewHandler: Z, fileRemoveHandler: ee, handleStateChange: de }; } class Dt { constructor(e, n) { // 记录在上传的附件数组 j(this, "queue"); j(this, "uploadOpts", { // 默认不限制,0代表不限制 Number.POSITIVE_INFINITY allowedContentTypes: ["*"], maxUploads: 0, /** 单位M,默认是12M,0代表不限制 */ maxFileSize: 12, concurrency: Number.POSITIVE_INFINITY, uploadedCount: 0 }); /** * 服务器端扩展 */ j(this, "extendServerConfig", null); j(this, "uploadServerSer"); j(this, "uploadContext", null); this.stateChangeRecord = e, this.serverToken = n, this.queue = [], this.uploadServerSer = Pe.getServerAPI(this.serverToken); } setUploadContext(e) { this.uploadContext = e; } /** * 处理从服务器端返回的结果 */ handleResultFromServer(e) { var n, i; switch (e.type) { case "removed": this.queue = this.queue.filter( (a) => { var s; return ((s = a.progress) == null ? void 0 : s.status) !== L.Remove; } ), e.hasOwnProperty("message") || (e.message = "被删除"), this.stateChangeRecord.value = e; break; case "error": this.queue = this.queue.filter((a) => e.files && e.files.findIndex((s) => a.id === s.id) < 0), (n = this.uploadContext) == null || n.emit("stateChange", e); break; default: (i = this.uploadContext) == null || i.emit("stateChange", e); } } setOptions(e) { e && (this.uploadOpts = Object.assign(this.uploadOpts, e)); } /** * 处理上传的附件信息 * @param incomingFiles */ handleFiles(e) { var i; const n = Array.from(e).reduce( (a, s, d) => { var x; const u = a.length + this.queue.length + 1, v = this.rejectedReason( s.name, u, s.size ); if (v.allowed) a = a.concat(s); else { const f = Fe( s, d ); (x = this.uploadContext) == null || x.emit("stateChange", { type: "rejected", file: f, message: v.message }); } return a; }, [] ); [].map.call(n, (a, s) => { var u; const d = Fe(a, s); this.queue.push(d), (u = this.uploadContext) == null || u.emit("stateChange", { type: "addedToQueue", file: d }); }), (i = this.uploadContext) == null || i.emit("stateChange", { type: "allAddedToQueue" }); } /** * 获取上传被拒绝的理由 * @param name * @param queuelength * @param size * @returns */ rejectedReason(e, n, i) { let a = !1, s = ""; return this.queue.findIndex((u) => u.name === e) > -1 ? s = "上传失败:已存在同名文件" : this.uploadOpts.allowedContentTypes && !Ct(this.uploadOpts.allowedContentTypes, e) ? s = `上传失败:只允许上传${this.uploadOpts.allowedContentTypes.join(",")}类型的文档` : this.exceedMaxUpload(n) ? s = `上传失败:文件总个数超出${this.uploadOpts.maxUploads}限制` : bt(this.uploadOpts.maxFileSize, i) ? i === 0 ? s = "上传失败:不允许文件为空" : a = !0 : s = `上传失败:单个文件大小超出${this.uploadOpts.maxFileSize}MB的限制`, { allowed: a, message: s }; } /** * 超出最大上传数值 * @param queuelength * @returns */ exceedMaxUpload(e = 0) { if (!this.uploadOpts || !this.uploadOpts.maxUploads) return !1; const n = this.uploadOpts.uploadedCount || 0; return this.uploadOpts.maxUploads > 0 && (this.uploadOpts.maxUploads <= n || e + n > this.uploadOpts.maxUploads); } /** * 从前端传来事件,进行服务器端方法类型判断 * @param input */ handleUploadEvent(e) { var n, i; switch (e.type) { case "upload": const a = this.queue.findIndex( (u) => u === e.file ); a !== -1 && e.file && this.serverMethod({ files: [this.queue[a]], event: e }); break; case "remove": if (!((n = e == null ? void 0 : e.file) != null && n.id)) return; const s = this.queue.findIndex( (u) => { var v; return u.id === ((v = e == null ? void 0 : e.file) == null ? void 0 : v.id); } ); if (s !== -1 && this.queue[s] && this.queue[s].progress) { const { progress: u } = this.queue[s]; u && (u.status = L.Remove); } this.serverMethod({ files: [e.file], event: e }); break; case "removeAll": const d = this.queue.filter( (u) => { var v; return ((v = u == null ? void 0 : u.progress) == null ? void 0 : v.status) === L.Queue; } ); d.length && ((i = this.uploadContext) == null || i.emit("stateChange", { type: "cancelled", files: d, message: "删除附件成功" }), this.queue = this.queue.filter( (u) => { var v; return ((v = u == null ? void 0 : u.progress) == null ? void 0 : v.status) !== L.Queue; } )), this.queue.length && (e.type = "remove", this.queue.forEach((u) => { u.progress && (u.progress.status = L.Remove); }), this.serverMethod({ files: this.queue, event: e })); break; } } /** * 处理上传的扩展参数 * @param extendSer */ setExtendServerConfig(e) { this.extendServerConfig = e; } /** * 处理服务器接口的方法 * @param upload * @returns */ serverMethod(e) { let n; switch (e.event.type) { case "upload": n = this.upload(e.files, e.event, (i) => this.handleResultFromServer(i)); break; case "removeAll": case "remove": n = this.remove(e.files, e.event, (i) => this.handleResultFromServer(i)); break; default: n = null; } n && n.then((i) => { this.handleResultFromServer(i); }).catch((i) => { this.handleResultFromServer(i); }); } /** * 上传附件 * @param files * @param event * @returns */ upload(e, n, i) { var a; return (a = this.uploadContext) == null || a.emit("stateChange", { type: "start", files: e }), this.uploadServerSer.upload(e, n, this.extendServerConfig, i); } /** * 删除附件 * @param files * @param event * @returns */ remove(e, n, i) { return this.uploadServerSer.remove(e, n, this.extendServerConfig, i); } /** * 重置 */ reset() { this.queue = []; } /** * 销毁 */ destroyed() { this.reset(); } } const ue = /* @__PURE__ */ K({ name: "FUploader", components: { "f-upload-progress": et, "f-preview-checkbox": Te, "f-file-select": Ee }, props: he, emits: ["filePreviewEvent", "fileDownloadEvent", "previewMultiSelectedEvent", "selectedEvent", "fileRemoveEvent", "fileRemovedEvent", "fUploadDoneEvent", "uploadDoneEvent"], setup(t, e) { const n = B(), i = new Dt(n, t.uploadServerToken); Ve("uploaderService", i); const a = B(t.customInfo); function s() { return Ae(t.uploadOptions, { // 允许上传的文件类型 allowedContentTypes: ["*"], // 默认不限制附件上传个数 maxUploads: 0, // 单位KB,默认是12M maxFileSize: "12MB" }); } const d = B(s()), u = B(null); q(() => t.uploadOptions, () => { d.value = s(); }, { deep: !0 }); const { disabled: v, uploadVisible: x, uploadDisabled: f, downloadButtonDisable: T, previewVisible: g, previewColumns: D, uploadFiles: E, innerFileInfos: H, previewEnableMulti: w, previewMultiSelectedLength: M, previewSelectAllBtnChecked: y, uploadEnableMulti: b, previewCurrentId: A, multiFileRemoveHandler: k, previewMultiSelectChangeHandler: z, fileMultiDownloadHandler: Z, selectOrCancelAllHandler: ee, rowSelectedHandler: te, hasColumnHtmlFunc: W, showPreviewStateColumn: Y, fileDownloadHandler: le, filePreviewHandler: $, fileRemoveHandler: ne, handleStateChange: V } = Oe(t, e, u); q(n, (r) => { switch (V(r), r.type) { case "removed": e.emit("fileRemovedEvent", r.files[0]); break; } }); const m = O(() => H.value.length > 0); function N() { var r; return He(d.value.allowedContentTypes || []) ? l("li", null, [l("span", null, [F("支持类型:")]), l("span", { class: "support-info--item-detail", style: "margin-right:4px;" }, [(r = d.value.allowedContentTypes) == null ? void 0 : r.join(""), F(",")])]) : ""; } function ie() { return De(d.value.maxFileSize || "") ? l("li", null, [l("span", null, [F("单个文件限制:")]), l("span", { class: "support-info--item-detail" }, [d.value.maxFileSize, F(",   ")])]) : ""; } function U() { return (d.value.maxUploads || 0) > 0 && l("li", null, [l("span", null, [F("文件总数限制:")]), l("span", { class: "support-info--item-detail" }, [d.value.maxUploads, F("个")])]); } function X() { return x.value && !f.value && !v.value ? l("div", { class: "ffileupload--support-info" }, [a.value ? l("ul", { class: "support-info--wrapper" }, [l("li", null, [l("span", { class: "support-info--item-detail", innerHTML: a.value }, null)])]) : l("ul", { class: "support-info--wrapper" }, [N(), ie(), U()])]) : null; } function ae(r) { var p, S, I; return l("div", { class: "uploadAndpreview--title-container" }, [l("div", { class: "ffilepreview--item-icon" }, [l("span", { class: ["ffilepreview--filetype-icon", xe(((p = r.file) == null ? void 0 : p.name) || "")] }, null)]), l("div", { class: "uploadAndpreview--right" }, [l("a", { class: "item-content--title", title: (S = r.file) == null ? void 0 : S.name }, [((I = r.file) == null ? void 0 : I.name) || "无名称"]), l(Q("f-upload-progress"), { status: r.type === "done" ? "success" : "active", percent: Ce(r), maxWidth: 300 }, null)])]); } function de(r) { return l("div", { class: "uploadAndpreview--title-container" }, [l("div", { class: "ffilepreview--item-icon" }, [l("span", { class: ["ffilepreview--filetype-icon", xe(r.name)] }, null)]), l("div", { class: "uploadAndpreview--right" }, [l("a", { class: ["item-content--title", "previewButtonDisable.value?'no-preview':''"], title: r.name, onClick: (p) => $(p, r) }, [r.name])])]); } function o(r, p, S) { return l("div", { class: "uploadAndpreview--filesize-container" }, [r === "preview" && S ? l("span", null, [wt(S.size)]) : null, r === "upload" && p ? l("span", null, [Ce(p)]) : null]); } function c(r, p) { return p && p.type === "error" ? l("div", { class: "uploadAndpreview--state-container" }, [l("p", { class: "upload-state--uploaded" }, [l("i", { class: "f-icon f-icon-message_warning text-danger" }, null), l("span", null, [F("存在异常")])])]) : l("div", { class: "uploadAndpreview--state-container" }, [r === "upload" ? p && p.type !== "done" ? l("p", { class: "upload-state--uploading" }, [l("i", { class: "f-icon f-icon-clock text-warning" }, null), l("span", null, [F("正在上传...")])]) : l("p", { class: "upload-state--uploaded" }, [l("i", { class: "f-icon f-icon-success text-success" }, null), l("span", null, [F("上传成功")])]) : r === "preview" ? l("p", { class: "upload-state--uploaded" }, [l("i", { class: "f-icon f-icon-success text-success" }, null), l("span", null, [F("已上传")])]) : ""]); } function h(r) { return l("div", { class: "uploadAndpreview--action-container" }, [T.value ? "" : l("button", { class: "btn preview-btn", title: "下载", onClick: (p) => le(p, r) }, [l("span", { class: "f-icon f-icon-enclosure_download" }, null)]), t.previewButtonDisable ? "" : l("button", { class: "btn preview-btn", title: "预览", onClick: (p) => $(p, r) }, [l("span", { class: "f-icon f-icon-enclosure_browse" }, null)]), t.deleteButtonDisable ? "" : l("button", { class: "btn preview-btn", title: "删除", onClick: (p) => ne(p, r, i) }, [l("span", { class: "f-icon f-icon-enclosure_delete", style: "top: -1px" }, null)])]); } function C(r) { return l("div", { class: "uploadAndpreview--date-container" }, [r.createTime || ""]); } function R(r, p, S, I) { let P; if (r = r || "preview", I.formatter) return P = I.formatter(S[I.field] || "", r, r === "preview" ? S : p, I), P; if (r === "preview" && S) switch (I.field) { case "state": P = c("preview", null); break; case "name": P = de(S); break; case "action": P = h(S); break; case "size": P = o(r, p, S); break; case "createTime": P = C(S); break; default: P = `<div>${S[I.field] || ""} </div>`; } if (r === "upload" && p) switch (I.field) { case "state": P = c("upload", p); break; case "name": P = ae(p); break; case "size": P = o(r, p, S); break; default: P = ""; } return P; } function _() { return x.value ? l("div", { class: "header--left-container" }, [l(Q("f-file-select"), { ref: u, disabled: f.value, selectText: t.selectText, uploadedCount: t.uploadedCount, uploadServerToken: t.uploadServerToken, enableMulti: b.value, options: d.value, extendConfig: t.extendConfig, onStateChange: (r) => V(r) }, null)]) : null; } function oe() { return !x.value && g.value && m.value ? l("div", { class: "header--left-container header--countInfo" }, [l("p", { class: "m-0" }, [F("共"), l("span", { class: "count" }, [E.value.length + H.value.length]), F("个附件"), M.value > 0 ? l(G, null, [F("(已选"), l("span", { class: "count-selected"