增加密码错误的异常捕获和oa自动登录

This commit is contained in:
砂糖
2025-07-14 09:39:32 +08:00
parent 80688b3239
commit 94b3ded9fb
3 changed files with 174 additions and 200 deletions

View File

@@ -6,69 +6,31 @@
<view class="title">欢迎使用德迅福安德信息科技有限公司内部交流平台</view>
</view>
<u-tabs :list="list" @click="click"></u-tabs>
<u-form
class="loginForm"
labelPosition="top"
:model="loginInfo"
:labelStyle="{
fontSize: '14px',
marginTop: '20rpx',
width: 'max-content',
}"
ref="loginForm"
>
<u-form class="loginForm" labelPosition="top" :model="loginInfo" :labelStyle="{
fontSize: '14px',
marginTop: '20rpx',
width: 'max-content',
}" ref="loginForm">
<u-form-item v-if="active === 0" label="" prop="phoneNumber">
<u-input
v-model="loginInfo.phoneNumber"
border="surround"
placeholder="请输入手机号码"
clearable
>
<view
slot="prefix"
class="phoneNumber_areacode"
@click="showPicker"
>
<u-input v-model="loginInfo.phoneNumber" border="surround" placeholder="请输入手机号码" clearable>
<view slot="prefix" class="phoneNumber_areacode" @click="showPicker">
<text class="areacode_content">+{{ loginInfo.areaCode }}</text>
<u-icon class="arrow_down" name="arrow-down"></u-icon>
</view>
</u-input>
</u-form-item>
<u-form-item v-if="active === 1" label="" prop="email">
<u-input
v-model="loginInfo.email"
border="surround"
placeholder="请输入您的邮箱"
clearable
>
<u-input v-model="loginInfo.email" border="surround" placeholder="请输入您的邮箱" clearable>
</u-input>
</u-form-item>
<u-form-item v-if="active > 1 || isPwdLogin" label="" prop="password">
<u-input
v-model="loginInfo.password"
border="surround"
placeholder="请输入密码"
:password="!eying"
clearable
>
<u-icon
@click="updateEye"
slot="suffix"
:name="eying ? 'eye-off' : 'eye'"
>
<u-input v-model="loginInfo.password" border="surround" placeholder="请输入密码" :password="!eying" clearable>
<u-icon @click="updateEye" slot="suffix" :name="eying ? 'eye-off' : 'eye'">
</u-icon>
</u-input>
</u-form-item>
<u-form-item
v-if="active <= 1 && !isPwdLogin"
label=""
prop="verificationCode"
>
<u-input
v-model="loginInfo.verificationCode"
border="surround"
placeholder="请输入验证码"
>
<u-form-item v-if="active <= 1 && !isPwdLogin" label="" prop="verificationCode">
<u-input v-model="loginInfo.verificationCode" border="surround" placeholder="请输入验证码">
<view class="code_btn" slot="suffix" @click="getCode">
{{ count !== 0 ? `${count} s` : "获取验证码" }}
</view>
@@ -80,12 +42,7 @@
<text class="forget" @click="toggleLoginMethod">{{ isPwdLogin ? "验证码登录" : "密码登录" }}</text>
</view>
<view class="login-btn">
<u-button
:loading="loading"
type="primary"
@click="startLogin"
:disabled="!canLogin"
>
<u-button :loading="loading" type="primary" @click="startLogin" :disabled="!canLogin">
登录
</u-button>
</view>
@@ -120,9 +77,9 @@ export default {
data() {
return {
list: [{
name: '手机号',
name: '手机号',
}, {
name: '邮箱',
name: '邮箱',
}],
loginInfo: {
email: "",
@@ -144,7 +101,7 @@ export default {
},
canLogin() {
return (
(this.loginInfo.phoneNumber || this.loginInfo.email) &&
(this.loginInfo.phoneNumber || this.loginInfo.email) &&
(this.loginInfo.password || this.loginInfo.verificationCode)
);
},
@@ -186,105 +143,51 @@ export default {
});
},
async startLogin() {
// this.$refs.loginForm.validate().then(async (valid) => {
try {
this.loading = true;
this.saveLoginInfo();
let data = {};
data = await businessLogin({
phoneNumber: this.loginInfo.phoneNumber,
email: this.loginInfo.email,
areaCode: `+${this.loginInfo.areaCode}`,
password: this.isPwdLogin ? md5(this.loginInfo.password) : "",
platform: uni.$u.os() === "ios" ? 1 : 2,
verifyCode: this.loginInfo.verificationCode,
});
console.log("data: " + JSON.stringify(data));
const { imToken, userID } = data;
await IMSDK.asyncApi(IMSDK.IMMethods.Login, uuidv4(), {
userID,
token: imToken,
});
this.saveLoginProfile(data);
this.$store.commit("user/SET_AUTH_DATA", data);
this.$store.dispatch("user/getSelfInfo");
this.$store.dispatch("conversation/getConversationList");
this.$store.dispatch("conversation/getUnReadCount");
this.$store.dispatch("contact/getFriendList");
this.$store.dispatch("contact/getGrouplist");
this.$store.dispatch("contact/getBlacklist");
this.$store.dispatch("contact/getRecvFriendApplications");
this.$store.dispatch("contact/getSentFriendApplications");
this.$store.dispatch("contact/getRecvGroupApplications");
this.$store.dispatch("contact/getSentGroupApplications");
// 登录成功后绑定deviceId与imId
// 获取设备cid调用云函数
// const cid = uni.getStorageSync('cid');
// uniCloud.callFunction({
// name: 'bindingIm',
// data: {
// deviceId: cid,
// imId: userID
// },
// success: (res) => {
// if (res.result.code === 200) {
// uni.showToast({
// title: res.result.msg,
// icon: 'success'
// });
// } else {
// uni.showToast({
// title: res.result.msg,
// icon: 'none'
// });
// }
// },
// fail: (err) => {
// uni.showToast({
// title: '云函数调用失败',
// icon: 'none'
// });
// console.error(err);
// }
// });
uni.switchTab({
url: "/pages/conversation/conversationList/index",
});
await getSMSCodeFromOa(this.loginInfo.phoneNumber);
const info = await loginOaByPhone(this.loginInfo.phoneNumber)
// console.log('用户信息', info)
// const oaUserId = info.userInfo.userId;
// uniCloud.callFunction({
// name: 'binding',
// data: {
// oaId: oaUserId,
// deviceId: cid
// },
// success: (res) => {
// if (res.result.code === 200) {
// uni.showToast({
// title: res.result.msg,
// icon: 'success'
// });
// } else {
// uni.showToast({
// title: res.result.msg,
// icon: 'none'
// });
// }
// },
// fail: (err) => {
// uni.showToast({
// title: '云函数调用失败',
// icon: 'none'
// });
// console.error(err);
// }
// });
this.loginInfo.password = "";
data = await businessLogin({
phoneNumber: this.loginInfo.phoneNumber,
email: this.loginInfo.email,
areaCode: `+${this.loginInfo.areaCode}`,
password: this.isPwdLogin ? md5(this.loginInfo.password) : "",
platform: uni.$u.os() === "ios" ? 1 : 2,
verifyCode: this.loginInfo.verificationCode,
});
console.log("data: " + JSON.stringify(data));
const { imToken, userID } = data;
if (!imToken || !userID) {
throw new Error("登录失败")
}
await IMSDK.asyncApi(IMSDK.IMMethods.Login, uuidv4(), {
userID,
token: imToken,
});
this.saveLoginProfile(data);
this.$store.commit("user/SET_AUTH_DATA", data);
this.$store.dispatch("user/getSelfInfo");
this.$store.dispatch("conversation/getConversationList");
this.$store.dispatch("conversation/getUnReadCount");
this.$store.dispatch("contact/getFriendList");
this.$store.dispatch("contact/getGrouplist");
this.$store.dispatch("contact/getBlacklist");
this.$store.dispatch("contact/getRecvFriendApplications");
this.$store.dispatch("contact/getSentFriendApplications");
this.$store.dispatch("contact/getRecvGroupApplications");
this.$store.dispatch("contact/getSentGroupApplications");
await getSMSCodeFromOa(this.loginInfo.phoneNumber);
const info = await loginOaByPhone(this.loginInfo.phoneNumber)
this.loginInfo.password = "";
this.loading = false;
// });
uni.switchTab({
url: "/pages/conversation/conversationList/index",
});
} catch (error) {
console.error(error);
uni.$u.toast("登录失败");
this.loading = false;
}
},
saveLoginProfile(data) {
const { imToken, chatToken, userID } = data;
@@ -371,11 +274,9 @@ export default {
.login {
color: #0c1c33;
padding: 10vh 80rpx 0;
background: linear-gradient(
180deg,
rgba(0, 137, 255, 0.1) 0%,
rgba(255, 255, 255, 0) 100%
);
background: linear-gradient(180deg,
rgba(0, 137, 255, 0.1) 0%,
rgba(255, 255, 255, 0) 100%);
.title {
font-size: 28rpx;

View File

@@ -3,21 +3,13 @@
<view class="self_info_row"></view>
<view class="info_card">
<my-avatar
:src="selfInfo.faceURL || '/static/images/default_avatar.png'"
:desc="selfInfo.nickname"
size="46"
/>
<my-avatar :src="selfInfo.faceURL || '/static/images/default_avatar.png'" :desc="selfInfo.nickname" size="46" />
<view class="id_row">
<text class="nickname">{{ selfInfo.nickname }}</text>
<view class="id_row_copy" @click="copy">
<text class="id">{{ selfInfo.userID }}</text>
<image
style="width: 32rpx; height: 32rpx"
src="@/static/images/id_copy.png"
mode=""
/>
<image style="width: 32rpx; height: 32rpx" src="@/static/images/id_copy.png" mode="" />
</view>
</view>
@@ -28,12 +20,7 @@
</view>
<view class="action_box">
<view
@click="profileMenuClick(item)"
class="profile_menu_item"
v-for="item in profileMenus"
:key="item.idx"
>
<view @click="profileMenuClick(item)" class="profile_menu_item" v-for="item in profileMenus" :key="item.idx">
<view class="menu_left">
<image style="width: 48rpx; height: 48rpx" :src="item.icon" mode="" />
<text>{{ item.title }}</text>
@@ -76,13 +63,18 @@ export default {
title: "应用更新",
icon: require("static/images/profile_menu_about.png"),
},
{
idx: 5,
title: '测试推送',
icon: require("static/images/profile_menu_about.png")
},
{
idx: 5,
title: '测试推送',
icon: require("static/images/profile_menu_about.png")
},
{
idx: 6,
title: "清理缓存",
icon: require("static/images/profile_menu_about.png"),
},
{
idx: 7,
title: "退出登录",
icon: require("static/images/profile_menu_logout.png"),
},
@@ -149,19 +141,22 @@ export default {
case 4:
this.showUpdateOptions();
break;
case 5:
uni.createPushMessage({
content: '今天还没有报工哦',
title: "报工提醒",
success() {
console.log('推送成功')
},
fail() {
console.log("推送失败")
}
});
break;
case 5:
uni.createPushMessage({
content: '今天还没有报工哦',
title: "报工提醒",
success() {
console.log('推送成功')
},
fail() {
console.log("推送失败")
}
});
break;
case 6:
this.clearCache();
break;
case 7:
uni.showModal({
title: "提示",
content: "确定要退出当前账号吗?",
@@ -189,7 +184,7 @@ export default {
if (ignoredVersion) {
content += `\n当前忽略版本${ignoredVersion}`;
}
uni.showActionSheet({
itemList: ['检查更新', '清除忽略版本', '取消'],
success: (res) => {
@@ -206,7 +201,7 @@ export default {
success: (modalRes) => {
if (modalRes.confirm) {
uni.$updateManager.clearIgnoredVersion();
uni.showToast({title: '已清除忽略版本设置'});
uni.showToast({ title: '已清除忽略版本设置' });
}
}
});
@@ -218,6 +213,82 @@ export default {
}
});
},
clearCache() {
uni.showModal({
title: "清理缓存",
content: "确定要清理应用缓存吗?清理后需要重新登录。",
confirmText: "确认清理",
cancelText: "取消",
success: (res) => {
if (res.confirm) {
uni.showLoading({
title: '清理中...'
});
// 清理本地存储
const clearStorageKeys = [
'IMToken',
'BusinessToken',
'userInfo',
'conversationList',
'messageList',
'contactList'
];
clearStorageKeys.forEach(key => {
try {
uni.removeStorageSync(key);
} catch (e) {
console.log(`清理缓存失败: ${key}`, e);
}
});
// 清理文件缓存
uni.getSavedFileList({
success: (fileRes) => {
if (fileRes.fileList && fileRes.fileList.length > 0) {
fileRes.fileList.forEach(file => {
uni.removeSavedFile({
filePath: file.filePath,
success: () => {
console.log('文件缓存清理成功:', file.filePath);
},
fail: (err) => {
console.log('文件缓存清理失败:', file.filePath, err);
}
});
});
}
},
fail: (err) => {
console.log('获取文件列表失败:', err);
}
});
// 清理图片缓存
uni.getImageInfo({
src: '/static/images/default_avatar.png',
success: () => {
// 这里可以添加更多图片缓存清理逻辑
}
});
setTimeout(() => {
uni.hideLoading();
uni.showToast({
title: '缓存清理完成',
icon: 'success'
});
// 清理完成后跳转到登录页
setTimeout(() => {
uni.$u.route("/pages/login/index");
}, 1500);
}, 1000);
}
}
});
},
},
};
</script>

View File

@@ -37,12 +37,12 @@ const request = config => {
data: config.data,
header: config.header,
dataType: 'json'
}).then(response => {
}).then(async response => {
let [error, res] = response
// 打印返回值
console.log('[oaRequest] 返回值:', res)
if (error) {
console.log(error)
console.log(error)
toast('后端接口连接异常')
reject('后端接口连接异常')
return
@@ -59,6 +59,12 @@ const request = config => {
try {
await getSMSCodeFromOa(phoneNumber)
await loginOaByPhone(phoneNumber)
const pages = getCurrentPages();
const page = pages[pages.length - 1];
// 重新加载当前页面
if (page && page.onLoad) {
page.onLoad(page.options || {});
}
} catch (e) {
console.log('OA自动登录失败', e)
toast('OA自动登录失败')
@@ -66,10 +72,6 @@ const request = config => {
} else {
toast('无法获取手机号OA自动登录失败')
}
// 登录
// store.dispatch('LogOut').then(res => {
// uni.reLaunch({ url: '/pages/login' })
// })
}
})
reject('无效的会话,或者会话已过期,请重新登录。')