240 lines
8.0 KiB
JavaScript
Raw Normal View History

2024-04-25 18:02:30 +08:00
"use strict";
const common_vendor = require("../../common/vendor.js");
2024-04-27 18:02:43 +08:00
const common_assets = require("../../common/assets.js");
2024-04-28 18:08:57 +08:00
const api_user = require("../../api/user.js");
2024-04-27 18:02:43 +08:00
const store_user = require("../../store/user.js");
2024-04-28 18:08:57 +08:00
require("../../utils/request.js");
require("../../config/app.js");
2024-04-27 18:02:43 +08:00
if (!Array) {
const _easycom_up_icon2 = common_vendor.resolveComponent("up-icon");
2024-05-06 17:58:41 +08:00
const _easycom_up_navbar2 = common_vendor.resolveComponent("up-navbar");
2024-04-27 18:02:43 +08:00
const _easycom_up_button2 = common_vendor.resolveComponent("up-button");
2024-04-28 18:08:57 +08:00
const _easycom_up_transition2 = common_vendor.resolveComponent("up-transition");
const _easycom_up_input2 = common_vendor.resolveComponent("up-input");
const _easycom_up_code2 = common_vendor.resolveComponent("up-code");
2024-05-06 17:58:41 +08:00
(_easycom_up_icon2 + _easycom_up_navbar2 + _easycom_up_button2 + _easycom_up_transition2 + _easycom_up_input2 + _easycom_up_code2)();
2024-04-27 18:02:43 +08:00
}
const _easycom_up_icon = () => "../../uni_modules/uview-plus/components/u-icon/u-icon.js";
2024-05-06 17:58:41 +08:00
const _easycom_up_navbar = () => "../../uni_modules/uview-plus/components/u-navbar/u-navbar.js";
2024-04-27 18:02:43 +08:00
const _easycom_up_button = () => "../../uni_modules/uview-plus/components/u-button/u-button.js";
2024-04-28 18:08:57 +08:00
const _easycom_up_transition = () => "../../uni_modules/uview-plus/components/u-transition/u-transition.js";
const _easycom_up_input = () => "../../uni_modules/uview-plus/components/u-input/u-input.js";
const _easycom_up_code = () => "../../uni_modules/uview-plus/components/u-code/u-code.js";
2024-04-27 18:02:43 +08:00
if (!Math) {
2024-05-06 17:58:41 +08:00
(_easycom_up_icon + _easycom_up_navbar + _easycom_up_button + _easycom_up_transition + _easycom_up_input + _easycom_up_code + bindPhone)();
2024-04-27 18:02:43 +08:00
}
2024-05-06 11:51:21 +08:00
const bindPhone = () => "../../components/bindPhone.js";
2024-04-25 18:02:30 +08:00
const _sfc_main = {
__name: "login",
setup(__props) {
2024-05-06 11:51:21 +08:00
const navToIndex = () => {
if (!userStore.userInfo.supplier)
common_vendor.index.reLaunch({
url: "/pages/index/index"
});
else
common_vendor.index.$u.toast("功能开发中");
};
const userStore = store_user.useUserStore();
if (userStore.userInfo && userStore.userInfo.mobile) {
navToIndex();
} else {
userStore.setToken("");
userStore.setUserInfo({});
}
2024-04-28 18:08:57 +08:00
const showWeixin = common_vendor.ref(true);
const isAgree = common_vendor.ref(false);
2024-04-30 16:24:55 +08:00
const weixinLogin = () => {
if (!isAgree.value)
return common_vendor.index.$u.toast("请先阅读并同意协议");
2024-04-30 18:08:36 +08:00
common_vendor.index.showLoading({
title: "登录中"
});
2024-04-30 16:24:55 +08:00
common_vendor.index.login({
provider: "weixin",
success: (res) => {
2024-05-06 11:51:21 +08:00
api_user.userLoginWeixinApi({
code: res.code
}).then((res2) => {
common_vendor.index.hideLoading();
userStore.setToken(res2.data.token);
userStore.setUserInfo(res2.data);
if (!res2.data.mobile) {
return showBind.value = true;
}
navToIndex();
});
2024-04-30 16:24:55 +08:00
},
fail: (err) => {
console.log(err);
common_vendor.index.$u.toast("登录失败");
}
});
2024-04-28 18:08:57 +08:00
};
2024-05-06 11:51:21 +08:00
const showBind = common_vendor.ref(false);
const getPhoneNumber = (e) => {
var _a;
console.log("===", e);
if (((_a = e.detail) == null ? void 0 : _a.errMsg) == "getPhoneNumber:ok") {
api_user.getMobileByMnpApi({
code: e.detail.code
}).then((res) => {
navToIndex();
});
} else {
console.log("用户拒绝授权");
return common_vendor.index.$u.toast("您拒绝了授权");
}
};
2024-04-28 18:08:57 +08:00
const loginForm = common_vendor.ref({
phone: "15366662222",
code: ""
});
const isPhone = () => {
loginForm.value.phone = loginForm.value.phone.replace(/\s*/g, "");
return !/^1[3456789]\d{9}$/.test(loginForm.value.phone);
};
const codeLogin = () => {
if (!isAgree.value)
return common_vendor.index.$u.toast("请先阅读并同意协议");
if (isPhone())
return common_vendor.index.$u.toast("请输入正确的手机号码");
console.log("登录");
api_user.userLoginApi({
account: "17811111111",
password: "1111",
terminal: 3,
scene: 1
}).then((res) => {
console.log(res);
});
};
const tips = common_vendor.ref("");
const seconds = common_vendor.ref(60);
const uCodeRef = common_vendor.ref(null);
const codeChange = (text) => {
tips.value = text;
};
const getCode = () => {
if (!isAgree.value)
return common_vendor.index.$u.toast("请先阅读并同意协议");
if (uCodeRef.value.canGetCode) {
if (isPhone())
return common_vendor.index.$u.toast("请输入正确的手机号码");
common_vendor.index.showLoading({
title: "正在获取验证码"
});
setTimeout(() => {
common_vendor.index.hideLoading();
common_vendor.index.$u.toast("验证码已发送");
uCodeRef.value.start();
}, 2e3);
} else {
common_vendor.index.$u.toast("倒计时结束后再发送");
}
};
const navBack = () => {
if (showWeixin.value == false) {
showWeixin.value = true;
return true;
} else
common_vendor.index.navigateBack();
};
2024-04-25 18:02:30 +08:00
return (_ctx, _cache) => {
2024-04-27 18:02:43 +08:00
return common_vendor.e({
2024-05-06 17:58:41 +08:00
a: !showWeixin.value
}, !showWeixin.value ? {
b: common_vendor.o(navBack),
c: common_vendor.p({
name: "arrow-left",
size: "20"
})
} : {}, {
d: common_vendor.p({
2024-04-28 18:08:57 +08:00
title: "登录",
autoBack: false,
placeholder: true,
bgColor: "rgba(0,0,0,0)"
}),
2024-05-06 17:58:41 +08:00
e: showWeixin.value
2024-04-28 18:08:57 +08:00
}, showWeixin.value ? {
2024-05-06 17:58:41 +08:00
f: common_vendor.p({
2024-04-27 18:02:43 +08:00
name: "weixin-fill",
color: "#fff",
size: "28"
}),
2024-05-06 17:58:41 +08:00
g: common_vendor.o(weixinLogin),
h: common_vendor.p({
2024-04-27 18:02:43 +08:00
color: "#20B128",
size: "large"
}),
2024-05-06 17:58:41 +08:00
i: common_vendor.o(($event) => showWeixin.value = false),
j: common_vendor.p({
2024-04-27 18:02:43 +08:00
color: "#ECFFEE",
size: "large"
2024-04-28 18:08:57 +08:00
}),
2024-05-06 17:58:41 +08:00
k: common_vendor.p({
2024-04-28 18:08:57 +08:00
show: showWeixin.value
})
} : {
2024-05-06 17:58:41 +08:00
l: common_vendor.o(($event) => loginForm.value.phone = $event),
m: common_vendor.p({
2024-04-28 18:08:57 +08:00
customStyle: {
height: "100%"
},
placeholderClass: "place",
border: "none",
placeholder: "请输入手机号",
type: "number",
modelValue: loginForm.value.phone
}),
2024-05-06 17:58:41 +08:00
n: common_vendor.sr(uCodeRef, "23c3038c-9,23c3038c-8", {
2024-04-28 18:08:57 +08:00
"k": "uCodeRef"
}),
2024-05-06 17:58:41 +08:00
o: common_vendor.o(codeChange),
p: common_vendor.p({
2024-04-28 18:08:57 +08:00
seconds: seconds.value
}),
2024-05-06 17:58:41 +08:00
q: common_vendor.t(tips.value),
r: common_vendor.o(getCode),
s: common_vendor.o(($event) => loginForm.value.code = $event),
t: common_vendor.p({
2024-04-28 18:08:57 +08:00
customStyle: {
height: "100%"
},
maxlength: 4,
placeholderClass: "place",
border: "none",
placeholder: "请输入验证码",
type: "number",
modelValue: loginForm.value.code
}),
2024-05-06 17:58:41 +08:00
v: common_vendor.o(codeLogin),
w: common_vendor.p({
2024-04-28 18:08:57 +08:00
color: "#20B128",
size: "large"
}),
2024-05-06 17:58:41 +08:00
x: common_vendor.p({
2024-04-28 18:08:57 +08:00
show: !showWeixin.value
2024-04-27 18:02:43 +08:00
})
}, {
2024-05-06 17:58:41 +08:00
y: !isAgree.value
2024-04-28 18:08:57 +08:00
}, !isAgree.value ? {
2024-05-06 17:58:41 +08:00
z: common_vendor.o(($event) => isAgree.value = true),
A: common_assets._imports_1
2024-04-28 18:08:57 +08:00
} : {
2024-05-06 17:58:41 +08:00
B: common_vendor.o(($event) => isAgree.value = false),
C: common_assets._imports_0
2024-05-06 11:51:21 +08:00
}, {
2024-05-06 17:58:41 +08:00
D: common_vendor.o(($event) => showBind.value = false),
E: common_vendor.o(getPhoneNumber),
F: common_vendor.p({
2024-05-06 11:51:21 +08:00
show: showBind.value
})
2024-04-27 18:02:43 +08:00
});
2024-04-25 18:02:30 +08:00
};
}
};
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__file", "D:/里海数字乡村/purchase-let/pages/login/login.vue"]]);
wx.createPage(MiniProgramPage);