UNPKG

26.4 kBJavaScriptView Raw
1var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
2
3import jsonp from './../jsonp';
4import DB from './../DB';
5import Device from './../Device';
6import Toast from './../Toast/instance.js';
7import Alert from './../Alert/instance.js';
8import Loading from './../Loading/instance.js';
9
10if (!window._seeds_lang) window._seeds_lang = {}; // 国际化数据
11
12var Bridge = {
13 /**
14 * 基础功能:start
15 */
16 debug: false,
17 // 拨打电话
18 tel: function tel(number) {
19 if (Device.device === 'pc') {
20 this.showToast(window._seeds_lang['hint_only_mobile'] || '此功能仅可在手机中使用');
21 return;
22 }
23 if (isNaN(number)) return;
24 window.location.href = 'tel:' + number;
25 },
26 // 弹出toast
27 toast: null,
28 showToast: function showToast(msg) {
29 var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
30
31 if (!msg) return;
32 if (!this.toast) {
33 // 提示错误
34 this.toast = new Toast({
35 parent: document.body,
36 maskClass: 'mask toast-mask' + (params.mask === false ? ' toast-propagation' : ''),
37 toastClass: 'toast ' + (params.position ? params.position : 'middle'),
38 icon: params.icon || '',
39 html: msg,
40 delay: params.delay || 2000
41 });
42 } else {
43 this.toast.setHTML(msg);
44 this.toast.setMaskClassName('mask toast-mask' + (params.mask === false ? ' toast-propagation' : ''));
45 this.toast.setToastClassName('toast ' + (params.position ? params.position : 'middle'));
46 this.toast.setIcon(params.icon || '');
47 this.toast.setDelay(params.delay || 2000);
48 }
49 this.toast.show();
50 if (params.success) {
51 setTimeout(function () {
52 params.success();
53 }, params.delay ? Math.round(params.delay / 2) : 1000);
54 }
55 },
56 // 弹出loading
57 loading: null,
58 showLoading: function showLoading() {
59 var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
60
61 if (!this.loading) {
62 this.loading = new Loading({
63 caption: params.caption || window._seeds_lang['loading'] || '正在加载...',
64 type: params.type,
65 icon: params.icon || '',
66 maskCss: params.css || null
67 });
68 } else {
69 if (params.caption) this.loading.setCaption(params.caption);
70 if (params.type) this.loading.setType(params.type);
71 if (params.css) this.loading.setMaskCss(params.css);
72 if (params.icon) this.toast.setIcon(params.icon || '');
73 if (params.mask) this.loading.setMaskClassName('mask loading-mask ' + (params.mask === false ? ' loading-propagation' : ''));
74 }
75 this.loading.show();
76 },
77 hideLoading: function hideLoading() {
78 if (!this.loading) {
79 this.toast.showToast(window._seeds_lang['hint_hideloading_after_showloading'] || 'showLoading后才能hideLoading');
80 } else {
81 this.loading.hide();
82 }
83 },
84 // 弹出Alert
85 alert: null,
86 showAlert: function showAlert(msg) {
87 var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
88
89 if (!this.alert) {
90 this.alert = new Alert(_extends({}, params, {
91 html: msg,
92 onClickSubmit: function onClickSubmit(e) {
93 if (params.success) params.success(e);else e.hide();
94 }
95 }));
96 } else {
97 if (params) {
98 this.alert.reset();
99 for (var n in params) {
100 this.alert.params[n] = params[n];
101 }
102 this.alert.updateDOM();
103 this.alert.setHTML(msg);
104 }
105 }
106 this.alert.show();
107 },
108 // 弹出Confirm
109 confirm: null,
110 showConfirm: function showConfirm(msg) {
111 var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
112
113 if (!this.confirm) {
114 this.confirm = new Alert(_extends({}, params, {
115 html: msg,
116 onClickSubmit: function onClickSubmit(e) {
117 if (params.success) params.success(e);
118 },
119 onClickCancel: function onClickCancel(e) {
120 if (params.fail) params.fail(e);else e.hide();
121 }
122 }));
123 } else {
124 if (params) {
125 this.confirm.reset();
126 for (var n in params) {
127 this.confirm.params[n] = params[n];
128 }
129 this.confirm.updateDOM();
130 if (params.success) this.confirm.setOnClickSubmit(params.success);
131 if (params.fail) this.confirm.setOnClickCancel(params.fail);
132 }
133 this.confirm.setHTML(msg);
134 }
135 this.confirm.show();
136 },
137 /**
138 * 百度地图:获取当前位置名称,只支持gcj02
139 * @param {Object} params: {longitude: '', latitude: '', success: fn, fail: fn}
140 * @returns {Object} {address:'地址全称'}
141 */
142 getAddress: function getAddress() {
143 var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
144
145 var url = 'https://api.map.baidu.com/geocoder/v2/?callback=renderReverse&location=' + params.latitude + ',' + params.longitude + '&output=json&pois=1&ak=IlfRglMOvFxapn5eGrmAj65H&ret_coordtype=gcj02ll';
146 jsonp(url, null, function (err, data) {
147 if (err) {
148 if (params.fail) params.fail({ errMsg: 'getAddress:' + (window._seeds_lang['hint_address_failed'] || '获取地址失败, 请稍后重试') + err });
149 } else {
150 var addrs = {};
151 if (data.result && data.result.formatted_address) {
152 addrs.address = data.result.formatted_address;
153 if (params.success) params.success(addrs);
154 } else {
155 if (params.fail) params.fail({ errMsg: 'getAddress:' + (window._seeds_lang['hint_address_failed'] || '获取地址失败, 请稍后重试') });
156 }
157 }
158 });
159 },
160 /**
161 * 百度地图:获得天气
162 * @param {Object} params: {location: 'lng,lat|lng,lat|lng,lat' | '北京市|上海市', success: fn, fail: fn}
163 * @returns {Object} 天气信息results
164 */
165 getWeather: function getWeather() {
166 var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
167
168 var url = 'http://api.map.baidu.com/telematics/v3/weather?location=' + (params.location || '南京市') + '&output=json&ak=IlfRglMOvFxapn5eGrmAj65H';
169 jsonp(url, null, function (err, data) {
170 if (err) {
171 if (params.fail) params.fail({ errMsg: 'getWeather:' + (window._seeds_lang['hint_weather_failed'] || '获取天气失败, 请稍后重试') + err });
172 } else {
173 if (data.results && data.results.length) {
174 if (params.success) params.success(data.results);
175 } else {
176 if (params.fail) params.fail({ errMsg: 'getWeather:' + (window._seeds_lang['hint_weather_failed'] || '获取天气失败, 请稍后重试') });
177 }
178 }
179 });
180 },
181 // 客户端默认返回控制
182 back: function back(argHistory, argBackLvl) {
183 // 返回操作对象与返回层级
184 var _history = window.history;
185 if (argHistory && argHistory.go) _history = argHistory;
186 var _backLvl = argBackLvl || -1;
187
188 // 返回类型
189 var isFromApp = Device.getUrlParameter('isFromApp', location.search) || '';
190 if (isFromApp === '1') {
191 // 关闭当前页面
192 try {
193 Bridge.closeWindow();
194 } catch (error) {
195 console.log(error);
196 }
197 } else if (isFromApp === 'home') {
198 // 返回首页
199 try {
200 Bridge.goHome();
201 } catch (error) {
202 console.log(error);
203 }
204 } else if (isFromApp === 'confirm') {
205 // 提示后返回上一页
206 Bridge.showConfirm(Bridge.confirmCaption || window._seeds_lang['confirm_quit_page'] || '您确定要离开此页面吗?', {
207 success: function success(e) {
208 e.hide();
209 _history.go(_backLvl);
210 }
211 });
212 } else if (isFromApp === 'confirm-close') {
213 // 提示后关闭当前页面
214 Bridge.showConfirm(Bridge.confirmCaption || window._seeds_lang['confirm_quit_page'] || '您确定要离开此页面吗?', {
215 success: function success(e) {
216 e.hide();
217 Bridge.closeWindow();
218 }
219 });
220 } else if (isFromApp === 'custom') {
221 console.log('自定义');
222 } else {
223 // 返加上一页
224 _history.go(_backLvl);
225 }
226 },
227 // 判断是否是主页
228 isHomePage: function isHomePage(callback) {
229 this.invoke('isHomePage', null, function (data) {
230 if (data.result.toString() === '1') {
231 callback(true);
232 } else {
233 callback(false);
234 }
235 });
236 },
237 // 获得版本信息
238 getAppVersion: function getAppVersion() {
239 var ua = navigator.userAgent.toLowerCase();
240 var verExp = ua.match(/dinghuoappversion\/.{0,}(\d+\.\d+\.\d+)/);
241 if (verExp && verExp[1]) return verExp[1].trim();
242 return '';
243 },
244 // 去首页
245 goHome: function goHome(callback) {
246 this.invoke('goHome', null, callback);
247 },
248 // 退出到登陆页面
249 logOut: function logOut() {
250 this.invoke('logOut');
251 },
252 // 打开新的窗口
253 openWindow: function openWindow(params, callback) {
254 this.invoke('openWindow', params, callback);
255 },
256 // 关闭当前窗
257 closeWindow: function closeWindow(callback) {
258 this.invoke('closeWindow', null, callback);
259 },
260 // 客户端添加返回绑定
261 addBackPress: function addBackPress(callback) {
262 try {
263 this.setBackEnable(true);
264 window.addEventListener('onBackPress', callback || this.back);
265 // ios客户端返回按钮绑定(ios不支持onBackPress)
266 this.addIosBackPress(callback);
267 } catch (error) {
268 console.log(error);
269 }
270 },
271 // 客户端移除返回绑定
272 removeBackPress: function removeBackPress(callback) {
273 try {
274 this.setBackEnable(false);
275 window.removeEventListener('onBackPress', callback || this.back);
276 } catch (error) {
277 console.log(error);
278 }
279 },
280 /**
281 * 基础功能:end
282 */
283
284 /**
285 * 定制功能
286 */
287 platform: 'dinghuo',
288 config: function config() {
289 // 返回物理按键绑定
290 this.addBackPress();
291 DB.setSession('bridge_isready', '1');
292 this.registerHandler(['getGoodsByApp', 'getCartGoodsByApp', 'onBackPress', 'setOnlineByApp']);
293 },
294 // 公共方法,通过桥接调用原生方法公共入口
295 invoke: function invoke(name, param, callback) {
296 if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {
297 /* 判断iPhone|iPad|iPod|iOS */
298 /* eslint-disable */
299 this.setup(function (bridge) {
300 bridge.callHandler(name, param, function (response) {
301 if (callback) {
302 try {
303 callback(JSON.parse(response));
304 } catch (e) {
305 callback(response);
306 }
307 }
308 });
309 });
310 /* eslint-enable */
311 } else if (/(Android)/i.test(navigator.userAgent)) {
312 /* 判断Android */
313 // 注册分类页面事件
314 if (window.WebViewJavascriptBridge) {
315 window.WebViewJavascriptBridge.callHandler(name, param && JSON.stringify(param), function (response) {
316 if (callback) {
317 try {
318 callback(JSON.parse(response));
319 } catch (e) {
320 callback(response);
321 }
322 }
323 });
324 } else {
325 document.addEventListener('WebViewJavascriptBridgeReady', function () {
326 window.WebViewJavascriptBridge.callHandler(name, param && JSON.stringify(param), function (response) {
327 if (callback) {
328 try {
329 callback(JSON.parse(response));
330 } catch (e) {
331 callback(response);
332 }
333 }
334 });
335 }, false);
336 }
337 }
338 },
339 setup: function setup(callback) {
340 /* eslint-disable */
341 if (window.WebViewJavascriptBridge) {
342 return callback(WebViewJavascriptBridge);
343 }
344 if (window.WVJBCallbacks) {
345 return window.WVJBCallbacks.push(callback);
346 }
347 window.WVJBCallbacks = [callback];
348 var WVJBIframe = document.createElement('iframe');
349 WVJBIframe.style.display = 'none';
350 WVJBIframe.src = 'https://__bridge_loaded__';
351 document.documentElement.appendChild(WVJBIframe);
352 setTimeout(function () {
353 document.documentElement.removeChild(WVJBIframe);
354 }, 0);
355 /* eslint-enable */
356 },
357
358 // 注册事件
359 registerHandler: function registerHandler(events) {
360 if (typeof window !== 'undefined') {
361 if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {
362 /* 判断iPhone|iPad|iPod|iOS */
363 /* eslint-disable */
364 this.setup(function (bridge) {
365 events.forEach(function (eventName) {
366 bridge.registerHandler(eventName, function () {
367 var event = new CustomEvent(eventName);
368 // 分发事件
369 window.dispatchEvent(event);
370 });
371 });
372 });
373 /* eslint-enable */
374 } else if (/(Android)/i.test(navigator.userAgent)) {
375 /* 判断Android */
376 // 注册分类页面事件
377 if (window.WebViewJavascriptBridge) {
378 events.forEach(function (eventName) {
379 window.WebViewJavascriptBridge.registerHandler(eventName, function () {
380 var event = new CustomEvent(eventName);
381 // 分发事件
382 window.dispatchEvent(event);
383 });
384 });
385 } else {
386 document.addEventListener('WebViewJavascriptBridgeReady', function () {
387 events.forEach(function (eventName) {
388 window.WebViewJavascriptBridge.registerHandler(eventName, function () {
389 var event = new CustomEvent(eventName);
390 // 分发事件
391 window.dispatchEvent(event);
392 });
393 });
394 }, false);
395 }
396 }
397 }
398 },
399 /**
400 * 支付宝支付
401 * @param {Object} params {orderInfo: ''}
402 * @param {Function} callback
403 * @callback(result) {Object} {code: "0", message: "支付成功"}|{code: "-1", message: "支付失败"}|{code: "-1", message: "数据解析异常"}
404 */
405 alipay: function alipay(params, callback) {
406 this.invoke('alipay', params, callback);
407 },
408 /**
409 * 商联支付
410 * @param {Object} params {appKey:'', dealerCode:'', orderId:'', payAmount:''}
411 * @param {Function} callback 回调
412 */
413 slopenpay: function slopenpay(params, callback) {
414 this.invoke('slopenpay', params, callback);
415 },
416 /**
417 * 大华捷通支付
418 * @param {Object} params {payChannel:'UPPay 云闪付 WXPay微信支付 AliPay 支付宝支付', payData:'服务端获取'}
419 * @param {Function} callback 回调
420 */
421 qmfpay: function qmfpay(params, callback) {
422 // resultCode:
423 // 0000 支付请求发送成功,商户订单是否成功支付应该以商户后台收到支付结果
424 // 1000 用户取消支付
425 // 1001 参数错误
426 // 1002 网络连接错误
427 // 1003 支付客户端未安装
428 // 2001 订单处理中,支付结果未知(有可能已经支付成功),请通过后台接口查询订单状态
429 // 2002 订单号重复
430 // 2003 订单支付失败
431 // 9999 其他支付错误
432 // 5004 版本过低
433 if (Bridge.getAppVersion() < '2.3.6') {
434 callback({ resultCode: '5004', resultInfo: '{"resultMsg":"请安装2.3.6以上版本"}' });
435 return;
436 }
437 this.invoke('qmfpay', params, callback);
438 },
439 /**
440 * 修改原生标题
441 * @param {Object} params {title: '自定义标题'}
442 * @param {Function} callback 回调
443 */
444 setTitle: function setTitle(params, callback) {
445 this.invoke('setTitle', params, callback);
446 },
447 /**
448 * ios绑定左上角返回按钮
449 * @param {Object} params {title: '自定义标题'}
450 * @param {Function} callback 回调
451 */
452 onHistoryBack: function onHistoryBack(callback) {
453 this.invoke('onHistoryBack', null, callback);
454 },
455 // ios客户端返回按钮绑定, ios不支持addBackPress
456 addIosBackPress: function addIosBackPress(callback) {
457 var _this = this;
458
459 this.onHistoryBack(function () {
460 if (callback) callback();else if (_this.back) _this.back();
461 _this.addIosBackPress(callback);
462 });
463 },
464 /**
465 * 分享文本
466 * @param {Object} params
467 * {
468 * title: '标题(仅ios支持)',
469 * desc: '副标题(仅ios支持)',
470 * link: '链接(仅ios支持)',
471 * text: '文本(安卓只支持发送文本)',
472 * }
473 * @param {Function} callback 回调
474 */
475 shareText: function shareText(params, callback) {
476 this.invoke('shareText', params, callback);
477 },
478 /**
479 * 获取订货包名
480 * @param {Function} callback({result: 'cn.com.wq.ordergoods'}), ios包名cn.com.wq.ordergoods, andriod包名com.waiqin365.dhcloud
481 */
482 getIdentification: function getIdentification(callback) {
483 if (Bridge.getAppVersion() < '2.3.6') {
484 callback({});
485 return;
486 }
487 this.invoke('getIdentification', null, callback);
488 },
489 /* -----------------------------------------------------
490 文件操作
491 ----------------------------------------------------- */
492 /* 文件是否存在
493 isExistsFile({
494 "fileName": "ss.txt",
495 "size": 200
496 }, (result) => {
497 // 返回格式 {{"isExists":"","filePath":"","fileName":""},isExists:'0'不存在,'1'存在
498 })
499 */
500 isExistsFile: function isExistsFile(params, callback) {
501 this.invoke('isExistsFile', params, callback);
502 },
503 /* 附件下载
504 downloadFile({
505 "id": "id",
506 "fileName": "ss.txt",
507 "downloadUrl": "http://...",
508 "size": 200
509 }, (result) => {
510 // 返回格式 {{"code":"","filePath":"","message":""},code:'0'失败,'1'成功,message失败原因
511 }) */
512 downloadFile: function downloadFile(params, callback) {
513 this.invoke('downloadFile', params, callback);
514 },
515 /* 附件打开
516 openFile({
517 "filePath": ""
518 }, (result) => {
519 // 返回格式 {{"code":"","message":""},code:'0'失败,'1'成功,message失败原因
520 }) */
521 openFile: function openFile(params, callback) {
522 this.invoke('openFile', params, callback);
523 },
524 /* -----------------------------------------------------
525 扫描二维码并返回结果
526 @return {resultStr:''}
527 ----------------------------------------------------- */
528 scanQRCode: function scanQRCode(params) {
529 this.invoke('scanQRCode', null, params.success);
530 },
531 /**
532 * 获取当前地理位置
533 * @param {Object} params
534 * params: {
535 * type {String}: 'wgs84'|'gcj02'坐标类型微信默认使用国际坐标'wgs84',
536 * cache {Number}: 默认60秒缓存防重复定位
537 * }
538 * @returns {Object} {latitude: '纬度', longitude: '经度', speed:'速度', accuracy:'位置精度'}
539 */
540 getLocation: function getLocation() {
541 var _this2 = this;
542
543 var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
544
545 // 先从cookie中读取位置信息
546 var appLocation = DB.getCookie('app_location');
547 if (appLocation === 'undefined') {
548 DB.removeCookie('app_location');
549 appLocation = '';
550 }
551 try {
552 if (appLocation) appLocation = JSON.parse(appLocation);
553 } catch (error) {
554 appLocation = '';
555 }
556 if (appLocation) {
557 if (params.success) params.success(appLocation);
558 return;
559 }
560
561 // 调用定位
562 if (this.locating) return;
563 this.locating = true;
564 console.log('调用定位...');
565 this.invoke('getLocation', 'gcj02', function (res) {
566 _this2.locating = false;
567 if (res && res.latitude) {
568 // 将位置信息存储到cookie中60秒
569 if (params.cache) DB.setCookie('app_location', JSON.stringify(res), params.cache || 60);
570 if (params.success) params.success(res);
571 } else {
572 if (params.fail) params.fail({ errMsg: 'getLocation:定位失败,请检查订货365定位权限是否开启' });else Bridge.showToast('定位失败,请检查订货365定位权限是否开启', { mask: false });
573 }
574 });
575 },
576 /* -----------------------------------------------------
577 获取当前网络状态
578 @return {networkType:'返回网络类型2g,3g,4g,wifi'}
579 ----------------------------------------------------- */
580 getNetworkType: function getNetworkType(callback) {
581 this.invoke('getNetworkType', null, callback);
582 },
583 /* -----------------------------------------------------
584 拍照、本地选图
585 @params:{sourceType:['album:相册', 'camera:拍照'],sizeType:['original:原图', 'compressed:压缩'],count:'最大张数'}
586 @return 选定照片的本地ID列表{localIds:[id,id,id]'}, src需要增加前缀'LocalResource://imageid'+id才能显示
587 ----------------------------------------------------- */
588 chooseImage: function chooseImage(params) {
589 this.invoke('chooseImage', params, params.success);
590 },
591 /* -----------------------------------------------------
592 上传图片
593 @params {dir:'',localIds:['localId', 'localId'], tenantId: ''}
594 ----------------------------------------------------- */
595 uploadImage: function uploadImage() {
596 var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
597
598 if (!params.dir) {
599 Bridge.showToast(window._seeds_lang['hint_upload_image_must_dir'] || '没有上传目录dir, 无法上传', { mask: false });
600 return;
601 }
602 if (!params.localIds || Object.isEmptyObject(params.localIds)) {
603 Bridge.showToast('请传入上传图片列表后再上传图片', { mask: false });
604 return;
605 }
606 // 格式化params
607 var uploadParams = {
608 localIds: params.localIds,
609 uploadDir: params.dir
610 };
611 if (uploadParams.tenantId) params.tenantId = params.tenantId;
612 this.invoke('uploadImage', uploadParams);
613 },
614 // 获取带前缀的图片
615 getPreviewImages: function getPreviewImages(imgIds) {
616 return imgIds.map(function (imgId) {
617 return 'LocalResource://imageid' + imgId;
618 });
619 },
620 getPreviewImage: function getPreviewImage(imgId) {
621 return 'LocalResource://imageid' + imgId;
622 },
623 /* -----------------------------------------------------
624 图片预览
625 备注:图片LocalResource://imageid标识为本地,客户端优先从本地查找,本地没有再从网络加载
626 @params {urls:'需要预览的图片http链接列表',current:'当前显示图片的http链接',index:'图片索引'}
627 ----------------------------------------------------- */
628 previewImage: function previewImage(argParams) {
629 if (!argParams.urls || !argParams.urls.length) return;
630 var self = this;
631 // 如果是网络图片直接显示,如果是本地图片,则加上前缀再显示
632 var params = argParams;
633 params.urls = argParams.urls.map(function (url) {
634 if (url.indexOf('//') === -1 && url.indexOf('http://') === -1 && url.indexOf('https://') !== -1) {
635 return self.getPreviewImage(url);
636 }
637 return url;
638 });
639 this.invoke('previewImage', params);
640 },
641 /* -----------------------------------------------------
642 监听/取消监听物理返回事件(仅android)
643 @params true:监听 | false:取消监听
644 ----------------------------------------------------- */
645 setBackEnable: function setBackEnable(flag) {
646 if (/(Android)/i.test(navigator.userAgent)) {
647 /* 判断Android */
648 this.invoke('setBackEnable', flag);
649 }
650 },
651 // 获取图片前缀
652 getImagePrefix: function getImagePrefix() {
653 return 'LocalResource://imageid';
654 },
655 // 下载图片
656 downloadImage: function downloadImage() {},
657 // 分享给朋友
658 onMenuShareAppMessage: function onMenuShareAppMessage() {},
659 // 分享到朋友圈
660 onMenuShareTimeline: function onMenuShareTimeline() {},
661 // 获取登陆信息
662 loginInfo: function loginInfo(callback) {
663 this.invoke('getLoginInfo', null, callback);
664 },
665 // 根据key获取登陆信息
666 getLoginInfo: function getLoginInfo(key, callback) {
667 this.loginInfo(function (result) {
668 callback(result[key]);
669 });
670 },
671
672 // 获取系统参数
673 systemParameter: function systemParameter(callback) {
674 this.invoke('getSystemParameter', null, callback);
675 },
676
677 // 修改原生角标
678 changeBadgeNum: function changeBadgeNum(count) {
679 this.invoke('setBadgeNum', { key: count });
680 },
681
682 /* 封装图片控件,使用示例见ImgUploader组件
683 bridge.Image({
684 onChooseSuccess: function (imgMap) {},
685 })
686 */
687 Image: function Image() {
688 var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
689
690 var s = this;
691 var msg = '';
692 // 选择照片
693 s.choose = function () {
694 var args = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
695
696 var option = {
697 enableSafe: args.enableSafe || false, // 安全上传,第次只能传一张
698 max: args.max || 5,
699 currentCount: args.currentCount || 0,
700 sourceType: args.sourceType || ['album', 'camera'],
701 sizeType: args.sizeType || ['original', 'compressed'],
702 chooseOptions: args.chooseOptions || {}
703 /* watermark: {
704 orderNo: 'xx', // 编号
705 submitName: 'xx', // 提交人
706 customerName: 'xx', // 客户
707 cmLocation: '118.730515, 31.982473', // 位置算偏差
708 isWaterMark: '1', // 是否启用水印
709 } */
710 };var count = option.max - option.currentCount;
711 if (count <= 0) {
712 msg = (window._seeds_lang['hint_max_upload'] || '最多只能传') + option.max + (window._seeds_lang['photos'] || '张照片');
713 Bridge.showToast(msg);
714 return;
715 }
716 // 如果设置了安全上传,则每次只允许上传一张
717 if (option.enableSafe) count = 1;
718 Bridge.chooseImage(Object.assign({
719 count: count, // 默认5
720 sizeType: option.sizeType, // 可以指定是原图还是压缩图,默认二者都有
721 sourceType: option.sourceType, // 可以指定来源是相册还是相机,默认二者都有camera|album
722 success: function success(res) {
723 var imgMap = {};
724 for (var i = 0, localId; localId = res.localIds[i++];) {
725 // eslint-disable-line
726 imgMap[localId] = {
727 serverId: '',
728 sourceType: JSON.stringify(option.sourceType) === JSON.stringify(['camera']) ? 'camera' : 'album'
729 };
730 }
731 if (params.onChooseSuccess) params.onChooseSuccess(imgMap, res);
732 }
733 }, option.chooseOptions));
734 };
735 }
736};
737
738export default Bridge;
\No newline at end of file