login.js 7.71 KB
"use strict";
const common_vendor = require("../../common/vendor.js");
const config = require("../../config.js");
const common_login = require("../../common/login.js");
require("../../common/request.js");
require("../../common/aes.js");
if (!Array) {
  const _easycom_uni_easyinput2 = common_vendor.resolveComponent("uni-easyinput");
  const _easycom_uni_countdown2 = common_vendor.resolveComponent("uni-countdown");
  (_easycom_uni_easyinput2 + _easycom_uni_countdown2)();
}
const _easycom_uni_easyinput = () => "../../uni_modules/uni-easyinput/components/uni-easyinput/uni-easyinput.js";
const _easycom_uni_countdown = () => "../../uni_modules/uni-countdown/components/uni-countdown/uni-countdown.js";
if (!Math) {
  (_easycom_uni_easyinput + _easycom_uni_countdown)();
}
const _sfc_main = {
  __name: "login",
  setup(__props) {
    const isActive = common_vendor.ref(0);
    common_vendor.ref(false);
    common_vendor.ref(true);
    const codeUrl = common_vendor.ref(null);
    const inputstyle = common_vendor.ref({
      borderColor: "transparent",
      fontSize: "30rpx"
    });
    const form = common_vendor.ref({
      username: null,
      password: null,
      code: null,
      uuid: null
    });
    const form2 = common_vendor.ref({
      telNo: null,
      captcha: null,
      code: null,
      uuid: null
    });
    const countDown = common_vendor.ref({
      start: false,
      second: 60
    });
    const app = getApp();
    common_vendor.onMounted(() => {
      getCode();
    });
    function changeActive(n) {
      isActive.value = n;
    }
    function login() {
      if (isActive.value == 0) {
        if (!form.value.username) {
          common_vendor.index.showToast({
            title: "账号不能为空",
            icon: "none"
          });
          return;
        }
        if (!form.value.password) {
          common_vendor.index.showToast({
            title: "密码不能为空",
            icon: "none"
          });
          return;
        }
        if (!form.value.code) {
          common_vendor.index.showToast({
            title: "验证码不能为空",
            icon: "none"
          });
          return;
        }
        common_login.pcLogin(form.value).then((res) => {
          app.globalData.isLogin = true;
          common_vendor.index.redirectTo({
            url: "/pages/index/index"
          });
        });
      } else if (isActive.value == 1) {
        if (!form2.value.telNo) {
          common_vendor.index.showToast({
            title: "手机号不能为空",
            icon: "none"
          });
          return;
        }
        if (!form2.value.code) {
          common_vendor.index.showToast({
            title: "短信验证码不能为空",
            icon: "none"
          });
          return;
        }
        common_login.loginByPhone(form2.value.telNo, form2.value.code).then(() => {
          app.globalData.isLogin = true;
          common_vendor.index.redirectTo({
            url: "/pages/index/index"
          });
        });
      }
    }
    function goRegister() {
      const path = "/pages/index/register";
      common_vendor.index.navigateTo({
        url: path
      });
    }
    function getCode() {
      common_login.getCodeImg().then((res) => {
        codeUrl.value = "data:image/gif;base64," + res.data.img;
        form.value.uuid = res.data.uuid;
        form2.value.uuid = res.data.uuid;
      });
    }
    function getCaptchaSms() {
      if (!form2.value.telNo) {
        common_vendor.index.showToast({
          title: "手机号不能为空",
          icon: "none"
        });
        return;
      }
      if (!form2.value.captcha) {
        common_vendor.index.showToast({
          title: "图形验证码不能为空",
          icon: "none"
        });
        return;
      }
      common_login.getSmsCode({
        uuid: form2.value.uuid,
        telNo: form2.value.telNo,
        code: form2.value.captcha
      }).then((res) => {
        common_vendor.index.showToast({
          title: "短信验证码下发成功",
          icon: "none"
        });
        countDown.value.start = true;
      }).catch(getCode);
    }
    function timeup() {
      countDown.value.start = false;
      countDown.value.second = 60;
      getCode();
    }
    return (_ctx, _cache) => {
      return common_vendor.e({
        a: common_vendor.unref(config.config).baseUrl_api + "/fs/static/login/ren1.png",
        b: common_vendor.unref(config.config).baseUrl_api + "/fs/static/login/logo@2x.png",
        c: common_vendor.n(isActive.value == 0 ? "active" : ""),
        d: common_vendor.o(($event) => changeActive(0)),
        e: common_vendor.n(isActive.value == 1 ? "active" : ""),
        f: common_vendor.o(($event) => changeActive(1)),
        g: isActive.value == 0
      }, isActive.value == 0 ? {
        h: common_vendor.unref(config.config).baseUrl_api + "/fs/static/login/tag01@2x.png",
        i: common_vendor.o(($event) => form.value.username = $event),
        j: common_vendor.p({
          styles: inputstyle.value,
          placeholder: "账号",
          modelValue: form.value.username
        }),
        k: common_vendor.unref(config.config).baseUrl_api + "/fs/static/login/tag02@2x.png",
        l: common_vendor.o(($event) => form.value.password = $event),
        m: common_vendor.p({
          styles: inputstyle.value,
          placeholder: "密码",
          type: "password",
          modelValue: form.value.password
        }),
        n: common_vendor.unref(config.config).baseUrl_api + "/fs/static/login/tag03@2x.png",
        o: common_vendor.o(($event) => form.value.code = $event),
        p: common_vendor.p({
          styles: inputstyle.value,
          placeholder: "图形验证码",
          modelValue: form.value.code
        }),
        q: codeUrl.value,
        r: common_vendor.o(getCode)
      } : {}, {
        s: isActive.value == 1
      }, isActive.value == 1 ? common_vendor.e({
        t: common_vendor.unref(config.config).baseUrl_api + "/fs/static/login/tag01@2x.png",
        v: common_vendor.o(($event) => form2.value.telNo = $event),
        w: common_vendor.p({
          styles: inputstyle.value,
          placeholder: "请输入手机号",
          modelValue: form2.value.telNo
        }),
        x: common_vendor.unref(config.config).baseUrl_api + "/fs/static/login/tag02@2x.png",
        y: common_vendor.o(($event) => form2.value.captcha = $event),
        z: common_vendor.p({
          styles: inputstyle.value,
          placeholder: "图形验证码",
          modelValue: form2.value.captcha
        }),
        A: codeUrl.value,
        B: common_vendor.o(getCode),
        C: common_vendor.unref(config.config).baseUrl_api + "/fs/static/login/tag04@2x.png",
        D: common_vendor.o(($event) => form2.value.code = $event),
        E: common_vendor.p({
          styles: inputstyle.value,
          placeholder: "短信验证码",
          modelValue: form2.value.code
        }),
        F: !countDown.value.start
      }, !countDown.value.start ? {
        G: common_vendor.o(getCaptchaSms)
      } : {}, {
        H: countDown.value.start
      }, countDown.value.start ? {
        I: common_vendor.o(timeup),
        J: common_vendor.p({
          color: "#014A9F",
          ["show-day"]: false,
          ["show-hour"]: false,
          ["show-min"]: false,
          start: countDown.value.start,
          second: countDown.value.second
        })
      } : {}) : {}, {
        K: common_vendor.o(login),
        L: common_vendor.o(goRegister),
        M: common_vendor.unref(config.config).baseUrl_api + "/fs/static/login/ren2.png"
      });
    };
  }
};
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-fa14255b"], ["__file", "/Users/yangyang/ztx_wx_minapp/pages/index/login.vue"]]);
wx.createPage(MiniProgramPage);