LoginModal.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. const api_dining = require("../../api/dining.js");
  4. const store_user = require("../../store/user.js");
  5. if (!Math) {
  6. BasicModal();
  7. }
  8. const BasicModal = () => "../../components/Modal/BasicModal.js";
  9. const _sfc_main = {
  10. __name: "LoginModal",
  11. props: {
  12. open: {
  13. type: Boolean,
  14. default: false
  15. }
  16. },
  17. emits: ["update:open", "success", "cancel"],
  18. setup(__props, { emit: __emit }) {
  19. const props = __props;
  20. const emit = __emit;
  21. const agreed = common_vendor.ref(false);
  22. const userStore = store_user.useUserStore();
  23. const getOpen = common_vendor.computed({
  24. get: () => props.open,
  25. set: (val) => emit("update:open", val)
  26. });
  27. const toggleAgree = () => {
  28. agreed.value = !agreed.value;
  29. };
  30. const handleClose = () => {
  31. getOpen.value = false;
  32. emit("cancel");
  33. };
  34. const handleGetPhoneNumber = async (e) => {
  35. if (!agreed.value) {
  36. common_vendor.index.showToast({
  37. title: "请先同意用户协议和隐私协议",
  38. icon: "none"
  39. });
  40. return;
  41. }
  42. if (!e.detail.code) {
  43. common_vendor.index.showToast({
  44. title: "授权失败,请重试",
  45. icon: "none"
  46. });
  47. return;
  48. }
  49. try {
  50. common_vendor.index.login({
  51. success: async (loginRes) => {
  52. try {
  53. const res = await api_dining.DiningUserWechatLogin({
  54. code: loginRes.code,
  55. phoneCode: e.detail.code
  56. });
  57. if (res && res.token) {
  58. userStore.login(res);
  59. getOpen.value = false;
  60. emit("success", res);
  61. } else {
  62. common_vendor.index.showToast({
  63. title: (res == null ? void 0 : res.msg) || "登录失败,请重试",
  64. icon: "none"
  65. });
  66. }
  67. } catch (error) {
  68. common_vendor.index.__f__("error", "at pages/components/LoginModal.vue:115", "登录失败:", error);
  69. common_vendor.index.showToast({
  70. title: "登录失败,请重试",
  71. icon: "none"
  72. });
  73. }
  74. },
  75. fail: () => {
  76. common_vendor.index.showToast({
  77. title: "获取登录凭证失败",
  78. icon: "none"
  79. });
  80. }
  81. });
  82. } catch (error) {
  83. common_vendor.index.__f__("error", "at pages/components/LoginModal.vue:130", "获取手机号失败:", error);
  84. common_vendor.index.showToast({
  85. title: "授权失败,请重试",
  86. icon: "none"
  87. });
  88. }
  89. };
  90. const handlePrivacy = () => {
  91. common_vendor.index.showToast({
  92. title: "隐私协议",
  93. icon: "none"
  94. });
  95. };
  96. const handleUserAgreement = () => {
  97. common_vendor.index.showToast({
  98. title: "用户协议",
  99. icon: "none"
  100. });
  101. };
  102. return (_ctx, _cache) => {
  103. return common_vendor.e({
  104. a: common_vendor.o(handleClose),
  105. b: common_vendor.o(handleGetPhoneNumber),
  106. c: !agreed.value,
  107. d: agreed.value
  108. }, agreed.value ? {} : {}, {
  109. e: agreed.value ? 1 : "",
  110. f: common_vendor.o(toggleAgree),
  111. g: common_vendor.o(handlePrivacy),
  112. h: common_vendor.o(handleUserAgreement),
  113. i: common_vendor.o(($event) => getOpen.value = $event),
  114. j: common_vendor.p({
  115. type: "bottom",
  116. isMack: true,
  117. open: getOpen.value
  118. })
  119. });
  120. };
  121. }
  122. };
  123. const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-65cbbddc"]]);
  124. wx.createComponent(Component);
  125. //# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/components/LoginModal.js.map