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

View File

@@ -3,21 +3,13 @@
<view class="self_info_row"></view> <view class="self_info_row"></view>
<view class="info_card"> <view class="info_card">
<my-avatar <my-avatar :src="selfInfo.faceURL || '/static/images/default_avatar.png'" :desc="selfInfo.nickname" size="46" />
:src="selfInfo.faceURL || '/static/images/default_avatar.png'"
:desc="selfInfo.nickname"
size="46"
/>
<view class="id_row"> <view class="id_row">
<text class="nickname">{{ selfInfo.nickname }}</text> <text class="nickname">{{ selfInfo.nickname }}</text>
<view class="id_row_copy" @click="copy"> <view class="id_row_copy" @click="copy">
<text class="id">{{ selfInfo.userID }}</text> <text class="id">{{ selfInfo.userID }}</text>
<image <image style="width: 32rpx; height: 32rpx" src="@/static/images/id_copy.png" mode="" />
style="width: 32rpx; height: 32rpx"
src="@/static/images/id_copy.png"
mode=""
/>
</view> </view>
</view> </view>
@@ -28,12 +20,7 @@
</view> </view>
<view class="action_box"> <view class="action_box">
<view <view @click="profileMenuClick(item)" class="profile_menu_item" v-for="item in profileMenus" :key="item.idx">
@click="profileMenuClick(item)"
class="profile_menu_item"
v-for="item in profileMenus"
:key="item.idx"
>
<view class="menu_left"> <view class="menu_left">
<image style="width: 48rpx; height: 48rpx" :src="item.icon" mode="" /> <image style="width: 48rpx; height: 48rpx" :src="item.icon" mode="" />
<text>{{ item.title }}</text> <text>{{ item.title }}</text>
@@ -76,13 +63,18 @@ export default {
title: "应用更新", title: "应用更新",
icon: require("static/images/profile_menu_about.png"), icon: require("static/images/profile_menu_about.png"),
}, },
{ {
idx: 5, idx: 5,
title: '测试推送', title: '测试推送',
icon: require("static/images/profile_menu_about.png") icon: require("static/images/profile_menu_about.png")
}, },
{ {
idx: 6, idx: 6,
title: "清理缓存",
icon: require("static/images/profile_menu_about.png"),
},
{
idx: 7,
title: "退出登录", title: "退出登录",
icon: require("static/images/profile_menu_logout.png"), icon: require("static/images/profile_menu_logout.png"),
}, },
@@ -149,19 +141,22 @@ export default {
case 4: case 4:
this.showUpdateOptions(); this.showUpdateOptions();
break; break;
case 5: case 5:
uni.createPushMessage({ uni.createPushMessage({
content: '今天还没有报工哦', content: '今天还没有报工哦',
title: "报工提醒", title: "报工提醒",
success() { success() {
console.log('推送成功') console.log('推送成功')
}, },
fail() { fail() {
console.log("推送失败") console.log("推送失败")
} }
}); });
break; break;
case 6: case 6:
this.clearCache();
break;
case 7:
uni.showModal({ uni.showModal({
title: "提示", title: "提示",
content: "确定要退出当前账号吗?", content: "确定要退出当前账号吗?",
@@ -189,7 +184,7 @@ export default {
if (ignoredVersion) { if (ignoredVersion) {
content += `\n当前忽略版本${ignoredVersion}`; content += `\n当前忽略版本${ignoredVersion}`;
} }
uni.showActionSheet({ uni.showActionSheet({
itemList: ['检查更新', '清除忽略版本', '取消'], itemList: ['检查更新', '清除忽略版本', '取消'],
success: (res) => { success: (res) => {
@@ -206,7 +201,7 @@ export default {
success: (modalRes) => { success: (modalRes) => {
if (modalRes.confirm) { if (modalRes.confirm) {
uni.$updateManager.clearIgnoredVersion(); 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> </script>

View File

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