xs-common-plugins 1.1.2 → 1.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (139) hide show
  1. package/README.md +37 -0
  2. package/package.json +1 -1
  3. package/src/App.vue +11 -11
  4. package/src/common/common.js +143 -14
  5. package/src/common/createMenuId.js +7 -7
  6. package/src/common/uploadImgToBase64.js +12 -12
  7. package/src/common/utils.js +95 -95
  8. package/src/components/Breadcrumb/index.vue +81 -81
  9. package/src/components/Col_TableCell/data.js +4 -4
  10. package/src/components/Col_TableCell/index.scss +77 -77
  11. package/src/components/Col_TableCell/index.vue +43 -43
  12. package/src/components/Col_TableCell/methods.js +19 -19
  13. package/src/components/Hamburger/index.vue +44 -44
  14. package/src/components/ReportCmp/data.js +3 -3
  15. package/src/components/ReportCmp/index.scss +29 -29
  16. package/src/components/ReportCmp/index.vue +2 -2
  17. package/src/components/ReportCmp/methods.js +30 -30
  18. package/src/components/Search/cascader/data.js +3 -3
  19. package/src/components/Search/cascader/index.scss +17 -17
  20. package/src/components/Search/cascader/index.vue +96 -96
  21. package/src/components/Search/cascader/methods.js +41 -41
  22. package/src/components/Search/data.js +5 -5
  23. package/src/components/Search/hk_cascader/index.vue +104 -104
  24. package/src/components/Search/hk_cascader_qudao/index.vue +94 -94
  25. package/src/components/Search/methods.js +86 -86
  26. package/src/components/Search/product_option/data.js +3 -3
  27. package/src/components/Search/product_option/index.scss +68 -68
  28. package/src/components/Search/product_option/index.vue +419 -419
  29. package/src/components/Search/product_option/methods.js +46 -46
  30. package/src/components/Search/select/data.js +3 -3
  31. package/src/components/Search/select/index.scss +2 -2
  32. package/src/components/Search/select/index.vue +114 -114
  33. package/src/components/Search/select/methods.js +51 -51
  34. package/src/components/Search_filter/data.js +5 -5
  35. package/src/components/Search_filter/index.vue +88 -88
  36. package/src/components/Search_filter/methods.js +43 -43
  37. package/src/components/TableCmp/data.js +3 -3
  38. package/src/components/TableCmp/index.scss +22 -22
  39. package/src/components/TableCmp/index.vue +98 -98
  40. package/src/components/TableCmp/methods.js +35 -35
  41. package/src/components/home/BarChart.vue +118 -118
  42. package/src/components/home/LineChart.vue +146 -146
  43. package/src/components/home/Panel.vue +135 -135
  44. package/src/components/home/PanelGroup.vue +146 -146
  45. package/src/components/home/PieChart.vue +81 -81
  46. package/src/components/home/RaddarChart.vue +119 -119
  47. package/src/components/home/TabLayout.vue +88 -88
  48. package/src/components/home/TableList.vue +158 -158
  49. package/src/components/home/Teng.vue +248 -248
  50. package/src/components/home/TransactionTable.vue +49 -49
  51. package/src/components/home/mixins/resize.js +55 -55
  52. package/src/components/im/methods.js +25 -25
  53. package/src/components/image-singleUpload/data.js +3 -3
  54. package/src/components/image-singleUpload/index.scss +26 -26
  55. package/src/components/image-singleUpload/index.vue +56 -56
  56. package/src/components/image-singleUpload/methods.js +30 -30
  57. package/src/components/image-upload/data.js +7 -7
  58. package/src/components/image-upload/index.vue +41 -41
  59. package/src/components/image-upload/methods.js +80 -80
  60. package/src/components/multiple-image-upload/data.js +11 -11
  61. package/src/components/multiple-image-upload/index.scss +8 -8
  62. package/src/components/multiple-image-upload/index.vue +63 -63
  63. package/src/components/multiple-image-upload/methods.js +45 -45
  64. package/src/components/pro-upload/data.js +3 -3
  65. package/src/components/pro-upload/index.scss +4 -4
  66. package/src/components/pro-upload/index.vue +89 -89
  67. package/src/components/pro-upload/methods.js +86 -86
  68. package/src/components/report_set/index.scss +44 -44
  69. package/src/components/report_set/index.vue +153 -153
  70. package/src/components/search-page/src/index.scss +5 -5
  71. package/src/components/search-page/src/index.vue +76 -76
  72. package/src/components/search-page/src/methods.js +36 -36
  73. package/src/mixin/dialog.js +31 -31
  74. package/src/mixin/dlg.js +46 -46
  75. package/src/mixin/newDialog.js +19 -19
  76. package/src/mixin/report.js +82 -82
  77. package/src/mixin/table.js +93 -93
  78. package/src/mixin/tableCell/colTableCell_analysis.js +103 -103
  79. package/src/mixin/upload.js +22 -22
  80. package/src/mixin/vmodel.js +26 -26
  81. package/src/plugins/im/components/conversation-list/index.css +91 -91
  82. package/src/plugins/im/components/conversation-list/index.json +3 -3
  83. package/src/plugins/im/components/conversation-list/index.vue +89 -89
  84. package/src/plugins/im/components/loading/loading.css +69 -69
  85. package/src/plugins/im/components/loading/loading.json +3 -3
  86. package/src/plugins/im/components/loading/loading.vue +14 -14
  87. package/src/plugins/im/components/msg-image/index.json +3 -3
  88. package/src/plugins/im/components/msg-text/index.json +3 -3
  89. package/src/plugins/im/components/msg-text/index.vue +24 -24
  90. package/src/plugins/im/im-plug-in/Protobuf-2.3.7.min.js +1 -1
  91. package/src/plugins/im/im-plug-in/RongCallLib-3.1.5.min.js +74 -74
  92. package/src/plugins/im/im-plug-in/RongIMLib-4.1.0.js +17420 -17420
  93. package/src/plugins/im/im-plug-in/init.js +216 -216
  94. package/src/plugins/im/im-plug-in/qiniu.js +266 -266
  95. package/src/plugins/im/im-plug-in/send-data.js +431 -431
  96. package/src/plugins/im/im-plug-in/upload.js +232 -232
  97. package/src/plugins/im/lib/RongIMEmoji-2.2.6.js +332 -332
  98. package/src/plugins/im/lib/RongIMLib-3.0.7.2-dev.js +11635 -11635
  99. package/src/plugins/im/lib/RongIMLib-3.0.7.2-dev.min.js +6 -6
  100. package/src/plugins/im/utils/underscore-1.8.3.js +1531 -1531
  101. package/src/plugins/im/utils/utils.js +149 -149
  102. package/src/plugins/row-col-cmp/colCmp/data.js +3 -3
  103. package/src/plugins/row-col-cmp/colCmp/index.scss +50 -50
  104. package/src/plugins/row-col-cmp/colCmp/index.vue +53 -53
  105. package/src/plugins/row-col-cmp/colCmp/methods.js +25 -25
  106. package/src/plugins/row-col-cmp/rowCmp/data.js +3 -3
  107. package/src/plugins/row-col-cmp/rowCmp/index.scss +3 -3
  108. package/src/plugins/row-col-cmp/rowCmp/index.vue +43 -43
  109. package/src/plugins/row-col-cmp/rowCmp/methods.js +29 -29
  110. package/src/router/index.js +47 -43
  111. package/src/store/getters.js +13 -13
  112. package/src/store/index.js +58 -58
  113. package/src/store/modules/app.js +55 -55
  114. package/src/store/modules/dic.js +1 -1
  115. package/src/store/modules/settings.js +28 -28
  116. package/src/store/modules/user.js +94 -94
  117. package/src/store/modules/widgetdata.js +42 -42
  118. package/src/styles/element-ui.scss +49 -49
  119. package/src/styles/mixin.scss +28 -28
  120. package/src/styles/sidebar.scss +210 -210
  121. package/src/styles/transition.scss +48 -48
  122. package/src/styles/variables.scss +25 -25
  123. package/src/utils/get-page-title.js +10 -10
  124. package/src/utils/getMenu.js +2 -1
  125. package/src/utils/global-config.js +15 -15
  126. package/src/utils/index.js +332 -332
  127. package/src/utils/localStorage.js +21 -21
  128. package/src/utils/validate.js +20 -20
  129. package/src/views/layout/components/AllSearch/index.vue +44 -44
  130. package/src/views/layout/components/AppMain.vue +50 -50
  131. package/src/views/layout/components/Navbar.vue +43 -2
  132. package/src/views/layout/components/Sidebar/FixiOSBug.js +26 -26
  133. package/src/views/layout/components/Sidebar/Item.vue +28 -28
  134. package/src/views/layout/components/Sidebar/Link.vue +34 -34
  135. package/src/views/layout/components/Sidebar/Logo.vue +79 -79
  136. package/src/views/layout/components/Sidebar/SidebarItem.vue +67 -67
  137. package/src/views/layout/components/Sidebar/index.vue +114 -114
  138. package/src/views/layout/components/index.js +3 -3
  139. package/src/views/layout/index.vue +105 -105
