fix bugs
This commit is contained in:
@@ -1,12 +1,15 @@
|
||||
<script>
|
||||
import config from './common/config.js'
|
||||
import {writeDebugLog,getSettingByKey,getSettings,verifyToken,logout} from './api/commonApi.js'
|
||||
import {writeDebugLog,writePublicDebugLog,getSettingByKey,getSettings,verifyToken,logout} from './api/commonApi.js'
|
||||
import { getCfgSettingByKey } from './api/configApi.js'
|
||||
import store from './store/index.js'
|
||||
import FixedCoordinateConverter from './common/fixedCoordinateConverter.js'
|
||||
import { getDeviceToken, refreshDeviceTokenAsync, refreshDeviceTokenAndFetch } from './common/pushDeviceToken.js';
|
||||
import { listenPushNotification, syncPendingPushNotifications } from './common/pushNotification.js';
|
||||
import {refreshToken} from './api/commonApi.js'
|
||||
import dayjs from './uni_modules/uview-ui/libs/util/dayjs.js';
|
||||
import { decryptCfgSettingValue } from './common/cfgSettingCrypto.js';
|
||||
import {saveDeviceToken} from './api/notification.js';
|
||||
// #ifdef APP-PLUS
|
||||
var networkModule = uni.requireNativePlugin("NetworkUtils-NetworkUtilsModule")
|
||||
// #endif
|
||||
@@ -59,6 +62,16 @@
|
||||
});*/
|
||||
// #ifdef APP-PLUS
|
||||
this.getSettingByKey('MACAU_STRING');
|
||||
|
||||
let userData = uni.getStorageSync("userData");
|
||||
if(userData != null && userData != undefined && userData != '' && userData.userId !=null){
|
||||
this.syncPushDeviceTokenFromNative();
|
||||
// 同步点击通知产生的 pending push,并在有 ConfirmNo 时跳转到 Limo Detail
|
||||
setTimeout(() => {
|
||||
this.syncPendingPushNotificationsFromNative();
|
||||
this.tryConsumePendingPushNavigation();
|
||||
}, 300);
|
||||
}
|
||||
// #endif
|
||||
},
|
||||
onHide: function() {
|
||||
@@ -257,8 +270,34 @@
|
||||
this.navTo('/pages/login/login',2,false);
|
||||
}
|
||||
},
|
||||
tryConsumePendingPushNavigation() {
|
||||
const pendingUrl = uni.getStorageSync('pendingPushNavigation');
|
||||
if (!pendingUrl) {
|
||||
return false;
|
||||
}
|
||||
if (!this.isUserLoggedIn()) {
|
||||
return false;
|
||||
}
|
||||
uni.removeStorageSync('pendingPushNavigation');
|
||||
console.log('[Push] consume pending navigation:', pendingUrl);
|
||||
this.navTo(pendingUrl, 0, false);
|
||||
return true;
|
||||
},
|
||||
async syncPendingPushNotificationsFromNative() {
|
||||
console.log('[Push] syncPendingPushNotificationsFromNative')
|
||||
await syncPendingPushNotifications((payload, meta) => {
|
||||
this.handlePushNotificationMessage(payload, {
|
||||
...meta,
|
||||
showToast: meta?.fromPending ? false : meta?.showToast
|
||||
})
|
||||
}, { showToast: false })
|
||||
await this.flushPendingPushSaveQueue()
|
||||
},
|
||||
//判断是否有Permission
|
||||
redirectByPermission(userData,needRedirect){
|
||||
if (this.tryConsumePendingPushNavigation()) {
|
||||
return;
|
||||
}
|
||||
if(userData!==null && userData!==undefined){
|
||||
if(userData.canViewDashboard){
|
||||
this.navTo('/pages/dashboard/dashboard',1,false);
|
||||
@@ -271,8 +310,71 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
/** 从原生读取当前缓存的 APNs DeviceToken,并写入本地 Storage(供业务上报) */
|
||||
syncPushDeviceTokenFromNative() {
|
||||
getDeviceToken({})
|
||||
.then(async (ret) => {
|
||||
console.log('[APNs] getDeviceToken', ret.status, ret.updatedAt);
|
||||
const deviceToken = ret.deviceToken ? String(ret.deviceToken).trim() : '';
|
||||
let useLanguage = 0;
|
||||
//获取AppSetting,后端可以判断发中文还是发英文 英文:0 中文:1 默认为0
|
||||
if(uni.getLocale()!==null && uni.getLocale()!==undefined){
|
||||
useLanguage = uni.getLocale()=='en'? 0 : 1;
|
||||
}
|
||||
if (deviceToken) {
|
||||
const userId = this.getCachedUserId();
|
||||
console.log('[APNs] saveDeviceToken params', {
|
||||
userId,
|
||||
deviceToken,
|
||||
rawUserData: uni.getStorageSync('userData'),
|
||||
rawRet: ret,
|
||||
useLanguage
|
||||
});
|
||||
this.writeLog(
|
||||
userId,
|
||||
'syncPushDeviceTokenFromNative',
|
||||
'',
|
||||
'[APP][App.vue][getDevice Token][Success]' + deviceToken,
|
||||
'',
|
||||
'',
|
||||
1,
|
||||
false
|
||||
);
|
||||
uni.setStorageSync('apnsDeviceToken', deviceToken);
|
||||
uni.setStorageSync('apnsDeviceTokenUpdatedAt', ret.updatedAt || 0);
|
||||
try {
|
||||
const res = await saveDeviceToken({ userId, deviceToken, useLanguage});
|
||||
console.log('[APNs] saveDeviceToken success', res);
|
||||
} catch (saveErr) {
|
||||
console.error('[APNs] saveDeviceToken failed', saveErr);
|
||||
}
|
||||
}
|
||||
})
|
||||
.catch((e) => {
|
||||
console.warn('[APNs] getDeviceToken fail', e);
|
||||
uni.showToast({
|
||||
title: 'error = ' + e,
|
||||
icon: 'none'
|
||||
});
|
||||
const userId = this.getCachedUserId();
|
||||
this.writeLog(
|
||||
userId,
|
||||
'syncPushDeviceTokenFromNative',
|
||||
'',
|
||||
'[APP][App.vue][getDevice Token][Fail] Error Message :' + e,
|
||||
'',
|
||||
'',
|
||||
1,
|
||||
false
|
||||
);
|
||||
});
|
||||
},
|
||||
//根据Permission显示Tabbar
|
||||
showTabbarByPermission(userData){
|
||||
uni.setTabBarItem({
|
||||
index: 3,
|
||||
visible: !!userData && userData.canViewCalendar === true
|
||||
});
|
||||
if(userData!==null && userData!==undefined){
|
||||
console.log('Setting Tabbar');
|
||||
if(userData.canViewDashboard){
|
||||
@@ -483,7 +585,8 @@
|
||||
//console.log(obj);
|
||||
|
||||
try{
|
||||
const response = await writeDebugLog(obj);
|
||||
const token = uni.getStorageSync('token');
|
||||
const response = token ? await writeDebugLog(obj) : await writePublicDebugLog(obj);
|
||||
}
|
||||
catch(e){
|
||||
console.error(e.errMsg);
|
||||
@@ -513,6 +616,7 @@
|
||||
index:2,
|
||||
visible:false
|
||||
});
|
||||
uni.setTabBarItem({ index: 3, visible: false });
|
||||
if(siteData.mockSSO==false&&!siteData.internalTag){
|
||||
//this.logoutWithADFSApp()
|
||||
uni.redirectTo({
|
||||
@@ -546,6 +650,19 @@
|
||||
uni.hideLoading();
|
||||
}
|
||||
},
|
||||
getCachedUserId() {
|
||||
const userData = uni.getStorageSync('userData');
|
||||
if (
|
||||
userData != null &&
|
||||
userData !== '' &&
|
||||
userData != undefined &&
|
||||
userData.userId != null &&
|
||||
userData.userId !== ''
|
||||
) {
|
||||
return userData.userId;
|
||||
}
|
||||
return '';
|
||||
},
|
||||
async navTo(url,type,auth){
|
||||
let token = uni.getStorageSync('token');
|
||||
if(token){
|
||||
|
||||
Reference in New Issue
Block a user