diff --git a/pages/login/index.vue b/pages/login/index.vue index 88ea34f..3698908 100644 --- a/pages/login/index.vue +++ b/pages/login/index.vue @@ -6,69 +6,31 @@ 欢迎使用德迅,福安德信息科技有限公司内部交流平台 - + - - + + +{{ loginInfo.areaCode }} - + - - + + - - + + {{ count !== 0 ? `${count} s` : "获取验证码" }} @@ -80,12 +42,7 @@ {{ isPwdLogin ? "验证码登录" : "密码登录" }} @@ -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; diff --git a/pages/profile/index/index.vue b/pages/profile/index/index.vue index b27ed1d..3e29196 100644 --- a/pages/profile/index/index.vue +++ b/pages/profile/index/index.vue @@ -3,21 +3,13 @@ - + {{ selfInfo.nickname }} {{ selfInfo.userID }} - + @@ -28,12 +20,7 @@ - + {{ item.title }} @@ -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); + } + } + }); + }, }, }; diff --git a/util/oaRequest.js b/util/oaRequest.js index fd23068..1adab92 100644 --- a/util/oaRequest.js +++ b/util/oaRequest.js @@ -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('无效的会话,或者会话已过期,请重新登录。')