blob: 13e0014deac4b29cdaebaa799d81f92d2d6529fa [file] [log] [blame]
binquan.qiu7f2665f2020-03-27 17:19:57 +08001module.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 = "";
82/******/
83/******/
84/******/ // Load entry module and return exports
85/******/ return __webpack_require__(__webpack_require__.s = 22);
86/******/ })
87/************************************************************************/
88/******/ ({
89
90/***/ 22:
91/***/ (function(module, exports, __webpack_require__) {
92
93"use strict";
94
95
96Component({
97 options: {
98 addGlobalClass: true
99 },
100 properties: {
101 title: {
102 type: String,
103 value: '图片上传'
104 },
105 sizeType: {
106 type: Array,
107 value: ['original', 'compressed']
108 },
109 sourceType: {
110 type: Array,
111 value: ['album', 'camera']
112 },
113 maxSize: {
114 type: Number,
115 value: 5 * 1024 * 1024
116 },
117 maxCount: {
118 type: Number,
119 value: 1
120 },
121 files: {
122 type: Array,
123 value: [],
124 observer: function observer(newVal, oldVal, changedP) {
125 this.setData({
126 currentFiles: newVal
127 });
128 }
129 },
130 select: {
131 type: Function,
132 value: function value() {}
133 },
134 upload: {
135 type: Function,
136 value: null
137 },
138 tips: {
139 type: String,
140 value: ''
141 },
142 extClass: {
143 type: String,
144 value: ''
145 },
146 showDelete: {
147 type: Boolean,
148 value: true
149 }
150 },
151 data: {
152 currentFiles: [],
153 showPreview: false,
154 previewImageUrls: []
155 },
156 ready: function ready() {},
157
158 methods: {
159 previewImage: function previewImage(e) {
160 var index = e.currentTarget.dataset.index;
161
162 var previewImageUrls = [];
163 this.data.files.map(function (item) {
164 previewImageUrls.push(item.url);
165 });
166 this.setData({
167 previewImageUrls: previewImageUrls,
168 previewCurrent: index,
169 showPreview: true
170 });
171 },
172 chooseImage: function chooseImage(e) {
173 var _this = this;
174
175 if (this.uploading) return;
176 wx.chooseImage({
177 count: this.data.maxCount - this.data.files.length,
178 success: function success(res) {
179 var invalidIndex = -1;
180 res.tempFiles.forEach(function (item, index) {
181 if (item.size > _this.data.maxSize) {
182 invalidIndex = index;
183 }
184 });
185 if (typeof _this.data.select === 'function') {
186 var ret = _this.data.select(res);
187 if (ret === false) {
188 return;
189 }
190 }
191 if (invalidIndex >= 0) {
192 _this.triggerEvent('fail', { type: 1, errMsg: 'chooseImage:fail size exceed ' + _this.data.maxSize, total: res.tempFilePaths.length, index: invalidIndex }, {});
193 return;
194 }
195 var mgr = wx.getFileSystemManager();
196 var contents = res.tempFilePaths.map(function (item) {
197 var fileContent = mgr.readFileSync(item);
198 return fileContent;
199 });
200 var obj = { tempFilePaths: res.tempFilePaths, tempFiles: res.tempFiles, contents: contents };
201 _this.triggerEvent('select', obj, {});
202 var files = res.tempFilePaths.map(function (item, i) {
203 return { loading: true, url: 'data:image/jpg;base64,' + wx.arrayBufferToBase64(contents[i]) };
204 });
205 if (!files || !files.length) return;
206 if (typeof _this.data.upload === 'function') {
207 var len = _this.data.files.length;
208 var newFiles = _this.data.files.concat(files);
209 _this.setData({ files: newFiles, currentFiles: newFiles });
210 _this.loading = true;
211 _this.data.upload(obj).then(function (json) {
212 _this.loading = false;
213 if (json.urls) {
214 var oldFiles = _this.data.files;
215 json.urls.forEach(function (url, index) {
216 oldFiles[len + index].url = url;
217 oldFiles[len + index].loading = false;
218 });
219 _this.setData({ files: oldFiles, currentFiles: newFiles });
220 _this.triggerEvent('success', json, {});
221 } else {
222 _this.triggerEvent('fail', { type: 3, errMsg: 'upload file fail, urls not found' }, {});
223 }
224 }).catch(function (err) {
225 _this.loading = false;
226 var oldFiles = _this.data.files;
227 res.tempFilePaths.map(function (item, index) {
228 oldFiles[len + index].error = true;
229 oldFiles[len + index].loading = false;
230 });
231 _this.setData({ files: oldFiles, currentFiles: newFiles });
232 _this.triggerEvent('fail', { type: 3, errMsg: 'upload file fail', error: err }, {});
233 });
234 }
235 },
236 fail: function fail(_fail) {
237 if (_fail.errMsg.indexOf('chooseImage:fail cancel') >= 0) {
238 _this.triggerEvent('cancel', {}, {});
239 return;
240 }
241 _fail.type = 2;
242 _this.triggerEvent('fail', _fail, {});
243 }
244 });
245 },
246 deletePic: function deletePic(e) {
247 var index = e.detail.index;
248 var files = this.data.files;
249 var file = files.splice(index, 1);
250 this.setData({
251 files: files,
252 currentFiles: files
253 });
254 this.triggerEvent('delete', { index: index, item: file[0] });
255 }
256 }
257});
258
259/***/ })
260
261/******/ });