2 lines
3.7 KiB
JavaScript
2 lines
3.7 KiB
JavaScript
|
|
"use strict";const e=require("../../common/vendor.js"),o=require("../../config/api.js"),n=require("../../common/assets.js"),t={data:()=>({phone:"",cacheSize:"12.5MB",userInfo:{nickname:"",avatar:""},useWechatService:!0,servicePhone:""}),onLoad(){this.loadSettings(),this.loadServiceConfig(),this.calculateCacheSize()},methods:{loadSettings(){const o=e.index.getStorageSync("userInfo");o&&o.phone&&(this.phone=o.phone.replace(/(\d{3})\d{4}(\d{4})/,"$1****$2"))},editProfile(){e.index.navigateTo({url:"/pages/profile/edit-profile"})},changePassword(){e.index.navigateTo({url:"/pages/settings/change-password"})},bindPhone(){e.index.navigateTo({url:"/pages/settings/bind-phone"})},clearCache(){e.index.showModal({title:"清除缓存",content:"确定要清除所有缓存吗?此操作将清除应用缓存数据(不包括登录信息)。",success:o=>{if(o.confirm){e.index.showLoading({title:"清除中..."});try{const o=e.index.getStorageInfoSync().keys||[],n=["token","userId","userInfo","userNickname","userPhone","username","avatarUrl","nickname"];o.forEach((o=>{n.includes(o)||e.index.removeStorageSync(o)})),setTimeout((()=>{e.index.hideLoading(),this.cacheSize="0MB",e.index.showToast({title:"清除成功",icon:"success"}),this.calculateCacheSize()}),1e3)}catch(n){console.error("清除缓存失败:",n),e.index.hideLoading(),e.index.showToast({title:"清除失败,请重试",icon:"none"})}}}})},calculateCacheSize(){try{const o=e.index.getStorageInfoSync();let n=0;(o.keys||[]).forEach((o=>{const t=e.index.getStorageSync(o);if(t){const e=JSON.stringify(t);n+=2*e.length}}));const t=(n/1024/1024).toFixed(2);this.cacheSize=t>0?`${t}MB`:"0MB"}catch(o){console.error("计算缓存大小失败:",o),this.cacheSize="0MB"}},showPrivacy(){e.index.navigateTo({url:"/pages/settings/privacy-policy"})},showAgreement(){e.index.navigateTo({url:"/pages/settings/user-agreement"})},showAbout(){e.index.navigateTo({url:"/pages/settings/about"})},async loadServiceConfig(){try{const n=e.index.getStorageSync("appConfig");n&&n.common&&(this.useWechatService=!1!==n.common.useWechatService,this.servicePhone=n.common.servicePhone||"");const t=await e.index.request({url:`${o.API_BASE}${o.API_ENDPOINTS.config.getAppConfig}`,method:"GET",header:{"Content-Type":"application/json"}}),i=Array.isArray(t)?t[1]:t;if(i&&i.data&&i.data.success&&i.data.data){const o=i.data.data;e.index.setStorageSync("appConfig",o),o.common&&(this.useWechatService=!1!==o.common.useWechatService,this.servicePhone=o.common.servicePhone||"")}}catch(n){console.error("加载配置失败:",n)}},callService(){e.index.makePhoneCall({phoneNumber:this.servicePhone})},handleLogout(){e.index.showModal({title:"退出登录",content:"确定要退出登录吗?",success:o=>{o.confirm&&(e.index.removeStorageSync("token"),e.index.removeStorageSync("userId"),e.index.removeStorageSync("userInfo"),e.index.removeStorageSync("nickname"),e.index.removeStorageSync("userNickname"),e.index.removeStorageSync("userPhone"),e.index.removeStorageSync("username"),e.index.removeStorageSync("avatarUrl"),e.index.showToast({title:"已退出登录",icon:"success",duration:1500}),setTimeout((()=>{e.index.reLaunch({url:"/pages/login/login"})}),1500))}})}}};const i=e._export_sfc(t,[["render",function(o,t,i,a,c,s){return{a:e.o(((...e)=>s.editProfile&&s.editProfile(...e))),b:e.o(((...e)=>s.changePassword&&s.changePassword(...e))),c:e.t(c.phone||"未绑定"),d:e.o(((...e)=>s.bindPhone&&s.bindPhone(...e))),e:n._imports_0,f:e.t(c.cacheSize),g:e.o(((...e)=>s.clearCache&&s.clearCache(...e))),h:e.o(((...e)=>s.showPrivacy&&s.showPrivacy(...e))),i:e.o(((...e)=>s.showAgreement&&s.showAgreement(...e))),j:e.o(((...e)=>s.showAbout&&s.showAbout(...e))),k:e.o(((...e)=>s.handleLogout&&s.handleLogout(...e)))}}],["__scopeId","data-v-15e4c888"]]);wx.createPage(i);
|