You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
277 lines
6.4 KiB
277 lines
6.4 KiB
import { inputSync } from "@utils/tools";
|
|
import validate from "@utils/validate/index.js";
|
|
import {
|
|
wxRequestPost,
|
|
wxNavigateTo,
|
|
} from "@utils/promise-wx-api";
|
|
import nextTick from "@npm/dai-mp/tools/nextTick.js";
|
|
import computedBehavior from "@npm/dai-mp/mixins/computed-component/index.js";
|
|
|
|
const app = getApp();
|
|
|
|
Component({
|
|
behaviors: [computedBehavior],
|
|
properties: {},
|
|
data: {
|
|
pageTitle: "党群e事通",
|
|
|
|
loginType: "wxcode", //登录类型:wxcode微信, sms短信, password 密码
|
|
|
|
loginStatus: 0, // 登录状态 0未 1中 2功 3败
|
|
|
|
fmData: {
|
|
isNovice: false,
|
|
phone: "",
|
|
smsCode: "",
|
|
password: "",
|
|
},
|
|
// 手机验证码
|
|
codeData: {
|
|
status: 0, // 0初始 1发送中 2成功 3失败
|
|
cd: 0,
|
|
},
|
|
|
|
token: "",
|
|
|
|
isShowPassword: true, //是否按密码样式显示
|
|
},
|
|
|
|
computed: {
|
|
// 提交前预验证错误,为空说明可以提交
|
|
errBeforeSmsSubmit(data) {
|
|
const { fmData } = data,
|
|
vlt = validate(fmData, {
|
|
phone: [
|
|
{
|
|
rule: "required",
|
|
message: "请先输入【手机号码】",
|
|
},
|
|
{
|
|
rule: "mobile",
|
|
message: "【手机号码】格式不正确",
|
|
},
|
|
],
|
|
smsCode: [
|
|
{
|
|
rule: "required",
|
|
message: "请先输入【短信验证码】",
|
|
},
|
|
],
|
|
});
|
|
if (!vlt.valid) {
|
|
return vlt.error;
|
|
} else {
|
|
return "";
|
|
}
|
|
},
|
|
|
|
// 提交前预验证错误,为空说明可以提交
|
|
errBeforePasswordSubmit(data) {
|
|
const { fmData } = data,
|
|
vlt = validate(fmData, {
|
|
phone: [
|
|
{
|
|
rule: "required",
|
|
message: "请先输入【手机号码】",
|
|
},
|
|
{
|
|
rule: "mobile",
|
|
message: "【手机号码】格式不正确",
|
|
},
|
|
],
|
|
password: [
|
|
{
|
|
rule: "required",
|
|
message: "请先输入【密码】",
|
|
},
|
|
],
|
|
});
|
|
if (!vlt.valid) {
|
|
return vlt.error;
|
|
} else {
|
|
return "";
|
|
}
|
|
},
|
|
},
|
|
|
|
watch: {
|
|
// "tempCurrAgencyName, currAgencyName": function (a, b) {
|
|
// console.log(a, b);
|
|
// },
|
|
},
|
|
|
|
methods: {
|
|
onLoad() {
|
|
const { customerName } = wx.getExtConfigSync ? wx.getExtConfigSync() : {};
|
|
if (customerName) {
|
|
this.setData({
|
|
pageTitle: customerName,
|
|
});
|
|
}
|
|
},
|
|
|
|
inputSync,
|
|
|
|
// 获取短信验证码
|
|
async getTelCode() {
|
|
const { codeData } = this.data;
|
|
if (codeData.status == 1 || codeData.cd != 0) return;
|
|
|
|
const { fmData } = this.data,
|
|
vlt = validate(fmData, {
|
|
phone: [
|
|
{
|
|
rule: "required",
|
|
message: "请先输入【手机号码】",
|
|
},
|
|
{
|
|
rule: "mobile",
|
|
message: "【手机号码】格式不正确",
|
|
},
|
|
],
|
|
});
|
|
if (!vlt.valid) {
|
|
return wx.showToast({
|
|
title: vlt.error,
|
|
icon: "none",
|
|
duration: 1500,
|
|
});
|
|
}
|
|
|
|
codeData.status = 1;
|
|
this.setData({ codeData });
|
|
|
|
const {
|
|
data: {
|
|
data: { code },
|
|
},
|
|
msg,
|
|
} = await wxRequestPost(
|
|
"auth/gov/loginwxmp/sendsmscode",
|
|
{
|
|
mobile: fmData.phone,
|
|
},
|
|
{
|
|
// isMock: true,
|
|
isQuiet: false,
|
|
}
|
|
);
|
|
|
|
if (msg === "success" && code === 0) {
|
|
codeData.status = 2;
|
|
codeData.cd = 59;
|
|
this.setData({ codeData });
|
|
|
|
// 开始倒计时
|
|
this.sendTelCodeCd();
|
|
} else {
|
|
codeData.status = 3;
|
|
this.setData({ codeData });
|
|
}
|
|
},
|
|
|
|
// 发送短信倒计时
|
|
sendTelCodeCd() {
|
|
// 开始计时
|
|
const cdFn = async () => {
|
|
await nextTick(1000);
|
|
|
|
const { codeData } = this.data;
|
|
if (codeData.cd > 0) {
|
|
codeData.cd -= 1;
|
|
this.setData({ codeData });
|
|
cdFn();
|
|
}
|
|
};
|
|
cdFn();
|
|
},
|
|
|
|
//切换登录模式
|
|
changeLoginType(e) {
|
|
let type = e.target.dataset.name;
|
|
console.log(type);
|
|
this.setData({
|
|
loginType: type,
|
|
});
|
|
},
|
|
|
|
//显示密码
|
|
showPossword() {
|
|
const { isShowPassword } = this.data;
|
|
this.setData({
|
|
isShowPassword: !isShowPassword,
|
|
});
|
|
},
|
|
|
|
// 获取组织列表
|
|
async submit() {
|
|
const { loginType } = this.data;
|
|
if (loginType == "wxcode") {
|
|
app.setAccountInfo({ isPhoneAccount: false });
|
|
await this.submitByWxcode();
|
|
} else if (loginType == "password") {
|
|
if (await this.submitByPassport()) {
|
|
app.setAccountInfo({ isPhoneAccount: true });
|
|
} else {
|
|
return;
|
|
}
|
|
}
|
|
|
|
wxNavigateTo("../chooseGrid/chooseGrid", { isNovice: true });
|
|
},
|
|
|
|
async submitByWxcode() {
|
|
wx.showLoading({ title: "请求中" });
|
|
await app.loginGetToken();
|
|
wx.hideLoading();
|
|
},
|
|
|
|
async submitByPassport() {
|
|
console.log("密码登录");
|
|
const { errBeforePasswordSubmit } = this.data;
|
|
if (errBeforePasswordSubmit) {
|
|
wx.showToast({
|
|
title: errBeforePasswordSubmit,
|
|
icon: "none",
|
|
duration: 2000,
|
|
});
|
|
return false;
|
|
}
|
|
|
|
const { fmData } = this.data;
|
|
wx.showLoading({
|
|
title: "提交中",
|
|
mask: true,
|
|
});
|
|
|
|
const extAppid = wx.getStorageSync("extAppid");
|
|
const url = "/auth/thirdlogin/redislogin";
|
|
const {
|
|
data: {
|
|
data: { code, data },
|
|
},
|
|
msg,
|
|
} = await wxRequestPost(
|
|
url,
|
|
{
|
|
isNovice: fmData.isNovice,
|
|
mobile: fmData.phone,
|
|
password: fmData.password,
|
|
appId: extAppid,
|
|
},
|
|
{
|
|
// isMock: true,
|
|
isQuiet: false,
|
|
}
|
|
);
|
|
wx.hideLoading();
|
|
|
|
if (msg === "success" && code === 0) {
|
|
app.setAccountInfo({ token: data.token });
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
},
|
|
},
|
|
});
|
|
|