upload.js 36 KB

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