index.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
  4. __name: "index",
  5. setup(__props) {
  6. var _a, _b, _c;
  7. const $api = (_a = common_vendor.getCurrentInstance()) == null ? void 0 : _a.appContext.config.globalProperties.$api;
  8. const $app = (_b = common_vendor.getCurrentInstance()) == null ? void 0 : _b.appContext.config.globalProperties.$app;
  9. const $config = (_c = common_vendor.getCurrentInstance()) == null ? void 0 : _c.appContext.config.globalProperties.$config;
  10. const config = common_vendor.ref({ logo: [] });
  11. common_vendor.onLoad(async () => {
  12. await searchConfig();
  13. await search();
  14. });
  15. const searchConfig = async () => {
  16. let res = await $api(`config`, "GET", {});
  17. if (res.errcode == 0) {
  18. config.value = res.data[0] || {};
  19. common_vendor.index.setStorage({
  20. key: "config",
  21. data: res.data[0] || {}
  22. });
  23. }
  24. };
  25. const search = async () => {
  26. common_vendor.index.getStorage({
  27. key: "openid",
  28. success: async function(res) {
  29. var _a2;
  30. const user = await $api("token/openid", "POST", {
  31. openid: res.data
  32. });
  33. if (user.errcode == "0" && ((_a2 = user.data) == null ? void 0 : _a2._id)) {
  34. common_vendor.index.setStorage({
  35. key: "user",
  36. data: user.data
  37. });
  38. } else {
  39. common_vendor.index.removeStorage({
  40. key: "user",
  41. success: function(res2) {
  42. console.log("success");
  43. }
  44. });
  45. }
  46. common_vendor.index.reLaunch({
  47. url: `/pages/home/index`
  48. });
  49. },
  50. fail: function(err) {
  51. common_vendor.index.login({
  52. success: async function(res) {
  53. var _a2;
  54. if (res.code) {
  55. common_vendor.index.reLaunch({
  56. url: `/pages/home/index`
  57. });
  58. const aee = await $app("/wechat/api/login/app", "GET", {
  59. js_code: res.code,
  60. config: $config.wx_projectkey
  61. });
  62. if (aee.errcode == "0") {
  63. common_vendor.index.setStorage({
  64. key: "openid",
  65. data: aee.data.openid
  66. });
  67. const user = await $api("token/openid", "POST", {
  68. openid: aee.data.openid
  69. });
  70. if (user.errcode == "0" && ((_a2 = user.data) == null ? void 0 : _a2._id)) {
  71. common_vendor.index.setStorage({
  72. key: "user",
  73. data: user.data
  74. });
  75. } else {
  76. common_vendor.index.removeStorage({
  77. key: "user",
  78. success: function(res2) {
  79. console.log("success");
  80. }
  81. });
  82. }
  83. common_vendor.index.reLaunch({
  84. url: `/pages/home/index`
  85. });
  86. } else {
  87. common_vendor.index.showToast({
  88. title: aee.errmsg,
  89. icon: "none"
  90. });
  91. }
  92. } else {
  93. common_vendor.index.showToast({
  94. title: res.errMsg,
  95. icon: "none"
  96. });
  97. }
  98. }
  99. });
  100. }
  101. });
  102. };
  103. return (_ctx, _cache) => {
  104. var _a2, _b2;
  105. return {
  106. a: ((_b2 = (_a2 = config.value) == null ? void 0 : _a2.logo[0]) == null ? void 0 : _b2.url) || "/static/logo.jpg"
  107. };
  108. };
  109. }
  110. });
  111. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-1cf27b2a"], ["__file", "D:/project/学吧/learn_applet/pages/index/index.vue"]]);
  112. wx.createPage(MiniProgramPage);