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

Merge branch 'dev' of https://github.com/dcloudio/uni-app into alpha

import Vue from 'vue'
// 使用白名单过滤(前期有一批自定义组件使用了 uni-)
import tags from 'uni-helpers/tags'
const oldIsReservedTag = Vue.config.isReservedTag
Vue.config.isReservedTag = function (tag) {
return tags.indexOf(tag) !== -1 || oldIsReservedTag(tag)
}
Vue.config.ignoredElements = tags
const oldGetTagNamespace = Vue.config.getTagNamespace
const conflictTags = ['switch', 'image', 'text', 'view']
Vue.config.getTagNamespace = function (tag) {
if (~conflictTags.indexOf(tag)) { // svg 部分标签名称与 uni 标签冲突
return false
}
return oldGetTagNamespace(tag) || false
}
require('uni-components')
......@@ -161,7 +161,7 @@ var serviceContext = (function () {
return false
}
return page.$page.meta.isTabBar
}
}
const route = __uniRoutes.find(route => route.path.slice(1) === path);
return route && route.meta.isTabBar
} catch (e) {
......@@ -174,6 +174,10 @@ var serviceContext = (function () {
function base64ToArrayBuffer (data) {
return base64Arraybuffer_2(data)
}
function arrayBufferToBase64 (data) {
return base64Arraybuffer_1(data)
}
function callApiSync (api, args, name, alias) {
......@@ -2025,7 +2029,7 @@ var serviceContext = (function () {
required: true
}];
const arrayBufferToBase64 = [{
const arrayBufferToBase64$1 = [{
name: 'arrayBuffer',
type: [ArrayBuffer, Uint8Array],
required: true
......@@ -2033,7 +2037,7 @@ var serviceContext = (function () {
var require_context_module_0_0 = /*#__PURE__*/Object.freeze({
base64ToArrayBuffer: base64ToArrayBuffer$1,
arrayBufferToBase64: arrayBufferToBase64
arrayBufferToBase64: arrayBufferToBase64$1
});
const canIUse = [{
......@@ -3713,13 +3717,13 @@ var serviceContext = (function () {
return base64Arraybuffer_2(str)
}
function arrayBufferToBase64$1 (buffer) {
function arrayBufferToBase64$2 (buffer) {
return base64Arraybuffer_1(buffer)
}
var require_context_module_1_0 = /*#__PURE__*/Object.freeze({
base64ToArrayBuffer: base64ToArrayBuffer$2,
arrayBufferToBase64: arrayBufferToBase64$1
arrayBufferToBase64: arrayBufferToBase64$2
});
var platformSchema = {};
......@@ -6079,53 +6083,64 @@ var serviceContext = (function () {
}
}
let socketTaskId = 0;
const socketTasks = {};
const publishStateChange$2 = (res) => {
publish('onSocketTaskStateChange', res);
};
const createSocketTaskById = function (socketTaskId, {
url,
data,
header,
method,
protocols
} = {}) {
// fixed by hxy 需要测试是否支持 arraybuffer
const socket = requireNativePlugin('webSocket');
socket.WebSocket(url, Array.isArray(protocols) ? protocols.join(',') : protocols);
// socket.binaryType = 'arraybuffer'
socketTasks[socketTaskId] = socket;
let socket;
function getSocket () {
if (socket) {
return socket
}
socket = requireNativePlugin('uni-webSocket');
socket.onopen(function (e) {
publishStateChange$2({
socketTaskId,
socketTaskId: e.id,
state: 'open'
});
});
socket.onmessage(function (e) {
const data = e.data;
publishStateChange$2({
socketTaskId,
socketTaskId: e.id,
state: 'message',
data: e.data
data: typeof data === 'object' ? base64ToArrayBuffer(data.base64) : data
});
});
socket.onerror(function (e) {
publishStateChange$2({
socketTaskId,
socketTaskId: e.id,
state: 'error',
errMsg: e.message
errMsg: e.data
});
});
socket.onclose(function (e) {
const socketTaskId = e.id;
delete socketTasks[socketTaskId];
publishStateChange$2({
socketTaskId,
state: 'close'
});
});
return socket
}
const createSocketTaskById = function (socketTaskId, {
url,
data,
header,
method,
protocols
} = {}) {
const socket = getSocket();
socket.WebSocket({
id: socketTaskId,
url,
protocol: Array.isArray(protocols) ? protocols.join(',') : protocols
});
socketTasks[socketTaskId] = socket;
return {
socketTaskId,
errMsg: 'createSocketTask:ok'
......@@ -6133,13 +6148,14 @@ var serviceContext = (function () {
};
function createSocketTask (args) {
return createSocketTaskById(++socketTaskId, args)
return createSocketTaskById(String(Date.now()), args)
}
function operateSocketTask (args) {
const {
operationType,
code,
reason,
data,
socketTaskId
} = unpack(args);
......@@ -6152,13 +6168,23 @@ var serviceContext = (function () {
switch (operationType) {
case 'send':
if (data) {
socket.send(data);
socket.send({
id: socketTaskId,
data: typeof data === 'object' ? {
'@type': 'binary',
base64: arrayBufferToBase64(data)
} : data
});
}
return {
errMsg: 'operateSocketTask:ok'
}
case 'close':
socket.close(code);
socket.close({
id: socketTaskId,
code,
reason
});
delete socketTasks[socketTaskId];
return {
errMsg: 'operateSocketTask:ok'
......
......@@ -15,6 +15,7 @@ const WebpackErrorsPlugin = require('@dcloudio/vue-cli-plugin-uni/packages/webpa
const WebpackUniMPPlugin = require('@dcloudio/webpack-uni-mp-loader/lib/plugin/index-new')
const onErrors = require('@dcloudio/vue-cli-plugin-uni/util/on-errors')
const onWarnings = require('@dcloudio/vue-cli-plugin-uni/util/on-warnings')
const cssLoaders = require('./css-loader.conf')
const vueLoaderOptions = require('./vue-loader.conf')
......@@ -65,7 +66,8 @@ const plugins = [
}),
new webpack.ProvidePlugin(provide),
new WebpackErrorsPlugin({
onErrors
onErrors,
onWarnings
}),
new WebpackAppPlusNVuePlugin()
]
......@@ -192,12 +194,12 @@ module.exports = function () {
},
externals: {
'vue': 'Vue'
},
performance: {
hints: false
},
performance: {
hints: false
},
optimization: {
namedModules: false
namedModules: false
},
output: {
path: process.env.UNI_OUTPUT_DIR,
......
......@@ -190,9 +190,10 @@ module.exports = function configureWebpack (platformOptions, manifestPlatformOpt
if (runByHBuilderX) { // 使用 HBuilderX 中运行时,调整错误日志输出
const WebpackErrorsPlugin = require('../packages/webpack-errors-plugin')
const onErrors = require('../util/on-errors')
const onWarnings = require('../util/on-warnings')
plugins.push(new WebpackErrorsPlugin({
onErrors,
onWarnings: onErrors
onWarnings
}))
}
......
......@@ -148,16 +148,9 @@ if (
platformOptions.uniStatistics || {}
)
if (
uniStatistics.enable !== false &&
(
process.env.NODE_ENV === 'production' ||
uniStatistics.enable === 'development'
)
) {
if (process.UNI_STAT_CONFIG.appid) {
process.env.UNI_USING_STAT = true
} else {
if (uniStatistics.enable !== false) {
process.env.UNI_USING_STAT = true
if (!process.UNI_STAT_CONFIG.appid && process.env.NODE_ENV === 'production') {
console.log()
console.warn(`当前应用未配置Appid,无法使用uni统计,详情参考:https://ask.dcloud.net.cn/article/36303`)
console.log()
......
const path = require('path')
const formatErrors = require('./format-errors')
const stringify = require('./stringify')
module.exports = function (errors) {
console.error(
Array.from(
new Set(
errors.map(err => {
const formatError = formatErrors[err.name]
if (formatError) {
const result = formatError(err)
if (result) {
if (typeof result === 'string') {
return result
} else {
const file = path.relative(process.env.UNI_INPUT_DIR, err.module.resource).split('?')[0]
if (file === 'pages.json') {
result.line = 1
}
return `${result.message} at ${file}:${result.line || 1}`
}
} else if (result === false) {
return '' // skip
}
}
return err.message
})
)
)
.filter(msg => !!msg)
.join('\n')
)
console.error(stringify(errors))
}
const stringify = require('./stringify')
module.exports = function (errors) {
const {
runByHBuilderX
} = require('@dcloudio/uni-cli-shared')
if (runByHBuilderX) {
console.log(stringify(errors))
} else {
console.warn(stringify(errors))
}
}
const path = require('path')
const formatErrors = require('./format-errors')
module.exports = function stringify (errors) {
return (Array.from(
new Set(
errors.map(err => {
const formatError = formatErrors[err.name]
if (formatError) {
const result = formatError(err)
if (result) {
if (typeof result === 'string') {
return result
} else {
const file = path.relative(process.env.UNI_INPUT_DIR, err.module.resource).split('?')[0]
if (file === 'pages.json') {
result.line = 1
}
return `${result.message} at ${file}:${result.line || 1}`
}
} else if (result === false) {
return '' // skip
}
}
return err.message
})
)
)
.filter(msg => !!msg)
.join('\n'))
}
import {
unpack,
publish,
requireNativePlugin
requireNativePlugin,
base64ToArrayBuffer,
arrayBufferToBase64
} from '../../bridge'
let socketTaskId = 0
const socketTasks = {}
const publishStateChange = (res) => {
publish('onSocketTaskStateChange', res)
}
const createSocketTaskById = function (socketTaskId, {
url,
data,
header,
method,
protocols
} = {}) {
// fixed by hxy 需要测试是否支持 arraybuffer
const socket = requireNativePlugin('webSocket')
socket.WebSocket(url, Array.isArray(protocols) ? protocols.join(',') : protocols)
// socket.binaryType = 'arraybuffer'
socketTasks[socketTaskId] = socket
let socket
function getSocket () {
if (socket) {
return socket
}
socket = requireNativePlugin('uni-webSocket')
socket.onopen(function (e) {
publishStateChange({
socketTaskId,
socketTaskId: e.id,
state: 'open'
})
})
socket.onmessage(function (e) {
const data = e.data
publishStateChange({
socketTaskId,
socketTaskId: e.id,
state: 'message',
data: e.data
data: typeof data === 'object' ? base64ToArrayBuffer(data.base64) : data
})
})
socket.onerror(function (e) {
publishStateChange({
socketTaskId,
socketTaskId: e.id,
state: 'error',
errMsg: e.message
errMsg: e.data
})
})
socket.onclose(function (e) {
const socketTaskId = e.id
delete socketTasks[socketTaskId]
publishStateChange({
socketTaskId,
state: 'close'
})
})
return socket
}
const createSocketTaskById = function (socketTaskId, {
url,
data,
header,
method,
protocols
} = {}) {
const socket = getSocket()
socket.WebSocket({
id: socketTaskId,
url,
protocol: Array.isArray(protocols) ? protocols.join(',') : protocols
})
socketTasks[socketTaskId] = socket
return {
socketTaskId,
errMsg: 'createSocketTask:ok'
......@@ -58,13 +71,14 @@ const createSocketTaskById = function (socketTaskId, {
}
export function createSocketTask (args) {
return createSocketTaskById(++socketTaskId, args)
return createSocketTaskById(String(Date.now()), args)
}
export function operateSocketTask (args) {
const {
operationType,
code,
reason,
data,
socketTaskId
} = unpack(args)
......@@ -77,13 +91,23 @@ export function operateSocketTask (args) {
switch (operationType) {
case 'send':
if (data) {
socket.send(data)
socket.send({
id: socketTaskId,
data: typeof data === 'object' ? {
'@type': 'binary',
base64: arrayBufferToBase64(data)
} : data
})
}
return {
errMsg: 'operateSocketTask:ok'
}
case 'close':
socket.close(code)
socket.close({
id: socketTaskId,
code,
reason
})
delete socketTasks[socketTaskId]
return {
errMsg: 'operateSocketTask:ok'
......@@ -92,4 +116,4 @@ export function operateSocketTask (args) {
return {
errMsg: 'operateSocketTask:fail'
}
}
}
import {
decode
decode,
encode
} from 'base64-arraybuffer'
export {
......@@ -56,7 +57,7 @@ export function isTabBarPage (path = '') {
return false
}
return page.$page.meta.isTabBar
}
}
const route = __uniRoutes.find(route => route.path.slice(1) === path)
return route && route.meta.isTabBar
} catch (e) {
......@@ -70,3 +71,7 @@ export function isTabBarPage (path = '') {
export function base64ToArrayBuffer (data) {
return decode(data)
}
export function arrayBufferToBase64 (data) {
return encode(data)
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册