loop.js 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  1. // 分组下拉
  2. function Groupdrop() {
  3. var group = wx.getStorageSync('group')
  4. var groups = []
  5. for (let i = 0; i < group.length; i++) {
  6. groups.push(group[i].groupName)
  7. }
  8. //改变分组下标
  9. if (wx.getStorageSync('groupName') != '') {
  10. let GroupName = groups
  11. for (let n = 0; n < GroupName.length; n++) {
  12. if (GroupName[n] == wx.getStorageSync('groupName')) {
  13. return {
  14. n,
  15. groups
  16. }
  17. }
  18. }
  19. } else {
  20. wx.setStorageSync('groupName', groups[0])
  21. return {
  22. groups
  23. }
  24. }
  25. }
  26. //设备下拉
  27. function Devicedrop(groupName, groupIndex) {
  28. var group = wx.getStorageSync('group')
  29. var device = []
  30. for (let j = 0; j < group.length; j++) {
  31. if (groupName[groupIndex] == group[j].groupName) {
  32. if (group[j].devices != null && group[j].devices.length != 0) {
  33. for (let p = 0; p < group[j].devices.length; p++) {
  34. device.push(group[j].devices[p].deviceName)
  35. }
  36. if (wx.getStorageSync('deviceName') != '') {
  37. for (let m = 0; m < device.length; m++) {
  38. if (device[m] == wx.getStorageSync('deviceName')) {
  39. return {
  40. m,
  41. device
  42. }
  43. }
  44. }
  45. } else {
  46. wx.setStorageSync('deviceName', device[0])
  47. return {
  48. device
  49. }
  50. }
  51. } else {
  52. return '离线'
  53. }
  54. }
  55. }
  56. }
  57. //设备id,key
  58. function deviceMessage(groupNames, deviceNames) {
  59. var group = wx.getStorageSync('group')
  60. for (let d = 0; d < group.length; d++) {
  61. if (groupNames == group[d].groupName) {
  62. for (let g = 0; g < group[d].devices.length; g++) {
  63. if (deviceNames == group[d].devices[g].deviceName) {
  64. console.log(group[d].devices[g].module)
  65. if (group[d].devices[g].module == 0) {
  66. var loopnum = group[d].devices[g].circuits
  67. var deviceId = group[d].devices[g].deviceId
  68. var deviceKey = group[d].devices[g].deviceKey
  69. return [loopnum, deviceId, deviceKey]
  70. } else {
  71. }
  72. }
  73. }
  74. }
  75. }
  76. }
  77. //设备信息
  78. function deviceinfo(data,arr,brr,time,state,state1,
  79. fixed1,fixed2,fixed3,fixed4,address,
  80. radio1,radio2,radio3,index,indexs) {
  81. //以下为回路
  82. for (let i = 1; i < data.length; i++) {
  83. //回路数量
  84. if (data[i].id == "RelayCount") {
  85. var num = data[i].current_value
  86. num = parseInt(num)
  87. loopnum = loopnum.split(',')
  88. var num1 = []
  89. for (let a = 0; a < num; a++) {
  90. num1.push(loopnum[a])
  91. }
  92. num1.push('所有回路')
  93. var crr = num1
  94. }
  95. //时控一开时间
  96. else if (data[i].id == "R1_DayOpenTime1") {
  97. var timeopen1 = data[i].current_value
  98. }
  99. //时控一关时间
  100. else if (data[i].id == "R1_DayCloseTime1") {
  101. var timeshut1 = data[i].current_value
  102. }
  103. //时控二开时间
  104. else if (data[i].id == "R1_DayOpenTime2") {
  105. var timeopen2 = data[i].current_value
  106. }
  107. //时控二关时间
  108. else if (data[i].id == "R1_DayCloseTime2") {
  109. var timeshut2 = data[i].current_value
  110. }
  111. //日期调控
  112. else if (data[i].id == "R1_Week") {
  113. var weeks = data[i].current_value
  114. var recorddate = weeks
  115. weeks = parseInt(weeks)
  116. weeks = weeks.toString(2)
  117. weeks = weeks + ''
  118. }
  119. //功能1
  120. else if (data[i].id == "R1_FunctionStatus1") {
  121. var Function1 = data[i].current_value
  122. var par = parseInt(Function1)
  123. par = par.toString(2)
  124. par = par + ''
  125. switch (par.length) {
  126. case 1:
  127. par = '00000' + par
  128. break;
  129. case 2:
  130. par = '0000' + par
  131. break;
  132. case 3:
  133. par = '000' + par
  134. break;
  135. case 4:
  136. par = '00' + par
  137. break;
  138. case 5:
  139. par = '0' + par
  140. break;
  141. default:
  142. par = par
  143. }
  144. }
  145. //功能二
  146. else if (data[i].id == "R1_FunctionStatus2") {
  147. var Function2 = data[i].current_value
  148. var qur = parseInt(Function2)
  149. qur = qur.toString(2)
  150. qur = qur + ''
  151. switch (qur.length) {
  152. case 1:
  153. qur = '000' + qur
  154. break;
  155. case 2:
  156. qur = '00' + qur
  157. break;
  158. case 3:
  159. qur = '0' + qur
  160. break;
  161. case 4:
  162. qur = qur
  163. break;
  164. }
  165. }
  166. //报警
  167. else if (data[i].id == "R1_RelayStatus") {
  168. var police = data[i].current_value
  169. }
  170. //光控开
  171. else if (data[i].id == "R1_LcOn") {
  172. var Lightcontrolopen = data[i].current_value
  173. for (let i = 0; i < 100; i++) {
  174. arr[i] = i
  175. }
  176. Lightcontrolopen = parseInt(Lightcontrolopen)
  177. var index = Lightcontrolopen
  178. }
  179. //光控关
  180. else if (data[i].id == "R1_LcOff") {
  181. var Lightcontrolshut = data[i].current_value
  182. for (let j = 0; j < 100; j++) {
  183. brr[j] = j
  184. }
  185. Lightcontrolshut = parseInt(Lightcontrolshut)
  186. var indexs = Lightcontrolshut
  187. }
  188. }
  189. //时控一开时间
  190. var timeOpen1
  191. switch (timeopen1.length) {
  192. case 1:
  193. timeOpen1 = '00' + ':' + '0' + timeopen1.substring(0, 1)
  194. break;
  195. case 2:
  196. timeOpen1 = '00' + ':' + timeopen1.substring(0, 2)
  197. break;
  198. case 3:
  199. var timeOpen1 = '0' + timeopen1.substring(0, 1) + ':' + timeopen1.substring(1, 3)
  200. break;
  201. case 4:
  202. var timeOpen1 = timeopen1.substring(0, 2) + ':' + timeopen1.substring(2, 4)
  203. break;
  204. }
  205. //时控一关时间
  206. var timeShut1
  207. switch (timeshut1.length) {
  208. case 1:
  209. timeShut1 = '00' + ':' + '0' + timeshut1.substring(0, 1)
  210. break;
  211. case 2:
  212. timeShut1 = '00' + ':' + timeshut1.substring(0, 2)
  213. break;
  214. case 3:
  215. var timeShut1 = '0' + timeshut1.substring(0, 1) + ':' + timeshut1.substring(1, 3)
  216. break;
  217. case 4:
  218. var timeShut1 = timeshut1.substring(0, 2) + ':' + timeshut1.substring(2, 4)
  219. break;
  220. }
  221. //时控二开时间
  222. var timeOpen2
  223. switch (timeopen2.length) {
  224. case 1:
  225. timeOpen2 = '00' + ':' + '0' + timeopen2.substring(0, 1)
  226. break;
  227. case 2:
  228. timeOpen2 = '00' + ':' + timeopen2.substring(0, 2)
  229. break;
  230. case 3:
  231. var timeOpen2 = '0' + timeopen2.substring(0, 1) + ':' + timeopen2.substring(1, 3)
  232. break;
  233. case 4:
  234. var timeOpen2 = timeopen2.substring(0, 2) + ':' + timeopen2.substring(2, 4)
  235. break;
  236. }
  237. //时控二关时间
  238. var timeShut2
  239. switch (timeshut2.length) {
  240. case 1:
  241. timeShut2 = '00' + ':' + '0' + timeshut2.substring(0, 1)
  242. break;
  243. case 2:
  244. timeShut2 = '00' + ':' + timeshut2.substring(0, 2)
  245. break;
  246. case 3:
  247. var timeShut2 = '0' + timeshut2.substring(0, 1) + ':' + timeshut2.substring(1, 3)
  248. break;
  249. case 4:
  250. var timeShut2 = timeshut2.substring(0, 2) + ':' + timeshut2.substring(2, 4)
  251. break;
  252. }
  253. //功能1
  254. for (var i = 0; i < par.length; i++) {
  255. switch (par.substring(i, i + 1)) {
  256. case "0":
  257. switch (i) {
  258. case 0:
  259. state[3] = false
  260. break;
  261. case 1:
  262. state[2] = false
  263. break;
  264. case 2:
  265. fixed2 = "固定"
  266. break;
  267. case 3:
  268. fixed1 = "固定"
  269. break;
  270. case 4:
  271. state[1] = false
  272. break;
  273. case 5:
  274. state[0] = false
  275. break;
  276. }
  277. break;
  278. case "1":
  279. switch (i) {
  280. case 0:
  281. state[3] = true
  282. break;
  283. case 1:
  284. state[2] = true
  285. break;
  286. case 2:
  287. fixed2 = "经纬"
  288. break;
  289. case 3:
  290. fixed1 = "经纬"
  291. break;
  292. case 4:
  293. state[1] = true
  294. break;
  295. case 5:
  296. state[0] = true
  297. break;
  298. }
  299. break;
  300. }
  301. }
  302. //功能2
  303. for (let j = 0; j < qur.length; j++) {
  304. switch (qur.substring(j, j + 1)) {
  305. case "0":
  306. switch (j) {
  307. case 0:
  308. fixed4 = "固定"
  309. break;
  310. case 1:
  311. fixed3 = "固定"
  312. break;
  313. case 2:
  314. state1[1] = false
  315. break;
  316. case 3:
  317. state1[0] = false
  318. break;
  319. }
  320. break;
  321. case "1":
  322. switch (j) {
  323. case 0:
  324. fixed4 = "经纬"
  325. break;
  326. case 1:
  327. fixed3 = "经纬"
  328. break;
  329. case 2:
  330. state1[1] = true
  331. break;
  332. case 3:
  333. state1[0] = true
  334. break;
  335. }
  336. break;
  337. }
  338. }
  339. //日期调控
  340. if (weeks == '0') {
  341. for (let x = 0; x < weeks.length; x++) {
  342. address[x] = "/image/false.png"
  343. }
  344. } else {
  345. for (let i = 0; i < weeks.length; i++) {
  346. switch (weeks.substring(i, i + 1)) {
  347. case '0':
  348. address[weeks.length - i - 1] = "/image/false.png"
  349. break;
  350. case '1':
  351. address[weeks.length - i - 1] = "/image/true.png"
  352. break;
  353. }
  354. }
  355. }
  356. //报警状态
  357. police = parseInt(police)
  358. police = police.toString(2)
  359. switch (police.length) {
  360. case 1:
  361. police = '000' + police
  362. break;
  363. case 2:
  364. police = '00' + police
  365. break;
  366. case 3:
  367. police = '0' + police
  368. break;
  369. default:
  370. police = police
  371. break;
  372. }
  373. if (police.substring(1, 2) == '0' && police.substring(0, 1) == '0') {
  374. radio1 = true
  375. } else if (police.substring(1, 2) == '1' && police.substring(0, 1) == '0') {
  376. radio2 = true
  377. } else if (police.substring(1, 2) == '0' && police.substring(0, 1) == '1') {
  378. radio3 = true
  379. }
  380. time[0] = timeOpen1
  381. time[1] = timeShut1
  382. time[2] = timeOpen2
  383. time[3] = timeShut2
  384. return {crr,recorddate,arr,brr,time,state,state1,
  385. fixed1,fixed2,fixed3,fixed4,address,
  386. radio1,radio2,radio3,index,indexs}
  387. }
  388. module.exports = {
  389. Groupdrop: Groupdrop,
  390. Devicedrop: Devicedrop,
  391. deviceMessage: deviceMessage,
  392. deviceinfo:deviceinfo
  393. }