debug.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. const utils_userCache = require("../../utils/userCache.js");
  4. const _sfc_main = {
  5. __name: "debug",
  6. setup(__props) {
  7. const logs = common_vendor.ref([]);
  8. const isLogined = common_vendor.ref(false);
  9. const tokenDisplay = common_vendor.ref("无");
  10. const userInfoDisplay = common_vendor.ref("无");
  11. const refreshStatus = () => {
  12. isLogined.value = utils_userCache.isLogin();
  13. const token = utils_userCache.getToken();
  14. tokenDisplay.value = token ? token.substring(0, 20) + "..." : "无";
  15. const userInfo = utils_userCache.getUserInfo();
  16. if (userInfo) {
  17. userInfoDisplay.value = JSON.stringify(userInfo);
  18. } else {
  19. userInfoDisplay.value = "无";
  20. }
  21. addLog("状态已刷新");
  22. };
  23. const addLog = (text) => {
  24. const now = /* @__PURE__ */ new Date();
  25. const time = `${now.getHours().toString().padStart(2, "0")}:${now.getMinutes().toString().padStart(2, "0")}:${now.getSeconds().toString().padStart(2, "0")}`;
  26. logs.value.unshift({ time, text });
  27. if (logs.value.length > 20) {
  28. logs.value.pop();
  29. }
  30. };
  31. const simulateLogin = () => {
  32. const mockUserInfo = {
  33. id: "test_user_001",
  34. nickname: "测试用户",
  35. phone: "13800138000",
  36. avatar: ""
  37. };
  38. const mockToken = "mock_token_" + Date.now();
  39. const success = utils_userCache.saveUserInfo(mockUserInfo, mockToken);
  40. if (success) {
  41. addLog("模拟登录成功");
  42. refreshStatus();
  43. common_vendor.index.showToast({
  44. title: "模拟登录成功",
  45. icon: "success"
  46. });
  47. } else {
  48. addLog("模拟登录失败");
  49. }
  50. };
  51. const clearCache = () => {
  52. common_vendor.index.showModal({
  53. title: "提示",
  54. content: "确定要清除缓存吗?",
  55. success: (res) => {
  56. if (res.confirm) {
  57. utils_userCache.clearUserInfo();
  58. addLog("缓存已清除");
  59. refreshStatus();
  60. common_vendor.index.showToast({
  61. title: "已清除",
  62. icon: "success"
  63. });
  64. }
  65. }
  66. });
  67. };
  68. const gotoSplash = () => {
  69. addLog("跳转到启动页");
  70. common_vendor.index.reLaunch({
  71. url: "/pages/splash/splash"
  72. });
  73. };
  74. const gotoLogin = () => {
  75. addLog("跳转到登录页");
  76. common_vendor.index.navigateTo({
  77. url: "/pages/login/login"
  78. });
  79. };
  80. const gotoHome = () => {
  81. addLog("跳转到首页");
  82. common_vendor.index.navigateTo({
  83. url: "/pages/index/index"
  84. });
  85. };
  86. common_vendor.onMounted(() => {
  87. addLog("调试工具已加载");
  88. refreshStatus();
  89. });
  90. return (_ctx, _cache) => {
  91. return {
  92. a: common_vendor.t(isLogined.value ? "已登录" : "未登录"),
  93. b: isLogined.value ? 1 : "",
  94. c: !isLogined.value ? 1 : "",
  95. d: common_vendor.t(tokenDisplay.value),
  96. e: common_vendor.t(userInfoDisplay.value),
  97. f: common_vendor.o(simulateLogin, "bc"),
  98. g: common_vendor.o(clearCache, "bd"),
  99. h: common_vendor.o(refreshStatus, "f0"),
  100. i: common_vendor.o(gotoSplash, "41"),
  101. j: common_vendor.o(gotoLogin, "92"),
  102. k: common_vendor.o(gotoHome, "48"),
  103. l: common_vendor.f(logs.value, (log, index, i0) => {
  104. return {
  105. a: common_vendor.t(log.time),
  106. b: common_vendor.t(log.text),
  107. c: index
  108. };
  109. })
  110. };
  111. };
  112. }
  113. };
  114. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-42851fab"]]);
  115. wx.createPage(MiniProgramPage);
  116. //# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/test/debug.js.map