提交 d6230bb1 编写于 作者: fxy060608's avatar fxy060608

feat(h5): Compatible with externals (webpack)

上级 a79e485c
......@@ -7,50 +7,60 @@ import Vue from 'vue'
// import 'uni-platform/view/index.css'
import initVue from 'uni-core/vue'
global.UniViewJSBridge = {
class UniApp {
constructor () {
this._init()
}
_init () {
global.UniViewJSBridge = {
subscribe: UniViewJSBridge.subscribe,
publishHandler: UniViewJSBridge.publishHandler,
subscribeHandler: UniViewJSBridge.subscribeHandler
}
}
global.UniServiceJSBridge = {
global.UniServiceJSBridge = {
subscribe: UniServiceJSBridge.subscribe,
publishHandler: UniServiceJSBridge.publishHandler,
subscribeHandler: UniServiceJSBridge.subscribeHandler
}
}
const {
const {
default: uni,
getApp,
getCurrentPages
} = require('uni-platform/service/index')
} = require('uni-platform/service/index')
// 与微信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 => {
// 与微信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
})
})
})
global.uni = uni
global.uni = uni
global.wx = global.uni
global.wx = global.uni
global.getApp = getApp
global.getCurrentPages = getCurrentPages
global.getApp = getApp
global.getCurrentPages = getCurrentPages
Vue.use(require('uni-service/plugins').default, {
Vue.use(require('uni-service/plugins').default, {
routes: __uniRoutes
})
})
Vue.use(require('uni-view/plugins').default, {
Vue.use(require('uni-view/plugins').default, {
routes: __uniRoutes
})
})
initVue(Vue)
require('uni-platform/components')
require('uni-components')
initVue(Vue)
require('uni-platform/components')
require('uni-components')
}
}
global.UniApp = UniApp
global.__uniConfig && new UniApp()
......@@ -411,5 +411,6 @@ global.__uniConfig.qqMapKey = ${JSON.stringify(qqMapKey)};
global.__uniConfig.nvue = ${JSON.stringify({ 'flex-direction': getFlexDirection(manifestJson['app-plus']) })}
${genRegisterPageVueComponentsCode(pageComponents)}
global.__uniRoutes=[${genPageRoutes(pageComponents).concat(genSystemRoutes()).join(',')}]
global.UniApp && new global.UniApp();
`
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册