rabin 7 年之前
父節點
當前提交
65609ae077

文件差異過大導致無法顯示
+ 0 - 0
front/static/pc/js/global.js


+ 32 - 3
front/static/pc/js/main.js

@@ -69,7 +69,7 @@ var Farm =
 		} else {
 			e.attr('data-status', 1);
 		}
-		self.clearLoop();
+		self.ClearLoop();
 		e.addClass('loading');
 		self.Request('post', url, data, function(msg)
 		{	
@@ -85,6 +85,35 @@ var Farm =
 		})
 	}
 
+	,Button : function(obj, url, id, value, disabledId)
+	{
+		var self = this;
+		var e = $(obj);
+		var c = e.attr('class');
+		var p = e.parent();
+		if (c.indexOf('disabled') != -1) {
+			return;
+		}
+		var name = e.html();
+		p.find('.open').removeClass('open');
+		e.addClass('open');
+		if (disabledId) {
+			$(disabledId).addClass('disabled');
+		} else {
+			p.find('.disabled').removeClass('disabled');
+		}
+		data = {};
+		data.id = id;
+		data.value = value;
+		self.ClearLoop();
+		e.addClass('loading');
+		self.Request('post', url, data, function(msg)
+		{	
+			e.removeClass('loading');
+			self.CreateLoop();
+		})
+	}
+
 	,Request : function(type, url, data, callback)
 	{
 		data._xsrf = this.Cookie("_xsrf");
@@ -188,7 +217,7 @@ var Farm =
 
 	,ShowChart : function(url) {
 		this.url = url;
-		this.clearLoop();
+		this.ClearLoop();
 		this.Load();
 		document.getElementById('chart').scrollIntoView();
 	}
@@ -199,7 +228,7 @@ var Farm =
 		}
 	}
 
-	,clearLoop : function() {
+	,ClearLoop : function() {
 		if (this.loop) {
 			clearInterval(this.loop);
 			this.loop = false;

文件差異過大導致無法顯示
+ 21 - 1
front/static/pc/kzsb.html


文件差異過大導致無法顯示
+ 21 - 0
front/templates/pc/device/data.html


+ 14 - 0
front/templates/pc/device/inc/data.html

@@ -34,6 +34,20 @@
             <dt>{{value['value']}}</dt>
             <dd class="tit" {% if 'stat' in data and data['stat'] %}style="cursor: pointer;"  onclick="Farm.ShowChart('{{loadUrl}}&device={{value['id']}}')"{% end %}>{{value['name']}}({{value['unit']}})</dd>
         </dl>
+        {% elif value['hardware_type'] == 3 and value['unit'] == 'button' %}
+        <dl class="button">
+            {% if 'noset' not in data %}
+            <dd class="controller"></dd>
+            {% end %}
+            <dt>
+                <button onclick="Farm.Button(this, '/device/update', '{{value['id']}}', 1, '#button_down_{{value['id']}}')" id="button_up_{{value['id']}}" class="btn-switch {% if value['value'] in ('2','3') %}disabled{% end %} {% if value['value'] in ('1','4') %}open{% end %}"></button>
+
+                <button onclick="Farm.Button(this, '/device/update', '{{value['id']}}', 5)" id="button_stop_{{value['id']}}" class="btn-switch {% if value['value'] == '5' %}open{% end %}"></button>
+
+                <button onclick="Farm.Button(this, '/device/update', '{{value['id']}}', 2, '#button_up_{{value['id']}}')" id="button_down_{{value['id']}}" class="btn-switch {% if value['value'] in ('1','4') %}disabled{% end %} {% if value['value'] in ('2','3') %}open{% end %}"></button>
+            </dt>
+            <dd class="tit">{{value['name']}}</dd>          
+        </dl>
         {% elif value['hardware_type'] == 3 %}
         <dl>
             {% if 'noset' not in data %}

+ 1 - 0
install.py

@@ -105,6 +105,7 @@ def device():
 		,{'name':'电源', 'key':'power','unit':'V'}
 		,{'name':'阀门', 'key':'valve','unit':''}
 		,{'name':'放风机', 'key':'blower','unit':''}
+		,{'name':'卷帘机', 'key':'curtain','unit':''}
 		)
 	model = Demeter.model('device_type')
 	for value in device_type:

+ 10 - 0
pub.py

@@ -12,6 +12,16 @@ import random
 import time
 import base64
 
+"""
+def callback(param, client, userdata, mid):
+	print mid
+
+pub = Pub()
+key = 'update/test/222/222'
+value = 2
+state = pub.push(key, value, 2, callback=callback, param='ttt')
+print state
+"""
 def push():
 	# 模拟传感器设备数据
 	gateway = 10086

+ 3 - 3
service/device.py

@@ -56,8 +56,8 @@ class Device(object):
 		model.id = device_id
 		info = model.select(type='fetchone')
 		if info:
-			model.id = device_id
-			model.update(value=switch)
+			#model.id = device_id
+			#model.update(value=switch)
 			model = Demeter.model('device_gateway')
 			model.id = info['gateway_id']
 			gateway_info = model.select(type='fetchone')
@@ -71,7 +71,7 @@ class Device(object):
 					switch = str(switch)
 					gateway_info['hardware_id'] = str(gateway_info['hardware_id'])
 					# 这里要向服务器发送pub请求了,暂时使用临时文件代替
-					Demeter.temp(key=type_info['key'], name=info['hardware_id'], value=switch)
+					#Demeter.temp(key=type_info['key'], name=info['hardware_id'], value=switch)
 					#pub
 					pub = Pub()
 					key = 'update/' + type_info['key'] + '/' + gateway_info['hardware_id']  + '/' + info['hardware_id']

部分文件因文件數量過多而無法顯示