UNPKG

tdesign-vue

Version:
207 lines (203 loc) 10.4 kB
/** * tdesign v1.12.1 * (c) 2025 tdesign * @license MIT */ import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray'; import _defineProperty from '@babel/runtime/helpers/defineProperty'; import { defineComponent, computed } from '@vue/composition-api'; import { CloseIcon, TimeFilledIcon, CheckCircleFilledIcon, ErrorCircleFilledIcon, CloseCircleFilledIcon } from 'tdesign-icons-vue'; import { Loading } from '../../loading/index.js'; import { Link } from '../../link/index.js'; import { renderTNodeJSX } from '../../utils/render-tnode.js'; import { abridgeName } from '../../_common/js/upload/utils.js'; import { useGlobalIcon } from '../../hooks/useGlobalIcon.js'; import { commonProps } from '../constants.js'; import '../../loading/directive.js'; import 'lodash-es'; import '../../loading/plugin.js'; import 'vue'; import '../../loading/loading.js'; import '../../loading/icon/gradient.js'; import '../../_common/js/loading/circle-adapter.js'; import '../../_common/js/utils/setStyle.js'; import '../../_common/js/utils/helper.js'; import '@babel/runtime/helpers/objectWithoutProperties'; import '@babel/runtime/helpers/slicedToArray'; import '../../config-provider/config-receiver.js'; import '../../config-provider/context.js'; import '../../_common/js/global-config/default-config.js'; import '../../_common/js/global-config/locale/zh_CN.js'; import '../../_chunks/dep-c44a474d.js'; import '@babel/runtime/helpers/typeof'; import '../../_chunks/dep-d639fbd7.js'; import 'dayjs'; import '../../_chunks/dep-3c66615e.js'; import '../../config-provider/type.js'; import '../../_common/js/global-config/t.js'; import '../../utils/mixins.js'; import '../../utils/dom.js'; import 'raf'; import '../../utils/easing.js'; import '../../utils/transfer-dom.js'; import '../../loading/props.js'; import '@babel/runtime/helpers/readOnlyError'; import '../../config.js'; import '../../utils/withInstall.js'; import './style/css.js'; import '../../loading/type.js'; import '../../link/link.js'; import '../../link/props.js'; import '../../link/type.js'; import '../../_common/js/log/log.js'; import '../../hooks/useConfig.js'; import '../../config-provider/useConfig.js'; function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } var NormalFile = defineComponent({ name: "UploadNormalFile", props: _objectSpread({ multiple: Boolean }, commonProps), setup: function setup(props) { var icons = useGlobalIcon({ CloseIcon: CloseIcon, TimeFilledIcon: TimeFilledIcon, CheckCircleFilledIcon: CheckCircleFilledIcon, ErrorCircleFilledIcon: ErrorCircleFilledIcon, CloseCircleFilledIcon: CloseCircleFilledIcon }); var uploadPrefix = computed(function () { return "".concat(props.classPrefix, "-upload"); }); var classes = computed(function () { return ["".concat(uploadPrefix.value, "__single"), "".concat(uploadPrefix.value, "__single-").concat(props.theme)]; }); return { classes: classes, uploadPrefix: uploadPrefix, icons: icons }; }, methods: { renderProgress: function renderProgress(percent) { var h = this.$createElement; return h("div", { "class": "".concat(this.uploadPrefix, "__single-progress") }, [h(Loading), h("span", { "class": "".concat(this.uploadPrefix, "__single-percent") }, [percent || 0, "%"])]); }, renderFilePreviewAsText: function renderFilePreviewAsText(files) { var _files$, _this = this; var h = this.$createElement; if (this.theme !== "file") return null; if (!this.multiple && ((_files$ = files[0]) === null || _files$ === void 0 ? void 0 : _files$.status) === "fail" && this.autoUpload) { return null; } var _this$icons = this.icons, ErrorCircleFilledIcon = _this$icons.ErrorCircleFilledIcon, TimeFilledIcon = _this$icons.TimeFilledIcon, CloseIcon = _this$icons.CloseIcon; return files.map(function (file, index) { var fileName = _this.abridgeName && file.name ? abridgeName.apply(void 0, [file.name].concat(_toConsumableArray(_this.abridgeName))) : file.name; return h("div", { "class": "".concat(_this.uploadPrefix, "__single-display-text ").concat(_this.uploadPrefix, "__display-text--margin"), "key": file.name + index + file.percent + file.status }, [file.url ? h(Link, { "attrs": { "href": file.url, "target": "_blank", "hover": "color", "size": "small" }, "class": "".concat(_this.uploadPrefix, "__single-name") }, [fileName]) : h("span", { "class": "".concat(_this.uploadPrefix, "__single-name") }, [fileName]), file.status === "fail" && h("div", { "class": "".concat(_this.uploadPrefix, "__flow-status ").concat(_this.uploadPrefix, "__file-fail") }, [h(ErrorCircleFilledIcon)]), file.status === "waiting" && h("div", { "class": "".concat(_this.uploadPrefix, "__flow-status ").concat(_this.uploadPrefix, "__file-waiting") }, [h(TimeFilledIcon)]), file.status === "progress" && _this.renderProgress(file.percent), !_this.disabled && file.status !== "progress" && h(CloseIcon, { "class": "".concat(_this.uploadPrefix, "__icon-delete"), "on": { "click": function click(_ref) { var e = _ref.e; return _this.onRemove({ e: e, file: file, index: index }); } } })]); }); }, renderFilePreviewAsInput: function renderFilePreviewAsInput() { var _this$abridgeName, _this2 = this; var h = this.$createElement; if (this.theme !== "file-input") return; var _this$icons2 = this.icons, TimeFilledIcon = _this$icons2.TimeFilledIcon, CheckCircleFilledIcon = _this$icons2.CheckCircleFilledIcon, ErrorCircleFilledIcon = _this$icons2.ErrorCircleFilledIcon, CloseCircleFilledIcon = _this$icons2.CloseCircleFilledIcon; var file = this.displayFiles[0] || {}; var inputTextClass = ["".concat(this.classPrefix, "-input__inner"), _defineProperty({}, "".concat(this.uploadPrefix, "__placeholder"), !this.displayFiles[0])]; var disabledClass = this.disabled ? "".concat(this.classPrefix, "-is-disabled") : ""; var fileName = (_this$abridgeName = this.abridgeName) !== null && _this$abridgeName !== void 0 && _this$abridgeName.length && file !== null && file !== void 0 && file.name ? abridgeName.apply(void 0, [file.name].concat(_toConsumableArray(this.abridgeName))) : file === null || file === void 0 ? void 0 : file.name; return h("div", { "class": "".concat(this.uploadPrefix, "__single-input-preview ").concat(this.classPrefix, "-input ").concat(disabledClass) }, [h("div", { "class": inputTextClass }, [h("span", { "class": ["".concat(this.uploadPrefix, "__single-input-text"), _defineProperty({}, this.placeholderClass, this.placeholder)] }, [file.name ? fileName : this.placeholder]), file.status === "progress" && this.renderProgress(file.percent), file.status === "waiting" && h(TimeFilledIcon, { "class": "".concat(this.uploadPrefix, "__status-icon ").concat(this.uploadPrefix, "__file-waiting") }), file.status === "success" && h(CheckCircleFilledIcon, { "class": "".concat(this.uploadPrefix, "__status-icon") }), file.name && file.status === "fail" && h(ErrorCircleFilledIcon, { "class": "".concat(this.uploadPrefix, "__status-icon ").concat(this.uploadPrefix, "__file-fail") }), Boolean(!this.disabled && file.name) && h(CloseCircleFilledIcon, { "class": "".concat(this.uploadPrefix, "__single-input-clear"), "on": { "click": function click(_ref4) { var e = _ref4.e; return _this2.onRemove({ e: e, file: file, index: 0 }); } } })])]); } }, render: function render() { var _this$$scopedSlots$de, _this$$scopedSlots, _this$displayFiles$, _this$displayFiles$0$; var h = arguments[0]; var fileListDisplay = renderTNodeJSX(this, "fileListDisplay", { params: { onRemove: this.onRemove, toUploadFiles: this.toUploadFiles, sizeOverLimitMessage: this.sizeOverLimitMessage, locale: this.locale, files: this.displayFiles } }); if (this.fileListDisplay === null || fileListDisplay === null) { fileListDisplay = null; } return h("div", { "class": this.classes }, [this.theme === "file-input" && this.renderFilePreviewAsInput(), (_this$$scopedSlots$de = (_this$$scopedSlots = this.$scopedSlots)["default"]) === null || _this$$scopedSlots$de === void 0 ? void 0 : _this$$scopedSlots$de.call(_this$$scopedSlots, null), this.theme === "file" && this.placeholder && !this.displayFiles[0] && h("small", { "class": [this.tipsClasses, this.placeholderClass] }, [this.placeholder]), fileListDisplay === null ? null : fileListDisplay || this.renderFilePreviewAsText(this.displayFiles), !this.multiple && ((_this$displayFiles$ = this.displayFiles[0]) === null || _this$displayFiles$ === void 0 ? void 0 : _this$displayFiles$.status) === "fail" && this.theme === "file" ? h("small", { "class": [this.errorClasses, this.placeholderClass] }, [((_this$displayFiles$0$ = this.displayFiles[0].response) === null || _this$displayFiles$0$ === void 0 ? void 0 : _this$displayFiles$0$.error) || this.locale.progress.failText]) : null]); } }); export { NormalFile as default }; //# sourceMappingURL=normal-file.js.map