main.js 2.1 KB
Newer Older
fxy060608's avatar
fxy060608 已提交
1 2 3 4 5 6
/**
 * 1.导出全局对象(UniViewJSBridge,UniServiceJSBridge,uni,getApp,getCurrentPages)
 * 2.引入 Vue 插件(uniVueServicePlugin,uniVueServicePlugin)
 * 3.引入 Vue 组件
 */
import Vue from 'vue'
fxy060608's avatar
fxy060608 已提交
7
// import 'uni-platform/view/index.css'
fxy060608's avatar
init v3  
fxy060608 已提交
8
import initVue from 'uni-core/vue'
fxy060608's avatar
fxy060608 已提交
9

fxy060608's avatar
fxy060608 已提交
10 11 12
global.UniViewJSBridge = {
  subscribe: UniViewJSBridge.subscribe,
  publishHandler: UniViewJSBridge.publishHandler,
fxy060608's avatar
fxy060608 已提交
13 14 15
  subscribeHandler: UniViewJSBridge.subscribeHandler
}

fxy060608's avatar
fxy060608 已提交
16 17 18
global.UniServiceJSBridge = {
  subscribe: UniServiceJSBridge.subscribe,
  publishHandler: UniServiceJSBridge.publishHandler,
fxy060608's avatar
fxy060608 已提交
19 20 21 22 23 24 25
  subscribeHandler: UniServiceJSBridge.subscribeHandler
}

const {
  default: uni,
  getApp,
  getCurrentPages
fxy060608's avatar
fxy060608 已提交
26
} = require('uni-platform/service/index')
fxy060608's avatar
fxy060608 已提交
27

28 29 30 31 32 33 34 35 36 37 38
// 与微信JS-SDK同名的方法
// const sameNameApis = ['setClipboardData', 'getClipboardData', 'onUserCaptureScreen', 'openBluetoothAdapter', 'startBluetoothDevicesDiscovery', 'onBluetoothDeviceFound', 'stopBluetoothDevicesDiscovery', 'onBluetoothAdapterStateChange', 'getConnectedBluetoothDevices', 'getBluetoothDevices', 'getBluetoothAdapterState', 'closeBluetoothAdapter', 'writeBLECharacteristicValue', 'readBLECharacteristicValue', 'onBLEConnectionStateChange', 'onBLECharacteristicValueChange', 'notifyBLECharacteristicValueChange', 'getBLEDeviceServices', 'getBLEDeviceCharacteristics', 'createBLEConnection', 'closeBLEConnection', 'onBeaconServiceChange', 'onBeaconUpdate', 'getBeacons', 'startBeaconDiscovery', 'stopBeaconDiscovery', 'chooseImage', 'previewImage', 'getNetworkType', 'onNetworkStatusChange', 'openLocation', 'getLocation']
// 默认会被iOS企业微信替换的方法
const sameNameApis = ['chooseImage']
sameNameApis.forEach(item => {
  Object.defineProperty(uni, item, {
    writable: false,
    configurable: false
  })
})

fxy060608's avatar
fxy060608 已提交
39
global.uni = uni
40 41

global.wx = global.uni
fxy060608's avatar
fxy060608 已提交
42 43 44 45 46 47 48 49 50 51 52 53

global.getApp = getApp
global.getCurrentPages = getCurrentPages

Vue.use(require('uni-service/plugins').default, {
  routes: __uniRoutes
})

Vue.use(require('uni-view/plugins').default, {
  routes: __uniRoutes
})

fxy060608's avatar
init v3  
fxy060608 已提交
54
initVue(Vue)
55
require('uni-platform/components')
56
require('uni-components')