扩展代码:
1 /* 2 *分享到微博 3 */ 4 Ext.define('ux.WeiboPicker', { 5 extend: 'Ext.Picker', 6 xtype: 'weiboPicker', 7 config: { 8 toolbar: { 9 ui: 'light', 10 title: '分享到' 11 }, 12 value: { 13 weibo: 'sinaminiblog' 14 }, 15 slots: [{ 16 name: 'weibo', 17 data: [{ 18 text: '新浪微博', 19 value: 'sinaminiblog' 20 }, 21 { 22 text: '人人网', 23 value: 'renren' 24 }] 25 }], 26 //分享到参数 27 weiboParams: null 28 }, 29 /*显示分享到微博参数格式{url:url,title:title,summary:summary,publisherUuid:publisherUuid,pic:pic} 30 *url为必填项,必须为以下格式 http://www.baidu.com 31 * 具体参考http://www.bshare.cn/help/apiRedirect 32 */ 33 show: function (params) { 34 this.setWeiboParams(params); 35 this.callParent(arguments); 36 }, 37 //确定 38 onDoneButtonTap: function () { 39 var params = this.getWeiboParams(); 40 var url = 'http://api.bshare.cn/share/' + this.getValue().weibo + '?1=1'; 41 for (var item in params) { 42 var value = params[item]; 43 if (item == 'url') { 44 value = escape(value); //转码特殊符号防止url中包含参数 45 } 46 url = url + '&' + item + '=' + value; 47 } 48 window.open(url, '_system'); 49 this.endPick(); 50 }, 51 //取消 52 onCancelButtonTap: function () { 53 this.endPick(); 54 }, 55 //销毁 56 endPick: function () { 57 this.hide(); 58 this.destroy(); 59 } 60 });
使用示例:
1 var weibo = Ext.create('ux.WeiboPicker'); 2 Ext.Viewport.add(weibo); 3 weibo.showWeibo({ url: 'http://www.baidu.com', title: '分享标题' });
效果图: