upload.js 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408
  1. module.exports =
  2. /******/ (function(modules) { // webpackBootstrap
  3. /******/ // The module cache
  4. /******/ var installedModules = {};
  5. /******/
  6. /******/ // The require function
  7. /******/ function __webpack_require__(moduleId) {
  8. /******/
  9. /******/ // Check if module is in cache
  10. /******/ if(installedModules[moduleId]) {
  11. /******/ return installedModules[moduleId].exports;
  12. /******/ }
  13. /******/ // Create a new module (and put it into the cache)
  14. /******/ var module = installedModules[moduleId] = {
  15. /******/ i: moduleId,
  16. /******/ l: false,
  17. /******/ exports: {}
  18. /******/ };
  19. /******/
  20. /******/ // Execute the module function
  21. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  22. /******/
  23. /******/ // Flag the module as loaded
  24. /******/ module.l = true;
  25. /******/
  26. /******/ // Return the exports of the module
  27. /******/ return module.exports;
  28. /******/ }
  29. /******/
  30. /******/
  31. /******/ // expose the modules object (__webpack_modules__)
  32. /******/ __webpack_require__.m = modules;
  33. /******/
  34. /******/ // expose the module cache
  35. /******/ __webpack_require__.c = installedModules;
  36. /******/
  37. /******/ // define getter function for harmony exports
  38. /******/ __webpack_require__.d = function(exports, name, getter) {
  39. /******/ if(!__webpack_require__.o(exports, name)) {
  40. /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
  41. /******/ }
  42. /******/ };
  43. /******/
  44. /******/ // define __esModule on exports
  45. /******/ __webpack_require__.r = function(exports) {
  46. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  47. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  48. /******/ }
  49. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  50. /******/ };
  51. /******/
  52. /******/ // create a fake namespace object
  53. /******/ // mode & 1: value is a module id, require it
  54. /******/ // mode & 2: merge all properties of value into the ns
  55. /******/ // mode & 4: return value when already ns object
  56. /******/ // mode & 8|1: behave like require
  57. /******/ __webpack_require__.t = function(value, mode) {
  58. /******/ if(mode & 1) value = __webpack_require__(value);
  59. /******/ if(mode & 8) return value;
  60. /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  61. /******/ var ns = Object.create(null);
  62. /******/ __webpack_require__.r(ns);
  63. /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  64. /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  65. /******/ return ns;
  66. /******/ };
  67. /******/
  68. /******/ // getDefaultExport function for compatibility with non-harmony modules
  69. /******/ __webpack_require__.n = function(module) {
  70. /******/ var getter = module && module.__esModule ?
  71. /******/ function getDefault() { return module['default']; } :
  72. /******/ function getModuleExports() { return module; };
  73. /******/ __webpack_require__.d(getter, 'a', getter);
  74. /******/ return getter;
  75. /******/ };
  76. /******/
  77. /******/ // Object.prototype.hasOwnProperty.call
  78. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  79. /******/
  80. /******/ // __webpack_public_path__
  81. /******/ __webpack_require__.p = "/dist/";
  82. /******/
  83. /******/
  84. /******/ // Load entry module and return exports
  85. /******/ return __webpack_require__(__webpack_require__.s = 57);
  86. /******/ })
  87. /************************************************************************/
  88. /******/ ({
  89. /***/ 0:
  90. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  91. "use strict";
  92. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return normalizeComponent; });
  93. /* globals __VUE_SSR_CONTEXT__ */
  94. // IMPORTANT: Do NOT use ES2015 features in this file (except for modules).
  95. // This module is a runtime utility for cleaner component module output and will
  96. // be included in the final webpack user bundle.
  97. function normalizeComponent (
  98. scriptExports,
  99. render,
  100. staticRenderFns,
  101. functionalTemplate,
  102. injectStyles,
  103. scopeId,
  104. moduleIdentifier, /* server only */
  105. shadowMode /* vue-cli only */
  106. ) {
  107. // Vue.extend constructor export interop
  108. var options = typeof scriptExports === 'function'
  109. ? scriptExports.options
  110. : scriptExports
  111. // render functions
  112. if (render) {
  113. options.render = render
  114. options.staticRenderFns = staticRenderFns
  115. options._compiled = true
  116. }
  117. // functional template
  118. if (functionalTemplate) {
  119. options.functional = true
  120. }
  121. // scopedId
  122. if (scopeId) {
  123. options._scopeId = 'data-v-' + scopeId
  124. }
  125. var hook
  126. if (moduleIdentifier) { // server build
  127. hook = function (context) {
  128. // 2.3 injection
  129. context =
  130. context || // cached call
  131. (this.$vnode && this.$vnode.ssrContext) || // stateful
  132. (this.parent && this.parent.$vnode && this.parent.$vnode.ssrContext) // functional
  133. // 2.2 with runInNewContext: true
  134. if (!context && typeof __VUE_SSR_CONTEXT__ !== 'undefined') {
  135. context = __VUE_SSR_CONTEXT__
  136. }
  137. // inject component styles
  138. if (injectStyles) {
  139. injectStyles.call(this, context)
  140. }
  141. // register component module identifier for async chunk inferrence
  142. if (context && context._registeredComponents) {
  143. context._registeredComponents.add(moduleIdentifier)
  144. }
  145. }
  146. // used by ssr in case component is cached and beforeCreate
  147. // never gets called
  148. options._ssrRegister = hook
  149. } else if (injectStyles) {
  150. hook = shadowMode
  151. ? function () { injectStyles.call(this, this.$root.$options.shadowRoot) }
  152. : injectStyles
  153. }
  154. if (hook) {
  155. if (options.functional) {
  156. // for template-only hot-reload because in that case the render fn doesn't
  157. // go through the normalizer
  158. options._injectStyles = hook
  159. // register for functioal component in vue file
  160. var originalRender = options.render
  161. options.render = function renderWithStyleInjection (h, context) {
  162. hook.call(context)
  163. return originalRender(h, context)
  164. }
  165. } else {
  166. // inject component registration as beforeCreate hook
  167. var existing = options.beforeCreate
  168. options.beforeCreate = existing
  169. ? [].concat(existing, hook)
  170. : [hook]
  171. }
  172. }
  173. return {
  174. exports: scriptExports,
  175. options: options
  176. }
  177. }
  178. /***/ }),
  179. /***/ 11:
  180. /***/ (function(module, exports) {
  181. module.exports = require("element-ui/lib/mixins/migrating");
  182. /***/ }),
  183. /***/ 26:
  184. /***/ (function(module, exports) {
  185. module.exports = require("babel-helper-vue-jsx-merge-props");
  186. /***/ }),
  187. /***/ 42:
  188. /***/ (function(module, exports) {
  189. module.exports = require("element-ui/lib/progress");
  190. /***/ }),
  191. /***/ 57:
  192. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  193. "use strict";
  194. __webpack_require__.r(__webpack_exports__);
  195. // CONCATENATED MODULE: ./node_modules/vue-loader/lib/loaders/templateLoader.js??vue-loader-options!./node_modules/vue-loader/lib??vue-loader-options!./packages/upload/src/upload-list.vue?vue&type=template&id=173fedf5&
  196. var upload_listvue_type_template_id_173fedf5_render = function() {
  197. var _vm = this
  198. var _h = _vm.$createElement
  199. var _c = _vm._self._c || _h
  200. return _c(
  201. "transition-group",
  202. {
  203. class: [
  204. "el-upload-list",
  205. "el-upload-list--" + _vm.listType,
  206. { "is-disabled": _vm.disabled }
  207. ],
  208. attrs: { tag: "ul", name: "el-list" }
  209. },
  210. _vm._l(_vm.files, function(file) {
  211. return _c(
  212. "li",
  213. {
  214. key: file.uid,
  215. class: [
  216. "el-upload-list__item",
  217. "is-" + file.status,
  218. _vm.focusAble && _vm.focusing ? "focusing" : ""
  219. ],
  220. attrs: { tabindex: "0" },
  221. on: {
  222. keydown: function($event) {
  223. if (
  224. !("button" in $event) &&
  225. _vm._k($event.keyCode, "delete", [8, 46], $event.key, [
  226. "Backspace",
  227. "Delete",
  228. "Del"
  229. ])
  230. ) {
  231. return null
  232. }
  233. !_vm.disabled && _vm.$emit("remove", file)
  234. },
  235. focus: function($event) {
  236. _vm.focusing = true
  237. },
  238. blur: function($event) {
  239. _vm.focusing = false
  240. },
  241. click: function($event) {
  242. _vm.focusing = false
  243. }
  244. }
  245. },
  246. [
  247. _vm._t(
  248. "default",
  249. [
  250. file.status !== "uploading" &&
  251. ["picture-card", "picture"].indexOf(_vm.listType) > -1
  252. ? _c("img", {
  253. staticClass: "el-upload-list__item-thumbnail",
  254. attrs: { src: file.url, alt: "" }
  255. })
  256. : _vm._e(),
  257. _c(
  258. "a",
  259. {
  260. staticClass: "el-upload-list__item-name",
  261. on: {
  262. click: function($event) {
  263. _vm.handleClick(file, $event)
  264. }
  265. }
  266. },
  267. [
  268. _c("i", { staticClass: "el-icon-document" }),
  269. _vm._v(_vm._s(file.name) + "\n ")
  270. ]
  271. ),
  272. _c(
  273. "label",
  274. { staticClass: "el-upload-list__item-status-label" },
  275. [
  276. _c("i", {
  277. class: {
  278. "el-icon-upload-success": true,
  279. "el-icon-circle-check": _vm.listType === "text",
  280. "el-icon-check":
  281. ["picture-card", "picture"].indexOf(_vm.listType) > -1
  282. }
  283. })
  284. ]
  285. ),
  286. !_vm.disabled
  287. ? _c("i", {
  288. staticClass: "el-icon-close",
  289. on: {
  290. click: function($event) {
  291. _vm.$emit("remove", file)
  292. }
  293. }
  294. })
  295. : _vm._e(),
  296. !_vm.disabled
  297. ? _c("i", { staticClass: "el-icon-close-tip" }, [
  298. _vm._v(_vm._s(_vm.t("el.upload.deleteTip")))
  299. ])
  300. : _vm._e(),
  301. file.status === "uploading"
  302. ? _c("el-progress", {
  303. attrs: {
  304. type: _vm.listType === "picture-card" ? "circle" : "line",
  305. "stroke-width": _vm.listType === "picture-card" ? 6 : 2,
  306. percentage: _vm.parsePercentage(file.percentage)
  307. }
  308. })
  309. : _vm._e(),
  310. _vm.listType === "picture-card"
  311. ? _c("span", { staticClass: "el-upload-list__item-actions" }, [
  312. _vm.handlePreview && _vm.listType === "picture-card"
  313. ? _c(
  314. "span",
  315. {
  316. staticClass: "el-upload-list__item-preview",
  317. on: {
  318. click: function($event) {
  319. _vm.handlePreview(file, $event)
  320. }
  321. }
  322. },
  323. [_c("i", { staticClass: "el-icon-zoom-in" })]
  324. )
  325. : _vm._e(),
  326. !_vm.disabled
  327. ? _c(
  328. "span",
  329. {
  330. staticClass: "el-upload-list__item-delete",
  331. on: {
  332. click: function($event) {
  333. _vm.$emit("remove", file)
  334. }
  335. }
  336. },
  337. [_c("i", { staticClass: "el-icon-delete" })]
  338. )
  339. : _vm._e()
  340. ])
  341. : _vm._e()
  342. ],
  343. { file: file }
  344. )
  345. ],
  346. 2
  347. )
  348. }),
  349. 0
  350. )
  351. }
  352. var staticRenderFns = []
  353. upload_listvue_type_template_id_173fedf5_render._withStripped = true
  354. // CONCATENATED MODULE: ./packages/upload/src/upload-list.vue?vue&type=template&id=173fedf5&
  355. // EXTERNAL MODULE: external "element-ui/lib/mixins/locale"
  356. var locale_ = __webpack_require__(6);
  357. var locale_default = /*#__PURE__*/__webpack_require__.n(locale_);
  358. // EXTERNAL MODULE: external "element-ui/lib/progress"
  359. var progress_ = __webpack_require__(42);
  360. var progress_default = /*#__PURE__*/__webpack_require__.n(progress_);
  361. // CONCATENATED MODULE: ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib??vue-loader-options!./packages/upload/src/upload-list.vue?vue&type=script&lang=js&
  362. //
  363. //
  364. //
  365. //
  366. //
  367. //
  368. //
  369. //
  370. //
  371. //
  372. //
  373. //
  374. //
  375. //
  376. //
  377. //
  378. //
  379. //
  380. //
  381. //
  382. //
  383. //
  384. //
  385. //
  386. //
  387. //
  388. //
  389. //
  390. //
  391. //
  392. //
  393. //
  394. //
  395. //
  396. //
  397. //
  398. //
  399. //
  400. //
  401. //
  402. //
  403. //
  404. //
  405. //
  406. //
  407. //
  408. //
  409. //
  410. //
  411. //
  412. //
  413. //
  414. //
  415. //
  416. //
  417. //
  418. //
  419. //
  420. //
  421. //
  422. //
  423. //
  424. //
  425. //
  426. /* harmony default export */ var upload_listvue_type_script_lang_js_ = ({
  427. name: 'ElUploadList',
  428. mixins: [locale_default.a],
  429. data: function data() {
  430. return {
  431. focusing: false
  432. };
  433. },
  434. components: { ElProgress: progress_default.a },
  435. props: {
  436. files: {
  437. type: Array,
  438. default: function _default() {
  439. return [];
  440. }
  441. },
  442. disabled: {
  443. type: Boolean,
  444. default: false
  445. },
  446. handlePreview: Function,
  447. listType: String,
  448. focusAble: {
  449. type: Boolean,
  450. default: true
  451. }
  452. },
  453. methods: {
  454. parsePercentage: function parsePercentage(val) {
  455. return parseInt(val, 10);
  456. },
  457. handleClick: function handleClick(file, event) {
  458. this.handlePreview && this.handlePreview(file, event);
  459. }
  460. }
  461. });
  462. // CONCATENATED MODULE: ./packages/upload/src/upload-list.vue?vue&type=script&lang=js&
  463. /* harmony default export */ var src_upload_listvue_type_script_lang_js_ = (upload_listvue_type_script_lang_js_);
  464. // EXTERNAL MODULE: ./node_modules/vue-loader/lib/runtime/componentNormalizer.js
  465. var componentNormalizer = __webpack_require__(0);
  466. // CONCATENATED MODULE: ./packages/upload/src/upload-list.vue
  467. /* normalize component */
  468. var component = Object(componentNormalizer["a" /* default */])(
  469. src_upload_listvue_type_script_lang_js_,
  470. upload_listvue_type_template_id_173fedf5_render,
  471. staticRenderFns,
  472. false,
  473. null,
  474. null,
  475. null
  476. )
  477. /* hot reload */
  478. if (false) { var api; }
  479. component.options.__file = "packages/upload/src/upload-list.vue"
  480. /* harmony default export */ var upload_list = (component.exports);
  481. // EXTERNAL MODULE: external "babel-helper-vue-jsx-merge-props"
  482. var external_babel_helper_vue_jsx_merge_props_ = __webpack_require__(26);
  483. var external_babel_helper_vue_jsx_merge_props_default = /*#__PURE__*/__webpack_require__.n(external_babel_helper_vue_jsx_merge_props_);
  484. // CONCATENATED MODULE: ./packages/upload/src/ajax.js
  485. function getError(action, option, xhr) {
  486. var msg = void 0;
  487. if (xhr.response) {
  488. msg = '' + (xhr.response.error || xhr.response);
  489. } else if (xhr.responseText) {
  490. msg = '' + xhr.responseText;
  491. } else {
  492. msg = 'fail to post ' + action + ' ' + xhr.status;
  493. }
  494. var err = new Error(msg);
  495. err.status = xhr.status;
  496. err.method = 'post';
  497. err.url = action;
  498. return err;
  499. }
  500. function getBody(xhr) {
  501. var text = xhr.responseText || xhr.response;
  502. if (!text) {
  503. return text;
  504. }
  505. try {
  506. return JSON.parse(text);
  507. } catch (e) {
  508. return text;
  509. }
  510. }
  511. function upload(option) {
  512. if (typeof XMLHttpRequest === 'undefined') {
  513. return;
  514. }
  515. var xhr = new XMLHttpRequest();
  516. var action = option.action;
  517. if (xhr.upload) {
  518. xhr.upload.onprogress = function progress(e) {
  519. if (e.total > 0) {
  520. e.percent = e.loaded / e.total * 100;
  521. }
  522. option.onProgress(e);
  523. };
  524. }
  525. var formData = new FormData();
  526. if (option.data) {
  527. Object.keys(option.data).forEach(function (key) {
  528. formData.append(key, option.data[key]);
  529. });
  530. }
  531. formData.append(option.filename, option.file, option.file.name);
  532. xhr.onerror = function error(e) {
  533. option.onError(e);
  534. };
  535. xhr.onload = function onload() {
  536. if (xhr.status < 200 || xhr.status >= 300) {
  537. return option.onError(getError(action, option, xhr));
  538. }
  539. option.onSuccess(getBody(xhr));
  540. };
  541. xhr.open('post', action, true);
  542. if (option.withCredentials && 'withCredentials' in xhr) {
  543. xhr.withCredentials = true;
  544. }
  545. var headers = option.headers || {};
  546. for (var item in headers) {
  547. if (headers.hasOwnProperty(item) && headers[item] !== null) {
  548. xhr.setRequestHeader(item, headers[item]);
  549. }
  550. }
  551. xhr.send(formData);
  552. return xhr;
  553. }
  554. // CONCATENATED MODULE: ./node_modules/vue-loader/lib/loaders/templateLoader.js??vue-loader-options!./node_modules/vue-loader/lib??vue-loader-options!./packages/upload/src/upload-dragger.vue?vue&type=template&id=7ebbf219&
  555. var upload_draggervue_type_template_id_7ebbf219_render = function() {
  556. var _vm = this
  557. var _h = _vm.$createElement
  558. var _c = _vm._self._c || _h
  559. return _c(
  560. "div",
  561. {
  562. staticClass: "el-upload-dragger",
  563. class: {
  564. "is-dragover": _vm.dragover
  565. },
  566. on: {
  567. drop: function($event) {
  568. $event.preventDefault()
  569. return _vm.onDrop($event)
  570. },
  571. dragover: function($event) {
  572. $event.preventDefault()
  573. return _vm.onDragover($event)
  574. },
  575. dragleave: function($event) {
  576. $event.preventDefault()
  577. _vm.dragover = false
  578. }
  579. }
  580. },
  581. [_vm._t("default")],
  582. 2
  583. )
  584. }
  585. var upload_draggervue_type_template_id_7ebbf219_staticRenderFns = []
  586. upload_draggervue_type_template_id_7ebbf219_render._withStripped = true
  587. // CONCATENATED MODULE: ./packages/upload/src/upload-dragger.vue?vue&type=template&id=7ebbf219&
  588. // CONCATENATED MODULE: ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib??vue-loader-options!./packages/upload/src/upload-dragger.vue?vue&type=script&lang=js&
  589. //
  590. //
  591. //
  592. //
  593. //
  594. //
  595. //
  596. //
  597. //
  598. //
  599. //
  600. //
  601. //
  602. /* harmony default export */ var upload_draggervue_type_script_lang_js_ = ({
  603. name: 'ElUploadDrag',
  604. props: {
  605. disabled: Boolean
  606. },
  607. inject: {
  608. uploader: {
  609. default: ''
  610. }
  611. },
  612. data: function data() {
  613. return {
  614. dragover: false
  615. };
  616. },
  617. methods: {
  618. onDragover: function onDragover() {
  619. if (!this.disabled) {
  620. this.dragover = true;
  621. }
  622. },
  623. onDrop: function onDrop(e) {
  624. if (this.disabled || !this.uploader) return;
  625. var accept = this.uploader.accept;
  626. this.dragover = false;
  627. if (!accept) {
  628. this.$emit('file', e.dataTransfer.files);
  629. return;
  630. }
  631. this.$emit('file', [].slice.call(e.dataTransfer.files).filter(function (file) {
  632. var type = file.type,
  633. name = file.name;
  634. var extension = name.indexOf('.') > -1 ? '.' + name.split('.').pop() : '';
  635. var baseType = type.replace(/\/.*$/, '');
  636. return accept.split(',').map(function (type) {
  637. return type.trim();
  638. }).filter(function (type) {
  639. return type;
  640. }).some(function (acceptedType) {
  641. if (/\..+$/.test(acceptedType)) {
  642. return extension === acceptedType;
  643. }
  644. if (/\/\*$/.test(acceptedType)) {
  645. return baseType === acceptedType.replace(/\/\*$/, '');
  646. }
  647. if (/^[^\/]+\/[^\/]+$/.test(acceptedType)) {
  648. return type === acceptedType;
  649. }
  650. return false;
  651. });
  652. }));
  653. }
  654. }
  655. });
  656. // CONCATENATED MODULE: ./packages/upload/src/upload-dragger.vue?vue&type=script&lang=js&
  657. /* harmony default export */ var src_upload_draggervue_type_script_lang_js_ = (upload_draggervue_type_script_lang_js_);
  658. // CONCATENATED MODULE: ./packages/upload/src/upload-dragger.vue
  659. /* normalize component */
  660. var upload_dragger_component = Object(componentNormalizer["a" /* default */])(
  661. src_upload_draggervue_type_script_lang_js_,
  662. upload_draggervue_type_template_id_7ebbf219_render,
  663. upload_draggervue_type_template_id_7ebbf219_staticRenderFns,
  664. false,
  665. null,
  666. null,
  667. null
  668. )
  669. /* hot reload */
  670. if (false) { var upload_dragger_api; }
  671. upload_dragger_component.options.__file = "packages/upload/src/upload-dragger.vue"
  672. /* harmony default export */ var upload_dragger = (upload_dragger_component.exports);
  673. // CONCATENATED MODULE: ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib??vue-loader-options!./packages/upload/src/upload.vue?vue&type=script&lang=js&
  674. /* harmony default export */ var uploadvue_type_script_lang_js_ = ({
  675. inject: ['uploader'],
  676. components: {
  677. UploadDragger: upload_dragger
  678. },
  679. props: {
  680. type: String,
  681. action: {
  682. type: String,
  683. required: true
  684. },
  685. name: {
  686. type: String,
  687. default: 'file'
  688. },
  689. data: Object,
  690. headers: Object,
  691. withCredentials: Boolean,
  692. multiple: Boolean,
  693. accept: String,
  694. onStart: Function,
  695. onProgress: Function,
  696. onSuccess: Function,
  697. onError: Function,
  698. beforeUpload: Function,
  699. drag: Boolean,
  700. onPreview: {
  701. type: Function,
  702. default: function _default() {}
  703. },
  704. onRemove: {
  705. type: Function,
  706. default: function _default() {}
  707. },
  708. fileList: Array,
  709. autoUpload: Boolean,
  710. listType: String,
  711. httpRequest: {
  712. type: Function,
  713. default: upload
  714. },
  715. disabled: Boolean,
  716. limit: Number,
  717. onExceed: Function
  718. },
  719. data: function data() {
  720. return {
  721. mouseover: false,
  722. reqs: {}
  723. };
  724. },
  725. methods: {
  726. isImage: function isImage(str) {
  727. return str.indexOf('image') !== -1;
  728. },
  729. handleChange: function handleChange(ev) {
  730. var files = ev.target.files;
  731. if (!files) return;
  732. this.uploadFiles(files);
  733. },
  734. uploadFiles: function uploadFiles(files) {
  735. var _this = this;
  736. if (this.limit && this.fileList.length + files.length > this.limit) {
  737. this.onExceed && this.onExceed(files, this.fileList);
  738. return;
  739. }
  740. var postFiles = Array.prototype.slice.call(files);
  741. if (!this.multiple) {
  742. postFiles = postFiles.slice(0, 1);
  743. }
  744. if (postFiles.length === 0) {
  745. return;
  746. }
  747. postFiles.forEach(function (rawFile) {
  748. _this.onStart(rawFile);
  749. if (_this.autoUpload) _this.upload(rawFile);
  750. });
  751. },
  752. upload: function upload(rawFile) {
  753. var _this2 = this;
  754. this.$refs.input.value = null;
  755. if (!this.beforeUpload) {
  756. return this.post(rawFile);
  757. }
  758. var before = this.beforeUpload(rawFile);
  759. if (before && before.then) {
  760. before.then(function (processedFile) {
  761. var fileType = Object.prototype.toString.call(processedFile);
  762. if (fileType === '[object File]' || fileType === '[object Blob]') {
  763. if (fileType === '[object Blob]') {
  764. processedFile = new File([processedFile], rawFile.name, {
  765. type: rawFile.type
  766. });
  767. }
  768. for (var p in rawFile) {
  769. if (rawFile.hasOwnProperty(p)) {
  770. processedFile[p] = rawFile[p];
  771. }
  772. }
  773. _this2.post(processedFile);
  774. } else {
  775. _this2.post(rawFile);
  776. }
  777. }, function () {
  778. _this2.onRemove(null, rawFile);
  779. });
  780. } else if (before !== false) {
  781. this.post(rawFile);
  782. } else {
  783. this.onRemove(null, rawFile);
  784. }
  785. },
  786. abort: function abort(file) {
  787. var reqs = this.reqs;
  788. if (file) {
  789. var uid = file;
  790. if (file.uid) uid = file.uid;
  791. if (reqs[uid]) {
  792. reqs[uid].abort();
  793. }
  794. } else {
  795. Object.keys(reqs).forEach(function (uid) {
  796. if (reqs[uid]) reqs[uid].abort();
  797. delete reqs[uid];
  798. });
  799. }
  800. },
  801. post: function post(rawFile) {
  802. var _this3 = this;
  803. var uid = rawFile.uid;
  804. var options = {
  805. headers: this.headers,
  806. withCredentials: this.withCredentials,
  807. file: rawFile,
  808. data: this.data,
  809. filename: this.name,
  810. action: this.action,
  811. onProgress: function onProgress(e) {
  812. _this3.onProgress(e, rawFile);
  813. },
  814. onSuccess: function onSuccess(res) {
  815. _this3.onSuccess(res, rawFile);
  816. delete _this3.reqs[uid];
  817. },
  818. onError: function onError(err) {
  819. _this3.onError(err, rawFile);
  820. delete _this3.reqs[uid];
  821. }
  822. };
  823. var req = this.httpRequest(options);
  824. this.reqs[uid] = req;
  825. if (req && req.then) {
  826. req.then(options.onSuccess, options.onError);
  827. }
  828. },
  829. handleClick: function handleClick() {
  830. if (!this.disabled) {
  831. this.$refs.input.value = null;
  832. this.$refs.input.click();
  833. }
  834. },
  835. handleKeydown: function handleKeydown(e) {
  836. if (e.target !== e.currentTarget) return;
  837. if (e.keyCode === 13 || e.keyCode === 32) {
  838. this.handleClick();
  839. }
  840. }
  841. },
  842. render: function render(h) {
  843. var handleClick = this.handleClick,
  844. drag = this.drag,
  845. name = this.name,
  846. handleChange = this.handleChange,
  847. multiple = this.multiple,
  848. accept = this.accept,
  849. listType = this.listType,
  850. uploadFiles = this.uploadFiles,
  851. disabled = this.disabled,
  852. handleKeydown = this.handleKeydown;
  853. var data = {
  854. class: {
  855. 'el-upload': true
  856. },
  857. on: {
  858. click: handleClick,
  859. keydown: handleKeydown
  860. }
  861. };
  862. data.class['el-upload--' + listType] = true;
  863. return h(
  864. 'div',
  865. external_babel_helper_vue_jsx_merge_props_default()([data, {
  866. attrs: { tabindex: '0' }
  867. }]),
  868. [drag ? h(
  869. 'upload-dragger',
  870. {
  871. attrs: { disabled: disabled },
  872. on: {
  873. 'file': uploadFiles
  874. }
  875. },
  876. [this.$slots.default]
  877. ) : this.$slots.default, h('input', { 'class': 'el-upload__input', attrs: { type: 'file', name: name, multiple: multiple, accept: accept },
  878. ref: 'input', on: {
  879. 'change': handleChange
  880. }
  881. })]
  882. );
  883. }
  884. });
  885. // CONCATENATED MODULE: ./packages/upload/src/upload.vue?vue&type=script&lang=js&
  886. /* harmony default export */ var src_uploadvue_type_script_lang_js_ = (uploadvue_type_script_lang_js_);
  887. // CONCATENATED MODULE: ./packages/upload/src/upload.vue
  888. var upload_render, upload_staticRenderFns
  889. /* normalize component */
  890. var upload_component = Object(componentNormalizer["a" /* default */])(
  891. src_uploadvue_type_script_lang_js_,
  892. upload_render,
  893. upload_staticRenderFns,
  894. false,
  895. null,
  896. null,
  897. null
  898. )
  899. /* hot reload */
  900. if (false) { var upload_api; }
  901. upload_component.options.__file = "packages/upload/src/upload.vue"
  902. /* harmony default export */ var src_upload = (upload_component.exports);
  903. // EXTERNAL MODULE: external "element-ui/lib/mixins/migrating"
  904. var migrating_ = __webpack_require__(11);
  905. var migrating_default = /*#__PURE__*/__webpack_require__.n(migrating_);
  906. // CONCATENATED MODULE: ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib??vue-loader-options!./packages/upload/src/index.vue?vue&type=script&lang=js&
  907. function noop() {}
  908. /* harmony default export */ var srcvue_type_script_lang_js_ = ({
  909. name: 'ElUpload',
  910. mixins: [migrating_default.a],
  911. components: {
  912. ElProgress: progress_default.a,
  913. UploadList: upload_list,
  914. Upload: src_upload
  915. },
  916. provide: function provide() {
  917. return {
  918. uploader: this
  919. };
  920. },
  921. inject: {
  922. elForm: {
  923. default: ''
  924. }
  925. },
  926. props: {
  927. action: {
  928. type: String,
  929. required: true
  930. },
  931. headers: {
  932. type: Object,
  933. default: function _default() {
  934. return {};
  935. }
  936. },
  937. data: Object,
  938. multiple: Boolean,
  939. name: {
  940. type: String,
  941. default: 'file'
  942. },
  943. drag: Boolean,
  944. dragger: Boolean,
  945. withCredentials: Boolean,
  946. showFileList: {
  947. type: Boolean,
  948. default: true
  949. },
  950. accept: String,
  951. type: {
  952. type: String,
  953. default: 'select'
  954. },
  955. beforeUpload: Function,
  956. beforeRemove: Function,
  957. onRemove: {
  958. type: Function,
  959. default: noop
  960. },
  961. onChange: {
  962. type: Function,
  963. default: noop
  964. },
  965. onPreview: {
  966. type: Function
  967. },
  968. onSuccess: {
  969. type: Function,
  970. default: noop
  971. },
  972. onProgress: {
  973. type: Function,
  974. default: noop
  975. },
  976. onError: {
  977. type: Function,
  978. default: noop
  979. },
  980. focusAble: {
  981. type: Boolean,
  982. default: true
  983. },
  984. fileList: {
  985. type: Array,
  986. default: function _default() {
  987. return [];
  988. }
  989. },
  990. autoUpload: {
  991. type: Boolean,
  992. default: true
  993. },
  994. listType: {
  995. type: String,
  996. default: 'text' // text,picture,picture-card
  997. },
  998. httpRequest: Function,
  999. disabled: Boolean,
  1000. limit: Number,
  1001. onExceed: {
  1002. type: Function,
  1003. default: noop
  1004. }
  1005. },
  1006. data: function data() {
  1007. return {
  1008. uploadFiles: [],
  1009. dragOver: false,
  1010. draging: false,
  1011. tempIndex: 1
  1012. };
  1013. },
  1014. computed: {
  1015. uploadDisabled: function uploadDisabled() {
  1016. return this.disabled || (this.elForm || {}).disabled;
  1017. }
  1018. },
  1019. watch: {
  1020. listType: function listType(type) {
  1021. if (type === 'picture-card' || type === 'picture') {
  1022. this.uploadFiles = this.uploadFiles.map(function (file) {
  1023. if (!file.url && file.raw) {
  1024. try {
  1025. file.url = URL.createObjectURL(file.raw);
  1026. } catch (err) {
  1027. console.error('[Element Error][Upload]', err);
  1028. }
  1029. }
  1030. return file;
  1031. });
  1032. }
  1033. },
  1034. fileList: {
  1035. immediate: true,
  1036. handler: function handler(fileList) {
  1037. var _this = this;
  1038. this.uploadFiles = fileList.map(function (item) {
  1039. item.uid = item.uid || Date.now() + _this.tempIndex++;
  1040. item.status = item.status || 'success';
  1041. return item;
  1042. });
  1043. }
  1044. }
  1045. },
  1046. methods: {
  1047. handleStart: function handleStart(rawFile) {
  1048. rawFile.uid = Date.now() + this.tempIndex++;
  1049. var file = {
  1050. status: 'ready',
  1051. name: rawFile.name,
  1052. size: rawFile.size,
  1053. percentage: 0,
  1054. uid: rawFile.uid,
  1055. raw: rawFile
  1056. };
  1057. if (this.listType === 'picture-card' || this.listType === 'picture') {
  1058. try {
  1059. file.url = URL.createObjectURL(rawFile);
  1060. } catch (err) {
  1061. console.error('[Element Error][Upload]', err);
  1062. return;
  1063. }
  1064. }
  1065. this.uploadFiles.push(file);
  1066. this.onChange(file, this.uploadFiles);
  1067. },
  1068. handleProgress: function handleProgress(ev, rawFile) {
  1069. var file = this.getFile(rawFile);
  1070. this.onProgress(ev, file, this.uploadFiles);
  1071. file.status = 'uploading';
  1072. file.percentage = ev.percent || 0;
  1073. },
  1074. handleSuccess: function handleSuccess(res, rawFile) {
  1075. var file = this.getFile(rawFile);
  1076. if (file) {
  1077. file.status = 'success';
  1078. file.response = res;
  1079. this.onSuccess(res, file, this.uploadFiles);
  1080. this.onChange(file, this.uploadFiles);
  1081. }
  1082. },
  1083. handleError: function handleError(err, rawFile) {
  1084. var file = this.getFile(rawFile);
  1085. var fileList = this.uploadFiles;
  1086. file.status = 'fail';
  1087. fileList.splice(fileList.indexOf(file), 1);
  1088. this.onError(err, file, this.uploadFiles);
  1089. this.onChange(file, this.uploadFiles);
  1090. },
  1091. handleRemove: function handleRemove(file, raw) {
  1092. var _this2 = this;
  1093. if (raw) {
  1094. file = this.getFile(raw);
  1095. }
  1096. var doRemove = function doRemove() {
  1097. _this2.abort(file);
  1098. var fileList = _this2.uploadFiles;
  1099. fileList.splice(fileList.indexOf(file), 1);
  1100. _this2.onRemove(file, fileList);
  1101. };
  1102. if (!this.beforeRemove) {
  1103. doRemove();
  1104. } else if (typeof this.beforeRemove === 'function') {
  1105. var before = this.beforeRemove(file, this.uploadFiles);
  1106. if (before && before.then) {
  1107. before.then(function () {
  1108. doRemove();
  1109. }, noop);
  1110. } else if (before !== false) {
  1111. doRemove();
  1112. }
  1113. }
  1114. },
  1115. getFile: function getFile(rawFile) {
  1116. var fileList = this.uploadFiles;
  1117. var target = void 0;
  1118. fileList.every(function (item) {
  1119. target = rawFile.uid === item.uid ? item : null;
  1120. return !target;
  1121. });
  1122. return target;
  1123. },
  1124. abort: function abort(file) {
  1125. this.$refs['upload-inner'].abort(file);
  1126. },
  1127. clearFiles: function clearFiles() {
  1128. this.uploadFiles = [];
  1129. },
  1130. submit: function submit() {
  1131. var _this3 = this;
  1132. this.uploadFiles.filter(function (file) {
  1133. return file.status === 'ready';
  1134. }).forEach(function (file) {
  1135. _this3.$refs['upload-inner'].upload(file.raw);
  1136. });
  1137. },
  1138. getMigratingConfig: function getMigratingConfig() {
  1139. return {
  1140. props: {
  1141. 'default-file-list': 'default-file-list is renamed to file-list.',
  1142. 'show-upload-list': 'show-upload-list is renamed to show-file-list.',
  1143. 'thumbnail-mode': 'thumbnail-mode has been deprecated, you can implement the same effect according to this case: http://element.eleme.io/#/zh-CN/component/upload#yong-hu-tou-xiang-shang-chuan'
  1144. }
  1145. };
  1146. }
  1147. },
  1148. beforeDestroy: function beforeDestroy() {
  1149. this.uploadFiles.forEach(function (file) {
  1150. if (file.url && file.url.indexOf('blob:') === 0) {
  1151. URL.revokeObjectURL(file.url);
  1152. }
  1153. });
  1154. },
  1155. render: function render(h) {
  1156. var _this4 = this;
  1157. var uploadList = void 0;
  1158. if (this.showFileList) {
  1159. uploadList = h(
  1160. upload_list,
  1161. {
  1162. attrs: {
  1163. disabled: this.uploadDisabled,
  1164. listType: this.listType,
  1165. files: this.uploadFiles,
  1166. focusAble: this.focusAble,
  1167. handlePreview: this.onPreview },
  1168. on: {
  1169. 'remove': this.handleRemove
  1170. }
  1171. },
  1172. [function (props) {
  1173. if (_this4.$scopedSlots.file) {
  1174. return _this4.$scopedSlots.file({
  1175. file: props.file
  1176. });
  1177. }
  1178. }]
  1179. );
  1180. }
  1181. var uploadData = {
  1182. props: {
  1183. type: this.type,
  1184. drag: this.drag,
  1185. action: this.action,
  1186. multiple: this.multiple,
  1187. 'before-upload': this.beforeUpload,
  1188. 'with-credentials': this.withCredentials,
  1189. headers: this.headers,
  1190. name: this.name,
  1191. data: this.data,
  1192. accept: this.accept,
  1193. fileList: this.uploadFiles,
  1194. autoUpload: this.autoUpload,
  1195. listType: this.listType,
  1196. disabled: this.uploadDisabled,
  1197. limit: this.limit,
  1198. 'on-exceed': this.onExceed,
  1199. 'on-start': this.handleStart,
  1200. 'on-progress': this.handleProgress,
  1201. 'on-success': this.handleSuccess,
  1202. 'on-error': this.handleError,
  1203. 'on-preview': this.onPreview,
  1204. 'on-remove': this.handleRemove,
  1205. 'http-request': this.httpRequest,
  1206. focusAble: this.focusAble
  1207. },
  1208. ref: 'upload-inner'
  1209. };
  1210. var trigger = this.$slots.trigger || this.$slots.default;
  1211. var uploadComponent = h(
  1212. 'upload',
  1213. uploadData,
  1214. [trigger]
  1215. );
  1216. return h('div', [this.listType === 'picture-card' ? uploadList : '', this.$slots.trigger ? [uploadComponent, this.$slots.default] : uploadComponent, this.$slots.tip, this.listType !== 'picture-card' ? uploadList : '']);
  1217. }
  1218. });
  1219. // CONCATENATED MODULE: ./packages/upload/src/index.vue?vue&type=script&lang=js&
  1220. /* harmony default export */ var upload_srcvue_type_script_lang_js_ = (srcvue_type_script_lang_js_);
  1221. // CONCATENATED MODULE: ./packages/upload/src/index.vue
  1222. var src_render, src_staticRenderFns
  1223. /* normalize component */
  1224. var src_component = Object(componentNormalizer["a" /* default */])(
  1225. upload_srcvue_type_script_lang_js_,
  1226. src_render,
  1227. src_staticRenderFns,
  1228. false,
  1229. null,
  1230. null,
  1231. null
  1232. )
  1233. /* hot reload */
  1234. if (false) { var src_api; }
  1235. src_component.options.__file = "packages/upload/src/index.vue"
  1236. /* harmony default export */ var src = (src_component.exports);
  1237. // CONCATENATED MODULE: ./packages/upload/index.js
  1238. /* istanbul ignore next */
  1239. src.install = function (Vue) {
  1240. Vue.component(src.name, src);
  1241. };
  1242. /* harmony default export */ var packages_upload = __webpack_exports__["default"] = (src);
  1243. /***/ }),
  1244. /***/ 6:
  1245. /***/ (function(module, exports) {
  1246. module.exports = require("element-ui/lib/mixins/locale");
  1247. /***/ })
  1248. /******/ });