脚本定制
请移步 软件|源码定制 页
代码模板
//定义创建的本地存储名称
var storageName = "道无涯i";
//将需要存储的数据按数据类型放进对应数组
var stringArr = []
var booleanArr = []
var numberArr = []
//封装的按类型设置本地存储,无需更改
function setStorage(storageName, type, idarr) {
let storage = storages.create(storageName)
if (type == "string") {
for (let id = 0; id < idarr.length; id++) {
if (storage.get(idarr[id]) != undefined) {
ui[idarr[id]].setText(storage.get(idarr[id]))
}
}
} else if (type == "boolean") {
for (let id = 0; id < idarr.length; id++) {
if (storage.get(idarr[id]) != undefined) {
ui[idarr[id]].setChecked(storage.get(idarr[id]))
}
}
} else if (type == "number") {
for (let id = 0; id < idarr.length; id++) {
if (storage.get(idarr[id]) != undefined) {
ui[idarr[id]].setSelection(storage.get(idarr[id]))
}
}
}
}
//封装的按类型保存本地存储,无需更改
function putStorage(storageName, type, idarr) {
let storage = storages.create(storageName)
if (type == "string") {
for (let id = 0; id < idarr.length; id++) {
storage.put(idarr[id], ui[idarr[id]].text())
}
} else if (type == "boolean") {
for (let id = 0; id < idarr.length; id++) {
storage.put(idarr[id], ui[idarr[id]].isChecked())
}
} else if (type == "number") {
for (let id = 0; id < idarr.length; id++) {
storage.put(idarr[id], ui[idarr[id]].getSelectedItemPosition())
}
}
}
//封装的读取界面配置的函数,用于设置UI界面配置,在主线程调用
function 读取界面配置() {
setStorage(storageName, "string", stringArr)
setStorage(storageName, "boolean", booleanArr)
setStorage(storageName, "number", numberArr)
}
//封装的保存界面配置的函数,用于保存UI界面配置,在需要保存数据的事件下调用
function 保存界面配置() {
putStorage(storageName, "string", stringArr)
putStorage(storageName, "boolean", booleanArr)
putStorage(storageName, "number", numberArr)
}