index.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. const api_services_connect = require("../../api/services/connect.js");
  4. const utils_storage = require("../../utils/storage.js");
  5. const _sfc_main = {
  6. data() {
  7. return {
  8. plotInfo: {
  9. total: 3,
  10. active: 2,
  11. idle: 1
  12. },
  13. serviceList: [
  14. {
  15. name: "农资商城",
  16. iconText: "商",
  17. path: "/pages/service/mall"
  18. },
  19. {
  20. name: "农产品销售",
  21. iconText: "售",
  22. path: "/pages/service/sales"
  23. },
  24. {
  25. name: "在线专家问诊",
  26. iconText: "诊",
  27. path: "/pages/service/expert"
  28. },
  29. {
  30. name: "绿色认证申请",
  31. iconText: "证",
  32. path: "/pages/service/certification"
  33. },
  34. {
  35. name: "保险接入",
  36. iconText: "保",
  37. path: "/pages/service/insurance"
  38. }
  39. ],
  40. userInfo: {
  41. nickName: "游客",
  42. id: "",
  43. avatar: "/static/images/icon.png"
  44. },
  45. isLogin: false
  46. };
  47. },
  48. onShow() {
  49. this.checkLoginStatus();
  50. },
  51. methods: {
  52. refresh() {
  53. api_services_connect.refresh().then((res) => {
  54. console.log("请求成功。未执行属性token", res);
  55. });
  56. },
  57. // 检查登录状态
  58. checkLoginStatus() {
  59. console.log("执行Show");
  60. if (utils_storage.storage.getHasLogin()) {
  61. this.isLogin = true;
  62. const userInfo = utils_storage.storage.getUserInfo();
  63. console.log("执行Show", userInfo);
  64. if (userInfo) {
  65. this.userInfo = userInfo;
  66. }
  67. } else {
  68. this.isLogin = false;
  69. }
  70. },
  71. navigateToLogin() {
  72. common_vendor.index.navigateTo({
  73. url: "/pages/login/index"
  74. });
  75. },
  76. navigateToPlots() {
  77. common_vendor.index.navigateTo({
  78. url: "/pages/plots/list"
  79. });
  80. },
  81. navigateToService(item) {
  82. common_vendor.index.navigateTo({
  83. url: item.path
  84. });
  85. },
  86. handleContact() {
  87. common_vendor.index.makePhoneCall({
  88. phoneNumber: "400-xxx-xxxx"
  89. // 替换为实际的客服电话
  90. });
  91. },
  92. navigateToAbout() {
  93. common_vendor.index.navigateTo({
  94. url: "/pages/about/index"
  95. });
  96. },
  97. navigateToSettings() {
  98. common_vendor.index.navigateTo({
  99. url: "/pages/settings/index"
  100. });
  101. },
  102. // 使用授权服务处理登出
  103. handleLogout() {
  104. common_vendor.index.showModal({
  105. title: "提示",
  106. content: "确认退出登录?",
  107. success: (res) => {
  108. if (res.confirm) {
  109. api_services_connect.logout().then(() => {
  110. this.isLogin = false;
  111. this.userInfo = {
  112. nickname: "游客",
  113. id: "",
  114. avatar: "/static/images/icon.png"
  115. };
  116. });
  117. }
  118. }
  119. });
  120. }
  121. }
  122. };
  123. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  124. return common_vendor.e({
  125. a: $data.userInfo.avatar || "/static/images/default-avatar.png",
  126. b: $data.isLogin
  127. }, $data.isLogin ? {
  128. c: common_vendor.t($data.userInfo.nickName),
  129. d: common_vendor.t($data.userInfo.sex == "0" ? "男" : "女")
  130. } : {
  131. e: common_vendor.o((...args) => $options.navigateToLogin && $options.navigateToLogin(...args))
  132. }, {
  133. f: common_vendor.o((...args) => $options.navigateToPlots && $options.navigateToPlots(...args)),
  134. g: common_vendor.o((...args) => $options.refresh && $options.refresh(...args)),
  135. h: common_vendor.t($data.plotInfo.total),
  136. i: common_vendor.t($data.plotInfo.active),
  137. j: common_vendor.t($data.plotInfo.idle),
  138. k: common_vendor.f($data.serviceList, (item, index, i0) => {
  139. return {
  140. a: common_vendor.t(item.iconText),
  141. b: common_vendor.t(item.name),
  142. c: index,
  143. d: common_vendor.o(($event) => $options.navigateToService(item), index)
  144. };
  145. }),
  146. l: common_vendor.o((...args) => $options.handleContact && $options.handleContact(...args)),
  147. m: common_vendor.o((...args) => $options.navigateToAbout && $options.navigateToAbout(...args)),
  148. n: common_vendor.o((...args) => $options.navigateToSettings && $options.navigateToSettings(...args)),
  149. o: this.isLogin
  150. }, this.isLogin ? {
  151. p: common_vendor.o((...args) => $options.handleLogout && $options.handleLogout(...args))
  152. } : {});
  153. }
  154. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);
  155. wx.createPage(MiniProgramPage);