index.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 openid = common_vendor.computed(() => {
  11. return common_vendor.index.getStorageSync("openid");
  12. });
  13. const logoUrl = common_vendor.ref("");
  14. const initUser = async () => {
  15. common_vendor.index.login({
  16. success: async function(result) {
  17. if (!result.code) {
  18. common_vendor.index.showToast({
  19. title: "登录失败请重进!",
  20. icon: "fail"
  21. });
  22. return false;
  23. }
  24. if (!openid.value) {
  25. const res = await login(result.code);
  26. if (res)
  27. common_vendor.index.setStorageSync("openid", res);
  28. }
  29. common_vendor.index.redirectTo({
  30. url: "/pages/home/index"
  31. });
  32. }
  33. });
  34. };
  35. const login = async (js_code) => {
  36. const res = await $app("/wechat/api/login/app", "GET", {
  37. js_code,
  38. config: $config.wx_projectkey
  39. });
  40. if (res.errcode === 0)
  41. return res.data.openid;
  42. else {
  43. common_vendor.index.showToast({
  44. title: "登录失败请重进!",
  45. icon: "fail"
  46. });
  47. return false;
  48. }
  49. };
  50. const searchConfig = async () => {
  51. const res = await $api("/system/matchconfig/findOne", "GET", {});
  52. if (res.code === 200) {
  53. if (res.data) {
  54. logoUrl.value = res.data.logoUrl;
  55. common_vendor.index.setStorageSync("config", res.data);
  56. }
  57. } else {
  58. common_vendor.index.showToast({
  59. title: res.msg || "",
  60. icon: "error"
  61. });
  62. }
  63. };
  64. initUser();
  65. searchConfig();
  66. return (_ctx, _cache) => {
  67. return {
  68. a: logoUrl.value || "/static/logo.png"
  69. };
  70. };
  71. }
  72. });
  73. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-1cf27b2a"], ["__file", "D:/project/足球比赛/match_applet/pages/index/index.vue"]]);
  74. wx.createPage(MiniProgramPage);