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

refactor

上级 1ce2f9fc
......@@ -24,7 +24,7 @@ module.exports = function genRequireCode (baseDirname, modules) {
const moduleAbsolutePath = Path.resolve(baseDirname, file).replace(/\\/g, '/')
importCode += genImportCode(moduleName, moduleAbsolutePath)
moduleProps += genPropsCode(moduleAbsolutePath, moduleName)
moduleProps += genPropsCode(file, moduleName)
})
const requireFnCode = (`
(function() {
......
......@@ -319,7 +319,7 @@ const canIUse = [{
required: true
}];
var require_context_module_0_0 = /*#__PURE__*/Object.freeze({
var require_context_module_1_0 = /*#__PURE__*/Object.freeze({
canIUse: canIUse
});
......@@ -335,7 +335,7 @@ const arrayBufferToBase64 = [{
required: true
}];
var require_context_module_0_1 = /*#__PURE__*/Object.freeze({
var require_context_module_1_1 = /*#__PURE__*/Object.freeze({
base64ToArrayBuffer: base64ToArrayBuffer,
arrayBufferToBase64: arrayBufferToBase64
});
......@@ -472,7 +472,7 @@ const drawCanvas = {
}
};
var require_context_module_0_2 = /*#__PURE__*/Object.freeze({
var require_context_module_1_2 = /*#__PURE__*/Object.freeze({
canvasGetImageData: canvasGetImageData,
canvasPutImageData: canvasPutImageData,
canvasToTempFilePath: canvasToTempFilePath,
......@@ -497,7 +497,7 @@ const createCanvasContext = [{
type: Object
}];
var require_context_module_0_3 = /*#__PURE__*/Object.freeze({
var require_context_module_1_3 = /*#__PURE__*/Object.freeze({
createAudioContext: createAudioContext,
createVideoContext: createVideoContext,
createMapContext: createMapContext,
......@@ -516,7 +516,7 @@ const makePhoneCall = {
}
};
var require_context_module_0_4 = /*#__PURE__*/Object.freeze({
var require_context_module_1_4 = /*#__PURE__*/Object.freeze({
makePhoneCall: makePhoneCall
});
......@@ -530,7 +530,7 @@ const openDocument = {
}
};
var require_context_module_0_5 = /*#__PURE__*/Object.freeze({
var require_context_module_1_5 = /*#__PURE__*/Object.freeze({
openDocument: openDocument
});
......@@ -577,7 +577,7 @@ const openLocation = {
}
};
var require_context_module_0_6 = /*#__PURE__*/Object.freeze({
var require_context_module_1_6 = /*#__PURE__*/Object.freeze({
getLocation: getLocation,
openLocation: openLocation
});
......@@ -635,7 +635,7 @@ const chooseImage = {
}
};
var require_context_module_0_7 = /*#__PURE__*/Object.freeze({
var require_context_module_1_7 = /*#__PURE__*/Object.freeze({
chooseImage: chooseImage
});
......@@ -662,7 +662,7 @@ const chooseVideo = {
}
};
var require_context_module_0_8 = /*#__PURE__*/Object.freeze({
var require_context_module_1_8 = /*#__PURE__*/Object.freeze({
chooseVideo: chooseVideo
});
......@@ -737,7 +737,7 @@ const getImageInfo = {
}
};
var require_context_module_0_9 = /*#__PURE__*/Object.freeze({
var require_context_module_1_9 = /*#__PURE__*/Object.freeze({
getImageInfo: getImageInfo
});
......@@ -772,7 +772,7 @@ const previewImage = {
}
};
var require_context_module_0_10 = /*#__PURE__*/Object.freeze({
var require_context_module_1_10 = /*#__PURE__*/Object.freeze({
previewImage: previewImage
});
......@@ -814,7 +814,7 @@ const setNavigationBarTitle = {
}
};
var require_context_module_0_11 = /*#__PURE__*/Object.freeze({
var require_context_module_1_11 = /*#__PURE__*/Object.freeze({
setNavigationBarColor: setNavigationBarColor,
setNavigationBarTitle: setNavigationBarTitle
});
......@@ -832,7 +832,7 @@ const downloadFile = {
}
};
var require_context_module_0_12 = /*#__PURE__*/Object.freeze({
var require_context_module_1_12 = /*#__PURE__*/Object.freeze({
downloadFile: downloadFile
});
......@@ -892,7 +892,7 @@ const request = {
}
};
var require_context_module_0_13 = /*#__PURE__*/Object.freeze({
var require_context_module_1_13 = /*#__PURE__*/Object.freeze({
request: request
});
......@@ -945,7 +945,7 @@ const closeSocket = {
}
};
var require_context_module_0_14 = /*#__PURE__*/Object.freeze({
var require_context_module_1_14 = /*#__PURE__*/Object.freeze({
connectSocket: connectSocket,
sendSocketMessage: sendSocketMessage,
closeSocket: closeSocket
......@@ -981,7 +981,7 @@ const uploadFile = {
}
};
var require_context_module_0_15 = /*#__PURE__*/Object.freeze({
var require_context_module_1_15 = /*#__PURE__*/Object.freeze({
uploadFile: uploadFile
});
......@@ -999,7 +999,7 @@ const pageScrollTo = {
}
};
var require_context_module_0_16 = /*#__PURE__*/Object.freeze({
var require_context_module_1_16 = /*#__PURE__*/Object.freeze({
pageScrollTo: pageScrollTo
});
......@@ -1023,7 +1023,7 @@ const getProvider = {
}
};
var require_context_module_0_17 = /*#__PURE__*/Object.freeze({
var require_context_module_1_17 = /*#__PURE__*/Object.freeze({
getProvider: getProvider
});
......@@ -1140,7 +1140,7 @@ const showActionSheet = {
}
};
var require_context_module_0_18 = /*#__PURE__*/Object.freeze({
var require_context_module_1_18 = /*#__PURE__*/Object.freeze({
showModal: showModal,
showToast: showToast,
showLoading: showLoading,
......@@ -1291,7 +1291,7 @@ const navigateBack = Object.assign({
]
));
var require_context_module_0_19 = /*#__PURE__*/Object.freeze({
var require_context_module_1_19 = /*#__PURE__*/Object.freeze({
redirectTo: redirectTo,
reLaunch: reLaunch,
navigateTo: navigateTo,
......@@ -1318,7 +1318,7 @@ const setStorageSync = [{
required: true
}];
var require_context_module_0_20 = /*#__PURE__*/Object.freeze({
var require_context_module_1_20 = /*#__PURE__*/Object.freeze({
setStorage: setStorage,
setStorageSync: setStorageSync
});
......@@ -1400,7 +1400,7 @@ const setTabBarBadge = {
}
};
var require_context_module_0_21 = /*#__PURE__*/Object.freeze({
var require_context_module_1_21 = /*#__PURE__*/Object.freeze({
setTabBarItem: setTabBarItem,
setTabBarStyle: setTabBarStyle,
hideTabBar: hideTabBar,
......@@ -1415,28 +1415,28 @@ const protocol = Object.create(null);
const modules =
(function() {
var map = {
'/Users/fxy/Documents/GitHub/uni-app-dev/src/core/helpers/protocol/base.js': require_context_module_0_0,
'/Users/fxy/Documents/GitHub/uni-app-dev/src/core/helpers/protocol/base64.js': require_context_module_0_1,
'/Users/fxy/Documents/GitHub/uni-app-dev/src/core/helpers/protocol/canvas.js': require_context_module_0_2,
'/Users/fxy/Documents/GitHub/uni-app-dev/src/core/helpers/protocol/context.js': require_context_module_0_3,
'/Users/fxy/Documents/GitHub/uni-app-dev/src/core/helpers/protocol/device/make-phone-call.js': require_context_module_0_4,
'/Users/fxy/Documents/GitHub/uni-app-dev/src/core/helpers/protocol/file/open-document.js': require_context_module_0_5,
'/Users/fxy/Documents/GitHub/uni-app-dev/src/core/helpers/protocol/location.js': require_context_module_0_6,
'/Users/fxy/Documents/GitHub/uni-app-dev/src/core/helpers/protocol/media/choose-image.js': require_context_module_0_7,
'/Users/fxy/Documents/GitHub/uni-app-dev/src/core/helpers/protocol/media/choose-video.js': require_context_module_0_8,
'/Users/fxy/Documents/GitHub/uni-app-dev/src/core/helpers/protocol/media/get-image-info.js': require_context_module_0_9,
'/Users/fxy/Documents/GitHub/uni-app-dev/src/core/helpers/protocol/media/preview-image.js': require_context_module_0_10,
'/Users/fxy/Documents/GitHub/uni-app-dev/src/core/helpers/protocol/navigation-bar.js': require_context_module_0_11,
'/Users/fxy/Documents/GitHub/uni-app-dev/src/core/helpers/protocol/network/download-file.js': require_context_module_0_12,
'/Users/fxy/Documents/GitHub/uni-app-dev/src/core/helpers/protocol/network/request.js': require_context_module_0_13,
'/Users/fxy/Documents/GitHub/uni-app-dev/src/core/helpers/protocol/network/socket.js': require_context_module_0_14,
'/Users/fxy/Documents/GitHub/uni-app-dev/src/core/helpers/protocol/network/upload-file.js': require_context_module_0_15,
'/Users/fxy/Documents/GitHub/uni-app-dev/src/core/helpers/protocol/page-scroll-to.js': require_context_module_0_16,
'/Users/fxy/Documents/GitHub/uni-app-dev/src/core/helpers/protocol/plugins.js': require_context_module_0_17,
'/Users/fxy/Documents/GitHub/uni-app-dev/src/core/helpers/protocol/popup.js': require_context_module_0_18,
'/Users/fxy/Documents/GitHub/uni-app-dev/src/core/helpers/protocol/route.js': require_context_module_0_19,
'/Users/fxy/Documents/GitHub/uni-app-dev/src/core/helpers/protocol/storage.js': require_context_module_0_20,
'/Users/fxy/Documents/GitHub/uni-app-dev/src/core/helpers/protocol/tab-bar.js': require_context_module_0_21,
'./base.js': require_context_module_1_0,
'./base64.js': require_context_module_1_1,
'./canvas.js': require_context_module_1_2,
'./context.js': require_context_module_1_3,
'./device/make-phone-call.js': require_context_module_1_4,
'./file/open-document.js': require_context_module_1_5,
'./location.js': require_context_module_1_6,
'./media/choose-image.js': require_context_module_1_7,
'./media/choose-video.js': require_context_module_1_8,
'./media/get-image-info.js': require_context_module_1_9,
'./media/preview-image.js': require_context_module_1_10,
'./navigation-bar.js': require_context_module_1_11,
'./network/download-file.js': require_context_module_1_12,
'./network/request.js': require_context_module_1_13,
'./network/socket.js': require_context_module_1_14,
'./network/upload-file.js': require_context_module_1_15,
'./page-scroll-to.js': require_context_module_1_16,
'./plugins.js': require_context_module_1_17,
'./popup.js': require_context_module_1_18,
'./route.js': require_context_module_1_19,
'./storage.js': require_context_module_1_20,
'./tab-bar.js': require_context_module_1_21,
};
var req = function req(key) {
......@@ -1937,6 +1937,11 @@ var base64Arraybuffer_2 = base64Arraybuffer.decode;
const base64ToArrayBuffer$1 = base64Arraybuffer_2;
const arrayBufferToBase64$1 = base64Arraybuffer_1;
var require_context_module_0_0 = /*#__PURE__*/Object.freeze({
base64ToArrayBuffer: base64ToArrayBuffer$1,
arrayBufferToBase64: arrayBufferToBase64$1
});
var platformSchema = {};
// TODO 待处理其他 API 的检测
......@@ -1948,137 +1953,19 @@ function canIUse$1 (schema) {
return true
}
var require_context_module_0_1 = /*#__PURE__*/Object.freeze({
canIUse: canIUse$1
});
const interceptors = {
promiseInterceptor
};
/**
* 查看位置
* @param {*} param0
* @param {*} callbackId
*/
function openLocation$1 ({
latitude,
longitude,
scale,
name,
address
}, callbackId) {
const {
invokeCallbackHandler: invoke
} = UniServiceJSBridge;
getApp().$router.push({
type: 'navigateTo',
path: '/open-location',
query: {
latitude,
longitude,
scale,
name,
address
}
}, function () {
invoke(callbackId, {
errMsg: 'openLocation:ok'
});
}, function () {
invoke(callbackId, {
errMsg: 'openLocation:fail'
});
});
}
/**
* 选择位置
* @param {*} callbackId
*/
function chooseLocation (options, callbackId) {
const {
invokeCallbackHandler: invoke
} = UniServiceJSBridge;
getApp().$router.push({
type: 'navigateTo',
path: '/choose-location'
}, function () {
var fn = data => {
UniServiceJSBridge.unsubscribe('onChooseLocation', fn);
if (data) {
invoke(callbackId, Object.assign(data, {
errMsg: 'chooseLocation:ok'
}));
} else {
invoke(callbackId, {
errMsg: 'chooseLocation:fail'
});
}
};
UniServiceJSBridge.subscribe('onChooseLocation', fn);
}, function () {
invoke(callbackId, {
errMsg: 'chooseLocation:fail'
});
});
}
function setNavigationBar (type, args) {
const pages = getCurrentPages();
if (pages.length) {
const page = pages[pages.length - 1].$holder;
switch (type) {
case 'setNavigationBarColor':
const {
frontColor,
backgroundColor,
animation
} = args;
const {
duration,
timingFunc
} = animation;
if (frontColor) {
page.navigationBar.textColor = frontColor === '#000000' ? 'black' : 'white';
}
if (backgroundColor) {
page.navigationBar.backgroundColor = backgroundColor;
}
page.navigationBar.duration = duration + 'ms';
page.navigationBar.timingFunc = timingFunc;
break
case 'showNavigationBarLoading':
page.navigationBar.loading = true;
break
case 'hideNavigationBarLoading':
page.navigationBar.loading = false;
break
case 'setNavigationBarTitle':
const {
title
} = args;
page.navigationBar.titleText = title;
break
}
}
return {}
}
function setNavigationBarColor$1 (args) {
return setNavigationBar('setNavigationBarColor', args)
}
function showNavigationBarLoading () {
return setNavigationBar('showNavigationBarLoading')
}
function hideNavigationBarLoading () {
return setNavigationBar('hideNavigationBarLoading')
}
function setNavigationBarTitle$1 (args) {
return setNavigationBar('setNavigationBarTitle', args)
}
var require_context_module_0_2 = /*#__PURE__*/Object.freeze({
interceptors: interceptors,
addInterceptor: addInterceptor,
removeInterceptor: removeInterceptor
});
function pageScrollTo$1 (args) {
const pages = getCurrentPages();
......@@ -2090,6 +1977,10 @@ function pageScrollTo$1 (args) {
let pageId;
function setPullDownRefreshPageId (pullDownRefreshPageId) {
pageId = pullDownRefreshPageId;
}
function startPullDownRefresh () {
if (pageId) {
UniServiceJSBridge.emit(pageId + '.stopPullDownRefresh', {}, pageId);
......@@ -2116,142 +2007,12 @@ function stopPullDownRefresh () {
return {}
}
const {
emit,
invokeCallbackHandler: invoke
} = UniServiceJSBridge;
function showModal$1 (args, callbackId) {
emit('onShowModal', args, function (type) {
invoke(callbackId, {
[type]: true
});
});
}
function showToast$1 (args) {
emit('onShowToast', args);
return {}
}
function hideToast () {
emit('onHideToast');
return {}
}
function showLoading$1 (args) {
emit('onShowLoading', args);
return {}
}
function hideLoading () {
emit('onHideLoading');
return {}
}
function showActionSheet$1 (args, callbackId) {
emit('onShowActionSheet', args, function (tapIndex) {
if (tapIndex === -1) {
invoke(callbackId, {
errMsg: 'showActionSheet:fail cancel'
});
} else {
invoke(callbackId, {
tapIndex
});
}
});
}
function hasLifecycleHook (vueOptions = {}, hook) {
return Array.isArray(vueOptions[hook]) && vueOptions[hook].length
}
function onAppRoute (type, {
url,
delta,
animationType,
animationDuration,
from = 'navigateBack',
detail
} = {}) {
const router = getApp().$router;
switch (type) {
case 'redirectTo':
router.replace({
type,
path: url
});
break
case 'navigateTo':
router.push({
type,
path: url,
animationType,
animationDuration
});
break
case 'navigateBack':
let canBack = true;
const pages = getCurrentPages();
if (pages.length) {
const page = pages[pages.length - 1];
if (hasLifecycleHook(page.$options, 'onBackPress') && page.__call_hook('onBackPress', {
from
}) === true) {
canBack = false;
}
}
if (canBack) {
if (delta > 1) {
router._$delta = delta;
}
router.go(-delta, {
animationType,
animationDuration
});
}
break
case 'reLaunch':
router.replace({
type,
path: url
});
break
case 'switchTab':
router.replace({
type,
path: url,
params: {
detail
}
});
break
}
return {
errMsg: type + ':ok'
}
}
function redirectTo$1 (args) {
return onAppRoute('redirectTo', args)
}
function navigateTo$1 (args) {
return onAppRoute('navigateTo', args)
}
function navigateBack$1 (args) {
return onAppRoute('navigateBack', args)
}
function reLaunch$1 (args) {
return onAppRoute('reLaunch', args)
}
function switchTab$1 (args) {
return onAppRoute('switchTab', args)
}
var require_context_module_0_3 = /*#__PURE__*/Object.freeze({
pageScrollTo: pageScrollTo$1,
setPullDownRefreshPageId: setPullDownRefreshPageId,
startPullDownRefresh: startPullDownRefresh,
stopPullDownRefresh: stopPullDownRefresh
});
function setStorage$1 ({
key,
......@@ -2358,6 +2119,19 @@ function getStorageInfoSync () {
return res
}
var require_context_module_0_4 = /*#__PURE__*/Object.freeze({
setStorage: setStorage$1,
setStorageSync: setStorageSync$1,
getStorage: getStorage,
getStorageSync: getStorageSync,
removeStorage: removeStorage,
removeStorageSync: removeStorageSync,
clearStorage: clearStorage,
clearStorageSync: clearStorageSync,
getStorageInfo: getStorageInfo,
getStorageInfoSync: getStorageInfoSync
});
const EPS = 1e-4;
const BASE_DEVICE_WIDTH = 750;
let isIOS = false;
......@@ -2400,49 +2174,36 @@ function upx2px (number, newDeviceWidth) {
return number < 0 ? -result : result
}
var api = /*#__PURE__*/Object.freeze({
pageScrollTo: pageScrollTo$1,
startPullDownRefresh: startPullDownRefresh,
stopPullDownRefresh: stopPullDownRefresh,
base64ToArrayBuffer: base64ToArrayBuffer$1,
arrayBufferToBase64: arrayBufferToBase64$1,
canIUse: canIUse$1,
interceptors: interceptors,
addInterceptor: addInterceptor,
removeInterceptor: removeInterceptor,
openLocation: openLocation$1,
chooseLocation: chooseLocation,
setNavigationBarColor: setNavigationBarColor$1,
showNavigationBarLoading: showNavigationBarLoading,
hideNavigationBarLoading: hideNavigationBarLoading,
setNavigationBarTitle: setNavigationBarTitle$1,
showModal: showModal$1,
showToast: showToast$1,
hideToast: hideToast,
showLoading: showLoading$1,
hideLoading: hideLoading,
showActionSheet: showActionSheet$1,
redirectTo: redirectTo$1,
navigateTo: navigateTo$1,
navigateBack: navigateBack$1,
reLaunch: reLaunch$1,
switchTab: switchTab$1,
setStorage: setStorage$1,
setStorageSync: setStorageSync$1,
getStorage: getStorage,
getStorageSync: getStorageSync,
removeStorage: removeStorage,
removeStorageSync: removeStorageSync,
clearStorage: clearStorage,
clearStorageSync: clearStorageSync,
getStorageInfo: getStorageInfo,
getStorageInfoSync: getStorageInfoSync,
var require_context_module_0_5 = /*#__PURE__*/Object.freeze({
checkDeviceWidth: checkDeviceWidth,
upx2px: upx2px
});
const api = Object.create(null);
const modules$1 =
(function() {
var map = {
'./base64.js': require_context_module_0_0,
'./can-i-use.js': require_context_module_0_1,
'./interceptor.js': require_context_module_0_2,
'./page-event.js': require_context_module_0_3,
'./storage.js': require_context_module_0_4,
'./upx2px.js': require_context_module_0_5,
};
var req = function req(key) {
return map[key] || (function() { throw new Error("Cannot find module '" + key + "'.") }());
};
req.keys = function() {
return Object.keys(map);
};
return req;
})();
modules$1.keys().forEach(function (key) {
Object.assign(api, modules$1(key));
});
const uni$1 = Object.create(null);
Object.keys(api).forEach(name => {
......
......@@ -10,7 +10,6 @@
"license": "Apache-2.0",
"dependencies": {
"base64-arraybuffer": "^0.2.0",
"intersection-observer": "^0.7.0",
"rollup-plugin-require-context": "^1.0.0"
"intersection-observer": "^0.7.0"
}
}
const base = [
'base64ToArrayBuffer',
'arrayBufferToBase64'
]
const network = [
'request',
'uploadFile',
'downloadFile',
'connectSocket',
'onSocketOpen',
'onSocketError',
'sendSocketMessage',
'onSocketMessage',
'closeSocket',
'onSocketClose'
]
const route = [
'navigateTo',
'redirectTo',
'reLaunch',
'switchTab',
'navigateBack'
]
const storage = [
'setStorage',
'setStorageSync',
'getStorage',
'getStorageSync',
'getStorageInfo',
'getStorageInfoSync',
'removeStorage',
'removeStorageSync',
'clearStorage',
'clearStorageSync'
]
const location = [
'getLocation',
'chooseLocation',
'openLocation',
'createMapContext'
]
const media = [
'chooseImage',
'previewImage',
'getImageInfo',
'saveImageToPhotosAlbum',
'compressImage',
'chooseMessageFile',
'getRecorderManager',
'getBackgroundAudioManager',
'createInnerAudioContext',
'chooseVideo',
'saveVideoToPhotosAlbum',
'createVideoContext',
'createCameraContext',
'createLivePlayerContext'
]
const device = [
'getSystemInfo',
'getSystemInfoSync',
'canIUse',
'onMemoryWarning',
'getNetworkType',
'onNetworkStatusChange',
'onAccelerometerChange',
'startAccelerometer',
'stopAccelerometer',
'onCompassChange',
'startCompass',
'stopCompass',
'onGyroscopeChange',
'startGyroscope',
'stopGyroscope',
'makePhoneCall',
'scanCode',
'setClipboardData',
'getClipboardData',
'setScreenBrightness',
'getScreenBrightness',
'setKeepScreenOn',
'onUserCaptureScreen',
'vibrateLong',
'vibrateShort',
'addPhoneContact',
'openBluetoothAdapter',
'startBluetoothDevicesDiscovery',
'onBluetoothDeviceFound',
'stopBluetoothDevicesDiscovery',
'onBluetoothAdapterStateChange',
'getConnectedBluetoothDevices',
'getBluetoothDevices',
'getBluetoothAdapterState',
'closeBluetoothAdapter',
'writeBLECharacteristicValue',
'readBLECharacteristicValue',
'onBLEConnectionStateChange',
'onBLECharacteristicValueChange',
'notifyBLECharacteristicValueChange',
'getBLEDeviceServices',
'getBLEDeviceCharacteristics',
'createBLEConnection',
'closeBLEConnection',
'onBeaconServiceChange',
'onBeaconUpdate',
'getBeacons',
'startBeaconDiscovery',
'stopBeaconDiscovery'
]
const keyboard = [
'hideKeyboard'
]
const ui = [
'showToast',
'hideToast',
'showLoading',
'hideLoading',
'showModal',
'showActionSheet',
'setNavigationBarTitle',
'setNavigationBarColor',
'showNavigationBarLoading',
'hideNavigationBarLoading',
'setTabBarItem',
'setTabBarStyle',
'hideTabBar',
'showTabBar',
'setTabBarBadge',
'removeTabBarBadge',
'showTabBarRedDot',
'hideTabBarRedDot',
'setBackgroundColor',
'setBackgroundTextStyle',
'createAnimation',
'pageScrollTo',
'onWindowResize',
'offWindowResize',
'loadFontFace',
'startPullDownRefresh',
'stopPullDownRefresh',
'createSelectorQuery',
'createIntersectionObserver'
]
const event = [
'$emit',
'$on',
'$once',
'$off'
]
const file = [
'saveFile',
'getSavedFileList',
'getSavedFileInfo',
'removeSavedFile',
'getFileInfo',
'openDocument',
'getFileSystemManager'
]
const canvas = [
'createOffscreenCanvas',
'createCanvasContext',
'canvasToTempFilePath',
'canvasPutImageData',
'canvasGetImageData'
]
const third = [
'getProvider',
'login',
'checkSession',
'getUserInfo',
'share',
'showShareMenu',
'hideShareMenu',
'requestPayment',
'subscribePush',
'unsubscribePush',
'onPush',
'offPush',
'requireNativePlugin',
'upx2px'
]
const apis = [
...base,
...network,
...route,
...storage,
...location,
...media,
...device,
...keyboard,
...ui,
...event,
...file,
...canvas,
...third
]
export default apis
export * from '../service/api/event-bus'
import Vue from 'vue'
const getEmitter = (function () {
if (typeof getUniEmitter === 'function') {
/* eslint-disable no-undef */
return getUniEmitter
}
let Emitter
return function getUniEmitter () {
if (!Emitter) {
Emitter = new Vue()
}
return Emitter
}
})()
function apply (ctx, method, args) {
return ctx[method].apply(ctx, args)
}
export function $on () {
return apply(getEmitter(), '$on', [...arguments])
}
export function $off () {
return apply(getEmitter(), '$off', [...arguments])
}
export function $once () {
return apply(getEmitter(), '$once', [...arguments])
}
export function $emit () {
return apply(getEmitter(), '$emit', [...arguments])
}
......@@ -16,13 +16,13 @@ import * as extraApi from './extra'
import * as eventApi from './event-bus'
import * as api from 'uni-platform/service/api/index.js'
import * as api from 'uni-platform/runtime/api/index.js'
import {
protocols,
todos,
canIUses
} from 'uni-platform/service/api/protocols'
} from 'uni-platform/runtime/api/protocols'
import createApp from './wrapper/create-app'
import createPage from './wrapper/create-page'
......
......@@ -4,7 +4,7 @@ let isIOS = false
let deviceWidth = 0
let deviceDPR = 0
export function checkDeviceWidth () {
function checkDeviceWidth () {
const {
platform,
pixelRatio,
......
export const api = Object.create(null)
const baseApis = require.context(
'./api',
true,
/\.js$/
)
baseApis.keys().forEach(function (key) {
Object.assign(api, baseApis(key))
})
const platformApis = require.context(
'../../platforms/' + __PLATFORM__ + '/service/api',
true,
/\.js$/
)
platformApis.keys().forEach(function (key) {
Object.assign(api, platformApis(key))
})
export function invokeMethod (name, ...args) {
return api[name](...args)
}
import Vue from 'vue'
const getEmitter = (function () {
if (typeof getUniEmitter === 'function') {
/* eslint-disable no-undef */
return getUniEmitter
}
let Emitter
return function getUniEmitter () {
if (!Emitter) {
Emitter = new Vue()
}
return Emitter
}
})()
function apply (ctx, method, args) {
return ctx[method].apply(ctx, args)
}
export function $on () {
return apply(getEmitter(), '$on', [...arguments])
}
export function $off () {
return apply(getEmitter(), '$off', [...arguments])
}
export function $once () {
return apply(getEmitter(), '$once', [...arguments])
}
export function $emit () {
return apply(getEmitter(), '$emit', [...arguments])
}
......@@ -4,7 +4,7 @@ let isIOS = false
let deviceWidth = 0
let deviceDPR = 0
export function checkDeviceWidth () {
function checkDeviceWidth () {
const {
platform,
pixelRatio,
......
......@@ -33,8 +33,8 @@ export {
from 'uni-platform/service/bridge'
initOn(on, {
getApp,
getCurrentPages
})
getApp: global.getApp,
getCurrentPages: global.getCurrentPages
})
initSubscribe(subscribe)
import apis from 'uni-helpers/apis'
import {
wrapper,
wrapperUnimplemented
......@@ -7,27 +9,21 @@ import {
promisify
} from 'uni-helpers/promise'
import todoApis from 'uni-platform/helpers/todo-api'
import baseApi from './api/index'
import platformApi from 'uni-platform/service/api'
import {
api
} from './api'
const uni = Object.create(null)
/* eslint-disable no-undef */
uni.version = __VERSION__
todoApis.forEach(name => {
uni[name] = wrapperUnimplemented(name)
})
Object.keys(baseApi).forEach(name => {
uni[name] = promisify(name, wrapper(name, baseApi[name]))
})
Object.keys(platformApi).forEach(name => {
uni[name] = promisify(name, wrapper(name, platformApi[name]))
apis.forEach(name => {
if (api[name]) {
uni[name] = promisify(name, wrapper(name, api[name]))
} else {
uni[name] = wrapperUnimplemented(name)
}
})
export {
......
export * from 'uni-core/service/api/base64'
export * from 'uni-core/service/api/can-i-use'
export * from 'uni-core/service/api/interceptor'
export * from 'uni-core/service/api/location'
export * from 'uni-core/service/api/navigation-bar'
export {
pageScrollTo,
startPullDownRefresh,
stopPullDownRefresh
}
from 'uni-core/service/api/page-event'
export * from 'uni-core/service/api/popup'
export * from 'uni-core/service/api/route'
export * from 'uni-core/service/api/storage'
export * from 'uni-core/service/api/upx2px'
......@@ -8,7 +8,7 @@ import {
promisify
} from 'uni-helpers/promise'
import * as api from './api'
import api from 'uni-core/service/api'
const uni = Object.create(null)
......
const api = Object.create(null)
const modules = require.context('./', true, /\.js$/)
const modules = require.context('./api', true, /\.js$/)
modules.keys().forEach(function (key) {
if (key !== './index.js') {
Object.assign(api, modules(key))
}
Object.assign(api, modules(key))
})
export default api
......@@ -881,23 +881,3 @@ export function canvasToTempFilePath ({
callbackId: cId
})
}
export function createContext () {
return new CanvasContext()
}
export function drawCanvas ({
canvasId,
actions,
reserve
}) {
const app = getApp()
if (app.$route && app.$route.params.__id__) {
operateCanvas(canvasId, app.$route.params.__id__, 'actionsChanged', {
actions,
reserve
})
} else {
UniServiceJSBridge.emit('onError', 'drawCanvas:fail')
}
}
......@@ -4,11 +4,11 @@ const ua = navigator.userAgent
/**
* 是否安卓设备
*/
export const isAndroid = /android/i.test(ua)
const isAndroid = /android/i.test(ua)
/**
* 是否iOS设备
*/
export const isIOS = /iphone|ipad|ipod/i.test(ua)
const isIOS = /iphone|ipad|ipod/i.test(ua)
/**
* 获取系统信息-同步
*/
......
import Vue from 'vue'
const Emitter = new Vue()
function apply (ctx, method, args) {
return ctx[method].apply(ctx, args)
}
export function $on () {
return apply(Emitter, '$on', [...arguments])
}
export function $off () {
return apply(Emitter, '$off', [...arguments])
}
export function $once () {
return apply(Emitter, '$once', [...arguments])
}
export function $emit () {
return apply(Emitter, '$emit', [...arguments])
}
const api = Object.create(null)
const modules = require.context('./', true, /\.js$/)
modules.keys().forEach(function (key) {
if (key !== './index.js') {
Object.assign(api, modules(key))
}
})
export default api
/**
* 查看位置
* @param {*} param0
* @param {*} callbackId
*/
export function openLocation ({
latitude,
longitude,
scale,
name,
address
}, callbackId) {
const {
invokeCallbackHandler: invoke
} = UniServiceJSBridge
getApp().$router.push({
type: 'navigateTo',
path: '/open-location',
query: {
latitude,
longitude,
scale,
name,
address
}
}, function () {
invoke(callbackId, {
errMsg: 'openLocation:ok'
})
}, function () {
invoke(callbackId, {
errMsg: 'openLocation:fail'
})
})
}
/**
* 选择位置
* @param {*} callbackId
*/
export function chooseLocation (options, callbackId) {
const {
invokeCallbackHandler: invoke
} = UniServiceJSBridge
getApp().$router.push({
type: 'navigateTo',
path: '/choose-location'
}, function () {
var fn = data => {
UniServiceJSBridge.unsubscribe('onChooseLocation', fn)
if (data) {
invoke(callbackId, Object.assign(data, {
errMsg: 'chooseLocation:ok'
}))
} else {
invoke(callbackId, {
errMsg: 'chooseLocation:fail'
})
}
}
UniServiceJSBridge.subscribe('onChooseLocation', fn)
}, function () {
invoke(callbackId, {
errMsg: 'chooseLocation:fail'
})
})
/**
* 选择位置
* @param {*} callbackId
*/
export function chooseLocation (options, callbackId) {
const {
invokeCallbackHandler: invoke
} = UniServiceJSBridge
getApp().$router.push({
type: 'navigateTo',
path: '/choose-location'
}, function () {
var fn = data => {
UniServiceJSBridge.unsubscribe('onChooseLocation', fn)
if (data) {
invoke(callbackId, Object.assign(data, {
errMsg: 'chooseLocation:ok'
}))
} else {
invoke(callbackId, {
errMsg: 'chooseLocation:fail'
})
}
}
UniServiceJSBridge.subscribe('onChooseLocation', fn)
}, function () {
invoke(callbackId, {
errMsg: 'chooseLocation:fail'
})
})
}
import {
getJSONP
} from '../../../helpers/get-jsonp'
/**
* wgs84坐标转Gcj02坐标
* @param {object} coords
* @param {Function} success
* @param {Function} error
*/
function wgs84ToGcj02 (coords, success, error) {
/**
* uniapp 内置key
*/
var key = __uniConfig.qqMapKey
var url =
`https://apis.map.qq.com/ws/coord/v1/translate?locations=${coords.latitude},${coords.longitude}&type=1&key=${key}&output=jsonp`
getJSONP(url, {}, (res) => {
if ('locations' in res && res.locations.length) {
success({
longitude: res.locations[0].lng,
latitude: res.locations[0].lat
})
} else {
error(res)
}
}, error)
}
/**
* 获取定位信息
* @param {*} param0
* @param {*} callbackId
*/
export function getLocation ({
type,
altitude
}, callbackId) {
const {
invokeCallbackHandler: invoke
} = UniServiceJSBridge
function callback (coords) {
invoke(callbackId, Object.assign(coords, {
errMsg: 'getLocation:ok',
verticalAccuracy: coords.altitudeAccuracy || 0,
// 无专门水平精度,使用位置精度替代
horizontalAccuracy: coords.accuracy
}))
}
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition((position) => {
var coords = position.coords
if (type === 'WGS84') {
callback(coords)
} else {
wgs84ToGcj02(coords, callback, (err) => {
invoke(callbackId, {
errMsg: 'getLocation:fail ' + JSON.stringify(err)
})
})
}
}, () => {
invoke(callbackId, {
errMsg: 'getLocation:fail'
})
}, {
enableHighAccuracy: altitude,
timeout: 1000 * 60 * 5
})
} else {
invoke(callbackId, {
errMsg: 'getLocation:fail device nonsupport geolocation'
})
}
}
/**
* 查看位置
* @param {*} param0
* @param {*} callbackId
*/
export function openLocation ({
latitude,
longitude,
scale,
name,
address
}, callbackId) {
const {
invokeCallbackHandler: invoke
} = UniServiceJSBridge
getApp().$router.push({
type: 'navigateTo',
path: '/open-location',
query: {
latitude,
longitude,
scale,
name,
address
}
}, function () {
invoke(callbackId, {
errMsg: 'openLocation:ok'
})
}, function () {
invoke(callbackId, {
errMsg: 'openLocation:fail'
})
})
}
......@@ -2,7 +2,7 @@ import { fileToUrl } from 'uni-platform/helpers/file'
/**
* 下载任务
*/
export class DownloadTask {
class DownloadTask {
_xhr
_callbacks = []
constructor (xhr) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册