Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-app
提交
5518728d
U
uni-app
项目概览
DCloud
/
uni-app
4 个月 前同步成功
通知
730
Star
38707
Fork
3642
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
7
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
7
Issue
7
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
5518728d
编写于
10月 23, 2019
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(v3): v-model
上级
62fb0d52
变更
13
展开全部
隐藏空白更改
内联
并排
Showing
13 changed file
with
160 addition
and
130 deletion
+160
-130
packages/uni-app-plus/dist/index.v3.js
packages/uni-app-plus/dist/index.v3.js
+16
-26
packages/uni-template-compiler/__tests__/compiler-app-plus.service.spec.js
...late-compiler/__tests__/compiler-app-plus.service.spec.js
+51
-51
packages/uni-template-compiler/__tests__/demo.js
packages/uni-template-compiler/__tests__/demo.js
+3
-1
packages/uni-template-compiler/lib/app/parser/base-parser.js
packages/uni-template-compiler/lib/app/parser/base-parser.js
+5
-3
packages/uni-template-compiler/lib/app/pre-transform-node.js
packages/uni-template-compiler/lib/app/pre-transform-node.js
+3
-3
packages/uni-template-compiler/lib/app/service.js
packages/uni-template-compiler/lib/app/service.js
+15
-12
packages/uni-template-compiler/lib/app/util.js
packages/uni-template-compiler/lib/app/util.js
+50
-4
packages/uni-template-compiler/lib/util.js
packages/uni-template-compiler/lib/util.js
+1
-6
packages/vue-cli-plugin-uni/packages/vue-template-compiler/browser.js
...-cli-plugin-uni/packages/vue-template-compiler/browser.js
+4
-0
packages/vue-cli-plugin-uni/packages/vue-template-compiler/build.js
...ue-cli-plugin-uni/packages/vue-template-compiler/build.js
+4
-0
packages/webpack-uni-pages-loader/lib/platforms/app-plus/index.js
.../webpack-uni-pages-loader/lib/platforms/app-plus/index.js
+1
-1
src/platforms/app-plus/service/framework/plugins/data.js
src/platforms/app-plus/service/framework/plugins/data.js
+6
-4
src/platforms/app-plus/service/publish-handler.js
src/platforms/app-plus/service/publish-handler.js
+1
-19
未找到文件。
packages/uni-app-plus/dist/index.v3.js
浏览文件 @
5518728d
...
...
@@ -8598,19 +8598,8 @@ var serviceContext = (function () {
}
});
function
optimize
(
k
,
v
)
{
if
(
k
===
V_IF
||
k
===
V_ELSE_IF
||
k
===
V_SHOW
)
{
return
v
?
1
:
0
}
return
v
}
function
publishHandler
(
eventType
,
args
,
pageIds
)
{
args
=
JSON
.
stringify
(
args
,
optimize
);
args
=
JSON
.
stringify
(
args
);
if
(
process
.
env
.
NODE_ENV
!==
'
production
'
)
{
console
.
log
(
`UNIAPP[publishHandler]:[
${
+
new
Date
()}
]`
,
eventType
,
args
,
pageIds
);
}
...
...
@@ -9158,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
}
...
...
@@ -9181,7 +9170,7 @@ var serviceContext = (function () {
}
};
Vue
.
prototype
.
_$updated
=
function
updated
()
{
Vue
.
prototype
.
_$updated
=
function
updated
()
{
if
(
!
this
.
_$vd
)
{
return
}
...
...
@@ -9199,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
;
}
...
...
@@ -9225,7 +9214,7 @@ var serviceContext = (function () {
this
.
_$newData
=
Object
.
create
(
null
);
}
},
beforeUpdate
()
{
beforeUpdate
()
{
if
(
!
this
.
_$vd
)
{
return
}
...
...
@@ -9234,7 +9223,7 @@ var serviceContext = (function () {
console
.
log
(
`[
${
this
.
_$id
}
] beforeUpdate `
+
Date
.
now
());
this
.
_$newData
=
Object
.
create
(
null
);
},
beforeDestroy
()
{
beforeDestroy
()
{
if
(
!
this
.
_$vd
)
{
return
}
...
...
@@ -9244,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
);
...
...
@@ -9252,9 +9241,10 @@ var serviceContext = (function () {
case
B_STYLE
:
value
=
this
.
_$normalizeStyleBinding
(
value
);
break
case
V_IF
:
case
V_IF
:
case
V_SHOW
:
case
V_ELSE_IF
:
value
=
!!
value
;
value
=
value
?
1
:
0
;
break
case
V_FOR
:
return
setForData
.
call
(
this
,
id
,
value
)
...
...
@@ -9263,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
]
=
[]);
...
...
@@ -9284,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-template-compiler/__tests__/compiler-app-plus.service.spec.js
浏览文件 @
5518728d
此差异已折叠。
点击以展开。
packages/uni-template-compiler/__tests__/demo.js
浏览文件 @
5518728d
...
...
@@ -2,6 +2,8 @@ const compiler = require('../lib')
const
res
=
compiler
.
compile
(
`
<my-component v-model="\n test \n" />
`
,
{
resourcePath
:
'
/User/fxy/Documents/test.wxml
'
,
isReservedTag
:
function
(
tag
)
{
...
...
@@ -19,4 +21,4 @@ const res = compiler.compile(
console
.
log
(
require
(
'
util
'
).
inspect
(
res
,
{
colors
:
true
,
depth
:
null
}))
}))
packages/uni-template-compiler/lib/app/parser/base-parser.js
浏览文件 @
5518728d
...
...
@@ -32,10 +32,12 @@ function parseBinding (el, genVar) {
el
.
styleBinding
&&
(
el
.
styleBinding
=
genVar
(
'
s
'
,
el
.
styleBinding
))
}
function
parseDirs
(
el
,
genVar
)
{
function
parseDirs
(
el
,
genVar
,
ignoreDirs
=
[]
)
{
el
.
directives
&&
el
.
directives
.
forEach
(
dir
=>
{
dir
.
value
&&
(
dir
.
value
=
genVar
(
'
v-
'
+
dir
.
name
,
dir
.
value
))
dir
.
isDynamicArg
&&
(
dir
.
arg
=
genVar
(
'
v-
'
+
dir
.
name
+
'
-arg
'
,
dir
.
arg
))
if
(
ignoreDirs
.
indexOf
(
dir
.
name
)
===
-
1
)
{
dir
.
value
&&
(
dir
.
value
=
genVar
(
'
v-
'
+
dir
.
name
,
dir
.
value
))
dir
.
isDynamicArg
&&
(
dir
.
arg
=
genVar
(
'
v-
'
+
dir
.
name
+
'
-arg
'
,
dir
.
arg
))
}
})
}
...
...
packages/uni-template-compiler/lib/app/pre-transform-node.js
浏览文件 @
5518728d
const
{
ID
,
hasOwn
,
addAttr
add
Raw
Attr
}
=
require
(
'
./util
'
)
module
.
exports
=
function
preTransformNode
(
el
,
options
)
{
module
.
exports
=
function
preTransformNode
(
el
,
options
)
{
if
(
!
hasOwn
(
options
,
'
nid
'
))
{
options
.
nid
=
0
}
addAttr
(
el
,
ID
,
options
.
nid
++
)
add
Raw
Attr
(
el
,
ID
,
options
.
nid
++
)
if
(
el
.
attrsMap
[
'
v-for
'
])
{
el
.
forId
=
el
.
attrsMap
[
ID
]
}
...
...
packages/uni-template-compiler/lib/app/service.js
浏览文件 @
5518728d
...
...
@@ -26,7 +26,7 @@ const {
const
parseEvent
=
require
(
'
./parser/event-parser
'
)
const
parseBlock
=
require
(
'
./parser/block-parser
'
)
const
baseP
reTransformNode
=
require
(
'
./pre-transform-node
'
)
const
p
reTransformNode
=
require
(
'
./pre-transform-node
'
)
const
optimize
=
require
(
'
./optimizer
'
)
...
...
@@ -87,7 +87,7 @@ function transformNode (el, parent, state) {
parseIf
(
el
,
createGenVar
)
parseBinding
(
el
,
genVar
)
parseDirs
(
el
,
genVar
)
parseDirs
(
el
,
genVar
,
[
'
model
'
]
)
if
(
!
isComponent
(
el
.
tag
))
{
parseAttrs
(
el
,
genVar
)
...
...
@@ -106,27 +106,30 @@ function postTransformNode (el, options) {
}
}
function
parseTag
(
el
)
{
if
(
el
.
tag
===
'
input
'
||
el
.
tag
===
'
textarea
'
)
{
el
.
tag
=
`c-
${
el
.
tag
.
substr
(
0
,
1
)}
`
// 返回一个自定义组件标签,保证 v-model
function
genVModel
(
el
)
{
if
(
(
el
.
tag
===
'
input
'
||
el
.
tag
===
'
textarea
'
)
&&
el
.
directives
&&
el
.
directives
.
find
(
dir
=>
dir
.
name
===
'
model
'
)
)
{
const
prop
=
el
.
props
.
find
(
prop
=>
prop
.
name
===
'
value
'
)
prop
.
value
=
createGenVar
(
el
.
attrsMap
[
ID
])(
'
v-model
'
,
prop
.
value
)
}
if
(
el
.
model
)
{
el
.
model
.
value
=
createGenVar
(
el
.
attrsMap
[
ID
])(
'
v-model
'
,
el
.
model
.
value
)
}
}
function
genData
(
el
)
{
delete
el
.
$parentIterator3
if
(
el
.
model
)
{
el
.
model
.
callback
=
`function ($$v) {}`
}
genVModel
(
el
)
return
''
}
module
.
exports
=
{
preTransformNode
:
function
(
el
,
options
)
{
parseTag
(
el
)
return
basePreTransformNode
(
el
,
options
)
},
preTransformNode
,
postTransformNode
,
genData
}
packages/uni-template-compiler/lib/app/util.js
浏览文件 @
5518728d
...
...
@@ -28,7 +28,7 @@ function isVar (str) {
return
true
}
function
addAttr
(
el
,
name
,
value
)
{
function
add
Raw
Attr
(
el
,
name
,
value
)
{
el
.
attrsMap
[
name
]
=
value
el
.
attrsList
.
push
({
name
,
...
...
@@ -42,7 +42,7 @@ function updateEleId (el, it, state) {
}
const
id
=
el
.
attrsMap
[
ID
]
const
newId
=
Number
.
isInteger
(
id
)
?
`("
${
id
}
-"+
${
it
}
)`
:
`(
${
id
}
+
${
it
}
)`
addAttr
(
el
,
ID
,
newId
)
add
Raw
Attr
(
el
,
ID
,
newId
)
const
attr
=
el
.
attrs
.
find
(
attr
=>
attr
.
name
===
ID
)
attr
.
value
=
newId
el
.
children
.
forEach
(
child
=>
{
...
...
@@ -121,7 +121,7 @@ function processForKey (el) {
const
keyIndex
=
forEl
.
children
.
indexOf
(
el
)
el
.
key
=
`
${
forEl
.
forId
}
+'-
${
keyIndex
}
'+
${
it
}
`
}
else
{
// 当 template 下只有文本节点
if
(
el
.
children
&&
el
.
children
.
length
&&
!
el
.
children
.
find
(
child
=>
child
.
key
))
{
if
(
el
.
children
&&
el
.
children
.
length
&&
!
el
.
children
.
find
(
child
=>
child
.
key
))
{
el
.
children
[
0
].
parent
=
el
el
.
children
[
0
].
key
=
`
${
forEl
.
forId
}
+'-0'+
${
it
}
`
return
true
...
...
@@ -146,17 +146,63 @@ function traverseNode (el, parent, state) {
el
.
scopedSlots
&&
Object
.
values
(
el
.
scopedSlots
).
forEach
(
slot
=>
traverseNode
(
slot
,
el
,
state
))
}
function
addAttr
(
el
,
name
,
value
,
dynamic
)
{
const
attrs
=
dynamic
?
(
el
.
dynamicAttrs
||
(
el
.
dynamicAttrs
=
[]))
:
(
el
.
attrs
||
(
el
.
attrs
=
[]))
attrs
.
push
({
name
,
value
,
dynamic
})
el
.
plain
=
false
}
function
removeRawAttr
(
el
,
name
)
{
delete
el
.
attrsMap
[
name
]
const
index
=
el
.
attrsList
.
findIndex
(
attr
=>
attr
.
name
===
name
)
index
!==
-
1
&&
el
.
attrsList
.
splice
(
index
,
1
)
}
function
removeRawBindingAttr
(
el
,
name
)
{
removeRawAttr
(
el
,
'
:
'
+
name
)
removeRawAttr
(
el
,
'
v-bind:
'
+
name
)
console
.
log
(
el
)
throw
new
Error
(
'
123
'
)
}
function
addHandler
(
el
,
name
,
value
,
important
)
{
const
events
=
el
.
events
||
(
el
.
events
=
{})
const
handlers
=
events
[
name
]
const
newHandler
=
{
value
:
value
.
trim
(),
dynamic
:
undefined
}
if
(
Array
.
isArray
(
handlers
))
{
important
?
handlers
.
unshift
(
newHandler
)
:
handlers
.
push
(
newHandler
)
}
else
if
(
handlers
)
{
events
[
name
]
=
important
?
[
newHandler
,
handlers
]
:
[
handlers
,
newHandler
]
}
else
{
events
[
name
]
=
newHandler
}
el
.
plain
=
false
}
module
.
exports
=
{
V_FOR
,
V_IF
,
V_ELSE_IF
,
ID
,
ID
,
SET_DATA
,
GET_DATA
,
isVar
,
hasOwn
,
addAttr
,
addRawAttr
,
removeRawAttr
,
removeRawBindingAttr
,
getForEl
,
addHandler
,
processForKey
,
updateForEleId
,
getBindingAttr
,
...
...
packages/uni-template-compiler/lib/util.js
浏览文件 @
5518728d
...
...
@@ -183,12 +183,7 @@ const {
}
=
require
(
'
./h5
'
)
function
isComponent
(
tagName
)
{
if
(
tagName
===
'
block
'
||
tagName
===
'
template
'
||
tagName
===
'
c-i
'
||
// v3 service input => c-i
tagName
===
'
c-t
'
// v3 service textarea => c-t
)
{
if
(
tagName
===
'
block
'
||
tagName
===
'
template
'
)
{
return
false
}
return
!
hasOwn
(
tags
,
getTagName
(
tagName
.
replace
(
'
v-uni-
'
,
''
)))
...
...
packages/vue-cli-plugin-uni/packages/vue-template-compiler/browser.js
浏览文件 @
5518728d
...
...
@@ -3696,6 +3696,10 @@
return
}
if
(
process
.
env
.
UNI_PLATFORM
!==
'
h5
'
){
// fixed by xxxxxx 非 h5 平台 type 不会是 checkbox,radio
return
}
var
typeBinding
;
if
(
map
[
'
:type
'
]
||
map
[
'
v-bind:type
'
])
{
typeBinding
=
getBindingAttr
(
el
,
'
type
'
);
...
...
packages/vue-cli-plugin-uni/packages/vue-template-compiler/build.js
浏览文件 @
5518728d
...
...
@@ -3318,6 +3318,10 @@ function preTransformNode (el, options) {
return
}
if
(
process
.
env
.
UNI_PLATFORM
!==
'
h5
'
){
// fixed by xxxxxx 非 h5 平台 type 不会是 checkbox,radio
return
}
var
typeBinding
;
if
(
map
[
'
:type
'
]
||
map
[
'
v-bind:type
'
])
{
typeBinding
=
getBindingAttr
(
el
,
'
type
'
);
...
...
packages/webpack-uni-pages-loader/lib/platforms/app-plus/index.js
浏览文件 @
5518728d
...
...
@@ -213,7 +213,7 @@ module.exports = function (pagesJson, userManifestJson) {
let
flexDir
=
false
if
(
manifestJson
.
plus
.
nvueCompiler
&&
manifestJson
.
plus
.
nvueCompiler
===
'
uni-app
'
)
{
if
(
process
.
env
.
UNI_USING_NVUE_COMPILER
)
{
appJson
.
nvueCompiler
=
'
uni-app
'
flexDir
=
getFlexDirection
(
manifestJson
.
plus
)
}
else
{
...
...
src/platforms/app-plus/service/framework/plugins/data.js
浏览文件 @
5518728d
...
...
@@ -14,7 +14,8 @@ import {
import
{
V_IF
,
V_FOR
,
V_FOR
,
V_SHOW
,
V_ELSE_IF
,
B_CLASS
,
B_STYLE
...
...
@@ -110,7 +111,7 @@ export function initData (Vue) {
})
}
function
setData
(
id
,
name
,
value
)
{
function
setData
(
id
,
name
,
value
)
{
switch
(
name
)
{
case
B_CLASS
:
value
=
this
.
_$stringifyClass
(
value
)
...
...
@@ -118,9 +119,10 @@ function setData (id, name, value) {
case
B_STYLE
:
value
=
this
.
_$normalizeStyleBinding
(
value
)
break
case
V_IF
:
case
V_IF
:
case
V_SHOW
:
case
V_ELSE_IF
:
value
=
!!
value
value
=
value
?
1
:
0
break
case
V_FOR
:
return
setForData
.
call
(
this
,
id
,
value
)
...
...
src/platforms/app-plus/service/publish-handler.js
浏览文件 @
5518728d
import
{
V_IF
,
V_ELSE_IF
,
V_SHOW
}
from
'
./constants
'
function
optimize
(
k
,
v
)
{
if
(
k
===
V_IF
||
k
===
V_ELSE_IF
||
k
===
V_SHOW
)
{
return
v
?
1
:
0
}
return
v
}
export
function
publishHandler
(
eventType
,
args
,
pageIds
)
{
args
=
JSON
.
stringify
(
args
,
optimize
)
args
=
JSON
.
stringify
(
args
)
if
(
process
.
env
.
NODE_ENV
!==
'
production
'
)
{
console
.
log
(
`UNIAPP[publishHandler]:[
${
+
new
Date
()}
]`
,
eventType
,
args
,
pageIds
)
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录