dever 4 years ago
parent
commit
f2e74c2f9d
8 changed files with 162 additions and 62 deletions
  1. 2 2
      lib/dever/config.js
  2. 122 51
      lib/dever/index.js
  3. 1 1
      manifest.json
  4. 1 1
      pages/chat/user.vue
  5. 18 4
      pages/dream/index.vue
  6. 6 0
      pages/dream/view.vue
  7. 1 1
      pages/user/index.vue
  8. 11 2
      pages/user/login.vue

+ 2 - 2
lib/dever/config.js

@@ -10,8 +10,8 @@ const im = {
 //http request请求配置
 const request = {
 	//	服务器接口地址
-	host: "http://dl.shemic.com/",
-	host: "http://dev.shemic.com/dreamland/",
+	host: "https://dl.shemic.com/",
+	//host: "http://dev.shemic.com/dreamland/",
 	
 	//	请求的参数	
 	data: {},

+ 122 - 51
lib/dever/index.js

@@ -26,24 +26,25 @@ var http = {
 	},
 	
 	//request请求
-	request: function(vue, url, options, callback, err_callback) {
-		var self = this;
-		if (vue == 'post') {
+	request: function(vue, url, options, callback, err_callback, type) {
+		var self = this;
+		if (vue == 'post') {
 			config.request.method = 'POST';
-			config.request.method = 'GET';
-			vue = false;
-		} else {
-			config.request.method = 'GET';
-		}
-		if (typeof(url) == 'object') {
-			vue = url[1];
-			url = url[0];
-		}
-		if (typeof(vue) == 'object') {
-			vue.isDisabled = true;
+			//config.request.method = 'GET';
+			vue = false;
+		} else {
+			config.request.method = 'GET';
+		}
+		var method = config.request.method;
+		if (typeof(url) == 'object') {
+			vue = url[1];
+			url = url[0];
+		}
+		if (typeof(vue) == 'object') {
+			vue.isDisabled = true;
 		}
 		
-		self.core(url, options).then((result, state) => {
+		self.core(url, options, type, method).then((result, state) => {
 			if (typeof(vue) == 'object') {
 				if (!vue.fetch) {
 					vue.fetch = {}
@@ -71,7 +72,7 @@ var http = {
 		})
 	},
 	
-	core : function(url, options) {
+	core : function(url, options, type, method) {
 		var self = this;
 		options = this.option(options);
 		if (!options.noconcat) {
@@ -88,7 +89,11 @@ var http = {
 			loading_method = 'page';
 		}
 		if (config.request.url.indexOf('http') == -1) {
-			config.request.url = config.request.host + config.request.url;
+			if (type == 'im') {
+				config.request.url = config.im.api + config.request.url;
+			} else {
+				config.request.url = config.request.host + config.request.url;
+			}
 		}
 		config.request.data = options;
 		return new Promise((resolve, reject) => {
@@ -221,49 +226,100 @@ var http = {
 }
 
 var im = {
-	socket : false,
-	url : 'ws://me.5dev.cn:8282',
-	init : function(url, callback, connect) {
-		if (url) {
-			this.url = url;
-		} else {
-			this.url = config.im.host;
+	socket : {},
+	status : false,
+	//host
+	url : 'ws://me.5dev.cn:8282',
+	//推送路径
+	push_path : '',
+	init : function(key, url, callback, connect) {
+		if (url) {
+			this.url = url;
+		} else {
+			this.url = config.im.host;
 		}
-		this.connect(connect);
-		this.info(callback);
+		this.connect(key, callback, connect);
 	},
 	
-	connect : function(connect) {
-		uni.connectSocket({
+	connect : function(key, callback, connect) {
+		var self = this;
+		this.close(key);
+		this.socket[key] = uni.connectSocket({
 			url: this.url,
-			complete: (res)=> {
+			complete: (res)=> {
 				
 			}
 		});
-		uni.onSocketOpen(function (res) {
-		  if (connect) {
-		  	connect(true, res);
-		  }
+		this.socket[key].onOpen(function (res) {
+		  if (connect) {
+		  	connect(true, res);
+		  }
+		  console.info('open');
+		  self.status = true;
+		  
+		  self.socket[key].onMessage(function (res) {
+		  	if (res.data.indexOf('{') != -1) {
+		  		var data = eval("("+res.data+")");
+		  	} else {
+		  		var data = res.data;
+		  	}
+		  	
+		  	if (callback) {
+		  		callback(data);
+		  	}
+		  });
 		});
-		uni.onSocketError(function (res) {
-		  if (connect) {
-		  	connect(false, res);
-		  }
+		this.socket[key].onClose(function (res) {
+		  if (connect) {
+		  	connect(false, res);
+		  }
+		  console.info('close');
+		  self.status = false;
 		});
-		
+		
+		this.socket[key].onError(function (res) {
+			console.info('error');
+			self.connect(callback, connect);
+		});
+	},
+	
+	close : function(key) {
+		var self = this;
+		if (this.socket[key]) {
+			this.socket[key].close({
+				success(res) {
+					self.status = false;
+				},
+				fail(err) {
+					self.status = true;
+				}
+			})
+		}
 	},
 	
-	info : function(callback) {
-		uni.onSocketMessage(function (res) {
-			if (res.data.indexOf('{') != -1) {
-				var data = eval("("+res.data+")");
-			} else {
-				var data = res.data;
-			}
-			
-			if (callback) {
-				callback(data);
+	get : function(vue, url, options, callback, err_callback) {
+		this.request(vue, url, options, callback, err_callback); 
+	},
+	
+	post : function(url, options, callback, err_callback) {
+		this.request('post', url, options, callback, err_callback); 
+	},
+	
+	request : function(vue, url, options, callback, err_callback) {
+		if (!options) {
+			options = {};
+		}
+		var param = options;
+		param.noloading = 1;
+		dever.post(this.push_path, param, function(t) {
+			url += '?timestamp=' + t.timestamp + '&pop_token=' + t.token + '&login_uid=' + t.login_uid;
+			dever.config.im = t;
+			options.login_uid = t.login_uid;
+			if (t.friend_uid) {
+				options.friend_uid = t.friend_uid;
 			}
+			delete options.noloading;
+			http.request(vue, url, options, callback, err_callback, 'im');
 		});
 	}
 }
@@ -1198,9 +1254,24 @@ var dever = {
 		return upload;
 	},
 	
-	//im聊天
-	im : function(url, callback, connect) {
-		im.init(url, callback, connect);
+	//im聊天
+	im : function(key, url, callback, connect) {
+		im.init(key, url, callback, connect);
+	},
+	
+	//im聊天关闭
+	im_close : function(key) {
+		im.close(key);
+	},
+	
+	//im聊天 get请求
+	im_get : function(vue, url, options, callback, err_callback) {
+		im.get(vue, url, options, callback, err_callback);
+	},
+	
+	//im聊天 post请求
+	im_post : function(url, options, callback, err_callback) {
+		im.post(url, options, callback, err_callback);
 	},
 	
 	//删除上传

+ 1 - 1
manifest.json

@@ -100,7 +100,7 @@
         },
         "title" : "合小记",
         "devServer" : {
-            "https" : false,
+            "https" : true,
             "port" : ""
         },
         "domain" : "http://he.shemic.com/",

+ 1 - 1
pages/chat/user.vue

@@ -98,7 +98,7 @@
 			
 			im : function() {
 				var self = this;
-				this.Dever.im(false, function(t) {
+				this.Dever.im('chat', false, function(t) {
 					if (t.type == 'init') {
 						self.Dever.post('app/community/?l=chat.init', {code:self.Dever.config.code, client_id: t.client_id, uid:self.uid, noloading:1});
 					} else if (t.type == 'ping') {

+ 18 - 4
pages/dream/index.vue

@@ -109,9 +109,7 @@ export default{
 	},
 	onLoad(option) {
 		this.id = option.id;
-		this.code = option.code;
-		this.Dever.login = 'user/login?id=' + this.id;
-		this.Dever.checkLogin();
+		this.code = option.code;
 		this.getData();
 	},
 	// 重新加载
@@ -130,7 +128,23 @@ export default{
 				});
 			});
 		},
-		goView : function() {
+		goView : function() {
+			//是否登录
+			var token = this.Dever.getToken();
+			if (!token) {
+				var self = this;
+				this.Dever.alert('您还未登录,请先登录', 'none', function() {
+					if (self.id) {
+						self.Dever.login = 'user/login?id=' + self.id;
+					} else if (self.code) {
+						self.Dever.login = 'user/login?code=' + self.code;
+					}
+					
+					self.Dever.checkLogin();
+				});
+				
+				return;
+			}
 			//是否购买
 			if (!this.fetch.is_buy) {
 				this.showBuy();

+ 6 - 0
pages/dream/view.vue

@@ -130,11 +130,17 @@ export default{
 		}
 	},
 	onLoad(option) {
+		if (!option.code) {
+			this.Dever.location('index/index');
+			return;
+		}
 		if (option && option.name) {
 			uni.setNavigationBarTitle({
 				title:option.name
 			});
 		}
+		this.Dever.login = 'user/login?code=' + option.code;
+		this.Dever.checkLogin();
 		this.Dever.config.name = option.name;
 		this.Dever.config.code = option.code;
 		this.getData();

+ 1 - 1
pages/user/index.vue

@@ -39,7 +39,7 @@
 			
 			<!-- 底部信息 -->
 			<view class="footer">
-				<navigator url="forget" open-type="navigate" @click="shiming">实名认证</navigator>
+				<navigator url="forget" open-type="navigate" @click="shiming">关系伙伴</navigator>
 				<text>|</text>
 				<navigator url="register" open-type="navigate" @click="tixian">快速提现</navigator>
 			</view>

+ 11 - 2
pages/user/login.vue

@@ -78,6 +78,7 @@
 		data() {
 			return {
 				id : 0,
+				code : '',
 				system_logo : '',
 				system_name : '',
 				phoneData:'', // 用户/电话
@@ -94,12 +95,20 @@
 		onLoad(option) {
 			self = this;
 			self.id = option.id;
+			self.code = option.code;
 			self.getData();
 		},
 		methods: {
 			getData : function() {
-				if (self.id) {
-					self.Dever.get(self, 'app/collection/?l=api.getConfig', {id:self.id}, function(t) {
+				if (self.id || self.code) {
+					var data = {};
+					if (self.id) {
+						data.id = self.id;
+					}
+					if (self.code) {
+						data.code = self.code;
+					}
+					self.Dever.get(self, 'app/collection/?l=api.getConfig', data, function(t) {
 						uni.setNavigationBarTitle({
 							title:t.info.name
 						});