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

feat(v3): getRealPath

上级 560ec7ad
......@@ -1054,8 +1054,20 @@ var serviceContext = (function () {
const SCHEME_RE = /^([a-z-]+:)?\/\//i;
const DATA_RE = /^data:.*,.*/;
// 处理 Android 平台解压与非解压模式下获取的路径不一致的情况
function handleLocalPath (filePath) {
return plus.io.convertLocalFileSystemURL(filePath)
.replace(/^\/?apps\//, '/android_asset/apps/')
.replace(/\/$/, '')
}
let wwwPath;
function addBase (filePath) {
return filePath
if (!wwwPath) { // 需要时,初始化一次,外部直接初始化,需要等 plusready
wwwPath = 'file://' + handleLocalPath('_www') + '/';
}
return wwwPath + filePath
}
function getRealPath (filePath) {
......@@ -1071,6 +1083,11 @@ var serviceContext = (function () {
return filePath
}
// _do=>_doc,_documents,_downloads
if (filePath.indexOf('_www') === 0 || filePath.indexOf('_do') === 0) {
return 'file://' + handleLocalPath(filePath)
}
const pages = getCurrentPages();
if (pages.length) {
return addBase(getRealRoute(pages[pages.length - 1].$page.route, filePath).substr(1))
......
此差异已折叠。
......@@ -5,6 +5,9 @@
<meta charset="UTF-8" />
<script>
var __UniViewStartTime__ = Date.now();
document.addEventListener('DOMContentLoaded', function() {
document.documentElement.style.fontSize = document.documentElement.clientWidth / 20 + 'px'
})
var coverSupport = 'CSS' in window && typeof CSS.supports === 'function' && (CSS.supports('top: env(a)') ||
CSS.supports('top: constant(a)'))
document.write(
......@@ -12,16 +15,6 @@
(coverSupport ? ', viewport-fit=cover' : '') + '" />')
</script>
<title>View</title>
<style>
* {
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
-webkit-tap-highlight-color: transparent;
}
input[type="search"i]::-webkit-search-cancel-button {
display: none;
}
</style>
<link rel="stylesheet" href="view.css" />
</head>
......
......@@ -60,8 +60,8 @@ describe('codegen', () => {
})
it('generate text with multiple statements', () => {
assertCodegen(
'<div>A{{ d | e | f }}B{{text}}C</div>',
`with(this){return _c('div',[_v((_$s(0,'t0',_s(_f("f")(_f("e")(d)))))+(_$s(0,'t1',_s(text))))])}`
`<div :id="'a'+b">A{{ d | e | f }}B{{text}}C</div>`,
`with(this){return _c('div',{attrs:{"id":_$s(0,'a-id','a'+b),"_i":0}},[_v((_$s(0,'t0',_s(_f("f")(_f("e")(d)))))+(_$s(0,'t1',_s(text))))])}`
)
})
......
const compiler = require('../lib')
const res = compiler.compile(
`
<div><block v-for="item in items"><div></div><div></div></block></div>
<div :id="'a'+b">A{{ d | e | f }}B{{text}}C</div>
`, {
resourcePath: '/User/fxy/Documents/test.wxml',
isReservedTag: function (tag) {
......
const VARS = ['true', 'false', 'null']
const NUMBER_RE = /^-?\d*(\.\d+)?$/
const {
parseExpression
} = require('@babel/parser')
const t = require('@babel/types')
const ID = '_i'
const ITERATOR1 = '$1'
......@@ -16,12 +18,12 @@ function isVar (str) {
if (!str) {
return false
}
const firstLetter = str[0]
const expr = parseExpression(str)
if (
firstLetter === '"' || // string
firstLetter === '\'' || // string
VARS.includes(str) || // boolean | null
NUMBER_RE.test(str) // number
t.isStringLiteral(expr) ||
t.isNumericLiteral(expr) ||
t.isBooleanLiteral(expr) ||
t.isNullLiteral(expr)
) {
return false
}
......
......@@ -3,8 +3,20 @@ import getRealRoute from 'uni-helpers/get-real-route'
const SCHEME_RE = /^([a-z-]+:)?\/\//i
const DATA_RE = /^data:.*,.*/
// 处理 Android 平台解压与非解压模式下获取的路径不一致的情况
function handleLocalPath (filePath) {
return plus.io.convertLocalFileSystemURL(filePath)
.replace(/^\/?apps\//, '/android_asset/apps/')
.replace(/\/$/, '')
}
let wwwPath
function addBase (filePath) {
return filePath
if (!wwwPath) { // 需要时,初始化一次,外部直接初始化,需要等 plusready
wwwPath = 'file://' + handleLocalPath('_www') + '/'
}
return wwwPath + filePath
}
export default function getRealPath (filePath) {
......@@ -20,6 +32,11 @@ export default function getRealPath (filePath) {
return filePath
}
// _do=>_doc,_documents,_downloads
if (filePath.indexOf('_www') === 0 || filePath.indexOf('_do') === 0) {
return 'file://' + handleLocalPath(filePath)
}
const pages = getCurrentPages()
if (pages.length) {
return addBase(getRealRoute(pages[pages.length - 1].$page.route, filePath).substr(1))
......
......@@ -11,16 +11,12 @@ export function initEvent (Vue) {
})
Vue.prototype.$handleVModelEvent = function (nid, value) {
vd.addUIEvent(this._$id, nid, {
vd.sendUIEvent(this._$id, nid, {
type: 'input',
target: {
value
}
})
// 使用 setTimeout 做批量同步
setTimeout(() => {
vd.sendUIEvent()
}, 0)
}
Vue.prototype.$handleViewEvent = function ($vueEvent, options) {
......@@ -39,11 +35,7 @@ export function initEvent (Vue) {
delete $event.preventDefault
delete $event.stopPropagation
delete $event.options
vd.addUIEvent(cid, nid, $event)
// 使用 setTimeout 做批量同步
setTimeout(() => {
vd.sendUIEvent()
}, 0)
// 实时发送,延迟的话,会导致 touch 类事件被合并,影响实际业务逻辑,比如 touchstart 中修改变量为 true,touchend 修改为 false
vd.sendUIEvent(cid, nid, $event)
}
}
......@@ -13,8 +13,6 @@ export class VDomSync {
this.addBatchVData = []
this.updateBatchVData = []
this.vms = Object.create(null)
this.uiEventBatchData = []
}
addVData (cid, data = {}) {
......@@ -37,22 +35,17 @@ export class VDomSync {
this.vms[vm._$id] = vm
}
addUIEvent (cid, nid, event) {
this.uiEventBatchData.push([cid, nid, event])
}
sendUIEvent () {
if (this.uiEventBatchData.length) {
sendUIEvent (cid, nid, event) {
UniViewJSBridge.publishHandler(VD_SYNC, {
data: [
[UI_EVENT, this.uiEventBatchData]
[UI_EVENT, [
[cid, nid, event]
]]
],
options: {
timestamp: Date.now()
}
})
this.uiEventBatchData.length = 0
}
}
flush () {
......
* {
margin: 0;
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
-webkit-tap-highlight-color: transparent;
}
input[type="search"]::-webkit-search-cancel-button {
display: none;
}
@font-face {
font-weight: normal;
font-style: normal;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册