liujie
2026-09-11 4f6f15b818704079ff2e4e4719b798f48d68a335
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import { request } from '../utils/request'
 
function normalizeMessage(item) {
  const prototypeCopy = {
    ORDER_ASSIGNED: {
      title: '接单提醒',
      content: '您有一个新的讲解订单,请查看'
    },
    ORDER_CANCELLED: {
      title: '取消提醒',
      content: '您有一个讲解订单被取消,请查看'
    },
    AUDIT_APPROVED: {
      title: '系统提醒',
      content: '您的资料审核已通过'
    },
    AUDIT_REJECTED: {
      title: '系统提醒',
      content: '您的资料审核未通过'
    },
    ORDER_REVIEWED: {
      title: '评价提醒',
      content: '您有一条新的订单评价,请查看'
    }
  }[item.type]
 
  return {
    ...item,
    ...(prototypeCopy || {}),
    time: item.time ? item.time.replace('T', ' ') : '',
    url: item.targetUrl || (item.orderId ? `/pages/order-detail/index?id=${item.orderId}` : '')
  }
}
 
function playWebTone() {
  if (typeof window === 'undefined') return false
  const AudioContext = window.AudioContext || window.webkitAudioContext
  if (!AudioContext) return false
  const context = new AudioContext()
  const oscillator = context.createOscillator()
  const gain = context.createGain()
  oscillator.type = 'sine'
  oscillator.frequency.value = 880
  gain.gain.setValueAtTime(0.12, context.currentTime)
  gain.gain.exponentialRampToValueAtTime(0.001, context.currentTime + 0.22)
  oscillator.connect(gain)
  gain.connect(context.destination)
  oscillator.start()
  oscillator.stop(context.currentTime + 0.22)
  return true
}
 
function playNativeTone() {
  if (typeof plus === 'undefined' || !plus.device || !plus.device.beep) return false
  plus.device.beep(1)
  return true
}
 
export function getMessageList() {
  return request({ url: '/guide/notifications' }).then((list) => list.map(normalizeMessage))
}
 
export function getUnreadMessageCount() {
  return getMessageList().then((list) => list.filter((item) => !item.read).length)
}
 
export function markMessageRead(id) {
  return request({ url: `/guide/notifications/${id}/read`, method: 'PUT' })
}
 
export function playNotificationAlert() {
  if (typeof uni !== 'undefined' && uni.vibrateShort) {
    uni.vibrateShort({ type: 'medium' })
  }
  try {
    playNativeTone() || playWebTone()
  } catch (error) {
    return false
  }
  return true
}