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
179 lines
4.2 KiB
var LocalData = {}
|
|
var backPics = []
|
|
var serialNum = '';
|
|
serialNum=uni.getStorageSync('serialNum');
|
|
// 获取轮播图
|
|
const initBackPics = function() {
|
|
uni.getStorage({
|
|
key:'backPics',
|
|
success: (data) => {
|
|
backPics = data.data
|
|
// console.log('轮播图', backPics)
|
|
}
|
|
})
|
|
}
|
|
function findObjByName(list, name){
|
|
list.forEach((value) => {
|
|
if(value.name == name){
|
|
return value
|
|
}
|
|
})
|
|
return null
|
|
}
|
|
function setListData(list, local){
|
|
let num = list.length
|
|
for(let i = 0; i < num; i ++){
|
|
let obj = list[i]
|
|
let lObj = local[i]
|
|
if(!lObj){
|
|
local[i] = obj
|
|
}else{
|
|
if(!lObj.list){
|
|
lObj.list = []
|
|
}
|
|
lObj.list = lObj.list.concat(obj.list)
|
|
}
|
|
}
|
|
return local
|
|
}
|
|
|
|
const setStorage = function(LocalData) {
|
|
uni.setStorageSync('localData',LocalData)
|
|
// console.log('LocalData:', LocalData)
|
|
}
|
|
const setClass = function() {
|
|
LocalData.book = []
|
|
LocalData.doc = []
|
|
LocalData.video = []
|
|
LocalData.theme = []
|
|
LocalData.vr = []
|
|
|
|
console.log('LocalData:', LocalData)
|
|
uni.setStorageSync('localData',LocalData)
|
|
}
|
|
const getStorage = function() {
|
|
|
|
uni.getStorage({
|
|
key: 'localData',
|
|
success: (data) => {
|
|
LocalData = data.data
|
|
}
|
|
})
|
|
if(!LocalData.book){
|
|
LocalData.book = []
|
|
}
|
|
if(!LocalData.doc){
|
|
LocalData.doc = []
|
|
}
|
|
if(!LocalData.video){
|
|
LocalData.video = []
|
|
}
|
|
if(!LocalData.theme){
|
|
LocalData.theme = []
|
|
}
|
|
if(!LocalData.vr){
|
|
LocalData.vr = []
|
|
}
|
|
if(!LocalData.bookClass) LocalData.bookClass = []
|
|
if(!LocalData.docClass) LocalData.docClass = []
|
|
if(!LocalData.videoClass) LocalData.videoClass = []
|
|
if(!LocalData.themeClass) LocalData.themeClass = []
|
|
if(!LocalData.vrClass) LocalData.vrClass = []
|
|
return LocalData
|
|
}
|
|
//<<<<<<<<------------- encode/decode ------------->>>>>>>>>>>>>>>>>>//
|
|
// const CryptoJS = require('crypto-js'); //引用AES源码js
|
|
|
|
var encryptCode = null
|
|
var cryptKey = "FFFFFFFFFFFFFFFF"
|
|
var macAddress = ''
|
|
//解密方法
|
|
|
|
const initSn = function() {
|
|
console.log('initSn')
|
|
uni.getStorage({
|
|
key: 'encryptCode',
|
|
success: (res) => {
|
|
encryptCode = res.data
|
|
if (encryptCode == null || encryptCode.length < 1) {
|
|
console.log('err: 雷燕todo······跳到激活页面')
|
|
}
|
|
serialNum=uni.getStorageSync('serialNum');
|
|
console.log('init sn:', serialNum)
|
|
if(serialNum){
|
|
uni.navigateTo({
|
|
url:'../index/index'
|
|
})
|
|
}
|
|
},
|
|
fail: (err) => {
|
|
console.log('fail: 雷燕todo······跳到激活页面')
|
|
//雷燕todo······跳到激活页面
|
|
}
|
|
})
|
|
}
|
|
const setSerialNum = function(encode){
|
|
encryptCode = encode.toString()
|
|
serialNum=encode
|
|
console.log('setSerialNum:', serialNum, encryptCode)
|
|
uni.setStorageSync(
|
|
'encryptCode',
|
|
encryptCode)
|
|
}
|
|
const initMacAddress = function() {
|
|
// console.log('initMac')
|
|
var net = plus.android.importClass("java.net.NetworkInterface")
|
|
var wl0 = net.getByName('wlan0')
|
|
var macByte = wl0.getHardwareAddress()
|
|
var str = ''
|
|
//下面这段代码来自网络
|
|
for (var i = 0; i < macByte.length; i++) {
|
|
var tmp = '';
|
|
var num = macByte[i];
|
|
//此处填坑,当byte因为符合位导致数值为负时候,需要对数据进行处理
|
|
if (num < 0) {
|
|
tmp =(255+num+1).toString(16);
|
|
} else {
|
|
tmp = num.toString(16);
|
|
}
|
|
if (tmp.length == 1) {
|
|
tmp = "0" + tmp;
|
|
}
|
|
str += tmp;
|
|
}
|
|
console.log('mac', str)
|
|
|
|
macAddress = str.toUpperCase()
|
|
if(!macAddress || macAddress.length < 1 || macAddress == '02:00:00:00:00:00'){
|
|
plus.device.getInfo({
|
|
success:(res) => {
|
|
macAddress = res.uuid
|
|
macAddress = macAddress.substr(0, 16).toUpperCase()
|
|
macAddress = macAddress.length < 16 ? macAddress.concat('FFFFFFFFFFFFFFFF'.substr(0, 16 - macAddress.length)) : macAddress
|
|
cryptKey = macAddress
|
|
console.log('mac address_1:', macAddress, cryptKey)
|
|
initSn()
|
|
}
|
|
})
|
|
}else{
|
|
let tmp = macAddress.replace(/-*:*/gi,'')
|
|
cryptKey = tmp && tmp.length < 16 ? 'FF' + tmp.replace(/-*:*/gi,'') + 'FF' : tmp,
|
|
initSn()
|
|
}
|
|
console.log('mac address:', macAddress, cryptKey)
|
|
}
|
|
//<<<<<<<<------------- encode/decode ------------->>>>>>>>>>>>>>>>>>//
|
|
|
|
export {
|
|
LocalData,
|
|
setStorage,
|
|
setClass,
|
|
getStorage,
|
|
initSn,
|
|
serialNum,
|
|
initMacAddress,
|
|
macAddress,
|
|
backPics,
|
|
initBackPics,
|
|
setSerialNum
|
|
}
|