settings.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. const _sfc_main = {
  4. data() {
  5. return {
  6. toggleSettings: [
  7. {
  8. label: "阅读时不自动锁屏",
  9. value: false,
  10. key: "noAutoLock"
  11. },
  12. {
  13. label: "阅读时隐藏别人的笔记",
  14. value: false,
  15. key: "hideOthersNotes"
  16. },
  17. {
  18. label: "阅读时显示时间和电量",
  19. value: true,
  20. key: "showTimeBattery"
  21. },
  22. {
  23. label: "阅读时允许横屏",
  24. value: false,
  25. key: "allowLandscape"
  26. },
  27. {
  28. label: "点赞提醒",
  29. value: true,
  30. key: "likeReminder"
  31. }
  32. ],
  33. cacheSize: "20M"
  34. };
  35. },
  36. onLoad() {
  37. this.loadSettings();
  38. this.loadCacheSize();
  39. },
  40. methods: {
  41. goBack() {
  42. common_vendor.index.navigateBack();
  43. },
  44. handleToggleChange(index, event) {
  45. this.toggleSettings[index].value = event.detail.value;
  46. this.saveSettings();
  47. },
  48. handleInfoClick(type) {
  49. switch (type) {
  50. case "clearCache":
  51. this.clearCache();
  52. break;
  53. case "about":
  54. this.showAbout();
  55. break;
  56. case "contact":
  57. this.showContact();
  58. break;
  59. }
  60. },
  61. clearCache() {
  62. common_vendor.index.showModal({
  63. title: "提示",
  64. content: `确定要清理 ${this.cacheSize} 缓存吗?`,
  65. success: (res) => {
  66. if (res.confirm) {
  67. common_vendor.index.clearStorageSync();
  68. this.cacheSize = "0M";
  69. common_vendor.index.showToast({
  70. title: "缓存已清理",
  71. icon: "success"
  72. });
  73. }
  74. }
  75. });
  76. },
  77. showAbout() {
  78. common_vendor.index.navigateTo({
  79. url: "/pages/about/about"
  80. });
  81. },
  82. showContact() {
  83. common_vendor.index.showModal({
  84. title: "联系我们",
  85. content: "邮箱: support@yunread.com\n电话: 400-123-4567",
  86. showCancel: false
  87. });
  88. },
  89. handleLogout() {
  90. common_vendor.index.showModal({
  91. title: "提示",
  92. content: "确定要退出登录吗?",
  93. success: (res) => {
  94. if (res.confirm) {
  95. common_vendor.index.removeStorageSync("token");
  96. common_vendor.index.removeStorageSync("userInfo");
  97. common_vendor.index.showToast({
  98. title: "已退出登录",
  99. icon: "success"
  100. });
  101. setTimeout(() => {
  102. common_vendor.index.reLaunch({
  103. url: "/pages/login/login"
  104. });
  105. }, 1500);
  106. }
  107. }
  108. });
  109. },
  110. loadSettings() {
  111. const savedSettings = common_vendor.index.getStorageSync("appSettings");
  112. if (savedSettings) {
  113. this.toggleSettings.forEach((setting, index) => {
  114. if (savedSettings[setting.key] !== void 0) {
  115. this.toggleSettings[index].value = savedSettings[setting.key];
  116. }
  117. });
  118. }
  119. },
  120. saveSettings() {
  121. const settings = {};
  122. this.toggleSettings.forEach((setting) => {
  123. settings[setting.key] = setting.value;
  124. });
  125. common_vendor.index.setStorageSync("appSettings", settings);
  126. },
  127. loadCacheSize() {
  128. try {
  129. const info = common_vendor.index.getStorageInfoSync();
  130. const size = (info.keys.length * 2).toFixed(0);
  131. this.cacheSize = size + "M";
  132. } catch (e) {
  133. this.cacheSize = "20M";
  134. }
  135. }
  136. }
  137. };
  138. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  139. return {
  140. a: common_vendor.o((...args) => $options.goBack && $options.goBack(...args)),
  141. b: common_vendor.f($data.toggleSettings, (setting, index, i0) => {
  142. return {
  143. a: common_vendor.t(setting.label),
  144. b: setting.value,
  145. c: common_vendor.o(($event) => $options.handleToggleChange(index, $event), index),
  146. d: index
  147. };
  148. }),
  149. c: common_vendor.t($data.cacheSize),
  150. d: common_vendor.o(($event) => $options.handleInfoClick("clearCache")),
  151. e: common_vendor.o(($event) => $options.handleInfoClick("about")),
  152. f: common_vendor.o(($event) => $options.handleInfoClick("contact")),
  153. g: common_vendor.o((...args) => $options.handleLogout && $options.handleLogout(...args))
  154. };
  155. }
  156. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-7fad0a1c"]]);
  157. wx.createPage(MiniProgramPage);
  158. //# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/settings/settings.js.map