image-upload.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. exports.ids = [15];
  2. exports.modules = {
  3. /***/ 207:
  4. /***/ (function(module, exports) {
  5. // Exports
  6. module.exports = {
  7. };
  8. /***/ }),
  9. /***/ 228:
  10. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  11. "use strict";
  12. __webpack_require__.r(__webpack_exports__);
  13. /* harmony import */ var _node_modules_css_loader_dist_cjs_js_ref_7_oneOf_1_0_node_modules_vue_loader_lib_loaders_stylePostLoader_js_node_modules_postcss_loader_dist_cjs_js_ref_7_oneOf_1_1_node_modules_sass_loader_dist_cjs_js_ref_7_oneOf_1_2_node_modules_nuxt_components_dist_loader_js_ref_0_0_node_modules_vue_loader_lib_index_js_vue_loader_options_ImageUpload_vue_vue_type_style_index_0_id_596f82bc_prod_lang_scss_scoped_true__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(207);
  14. /* harmony import */ var _node_modules_css_loader_dist_cjs_js_ref_7_oneOf_1_0_node_modules_vue_loader_lib_loaders_stylePostLoader_js_node_modules_postcss_loader_dist_cjs_js_ref_7_oneOf_1_1_node_modules_sass_loader_dist_cjs_js_ref_7_oneOf_1_2_node_modules_nuxt_components_dist_loader_js_ref_0_0_node_modules_vue_loader_lib_index_js_vue_loader_options_ImageUpload_vue_vue_type_style_index_0_id_596f82bc_prod_lang_scss_scoped_true__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_node_modules_css_loader_dist_cjs_js_ref_7_oneOf_1_0_node_modules_vue_loader_lib_loaders_stylePostLoader_js_node_modules_postcss_loader_dist_cjs_js_ref_7_oneOf_1_1_node_modules_sass_loader_dist_cjs_js_ref_7_oneOf_1_2_node_modules_nuxt_components_dist_loader_js_ref_0_0_node_modules_vue_loader_lib_index_js_vue_loader_options_ImageUpload_vue_vue_type_style_index_0_id_596f82bc_prod_lang_scss_scoped_true__WEBPACK_IMPORTED_MODULE_0__);
  15. /* harmony reexport (unknown) */ for(var __WEBPACK_IMPORT_KEY__ in _node_modules_css_loader_dist_cjs_js_ref_7_oneOf_1_0_node_modules_vue_loader_lib_loaders_stylePostLoader_js_node_modules_postcss_loader_dist_cjs_js_ref_7_oneOf_1_1_node_modules_sass_loader_dist_cjs_js_ref_7_oneOf_1_2_node_modules_nuxt_components_dist_loader_js_ref_0_0_node_modules_vue_loader_lib_index_js_vue_loader_options_ImageUpload_vue_vue_type_style_index_0_id_596f82bc_prod_lang_scss_scoped_true__WEBPACK_IMPORTED_MODULE_0__) if(["default"].indexOf(__WEBPACK_IMPORT_KEY__) < 0) (function(key) { __webpack_require__.d(__webpack_exports__, key, function() { return _node_modules_css_loader_dist_cjs_js_ref_7_oneOf_1_0_node_modules_vue_loader_lib_loaders_stylePostLoader_js_node_modules_postcss_loader_dist_cjs_js_ref_7_oneOf_1_1_node_modules_sass_loader_dist_cjs_js_ref_7_oneOf_1_2_node_modules_nuxt_components_dist_loader_js_ref_0_0_node_modules_vue_loader_lib_index_js_vue_loader_options_ImageUpload_vue_vue_type_style_index_0_id_596f82bc_prod_lang_scss_scoped_true__WEBPACK_IMPORTED_MODULE_0__[key]; }) }(__WEBPACK_IMPORT_KEY__));
  16. /***/ }),
  17. /***/ 245:
  18. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  19. "use strict";
  20. // ESM COMPAT FLAG
  21. __webpack_require__.r(__webpack_exports__);
  22. // CONCATENATED MODULE: ./node_modules/babel-loader/lib??ref--2-0!./node_modules/vue-loader/lib/loaders/templateLoader.js??ref--6!./node_modules/@nuxt/components/dist/loader.js??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./components/ImageUpload.vue?vue&type=template&id=596f82bc&scoped=true
  23. var render = function render() {
  24. var _vm = this,
  25. _c = _vm._self._c;
  26. return _c('div', {
  27. staticClass: "com-image-upload"
  28. }, [_c('draggable', {
  29. staticClass: "flex start wrap",
  30. attrs: {
  31. "draggable": ".image-item"
  32. },
  33. on: {
  34. "end": _vm.end
  35. },
  36. model: {
  37. value: _vm.imageList,
  38. callback: function ($$v) {
  39. _vm.imageList = $$v;
  40. },
  41. expression: "imageList"
  42. }
  43. }, [_vm._l(_vm.imageList, function (item, index) {
  44. return _c('div', {
  45. key: item.uid || index,
  46. staticClass: "image-item flex",
  47. style: {
  48. width: _vm.width,
  49. height: _vm.height
  50. }
  51. }, [_c('img', {
  52. attrs: {
  53. "src": item.url,
  54. "alt": ""
  55. }
  56. }), _vm._v(" "), _c('div', {
  57. staticClass: "action-area flex center"
  58. }, [!_vm.disablePreview ? _c('span', {
  59. staticClass: "action-icon",
  60. on: {
  61. "click": function ($event) {
  62. return _vm.handlePictureCardPreview(item);
  63. }
  64. }
  65. }, [_c('i', {
  66. staticClass: "el-icon-zoom-in"
  67. })]) : _vm._e(), _vm._v(" "), _c('span', {
  68. staticClass: "action-icon",
  69. on: {
  70. "click": function ($event) {
  71. return _vm.handleRemove(index);
  72. }
  73. }
  74. }, [_c('i', {
  75. staticClass: "el-icon-delete"
  76. })])])]);
  77. }), _vm._v(" "), _c('el-progress', {
  78. directives: [{
  79. name: "show",
  80. rawName: "v-show",
  81. value: _vm.loading,
  82. expression: "loading"
  83. }],
  84. staticStyle: {
  85. "margin": "8px"
  86. },
  87. attrs: {
  88. "type": "circle",
  89. "percentage": _vm.uploadPercent,
  90. "width": Number(_vm.width.slice(0, _vm.width.length - 2))
  91. }
  92. }), _vm._v(" "), _c('div', {
  93. staticClass: "upload-wrap",
  94. class: {
  95. hide: _vm.loading || _vm.imageList.length >= _vm.max
  96. },
  97. style: {
  98. width: _vm.width,
  99. height: _vm.height
  100. }
  101. }, [_c('el-upload', {
  102. ref: "pictureUpload",
  103. staticClass: "custom-upload-item",
  104. attrs: {
  105. "multiple": true,
  106. "limit": _vm.max,
  107. "action": "",
  108. "drag": "",
  109. "accept": ".jpg,.png,.jpeg",
  110. "list-type": "picture-card",
  111. "file-list": _vm.imageList,
  112. "show-file-list": false,
  113. "auto-upload": false,
  114. "on-remove": _vm.handleRemove,
  115. "on-preview": _vm.handlePictureCardPreview,
  116. "on-change": (file, fileList) => {
  117. _vm.handleUpload(file, fileList);
  118. }
  119. }
  120. }, [_c('i', {
  121. staticClass: "el-icon-plus avatar-uploader-icon"
  122. })])], 1)], 2), _vm._ssrNode(" "), _c('el-dialog', {
  123. attrs: {
  124. "visible": _vm.imageDialogVisible
  125. },
  126. on: {
  127. "update:visible": function ($event) {
  128. _vm.imageDialogVisible = $event;
  129. }
  130. }
  131. }, [_c('img', {
  132. attrs: {
  133. "width": "100%",
  134. "src": _vm.imageUrl,
  135. "alt": ""
  136. }
  137. })])], 2);
  138. };
  139. var staticRenderFns = [];
  140. // CONCATENATED MODULE: ./components/ImageUpload.vue?vue&type=template&id=596f82bc&scoped=true
  141. // EXTERNAL MODULE: external "vuedraggable"
  142. var external_vuedraggable_ = __webpack_require__(143);
  143. var external_vuedraggable_default = /*#__PURE__*/__webpack_require__.n(external_vuedraggable_);
  144. // CONCATENATED MODULE: ./node_modules/babel-loader/lib??ref--2-0!./node_modules/@nuxt/components/dist/loader.js??ref--0-0!./node_modules/vue-loader/lib??vue-loader-options!./components/ImageUpload.vue?vue&type=script&lang=js
  145. // import { common } from '@/api'
  146. /* harmony default export */ var ImageUploadvue_type_script_lang_js = ({
  147. name: 'ImageUpload',
  148. components: {
  149. draggable: external_vuedraggable_default.a
  150. },
  151. props: {
  152. list: {
  153. type: Array,
  154. default: () => []
  155. },
  156. max: {
  157. type: Number,
  158. default: 16
  159. },
  160. disablePreview: {
  161. type: Boolean,
  162. default: false
  163. },
  164. width: {
  165. type: String,
  166. default: '150px'
  167. },
  168. height: {
  169. type: String,
  170. default: '150px'
  171. }
  172. },
  173. data() {
  174. return {
  175. // 组件内部数据.
  176. imageList: [],
  177. loading: false,
  178. uploadPercent: 0,
  179. imageDialogVisible: false,
  180. // 预览大图的url, 每次点击都会更新
  181. imageUrl: ''
  182. };
  183. },
  184. computed: {
  185. fulled() {
  186. return 0;
  187. }
  188. },
  189. watch: {
  190. list() {
  191. this.imageList = JSON.parse(JSON.stringify(this.list));
  192. }
  193. },
  194. mounted() {
  195. this.updateList();
  196. },
  197. methods: {
  198. handleUpload(file, fileList) {
  199. this.fileList = [];
  200. if (file.status === 'ready') {
  201. this.loading = true;
  202. const interval = setInterval(() => {
  203. if (this.uploadPercent >= 99) {
  204. clearInterval(interval);
  205. return;
  206. }
  207. this.uploadPercent += 1; // 进度条进度
  208. }, 100);
  209. }
  210. const formData = new FormData();
  211. fileList.forEach(file => {
  212. formData.append('file', file.raw);
  213. });
  214. formData.append('type', 1);
  215. this.$axios.post(`/uk-api/user_base/imagesUpload`, formData).then(response => {
  216. if (response.result.code === 200) {
  217. this.imageList.push({
  218. url: response.result.data,
  219. uid: file.uid
  220. });
  221. this.updateList();
  222. return;
  223. }
  224. this.$message({
  225. message: response.result.message,
  226. type: 'warning'
  227. });
  228. }).catch(error => {
  229. console.log(error, 'component upload image error');
  230. this.$message.error(error.response.data.msg);
  231. }).finally(() => {
  232. this.loading = false;
  233. // 进度条恢复到初始状态
  234. this.uploadPercent = 0;
  235. });
  236. },
  237. handleRemove(index) {
  238. this.imageList.splice(index, 1);
  239. this.updateList();
  240. },
  241. handlePictureCardPreview(file) {
  242. this.imageUrl = file.url;
  243. this.imageDialogVisible = true;
  244. },
  245. // 每次更新imageList后手动更新父组件的数据, 不能用watch自动更新, 因为同时要watch prop值更新iamgeList, 同时watch会死循环.
  246. // 直接把prop数据绑定到dragable 和 el-upload的话vue和eslint会报错, 也可能造成调试困难
  247. updateList() {
  248. this.$emit('update:list', JSON.parse(JSON.stringify(this.imageList)));
  249. },
  250. end() {
  251. this.updateList();
  252. }
  253. }
  254. });
  255. // CONCATENATED MODULE: ./components/ImageUpload.vue?vue&type=script&lang=js
  256. /* harmony default export */ var components_ImageUploadvue_type_script_lang_js = (ImageUploadvue_type_script_lang_js);
  257. // EXTERNAL MODULE: ./node_modules/vue-loader/lib/runtime/componentNormalizer.js
  258. var componentNormalizer = __webpack_require__(2);
  259. // CONCATENATED MODULE: ./components/ImageUpload.vue
  260. function injectStyles (context) {
  261. var style0 = __webpack_require__(228)
  262. if (style0.__inject__) style0.__inject__(context)
  263. }
  264. /* normalize component */
  265. var component = Object(componentNormalizer["a" /* default */])(
  266. components_ImageUploadvue_type_script_lang_js,
  267. render,
  268. staticRenderFns,
  269. false,
  270. injectStyles,
  271. "596f82bc",
  272. "7f6e537e"
  273. )
  274. /* harmony default export */ var ImageUpload = __webpack_exports__["default"] = (component.exports);
  275. /***/ })
  276. };;
  277. //# sourceMappingURL=image-upload.js.map