wangfukang 2 weeks ago
parent
commit
619273e1eb
  1. 64
      App.vue
  2. 50
      pages/login/login.vue

64
App.vue

@ -124,55 +124,58 @@
plus.runtime.setBadgeNumber(0);
let notificationEventType = result.notificationEventType
let woopId = result.extras && result.extras.dataType === 'woop' && result.extras.value;
const content = result.content || ''
//
if (result.notificationEventType === 'notificationOpened') {
if (this.NB.isAndroidOrIOS() == 'iOS') {
this.handlePushClick(result.ios.inAppExtras);
} else {
this.handlePushClick(result.android.inAppExtras);
const inAppExtras = this.getPushInAppExtras(result);
if (inAppExtras) {
this.handlePushClick(inAppExtras);
}
}
//
if (result.notificationEventType == 'notificationArrived') {
if (result.content.includes('订单出餐已超时')) {
if (content.includes('订单出餐已超时')) {
this.onPlayAudio(2)
} else if (result.content.includes('您有一笔配送订单无人接单')) {
} else if (content.includes('您有一笔配送订单无人接单')) {
this.onPlayAudio(5)
} else if (result.content.includes('您有一笔新的指定配送单,请及时接单')) {
} else if (content.includes('您有一笔新的指定配送单,请及时接单')) {
this.onPlayAudio(10)
} else if (result.content.includes('您有一笔配送中订单用户申请退款')) {
} else if (content.includes('您有一笔配送中订单用户申请退款')) {
this.onPlayAudio(11)
} else if (result.content.includes('抢单大厅来新单啦')) {
} else if (content.includes('抢单大厅来新单啦')) {
this.onPlayAudio(12)
} else if (result.content.includes('您有中转配送订单超时未送达中转点')) {
} else if (content.includes('您有中转配送订单超时未送达中转点')) {
this.onPlayAudio(7)
} else if (result.content.includes('您有一笔订单用户申请售后,请尽快处理')) {
} else if (content.includes('您有一笔订单用户申请售后,请尽快处理')) {
this.onPlayAudio(8)
} else if (result.content.includes('您有一个后台指派单,请及时查看')) {
} else if (content.includes('您有一个后台指派单,请及时查看')) {
this.onPlayAudio(13)
} else if (result.content.includes('您有一笔订单被改派')) {
} else if (content.includes('您有一笔订单被改派')) {
this.onPlayAudio(14)
} else {
if (result.content.includes('您有一笔新的订单')) {
if (content.includes('您有一笔新的订单')) {
this.onPlayAudio(4)
} else if (result.content.includes('您有一笔新的到店订单')) {
} else if (content.includes('您有一笔新的到店订单')) {
this.onPlayAudio(3)
} else if (result.content.includes('您有一笔订单申请退款')) {
} else if (content.includes('您有一笔订单申请退款')) {
this.onPlayAudio(1)
} else if (result.content.includes('您有一笔商家自配送订单,请立即处理')) {
} else if (content.includes('您有一笔商家自配送订单,请立即处理')) {
this.onPlayAudio(6)
} else if (result.content.includes('您有一笔预约订单可以出餐啦')) {
} else if (content.includes('您有一笔预约订单可以出餐啦')) {
this.onPlayAudio(9)
}
const printData = this.parsePushExtras(this.getPushInAppExtras(result));
if (printData && printData.order_id) {
//
this.globalData.printData.push(JSON.parse(result.android.inAppExtras))
this.globalData.printData.push(printData)
//
if (!this.globalData.isPrinting) {
this.processPrintQueue()
}
}
}
}
});
jpushModule.isPushStopped(res => {
@ -232,6 +235,22 @@
},
},
methods: {
getPushInAppExtras(result) {
if (!result) return '';
if (this.NB.isAndroidOrIOS() == 'iOS') {
return result.ios && result.ios.inAppExtras ? result.ios.inAppExtras : result.extras;
}
return result.android && result.android.inAppExtras ? result.android.inAppExtras : result.extras;
},
parsePushExtras(extras) {
if (!extras) return null;
if (typeof extras === 'object') return extras;
try {
return JSON.parse(extras);
} catch (e) {
return null;
}
},
autoConnectPrinter() {
if (!uni.getStorageSync('bluetoothDeviceId')) return;
const bluetooth = new Bluetooth({
@ -345,10 +364,17 @@
if (registerID) {
this.globalData.registrationID = registerID
uni.setStorageSync("registerID", registerID)
this.reportClientId(registerID)
}
// uni.setStorageSync("signPerson", result.signPerson)
})
},
reportClientId(clientId) {
if (!clientId || !uni.getStorageSync('hiver_token')) return;
this.NB.sendRequest('/auth/updateClientId', {
clientId: clientId
}, false, 'POST', 'application/x-www-form-urlencoded').catch(() => {});
},
getNotificationEnabled() {
if (uni.getSystemInfoSync().platform == "ios") {
jpushModule.requestNotificationAuthorization((result) => {

50
pages/login/login.vue

@ -177,8 +177,15 @@
if (!clientId) return;
app.globalData.registrationID = clientId;
uni.setStorageSync('registerID', clientId);
this.reportClientId(clientId);
},
getRegistrationID() {
reportClientId(clientId) {
if (!clientId || !uni.getStorageSync('hiver_token')) return;
this.NB.sendRequest('/auth/updateClientId', {
clientId: clientId
}, false, 'POST', 'application/x-www-form-urlencoded').catch(() => {});
},
getRegistrationID(options = {}) {
const cachedClientId = this.getStoredClientId();
if (cachedClientId) {
return Promise.resolve(cachedClientId);
@ -186,11 +193,30 @@
// #ifdef APP-PLUS
return new Promise(resolve => {
let isResolved = false;
let timer = null;
const finish = clientId => {
if (isResolved) return;
isResolved = true;
if (timer) clearTimeout(timer);
this.saveClientId(clientId);
resolve(clientId || this.getStoredClientId());
};
timer = setTimeout(() => {
finish('');
}, options.timeout || 800);
try {
if (!jpushModule || !jpushModule.getRegistrationID) {
finish('');
return;
}
jpushModule.getRegistrationID(result => {
const clientId = result && (result.registerID || result.registrationID);
this.saveClientId(clientId);
resolve(clientId || '');
finish(clientId || '');
});
} catch (e) {
finish('');
}
});
// #endif
@ -404,7 +430,18 @@
return;
}
uni.setStorageSync('yanzhengma', this.code)
const clientId = await this.getRegistrationID()
uni.showLoading({
title: '加载中...',
mask: true
});
let clientId = ''
try {
clientId = await this.getRegistrationID({
timeout: 800
});
} catch (e) {
clientId = this.getStoredClientId()
}
let url;
let data;
@ -430,10 +467,6 @@
};
}
let that = this;
uni.showLoading({
title: '加载中...',
mask: true
});
that.NB.sendRequest(url, data, false, 'POST', 'application/x-www-form-urlencoded').then(res => {
if (res.code !== 200) {
@ -445,6 +478,7 @@
} else {
// uni.removeStorageSync('code');
if (res.result.accessToken) uni.setStorageSync('hiver_token', res.result.accessToken)
if (clientId) this.reportClientId(clientId)
if (res.result.worker !== undefined) uni.setStorageSync('worker', res.result.worker)
uni.setStorageSync("wayValue", this.wayValue)
uni.setStorageSync("nickname", res.result.user.nickname)

Loading…
Cancel
Save