open-location-webview.js 1.2 KB
Newer Older
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
import {
  MAP_ID
} from '../constants'

import {
  ANI_SHOW,
  ANI_DURATION
} from '../../constants'

const OPEN_LOCATION_PATH = '_www/__uniappopenlocation.html'

export function openLocation (params) {
  const statusBarStyle = plus.navigator.getStatusBarStyle()
  const webview = plus.webview.create(
    OPEN_LOCATION_PATH,
    MAP_ID, {
      titleNView: {
        autoBackButton: true,
        titleColor: '#ffffff',
        titleText: '',
        titleSize: '17px',
        type: 'transparent'
      },
      popGesture: 'close',
      scrollIndicator: 'none'
    }, {
      __uniapp_type: 'map',
      __uniapp_statusbar_style: statusBarStyle,
      'uni-app': 'none'
    }
  )
  if (statusBarStyle === 'light') {
    plus.navigator.setStatusBarStyle('dark')
    webview.addEventListener('popGesture', ({
      type,
      result
    }) => {
      if (type === 'start') {
        plus.navigator.setStatusBarStyle('light')
      } else if (type === 'end' && !result) {
        plus.navigator.setStatusBarStyle('dark')
      }
    })
  }
  webview.show(ANI_SHOW, ANI_DURATION, () => {
    webview.evalJS(`__openLocation__(${JSON.stringify(params)})`)
  })

  return {
    errMsg: 'openLocation:ok'
  }
}