dever 4 years ago
parent
commit
e2234b303e
2 changed files with 23 additions and 18 deletions
  1. 3 1
      lib/dever/components/share.vue
  2. 20 17
      lib/dever/index.js

+ 3 - 1
lib/dever/components/share.vue

@@ -62,6 +62,8 @@
 				icon: '/static/dever/copy.png',
 				type: 'copy'
 			});
+			
+			this.init();
 		},
 		methods: {
 			open : function() {
@@ -69,7 +71,7 @@
 			},
 			
 			init : function() {
-				this.Dever.shareInit(this.data);
+				this.Dever.shareInit(wx, 1, 1, this.data);
 			},
 			
 			share : function(type) {

+ 20 - 17
lib/dever/index.js

@@ -561,20 +561,22 @@ var share =
     wechat : false,
     url : '',
     project : '',
-    uid : '-1',
+    token : '',
     param : {
         title : '',
         pic : '',
         content : '',
         link : '',
-    },
-    init : function(uid, project, url, param, button)
+    },
+	wx : false,
+    init : function(wx, project, host, param)
     {
-        var self = this;
+        var self = this;
+		self.wx = wx;
         self.wechat = dever.is_weixin();
         self.project = project;
-        self.url = url;
-        self.uid = uid;
+        self.url = host;
+        self.token = http.getToken();
         self.param = param;
 		self.param.timelineCallback = function() {};
 		self.param.sendMessageCallback = function() {};
@@ -596,9 +598,10 @@ var share =
 		options.project = project;
 		options.url = location.href.split('#')[0];
 		options.noloading = 1;
+		options.token = this.token;
 		http.request('post', url, options, function(result) {
 			var data = result.data;
-			wx.config({
+			self.wx.config({
 			    //debug:true,
 			    appId: data.appId,
 			    timestamp: data.timestamp,
@@ -611,8 +614,8 @@ var share =
 			    ]
 			});
 			
-			wx.ready(function() {
-			    wx.onMenuShareAppMessage({
+			self.wx.ready(function() {
+			    self.wx.onMenuShareAppMessage({
 			        title: param.title,
 			        desc: param.content,
 			        link: param.link,
@@ -630,7 +633,7 @@ var share =
 			            self.shareLog(1, 3);
 			        }
 			    });
-			    wx.onMenuShareTimeline({
+			    self.wx.onMenuShareTimeline({
 			        title: param.title,
 			        link: param.url,
 			        imgUrl: param.img,
@@ -647,7 +650,7 @@ var share =
 			            self.shareLog(2, 3);
 			        }
 			    });
-			    wx.onMenuShareQQ({
+			    self.wx.onMenuShareQQ({
 			        title: param.title,
 			        link: param.url,
 			        imgUrl: param.img,
@@ -674,22 +677,22 @@ var share =
             param = location.search.substr(1),
             ua = encodeURIComponent(navigator.userAgent),
             project = this.project,
-            uid = this.uid,
+            token = this.token,
             wechat = this.wechat;
 
         if (param.indexOf("tsina-") > -1 || param.indexOf("timeline") > -1 || param.indexOf("singlemessage") > -1 || param.indexOf("groupmessage") > -1) {
-            var url = this.url + 'reflux?callback=?' + '&project='+project+'&url=' + url + '&ua=' + ua + '&param=' + encodeURIComponent(param) + '&uid=' + uid + '&type=' + wechat;
+            var url = this.url + 'reflux?callback=?' + '&project='+project+'&url=' + url + '&ua=' + ua + '&param=' + encodeURIComponent(param) + '&token=' + token + '&type=' + wechat;
 			http.request('post', url, {noloading:1});
         }
     }
 
     ,shareLog: function(actType, actResult) {
         var project = this.project;
-        var uid = this.uid;
+        var token = this.token;
         var wechat = this.wechat;
         var ua = encodeURIComponent(navigator.userAgent);
         var url = encodeURIComponent(document.location.href);
-		var url = this.url + 'collect?callback=?' + '&project='+project+'&url=' + url + '&actType=' + actType + '&actResult=' + actResult + '&ua=' + ua + '&uid=' + uid + '&type=' + wechat
+		var url = this.url + 'collect?callback=?' + '&project='+project+'&url=' + url + '&actType=' + actType + '&actResult=' + actResult + '&ua=' + ua + '&token=' + token + '&type=' + wechat
 		http.request('post', url, {noloading:1});
     }
 }
@@ -1613,8 +1616,8 @@ var dever = {
 	},
 	
 	//分享功能初始化
-	shareInit : function(data) {
-		
+	shareInit : function(wx, project, host, data) {
+		share.init(wx, project, host, data);
 	},
 	
 	//通用的分享功能