index.js 2.5 KB

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