readSetting.ts 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import {defineStore} from 'pinia';
  2. import {reactive} from 'vue';
  3. import { read_setting_data, recharge_list_data } from '../data/data';
  4. import { config } from '../config/config';
  5. import { util } from '../framework/util';
  6. import { http } from '../framework/http';
  7. export const ReadSetting = defineStore('read-setting',()=>{
  8. let data:read_setting_data = reactive(new read_setting_data())
  9. let recharge_data:recharge_list_data[] = null
  10. async function updateReadSetting(d:read_setting_data){
  11. data.fontSizeIndex=d.fontSizeIndex;
  12. data.colorBgIndex = d.colorBgIndex;
  13. data.autoBuyNextChpater = d.autoBuyNextChpater
  14. util.setStorage(config.storage_key.READ_SETTING,JSON.stringify(data))
  15. }
  16. async function changeFontSize(index:number){
  17. data.fontSizeIndex=index;
  18. util.setStorage(config.storage_key.READ_SETTING,JSON.stringify(data))
  19. }
  20. async function changeBgColor(index:number){
  21. data.colorBgIndex=index;
  22. util.setStorage(config.storage_key.READ_SETTING,JSON.stringify(data))
  23. }
  24. async function changeAutoBuyNextChapter(isAuto:boolean){
  25. data.autoBuyNextChpater = isAuto
  26. util.setStorage(config.storage_key.READ_SETTING,JSON.stringify(data))
  27. }
  28. async function changeReadMode(mode:number){
  29. data.readMode = mode
  30. util.setStorage(config.storage_key.READ_SETTING,JSON.stringify(data))
  31. }
  32. function getReadSetting():read_setting_data{
  33. if(data==null||data ==undefined||data.colorBgIndex==undefined){
  34. // util.removeStorageForKey(config.storage_key.READ_SETTING)
  35. let obj = util.getStorage(config.storage_key.READ_SETTING)
  36. if(obj) {
  37. Object.assign(data,JSON.parse(obj))
  38. }else{
  39. data.colorBgIndex = 0;
  40. data.fontSizeIndex = 0;
  41. data.readMode = config.read_config.readMode.Bright
  42. data.autoBuyNextChpater = false
  43. util.setStorage(config.storage_key.READ_SETTING,JSON.stringify(data))
  44. }
  45. }
  46. return data
  47. }
  48. function getRechargeList(stype:number,cb:Function){
  49. if(recharge_data==null){
  50. http.StaticRequest(config.url_confg.Static.get_recharge_list(stype),(err,d)=>{
  51. if(d.code==config.url_confg.StatesCode.SUCCESS){
  52. recharge_data = d.content
  53. cb(recharge_data)
  54. }
  55. })
  56. }else{
  57. cb(recharge_data)
  58. }
  59. }
  60. return {data,updateReadSetting,getReadSetting,changeFontSize,changeBgColor,changeAutoBuyNextChapter,changeReadMode,getRechargeList}
  61. })