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

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

# Conflicts:
#	packages/uni-app-plus/dist/view.umd.min.js
#	packages/uni-h5/dist/index.umd.min.js
因为 它太大了无法显示 source diff 。你可以改为 查看blob
......@@ -168,12 +168,15 @@ at ${resourcePath}.vue:1`)
}
const filterTemplate = []
options.mp.filterModules.forEach(name => {
filterTemplate.push(
options.mp.platform.createFilterTag(
options.filterTagName,
options.filterModules[name]
const filterModule = options.filterModules[name]
if (filterModule.type !== 'renderjs' && filterModule.attrs.lang !== 'renderjs') {
filterTemplate.push(
options.mp.platform.createFilterTag(
options.filterTagName,
options.filterModules[name]
)
)
)
}
})
if (filterTemplate.length) {
......
......@@ -36,7 +36,8 @@ function getProvides (isAppService) {
'getRegExp': [wxsPath, 'getRegExp']
}
}
return { // app-view
return { // app-view
'__f__': [path.resolve(__dirname, '../format-log.js'), 'default'],
'getDate': [wxsPath, 'getDate'],
'getRegExp': [wxsPath, 'getRegExp']
}
......@@ -89,12 +90,12 @@ const v3 = {
'../../packages/webpack-uni-app-loader/view/script')
})
// view 层 renderjs
rules.push({
resourceQuery: [/lang=renderjs/, /blockType=renderjs/],
use: [{
loader: path.resolve(__dirname, '../../packages/webpack-uni-app-loader/view/renderjs')
}]
})
// rules.push({
// resourceQuery: [/lang=renderjs/, /blockType=renderjs/],
// use: [{
// loader: path.resolve(__dirname, '../../packages/webpack-uni-app-loader/view/renderjs')
// }]
// })
}
scriptLoaders.push({
loader: path.resolve(__dirname,
......
......@@ -27,13 +27,14 @@ module.exports = function parseCustomBlocks(descriptor, options) {
return true
}
if ( // renderjs
options.isAppView &&
block.attrs.module &&
(
block.type === 'renderjs' ||
block.attrs.lang === 'renderjs'
)
) {
return true
descriptor.renderjs = block
modules[block.attrs.module] = block
}
})
......
......@@ -212,6 +212,27 @@ if (process.env.UNI_USING_V3) {
} else {
root.walkRules(rule => {
const selectors = transformSelector(rule.selectors.join(','), function (selectors) {
selectors.each((selector) => {
// find the last child node to insert attribute selector
selector.each((n) => {
// ">>>" combinator
// and /deep/ alias for >>>, since >>> doesn't work in SASS
if (n.type === 'combinator' &&
(n.value === '>>>' || n.value ===
'/deep/')) {
n.value = ' '
n.spaces.before = n.spaces.after = ''
return false
}
// in newer versions of sass, /deep/ support is also dropped, so add a ::v-deep alias
if (n.type === 'pseudo' && n.value ===
'::v-deep') {
n.value = n.spaces.before = n.spaces.after =
''
return false
}
})
})
selectors.walkUniversals(node => {
node.parent.remove()
})
......
......@@ -141,6 +141,20 @@ module.exports = function (source) {
)
}
let renderjsImport = `var renderjs`
if(options.isAppView && descriptor.renderjs){
const src = descriptor.renderjs.src || resourcePath
const attrsQuery = attrsToQuery(descriptor.renderjs.attrs, 'js')
const query = `?vue&type=renderjs${attrsQuery}${inheritQuery}`
const request = stringifyRequest(src + query)
renderjsImport = (
`import renderjs from ${request}\n` +
`renderjs.__module = '${descriptor.renderjs.attrs.module}'\n` +
`export * from ${request}` // support named exports
)
}
// styles
let stylesCode = ``
// fixed by xxxxxx 仅限 view 层
......@@ -158,6 +172,7 @@ module.exports = function (source) {
// fixed by xxxxxx (injectStyles,auto components)
let code = `
${templateImport}
${renderjsImport}
${scriptImport}
${stylesCode}
......@@ -172,7 +187,8 @@ var component = normalizer(
${hasScoped ? JSON.stringify(id) : `null`},
${isServer ? JSON.stringify(hash(request)) : `null`},
${isShadow ? `true` : `false`},
components
components,
renderjs
)
`.trim() + `\n`
......
......@@ -13,7 +13,8 @@ export default function normalizeComponent (
scopeId,
moduleIdentifier, /* server only */
shadowMode, /* vue-cli only */
components // fixed by xxxxxx auto components
components, // fixed by xxxxxx auto components
renderjs // fixed by xxxxxx renderjs
) {
// Vue.extend constructor export interop
var options = typeof scriptExports === 'function'
......@@ -24,6 +25,13 @@ export default function normalizeComponent (
if (components) {
options.components = Object.assign(components, options.components || {})
}
// fixed by xxxxxx renderjs
if (renderjs) {
(renderjs.beforeCreate || (renderjs.beforeCreate = [])).unshift(function() {
this[renderjs.__module] = this
});
(options.mixins || (options.mixins = [])).push(renderjs)
}
// render functions
if (render) {
......
......@@ -30,6 +30,19 @@ module.exports = function selectBlock (
return
}
// renderjs
if (query.type === `renderjs`) {
if (appendExtension) {
loaderContext.resourcePath += '.js'
}
loaderContext.callback(
null,
descriptor.renderjs.content,
descriptor.renderjs.map
)
return
}
// styles
if (query.type === `style` && query.index != null) {
const style = descriptor.styles[query.index]
......
export const pixelRatio = (function () {
const canvas = document.createElement('canvas')
canvas.height = canvas.width = 0
const context = canvas.getContext('2d')
const backingStore = context.backingStorePixelRatio ||
context.webkitBackingStorePixelRatio ||
context.mozBackingStorePixelRatio ||
context.msBackingStorePixelRatio ||
context.oBackingStorePixelRatio ||
context.backingStorePixelRatio || 1
context.webkitBackingStorePixelRatio ||
context.mozBackingStorePixelRatio ||
context.msBackingStorePixelRatio ||
context.oBackingStorePixelRatio ||
context.backingStorePixelRatio || 1
return (window.devicePixelRatio || 1) / backingStore
})()
......
......@@ -259,10 +259,12 @@ var methods3 = ['setFillStyle', 'setTextAlign', 'setStrokeStyle', 'setGlobalAlph
]
var tempCanvas
function getTempCanvas () {
function getTempCanvas (width = 0, height = 0) {
if (!tempCanvas) {
tempCanvas = document.createElement('canvas')
}
tempCanvas.width = width
tempCanvas.height = height
return tempCanvas
}
......
<template>
<uni-canvas
:canvas-id="canvasId"
:disable-scroll="disableScroll"
<uni-canvas
:canvas-id="canvasId"
:disable-scroll="disableScroll"
v-on="_listeners">
<canvas
ref="canvas"
width="300"
<canvas
ref="canvas"
width="300"
height="150" />
<div style="position: absolute; top: 0; left: 0; width: 100%; height: 100%; overflow: hidden;">
<slot />
</div>
<v-uni-resize-sensor
ref="sensor"
@resize="_resize"/>
<v-uni-resize-sensor
ref="sensor"
@resize="_resize" />
</uni-canvas>
</template>
<script>
......@@ -42,6 +42,16 @@ function processTouches (target, touches) {
})
}
var tempCanvas
function getTempCanvas (width = 0, height = 0) {
if (!tempCanvas) {
tempCanvas = document.createElement('canvas')
}
tempCanvas.width = width
tempCanvas.height = height
return tempCanvas
}
export default {
name: 'Canvas',
mixins: [subscriber],
......@@ -97,6 +107,10 @@ export default {
height: this.$refs.sensor.$el.offsetHeight
})
},
beforeDestroy () {
const canvas = this.$refs.canvas
canvas.height = canvas.width = 0
},
methods: {
_handleSubscribe ({
type,
......@@ -335,7 +349,7 @@ export default {
} else {
// 解决 PLUS-APP(wkwebview)以及 H5 图像跨域问题(H5图像响应头需包含access-control-allow-origin)
if (window.plus && src.indexOf('http://') !== 0 && src.indexOf('https://') !==
0) {
0) {
loadFile(src)
} else if (/^data:.*,.*/.test(src)) {
sefl._images[src].src = src
......@@ -392,7 +406,6 @@ export default {
height = canvas.offsetHeight - y
}
try {
const newCanvas = document.createElement('canvas')
if (!hidpi) {
if (!destWidth && !destHeight) {
destWidth = Math.round(width * pixelRatio)
......@@ -406,15 +419,15 @@ export default {
destWidth = width
destHeight = height
}
newCanvas.width = destWidth
newCanvas.height = destHeight
const newCanvas = getTempCanvas(destWidth, destHeight)
const context = newCanvas.getContext('2d')
context.__hidpi__ = true
context.drawImageByCanvas(canvas, x, y, width, height, 0, 0, destWidth, destHeight, false)
imgData = context.getImageData(0, 0, destWidth, destHeight)
} catch (error) {
if (!callbackId) {
return
newCanvas.height = newCanvas.width = 0
} catch (error) {
if (!callbackId) {
return
}
UniViewJSBridge.publishHandler('onCanvasMethodCallback', {
callbackId,
......@@ -423,13 +436,13 @@ export default {
}
}, this.$page.id)
return
}
if (!callbackId) {
return {
data: [...imgData.data],
width: destWidth,
height: destHeight
}
}
if (!callbackId) {
return {
data: [...imgData.data],
width: destWidth,
height: destHeight
}
} else {
UniViewJSBridge.publishHandler('onCanvasMethodCallback', {
callbackId,
......@@ -439,7 +452,7 @@ export default {
width: destWidth,
height: destHeight
}
}, this.$page.id)
}, this.$page.id)
}
},
putImageData ({
......@@ -454,12 +467,11 @@ export default {
if (!height) {
height = Math.round(data.length / 4 / width)
}
const canvas = document.createElement('canvas')
canvas.width = width
canvas.height = height
const canvas = getTempCanvas(width, height)
const context = canvas.getContext('2d')
context.putImageData(new ImageData(new Uint8ClampedArray(data), width, height), 0, 0)
this.$refs.canvas.getContext('2d').drawImage(canvas, x, y, width, height)
canvas.height = canvas.width = 0
} catch (error) {
UniViewJSBridge.publishHandler('onCanvasMethodCallback', {
callbackId,
......@@ -475,91 +487,92 @@ export default {
errMsg: 'canvasPutImageData:ok'
}
}, this.$page.id)
},
getDataUrl ({
x = 0,
y = 0,
width,
height,
destWidth,
destHeight,
hidpi = true,
fileType,
qualit,
callbackId
}) {
let res = this.getImageData({
x,
y,
width,
height,
destWidth,
destHeight,
hidpi
})
if (!res.data || !res.data.length) {
UniViewJSBridge.publishHandler('onCanvasMethodCallback', {
callbackId,
data: {
errMsg: 'canvasGetDataUrl:fail'
}
}, this.$page.id)
return
}
let imgData
try {
imgData = new ImageData(new Uint8ClampedArray(res.data), res.width, res.height)
} catch (error) {
UniViewJSBridge.publishHandler('onCanvasMethodCallback', {
callbackId,
data: {
errMsg: 'canvasGetDataUrl:fail'
}
}, this.$page.id)
return
}
destWidth = res.width
destHeight = res.height
const canvas = document.createElement('canvas')
canvas.width = destWidth
canvas.height = destHeight
const c2d = canvas.getContext('2d')
c2d.putImageData(imgData, 0, 0)
let base64 = canvas.toDataURL('image/png')
const img = new Image()
img.onload = () => {
if (fileType === 'jpeg') {
c2d.fillStyle = '#fff'
c2d.fillRect(0, 0, destWidth, destHeight)
}
c2d.drawImage(img, 0, 0)
base64 = canvas.toDataURL(`image/${fileType}`, qualit)
UniViewJSBridge.publishHandler('onCanvasMethodCallback', {
callbackId,
data: {
errMsg: 'canvasGetDataUrl:ok',
base64: base64
}
}, this.$page.id)
}
img.src = base64
},
getDataUrl ({
x = 0,
y = 0,
width,
height,
destWidth,
destHeight,
hidpi = true,
fileType,
qualit,
callbackId
}) {
let res = this.getImageData({
x,
y,
width,
height,
destWidth,
destHeight,
hidpi
})
if (!res.data || !res.data.length) {
UniViewJSBridge.publishHandler('onCanvasMethodCallback', {
callbackId,
data: {
errMsg: 'canvasGetDataUrl:fail'
}
}, this.$page.id)
return
}
let imgData
try {
imgData = new ImageData(new Uint8ClampedArray(res.data), res.width, res.height)
} catch (error) {
UniViewJSBridge.publishHandler('onCanvasMethodCallback', {
callbackId,
data: {
errMsg: 'canvasGetDataUrl:fail'
}
}, this.$page.id)
return
}
destWidth = res.width
destHeight = res.height
const canvas = getTempCanvas(destWidth, destHeight)
const c2d = canvas.getContext('2d')
c2d.putImageData(imgData, 0, 0)
let base64 = canvas.toDataURL('image/png')
canvas.height = canvas.width = 0
const img = new Image()
img.onload = () => {
const canvas = getTempCanvas(destWidth, destHeight)
if (fileType === 'jpeg') {
c2d.fillStyle = '#fff'
c2d.fillRect(0, 0, destWidth, destHeight)
}
c2d.drawImage(img, 0, 0)
base64 = canvas.toDataURL(`image/${fileType}`, qualit)
canvas.height = canvas.width = 0
UniViewJSBridge.publishHandler('onCanvasMethodCallback', {
callbackId,
data: {
errMsg: 'canvasGetDataUrl:ok',
base64: base64
}
}, this.$page.id)
}
img.src = base64
}
}
}
</script>
<style>
uni-canvas {
width: 300px;
height: 150px;
display: block;
position: relative;
}
uni-canvas {
width: 300px;
height: 150px;
display: block;
position: relative;
}
uni-canvas>canvas {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
uni-canvas > canvas {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
</style>
......@@ -81,7 +81,7 @@ function updateView () {
)
}
window.addEventListener('resize', updateView)
window.addEventListener('resize', updateView)
window.addEventListener('updateview', updateView)
function vdSync ({
......@@ -119,7 +119,9 @@ function getData (id, name) {
function getChangeData (id, name) {
try {
const value = this.$r[id][name]
this.$set(this.wxsProps, name.replace('change:', ''), value)
const wxsPropName = name.replace('change:', '')
this[wxsPropName] = value
this.$set(this.wxsProps, wxsPropName, value)
return value
} catch (e) {
console.error(this.$options.__file + `:[${this._$id}]$r[${id}][${name}] is undefined`)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册