| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- "use strict";
- const common_vendor = require("../../common/vendor.js");
- const common_assets = require("../../common/assets.js");
- const api_auth = require("../../api/auth.js");
- const _sfc_main = {
- __name: "login",
- setup(__props) {
- const isAgree = common_vendor.ref(false);
- const showAgreementModal = common_vendor.ref(false);
- const showDocModal = common_vendor.ref(false);
- const docTitle = common_vendor.ref("");
- const docContent = common_vendor.ref("");
- const loginCode = common_vendor.ref("");
- const getLoginCode = () => {
- common_vendor.index.login({
- provider: "weixin",
- success: (res) => {
- loginCode.value = res.code;
- }
- });
- };
- common_vendor.onMounted(() => {
- const token = common_vendor.index.getStorageSync("token");
- const userInfo = common_vendor.index.getStorageSync("userInfo");
- if (token && userInfo && userInfo.studentId) {
- if (userInfo.isNewUser && !userInfo.name) {
- common_vendor.index.redirectTo({ url: "/pages/profile/profile" });
- } else {
- common_vendor.index.switchTab({ url: "/pages/jobs/jobs" });
- }
- return;
- }
- getLoginCode();
- });
- const openDocModal = async (type) => {
- try {
- const res = await api_auth.getAgreement(type);
- if (res.code === 200) {
- docTitle.value = res.data.title;
- docContent.value = res.data.content;
- showDocModal.value = true;
- return;
- }
- } catch (err) {
- common_vendor.index.__f__("error", "at pages/login/login.vue:153", "获取协议失败", err);
- common_vendor.index.showToast({
- title: "获取协议失败,请稍后重试",
- icon: "none"
- });
- }
- };
- const closeDocModal = () => {
- showDocModal.value = false;
- };
- const onAgreeChange = (e) => {
- isAgree.value = e.detail.value.length > 0;
- };
- const closeAgreementModal = () => {
- showAgreementModal.value = false;
- };
- const handleDirectLogin = async (e) => {
- if (e.detail.errMsg !== "getPhoneNumber:ok") {
- common_vendor.index.showToast({
- title: "授权失败",
- icon: "none"
- });
- return;
- }
- await onAllowLogin(e.detail.code);
- };
- const handleDirectLoginFromModal = async (e) => {
- isAgree.value = true;
- showAgreementModal.value = false;
- if (e.detail.errMsg !== "getPhoneNumber:ok") {
- common_vendor.index.showToast({
- title: "授权失败",
- icon: "none"
- });
- return;
- }
- await onAllowLogin(e.detail.code);
- };
- const onAllowLogin = async (phoneCode) => {
- common_vendor.index.showLoading({ title: "登录中..." });
- try {
- const res = await api_auth.wechatLogin({
- code: loginCode.value,
- phoneCode
- });
- common_vendor.index.hideLoading();
- if (res.code === 200) {
- common_vendor.index.setStorageSync("token", res.data.token);
- common_vendor.index.setStorageSync("userInfo", res.data);
- common_vendor.index.showToast({
- title: "登录成功",
- icon: "success"
- });
- setTimeout(() => {
- if (res.data.isNewUser) {
- common_vendor.index.navigateTo({ url: "/pages/profile/profile" });
- } else {
- common_vendor.index.switchTab({ url: "/pages/jobs/jobs" });
- }
- }, 1e3);
- }
- } catch (err) {
- common_vendor.index.__f__("error", "at pages/login/login.vue:234", "登录异常", err);
- common_vendor.index.hideLoading();
- getLoginCode();
- }
- };
- return (_ctx, _cache) => {
- return common_vendor.e({
- a: isAgree.value
- }, isAgree.value ? {
- b: common_vendor.o(handleDirectLogin)
- } : {
- c: common_vendor.o(($event) => showAgreementModal.value = true)
- }, {
- d: isAgree.value,
- e: common_vendor.o(($event) => openDocModal("service")),
- f: common_vendor.o(($event) => openDocModal("privacy")),
- g: common_vendor.o(onAgreeChange),
- h: common_assets._imports_0,
- i: common_assets._imports_1,
- j: common_assets._imports_2,
- k: common_assets._imports_3,
- l: common_vendor.o(closeAgreementModal),
- m: common_vendor.o(($event) => openDocModal("service")),
- n: common_vendor.o(($event) => openDocModal("privacy")),
- o: common_vendor.o(closeAgreementModal),
- p: common_vendor.o(handleDirectLoginFromModal),
- q: showAgreementModal.value ? 1 : "",
- r: common_vendor.o(closeDocModal),
- s: common_vendor.t(docTitle.value),
- t: docContent.value,
- v: common_vendor.o(closeDocModal),
- w: showDocModal.value ? 1 : ""
- });
- };
- }
- };
- const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-e4e4508d"]]);
- wx.createPage(MiniProgramPage);
- //# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/login/login.js.map
|