Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
20岁爱吃必胜客
uni-app
提交
51f5cc39
U
uni-app
项目概览
20岁爱吃必胜客
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
51f5cc39
编写于
10月 23, 2019
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor(v3): v-model(view)
上级
5518728d
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
68 addition
and
31 deletion
+68
-31
packages/uni-app-plus/dist/index.v3.js
packages/uni-app-plus/dist/index.v3.js
+12
-12
packages/uni-app-plus/dist/service.runtime.esm.js
packages/uni-app-plus/dist/service.runtime.esm.js
+6
-7
packages/uni-app-plus/dist/view.umd.js
packages/uni-app-plus/dist/view.umd.js
+16
-1
packages/uni-template-compiler/__tests__/compiler-app-plus.view.spec.js
...emplate-compiler/__tests__/compiler-app-plus.view.spec.js
+3
-3
packages/uni-template-compiler/__tests__/demo.js
packages/uni-template-compiler/__tests__/demo.js
+2
-2
packages/uni-template-compiler/lib/app/view.js
packages/uni-template-compiler/lib/app/view.js
+13
-4
src/platforms/app-plus/view/framework/plugins/event.js
src/platforms/app-plus/view/framework/plugins/event.js
+16
-2
未找到文件。
packages/uni-app-plus/dist/index.v3.js
浏览文件 @
51f5cc39
...
...
@@ -9147,17 +9147,17 @@ var serviceContext = (function () {
return
result
}
function
initData
(
Vue
)
{
function
initData
(
Vue
)
{
Vue
.
prototype
.
_$s
=
setData
;
Vue
.
prototype
.
_$i
=
setIfData
;
Vue
.
prototype
.
_$f
=
setForData
;
Vue
.
prototype
.
_$e
=
setElseIfData
;
Vue
.
prototype
.
_$setData
=
function
setData
(
type
,
data
)
{
Vue
.
prototype
.
_$setData
=
function
setData
(
type
,
data
)
{
this
.
_$vd
.
push
(
type
,
this
.
_$id
,
data
);
};
Vue
.
prototype
.
_$mounted
=
function
mounted
()
{
Vue
.
prototype
.
_$mounted
=
function
mounted
()
{
if
(
!
this
.
_$vd
)
{
return
}
...
...
@@ -9170,7 +9170,7 @@ var serviceContext = (function () {
}
};
Vue
.
prototype
.
_$updated
=
function
updated
()
{
Vue
.
prototype
.
_$updated
=
function
updated
()
{
if
(
!
this
.
_$vd
)
{
return
}
...
...
@@ -9188,13 +9188,13 @@ var serviceContext = (function () {
};
Object
.
defineProperty
(
Vue
.
prototype
,
'
_$vd
'
,
{
get
()
{
get
()
{
return
this
.
$root
.
_$vdomSync
}
});
Vue
.
mixin
({
beforeCreate
()
{
beforeCreate
()
{
if
(
this
.
$options
.
mpType
)
{
this
.
mpType
=
this
.
$options
.
mpType
;
}
...
...
@@ -9214,7 +9214,7 @@ var serviceContext = (function () {
this
.
_$newData
=
Object
.
create
(
null
);
}
},
beforeUpdate
()
{
beforeUpdate
()
{
if
(
!
this
.
_$vd
)
{
return
}
...
...
@@ -9223,7 +9223,7 @@ var serviceContext = (function () {
console
.
log
(
`[
${
this
.
_$id
}
] beforeUpdate `
+
Date
.
now
());
this
.
_$newData
=
Object
.
create
(
null
);
},
beforeDestroy
()
{
beforeDestroy
()
{
if
(
!
this
.
_$vd
)
{
return
}
...
...
@@ -9233,7 +9233,7 @@ var serviceContext = (function () {
});
}
function
setData
(
id
,
name
,
value
)
{
function
setData
(
id
,
name
,
value
)
{
switch
(
name
)
{
case
B_CLASS
:
value
=
this
.
_$stringifyClass
(
value
);
...
...
@@ -9253,7 +9253,7 @@ var serviceContext = (function () {
return
((
this
.
_$newData
[
id
]
||
(
this
.
_$newData
[
id
]
=
{}))[
name
]
=
value
)
}
function
setForData
(
id
,
value
)
{
function
setForData
(
id
,
value
)
{
const
diffData
=
this
.
_$newData
[
id
]
||
(
this
.
_$newData
[
id
]
=
{});
const
vForData
=
diffData
[
V_FOR
]
||
(
diffData
[
V_FOR
]
=
[]);
...
...
@@ -9274,11 +9274,11 @@ var serviceContext = (function () {
return
key
}
function
setIfData
(
id
,
value
)
{
function
setIfData
(
id
,
value
)
{
return
((
this
.
_$newData
[
id
]
||
(
this
.
_$newData
[
id
]
=
{}))[
V_IF
]
=
!!
value
)
}
function
setElseIfData
(
id
,
value
)
{
function
setElseIfData
(
id
,
value
)
{
return
((
this
.
_$newData
[
id
]
||
(
this
.
_$newData
[
id
]
=
{}))[
V_ELSE_IF
]
=
!!
value
)
}
...
...
packages/uni-app-plus/dist/service.runtime.esm.js
浏览文件 @
51f5cc39
...
...
@@ -6691,14 +6691,13 @@ var modules = platformModules.concat(baseModules);
var
patch
=
createPatchFunction
({
nodeOps
:
nodeOps
,
modules
:
modules
});
var
show
=
{
bind
:
function
bind
()
{},
update
:
function
update
()
{},
unbind
:
function
unbind
()
{}
};
var
model$1
=
{};
var
show
=
{};
var
platformDirectives
=
{
show
:
show
var
platformDirectives
=
{
model
:
model$1
,
show
:
show
};
var
platformComponents
=
{
...
...
packages/uni-app-plus/dist/view.umd.js
浏览文件 @
51f5cc39
...
...
@@ -13115,11 +13115,26 @@ function initEvent(Vue) {
}
});
Vue.prototype.$handleVModelEvent = function (nid, value) {
data["b" /* vd */].addUIEvent(this._$id, nid, {
type: 'input',
target: {
value: value
}
}); // 使用 setTimeout 做批量同步
setTimeout(function () {
data["b" /* vd */].sendUIEvent();
}, 0);
};
Vue.prototype.$handleViewEvent = function ($vueEvent, options) {
var isCustomEvent = $vueEvent._processed; // 自定义事件已提前处理过
var $event = this.$handleEvent($vueEvent);
var cid = this._$id; // 当自定义组件根节点触发事件时,nid 始终为 0
var nid = $vueEvent.currentTarget === this.$el ? 0 : $event.options.nid;
var nid =
isCustomEvent ||
$vueEvent.currentTarget === this.$el ? 0 : $event.options.nid;
if (typeof nid === 'undefined') {
return console.error("[".concat(cid, "] nid not found"));
...
...
packages/uni-template-compiler/__tests__/compiler-app-plus.view.spec.js
浏览文件 @
51f5cc39
...
...
@@ -141,21 +141,21 @@ describe('codegen', () => {
it
(
'
generate v-model directive
'
,
()
=>
{
assertCodegen
(
'
<input v-model="test">
'
,
`with(this){return _c('v-uni-input',{attrs:{"_i":0},model:{value:
(_$g(0,'v-model')),callback:function ($$v) {},expression:"_$g(0,'v-model')
"}})}`
`with(this){return _c('v-uni-input',{attrs:{"_i":0},model:{value:
_$g(0,'v-model'),callback:function($$v){$handleVModelEvent(0,$$v)},expression:"test
"}})}`
)
})
it
(
'
generate multiline v-model directive
'
,
()
=>
{
assertCodegen
(
'
<input v-model="
\n
test
\n
">
'
,
`with(this){return _c('v-uni-input',{attrs:{"_i":0},model:{value:
(_$g(0,'v-model')),callback:function ($$v) {},expression:"_$g(0,'v-model')
"}})}`
`with(this){return _c('v-uni-input',{attrs:{"_i":0},model:{value:
_$g(0,'v-model'),callback:function($$v){$handleVModelEvent(0,$$v)},expression:"\\n test \\n
"}})}`
)
})
it
(
'
generate multiline v-model directive on custom component
'
,
()
=>
{
assertCodegen
(
'
<my-component v-model="
\n
test
\n
" />
'
,
`with(this){return _c('my-component',{attrs:{"_i":0},model:{value:
(_$g(0,'v-model')),callback:function ($$v) {},expression:"_$g(0,'v-model')
"}})}`
`with(this){return _c('my-component',{attrs:{"_i":0},model:{value:
_$g(0,'v-model'),callback:function(){},expression:"\\n test \\n
"}})}`
)
})
...
...
packages/uni-template-compiler/__tests__/demo.js
浏览文件 @
51f5cc39
const
compiler
=
require
(
'
../lib
'
)
const
res
=
compiler
.
compile
(
`
<
my-component v-model="\n test \n" /
>
<
input v-model="\n test \n"
>
`
,
{
...
...
@@ -15,7 +15,7 @@ const res = compiler.compile(
mp
:
{
platform
:
'
app-plus
'
},
service
:
true
,
//
service: true,
view
:
true
})
console
.
log
(
require
(
'
util
'
).
inspect
(
res
,
{
...
...
packages/uni-template-compiler/lib/app/view.js
浏览文件 @
51f5cc39
...
...
@@ -83,7 +83,7 @@ function transformNode (el, parent, state) {
parseIf
(
el
,
createGenVar
)
parseBinding
(
el
,
genVar
)
parseDirs
(
el
,
genVar
)
parseDirs
(
el
,
genVar
,
[
'
model
'
]
)
parseAttrs
(
el
,
genVar
)
parseProps
(
el
,
genVar
)
}
...
...
@@ -135,12 +135,21 @@ function handleViewEvents (events) {
})
}
function
genVModel
(
el
)
{
if
(
el
.
model
)
{
el
.
model
.
value
=
createGenVar
(
el
.
attrsMap
[
ID
])(
'
v-model
'
,
el
.
model
.
value
)
if
(
el
.
tag
===
'
v-uni-input
'
||
el
.
tag
===
'
v-uni-textarea
'
)
{
el
.
model
.
callback
=
`function($$v){$handleVModelEvent(
${
el
.
attrsMap
[
ID
]}
,$$v)}`
}
else
{
el
.
model
.
callback
=
`function(){}`
}
}
}
function
genData
(
el
)
{
delete
el
.
$parentIterator3
if
(
el
.
model
)
{
el
.
model
.
callback
=
`function ($$v) {}`
}
genVModel
(
el
)
// 放在 postTransformNode 中处理的时机太靠前,v-model 等指令会新增 event
el
.
events
&&
handleViewEvents
(
el
.
events
)
...
...
src/platforms/app-plus/view/framework/plugins/event.js
浏览文件 @
51f5cc39
...
...
@@ -8,13 +8,27 @@ export function initEvent (Vue) {
get
()
{
return
getCurrentPages
()[
0
].
$page
}
})
})
Vue
.
prototype
.
$handleVModelEvent
=
function
(
nid
,
value
)
{
vd
.
addUIEvent
(
this
.
_$id
,
nid
,
{
type
:
'
input
'
,
target
:
{
value
}
})
// 使用 setTimeout 做批量同步
setTimeout
(()
=>
{
vd
.
sendUIEvent
()
},
0
)
}
Vue
.
prototype
.
$handleViewEvent
=
function
(
$vueEvent
,
options
)
{
const
isCustomEvent
=
$vueEvent
.
_processed
// 自定义事件已提前处理过
const
$event
=
this
.
$handleEvent
(
$vueEvent
)
const
cid
=
this
.
_$id
// 当自定义组件根节点触发事件时,nid 始终为 0
const
nid
=
$vueEvent
.
currentTarget
===
this
.
$el
?
0
:
$event
.
options
.
nid
const
nid
=
isCustomEvent
||
(
$vueEvent
.
currentTarget
===
this
.
$el
)
?
0
:
$event
.
options
.
nid
if
(
typeof
nid
===
'
undefined
'
)
{
return
console
.
error
(
`[
${
cid
}
] nid not found`
)
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录