|
|
@@ -2,6 +2,7 @@ import { API_LOCAL_PUSHES } from "@/services/http/api";
|
|
|
import { request } from "@/services/http/request";
|
|
|
import { recordCheck } from "@/services/trackTimeDuration";
|
|
|
import trackTimeService, { machine } from "@/store/trackTimeMachine"
|
|
|
+import Taro from "@tarojs/taro";
|
|
|
import dayjs from 'dayjs'
|
|
|
|
|
|
let PushNotification, Importance;
|
|
|
@@ -94,6 +95,15 @@ export const endSleep = (start_time: number) => {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+export const uploadLocalPushInfo = (params) => {
|
|
|
+ request({
|
|
|
+ url: API_LOCAL_PUSHES, method: 'POST', data: {
|
|
|
+ id: params.messageId,
|
|
|
+ result: 'SUCCESS'
|
|
|
+ }
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
export const getLocalPush = () => {
|
|
|
request({
|
|
|
url: API_LOCAL_PUSHES, method: 'GET', data: {}
|
|
|
@@ -127,37 +137,85 @@ export const getLocalPush = () => {
|
|
|
PushNotification.cancelAllLocalNotifications()
|
|
|
|
|
|
messages.map(item => {
|
|
|
- if (item.mode == 'ONCE') {
|
|
|
- PushNotification.localNotificationSchedule({
|
|
|
- //... You can use all the options from localNotifications
|
|
|
- title: item.title,
|
|
|
- message: item.content + ' ', // (required)
|
|
|
- date: new Date(item.once), // in 60 secs
|
|
|
- allowWhileIdle: true, // (optional) set notification to work while on doze, default: false
|
|
|
- messageId: item.id,
|
|
|
- // repeatType:'minute',
|
|
|
- /* Android Only Properties */
|
|
|
+ if (Taro.getSystemInfoSync().platform == 'ios') {
|
|
|
+ if (item.mode == 'ONCE') {
|
|
|
+ PushNotification.localNotificationSchedule({
|
|
|
+ //... You can use all the options from localNotifications
|
|
|
+ channelId: item.id,
|
|
|
+ title: item.title,
|
|
|
+ message: item.content + ' ', // (required)
|
|
|
+ date: new Date(item.once), // in 60 secs
|
|
|
+ allowWhileIdle: true, // (optional) set notification to work while on doze, default: false
|
|
|
+ messageId: item.id,
|
|
|
+ // repeatType:'minute',
|
|
|
+ /* Android Only Properties */
|
|
|
|
|
|
- })
|
|
|
+ })
|
|
|
+ }
|
|
|
+ else if (item.mode == 'RECURRING') {
|
|
|
+ const { time, repeat_type } = item.recurring;
|
|
|
+ const date = dayjs().format('YYYY-MM-DD')
|
|
|
+ PushNotification.localNotificationSchedule({
|
|
|
+ //... You can use all the options from localNotifications
|
|
|
+ channelId: item.id,
|
|
|
+ title: item.title,
|
|
|
+ message: item.content + ' ', // (required)
|
|
|
+ date: new Date(date + 'T' + time), // in 60 secs
|
|
|
+ allowWhileIdle: true, // (optional) set notification to work while on doze, default: false
|
|
|
+ messageId: item.id,
|
|
|
+ repeatType: repeat_type,
|
|
|
+ // repeatType:'minute',
|
|
|
+ /* Android Only Properties */
|
|
|
+
|
|
|
+ })
|
|
|
+ }
|
|
|
}
|
|
|
- else if (item.mode == 'RECURRING') {
|
|
|
- const { time, repeat_type } = item.recurring;
|
|
|
- const date = dayjs().format('YYYY-MM-DD')
|
|
|
- PushNotification.localNotificationSchedule({
|
|
|
- //... You can use all the options from localNotifications
|
|
|
- title: item.title,
|
|
|
- message: item.content + ' ', // (required)
|
|
|
- date: new Date(date + 'T' + time), // in 60 secs
|
|
|
- allowWhileIdle: true, // (optional) set notification to work while on doze, default: false
|
|
|
- messageId: item.id,
|
|
|
- repeatType: repeat_type,
|
|
|
- // repeatType:'minute',
|
|
|
- /* Android Only Properties */
|
|
|
+ else {
|
|
|
+ PushNotification.createChannel({
|
|
|
+ channelId: item.id, // (required)
|
|
|
+ channelName: "My channel", // (required)
|
|
|
+ channelDescription: "A channel to categorise your notifications", // (optional) default: undefined.
|
|
|
+ playSound: true, // (optional) default: true
|
|
|
+ soundName: "default", // (optional) See `soundName` parameter of `localNotification` function
|
|
|
+ importance: Importance.HIGH, // (optional) default: Importance.HIGH. Int value of the Android notification importance
|
|
|
+ vibrate: true, // (optional) default: true. Creates the default vibration pattern if true.
|
|
|
+ }, (created) => {
|
|
|
+ if (item.mode == 'ONCE') {
|
|
|
+ PushNotification.localNotificationSchedule({
|
|
|
+ //... You can use all the options from localNotifications
|
|
|
+ channelId: item.id,
|
|
|
+ title: item.title,
|
|
|
+ message: item.content + ' ', // (required)
|
|
|
+ date: new Date(item.once), // in 60 secs
|
|
|
+ allowWhileIdle: true, // (optional) set notification to work while on doze, default: false
|
|
|
+ messageId: item.id,
|
|
|
+ // repeatType:'minute',
|
|
|
+ /* Android Only Properties */
|
|
|
|
|
|
+ })
|
|
|
+ }
|
|
|
+ else if (item.mode == 'RECURRING') {
|
|
|
+ const { time, repeat_type } = item.recurring;
|
|
|
+ const date = dayjs().format('YYYY-MM-DD')
|
|
|
+ PushNotification.localNotificationSchedule({
|
|
|
+ //... You can use all the options from localNotifications
|
|
|
+ channelId: item.id,
|
|
|
+ title: item.title,
|
|
|
+ message: item.content + ' ', // (required)
|
|
|
+ date: new Date(date + 'T' + time), // in 60 secs
|
|
|
+ allowWhileIdle: true, // (optional) set notification to work while on doze, default: false
|
|
|
+ messageId: item.id,
|
|
|
+ repeatType: repeat_type,
|
|
|
+ // repeatType:'minute',
|
|
|
+ /* Android Only Properties */
|
|
|
+
|
|
|
+ })
|
|
|
+ }
|
|
|
})
|
|
|
}
|
|
|
|
|
|
})
|
|
|
+
|
|
|
console.log('notificatin push set', messages)
|
|
|
})
|
|
|
}
|