xs-common-plugins 1.2.3 → 1.2.5
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.
- package/README.md +298 -298
- package/common.js +110 -110
- package/index.js +1 -1
- package/package.json +16 -16
- package/src/App.vue +12 -12
- package/src/common/common.js +551 -549
- package/src/common/createMenuId.js +7 -7
- package/src/common/uploadImgToBase64.js +12 -12
- package/src/common/utils.js +95 -95
- package/src/components/Breadcrumb/index.vue +81 -81
- package/src/components/CheckBox_Cmp/index.vue +62 -62
- package/src/components/Col_TableCell/data.js +4 -4
- package/src/components/Col_TableCell/index.scss +77 -77
- package/src/components/Col_TableCell/index.vue +43 -43
- package/src/components/Col_TableCell/methods.js +19 -19
- package/src/components/FormItem/index.vue +92 -92
- package/src/components/Hamburger/index.vue +44 -44
- package/src/components/ReportCmp/data.js +3 -3
- package/src/components/ReportCmp/index.scss +29 -29
- package/src/components/ReportCmp/index.vue +76 -76
- package/src/components/ReportCmp/methods.js +30 -30
- package/src/components/Search/cascader/data.js +3 -3
- package/src/components/Search/cascader/index.scss +17 -17
- package/src/components/Search/cascader/index.vue +96 -96
- package/src/components/Search/cascader/methods.js +41 -41
- package/src/components/Search/data.js +5 -5
- package/src/components/Search/hk_cascader/index.vue +104 -104
- package/src/components/Search/hk_cascader_qudao/index.vue +94 -94
- package/src/components/Search/index.scss +219 -219
- package/src/components/Search/index.vue +410 -410
- package/src/components/Search/methods.js +86 -86
- package/src/components/Search/product_option/data.js +3 -3
- package/src/components/Search/product_option/index.scss +68 -68
- package/src/components/Search/product_option/index.vue +412 -412
- package/src/components/Search/product_option/methods.js +58 -58
- package/src/components/Search/select/data.js +3 -3
- package/src/components/Search/select/index.scss +2 -2
- package/src/components/Search/select/index.vue +114 -114
- package/src/components/Search/select/methods.js +51 -51
- package/src/components/Search_filter/data.js +5 -5
- package/src/components/Search_filter/index.scss +104 -104
- package/src/components/Search_filter/index.vue +88 -88
- package/src/components/Search_filter/methods.js +43 -43
- package/src/components/TableCmp/data.js +3 -3
- package/src/components/TableCmp/index.scss +22 -22
- package/src/components/TableCmp/index.vue +98 -98
- package/src/components/TableCmp/methods.js +35 -35
- package/src/components/TableItem/TableItem.vue +55 -55
- package/src/components/TextOVer/index.vue +55 -55
- package/src/components/UploadImg/index.vue +177 -177
- package/src/components/home/BarChart.vue +118 -118
- package/src/components/home/LineChart.vue +146 -146
- package/src/components/home/Panel.vue +135 -135
- package/src/components/home/PanelGroup.vue +146 -146
- package/src/components/home/PieChart.vue +81 -81
- package/src/components/home/RaddarChart.vue +119 -119
- package/src/components/home/TabLayout.vue +88 -88
- package/src/components/home/TableList.vue +158 -158
- package/src/components/home/Teng.vue +248 -248
- package/src/components/home/TransactionTable.vue +49 -49
- package/src/components/home/mixins/resize.js +55 -55
- package/src/components/im/index.vue +155 -155
- package/src/components/im/methods.js +25 -25
- package/src/components/im/pages/chatList/index.vue +45 -45
- package/src/components/im/pages/chatRoom/index.vue +159 -159
- package/src/components/image-singleUpload/data.js +3 -3
- package/src/components/image-singleUpload/index.scss +26 -26
- package/src/components/image-singleUpload/index.vue +56 -56
- package/src/components/image-singleUpload/methods.js +30 -30
- package/src/components/image-upload/data.js +7 -7
- package/src/components/image-upload/index.vue +41 -41
- package/src/components/image-upload/methods.js +80 -80
- package/src/components/multiple-image-upload/data.js +11 -11
- package/src/components/multiple-image-upload/index.scss +8 -8
- package/src/components/multiple-image-upload/index.vue +63 -63
- package/src/components/multiple-image-upload/methods.js +45 -45
- package/src/components/pro-upload/data.js +3 -3
- package/src/components/pro-upload/index.scss +4 -4
- package/src/components/pro-upload/index.vue +89 -89
- package/src/components/pro-upload/methods.js +86 -86
- package/src/components/report_set/index.scss +44 -44
- package/src/components/report_set/index.vue +153 -153
- package/src/components/search-page/src/index.scss +5 -5
- package/src/components/search-page/src/index.vue +76 -76
- package/src/components/search-page/src/methods.js +36 -36
- package/src/components/xsSelect/index.vue +125 -125
- package/src/mixin/dialog.js +31 -31
- package/src/mixin/dlg.js +46 -46
- package/src/mixin/keepAlive.js +53 -52
- package/src/mixin/newDialog.js +19 -19
- package/src/mixin/report.js +82 -82
- package/src/mixin/table.js +93 -93
- package/src/mixin/tableCell/colTableCell_analysis.js +103 -103
- package/src/mixin/upload.js +22 -22
- package/src/mixin/vmodel.js +26 -26
- package/src/plugins/im/components/chat/index.scss +163 -163
- package/src/plugins/im/components/chat/index.vue +144 -144
- package/src/plugins/im/components/chat/methods.js +149 -149
- package/src/plugins/im/components/conversation-list/index.css +91 -91
- package/src/plugins/im/components/conversation-list/index.json +3 -3
- package/src/plugins/im/components/conversation-list/index.vue +89 -89
- package/src/plugins/im/components/loading/loading.css +69 -69
- package/src/plugins/im/components/loading/loading.json +3 -3
- package/src/plugins/im/components/loading/loading.vue +14 -14
- package/src/plugins/im/components/msg-image/index.json +3 -3
- package/src/plugins/im/components/msg-image/index.vue +40 -40
- package/src/plugins/im/components/msg-text/index.json +3 -3
- package/src/plugins/im/components/msg-text/index.vue +24 -24
- package/src/plugins/im/components/send-msg/index.scss +164 -164
- package/src/plugins/im/components/send-msg/index.vue +107 -107
- package/src/plugins/im/components/send-msg/methods.js +125 -125
- package/src/plugins/im/components/template-message/index.vue +76 -76
- package/src/plugins/im/components/without.vue +19 -19
- package/src/plugins/im/im-plug-in/Protobuf-2.3.7.min.js +1 -1
- package/src/plugins/im/im-plug-in/RongCallLib-3.1.5.min.js +74 -74
- package/src/plugins/im/im-plug-in/RongIMLib-4.1.0.js +17420 -17420
- package/src/plugins/im/im-plug-in/init.js +216 -216
- package/src/plugins/im/im-plug-in/qiniu.js +266 -266
- package/src/plugins/im/im-plug-in/send-data.js +431 -431
- package/src/plugins/im/im-plug-in/upload.js +232 -232
- package/src/plugins/im/index.js +31 -31
- package/src/plugins/im/lib/RongIMEmoji-2.2.6.js +332 -332
- package/src/plugins/im/lib/RongIMLib-3.0.7.2-dev.js +11635 -11635
- package/src/plugins/im/lib/RongIMLib-3.0.7.2-dev.min.js +6 -6
- package/src/plugins/im/utils/services.js +625 -625
- package/src/plugins/im/utils/underscore-1.8.3.js +1531 -1531
- package/src/plugins/im/utils/utils.js +149 -149
- package/src/plugins/index.js +60 -60
- package/src/plugins/row-col-cmp/colCmp/data.js +3 -3
- package/src/plugins/row-col-cmp/colCmp/index.scss +50 -50
- package/src/plugins/row-col-cmp/colCmp/index.vue +53 -53
- package/src/plugins/row-col-cmp/colCmp/methods.js +25 -25
- package/src/plugins/row-col-cmp/index.js +20 -20
- package/src/plugins/row-col-cmp/rowCmp/data.js +3 -3
- package/src/plugins/row-col-cmp/rowCmp/index.scss +3 -3
- package/src/plugins/row-col-cmp/rowCmp/index.vue +43 -43
- package/src/plugins/row-col-cmp/rowCmp/methods.js +29 -29
- package/src/router/index.js +58 -58
- package/src/router/permission.js +126 -126
- package/src/store/getters.js +13 -13
- package/src/store/index.js +60 -60
- package/src/store/modules/app.js +55 -55
- package/src/store/modules/dic.js +74 -74
- package/src/store/modules/oss.js +40 -40
- package/src/store/modules/settings.js +28 -28
- package/src/store/modules/tagsView.js +160 -160
- package/src/store/modules/user.js +94 -94
- package/src/store/modules/widgetdata.js +42 -42
- package/src/styles/element-ui.scss +49 -49
- package/src/styles/index.scss +91 -91
- package/src/styles/mixin.scss +28 -28
- package/src/styles/sidebar.scss +210 -210
- package/src/styles/table.scss +90 -90
- package/src/styles/transition.scss +48 -48
- package/src/styles/variables.scss +25 -25
- package/src/utils/api.js +54 -54
- package/src/utils/auth.js +38 -38
- package/src/utils/concat_batch_btns.js +88 -88
- package/src/utils/enum.js +150 -150
- package/src/utils/filter.js +5 -5
- package/src/utils/filterRules.js +55 -55
- package/src/utils/get-page-title.js +10 -10
- package/src/utils/getMenu.js +82 -82
- package/src/utils/global-config.js +15 -15
- package/src/utils/global_directive.js +10 -10
- package/src/utils/index.js +332 -332
- package/src/utils/localStorage.js +21 -21
- package/src/utils/ossService.js +55 -55
- package/src/utils/prototype.js +46 -46
- package/src/utils/search.js +33 -33
- package/src/utils/signalR.js +24 -24
- package/src/utils/validate.js +20 -20
- package/src/views/callback/index.vue +35 -35
- package/src/views/home/index.vue +25 -25
- package/src/views/layout/components/AllSearch/index.vue +44 -44
- package/src/views/layout/components/AppMain.vue +66 -66
- package/src/views/layout/components/Sidebar/FixiOSBug.js +26 -26
- package/src/views/layout/components/Sidebar/Item.vue +28 -28
- package/src/views/layout/components/Sidebar/Link.vue +34 -34
- package/src/views/layout/components/Sidebar/Logo.vue +79 -79
- package/src/views/layout/components/Sidebar/SidebarItem.vue +67 -67
- package/src/views/layout/components/Sidebar/index.vue +114 -114
- package/src/views/layout/components/TagsView/ScrollPane.vue +94 -94
- package/src/views/layout/components/TagsView/index.vue +330 -330
- package/src/views/layout/components/index.js +3 -3
- package/src/views/layout/index.vue +107 -107
- package/src/views/redirect/index.vue +12 -12
- package/src/views/slienceAuth/index.vue +42 -42
|
@@ -1,217 +1,217 @@
|
|
|
1
|
-
(function(global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
|
3
|
-
typeof define === 'function' && define.amd ? define(factory) : (global.UploadClient = factory());
|
|
4
|
-
}(this, function() {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var calcPosition = function(width, height, opts) {
|
|
8
|
-
var isheight = width < height;
|
|
9
|
-
var scale = isheight ? height / width : width / height;
|
|
10
|
-
var zoom, x = 0,
|
|
11
|
-
y = 0,
|
|
12
|
-
w, h;
|
|
13
|
-
|
|
14
|
-
var gtScale = function() {
|
|
15
|
-
if (isheight) {
|
|
16
|
-
zoom = width / 100;
|
|
17
|
-
w = 100;
|
|
18
|
-
h = height / zoom;
|
|
19
|
-
y = (h - opts.maxHeight) / 2;
|
|
20
|
-
} else {
|
|
21
|
-
zoom = height / 100;
|
|
22
|
-
h = 100;
|
|
23
|
-
w = width / zoom;
|
|
24
|
-
x = (w - opts.maxWidth) / 2;
|
|
25
|
-
}
|
|
26
|
-
return {
|
|
27
|
-
w: w,
|
|
28
|
-
h: h,
|
|
29
|
-
x: -x,
|
|
30
|
-
y: -y
|
|
31
|
-
};
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
var ltScale = function() {
|
|
35
|
-
if (isheight) {
|
|
36
|
-
zoom = height / opts.maxHeight;
|
|
37
|
-
h = opts.maxHeight;
|
|
38
|
-
w = width / zoom;
|
|
39
|
-
} else {
|
|
40
|
-
zoom = width / opts.maxWidth;
|
|
41
|
-
w = opts.maxWidth;
|
|
42
|
-
h = height / zoom;
|
|
43
|
-
}
|
|
44
|
-
return {
|
|
45
|
-
w: w,
|
|
46
|
-
h: h,
|
|
47
|
-
x: -x,
|
|
48
|
-
y: -y
|
|
49
|
-
};
|
|
50
|
-
};
|
|
51
|
-
return scale > opts.scale ? gtScale() : ltScale();
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
var getBlobUrl = function(file) {
|
|
55
|
-
var URL = window.URL || window.webkitURL;
|
|
56
|
-
return URL ? URL.createObjectURL(file) : "";
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
var getThumbnail = function(file, opts, callback) {
|
|
60
|
-
var canvas = document.createElement("canvas"),
|
|
61
|
-
context = canvas.getContext('2d');
|
|
62
|
-
var img = new Image();
|
|
63
|
-
img.onload = function() {
|
|
64
|
-
var pos = calcPosition(img.width, img.height, opts);
|
|
65
|
-
canvas.width = pos.w > opts.maxWidth ? opts.maxWidth : pos.w;
|
|
66
|
-
canvas.height = pos.h > opts.maxHeight ? opts.maxHeight : pos.h;
|
|
67
|
-
context.drawImage(img, pos.x, pos.y, pos.w, pos.h);
|
|
68
|
-
try {
|
|
69
|
-
var base64 = canvas.toDataURL(file.type, opts.quality);
|
|
70
|
-
var reg = new RegExp('^data:image/[^;]+;base64,');
|
|
71
|
-
base64 = base64.replace(reg, '');
|
|
72
|
-
callback(base64);
|
|
73
|
-
} catch (e) {
|
|
74
|
-
throw new Error(e);
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
img.src = typeof file == 'string' ? 'data:image/jpg;base64,' + file : getBlobUrl(file);
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
var _compress = function(data, callback) {
|
|
81
|
-
var file = data.file;
|
|
82
|
-
var opts = data.compress;
|
|
83
|
-
getThumbnail(file, opts, callback);
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
_init = function(config, callback) {
|
|
87
|
-
if (config.getToken) {
|
|
88
|
-
config.getToken(function(token, data) {
|
|
89
|
-
data = data || {}
|
|
90
|
-
config.multi_parmas || (config.multi_parmas = {});
|
|
91
|
-
config.multi_parmas.token = token;
|
|
92
|
-
config.uploadHost || (config.uploadHost = {});
|
|
93
|
-
config.uploadHost['bos'] = data.bos;
|
|
94
|
-
|
|
95
|
-
config.ossConfig = data.ossConfig
|
|
96
|
-
|
|
97
|
-
config.bosHeader || (config.bosHeader = {})
|
|
98
|
-
config.bosHeader['bosDate'] = data.bosDate;
|
|
99
|
-
config.bosHeader['bosToken'] = data.bosToken;
|
|
100
|
-
config.bosUploadPath = data.path;
|
|
101
|
-
|
|
102
|
-
config.aliHeader = {}
|
|
103
|
-
config.aliHeader['osskeyId'] = data.osskeyId;
|
|
104
|
-
config.aliHeader['ossPolicy'] = data.ossPolicy;
|
|
105
|
-
config.aliHeader['ossSign'] = data.ossSign;
|
|
106
|
-
config['ossBucketName'] = data.ossBucketName;
|
|
107
|
-
config['uploadFileName'] = data.fileName;
|
|
108
|
-
|
|
109
|
-
config.headers || (config.headers = {});
|
|
110
|
-
if (config.base64) {
|
|
111
|
-
config.headers['Content-type'] = 'application/octet-stream';
|
|
112
|
-
config.headers['Authorization'] = 'UpToken ' + token;
|
|
113
|
-
}
|
|
114
|
-
var instance = UploadFile.init(config);
|
|
115
|
-
callback(instance);
|
|
116
|
-
});
|
|
117
|
-
} else {
|
|
118
|
-
config.headers || (config.headers = {});
|
|
119
|
-
if (config.base64) {
|
|
120
|
-
config.headers['Content-type'] = 'application/octet-stream';
|
|
121
|
-
}
|
|
122
|
-
var instance = UploadFile.init(config);
|
|
123
|
-
callback(instance);
|
|
124
|
-
}
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
var _upload = function(data, instance, callback) {
|
|
128
|
-
instance.upload(data.file, {
|
|
129
|
-
onError: function(errorCode) {
|
|
130
|
-
callback.onError(errorCode);
|
|
131
|
-
},
|
|
132
|
-
onProgress: function(loaded, total) {
|
|
133
|
-
callback.onProgress(loaded, total);
|
|
134
|
-
},
|
|
135
|
-
onCompleted: function(result) {
|
|
136
|
-
result.filename || (result.filename = result.hash);
|
|
137
|
-
var compress = data.compressThumbnail || _compress;
|
|
138
|
-
if (data.compress) {
|
|
139
|
-
compress(data, function(thumbnail) {
|
|
140
|
-
result.thumbnail = thumbnail;
|
|
141
|
-
callback.onCompleted(result);
|
|
142
|
-
});
|
|
143
|
-
} else {
|
|
144
|
-
callback.onCompleted(result);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
var File = function(instance) {
|
|
151
|
-
var me = this;
|
|
152
|
-
this.instance = instance
|
|
153
|
-
this.upload = function(file, callback) {
|
|
154
|
-
var data = {
|
|
155
|
-
file: file
|
|
156
|
-
};
|
|
157
|
-
_upload(data, me.instance, callback);
|
|
158
|
-
};
|
|
159
|
-
this.cancel = function() {
|
|
160
|
-
me.instance.cancel();
|
|
161
|
-
};
|
|
162
|
-
};
|
|
163
|
-
|
|
164
|
-
var initFile = function(config, callback) {
|
|
165
|
-
_init(config, function(instance) {
|
|
166
|
-
var uploadFile = new File(instance);
|
|
167
|
-
callback(uploadFile);
|
|
168
|
-
});
|
|
169
|
-
};
|
|
170
|
-
|
|
171
|
-
var Img = function(instance, cfg) {
|
|
172
|
-
var me = this;
|
|
173
|
-
this.cfg = cfg;
|
|
174
|
-
this.instance = instance;
|
|
175
|
-
this.upload = function(file, callback) {
|
|
176
|
-
var data = {
|
|
177
|
-
file: file,
|
|
178
|
-
compress: me.cfg
|
|
179
|
-
};
|
|
180
|
-
_upload(data, me.instance, callback);
|
|
181
|
-
};
|
|
182
|
-
|
|
183
|
-
this.cancel = function() {
|
|
184
|
-
me.instance.cancel();
|
|
185
|
-
};
|
|
186
|
-
};
|
|
187
|
-
|
|
188
|
-
var initImage = function(config, callback) {
|
|
189
|
-
_init(config, function(instance) {
|
|
190
|
-
var compress = {
|
|
191
|
-
maxHeight: config.height || 160,
|
|
192
|
-
maxWidth: config.width || 160,
|
|
193
|
-
quality: config.quality || 0.5,
|
|
194
|
-
scale: config.scale || 2.4
|
|
195
|
-
};
|
|
196
|
-
var uploadImage = new Img(instance, compress);
|
|
197
|
-
callback(uploadImage);
|
|
198
|
-
});
|
|
199
|
-
};
|
|
200
|
-
|
|
201
|
-
var ImgBase64 = function(config) {
|
|
202
|
-
config.base64 = true;
|
|
203
|
-
Img.call(this, config);
|
|
204
|
-
};
|
|
205
|
-
|
|
206
|
-
var initImgBase64 = function(config, callback) {
|
|
207
|
-
config.base64 = true;
|
|
208
|
-
initImage.call(this, config, callback);
|
|
209
|
-
};
|
|
210
|
-
|
|
211
|
-
return {
|
|
212
|
-
initFile: initFile,
|
|
213
|
-
initImage: initImage,
|
|
214
|
-
initImgBase64: initImgBase64,
|
|
215
|
-
dataType: UploadFile.dataType
|
|
216
|
-
};
|
|
1
|
+
(function(global, factory) {
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(factory) : (global.UploadClient = factory());
|
|
4
|
+
}(this, function() {
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
var calcPosition = function(width, height, opts) {
|
|
8
|
+
var isheight = width < height;
|
|
9
|
+
var scale = isheight ? height / width : width / height;
|
|
10
|
+
var zoom, x = 0,
|
|
11
|
+
y = 0,
|
|
12
|
+
w, h;
|
|
13
|
+
|
|
14
|
+
var gtScale = function() {
|
|
15
|
+
if (isheight) {
|
|
16
|
+
zoom = width / 100;
|
|
17
|
+
w = 100;
|
|
18
|
+
h = height / zoom;
|
|
19
|
+
y = (h - opts.maxHeight) / 2;
|
|
20
|
+
} else {
|
|
21
|
+
zoom = height / 100;
|
|
22
|
+
h = 100;
|
|
23
|
+
w = width / zoom;
|
|
24
|
+
x = (w - opts.maxWidth) / 2;
|
|
25
|
+
}
|
|
26
|
+
return {
|
|
27
|
+
w: w,
|
|
28
|
+
h: h,
|
|
29
|
+
x: -x,
|
|
30
|
+
y: -y
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
var ltScale = function() {
|
|
35
|
+
if (isheight) {
|
|
36
|
+
zoom = height / opts.maxHeight;
|
|
37
|
+
h = opts.maxHeight;
|
|
38
|
+
w = width / zoom;
|
|
39
|
+
} else {
|
|
40
|
+
zoom = width / opts.maxWidth;
|
|
41
|
+
w = opts.maxWidth;
|
|
42
|
+
h = height / zoom;
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
w: w,
|
|
46
|
+
h: h,
|
|
47
|
+
x: -x,
|
|
48
|
+
y: -y
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
return scale > opts.scale ? gtScale() : ltScale();
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
var getBlobUrl = function(file) {
|
|
55
|
+
var URL = window.URL || window.webkitURL;
|
|
56
|
+
return URL ? URL.createObjectURL(file) : "";
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
var getThumbnail = function(file, opts, callback) {
|
|
60
|
+
var canvas = document.createElement("canvas"),
|
|
61
|
+
context = canvas.getContext('2d');
|
|
62
|
+
var img = new Image();
|
|
63
|
+
img.onload = function() {
|
|
64
|
+
var pos = calcPosition(img.width, img.height, opts);
|
|
65
|
+
canvas.width = pos.w > opts.maxWidth ? opts.maxWidth : pos.w;
|
|
66
|
+
canvas.height = pos.h > opts.maxHeight ? opts.maxHeight : pos.h;
|
|
67
|
+
context.drawImage(img, pos.x, pos.y, pos.w, pos.h);
|
|
68
|
+
try {
|
|
69
|
+
var base64 = canvas.toDataURL(file.type, opts.quality);
|
|
70
|
+
var reg = new RegExp('^data:image/[^;]+;base64,');
|
|
71
|
+
base64 = base64.replace(reg, '');
|
|
72
|
+
callback(base64);
|
|
73
|
+
} catch (e) {
|
|
74
|
+
throw new Error(e);
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
img.src = typeof file == 'string' ? 'data:image/jpg;base64,' + file : getBlobUrl(file);
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
var _compress = function(data, callback) {
|
|
81
|
+
var file = data.file;
|
|
82
|
+
var opts = data.compress;
|
|
83
|
+
getThumbnail(file, opts, callback);
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
_init = function(config, callback) {
|
|
87
|
+
if (config.getToken) {
|
|
88
|
+
config.getToken(function(token, data) {
|
|
89
|
+
data = data || {}
|
|
90
|
+
config.multi_parmas || (config.multi_parmas = {});
|
|
91
|
+
config.multi_parmas.token = token;
|
|
92
|
+
config.uploadHost || (config.uploadHost = {});
|
|
93
|
+
config.uploadHost['bos'] = data.bos;
|
|
94
|
+
|
|
95
|
+
config.ossConfig = data.ossConfig
|
|
96
|
+
|
|
97
|
+
config.bosHeader || (config.bosHeader = {})
|
|
98
|
+
config.bosHeader['bosDate'] = data.bosDate;
|
|
99
|
+
config.bosHeader['bosToken'] = data.bosToken;
|
|
100
|
+
config.bosUploadPath = data.path;
|
|
101
|
+
|
|
102
|
+
config.aliHeader = {}
|
|
103
|
+
config.aliHeader['osskeyId'] = data.osskeyId;
|
|
104
|
+
config.aliHeader['ossPolicy'] = data.ossPolicy;
|
|
105
|
+
config.aliHeader['ossSign'] = data.ossSign;
|
|
106
|
+
config['ossBucketName'] = data.ossBucketName;
|
|
107
|
+
config['uploadFileName'] = data.fileName;
|
|
108
|
+
|
|
109
|
+
config.headers || (config.headers = {});
|
|
110
|
+
if (config.base64) {
|
|
111
|
+
config.headers['Content-type'] = 'application/octet-stream';
|
|
112
|
+
config.headers['Authorization'] = 'UpToken ' + token;
|
|
113
|
+
}
|
|
114
|
+
var instance = UploadFile.init(config);
|
|
115
|
+
callback(instance);
|
|
116
|
+
});
|
|
117
|
+
} else {
|
|
118
|
+
config.headers || (config.headers = {});
|
|
119
|
+
if (config.base64) {
|
|
120
|
+
config.headers['Content-type'] = 'application/octet-stream';
|
|
121
|
+
}
|
|
122
|
+
var instance = UploadFile.init(config);
|
|
123
|
+
callback(instance);
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
var _upload = function(data, instance, callback) {
|
|
128
|
+
instance.upload(data.file, {
|
|
129
|
+
onError: function(errorCode) {
|
|
130
|
+
callback.onError(errorCode);
|
|
131
|
+
},
|
|
132
|
+
onProgress: function(loaded, total) {
|
|
133
|
+
callback.onProgress(loaded, total);
|
|
134
|
+
},
|
|
135
|
+
onCompleted: function(result) {
|
|
136
|
+
result.filename || (result.filename = result.hash);
|
|
137
|
+
var compress = data.compressThumbnail || _compress;
|
|
138
|
+
if (data.compress) {
|
|
139
|
+
compress(data, function(thumbnail) {
|
|
140
|
+
result.thumbnail = thumbnail;
|
|
141
|
+
callback.onCompleted(result);
|
|
142
|
+
});
|
|
143
|
+
} else {
|
|
144
|
+
callback.onCompleted(result);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
var File = function(instance) {
|
|
151
|
+
var me = this;
|
|
152
|
+
this.instance = instance
|
|
153
|
+
this.upload = function(file, callback) {
|
|
154
|
+
var data = {
|
|
155
|
+
file: file
|
|
156
|
+
};
|
|
157
|
+
_upload(data, me.instance, callback);
|
|
158
|
+
};
|
|
159
|
+
this.cancel = function() {
|
|
160
|
+
me.instance.cancel();
|
|
161
|
+
};
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
var initFile = function(config, callback) {
|
|
165
|
+
_init(config, function(instance) {
|
|
166
|
+
var uploadFile = new File(instance);
|
|
167
|
+
callback(uploadFile);
|
|
168
|
+
});
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
var Img = function(instance, cfg) {
|
|
172
|
+
var me = this;
|
|
173
|
+
this.cfg = cfg;
|
|
174
|
+
this.instance = instance;
|
|
175
|
+
this.upload = function(file, callback) {
|
|
176
|
+
var data = {
|
|
177
|
+
file: file,
|
|
178
|
+
compress: me.cfg
|
|
179
|
+
};
|
|
180
|
+
_upload(data, me.instance, callback);
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
this.cancel = function() {
|
|
184
|
+
me.instance.cancel();
|
|
185
|
+
};
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
var initImage = function(config, callback) {
|
|
189
|
+
_init(config, function(instance) {
|
|
190
|
+
var compress = {
|
|
191
|
+
maxHeight: config.height || 160,
|
|
192
|
+
maxWidth: config.width || 160,
|
|
193
|
+
quality: config.quality || 0.5,
|
|
194
|
+
scale: config.scale || 2.4
|
|
195
|
+
};
|
|
196
|
+
var uploadImage = new Img(instance, compress);
|
|
197
|
+
callback(uploadImage);
|
|
198
|
+
});
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
var ImgBase64 = function(config) {
|
|
202
|
+
config.base64 = true;
|
|
203
|
+
Img.call(this, config);
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
var initImgBase64 = function(config, callback) {
|
|
207
|
+
config.base64 = true;
|
|
208
|
+
initImage.call(this, config, callback);
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
return {
|
|
212
|
+
initFile: initFile,
|
|
213
|
+
initImage: initImage,
|
|
214
|
+
initImgBase64: initImgBase64,
|
|
215
|
+
dataType: UploadFile.dataType
|
|
216
|
+
};
|
|
217
217
|
}));
|