ListItem.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. "use strict";
  2. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  3. Object.defineProperty(exports, "__esModule", {
  4. value: true
  5. });
  6. exports.listItemProps = exports.default = void 0;
  7. var _vue = require("vue");
  8. var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
  9. var _EyeOutlined = _interopRequireDefault(require("@ant-design/icons-vue/lib/icons/EyeOutlined"));
  10. var _DeleteOutlined = _interopRequireDefault(require("@ant-design/icons-vue/lib/icons/DeleteOutlined"));
  11. var _DownloadOutlined = _interopRequireDefault(require("@ant-design/icons-vue/lib/icons/DownloadOutlined"));
  12. var _tooltip = _interopRequireDefault(require("../../tooltip"));
  13. var _progress = _interopRequireDefault(require("../../progress"));
  14. var _useConfigInject = _interopRequireDefault(require("../../config-provider/hooks/useConfigInject"));
  15. var _transition = _interopRequireWildcard(require("../../_util/transition"));
  16. var _type = require("../../_util/type");
  17. function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
  18. function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
  19. const listItemProps = () => {
  20. return {
  21. prefixCls: String,
  22. locale: (0, _type.objectType)(undefined),
  23. file: (0, _type.objectType)(),
  24. items: (0, _type.arrayType)(),
  25. listType: (0, _type.stringType)(),
  26. isImgUrl: (0, _type.functionType)(),
  27. showRemoveIcon: (0, _type.booleanType)(),
  28. showDownloadIcon: (0, _type.booleanType)(),
  29. showPreviewIcon: (0, _type.booleanType)(),
  30. removeIcon: (0, _type.functionType)(),
  31. downloadIcon: (0, _type.functionType)(),
  32. previewIcon: (0, _type.functionType)(),
  33. iconRender: (0, _type.functionType)(),
  34. actionIconRender: (0, _type.functionType)(),
  35. itemRender: (0, _type.functionType)(),
  36. onPreview: (0, _type.functionType)(),
  37. onClose: (0, _type.functionType)(),
  38. onDownload: (0, _type.functionType)(),
  39. progress: (0, _type.objectType)()
  40. };
  41. };
  42. exports.listItemProps = listItemProps;
  43. var _default = exports.default = (0, _vue.defineComponent)({
  44. compatConfig: {
  45. MODE: 3
  46. },
  47. name: 'ListItem',
  48. inheritAttrs: false,
  49. props: listItemProps(),
  50. setup(props, _ref) {
  51. let {
  52. slots,
  53. attrs
  54. } = _ref;
  55. var _a;
  56. const showProgress = (0, _vue.shallowRef)(false);
  57. const progressRafRef = (0, _vue.shallowRef)();
  58. (0, _vue.onMounted)(() => {
  59. progressRafRef.value = setTimeout(() => {
  60. showProgress.value = true;
  61. }, 300);
  62. });
  63. (0, _vue.onBeforeUnmount)(() => {
  64. clearTimeout(progressRafRef.value);
  65. });
  66. const mergedStatus = (0, _vue.shallowRef)((_a = props.file) === null || _a === void 0 ? void 0 : _a.status);
  67. (0, _vue.watch)(() => {
  68. var _a;
  69. return (_a = props.file) === null || _a === void 0 ? void 0 : _a.status;
  70. }, status => {
  71. if (status !== 'removed') {
  72. mergedStatus.value = status;
  73. }
  74. });
  75. const {
  76. rootPrefixCls
  77. } = (0, _useConfigInject.default)('upload', props);
  78. const transitionProps = (0, _vue.computed)(() => (0, _transition.getTransitionProps)(`${rootPrefixCls.value}-fade`));
  79. return () => {
  80. var _a, _b;
  81. const {
  82. prefixCls,
  83. locale,
  84. listType,
  85. file,
  86. items,
  87. progress: progressProps,
  88. iconRender = slots.iconRender,
  89. actionIconRender = slots.actionIconRender,
  90. itemRender = slots.itemRender,
  91. isImgUrl,
  92. showPreviewIcon,
  93. showRemoveIcon,
  94. showDownloadIcon,
  95. previewIcon: customPreviewIcon = slots.previewIcon,
  96. removeIcon: customRemoveIcon = slots.removeIcon,
  97. downloadIcon: customDownloadIcon = slots.downloadIcon,
  98. onPreview,
  99. onDownload,
  100. onClose
  101. } = props;
  102. const {
  103. class: className,
  104. style
  105. } = attrs;
  106. // This is used for legacy span make scrollHeight the wrong value.
  107. // We will force these to be `display: block` with non `picture-card`
  108. const iconNode = iconRender({
  109. file
  110. });
  111. let icon = (0, _vue.createVNode)("div", {
  112. "class": `${prefixCls}-text-icon`
  113. }, [iconNode]);
  114. if (listType === 'picture' || listType === 'picture-card') {
  115. if (mergedStatus.value === 'uploading' || !file.thumbUrl && !file.url) {
  116. const uploadingClassName = {
  117. [`${prefixCls}-list-item-thumbnail`]: true,
  118. [`${prefixCls}-list-item-file`]: mergedStatus.value !== 'uploading'
  119. };
  120. icon = (0, _vue.createVNode)("div", {
  121. "class": uploadingClassName
  122. }, [iconNode]);
  123. } else {
  124. const thumbnail = (isImgUrl === null || isImgUrl === void 0 ? void 0 : isImgUrl(file)) ? (0, _vue.createVNode)("img", {
  125. "src": file.thumbUrl || file.url,
  126. "alt": file.name,
  127. "class": `${prefixCls}-list-item-image`,
  128. "crossorigin": file.crossOrigin
  129. }, null) : iconNode;
  130. const aClassName = {
  131. [`${prefixCls}-list-item-thumbnail`]: true,
  132. [`${prefixCls}-list-item-file`]: isImgUrl && !isImgUrl(file)
  133. };
  134. icon = (0, _vue.createVNode)("a", {
  135. "class": aClassName,
  136. "onClick": e => onPreview(file, e),
  137. "href": file.url || file.thumbUrl,
  138. "target": "_blank",
  139. "rel": "noopener noreferrer"
  140. }, [thumbnail]);
  141. }
  142. }
  143. const infoUploadingClass = {
  144. [`${prefixCls}-list-item`]: true,
  145. [`${prefixCls}-list-item-${mergedStatus.value}`]: true
  146. };
  147. const linkProps = typeof file.linkProps === 'string' ? JSON.parse(file.linkProps) : file.linkProps;
  148. const removeIcon = showRemoveIcon ? actionIconRender({
  149. customIcon: customRemoveIcon ? customRemoveIcon({
  150. file
  151. }) : (0, _vue.createVNode)(_DeleteOutlined.default, null, null),
  152. callback: () => onClose(file),
  153. prefixCls,
  154. title: locale.removeFile
  155. }) : null;
  156. const downloadIcon = showDownloadIcon && mergedStatus.value === 'done' ? actionIconRender({
  157. customIcon: customDownloadIcon ? customDownloadIcon({
  158. file
  159. }) : (0, _vue.createVNode)(_DownloadOutlined.default, null, null),
  160. callback: () => onDownload(file),
  161. prefixCls,
  162. title: locale.downloadFile
  163. }) : null;
  164. const downloadOrDelete = listType !== 'picture-card' && (0, _vue.createVNode)("span", {
  165. "key": "download-delete",
  166. "class": [`${prefixCls}-list-item-actions`, {
  167. picture: listType === 'picture'
  168. }]
  169. }, [downloadIcon, removeIcon]);
  170. const listItemNameClass = `${prefixCls}-list-item-name`;
  171. const fileName = file.url ? [(0, _vue.createVNode)("a", (0, _objectSpread2.default)((0, _objectSpread2.default)({
  172. "key": "view",
  173. "target": "_blank",
  174. "rel": "noopener noreferrer",
  175. "class": listItemNameClass,
  176. "title": file.name
  177. }, linkProps), {}, {
  178. "href": file.url,
  179. "onClick": e => onPreview(file, e)
  180. }), [file.name]), downloadOrDelete] : [(0, _vue.createVNode)("span", {
  181. "key": "view",
  182. "class": listItemNameClass,
  183. "onClick": e => onPreview(file, e),
  184. "title": file.name
  185. }, [file.name]), downloadOrDelete];
  186. const previewStyle = {
  187. pointerEvents: 'none',
  188. opacity: 0.5
  189. };
  190. const previewIcon = showPreviewIcon ? (0, _vue.createVNode)("a", {
  191. "href": file.url || file.thumbUrl,
  192. "target": "_blank",
  193. "rel": "noopener noreferrer",
  194. "style": file.url || file.thumbUrl ? undefined : previewStyle,
  195. "onClick": e => onPreview(file, e),
  196. "title": locale.previewFile
  197. }, [customPreviewIcon ? customPreviewIcon({
  198. file
  199. }) : (0, _vue.createVNode)(_EyeOutlined.default, null, null)]) : null;
  200. const pictureCardActions = listType === 'picture-card' && mergedStatus.value !== 'uploading' && (0, _vue.createVNode)("span", {
  201. "class": `${prefixCls}-list-item-actions`
  202. }, [previewIcon, mergedStatus.value === 'done' && downloadIcon, removeIcon]);
  203. const dom = (0, _vue.createVNode)("div", {
  204. "class": infoUploadingClass
  205. }, [icon, fileName, pictureCardActions, showProgress.value && (0, _vue.createVNode)(_transition.default, transitionProps.value, {
  206. default: () => [(0, _vue.withDirectives)((0, _vue.createVNode)("div", {
  207. "class": `${prefixCls}-list-item-progress`
  208. }, ['percent' in file ? (0, _vue.createVNode)(_progress.default, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, progressProps), {}, {
  209. "type": "line",
  210. "percent": file.percent
  211. }), null) : null]), [[_vue.vShow, mergedStatus.value === 'uploading']])]
  212. })]);
  213. const listContainerNameClass = {
  214. [`${prefixCls}-list-item-container`]: true,
  215. [`${className}`]: !!className
  216. };
  217. const message = file.response && typeof file.response === 'string' ? file.response : ((_a = file.error) === null || _a === void 0 ? void 0 : _a.statusText) || ((_b = file.error) === null || _b === void 0 ? void 0 : _b.message) || locale.uploadError;
  218. const item = mergedStatus.value === 'error' ? (0, _vue.createVNode)(_tooltip.default, {
  219. "title": message,
  220. "getPopupContainer": node => node.parentNode
  221. }, {
  222. default: () => [dom]
  223. }) : dom;
  224. return (0, _vue.createVNode)("div", {
  225. "class": listContainerNameClass,
  226. "style": style
  227. }, [itemRender ? itemRender({
  228. originNode: item,
  229. file,
  230. fileList: items,
  231. actions: {
  232. download: onDownload.bind(null, file),
  233. preview: onPreview.bind(null, file),
  234. remove: onClose.bind(null, file)
  235. }
  236. }) : item]);
  237. };
  238. }
  239. });