UNPKG

quick-admin-vue3-core

Version:

以快(计算机执行效率、开发效率)为核心的后台管理系统开发模板

144 lines (143 loc) 4.64 kB
import { defineComponent as j, mergeDefaults as k, inject as C, ref as f, computed as w, resolveComponent as g, createBlock as P, openBlock as D, createSlots as I, withCtx as p, createVNode as y, unref as M, createElementVNode as R, normalizeClass as N, toDisplayString as A } from "vue"; import { v as O, am as q, c as G, b as v } from "./platform-DsTwHxm6.js"; import { n as H } from "./index-D-KS7NhM.js"; import { _ as J } from "./_plugin-vue_export-helper-CHgC5LLL.js"; function b(t) { return t.split(",").map((o) => o.split(/[\/.]/)[1]).join(","); } function B(t, s = 0) { const o = t / 1024; return o < 1024 ? `${o.toFixed(s)}kb` : `${(o / 1024).toFixed(s)}M`; } function K(t) { const { accept: s, limitSize: o } = t, l = b(s), r = B(o); return `仅支持${l}格式,且不超过${r}`; } function Q(t, s) { return t.split(",").map((l) => l.split(/[\/.]/)[1]).includes(s.split("/")[1]) ? "" : `仅支持上传${b(t)}格式的文件`; } function W(t, s, o = !0) { return !o && s === 0 ? "文件内容不能为空" : s <= t ? "" : `文件大小不能超过 ${B(t)}`; } function X(t, s) { const { limitSize: o, accept: l, allowEmpty: r } = t, { type: u, size: c } = s; return Q(l, u) || W(o, c, r); } var F; const Y = /* @__PURE__ */ j({ __name: "BaseUpload", props: /* @__PURE__ */ k({ modelValue: {}, fit: {}, drag: { type: Boolean }, circle: { type: Boolean }, accept: {}, limitSize: {}, action: {}, listType: {}, limit: {}, tips: {}, disabled: { type: Boolean }, showFileList: { type: Boolean }, allowEmpty: { type: Boolean }, handleSuccessResponse: { type: Function } }, { modelValue: "", action: "#", accept: "image/png,image/jpg,image/jpeg", listType: "picture-card", limit: 1, limitSize: 1024 * 1024 * 10, //10M tips: (t) => K(t), showFileList: (t) => t.limit > 1, // drag: true, allowEmpty: !0, ...(F = G) == null ? void 0 : F.BaseUpload }), emits: ["update:modelValue", "success", "error"], setup(t, { emit: s }) { const o = t, l = s, r = C("openPopup"), u = f(0), { formItem: c } = O(), h = w(() => q().value ?? o.disabled), T = f(""), d = f([]), L = w({ get: () => o.modelValue, set(e) { l("update:modelValue", e), c == null || c.validate("blur"); } }), S = (e) => { const i = X(o, e); return i ? (v(i, "error"), !1) : !0; }, z = (e) => { const { loaded: i, total: a } = e; u.value = Math.floor(i / a * 100); }, _ = (e, i) => { const { handleSuccessResponse: a } = o; a == null || a(e, i).then((n) => { L.value = n, l("success", n); }).catch((n) => { v(n, "error"); }); }, U = (e, i, a) => { v("文件上传失败", "error"), l("error", e), T.value = URL.createObjectURL(i.raw); }, V = (e) => { r("图片预览", ["img", { src: e.url, wFull: !0, alt: "图片预览" }]); }, $ = (e, i) => { console.log(e, i); }; return (e, i) => { const a = g("el-icon"), n = g("BaseImg"), E = g("el-upload"); return D(), P(E, { class: "base-upload", "data-circle": e.circle, "file-list": d.value, "onUpdate:fileList": i[0] || (i[0] = (m) => d.value = m), accept: e.accept, "before-upload": S, "on-progress": z, "on-success": _, "on-error": U, "on-preview": V, "on-remove": $, action: e.action, listType: e.listType, limit: e.limit, drag: e.drag, disabled: h.value, "show-file-list": e.showFileList }, I({ default: p(() => [ y(a, { class: "icon-add" }, { default: p(() => [ y(M(H)) ]), _: 1 }) ]), _: 2 }, [ e.showFileList ? void 0 : { name: "file", fn: p(({ file: m }) => [ y(n, { class: "img", src: m.url, fit: e.fit, preview: h.value }, null, 8, ["src", "fit", "preview"]) ]), key: "0" }, e.tips ? { name: "tip", fn: p(() => [ R("div", { class: N(["tips", { "mt-h": !e.showFileList || !d.value.length }]) }, A(e.tips), 3) ]), key: "1" } : void 0 ]), 1032, ["data-circle", "file-list", "accept", "action", "listType", "limit", "drag", "disabled", "show-file-list"]); }; } }), oe = /* @__PURE__ */ J(Y, [["__scopeId", "data-v-1e4fb544"]]); export { oe as default };