loop.js 10 KB

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