From 55cb4e492f782126e941b80c53c496159d8eb3c0 Mon Sep 17 00:00:00 2001
From: wlzboy <66905212@qq.com>
Date: 星期五, 06 三月 2026 16:59:31 +0800
Subject: [PATCH] feat:同步用户时,增加 status delflag状态同步
---
app/App.vue | 167 ++++++++++++++++++++++++++++++++++++++++++++-----------
1 files changed, 132 insertions(+), 35 deletions(-)
diff --git a/app/App.vue b/app/App.vue
index dd3a43f..d5b65a7 100644
--- a/app/App.vue
+++ b/app/App.vue
@@ -5,6 +5,7 @@
import { getUnreadCount } from '@/api/message'
import storage from '@/utils/storage'
import { redirectToLoginByEnvironment } from '@/utils/wechat'
+ import { getAppFeatures } from '@/api/appConfig'
export default {
data() {
@@ -14,6 +15,7 @@
}
},
onLaunch: function(options) {
+ console.log('App onLaunch, options:', options);
this.lastToken = getToken()
this.initApp(options)
@@ -27,7 +29,9 @@
if (token) {
this.lastToken = token
this.updateUnreadMessageBadge()
- this.startMessagePolling()
+ // this.startMessagePolling()
+ // 鍔犺浇鏈嶅姟鍣ㄩ厤缃�
+ this.loadServerConfig()
}
})
@@ -37,7 +41,11 @@
this.stopMessagePolling()
this.lastToken = null
// 娓呴櫎娑堟伅寰芥爣
- uni.removeTabBarBadge({ index: 3 })
+ try {
+ uni.removeTabBarBadge({ index: 3 })
+ } catch (e) {
+ console.error('娓呴櫎娑堟伅寰芥爣澶辫触:', e)
+ }
})
},
onShow: function() {
@@ -63,7 +71,7 @@
this.updateUnreadMessageBadge()
// 閲嶆柊鍚姩杞锛堝鏋滀箣鍓嶅凡鍋滄锛�
if (!this.messagePollingTimer) {
- this.startMessagePolling()
+ // this.startMessagePolling()
}
}
},
@@ -74,35 +82,108 @@
methods: {
// 鍒濆鍖栧簲鐢�
initApp(options) {
- // 鍒濆鍖栧簲鐢ㄩ厤缃�
- this.initConfig()
- // 妫�鏌ョ敤鎴风櫥褰曠姸鎬佸苟鑷姩璺宠浆鍒板悎閫傜殑鐧诲綍椤甸潰
- this.checkLoginAndRedirect(options)
+ try {
+ // 鍒濆鍖栧簲鐢ㄩ厤缃�
+ this.initConfig()
+ // 妫�鏌ョ敤鎴风櫥褰曠姸鎬佸苟鑷姩璺宠浆鍒板悎閫傜殑鐧诲綍椤甸潰
+ this.checkLoginAndRedirect(options)
+ } catch (e) {
+ console.error('鍒濆鍖栧簲鐢ㄥけ璐�:', e)
+ }
// 娉ㄦ剰锛氫笉鍦ㄥ簲鐢ㄥ惎鍔ㄦ椂鑷姩鍚姩杞
// 鍙湁鍦ㄧ敤鎴蜂富鍔ㄧ櫥褰曟垚鍔熷悗鎵嶅惎鍔紙閫氳繃 user-login 浜嬩欢瑙﹀彂锛�
},
+
+ // 鍒濆鍖栭厤缃細鍚堝苟鏈湴閰嶇疆鍜屾湇鍔″櫒閰嶇疆
initConfig() {
+ // 鍏堜娇鐢ㄦ湰鍦伴粯璁ら厤缃�
this.globalData.config = config
+
+ // 濡傛灉鐢ㄦ埛宸茬櫥褰曪紝灏濊瘯鍔犺浇鏈嶅姟鍣ㄩ厤缃�
+ if (getToken()) {
+ this.loadServerConfig()
+ } else {
+ console.log('鐢ㄦ埛鏈櫥褰曪紝浣跨敤鏈湴榛樿閰嶇疆')
+ }
+ },
+
+ // 浠庢湇鍔″櫒鍔犺浇閰嶇疆
+ loadServerConfig() {
+ getAppFeatures().then(response => {
+ console.log('鍔犺浇鏈嶅姟鍣ㄩ厤缃垚鍔�:', response.data)
+ // 鍚堝苟閰嶇疆锛氭湇鍔″櫒閰嶇疆瑕嗙洊鏈湴閰嶇疆
+ if (response.data) {
+ this.globalData.config.features = Object.assign({},
+ this.globalData.config.features || {},
+ response.data
+ )
+ // 鏇存柊鍏ㄥ眬config瀵硅薄锛岀‘淇濆叾浠栧湴鏂逛篃鑳借幏鍙栧埌鏈�鏂伴厤缃�
+ config.features = this.globalData.config.features
+ }
+ }).catch(error => {
+ console.error('鍔犺浇鏈嶅姟鍣ㄩ厤缃け璐�:', error)
+ console.log('浣跨敤鏈湴榛樿閰嶇疆')
+ })
},
// 妫�鏌ョ櫥褰曠姸鎬佸苟鑷姩璺宠浆鍒板悎閫傜殑鐧诲綍椤甸潰
checkLoginAndRedirect(options) {
- if (!getToken()) {
- // 浣跨敤宸ュ叿绫绘牴鎹幆澧冭嚜鍔ㄨ烦杞埌鍚堥�傜殑鐧诲綍椤甸潰
- redirectToLoginByEnvironment(options, this.$tab);
+ try {
+ if (!getToken()) {
+ console.log('鐢ㄦ埛鏈櫥褰曪紝鍑嗗璺宠浆鍒扮櫥褰曢〉闈�')
+ // 淇濆瓨鐩爣椤甸潰鐢ㄤ簬鐧诲綍鍚庤烦杞�
+ if (options && options.path &&
+ options.path !== 'pages/login' &&
+ options.path !== 'pages/qylogin') {
+ // 鏋勯�犲畬鏁寸殑璺緞鍜屾煡璇㈠弬鏁�
+ let fullPath = '/' + options.path;
+ if (options.query) {
+ const queryString = Object.keys(options.query).map(key =>
+ `${key}=${encodeURIComponent(options.query[key])}`).join('&');
+ if (queryString) {
+ fullPath += '?' + queryString;
+ }
+ }
+
+ // 淇濆瓨鐩爣URL鍒版湰鍦板瓨鍌�
+ try {
+ uni.setStorageSync('targetUrl', fullPath);
+ } catch (e) {
+ console.error('淇濆瓨鐩爣URL澶辫触:', e);
+ }
+ }
+
+ // 浣跨敤宸ュ叿绫绘牴鎹幆澧冭嚜鍔ㄨ烦杞埌鍚堥�傜殑鐧诲綍椤甸潰
+ redirectToLoginByEnvironment(options, this.$tab);
+ } else {
+ console.log('鐢ㄦ埛宸茬櫥褰曪紝鏃犻渶璺宠浆')
+ }
+ } catch (e) {
+ console.error('妫�鏌ョ櫥褰曠姸鎬佸苟璺宠浆澶辫触:', e)
+ // fallback鍒版櫘閫氱櫥褰曢〉闈�
+ try {
+ this.$tab.reLaunch('/pages/login');
+ } catch (fallbackError) {
+ console.error('fallback璺宠浆涔熷け璐ヤ簡:', fallbackError);
+ }
}
},
// 鍒ゆ柇褰撳墠鏄惁鍦ㄧ櫥褰曢〉闈�
isLoginPage() {
- const pages = getCurrentPages()
- if (pages.length === 0) {
+ try {
+ const pages = getCurrentPages()
+ if (pages.length === 0) {
+ return false
+ }
+ const currentPage = pages[pages.length - 1]
+ const route = currentPage.route || ''
+ // 鍒ゆ柇鏄惁涓虹櫥褰曠浉鍏抽〉闈�
+ return route.includes('login') || route.includes('register')
+ } catch (e) {
+ console.error('鍒ゆ柇鏄惁涓虹櫥褰曢〉闈㈠け璐�:', e)
return false
}
- const currentPage = pages[pages.length - 1]
- const route = currentPage.route || ''
- // 鍒ゆ柇鏄惁涓虹櫥褰曠浉鍏抽〉闈�
- return route.includes('login') || route.includes('register')
},
// 鏇存柊鏈娑堟伅寰芥爣
@@ -119,15 +200,23 @@
if (count > 0) {
// 璁剧疆寰芥爣
- uni.setTabBarBadge({
- index: 3, // 娑堟伅椤甸潰鍦╰abBar涓殑绱㈠紩浣嶇疆锛�0寮�濮嬶級
- text: count > 99 ? '99+' : count.toString()
- })
+ try {
+ uni.setTabBarBadge({
+ index: 3, // 娑堟伅椤甸潰鍦╰abBar涓殑绱㈠紩浣嶇疆锛�0寮�濮嬶級
+ text: count > 99 ? '99+' : count.toString()
+ })
+ } catch (e) {
+ console.error('璁剧疆娑堟伅寰芥爣澶辫触:', e)
+ }
} else {
// 绉婚櫎寰芥爣
- uni.removeTabBarBadge({
- index: 3
- })
+ try {
+ uni.removeTabBarBadge({
+ index: 3
+ })
+ } catch (e) {
+ console.error('绉婚櫎娑堟伅寰芥爣澶辫触:', e)
+ }
}
}).catch(error => {
console.error('鑾峰彇鏈娑堟伅鏁伴噺澶辫触:', error)
@@ -136,22 +225,30 @@
// 鍚姩娑堟伅杞
startMessagePolling() {
- // 姣�30绉掕疆璇竴娆�
- this.messagePollingTimer = setInterval(() => {
- if (getToken()) {
- this.updateUnreadMessageBadge()
- } else {
- // 濡傛灉鐢ㄦ埛宸茬櫥鍑猴紝鍋滄杞
- this.stopMessagePolling()
- }
- }, 30000) // 30绉�
+ try {
+ // 姣�30绉掕疆璇竴娆�
+ this.messagePollingTimer = setInterval(() => {
+ if (getToken()) {
+ this.updateUnreadMessageBadge()
+ } else {
+ // 濡傛灉鐢ㄦ埛宸茬櫥鍑猴紝鍋滄杞
+ this.stopMessagePolling()
+ }
+ }, 30000) // 30绉�
+ } catch (e) {
+ console.error('鍚姩娑堟伅杞澶辫触:', e)
+ }
},
// 鍋滄娑堟伅杞
stopMessagePolling() {
- if (this.messagePollingTimer) {
- clearInterval(this.messagePollingTimer)
- this.messagePollingTimer = null
+ try {
+ if (this.messagePollingTimer) {
+ clearInterval(this.messagePollingTimer)
+ this.messagePollingTimer = null
+ }
+ } catch (e) {
+ console.error('鍋滄娑堟伅杞澶辫触:', e)
}
},
--
Gitblit v1.9.1