智慧画屏客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

179 lines
4.2 KiB

3 years ago
  1. var LocalData = {}
  2. var backPics = []
  3. var serialNum = '';
  4. serialNum=uni.getStorageSync('serialNum');
  5. // 获取轮播图
  6. const initBackPics = function() {
  7. uni.getStorage({
  8. key:'backPics',
  9. success: (data) => {
  10. backPics = data.data
  11. // console.log('轮播图', backPics)
  12. }
  13. })
  14. }
  15. function findObjByName(list, name){
  16. list.forEach((value) => {
  17. if(value.name == name){
  18. return value
  19. }
  20. })
  21. return null
  22. }
  23. function setListData(list, local){
  24. let num = list.length
  25. for(let i = 0; i < num; i ++){
  26. let obj = list[i]
  27. let lObj = local[i]
  28. if(!lObj){
  29. local[i] = obj
  30. }else{
  31. if(!lObj.list){
  32. lObj.list = []
  33. }
  34. lObj.list = lObj.list.concat(obj.list)
  35. }
  36. }
  37. return local
  38. }
  39. const setStorage = function(LocalData) {
  40. uni.setStorageSync('localData',LocalData)
  41. // console.log('LocalData:', LocalData)
  42. }
  43. const setClass = function() {
  44. LocalData.book = []
  45. LocalData.doc = []
  46. LocalData.video = []
  47. LocalData.theme = []
  48. LocalData.vr = []
  49. console.log('LocalData:', LocalData)
  50. uni.setStorageSync('localData',LocalData)
  51. }
  52. const getStorage = function() {
  53. uni.getStorage({
  54. key: 'localData',
  55. success: (data) => {
  56. LocalData = data.data
  57. }
  58. })
  59. if(!LocalData.book){
  60. LocalData.book = []
  61. }
  62. if(!LocalData.doc){
  63. LocalData.doc = []
  64. }
  65. if(!LocalData.video){
  66. LocalData.video = []
  67. }
  68. if(!LocalData.theme){
  69. LocalData.theme = []
  70. }
  71. if(!LocalData.vr){
  72. LocalData.vr = []
  73. }
  74. if(!LocalData.bookClass) LocalData.bookClass = []
  75. if(!LocalData.docClass) LocalData.docClass = []
  76. if(!LocalData.videoClass) LocalData.videoClass = []
  77. if(!LocalData.themeClass) LocalData.themeClass = []
  78. if(!LocalData.vrClass) LocalData.vrClass = []
  79. return LocalData
  80. }
  81. //<<<<<<<<------------- encode/decode ------------->>>>>>>>>>>>>>>>>>//
  82. // const CryptoJS = require('crypto-js'); //引用AES源码js
  83. var encryptCode = null
  84. var cryptKey = "FFFFFFFFFFFFFFFF"
  85. var macAddress = ''
  86. //解密方法
  87. const initSn = function() {
  88. console.log('initSn')
  89. uni.getStorage({
  90. key: 'encryptCode',
  91. success: (res) => {
  92. encryptCode = res.data
  93. if (encryptCode == null || encryptCode.length < 1) {
  94. console.log('err: 雷燕todo······跳到激活页面')
  95. }
  96. serialNum=uni.getStorageSync('serialNum');
  97. console.log('init sn:', serialNum)
  98. if(serialNum){
  99. uni.navigateTo({
  100. url:'../index/index'
  101. })
  102. }
  103. },
  104. fail: (err) => {
  105. console.log('fail: 雷燕todo······跳到激活页面')
  106. //雷燕todo······跳到激活页面
  107. }
  108. })
  109. }
  110. const setSerialNum = function(encode){
  111. encryptCode = encode.toString()
  112. serialNum=encode
  113. console.log('setSerialNum:', serialNum, encryptCode)
  114. uni.setStorageSync(
  115. 'encryptCode',
  116. encryptCode)
  117. }
  118. const initMacAddress = function() {
  119. // console.log('initMac')
  120. var net = plus.android.importClass("java.net.NetworkInterface")
  121. var wl0 = net.getByName('wlan0')
  122. var macByte = wl0.getHardwareAddress()
  123. var str = ''
  124. //下面这段代码来自网络
  125. for (var i = 0; i < macByte.length; i++) {
  126.     var tmp = '';
  127.     var num = macByte[i];
  128. //此处填坑,当byte因为符合位导致数值为负时候,需要对数据进行处理
  129.     if (num < 0) {
  130.       tmp =(255+num+1).toString(16);
  131.     } else {
  132.       tmp = num.toString(16);
  133.     }
  134.     if (tmp.length == 1) {
  135.       tmp = "0" + tmp;
  136.     }
  137.     str += tmp;
  138. }
  139. console.log('mac', str)
  140. macAddress = str.toUpperCase()
  141. if(!macAddress || macAddress.length < 1 || macAddress == '02:00:00:00:00:00'){
  142. plus.device.getInfo({
  143. success:(res) => {
  144. macAddress = res.uuid
  145. macAddress = macAddress.substr(0, 16).toUpperCase()
  146. macAddress = macAddress.length < 16 ? macAddress.concat('FFFFFFFFFFFFFFFF'.substr(0, 16 - macAddress.length)) : macAddress
  147. cryptKey = macAddress
  148. console.log('mac address_1:', macAddress, cryptKey)
  149. initSn()
  150. }
  151. })
  152. }else{
  153. let tmp = macAddress.replace(/-*:*/gi,'')
  154. cryptKey = tmp && tmp.length < 16 ? 'FF' + tmp.replace(/-*:*/gi,'') + 'FF' : tmp,
  155. initSn()
  156. }
  157. console.log('mac address:', macAddress, cryptKey)
  158. }
  159. //<<<<<<<<------------- encode/decode ------------->>>>>>>>>>>>>>>>>>//
  160. export {
  161. LocalData,
  162. setStorage,
  163. setClass,
  164. getStorage,
  165. initSn,
  166. serialNum,
  167. initMacAddress,
  168. macAddress,
  169. backPics,
  170. initBackPics,
  171. setSerialNum
  172. }