UNPKG

epic-designer-gold

Version:

基于vue3的设计器,可视化开发页面表单

94 lines (93 loc) 2.89 kB
import { defineComponent as k, useAttrs as E, ref as i, watch as d, computed as N, openBlock as m, createElementBlock as f, createVNode as g, unref as v, normalizeProps as B, guardReactiveProps as j, withCtx as A, createElementVNode as h, createCommentVNode as I, nextTick as z } from "vue"; import { Upload as L, Image as R, message as u } from "ant-design-vue"; const T = { class: "epic-upload-image" }, $ = { key: 0 }, F = /* @__PURE__ */ k({ __name: "uploadImage", props: { modelValue: { type: Array, default: () => [] }, maxCount: { type: Number } }, emits: ["update:modelValue", "change"], setup(x, { emit: V }) { const _ = E(), n = x, s = V, t = i([]), a = i(""), p = i(!1), c = (e) => { p.value = e; }; d(t, (e) => { s("update:modelValue", e), s("change", e); }), d( () => n.modelValue, (e) => { if (e != null && e.length > 0 && t.value != null) { if (t.value === e) return; t.value.length = 0, t.value.push(...e); } }, { deep: !0, immediate: !0 } ); function C(e) { z(() => { t.value = e; }); } const b = (e) => { var l, r; if (e.file.status !== "uploading") { if (e.file.status === "done") { const o = (r = (l = e.file.response) == null ? void 0 : l.data) == null ? void 0 : r.url; if (!e.file.url && !o) { e.file.status = "error", u.error("上传失败"); return; } e.file.url = o, e.file.thumbUrl = o; } e.file.status === "error" && u.error("upload error"); } }, w = (e) => { }, y = N(() => ({ ..._, "list-type": "picture-card", accept: "image/gif,image/jpeg,image/jpg,image/png,image/svg", "onUpdate:file-list": C, "file-list": t.value, "onBefore-upload": w, onChange: b, onPreview: U })); function U(e) { e.url && (a.value = e.url, c(!0)); } function P() { a.value && u.error("图片地址无法访问!"); } return (e, l) => (m(), f("div", T, [ g(v(L), B(j(y.value)), { default: A(() => { var r; return [ (((r = t.value) == null ? void 0 : r.length) ?? 0) < (n.maxCount ?? 999) ? (m(), f("div", $, l[0] || (l[0] = [ h("span", { class: "icon--epic icon--epic--cloud-upload-outlined mr-2px text-lg text-$epic-text-main" }, null, -1), h("div", { class: "ant-upload-text" }, "点击上传", -1) ]))) : I("", !0) ]; }), _: 1 }, 16), g(v(R), { style: { display: "none" }, src: a.value, preview: { visible: p.value, onVisibleChange: c }, onError: P }, null, 8, ["src", "preview"]) ])); } }); export { F as default };