upload.js 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374
  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 = 51);
  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. /***/ 10:
  180. /***/ (function(module, exports) {
  181. module.exports = require("element-ui/lib/mixins/migrating");
  182. /***/ }),
  183. /***/ 32:
  184. /***/ (function(module, exports) {
  185. module.exports = require("babel-helper-vue-jsx-merge-props");
  186. /***/ }),
  187. /***/ 39:
  188. /***/ (function(module, exports) {
  189. module.exports = require("element-ui/lib/progress");
  190. /***/ }),
  191. /***/ 51:
  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.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. file.status !== "uploading" &&
  248. ["picture-card", "picture"].indexOf(_vm.listType) > -1
  249. ? _c("img", {
  250. staticClass: "el-upload-list__item-thumbnail",
  251. attrs: { src: file.url, alt: "" }
  252. })
  253. : _vm._e(),
  254. _c(
  255. "a",
  256. {
  257. staticClass: "el-upload-list__item-name",
  258. on: {
  259. click: function($event) {
  260. _vm.handleClick(file)
  261. }
  262. }
  263. },
  264. [
  265. _c("i", { staticClass: "el-icon-document" }),
  266. _vm._v(_vm._s(file.name) + "\n ")
  267. ]
  268. ),
  269. _c("label", { staticClass: "el-upload-list__item-status-label" }, [
  270. _c("i", {
  271. class: {
  272. "el-icon-upload-success": true,
  273. "el-icon-circle-check": _vm.listType === "text",
  274. "el-icon-check":
  275. ["picture-card", "picture"].indexOf(_vm.listType) > -1
  276. }
  277. })
  278. ]),
  279. !_vm.disabled
  280. ? _c("i", {
  281. staticClass: "el-icon-close",
  282. on: {
  283. click: function($event) {
  284. _vm.$emit("remove", file)
  285. }
  286. }
  287. })
  288. : _vm._e(),
  289. !_vm.disabled
  290. ? _c("i", { staticClass: "el-icon-close-tip" }, [
  291. _vm._v(_vm._s(_vm.t("el.upload.deleteTip")))
  292. ])
  293. : _vm._e(),
  294. file.status === "uploading"
  295. ? _c("el-progress", {
  296. attrs: {
  297. type: _vm.listType === "picture-card" ? "circle" : "line",
  298. "stroke-width": _vm.listType === "picture-card" ? 6 : 2,
  299. percentage: _vm.parsePercentage(file.percentage)
  300. }
  301. })
  302. : _vm._e(),
  303. _vm.listType === "picture-card"
  304. ? _c("span", { staticClass: "el-upload-list__item-actions" }, [
  305. _vm.handlePreview && _vm.listType === "picture-card"
  306. ? _c(
  307. "span",
  308. {
  309. staticClass: "el-upload-list__item-preview",
  310. on: {
  311. click: function($event) {
  312. _vm.handlePreview(file)
  313. }
  314. }
  315. },
  316. [_c("i", { staticClass: "el-icon-zoom-in" })]
  317. )
  318. : _vm._e(),
  319. !_vm.disabled
  320. ? _c(
  321. "span",
  322. {
  323. staticClass: "el-upload-list__item-delete",
  324. on: {
  325. click: function($event) {
  326. _vm.$emit("remove", file)
  327. }
  328. }
  329. },
  330. [_c("i", { staticClass: "el-icon-delete" })]
  331. )
  332. : _vm._e()
  333. ])
  334. : _vm._e()
  335. ],
  336. 1
  337. )
  338. }),
  339. 0
  340. )
  341. }
  342. var staticRenderFns = []
  343. upload_listvue_type_template_id_173fedf5_render._withStripped = true
  344. // CONCATENATED MODULE: ./packages/upload/src/upload-list.vue?vue&type=template&id=173fedf5&
  345. // EXTERNAL MODULE: external "element-ui/lib/mixins/locale"
  346. var locale_ = __webpack_require__(7);
  347. var locale_default = /*#__PURE__*/__webpack_require__.n(locale_);
  348. // EXTERNAL MODULE: external "element-ui/lib/progress"
  349. var progress_ = __webpack_require__(39);
  350. var progress_default = /*#__PURE__*/__webpack_require__.n(progress_);
  351. // 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&
  352. //
  353. //
  354. //
  355. //
  356. //
  357. //
  358. //
  359. //
  360. //
  361. //
  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. /* harmony default export */ var upload_listvue_type_script_lang_js_ = ({
  415. name: 'ElUploadList',
  416. mixins: [locale_default.a],
  417. data: function data() {
  418. return {
  419. focusing: false
  420. };
  421. },
  422. components: { ElProgress: progress_default.a },
  423. props: {
  424. files: {
  425. type: Array,
  426. default: function _default() {
  427. return [];
  428. }
  429. },
  430. disabled: {
  431. type: Boolean,
  432. default: false
  433. },
  434. handlePreview: Function,
  435. listType: String
  436. },
  437. methods: {
  438. parsePercentage: function parsePercentage(val) {
  439. return parseInt(val, 10);
  440. },
  441. handleClick: function handleClick(file) {
  442. this.handlePreview && this.handlePreview(file);
  443. }
  444. }
  445. });
  446. // CONCATENATED MODULE: ./packages/upload/src/upload-list.vue?vue&type=script&lang=js&
  447. /* harmony default export */ var src_upload_listvue_type_script_lang_js_ = (upload_listvue_type_script_lang_js_);
  448. // EXTERNAL MODULE: ./node_modules/vue-loader/lib/runtime/componentNormalizer.js
  449. var componentNormalizer = __webpack_require__(0);
  450. // CONCATENATED MODULE: ./packages/upload/src/upload-list.vue
  451. /* normalize component */
  452. var component = Object(componentNormalizer["a" /* default */])(
  453. src_upload_listvue_type_script_lang_js_,
  454. upload_listvue_type_template_id_173fedf5_render,
  455. staticRenderFns,
  456. false,
  457. null,
  458. null,
  459. null
  460. )
  461. /* hot reload */
  462. if (false) { var api; }
  463. component.options.__file = "packages/upload/src/upload-list.vue"
  464. /* harmony default export */ var upload_list = (component.exports);
  465. // EXTERNAL MODULE: external "babel-helper-vue-jsx-merge-props"
  466. var external_babel_helper_vue_jsx_merge_props_ = __webpack_require__(32);
  467. var external_babel_helper_vue_jsx_merge_props_default = /*#__PURE__*/__webpack_require__.n(external_babel_helper_vue_jsx_merge_props_);
  468. // CONCATENATED MODULE: ./packages/upload/src/ajax.js
  469. function getError(action, option, xhr) {
  470. var msg = void 0;
  471. if (xhr.response) {
  472. msg = '' + (xhr.response.error || xhr.response);
  473. } else if (xhr.responseText) {
  474. msg = '' + xhr.responseText;
  475. } else {
  476. msg = 'fail to post ' + action + ' ' + xhr.status;
  477. }
  478. var err = new Error(msg);
  479. err.status = xhr.status;
  480. err.method = 'post';
  481. err.url = action;
  482. return err;
  483. }
  484. function getBody(xhr) {
  485. var text = xhr.responseText || xhr.response;
  486. if (!text) {
  487. return text;
  488. }
  489. try {
  490. return JSON.parse(text);
  491. } catch (e) {
  492. return text;
  493. }
  494. }
  495. function upload(option) {
  496. if (typeof XMLHttpRequest === 'undefined') {
  497. return;
  498. }
  499. var xhr = new XMLHttpRequest();
  500. var action = option.action;
  501. if (xhr.upload) {
  502. xhr.upload.onprogress = function progress(e) {
  503. if (e.total > 0) {
  504. e.percent = e.loaded / e.total * 100;
  505. }
  506. option.onProgress(e);
  507. };
  508. }
  509. var formData = new FormData();
  510. if (option.data) {
  511. Object.keys(option.data).forEach(function (key) {
  512. formData.append(key, option.data[key]);
  513. });
  514. }
  515. formData.append(option.filename, option.file, option.file.name);
  516. xhr.onerror = function error(e) {
  517. option.onError(e);
  518. };
  519. xhr.onload = function onload() {
  520. if (xhr.status < 200 || xhr.status >= 300) {
  521. return option.onError(getError(action, option, xhr));
  522. }
  523. option.onSuccess(getBody(xhr));
  524. };
  525. xhr.open('post', action, true);
  526. if (option.withCredentials && 'withCredentials' in xhr) {
  527. xhr.withCredentials = true;
  528. }
  529. var headers = option.headers || {};
  530. for (var item in headers) {
  531. if (headers.hasOwnProperty(item) && headers[item] !== null) {
  532. xhr.setRequestHeader(item, headers[item]);
  533. }
  534. }
  535. xhr.send(formData);
  536. return xhr;
  537. }
  538. // 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&
  539. var upload_draggervue_type_template_id_7ebbf219_render = function() {
  540. var _vm = this
  541. var _h = _vm.$createElement
  542. var _c = _vm._self._c || _h
  543. return _c(
  544. "div",
  545. {
  546. staticClass: "el-upload-dragger",
  547. class: {
  548. "is-dragover": _vm.dragover
  549. },
  550. on: {
  551. drop: function($event) {
  552. $event.preventDefault()
  553. return _vm.onDrop($event)
  554. },
  555. dragover: function($event) {
  556. $event.preventDefault()
  557. return _vm.onDragover($event)
  558. },
  559. dragleave: function($event) {
  560. $event.preventDefault()
  561. _vm.dragover = false
  562. }
  563. }
  564. },
  565. [_vm._t("default")],
  566. 2
  567. )
  568. }
  569. var upload_draggervue_type_template_id_7ebbf219_staticRenderFns = []
  570. upload_draggervue_type_template_id_7ebbf219_render._withStripped = true
  571. // CONCATENATED MODULE: ./packages/upload/src/upload-dragger.vue?vue&type=template&id=7ebbf219&
  572. // 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&
  573. //
  574. //
  575. //
  576. //
  577. //
  578. //
  579. //
  580. //
  581. //
  582. //
  583. //
  584. //
  585. //
  586. /* harmony default export */ var upload_draggervue_type_script_lang_js_ = ({
  587. name: 'ElUploadDrag',
  588. props: {
  589. disabled: Boolean
  590. },
  591. inject: {
  592. uploader: {
  593. default: ''
  594. }
  595. },
  596. data: function data() {
  597. return {
  598. dragover: false
  599. };
  600. },
  601. methods: {
  602. onDragover: function onDragover() {
  603. if (!this.disabled) {
  604. this.dragover = true;
  605. }
  606. },
  607. onDrop: function onDrop(e) {
  608. if (this.disabled || !this.uploader) return;
  609. var accept = this.uploader.accept;
  610. this.dragover = false;
  611. if (!accept) {
  612. this.$emit('file', e.dataTransfer.files);
  613. return;
  614. }
  615. this.$emit('file', [].slice.call(e.dataTransfer.files).filter(function (file) {
  616. var type = file.type,
  617. name = file.name;
  618. var extension = name.indexOf('.') > -1 ? '.' + name.split('.').pop() : '';
  619. var baseType = type.replace(/\/.*$/, '');
  620. return accept.split(',').map(function (type) {
  621. return type.trim();
  622. }).filter(function (type) {
  623. return type;
  624. }).some(function (acceptedType) {
  625. if (/\..+$/.test(acceptedType)) {
  626. return extension === acceptedType;
  627. }
  628. if (/\/\*$/.test(acceptedType)) {
  629. return baseType === acceptedType.replace(/\/\*$/, '');
  630. }
  631. if (/^[^\/]+\/[^\/]+$/.test(acceptedType)) {
  632. return type === acceptedType;
  633. }
  634. return false;
  635. });
  636. }));
  637. }
  638. }
  639. });
  640. // CONCATENATED MODULE: ./packages/upload/src/upload-dragger.vue?vue&type=script&lang=js&
  641. /* harmony default export */ var src_upload_draggervue_type_script_lang_js_ = (upload_draggervue_type_script_lang_js_);
  642. // CONCATENATED MODULE: ./packages/upload/src/upload-dragger.vue
  643. /* normalize component */
  644. var upload_dragger_component = Object(componentNormalizer["a" /* default */])(
  645. src_upload_draggervue_type_script_lang_js_,
  646. upload_draggervue_type_template_id_7ebbf219_render,
  647. upload_draggervue_type_template_id_7ebbf219_staticRenderFns,
  648. false,
  649. null,
  650. null,
  651. null
  652. )
  653. /* hot reload */
  654. if (false) { var upload_dragger_api; }
  655. upload_dragger_component.options.__file = "packages/upload/src/upload-dragger.vue"
  656. /* harmony default export */ var upload_dragger = (upload_dragger_component.exports);
  657. // 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&
  658. /* harmony default export */ var uploadvue_type_script_lang_js_ = ({
  659. inject: ['uploader'],
  660. components: {
  661. UploadDragger: upload_dragger
  662. },
  663. props: {
  664. type: String,
  665. action: {
  666. type: String,
  667. required: true
  668. },
  669. name: {
  670. type: String,
  671. default: 'file'
  672. },
  673. data: Object,
  674. headers: Object,
  675. withCredentials: Boolean,
  676. multiple: Boolean,
  677. accept: String,
  678. onStart: Function,
  679. onProgress: Function,
  680. onSuccess: Function,
  681. onError: Function,
  682. beforeUpload: Function,
  683. drag: Boolean,
  684. onPreview: {
  685. type: Function,
  686. default: function _default() {}
  687. },
  688. onRemove: {
  689. type: Function,
  690. default: function _default() {}
  691. },
  692. fileList: Array,
  693. autoUpload: Boolean,
  694. listType: String,
  695. httpRequest: {
  696. type: Function,
  697. default: upload
  698. },
  699. disabled: Boolean,
  700. limit: Number,
  701. onExceed: Function
  702. },
  703. data: function data() {
  704. return {
  705. mouseover: false,
  706. reqs: {}
  707. };
  708. },
  709. methods: {
  710. isImage: function isImage(str) {
  711. return str.indexOf('image') !== -1;
  712. },
  713. handleChange: function handleChange(ev) {
  714. var files = ev.target.files;
  715. if (!files) return;
  716. this.uploadFiles(files);
  717. },
  718. uploadFiles: function uploadFiles(files) {
  719. var _this = this;
  720. if (this.limit && this.fileList.length + files.length > this.limit) {
  721. this.onExceed && this.onExceed(files, this.fileList);
  722. return;
  723. }
  724. var postFiles = Array.prototype.slice.call(files);
  725. if (!this.multiple) {
  726. postFiles = postFiles.slice(0, 1);
  727. }
  728. if (postFiles.length === 0) {
  729. return;
  730. }
  731. postFiles.forEach(function (rawFile) {
  732. _this.onStart(rawFile);
  733. if (_this.autoUpload) _this.upload(rawFile);
  734. });
  735. },
  736. upload: function upload(rawFile) {
  737. var _this2 = this;
  738. this.$refs.input.value = null;
  739. if (!this.beforeUpload) {
  740. return this.post(rawFile);
  741. }
  742. var before = this.beforeUpload(rawFile);
  743. if (before && before.then) {
  744. before.then(function (processedFile) {
  745. var fileType = Object.prototype.toString.call(processedFile);
  746. if (fileType === '[object File]' || fileType === '[object Blob]') {
  747. if (fileType === '[object Blob]') {
  748. processedFile = new File([processedFile], rawFile.name, {
  749. type: rawFile.type
  750. });
  751. }
  752. for (var p in rawFile) {
  753. if (rawFile.hasOwnProperty(p)) {
  754. processedFile[p] = rawFile[p];
  755. }
  756. }
  757. _this2.post(processedFile);
  758. } else {
  759. _this2.post(rawFile);
  760. }
  761. }, function () {
  762. _this2.onRemove(null, rawFile);
  763. });
  764. } else if (before !== false) {
  765. this.post(rawFile);
  766. } else {
  767. this.onRemove(null, rawFile);
  768. }
  769. },
  770. abort: function abort(file) {
  771. var reqs = this.reqs;
  772. if (file) {
  773. var uid = file;
  774. if (file.uid) uid = file.uid;
  775. if (reqs[uid]) {
  776. reqs[uid].abort();
  777. }
  778. } else {
  779. Object.keys(reqs).forEach(function (uid) {
  780. if (reqs[uid]) reqs[uid].abort();
  781. delete reqs[uid];
  782. });
  783. }
  784. },
  785. post: function post(rawFile) {
  786. var _this3 = this;
  787. var uid = rawFile.uid;
  788. var options = {
  789. headers: this.headers,
  790. withCredentials: this.withCredentials,
  791. file: rawFile,
  792. data: this.data,
  793. filename: this.name,
  794. action: this.action,
  795. onProgress: function onProgress(e) {
  796. _this3.onProgress(e, rawFile);
  797. },
  798. onSuccess: function onSuccess(res) {
  799. _this3.onSuccess(res, rawFile);
  800. delete _this3.reqs[uid];
  801. },
  802. onError: function onError(err) {
  803. _this3.onError(err, rawFile);
  804. delete _this3.reqs[uid];
  805. }
  806. };
  807. var req = this.httpRequest(options);
  808. this.reqs[uid] = req;
  809. if (req && req.then) {
  810. req.then(options.onSuccess, options.onError);
  811. }
  812. },
  813. handleClick: function handleClick() {
  814. if (!this.disabled) {
  815. this.$refs.input.value = null;
  816. this.$refs.input.click();
  817. }
  818. },
  819. handleKeydown: function handleKeydown(e) {
  820. if (e.target !== e.currentTarget) return;
  821. if (e.keyCode === 13 || e.keyCode === 32) {
  822. this.handleClick();
  823. }
  824. }
  825. },
  826. render: function render(h) {
  827. var handleClick = this.handleClick,
  828. drag = this.drag,
  829. name = this.name,
  830. handleChange = this.handleChange,
  831. multiple = this.multiple,
  832. accept = this.accept,
  833. listType = this.listType,
  834. uploadFiles = this.uploadFiles,
  835. disabled = this.disabled,
  836. handleKeydown = this.handleKeydown;
  837. var data = {
  838. class: {
  839. 'el-upload': true
  840. },
  841. on: {
  842. click: handleClick,
  843. keydown: handleKeydown
  844. }
  845. };
  846. data.class['el-upload--' + listType] = true;
  847. return h(
  848. 'div',
  849. external_babel_helper_vue_jsx_merge_props_default()([data, {
  850. attrs: { tabindex: '0' }
  851. }]),
  852. [drag ? h(
  853. 'upload-dragger',
  854. {
  855. attrs: { disabled: disabled },
  856. on: {
  857. 'file': uploadFiles
  858. }
  859. },
  860. [this.$slots.default]
  861. ) : this.$slots.default, h('input', { 'class': 'el-upload__input', attrs: { type: 'file', name: name, multiple: multiple, accept: accept },
  862. ref: 'input', on: {
  863. 'change': handleChange
  864. }
  865. })]
  866. );
  867. }
  868. });
  869. // CONCATENATED MODULE: ./packages/upload/src/upload.vue?vue&type=script&lang=js&
  870. /* harmony default export */ var src_uploadvue_type_script_lang_js_ = (uploadvue_type_script_lang_js_);
  871. // CONCATENATED MODULE: ./packages/upload/src/upload.vue
  872. var upload_render, upload_staticRenderFns
  873. /* normalize component */
  874. var upload_component = Object(componentNormalizer["a" /* default */])(
  875. src_uploadvue_type_script_lang_js_,
  876. upload_render,
  877. upload_staticRenderFns,
  878. false,
  879. null,
  880. null,
  881. null
  882. )
  883. /* hot reload */
  884. if (false) { var upload_api; }
  885. upload_component.options.__file = "packages/upload/src/upload.vue"
  886. /* harmony default export */ var src_upload = (upload_component.exports);
  887. // EXTERNAL MODULE: external "element-ui/lib/mixins/migrating"
  888. var migrating_ = __webpack_require__(10);
  889. var migrating_default = /*#__PURE__*/__webpack_require__.n(migrating_);
  890. // 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&
  891. function noop() {}
  892. /* harmony default export */ var srcvue_type_script_lang_js_ = ({
  893. name: 'ElUpload',
  894. mixins: [migrating_default.a],
  895. components: {
  896. ElProgress: progress_default.a,
  897. UploadList: upload_list,
  898. Upload: src_upload
  899. },
  900. provide: function provide() {
  901. return {
  902. uploader: this
  903. };
  904. },
  905. inject: {
  906. elForm: {
  907. default: ''
  908. }
  909. },
  910. props: {
  911. action: {
  912. type: String,
  913. required: true
  914. },
  915. headers: {
  916. type: Object,
  917. default: function _default() {
  918. return {};
  919. }
  920. },
  921. data: Object,
  922. multiple: Boolean,
  923. name: {
  924. type: String,
  925. default: 'file'
  926. },
  927. drag: Boolean,
  928. dragger: Boolean,
  929. withCredentials: Boolean,
  930. showFileList: {
  931. type: Boolean,
  932. default: true
  933. },
  934. accept: String,
  935. type: {
  936. type: String,
  937. default: 'select'
  938. },
  939. beforeUpload: Function,
  940. beforeRemove: Function,
  941. onRemove: {
  942. type: Function,
  943. default: noop
  944. },
  945. onChange: {
  946. type: Function,
  947. default: noop
  948. },
  949. onPreview: {
  950. type: Function
  951. },
  952. onSuccess: {
  953. type: Function,
  954. default: noop
  955. },
  956. onProgress: {
  957. type: Function,
  958. default: noop
  959. },
  960. onError: {
  961. type: Function,
  962. default: noop
  963. },
  964. fileList: {
  965. type: Array,
  966. default: function _default() {
  967. return [];
  968. }
  969. },
  970. autoUpload: {
  971. type: Boolean,
  972. default: true
  973. },
  974. listType: {
  975. type: String,
  976. default: 'text' // text,picture,picture-card
  977. },
  978. httpRequest: Function,
  979. disabled: Boolean,
  980. limit: Number,
  981. onExceed: {
  982. type: Function,
  983. default: noop
  984. }
  985. },
  986. data: function data() {
  987. return {
  988. uploadFiles: [],
  989. dragOver: false,
  990. draging: false,
  991. tempIndex: 1
  992. };
  993. },
  994. computed: {
  995. uploadDisabled: function uploadDisabled() {
  996. return this.disabled || (this.elForm || {}).disabled;
  997. }
  998. },
  999. watch: {
  1000. listType: function listType(type) {
  1001. if (type === 'picture-card' || type === 'picture') {
  1002. this.uploadFiles = this.uploadFiles.map(function (file) {
  1003. if (!file.url && file.raw) {
  1004. try {
  1005. file.url = URL.createObjectURL(file.raw);
  1006. } catch (err) {
  1007. console.error('[Element Error][Upload]', err);
  1008. }
  1009. }
  1010. return file;
  1011. });
  1012. }
  1013. },
  1014. fileList: {
  1015. immediate: true,
  1016. handler: function handler(fileList) {
  1017. var _this = this;
  1018. this.uploadFiles = fileList.map(function (item) {
  1019. item.uid = item.uid || Date.now() + _this.tempIndex++;
  1020. item.status = item.status || 'success';
  1021. return item;
  1022. });
  1023. }
  1024. }
  1025. },
  1026. methods: {
  1027. handleStart: function handleStart(rawFile) {
  1028. rawFile.uid = Date.now() + this.tempIndex++;
  1029. var file = {
  1030. status: 'ready',
  1031. name: rawFile.name,
  1032. size: rawFile.size,
  1033. percentage: 0,
  1034. uid: rawFile.uid,
  1035. raw: rawFile
  1036. };
  1037. if (this.listType === 'picture-card' || this.listType === 'picture') {
  1038. try {
  1039. file.url = URL.createObjectURL(rawFile);
  1040. } catch (err) {
  1041. console.error('[Element Error][Upload]', err);
  1042. return;
  1043. }
  1044. }
  1045. this.uploadFiles.push(file);
  1046. this.onChange(file, this.uploadFiles);
  1047. },
  1048. handleProgress: function handleProgress(ev, rawFile) {
  1049. var file = this.getFile(rawFile);
  1050. this.onProgress(ev, file, this.uploadFiles);
  1051. file.status = 'uploading';
  1052. file.percentage = ev.percent || 0;
  1053. },
  1054. handleSuccess: function handleSuccess(res, rawFile) {
  1055. var file = this.getFile(rawFile);
  1056. if (file) {
  1057. file.status = 'success';
  1058. file.response = res;
  1059. this.onSuccess(res, file, this.uploadFiles);
  1060. this.onChange(file, this.uploadFiles);
  1061. }
  1062. },
  1063. handleError: function handleError(err, rawFile) {
  1064. var file = this.getFile(rawFile);
  1065. var fileList = this.uploadFiles;
  1066. file.status = 'fail';
  1067. fileList.splice(fileList.indexOf(file), 1);
  1068. this.onError(err, file, this.uploadFiles);
  1069. this.onChange(file, this.uploadFiles);
  1070. },
  1071. handleRemove: function handleRemove(file, raw) {
  1072. var _this2 = this;
  1073. if (raw) {
  1074. file = this.getFile(raw);
  1075. }
  1076. var doRemove = function doRemove() {
  1077. _this2.abort(file);
  1078. var fileList = _this2.uploadFiles;
  1079. fileList.splice(fileList.indexOf(file), 1);
  1080. _this2.onRemove(file, fileList);
  1081. };
  1082. if (!this.beforeRemove) {
  1083. doRemove();
  1084. } else if (typeof this.beforeRemove === 'function') {
  1085. var before = this.beforeRemove(file, this.uploadFiles);
  1086. if (before && before.then) {
  1087. before.then(function () {
  1088. doRemove();
  1089. }, noop);
  1090. } else if (before !== false) {
  1091. doRemove();
  1092. }
  1093. }
  1094. },
  1095. getFile: function getFile(rawFile) {
  1096. var fileList = this.uploadFiles;
  1097. var target = void 0;
  1098. fileList.every(function (item) {
  1099. target = rawFile.uid === item.uid ? item : null;
  1100. return !target;
  1101. });
  1102. return target;
  1103. },
  1104. abort: function abort(file) {
  1105. this.$refs['upload-inner'].abort(file);
  1106. },
  1107. clearFiles: function clearFiles() {
  1108. this.uploadFiles = [];
  1109. },
  1110. submit: function submit() {
  1111. var _this3 = this;
  1112. this.uploadFiles.filter(function (file) {
  1113. return file.status === 'ready';
  1114. }).forEach(function (file) {
  1115. _this3.$refs['upload-inner'].upload(file.raw);
  1116. });
  1117. },
  1118. getMigratingConfig: function getMigratingConfig() {
  1119. return {
  1120. props: {
  1121. 'default-file-list': 'default-file-list is renamed to file-list.',
  1122. 'show-upload-list': 'show-upload-list is renamed to show-file-list.',
  1123. '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'
  1124. }
  1125. };
  1126. }
  1127. },
  1128. beforeDestroy: function beforeDestroy() {
  1129. this.uploadFiles.forEach(function (file) {
  1130. if (file.url && file.url.indexOf('blob:') === 0) {
  1131. URL.revokeObjectURL(file.url);
  1132. }
  1133. });
  1134. },
  1135. render: function render(h) {
  1136. var uploadList = void 0;
  1137. if (this.showFileList) {
  1138. uploadList = h(upload_list, {
  1139. attrs: {
  1140. disabled: this.uploadDisabled,
  1141. listType: this.listType,
  1142. files: this.uploadFiles,
  1143. handlePreview: this.onPreview },
  1144. on: {
  1145. 'remove': this.handleRemove
  1146. }
  1147. });
  1148. }
  1149. var uploadData = {
  1150. props: {
  1151. type: this.type,
  1152. drag: this.drag,
  1153. action: this.action,
  1154. multiple: this.multiple,
  1155. 'before-upload': this.beforeUpload,
  1156. 'with-credentials': this.withCredentials,
  1157. headers: this.headers,
  1158. name: this.name,
  1159. data: this.data,
  1160. accept: this.accept,
  1161. fileList: this.uploadFiles,
  1162. autoUpload: this.autoUpload,
  1163. listType: this.listType,
  1164. disabled: this.uploadDisabled,
  1165. limit: this.limit,
  1166. 'on-exceed': this.onExceed,
  1167. 'on-start': this.handleStart,
  1168. 'on-progress': this.handleProgress,
  1169. 'on-success': this.handleSuccess,
  1170. 'on-error': this.handleError,
  1171. 'on-preview': this.onPreview,
  1172. 'on-remove': this.handleRemove,
  1173. 'http-request': this.httpRequest
  1174. },
  1175. ref: 'upload-inner'
  1176. };
  1177. var trigger = this.$slots.trigger || this.$slots.default;
  1178. var uploadComponent = h(
  1179. 'upload',
  1180. uploadData,
  1181. [trigger]
  1182. );
  1183. return h('div', [this.listType === 'picture-card' ? uploadList : '', this.$slots.trigger ? [uploadComponent, this.$slots.default] : uploadComponent, this.$slots.tip, this.listType !== 'picture-card' ? uploadList : '']);
  1184. }
  1185. });
  1186. // CONCATENATED MODULE: ./packages/upload/src/index.vue?vue&type=script&lang=js&
  1187. /* harmony default export */ var upload_srcvue_type_script_lang_js_ = (srcvue_type_script_lang_js_);
  1188. // CONCATENATED MODULE: ./packages/upload/src/index.vue
  1189. var src_render, src_staticRenderFns
  1190. /* normalize component */
  1191. var src_component = Object(componentNormalizer["a" /* default */])(
  1192. upload_srcvue_type_script_lang_js_,
  1193. src_render,
  1194. src_staticRenderFns,
  1195. false,
  1196. null,
  1197. null,
  1198. null
  1199. )
  1200. /* hot reload */
  1201. if (false) { var src_api; }
  1202. src_component.options.__file = "packages/upload/src/index.vue"
  1203. /* harmony default export */ var src = (src_component.exports);
  1204. // CONCATENATED MODULE: ./packages/upload/index.js
  1205. /* istanbul ignore next */
  1206. src.install = function (Vue) {
  1207. Vue.component(src.name, src);
  1208. };
  1209. /* harmony default export */ var packages_upload = __webpack_exports__["default"] = (src);
  1210. /***/ }),
  1211. /***/ 7:
  1212. /***/ (function(module, exports) {
  1213. module.exports = require("element-ui/lib/mixins/locale");
  1214. /***/ })
  1215. /******/ });