微信小程序登录图片修改

dev_xd
lj7788@126.com 2025-09-12 17:16:18 +08:00
parent f1575e2bba
commit 293e1566d1
2 changed files with 63 additions and 59 deletions

View File

@ -7,7 +7,7 @@ import {
getUserInfo, getUserInfo,
getSessionKey, getSessionKey,
setSessionKey, setSessionKey,
} from '../../utils/auth' } from "../../utils/auth";
import { import {
wxLogin, wxLogin,
maLogin, maLogin,
@ -15,43 +15,41 @@ import {
getMaOpenId, getMaOpenId,
refreshMobileToken, refreshMobileToken,
findUserInfoByCache, findUserInfoByCache,
} from '../../api/login' } from "../../api/login";
import { import { findMyProjectList, findProSubDeptsUserInfo } from "../../api/project";
findMyProjectList, import config from "../../config";
findProSubDeptsUserInfo,
} from '../../api/project'
const app = getApp(); const app = getApp();
Page({ Page({
/** /**
* 页面的初始数据 * 页面的初始数据
*/ */
data: { data: {
username: '', username: "",
password: '', password: "",
code: '', code: "",
uuid: '', uuid: "",
codeUrl: '', codeUrl: "",
checked: true, checked: true,
logo: config.baseImgUrl + "/cdn/app_logo.png",
}, },
//获取填写的账号信息 //获取填写的账号信息
name: function (even) { name: function (even) {
this.setData({ this.setData({
username: even.detail.value username: even.detail.value,
}) });
}, },
//获取填写的密码信息 //获取填写的密码信息
psw: function (even) { psw: function (even) {
this.setData({ this.setData({
password: even.detail.value password: even.detail.value,
}) });
}, },
//获取填写的密码信息 //获取填写的密码信息
code: function (even) { code: function (even) {
this.setData({ this.setData({
code: even.detail.value code: even.detail.value,
}) });
}, },
onLoad: function (option) { onLoad: function (option) {
@ -59,15 +57,15 @@ Page({
if (getToken()) { if (getToken()) {
console.log("Authorization...{}", getToken()); console.log("Authorization...{}", getToken());
//刷新权限信息 //刷新权限信息
refreshMobileToken().then(res => { refreshMobileToken().then((res) => {
if (res.code == '200') { if (res.code == "200") {
this.getUserInfoByCache(); this.getUserInfoByCache();
} else { } else {
this.loadCodeImage(); this.loadCodeImage();
} }
}); });
} else { } else {
console.log("未查询到Token...{}...准备重新登录") console.log("未查询到Token...{}...准备重新登录");
this.loadCodeImage(); this.loadCodeImage();
} }
}, },
@ -77,23 +75,24 @@ Page({
*/ */
getMaOpenId: function () { getMaOpenId: function () {
wx.login({ wx.login({
success: res => { success: (res) => {
getMaOpenId({ 'code': res.code }).then(response => { getMaOpenId({ code: res.code }).then((response) => {
setOpenId(response.data.openid); setOpenId(response.data.openid);
setSessionKey(response.data.sessionKey); setSessionKey(response.data.sessionKey);
}); });
} },
}) });
}, },
loadCodeImage: function () { loadCodeImage: function () {
getCodeImg().then(res => { getCodeImg().then((res) => {
let captchaEnabled = res.captchaEnabled === undefined ? true : res.captchaEnabled let captchaEnabled =
res.captchaEnabled === undefined ? true : res.captchaEnabled;
if (captchaEnabled) { if (captchaEnabled) {
this.setData({ this.setData({
codeUrl: 'data:image/gif;base64,' + res.img, codeUrl: "data:image/gif;base64," + res.img,
uuid: res.uuid uuid: res.uuid,
}) });
} }
}); });
}, },
@ -119,13 +118,13 @@ Page({
let that = this; let that = this;
//发送请求 //发送请求
wxLogin({ wxLogin({
"username": username, username: username,
"password": password, password: password,
"code": code, code: code,
"uuid": that.data.uuid, uuid: that.data.uuid,
}).then(res => { }).then((res) => {
if (res.code == '200') { if (res.code == "200") {
setToken(res.data.access_token) setToken(res.data.access_token);
//跳转页面 //跳转页面
this.getUserInfoByCache(); this.getUserInfoByCache();
} else { } else {
@ -140,12 +139,12 @@ Page({
openId: getOpenId(), openId: getOpenId(),
sessionKey: getSessionKey(), sessionKey: getSessionKey(),
iv: e.detail.iv, iv: e.detail.iv,
encryptedData: e.detail.encryptedData encryptedData: e.detail.encryptedData,
} };
maLogin(data).then(res => { maLogin(data).then((res) => {
setToken(res.data.access_token); setToken(res.data.access_token);
this.getUserInfoByCache(); this.getUserInfoByCache();
}) });
} else { } else {
//用户决绝授权 //用户决绝授权
app.toast("请允许微信手机号一键登录"); app.toast("请允许微信手机号一键登录");
@ -155,12 +154,15 @@ Page({
/** /**
* 查询 * 查询
* 用户详细信息 * 用户详细信息
* @param {*} e * @param {*} e
*/ */
getUserInfoByCache: function () { getUserInfoByCache: function () {
findUserInfoByCache().then(res => { findUserInfoByCache().then((res) => {
if (res.code == 200) { if (res.code == 200) {
res.user.isTechnician = (res.user.roles || []).find(role => role.roleKey.indexOf("zbjsy_") >= 0) != null; res.user.isTechnician =
(res.user.roles || []).find(
(role) => role.roleKey.indexOf("zbjsy_") >= 0
) != null;
setUserInfo(res.user); setUserInfo(res.user);
app.globalData.userData = res.user; app.globalData.userData = res.user;
this.getMyProjectList(); this.getMyProjectList();
@ -174,29 +176,31 @@ Page({
* 根据项目配置进入不同页面... * 根据项目配置进入不同页面...
*/ */
getMyProjectList: function () { getMyProjectList: function () {
findMyProjectList().then(res => { findMyProjectList().then((res) => {
if (res.code == 200) { if (res.code == 200) {
app.globalData.projectInfoList = res.rows; app.globalData.projectInfoList = res.rows;
if (res.rows.length > 0) { if (res.rows.length > 0) {
if (res.rows.length == 1) { if (res.rows.length == 1) {
app.globalData.useProjectId = res.rows[0].id; app.globalData.useProjectId = res.rows[0].id;
app.globalData.useProjectName = res.rows[0].projectName; app.globalData.useProjectName = res.rows[0].projectName;
findProSubDeptsUserInfo(app.globalData.useProjectId).then(detail => { findProSubDeptsUserInfo(app.globalData.useProjectId).then(
if (detail.code == 200) { (detail) => {
let userInfo = getUserInfo(); if (detail.code == 200) {
userInfo.projectUserInfo = detail.data; let userInfo = getUserInfo();
setUserInfo(userInfo); userInfo.projectUserInfo = detail.data;
//单项目直接进入项目页面 setUserInfo(userInfo);
wx.redirectTo({ //单项目直接进入项目页面
url: '../../pageage/project_info/index', wx.redirectTo({
}) url: "../../pageage/project_info/index",
});
}
} }
}); );
} else { } else {
//多项目进入项目切换页面 //多项目进入项目切换页面
wx.redirectTo({ wx.redirectTo({
url: '../../pageage/project_list/index', url: "../../pageage/project_list/index",
}) });
} }
} else { } else {
app.toast("未查询到当前用户项目,信息审核中或人员已离场"); app.toast("未查询到当前用户项目,信息审核中或人员已离场");
@ -205,4 +209,4 @@ Page({
} }
}); });
}, },
}) });

View File

@ -3,7 +3,7 @@
<image wx:if="{{false}}" src="https://xiangguan.sxyanzhu.com/profile/static/sys_logo.png"></image> <image wx:if="{{false}}" src="https://xiangguan.sxyanzhu.com/profile/static/sys_logo.png"></image>
</view> </view>
<view class="login_title"> <view class="login_title">
<image src="https://xiangguan.sxyanzhu.com/profile/static/yanzhu_logo.png"></image> <image src="{{logo}}"></image>
</view> </view>
<view wx:if="{{false}}" class="loadings"> <view wx:if="{{false}}" class="loadings">
<!-- <image src="/images/loading_i.gif"></image> --> <!-- <image src="/images/loading_i.gif"></image> -->