loop.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  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. weeks = weeks.toString(2)
  116. weeks = weeks + ''
  117. }
  118. //功能1
  119. else if (data[i].id == "R1_FunctionStatus1") {
  120. var Function1 = data[i].current_value
  121. var par = parseInt(Function1)
  122. par = par.toString(2)
  123. par = par + ''
  124. switch (par.length) {
  125. case 1:
  126. par = '00000' + par
  127. break;
  128. case 2:
  129. par = '0000' + par
  130. break;
  131. case 3:
  132. par = '000' + par
  133. break;
  134. case 4:
  135. par = '00' + par
  136. break;
  137. case 5:
  138. par = '0' + par
  139. break;
  140. default:
  141. par = par
  142. }
  143. }
  144. //功能二
  145. else if (data[i].id == "R1_FunctionStatus2") {
  146. var Function2 = data[i].current_value
  147. var qur = parseInt(Function2)
  148. qur = qur.toString(2)
  149. qur = qur + ''
  150. switch (qur.length) {
  151. case 1:
  152. qur = '000' + qur
  153. break;
  154. case 2:
  155. qur = '00' + qur
  156. break;
  157. case 3:
  158. qur = '0' + qur
  159. break;
  160. case 4:
  161. qur = qur
  162. break;
  163. }
  164. }
  165. //报警
  166. else if (data[i].id == "R1_RelayStatus") {
  167. var police = data[i].current_value
  168. }
  169. //光控开
  170. else if (data[i].id == "R1_LcOn") {
  171. var Lightcontrolopen = data[i].current_value
  172. for (let i = 0; i < 100; i++) {
  173. arr[i] = i
  174. }
  175. Lightcontrolopen = parseInt(Lightcontrolopen)
  176. var index = Lightcontrolopen
  177. }
  178. //光控关
  179. else if (data[i].id == "R1_LcOff") {
  180. var Lightcontrolshut = data[i].current_value
  181. for (let j = 0; j < 100; j++) {
  182. brr[j] = j
  183. }
  184. Lightcontrolshut = parseInt(Lightcontrolshut)
  185. var indexs = Lightcontrolshut
  186. }
  187. }
  188. //时控一开时间
  189. var timeOpen1
  190. switch (timeopen1.length) {
  191. case 1:
  192. timeOpen1 = '00' + ':' + '0' + timeopen1.substring(0, 1)
  193. break;
  194. case 2:
  195. timeOpen1 = '00' + ':' + timeopen1.substring(0, 2)
  196. break;
  197. case 3:
  198. var timeOpen1 = '0' + timeopen1.substring(0, 1) + ':' + timeopen1.substring(1, 3)
  199. break;
  200. case 4:
  201. var timeOpen1 = timeopen1.substring(0, 2) + ':' + timeopen1.substring(2, 4)
  202. break;
  203. }
  204. //时控一关时间
  205. var timeShut1
  206. switch (timeshut1.length) {
  207. case 1:
  208. timeShut1 = '00' + ':' + '0' + timeshut1.substring(0, 1)
  209. break;
  210. case 2:
  211. timeShut1 = '00' + ':' + timeshut1.substring(0, 2)
  212. break;
  213. case 3:
  214. var timeShut1 = '0' + timeshut1.substring(0, 1) + ':' + timeshut1.substring(1, 3)
  215. break;
  216. case 4:
  217. var timeShut1 = timeshut1.substring(0, 2) + ':' + timeshut1.substring(2, 4)
  218. break;
  219. }
  220. //时控二开时间
  221. var timeOpen2
  222. switch (timeopen2.length) {
  223. case 1:
  224. timeOpen2 = '00' + ':' + '0' + timeopen2.substring(0, 1)
  225. break;
  226. case 2:
  227. timeOpen2 = '00' + ':' + timeopen2.substring(0, 2)
  228. break;
  229. case 3:
  230. var timeOpen2 = '0' + timeopen2.substring(0, 1) + ':' + timeopen2.substring(1, 3)
  231. break;
  232. case 4:
  233. var timeOpen2 = timeopen2.substring(0, 2) + ':' + timeopen2.substring(2, 4)
  234. break;
  235. }
  236. //时控二关时间
  237. var timeShut2
  238. switch (timeshut2.length) {
  239. case 1:
  240. timeShut2 = '00' + ':' + '0' + timeshut2.substring(0, 1)
  241. break;
  242. case 2:
  243. timeShut2 = '00' + ':' + timeshut2.substring(0, 2)
  244. break;
  245. case 3:
  246. var timeShut2 = '0' + timeshut2.substring(0, 1) + ':' + timeshut2.substring(1, 3)
  247. break;
  248. case 4:
  249. var timeShut2 = timeshut2.substring(0, 2) + ':' + timeshut2.substring(2, 4)
  250. break;
  251. }
  252. //功能1
  253. for (var i = 0; i < par.length; i++) {
  254. switch (par.substring(i, i + 1)) {
  255. case "0":
  256. switch (i) {
  257. case 0:
  258. state[3] = false
  259. break;
  260. case 1:
  261. state[2] = false
  262. break;
  263. case 2:
  264. fixed2 = "固定"
  265. break;
  266. case 3:
  267. fixed1 = "固定"
  268. break;
  269. case 4:
  270. state[1] = false
  271. break;
  272. case 5:
  273. state[0] = false
  274. break;
  275. }
  276. break;
  277. case "1":
  278. switch (i) {
  279. case 0:
  280. state[3] = true
  281. break;
  282. case 1:
  283. state[2] = true
  284. break;
  285. case 2:
  286. fixed2 = "经纬"
  287. break;
  288. case 3:
  289. fixed1 = "经纬"
  290. break;
  291. case 4:
  292. state[1] = true
  293. break;
  294. case 5:
  295. state[0] = true
  296. break;
  297. }
  298. break;
  299. }
  300. }
  301. //功能2
  302. for (let j = 0; j < qur.length; j++) {
  303. switch (qur.substring(j, j + 1)) {
  304. case "0":
  305. switch (j) {
  306. case 0:
  307. fixed4 = "固定"
  308. break;
  309. case 1:
  310. fixed3 = "固定"
  311. break;
  312. case 2:
  313. state1[1] = false
  314. break;
  315. case 3:
  316. state1[0] = false
  317. break;
  318. }
  319. break;
  320. case "1":
  321. switch (j) {
  322. case 0:
  323. fixed4 = "经纬"
  324. break;
  325. case 1:
  326. fixed3 = "经纬"
  327. break;
  328. case 2:
  329. state1[1] = true
  330. break;
  331. case 3:
  332. state1[0] = true
  333. break;
  334. }
  335. break;
  336. }
  337. }
  338. //日期调控
  339. if (weeks == '0') {
  340. for (let x = 0; x < weeks.length; x++) {
  341. address[x] = "/image/false.png"
  342. }
  343. } else {
  344. for (let i = 0; i < weeks.length; i++) {
  345. switch (weeks.substring(i, i + 1)) {
  346. case '0':
  347. address[weeks.length - i - 1] = "/image/false.png"
  348. break;
  349. case '1':
  350. address[weeks.length - i - 1] = "/image/true.png"
  351. break;
  352. }
  353. }
  354. }
  355. //报警状态
  356. police = parseInt(police)
  357. police = police.toString(2)
  358. switch (police.length) {
  359. case 1:
  360. police = '000' + police
  361. break;
  362. case 2:
  363. police = '00' + police
  364. break;
  365. case 3:
  366. police = '0' + police
  367. break;
  368. default:
  369. police = police
  370. break;
  371. }
  372. if (police.substring(1, 2) == '0' && police.substring(0, 1) == '0') {
  373. radio1 = true
  374. } else if (police.substring(1, 2) == '1' && police.substring(0, 1) == '0') {
  375. radio2 = true
  376. } else if (police.substring(1, 2) == '0' && police.substring(0, 1) == '1') {
  377. radio3 = true
  378. }
  379. time[0] = timeOpen1
  380. time[1] = timeShut1
  381. time[2] = timeOpen2
  382. time[3] = timeShut2
  383. return {crr,recorddate,arr,brr,time,state,state1,
  384. fixed1,fixed2,fixed3,fixed4,address,
  385. radio1,radio2,radio3,index,indexs}
  386. }
  387. //新设备信息
  388. function newDeviceinfo(Device,Group){
  389. getDevice(Device,Group).then(res => {
  390. })
  391. }
  392. //时间开关选择器(新设备)
  393. module.exports = {
  394. Groupdrop: Groupdrop,
  395. Devicedrop: Devicedrop,
  396. deviceMessage: deviceMessage,
  397. deviceinfo:deviceinfo,
  398. newDeviceinfo:newDeviceinfo
  399. }