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

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

# Conflicts:
#	packages/uni-app-plus/dist/index.v3.js
......@@ -42,9 +42,9 @@ export default {
if (vnode.text) {
// 处理可能出现的多余的转义字符
const nodeText = vnode.text.replace(/\\n/g, '\n')
const texts = nodeText.split('\n')
const texts = this._decodeHtml(nodeText).trim().split('\n')
texts.forEach((text, index) => {
nodeList.push(this._decodeHtml(text))
nodeList.push(text)
if (index !== (texts.length - 1)) {
nodeList.push(createElement('br'))
}
......@@ -73,4 +73,4 @@ export default {
user-select: text;
-webkit-user-select: text;
}
</style>
</style>
import {
isPlainObject
looseEqual
} from 'uni-shared'
import {
V_FOR,
B_STYLE
} from '../../constants'
function setResult (data, k, v) {
data[k] = v
}
function diffObject (newObj, oldObj, every = true) {
let result, key, cur, old
for (key in newObj) {
cur = newObj[key]
old = oldObj[key]
if (old !== cur) {
if (!every) {
return newObj
}
setResult(result || (result = Object.create(null)), key, cur)
}
}
return result
}
function diffArray (newArr, oldArr) {
const newLen = newArr.length
if (newLen !== oldArr.length) {
return newArr
}
if (isPlainObject(newArr[0])) {
for (let i = 0; i < newLen; i++) {
if (diffObject(newArr[i], oldArr[i], false)) {
return newArr
}
}
} else {
for (let i = 0; i < newLen; i++) {
if (newArr[i] !== oldArr[i]) {
return newArr
}
}
}
}
function diffElmData (newObj, oldObj) {
let result, key, cur, old
for (key in newObj) {
cur = newObj[key]
old = oldObj[key]
if (old !== cur) {
if (key === B_STYLE && isPlainObject(cur) && isPlainObject(old)) { // 全量同步 style (因为 style 可能会动态删除部分样式)
if (Object.keys(cur).length !== Object.keys(old).length) { // 长度不等
setResult(result || (result = Object.create(null)), B_STYLE, cur)
} else {
const style = diffObject(cur, old, false)
style && setResult(result || (result = Object.create(null)), B_STYLE, style)
}
} else if (key === V_FOR && Array.isArray(cur) && Array.isArray(old)) {
const vFor = diffArray(cur, old)
vFor && setResult(result || (result = Object.create(null)), V_FOR, vFor)
} else {
if (key.indexOf('change:') === 0) { // wxs change:prop
try {
// 先简单的用 stringify 判断
if (JSON.stringify(cur) === JSON.stringify(old)) {
continue
}
} catch (e) {}
}
setResult(result || (result = Object.create(null)), key, cur)
}
if (!looseEqual(old, cur)) {
setResult(result || (result = Object.create(null)), key, cur)
}
}
return result
......
......@@ -32,14 +32,9 @@ let PageVueComponent
const handleData = {
[PAGE_CREATE]: function onPageCreate (data) {
const [pageId, pagePath, pageOptions] = data
document.title = `${pagePath}[${pageId}]`
// 页面存在横竖屏切换时,预加载的 webview 的 fontSize 需要再次校正一下
const oldFontSize = document.documentElement.style.fontSize
const newFontSize = document.documentElement.clientWidth / 20 + 'px'
if (oldFontSize !== newFontSize) {
document.documentElement.style.fontSize = newFontSize
}
document.title = `${pagePath}[${pageId}]`
updateRootFontSize()
// 设置当前页面伪对象,方便其他地方使用 getCurrentPages 获取当前页面 id,route
setCurrentPage(pageId, pagePath)
......@@ -89,7 +84,23 @@ function updateView () {
)
}
window.addEventListener('resize', updateView)
function updateRootFontSize () {
// 页面存在横竖屏切换时,预加载的 webview 的 fontSize 需要再次校正一下
const oldFontSize = document.documentElement.style.fontSize
const newFontSize = document.documentElement.clientWidth / 20 + 'px'
if (oldFontSize !== newFontSize) {
document.documentElement.style.fontSize = newFontSize
}
}
window.addEventListener('resize', () => {
// TODO 与之前逻辑保持一致,仅当前 webview 未被使用时,校准 fontSize,后续考虑动态旋转,调整rootfontSize
if (!getCurrentPages().length) {
updateRootFontSize()
}
updateView()
})
window.addEventListener('updateview', updateView)
function vdSync ({
......
......@@ -96,3 +96,42 @@ export function debounce (fn, delay) {
export function kebabCase (string) {
return string.replace(/[A-Z]/g, str => '-' + str.toLowerCase())
}
/**
* Check if two values are loosely equal - that is,
* if they are plain objects, do they have the same shape?
*/
export function looseEqual (a, b) {
if (a === b) return true
const isObjectA = isObject(a)
const isObjectB = isObject(b)
if (isObjectA && isObjectB) {
try {
const isArrayA = Array.isArray(a)
const isArrayB = Array.isArray(b)
if (isArrayA && isArrayB) {
return a.length === b.length && a.every((e, i) => {
return looseEqual(e, b[i])
})
} else if (a instanceof Date && b instanceof Date) {
return a.getTime() === b.getTime()
} else if (!isArrayA && !isArrayB) {
const keysA = Object.keys(a)
const keysB = Object.keys(b)
return keysA.length === keysB.length && keysA.every(key => {
return looseEqual(a[key], b[key])
})
} else {
/* istanbul ignore next */
return false
}
} catch (e) {
/* istanbul ignore next */
return false
}
} else if (!isObjectA && !isObjectB) {
return String(a) === String(b)
} else {
return false
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册