12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- import {defineStore} from 'pinia';
- import {reactive} from 'vue';
- import { read_setting_data, recharge_list_data } from '../data/data';
- import { config } from '../config/config';
- import { util } from '../framework/util';
- import { http } from '../framework/http';
- export const ReadSetting = defineStore('read-setting',()=>{
- let data:read_setting_data = reactive(new read_setting_data())
- let recharge_data:recharge_list_data[] = null
- async function updateReadSetting(d:read_setting_data){
- data.fontSizeIndex=d.fontSizeIndex;
- data.colorBgIndex = d.colorBgIndex;
- data.autoBuyNextChpater = d.autoBuyNextChpater
- util.setStorage(config.storage_key.READ_SETTING,JSON.stringify(data))
- }
-
- async function changeFontSize(index:number){
- data.fontSizeIndex=index;
- util.setStorage(config.storage_key.READ_SETTING,JSON.stringify(data))
- }
-
- async function changeBgColor(index:number){
- data.colorBgIndex=index;
- util.setStorage(config.storage_key.READ_SETTING,JSON.stringify(data))
- }
-
- async function changeAutoBuyNextChapter(isAuto:boolean){
- data.autoBuyNextChpater = isAuto
- util.setStorage(config.storage_key.READ_SETTING,JSON.stringify(data))
- }
-
- async function changeReadMode(mode:number){
- data.readMode = mode
- util.setStorage(config.storage_key.READ_SETTING,JSON.stringify(data))
- }
-
- function getReadSetting():read_setting_data{
- if(data==null||data ==undefined||data.colorBgIndex==undefined){
- // util.removeStorageForKey(config.storage_key.READ_SETTING)
- let obj = util.getStorage(config.storage_key.READ_SETTING)
- if(obj) {
- Object.assign(data,JSON.parse(obj))
- }else{
- data.colorBgIndex = 0;
- data.fontSizeIndex = 0;
- data.readMode = config.read_config.readMode.Bright
- data.autoBuyNextChpater = false
- util.setStorage(config.storage_key.READ_SETTING,JSON.stringify(data))
- }
- }
- return data
- }
-
- function getRechargeList(stype:number,cb:Function){
- if(recharge_data==null){
- http.StaticRequest(config.url_confg.Static.get_recharge_list(stype),(err,d)=>{
- if(d.code==config.url_confg.StatesCode.SUCCESS){
- recharge_data = d.content
- cb(recharge_data)
- }
- })
- }else{
- cb(recharge_data)
- }
- }
- return {data,updateReadSetting,getReadSetting,changeFontSize,changeBgColor,changeAutoBuyNextChapter,changeReadMode,getRechargeList}
- })
|