'f'
mh-two-thousand-and-two
2024-04-12 26f2711ef9461961fb953e2b497bd314ef95e345
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
import createCallbacks from 'uni-helpers/callbacks'
import {
  getCurrentPageVm
} from '../../platform'
import {
  checkInWindows
} from 'uni-helpers/windows'
const createMediaQueryObserverCallbacks = createCallbacks('requestMediaQueryObserver')
 
class ServiceMediaQueryObserver {
  constructor (component, options) {
    this.pageId = component.$page && component.$page.id
    this.component = component._$id || component // app-plus 平台传输_$id
    this.options = options
  }
 
  observe (options, callback) {
    if (typeof callback !== 'function') {
      return
    }
    this.options = options
 
    this.reqId = createMediaQueryObserverCallbacks.push(callback)
 
    UniServiceJSBridge.publishHandler('requestMediaQueryObserver', {
      reqId: this.reqId,
      component: this.component,
      options: this.options
    }, checkInWindows(this.component) ? this.component : this.pageId)
  }
 
  disconnect () {
    UniServiceJSBridge.publishHandler('destroyMediaQueryObserver', {
      reqId: this.reqId
    }, checkInWindows(this.component) ? this.component : this.pageId)
  }
}
 
export function createMediaQueryObserver (context, options) {
  if (!context._isVue) {
    options = context
    context = null
  }
  if (context) {
    return new ServiceMediaQueryObserver(context, options)
  }
  return new ServiceMediaQueryObserver(getCurrentPageVm('createMediaQueryObserver'), options)
}