2024-10-13 11:24:45 +08:00
|
|
|
import {
|
|
|
|
getToken,
|
2024-10-13 15:40:15 +08:00
|
|
|
setToken,
|
|
|
|
getOpenId,
|
2024-10-15 00:32:25 +08:00
|
|
|
setOpenId,
|
2024-12-29 11:46:50 +08:00
|
|
|
setUserInfo,
|
2025-02-16 17:19:52 +08:00
|
|
|
getUserInfo,
|
2024-10-15 00:32:25 +08:00
|
|
|
getSessionKey,
|
|
|
|
setSessionKey,
|
2025-09-12 17:16:18 +08:00
|
|
|
} from "../../utils/auth";
|
2024-10-13 11:24:45 +08:00
|
|
|
import {
|
2024-10-15 23:55:05 +08:00
|
|
|
wxLogin,
|
2024-10-13 15:40:15 +08:00
|
|
|
maLogin,
|
2024-10-13 11:24:45 +08:00
|
|
|
getCodeImg,
|
2024-10-13 15:40:15 +08:00
|
|
|
getMaOpenId,
|
2024-10-15 23:55:05 +08:00
|
|
|
refreshMobileToken,
|
2024-12-29 11:46:50 +08:00
|
|
|
findUserInfoByCache,
|
2025-09-12 17:16:18 +08:00
|
|
|
} from "../../api/login";
|
|
|
|
import { findMyProjectList, findProSubDeptsUserInfo } from "../../api/project";
|
|
|
|
import config from "../../config";
|
2024-10-13 11:24:45 +08:00
|
|
|
const app = getApp();
|
|
|
|
Page({
|
|
|
|
/**
|
|
|
|
* 页面的初始数据
|
|
|
|
*/
|
|
|
|
data: {
|
2025-09-12 17:16:18 +08:00
|
|
|
username: "",
|
|
|
|
password: "",
|
|
|
|
code: "",
|
|
|
|
uuid: "",
|
|
|
|
codeUrl: "",
|
2024-12-17 20:25:21 +08:00
|
|
|
checked: true,
|
2025-09-12 17:16:18 +08:00
|
|
|
logo: config.baseImgUrl + "/cdn/app_logo.png",
|
2024-10-13 11:24:45 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
//获取填写的账号信息
|
|
|
|
name: function (even) {
|
|
|
|
this.setData({
|
2025-09-12 17:16:18 +08:00
|
|
|
username: even.detail.value,
|
|
|
|
});
|
2024-10-13 11:24:45 +08:00
|
|
|
},
|
|
|
|
//获取填写的密码信息
|
|
|
|
psw: function (even) {
|
|
|
|
this.setData({
|
2025-09-12 17:16:18 +08:00
|
|
|
password: even.detail.value,
|
|
|
|
});
|
2024-10-13 11:24:45 +08:00
|
|
|
},
|
|
|
|
//获取填写的密码信息
|
|
|
|
code: function (even) {
|
|
|
|
this.setData({
|
2025-09-12 17:16:18 +08:00
|
|
|
code: even.detail.value,
|
|
|
|
});
|
2024-10-13 11:24:45 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
onLoad: function (option) {
|
2024-10-13 15:40:15 +08:00
|
|
|
this.getMaOpenId();
|
2024-10-13 11:24:45 +08:00
|
|
|
if (getToken()) {
|
|
|
|
console.log("Authorization...{}", getToken());
|
|
|
|
//刷新权限信息
|
2025-09-12 17:16:18 +08:00
|
|
|
refreshMobileToken().then((res) => {
|
|
|
|
if (res.code == "200") {
|
2024-12-29 11:46:50 +08:00
|
|
|
this.getUserInfoByCache();
|
2024-10-13 11:24:45 +08:00
|
|
|
} else {
|
2024-12-29 11:46:50 +08:00
|
|
|
this.loadCodeImage();
|
2024-10-13 11:24:45 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
2025-09-12 17:16:18 +08:00
|
|
|
console.log("未查询到Token...{}...准备重新登录");
|
2024-10-13 11:24:45 +08:00
|
|
|
this.loadCodeImage();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2024-10-13 15:40:15 +08:00
|
|
|
/**
|
|
|
|
* 授权登录
|
|
|
|
*/
|
|
|
|
getMaOpenId: function () {
|
|
|
|
wx.login({
|
2025-09-12 17:16:18 +08:00
|
|
|
success: (res) => {
|
|
|
|
getMaOpenId({ code: res.code }).then((response) => {
|
2024-10-15 00:32:25 +08:00
|
|
|
setOpenId(response.data.openid);
|
|
|
|
setSessionKey(response.data.sessionKey);
|
2024-10-13 15:40:15 +08:00
|
|
|
});
|
2025-09-12 17:16:18 +08:00
|
|
|
},
|
|
|
|
});
|
2024-10-13 15:40:15 +08:00
|
|
|
},
|
|
|
|
|
2024-10-13 11:24:45 +08:00
|
|
|
loadCodeImage: function () {
|
2025-09-12 17:16:18 +08:00
|
|
|
getCodeImg().then((res) => {
|
|
|
|
let captchaEnabled =
|
|
|
|
res.captchaEnabled === undefined ? true : res.captchaEnabled;
|
2024-10-13 11:24:45 +08:00
|
|
|
if (captchaEnabled) {
|
|
|
|
this.setData({
|
2025-09-12 17:16:18 +08:00
|
|
|
codeUrl: "data:image/gif;base64," + res.img,
|
|
|
|
uuid: res.uuid,
|
|
|
|
});
|
2024-10-13 11:24:45 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
//登录
|
|
|
|
userLogin: function () {
|
|
|
|
var username = this.data.username;
|
|
|
|
var password = this.data.password;
|
|
|
|
var code = this.data.code;
|
|
|
|
if (username == "") {
|
|
|
|
app.toast("登录账号不能为空");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (password == "") {
|
|
|
|
app.toast("登录密码不能为空");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (code == "") {
|
|
|
|
app.toast("验证码不能为空");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
//启动蒙版
|
|
|
|
let that = this;
|
|
|
|
//发送请求
|
2024-10-15 23:55:05 +08:00
|
|
|
wxLogin({
|
2025-09-12 17:16:18 +08:00
|
|
|
username: username,
|
|
|
|
password: password,
|
|
|
|
code: code,
|
|
|
|
uuid: that.data.uuid,
|
|
|
|
}).then((res) => {
|
|
|
|
if (res.code == "200") {
|
|
|
|
setToken(res.data.access_token);
|
2024-10-13 11:24:45 +08:00
|
|
|
//跳转页面
|
2024-12-29 11:46:50 +08:00
|
|
|
this.getUserInfoByCache();
|
2024-10-13 11:24:45 +08:00
|
|
|
} else {
|
|
|
|
that.loadCodeImage();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
getPhoneNumber(e) {
|
2025-08-01 18:25:02 +08:00
|
|
|
if (e.detail.code) {
|
2024-10-13 15:40:15 +08:00
|
|
|
let data = {
|
2025-08-01 18:25:02 +08:00
|
|
|
openId: getOpenId(),
|
|
|
|
sessionKey: getSessionKey(),
|
2024-10-13 15:40:15 +08:00
|
|
|
iv: e.detail.iv,
|
2025-09-12 17:16:18 +08:00
|
|
|
encryptedData: e.detail.encryptedData,
|
|
|
|
};
|
|
|
|
maLogin(data).then((res) => {
|
2025-01-04 18:20:48 +08:00
|
|
|
setToken(res.data.access_token);
|
|
|
|
this.getUserInfoByCache();
|
2025-09-12 17:16:18 +08:00
|
|
|
});
|
2025-08-01 18:25:02 +08:00
|
|
|
} else {
|
2024-10-13 15:40:15 +08:00
|
|
|
//用户决绝授权
|
|
|
|
app.toast("请允许微信手机号一键登录");
|
|
|
|
}
|
2024-10-13 11:24:45 +08:00
|
|
|
},
|
|
|
|
|
2024-12-29 11:46:50 +08:00
|
|
|
/**
|
|
|
|
* 查询
|
|
|
|
* 用户详细信息
|
2025-09-12 17:16:18 +08:00
|
|
|
* @param {*} e
|
2024-12-29 11:46:50 +08:00
|
|
|
*/
|
|
|
|
getUserInfoByCache: function () {
|
2025-09-12 17:16:18 +08:00
|
|
|
findUserInfoByCache().then((res) => {
|
2025-08-01 18:25:02 +08:00
|
|
|
if (res.code == 200) {
|
2025-09-12 17:16:18 +08:00
|
|
|
res.user.isTechnician =
|
|
|
|
(res.user.roles || []).find(
|
|
|
|
(role) => role.roleKey.indexOf("zbjsy_") >= 0
|
|
|
|
) != null;
|
2024-12-29 11:46:50 +08:00
|
|
|
setUserInfo(res.user);
|
|
|
|
app.globalData.userData = res.user;
|
|
|
|
this.getMyProjectList();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 查询
|
|
|
|
* 用户项目信息
|
|
|
|
* 根据项目配置进入不同页面...
|
|
|
|
*/
|
|
|
|
getMyProjectList: function () {
|
2025-09-12 17:16:18 +08:00
|
|
|
findMyProjectList().then((res) => {
|
2025-08-01 18:25:02 +08:00
|
|
|
if (res.code == 200) {
|
2024-12-29 11:46:50 +08:00
|
|
|
app.globalData.projectInfoList = res.rows;
|
2025-08-01 18:25:02 +08:00
|
|
|
if (res.rows.length > 0) {
|
|
|
|
if (res.rows.length == 1) {
|
2024-12-29 11:46:50 +08:00
|
|
|
app.globalData.useProjectId = res.rows[0].id;
|
|
|
|
app.globalData.useProjectName = res.rows[0].projectName;
|
2025-09-12 17:16:18 +08:00
|
|
|
findProSubDeptsUserInfo(app.globalData.useProjectId).then(
|
|
|
|
(detail) => {
|
|
|
|
if (detail.code == 200) {
|
|
|
|
let userInfo = getUserInfo();
|
|
|
|
userInfo.projectUserInfo = detail.data;
|
|
|
|
setUserInfo(userInfo);
|
|
|
|
//单项目直接进入项目页面
|
|
|
|
wx.redirectTo({
|
|
|
|
url: "../../pageage/project_info/index",
|
|
|
|
});
|
|
|
|
}
|
2025-02-16 17:19:52 +08:00
|
|
|
}
|
2025-09-12 17:16:18 +08:00
|
|
|
);
|
2025-08-01 18:25:02 +08:00
|
|
|
} else {
|
2024-12-29 11:46:50 +08:00
|
|
|
//多项目进入项目切换页面
|
|
|
|
wx.redirectTo({
|
2025-09-12 17:16:18 +08:00
|
|
|
url: "../../pageage/project_list/index",
|
|
|
|
});
|
2024-12-29 11:46:50 +08:00
|
|
|
}
|
2025-08-01 18:25:02 +08:00
|
|
|
} else {
|
2024-12-29 11:46:50 +08:00
|
|
|
app.toast("未查询到当前用户项目,信息审核中或人员已离场");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
2025-09-12 17:16:18 +08:00
|
|
|
});
|