From 435597a1297ade23331bc0f95f955d2e75c3e01d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=88=B1=7E=E6=B5=B7=7E=E7=88=B1=E6=B5=B7=E7=88=B1?= =?UTF-8?q?=E6=B5=B7=7E=E5=8F=B3?= <1828712314@qq.com> Date: Thu, 27 Feb 2025 11:23:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=99=BB=E5=BD=95=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App.vue | 21 ----------- pages.json | 13 +++---- pages/login.vue | 71 ++++++++++++++++++------------------ sub/invite/addEnterprise.vue | 2 +- sub/owner/edit.vue | 14 +++++-- sub/owner/invite.vue | 4 +- utils/permission.js | 3 ++ 7 files changed, 58 insertions(+), 70 deletions(-) diff --git a/App.vue b/App.vue index c70e04e..95ccbe9 100644 --- a/App.vue +++ b/App.vue @@ -14,12 +14,6 @@ export default { uni.hideTabBar() // 初始化应用配置 this.initConfig() - if (!getOpenId()) { - this.applogin() - return - } - // 检查用户登录状态 - // this.checkLogin() }, initConfig() { this.globalData.config = config @@ -33,21 +27,6 @@ export default { console.error('获取设备信息失败:', err) } }) - }, - checkLogin() { - if (!getAccessToken()) { - this.$tab.reLaunch('/pages/login') - } - }, - async applogin() { - uni.login({ - success: res => { - setOpenId(res.code) - }, - fail: err => { - console.log('getOpenIdFail', err) - } - }) } } } diff --git a/pages.json b/pages.json index c97e3a6..d6741eb 100644 --- a/pages.json +++ b/pages.json @@ -1,5 +1,11 @@ { "pages": [{ + "path": "pages/login", + "style": { + "navigationBarTitleText": "登录", + "navigationStyle": "custom" + } + }, { "path": "pages/index", "style": { "navigationBarTitleText": "首页", @@ -10,13 +16,6 @@ } } }, - { - "path": "pages/login", - "style": { - "navigationBarTitleText": "登录", - "navigationStyle": "custom" - } - }, { "path": "pages/enterprise", "style": { diff --git a/pages/login.vue b/pages/login.vue index ad91a2e..538895b 100644 --- a/pages/login.vue +++ b/pages/login.vue @@ -32,39 +32,53 @@ export default { // 初始化应用 async initApp() { await uni.hideTabBar() + console.log('initapp') uni.hideTabBar({ animation: false }) - // 检查用户登录状态 - this.checkLogin() + if (!getOpenId()) { + // 如果没有openid则获取 + this.getWxOpenId().then(() => { + this.checkLogin() + }) + } else { + // 检查用户登录状态 + this.checkLogin() + } }, checkLogin() { console.log('accessToken', getAccessToken()) if (!getAccessToken()) { + // 如果没有token则获取 this.login() } else { this.loginSuccess() } }, - login() { - console.log('openId', getOpenId()) - if (getOpenId()) { - clearTimeout(this.timer) - const data = { - type: 34, - code: getOpenId(), - state: 'default', - userType: this.getUserType() - } - this.$store.dispatch('Login', data).then(() => { - this.loginSuccess() + getWxOpenId() { + return new Promise((resolve, reject) => { + uni.login({ + success: res => { + setOpenId(res.code) + resolve() + }, + fail: err => { + console.log('getOpenIdFail', err) + reject() + } }) - } else { - this.timer && clearTimeout(this.timer) - this.timer = setTimeout(() => { - this.login() - }, 200) + }) + }, + login() { + const data = { + type: 34, + code: getOpenId(), + state: 'default', + userType: this.getUserType() } + this.$store.dispatch('Login', data).then(() => { + this.loginSuccess() + }) }, getUserType() { // 企业邀请 @@ -76,15 +90,10 @@ export default { loginSuccess() { this.$store.dispatch('GetInfo').then(res => { this.handlerNavigateTo(res.data.user) + console.log('user', res.data.user) }) }, handlerNavigateTo(user) { - if (this.redirect) { - uni.reLaunch({ - url: this.redirect - }) - return - } // 邀请企业 if (this.inviteId) { uni.reLaunch({ @@ -93,19 +102,11 @@ export default { return } - // 审核中 - if (user.audit == 1) { - uni.reLaunch({ - url: '/sub/common/waiting' - }) - return - } - // 局内用户首次登录 - if (user.audit == null) { + if (user.audit == null || user.audit == 1) { // 局内用户首次登录 uni.reLaunch({ - url: '/sub/owner/edit' + url: `/sub/owner/edit?audit=${user.audit}` }) return } diff --git a/sub/invite/addEnterprise.vue b/sub/invite/addEnterprise.vue index 3776611..0ca10ef 100644 --- a/sub/invite/addEnterprise.vue +++ b/sub/invite/addEnterprise.vue @@ -274,7 +274,7 @@ export default { this.form.tags = data }) uni.$on('prove', data => { - if (this.form.id) { + if (this.form.id != '') { this.getProve() } else { this.prove.push(data) diff --git a/sub/owner/edit.vue b/sub/owner/edit.vue index cb34d1a..40c16e5 100644 --- a/sub/owner/edit.vue +++ b/sub/owner/edit.vue @@ -137,7 +137,10 @@ export default { } } }, - async onLoad() { + async onLoad(options) { + if (options.audit) { + this.form.audit = options.audit + } await this.getDict() }, onShow() { @@ -157,9 +160,12 @@ export default { } }, init() { - getUserProfile().then(res => { - this.form = res.data - }) + console.log('登录信息', this.$store.getters) + if (this.$store.getters.userId) { + getUserProfile().then(res => { + this.form = res.data + }) + } }, async getDict() { const dict = await getDictBatchByType({ diff --git a/sub/owner/invite.vue b/sub/owner/invite.vue index 1eaed96..d9bbffc 100644 --- a/sub/owner/invite.vue +++ b/sub/owner/invite.vue @@ -24,7 +24,7 @@ export default { onShareAppMessage() { return { title: '邀请企业入驻', - path: `/sub/invite/index?inviteId=${this.$store.getters.userId}`, + path: `/pages/login?inviteId=${this.$store.getters.userId}`, imageUrl: 'http://82.156.141.150:9001/api/v1/download-shared-object/aHR0cDovL2xvY2FsaG9zdDo5MDAwL2h1YW5iYW8vbWluaWFwcC9pbnZhdGUucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUQxODY1RVA2NEczMEdEUUhDVTglMkYyMDI1MDIxOCUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMThUMDcyMDI0WiZYLUFtei1FeHBpcmVzPTQzMTk5JlgtQW16LVNlY3VyaXR5LVRva2VuPWV5SmhiR2NpT2lKSVV6VXhNaUlzSW5SNWNDSTZJa3BYVkNKOS5leUpoWTJObGMzTkxaWGtpT2lKQlJERTROalZGVURZMFJ6TXdSMFJSU0VOVk9DSXNJbVY0Y0NJNk1UY3pPVGt3TmpJME55d2ljR0Z5Wlc1MElqb2lZV1J0YVc0aWZRLmp6djBhdEY5QVBYXzVjYWg4c18yeXhVV3oxek9BekFzSVdzemVrUmZwcXlHd0RPWkptazlUSGJRUnBDdVNmLVMyU0otWTI1cldUd2hpNUlrY0xBSThRJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZ2ZXJzaW9uSWQ9bnVsbCZYLUFtei1TaWduYXR1cmU9MjcxZTkzOTE1MDkwYzUzYmRjYTg0MjQ1MTJhYjk3ZWQxZWMyN2QzM2MwM2U3NGUwYmRhNTBmYjQyNWI0N2MyOQ' } @@ -32,7 +32,7 @@ export default { onShareTimeline() { return { title: '邀请企业入驻', // 标题 - path: `/sub/invite/index?inviteId=${this.$store.getters.userId}`, + path: `/pages/login?inviteId=${this.$store.getters.userId}`, imageUrl: 'http://82.156.141.150:9001/api/v1/download-shared-object/aHR0cDovL2xvY2FsaG9zdDo5MDAwL2h1YW5iYW8vbWluaWFwcC9pbnZhdGUucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUQxODY1RVA2NEczMEdEUUhDVTglMkYyMDI1MDIxOCUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMThUMDcyMDI0WiZYLUFtei1FeHBpcmVzPTQzMTk5JlgtQW16LVNlY3VyaXR5LVRva2VuPWV5SmhiR2NpT2lKSVV6VXhNaUlzSW5SNWNDSTZJa3BYVkNKOS5leUpoWTJObGMzTkxaWGtpT2lKQlJERTROalZGVURZMFJ6TXdSMFJSU0VOVk9DSXNJbVY0Y0NJNk1UY3pPVGt3TmpJME55d2ljR0Z5Wlc1MElqb2lZV1J0YVc0aWZRLmp6djBhdEY5QVBYXzVjYWg4c18yeXhVV3oxek9BekFzSVdzemVrUmZwcXlHd0RPWkptazlUSGJRUnBDdVNmLVMyU0otWTI1cldUd2hpNUlrY0xBSThRJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZ2ZXJzaW9uSWQ9bnVsbCZYLUFtei1TaWduYXR1cmU9MjcxZTkzOTE1MDkwYzUzYmRjYTg0MjQ1MTJhYjk3ZWQxZWMyN2QzM2MwM2U3NGUwYmRhNTBmYjQyNWI0N2MyOQ' } diff --git a/utils/permission.js b/utils/permission.js index 68ee732..cb152e3 100644 --- a/utils/permission.js +++ b/utils/permission.js @@ -36,6 +36,9 @@ export function checkRole(value) { console.log(roles); const permissionRoles = value const super_admin = "admin" + if (!roles) { + return false + } const hasRole = roles.some(role => { return super_admin === role || permissionRoles.includes(role) })