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

feat(v3): getRealPath

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