Autojs本地存储之函数封装模板

脚本定制

请移步 软件|源码定制

代码模板

//定义创建的本地存储名称
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])) {
                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])) {
                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])) {
                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)
}



作 者:道无涯
来 源:道无涯博客
链 接: https://www.daowuya.love/autojs本地存储之函数封装模板/
版 权 声 明:本博客所有文章除特别声明外,均采用CC BY-NC-SA 4.0许可协议。文章版权归作者所有,未经允许请勿转载!


暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