@@ -1,267 +1,267 @@
1
- (function(win) {
2
- function forEach(m, callback) {
3
- for (var key in m) {
4
- callback(key, m[key]);
5
- }
6
- }
7
-
8
- function buildUrl(url, items) {
9
- var query = '';
10
- forEach(items, function(name, value) {
11
- if (name != 'token') {
12
- query += (query ? '&' : '') + encodeURIComponent(name) + '=' + encodeURIComponent(value);
13
- }
14
- });
15
-
16
- if (query) {
17
- url += (url.indexOf('?') > 0 ? '&' : '?') + query;
18
- }
19
-
20
- return url;
21
- }
22
-
23
- function encode2UTF8(argString) {
24
- if (argString === null || typeof argString === 'undefined') {
25
- return '';
26
- }
27
- var string = (argString + ''); // .replace(/\r\n/g, '\n').replace(/\r/g, '\n');
28
- var utftext = '',
29
- start, end, stringl = 0;
30
- start = end = 0;
31
- stringl = string.length;
32
- for (var n = 0; n < stringl; n++) {
33
- var c1 = string.charCodeAt(n);
34
- var enc = null;
35
-
36
- if (c1 < 128) {
37
- end++;
38
- } else if (c1 > 127 && c1 < 2048) {
39
- enc = String.fromCharCode(
40
- (c1 >> 6) | 192, (c1 & 63) | 128
41
- );
42
- } else if (c1 & 0xF800 ^ 0xD800 > 0) {
43
- enc = String.fromCharCode(
44
- (c1 >> 12) | 224, ((c1 >> 6) & 63) | 128, (c1 & 63) | 128
45
- );
46
- } else { // surrogate pairs
47
- if (c1 & 0xFC00 ^ 0xD800 > 0) {
48
- throw new RangeError('Unmatched trail surrogate at ' + n);
49
- }
50
- var c2 = string.charCodeAt(++n);
51
- if (c2 & 0xFC00 ^ 0xDC00 > 0) {
52
- throw new RangeError('Unmatched lead surrogate at ' + (n - 1));
53
- }
54
- c1 = ((c1 & 0x3FF) << 10) + (c2 & 0x3FF) + 0x10000;
55
- enc = String.fromCharCode(
56
- (c1 >> 18) | 240, ((c1 >> 12) & 63) | 128, ((c1 >> 6) & 63) | 128, (c1 & 63) | 128
57
- );
58
- }
59
- if (enc !== null) {
60
- if (end > start) {
61
- utftext += string.slice(start, end);
62
- }
63
- utftext += enc;
64
- start = end = n + 1;
65
- }
66
- }
67
-
68
- if (end > start) {
69
- utftext += string.slice(start, stringl);
70
- }
71
-
72
- return utftext;
73
- }
74
- // Copy 七牛 SDK 方法
75
- function encode2Base64(data) {
76
- var b64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
77
- var o1, o2, o3, h1, h2, h3, h4, bits, i = 0,
78
- ac = 0,
79
- enc = '',
80
- tmp_arr = [];
81
-
82
- if (!data) {
83
- return data;
84
- }
85
-
86
- data = encode2UTF8(data + '');
87
-
88
- do { // pack three octets into four hexets
89
- o1 = data.charCodeAt(i++);
90
- o2 = data.charCodeAt(i++);
91
- o3 = data.charCodeAt(i++);
92
-
93
- bits = o1 << 16 | o2 << 8 | o3;
94
-
95
- h1 = bits >> 18 & 0x3f;
96
- h2 = bits >> 12 & 0x3f;
97
- h3 = bits >> 6 & 0x3f;
98
- h4 = bits & 0x3f;
99
-
100
- // use hexets to index into b64, and append result to encoded string
101
- tmp_arr[ac++] = b64.charAt(h1) + b64.charAt(h2) + b64.charAt(h3) + b64.charAt(h4);
102
- } while (i < data.length);
103
-
104
- enc = tmp_arr.join('');
105
-
106
- switch (data.length % 3) {
107
- case 1:
108
- enc = enc.slice(0, -2) + '==';
109
- break;
110
- case 2:
111
- enc = enc.slice(0, -1) + '=';
112
- break;
113
- }
114
- return enc;
115
- }
116
- // Copy 七牛 SDK 方法
117
- function URLSafeBase64Encode(v) {
118
- v = encode2Base64(v);
119
- return v.replace(/\//g, '_').replace(/\+/g, '-');
120
- }
121
-
122
- function chunkLastStep(data, opts, callback) {
123
- // 七牛 URL 规定
124
- var key = '/key/' + URLSafeBase64Encode(data.filename);
125
- var fname = '/fname/' + URLSafeBase64Encode(data.filename);
126
- var url = opts.domain + '/mkfile/' + data.size + key + fname;
127
- var options = {
128
- domain: url,
129
- method: 'POST',
130
- headers: {
131
- 'Content-Type': 'application/octet-stream'
132
- },
133
- multi_parmas: opts.multi_parmas,
134
- support_options: true,
135
- stream: true
136
- };
137
- uploadData(data.ctx, options, {
138
- onCompleted: function(res) {
139
- res.filename = data.filename;
140
- res.name = data.name;
141
- callback.onCompleted(res);
142
- },
143
- onError: function() {
144
- throw new Error('qiniu uploadChunk error');
145
- },
146
- onProgress: function(chunkLoaded, total) {},
147
- onOpen: function(xhr) {
148
- callback.onOpen(xhr);
149
- }
150
- });
151
- }
152
-
153
- var offset = 0,
154
- ctxStore = {};
155
-
156
- function uploadNextChunk(blob, opts, callback) {
157
- var chunk = Math.ceil(offset / opts.chunk_size),
158
- chunks = Math.ceil(blob.size / opts.chunk_size),
159
- curChunkSize = Math.min(opts.chunk_size, blob.size - offset),
160
- chunkBlob = blob.slice(offset, offset + curChunkSize),
161
- chunkInfo = {
162
- chunk: chunk,
163
- chunks: chunks,
164
- name: blob.uniqueName
165
- };
166
- forEach(chunkInfo, function(key, value) {
167
- opts.multi_parmas[key] = value;
168
- });
169
- opts.filesize = blob.size;
170
- opts.headers = {
171
- 'Content-Type': 'application/octet-stream'
172
- };
173
- opts.isChunk = true;
174
- uploadData(chunkBlob, opts, {
175
- onCompleted: function(chunkRes) {
176
- offset += curChunkSize;
177
- // callback.onProgress(Math.floor((chunk + 1) / chunks * blob.size), blob.size);
178
- ctxStore[blob.uniqueName] = ctxStore[blob.uniqueName] || [];
179
- ctxStore[blob.uniqueName].push(chunkRes.ctx);
180
- if (offset < blob.size) {
181
- if (chunkRes.ctx) {
182
- uploadNextChunk(blob, opts, callback);
183
- }else{
184
- offset = 0;
185
- delete ctxStore[blob.uniqueName]
186
- }
187
- } else {
188
- offset = 0;
189
- delete opts.isChunk;
190
- delete opts.headers['Content-Type'];
191
- forEach(chunkInfo, function(key, value) {
192
- delete opts.multi_parmas[key];
193
- });
194
- var ctx = ctxStore[blob.uniqueName].join(',');
195
- var data = {
196
- ctx: ctx,
197
- name: blob.name,
198
- size: blob.size,
199
- filename: blob.uniqueName
200
- };
201
- chunkLastStep(data, opts, callback);
202
- }
203
- },
204
- onError: function() {
205
- throw new Error('qiniu uploadChunk error');
206
- },
207
- onProgress: function(chunkLoaded, total) {
208
- var loaded = chunkLoaded + offset;
209
- callback.onProgress(loaded, opts.filesize);
210
- },
211
- onOpen: function(xhr) {
212
- callback.onOpen(xhr);
213
- }
214
- });
215
- }
216
-
217
- function uploadData(data, options, callback) {
218
- var xhr = new XMLHttpRequest();
219
- if (xhr.upload && options.support_options) {
220
- xhr.upload.onprogress = function(event) {
221
- callback.onProgress(event.loaded, event.total);
222
- };
223
- }
224
-
225
- xhr.onreadystatechange = function() {
226
- if (xhr.readyState == 4) {
227
- var result = xhr.responseText || "{}";
228
- result = JSON.parse(result);
229
- result.filename = options.unique_value;
230
- callback.onCompleted(result);
231
- }
232
- };
233
-
234
- var url = options.domain;
235
- if (options.isChunk) {
236
- url += '/mkblk/' + data.size;
237
- url = buildUrl(url, options.multi_parmas);
238
- }
239
- xhr.open(options.method, url, true);
240
-
241
- callback.onOpen(xhr);
242
-
243
- if (options.stream) {
244
- xhr.setRequestHeader('authorization', 'UpToken ' + options.multi_parmas.token);
245
- }
246
-
247
- forEach(options.headers, function(key, value) {
248
- xhr.setRequestHeader(key, value);
249
- });
250
- xhr.send(data);
251
- }
252
-
253
- function uploadQiniu(file, opts, callback) {
254
- if (file.size && opts.chunk_size < file.size) {
255
- var uniqueName = opts['genUId'](file);
256
- var suffix = file.name.substr(file.name.lastIndexOf('.'));
257
- uniqueName = uniqueName + suffix;
258
- file.uniqueName = uniqueName;
259
- opts.stream = true;
260
- uploadNextChunk(file, opts, callback);
261
- } else {
262
- var data = opts['data'](file, opts);
263
- uploadData(data, opts, callback);
264
- }
265
- }
266
- win.uploadProcess = uploadQiniu;
1
+ (function(win) {
2
+ function forEach(m, callback) {
3
+ for (var key in m) {
4
+ callback(key, m[key]);
5
+ }
6
+ }
7
+
8
+ function buildUrl(url, items) {
9
+ var query = '';
10
+ forEach(items, function(name, value) {
11
+ if (name != 'token') {
12
+ query += (query ? '&' : '') + encodeURIComponent(name) + '=' + encodeURIComponent(value);
13
+ }
14
+ });
15
+
16
+ if (query) {
17
+ url += (url.indexOf('?') > 0 ? '&' : '?') + query;
18
+ }
19
+
20
+ return url;
21
+ }
22
+
23
+ function encode2UTF8(argString) {
24
+ if (argString === null || typeof argString === 'undefined') {
25
+ return '';
26
+ }
27
+ var string = (argString + ''); // .replace(/\r\n/g, '\n').replace(/\r/g, '\n');
28
+ var utftext = '',
29
+ start, end, stringl = 0;
30
+ start = end = 0;
31
+ stringl = string.length;
32
+ for (var n = 0; n < stringl; n++) {
33
+ var c1 = string.charCodeAt(n);
34
+ var enc = null;
35
+
36
+ if (c1 < 128) {
37
+ end++;
38
+ } else if (c1 > 127 && c1 < 2048) {
39
+ enc = String.fromCharCode(
40
+ (c1 >> 6) | 192, (c1 & 63) | 128
41
+ );
42
+ } else if (c1 & 0xF800 ^ 0xD800 > 0) {
43
+ enc = String.fromCharCode(
44
+ (c1 >> 12) | 224, ((c1 >> 6) & 63) | 128, (c1 & 63) | 128
45
+ );
46
+ } else { // surrogate pairs
47
+ if (c1 & 0xFC00 ^ 0xD800 > 0) {
48
+ throw new RangeError('Unmatched trail surrogate at ' + n);
49
+ }
50
+ var c2 = string.charCodeAt(++n);
51
+ if (c2 & 0xFC00 ^ 0xDC00 > 0) {
52
+ throw new RangeError('Unmatched lead surrogate at ' + (n - 1));
53
+ }
54
+ c1 = ((c1 & 0x3FF) << 10) + (c2 & 0x3FF) + 0x10000;
55
+ enc = String.fromCharCode(
56
+ (c1 >> 18) | 240, ((c1 >> 12) & 63) | 128, ((c1 >> 6) & 63) | 128, (c1 & 63) | 128
57
+ );
58
+ }
59
+ if (enc !== null) {
60
+ if (end > start) {
61
+ utftext += string.slice(start, end);
62
+ }
63
+ utftext += enc;
64
+ start = end = n + 1;
65
+ }
66
+ }
67
+
68
+ if (end > start) {
69
+ utftext += string.slice(start, stringl);
70
+ }
71
+
72
+ return utftext;
73
+ }
74
+ // Copy 七牛 SDK 方法
75
+ function encode2Base64(data) {
76
+ var b64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
77
+ var o1, o2, o3, h1, h2, h3, h4, bits, i = 0,
78
+ ac = 0,
79
+ enc = '',
80
+ tmp_arr = [];
81
+
82
+ if (!data) {
83
+ return data;
84
+ }
85
+
86
+ data = encode2UTF8(data + '');
87
+
88
+ do { // pack three octets into four hexets
89
+ o1 = data.charCodeAt(i++);
90
+ o2 = data.charCodeAt(i++);
91
+ o3 = data.charCodeAt(i++);
92
+
93
+ bits = o1 << 16 | o2 << 8 | o3;
94
+
95
+ h1 = bits >> 18 & 0x3f;
96
+ h2 = bits >> 12 & 0x3f;
97
+ h3 = bits >> 6 & 0x3f;
98
+ h4 = bits & 0x3f;
99
+
100
+ // use hexets to index into b64, and append result to encoded string
101
+ tmp_arr[ac++] = b64.charAt(h1) + b64.charAt(h2) + b64.charAt(h3) + b64.charAt(h4);
102
+ } while (i < data.length);
103
+
104
+ enc = tmp_arr.join('');
105
+
106
+ switch (data.length % 3) {
107
+ case 1:
108
+ enc = enc.slice(0, -2) + '==';
109
+ break;
110
+ case 2:
111
+ enc = enc.slice(0, -1) + '=';
112
+ break;
113
+ }
114
+ return enc;
115
+ }
116
+ // Copy 七牛 SDK 方法
117
+ function URLSafeBase64Encode(v) {
118
+ v = encode2Base64(v);
119
+ return v.replace(/\//g, '_').replace(/\+/g, '-');
120
+ }
121
+
122
+ function chunkLastStep(data, opts, callback) {
123
+ // 七牛 URL 规定
124
+ var key = '/key/' + URLSafeBase64Encode(data.filename);
125
+ var fname = '/fname/' + URLSafeBase64Encode(data.filename);
126
+ var url = opts.domain + '/mkfile/' + data.size + key + fname;
127
+ var options = {
128
+ domain: url,
129
+ method: 'POST',
130
+ headers: {
131
+ 'Content-Type': 'application/octet-stream'
132
+ },
133
+ multi_parmas: opts.multi_parmas,
134
+ support_options: true,
135
+ stream: true
136
+ };
137
+ uploadData(data.ctx, options, {
138
+ onCompleted: function(res) {
139
+ res.filename = data.filename;
140
+ res.name = data.name;
141
+ callback.onCompleted(res);
142
+ },
143
+ onError: function() {
144
+ throw new Error('qiniu uploadChunk error');
145
+ },
146
+ onProgress: function(chunkLoaded, total) {},
147
+ onOpen: function(xhr) {
148
+ callback.onOpen(xhr);
149
+ }
150
+ });
151
+ }
152
+
153
+ var offset = 0,
154
+ ctxStore = {};
155
+
156
+ function uploadNextChunk(blob, opts, callback) {
157
+ var chunk = Math.ceil(offset / opts.chunk_size),
158
+ chunks = Math.ceil(blob.size / opts.chunk_size),
159
+ curChunkSize = Math.min(opts.chunk_size, blob.size - offset),
160
+ chunkBlob = blob.slice(offset, offset + curChunkSize),
161
+ chunkInfo = {
162
+ chunk: chunk,
163
+ chunks: chunks,
164
+ name: blob.uniqueName
165
+ };
166
+ forEach(chunkInfo, function(key, value) {
167
+ opts.multi_parmas[key] = value;
168
+ });
169
+ opts.filesize = blob.size;
170
+ opts.headers = {
171
+ 'Content-Type': 'application/octet-stream'
172
+ };
173
+ opts.isChunk = true;
174
+ uploadData(chunkBlob, opts, {
175
+ onCompleted: function(chunkRes) {
176
+ offset += curChunkSize;
177
+ // callback.onProgress(Math.floor((chunk + 1) / chunks * blob.size), blob.size);
178
+ ctxStore[blob.uniqueName] = ctxStore[blob.uniqueName] || [];
179
+ ctxStore[blob.uniqueName].push(chunkRes.ctx);
180
+ if (offset < blob.size) {
181
+ if (chunkRes.ctx) {
182
+ uploadNextChunk(blob, opts, callback);
183
+ }else{
184
+ offset = 0;
185
+ delete ctxStore[blob.uniqueName]
186
+ }
187
+ } else {
188
+ offset = 0;
189
+ delete opts.isChunk;
190
+ delete opts.headers['Content-Type'];
191
+ forEach(chunkInfo, function(key, value) {
192
+ delete opts.multi_parmas[key];
193
+ });
194
+ var ctx = ctxStore[blob.uniqueName].join(',');
195
+ var data = {
196
+ ctx: ctx,
197
+ name: blob.name,
198
+ size: blob.size,
199
+ filename: blob.uniqueName
200
+ };
201
+ chunkLastStep(data, opts, callback);
202
+ }
203
+ },
204
+ onError: function() {
205
+ throw new Error('qiniu uploadChunk error');
206
+ },
207
+ onProgress: function(chunkLoaded, total) {
208
+ var loaded = chunkLoaded + offset;
209
+ callback.onProgress(loaded, opts.filesize);
210
+ },
211
+ onOpen: function(xhr) {
212
+ callback.onOpen(xhr);
213
+ }
214
+ });
215
+ }
216
+
217
+ function uploadData(data, options, callback) {
218
+ var xhr = new XMLHttpRequest();
219
+ if (xhr.upload && options.support_options) {
220
+ xhr.upload.onprogress = function(event) {
221
+ callback.onProgress(event.loaded, event.total);
222
+ };
223
+ }
224
+
225
+ xhr.onreadystatechange = function() {
226
+ if (xhr.readyState == 4) {
227
+ var result = xhr.responseText || "{}";
228
+ result = JSON.parse(result);
229
+ result.filename = options.unique_value;
230
+ callback.onCompleted(result);
231
+ }
232
+ };
233
+
234
+ var url = options.domain;
235
+ if (options.isChunk) {
236
+ url += '/mkblk/' + data.size;
237
+ url = buildUrl(url, options.multi_parmas);
238
+ }
239
+ xhr.open(options.method, url, true);
240
+
241
+ callback.onOpen(xhr);
242
+
243
+ if (options.stream) {
244
+ xhr.setRequestHeader('authorization', 'UpToken ' + options.multi_parmas.token);
245
+ }
246
+
247
+ forEach(options.headers, function(key, value) {
248
+ xhr.setRequestHeader(key, value);
249
+ });
250
+ xhr.send(data);
251
+ }
252
+
253
+ function uploadQiniu(file, opts, callback) {
254
+ if (file.size && opts.chunk_size < file.size) {
255
+ var uniqueName = opts['genUId'](file);
256
+ var suffix = file.name.substr(file.name.lastIndexOf('.'));
257
+ uniqueName = uniqueName + suffix;
258
+ file.uniqueName = uniqueName;
259
+ opts.stream = true;
260
+ uploadNextChunk(file, opts, callback);
261
+ } else {
262
+ var data = opts['data'](file, opts);
263
+ uploadData(data, opts, callback);
264
+ }
265
+ }
266
+ win.uploadProcess = uploadQiniu;
267
267
  })(window);