211 lines
6.5 KiB
JavaScript
211 lines
6.5 KiB
JavaScript
import VueDraggable from "vuedraggable";
|
|
import { LicenseMixin, UNAUTHORIZED_TIP } from "../utils/license-util";
|
|
import ImageItem from "./components/image-item";
|
|
import props from "./props";
|
|
function normalizeComponent(scriptExports, render2, staticRenderFns, functionalTemplate, injectStyles, scopeId, moduleIdentifier, shadowMode) {
|
|
var options = typeof scriptExports === "function" ? scriptExports.options : scriptExports;
|
|
if (render2) {
|
|
options.render = render2;
|
|
options.staticRenderFns = staticRenderFns;
|
|
options._compiled = true;
|
|
}
|
|
if (functionalTemplate) {
|
|
options.functional = true;
|
|
}
|
|
if (scopeId) {
|
|
options._scopeId = "data-v-" + scopeId;
|
|
}
|
|
var hook;
|
|
if (moduleIdentifier) {
|
|
hook = function(context) {
|
|
context = context || this.$vnode && this.$vnode.ssrContext || this.parent && this.parent.$vnode && this.parent.$vnode.ssrContext;
|
|
if (!context && typeof __VUE_SSR_CONTEXT__ !== "undefined") {
|
|
context = __VUE_SSR_CONTEXT__;
|
|
}
|
|
if (injectStyles) {
|
|
injectStyles.call(this, context);
|
|
}
|
|
if (context && context._registeredComponents) {
|
|
context._registeredComponents.add(moduleIdentifier);
|
|
}
|
|
};
|
|
options._ssrRegister = hook;
|
|
} else if (injectStyles) {
|
|
hook = shadowMode ? function() {
|
|
injectStyles.call(
|
|
this,
|
|
(options.functional ? this.parent : this).$root.$options.shadowRoot
|
|
);
|
|
} : injectStyles;
|
|
}
|
|
if (hook) {
|
|
if (options.functional) {
|
|
options._injectStyles = hook;
|
|
var originalRender = options.render;
|
|
options.render = function renderWithStyleInjection(h, context) {
|
|
hook.call(context);
|
|
return originalRender(h, context);
|
|
};
|
|
} else {
|
|
var existing = options.beforeCreate;
|
|
options.beforeCreate = existing ? [].concat(existing, hook) : [hook];
|
|
}
|
|
}
|
|
return {
|
|
exports: scriptExports,
|
|
options
|
|
};
|
|
}
|
|
const _sfc_main = {
|
|
name: "EleImageUpload",
|
|
components: { VueDraggable, ImageItem },
|
|
mixins: [LicenseMixin],
|
|
inject: {
|
|
elForm: {
|
|
default: null
|
|
}
|
|
},
|
|
props,
|
|
emits: ["input", "remove", "item-click", "upload"],
|
|
data() {
|
|
return {
|
|
currentUrl: void 0
|
|
};
|
|
},
|
|
computed: {
|
|
isDisabled() {
|
|
var _a;
|
|
return this.disabled || ((_a = this.elForm) == null ? void 0 : _a.disabled);
|
|
},
|
|
uploadVisible() {
|
|
return !this.isDisabled && !(typeof this.limit === "number" && this.limit > 0 && this.value.length >= this.limit);
|
|
},
|
|
previewSrcList() {
|
|
return this.preview ? this.value.filter((d) => !!d.url).map((d) => d.url) : null;
|
|
}
|
|
},
|
|
methods: {
|
|
updateValue(value) {
|
|
this.$emit("input", value);
|
|
},
|
|
onUpload(file) {
|
|
if (!this.authenticated) {
|
|
console.warn(UNAUTHORIZED_TIP);
|
|
return false;
|
|
}
|
|
if (!this.uploadVisible) {
|
|
return false;
|
|
}
|
|
if (typeof this.uploadHandler === "function") {
|
|
this.uploadHandler(file);
|
|
return false;
|
|
}
|
|
const item = {
|
|
file,
|
|
uid: file.uid,
|
|
name: file.name,
|
|
progress: 0,
|
|
status: void 0
|
|
};
|
|
if (file.type.startsWith("image")) {
|
|
item.url = window.URL.createObjectURL(file);
|
|
}
|
|
if (typeof this.beforeUpload === "function") {
|
|
Promise.resolve(this.beforeUpload(file)).then((result) => {
|
|
if (result !== false) {
|
|
this.uploadItem(item);
|
|
}
|
|
}).catch((e) => {
|
|
if (e) {
|
|
console.error(e);
|
|
}
|
|
});
|
|
} else {
|
|
this.uploadItem(item);
|
|
}
|
|
return false;
|
|
},
|
|
uploadItem(item) {
|
|
this.updateValue(this.value.concat([item]));
|
|
if (this.autoUpload) {
|
|
this.$emit("upload", item);
|
|
}
|
|
},
|
|
onRemove(item) {
|
|
if (typeof this.removeHandler === "function") {
|
|
this.removeHandler(item);
|
|
return;
|
|
}
|
|
if (typeof this.beforeRemove === "function") {
|
|
Promise.resolve(this.beforeRemove(item)).then((result) => {
|
|
if (result !== false) {
|
|
this.removeItem(item);
|
|
}
|
|
}).catch(() => {
|
|
});
|
|
} else {
|
|
this.removeItem(item);
|
|
}
|
|
},
|
|
removeItem(item) {
|
|
this.updateValue(this.value.filter((d) => d !== item));
|
|
this.$emit("remove", item);
|
|
},
|
|
onItemClick(item) {
|
|
if (this.preview && item.url) {
|
|
this.currentUrl = item.url;
|
|
this.$nextTick(() => {
|
|
if (this.$refs.previewRef) {
|
|
this.$refs.previewRef.showViewer = true;
|
|
}
|
|
});
|
|
}
|
|
this.$emit("item-click", item);
|
|
},
|
|
onRetry(item) {
|
|
this.$emit("upload", item);
|
|
}
|
|
},
|
|
deactivated() {
|
|
this.currentUrl = void 0;
|
|
}
|
|
};
|
|
var _sfc_render = function render() {
|
|
var _vm = this, _c = _vm._self._c;
|
|
return _c("VueDraggable", { class: [
|
|
"ele-image-upload-list",
|
|
{ "ele-image-upload-disabled": _vm.isDisabled }
|
|
], attrs: { "value": _vm.value, "animation": 300, "draggable": ".draggable", "set-data": () => void 0 }, on: { "input": _vm.updateValue }, scopedSlots: _vm._u([{ key: "footer", fn: function() {
|
|
return [_vm.uploadVisible ? _c("div", { staticClass: "ele-image-upload-item ele-image-upload-button", style: [_vm.itemStyle, _vm.buttonStyle] }, [_c("el-upload", { attrs: { "action": "", "drag": _vm.drag, "accept": _vm.accept, "multiple": _vm.multiple, "show-file-list": false, "before-upload": _vm.onUpload } }, [_vm._t("icon", function() {
|
|
return [_c("i", { staticClass: "el-icon-plus ele-image-upload-icon" })];
|
|
})], 2)], 1) : _vm._e(), _vm.currentUrl ? _c("el-image", { ref: "previewRef", staticStyle: { "display": "none" }, attrs: { "src": _vm.currentUrl, "preview-src-list": _vm.previewSrcList } }) : _vm._e()];
|
|
}, proxy: true }], null, true) }, _vm._l(_vm.value, function(item) {
|
|
return _c("ImageItem", { key: item.uid, attrs: { "item": item, "disabled": _vm.isDisabled, "item-style": _vm.itemStyle }, on: { "item-click": function($event) {
|
|
return _vm.onItemClick(item);
|
|
}, "remove": function($event) {
|
|
return _vm.onRemove(item);
|
|
}, "retry": function($event) {
|
|
return _vm.onRetry(item);
|
|
} }, scopedSlots: _vm._u([_vm._l(Object.keys(_vm.$scopedSlots), function(name) {
|
|
return { key: name, fn: function(props2) {
|
|
return [_vm._t(name, null, null, props2 || {})];
|
|
} };
|
|
})], null, true) });
|
|
}), 1);
|
|
};
|
|
var _sfc_staticRenderFns = [];
|
|
var __component__ = /* @__PURE__ */ normalizeComponent(
|
|
_sfc_main,
|
|
_sfc_render,
|
|
_sfc_staticRenderFns,
|
|
false,
|
|
null,
|
|
null,
|
|
null,
|
|
null
|
|
);
|
|
const index = __component__.exports;
|
|
export {
|
|
index as default
|
|
};
|