Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
20岁爱吃必胜客
uni-app
提交
9e5c0d33
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,发现更多精彩内容 >>
提交
9e5c0d33
编写于
12月 06, 2019
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(v3): mp runtime
上级
5e9f0482
变更
14
隐藏空白更改
内联
并排
Showing
14 changed file
with
162 addition
and
91 deletion
+162
-91
packages/uni-app-plus/dist/service.runtime.esm.js
packages/uni-app-plus/dist/service.runtime.esm.js
+3
-0
packages/uni-migration/__tests__/demo.js
packages/uni-migration/__tests__/demo.js
+1
-1
packages/uni-migration/__tests__/wxml.spec.js
packages/uni-migration/__tests__/wxml.spec.js
+1
-1
packages/uni-migration/lib/index.js
packages/uni-migration/lib/index.js
+2
-1
packages/uni-migration/lib/mp-weixin/patch.js
packages/uni-migration/lib/mp-weixin/patch.js
+30
-18
packages/uni-migration/lib/mp-weixin/transform/template-transformer/transform/traverse.js
...ixin/transform/template-transformer/transform/traverse.js
+8
-4
packages/uni-mp-weixin/dist/mp.js
packages/uni-mp-weixin/dist/mp.js
+46
-27
packages/vue-cli-plugin-uni/lib/app-plus/index.js
packages/vue-cli-plugin-uni/lib/app-plus/index.js
+3
-2
src/core/runtime/mp/index.js
src/core/runtime/mp/index.js
+7
-1
src/core/runtime/mp/polyfill/index.js
src/core/runtime/mp/polyfill/index.js
+1
-8
src/core/runtime/mp/polyfill/methods.js
src/core/runtime/mp/polyfill/methods.js
+6
-0
src/core/runtime/mp/polyfill/state/data.js
src/core/runtime/mp/polyfill/state/data.js
+41
-0
src/core/runtime/mp/polyfill/state/index.js
src/core/runtime/mp/polyfill/state/index.js
+5
-20
src/core/runtime/mp/polyfill/state/properties.js
src/core/runtime/mp/polyfill/state/properties.js
+8
-8
未找到文件。
packages/uni-app-plus/dist/service.runtime.esm.js
浏览文件 @
9e5c0d33
...
...
@@ -4181,6 +4181,9 @@ function updateChildComponent (
vm
.
$options
.
propsData
=
propsData
;
}
// fixed by xxxxxx update properties(mp runtime)
vm
.
_$updateProperties
&&
vm
.
_$updateProperties
(
vm
);
// update listeners
listeners
=
listeners
||
emptyObject
;
var
oldListeners
=
vm
.
$options
.
_parentListeners
;
...
...
packages/uni-migration/__tests__/demo.js
浏览文件 @
9e5c0d33
...
...
@@ -13,7 +13,7 @@ migrate('/Users/fxy/Downloads/wa-vantui_1.1')
// transformTemplate
// } = require('../lib/mp-weixin/transform/template-transformer')
// console.log(transformTemplate(
// `<view wx:for="{{ columns }}" wx:for-item="item1" wx:key="
title
"/>`, {
// `<view wx:for="{{ columns }}" wx:for-item="item1" wx:key="
item1
"/>`, {
// filename: 'index'
// }
// ))
packages/uni-migration/__tests__/wxml.spec.js
浏览文件 @
9e5c0d33
...
...
@@ -24,7 +24,7 @@ describe('wxml:compiler', () => {
`<view v-for="(item1,index) in (isSimple(columns) ? [columns] : columns)" :key="item1.index"></view>`
)
assertCodegen
(
'
<view wx:for="{{ columns }}" wx:for-item="item1" wx:key="
*this
"/>
'
,
'
<view wx:for="{{ columns }}" wx:for-item="item1" wx:key="
item1
"/>
'
,
`<view v-for="(item1,index) in (columns)" :key="item1"></view>`
)
assertCodegen
(
...
...
packages/uni-migration/lib/index.js
浏览文件 @
9e5c0d33
...
...
@@ -20,6 +20,7 @@ module.exports = function migrate(input, out, options = {
}
const
[
files
,
assets
]
=
migrater
.
transform
(
input
,
out
,
options
)
files
.
forEach
(
file
=>
{
migrater
.
patch
.
vue
(
file
)
console
.
log
(
`write:
${
file
.
path
}
`
)
fs
.
outputFileSync
(
file
.
path
,
file
.
content
)
})
...
...
@@ -30,7 +31,7 @@ module.exports = function migrate(input, out, options = {
if
(
typeof
asset
===
'
string
'
)
{
const
src
=
path
.
resolve
(
input
,
asset
)
const
dest
=
path
.
resolve
(
out
,
asset
.
replace
(
styleExtname
,
'
.css
'
))
if
(
!
migrater
.
patch
(
src
,
dest
))
{
if
(
!
migrater
.
patch
.
asset
(
src
,
dest
))
{
if
(
needCopy
||
(
asset
.
indexOf
(
styleExtname
)
!==
-
1
&&
...
...
packages/uni-migration/lib/mp-weixin/patch.js
浏览文件 @
9e5c0d33
...
...
@@ -4,40 +4,52 @@ const {
normalizePath
}
=
require
(
'
./util
'
)
const
VANTS
=
[{
// wxs array.constructor
const
VANT
_ASSET
S
=
[{
// wxs array.constructor
test
(
src
)
{
return
src
.
indexOf
(
'
array.wxs
'
)
!==
-
1
},
source
(
code
)
{
return
code
.
replace
(
`array.constructor === 'Array'`
,
'
Array.isArray(array)
'
)
}
},
{
// vue $options conflicts
test
(
src
)
{
return
normalizePath
(
src
).
indexOf
(
'
mixins/observer/index.js
'
)
!==
-
1
},
source
(
code
)
{
return
code
.
replace
(
`options.methods.$options`
,
`options.methods.$getVantOptions`
)
}
},
{
// vue $options conflicts
test
(
src
)
{
return
normalizePath
(
src
).
indexOf
(
'
mixins/observer/behavior.js
'
)
!==
-
1
}]
const
PATCH_ASSETS
=
[
...
VANT_ASSETS
]
const
VANT_VUES
=
[{
test
(
file
)
{
return
normalizePath
(
file
.
path
).
indexOf
(
'
/image/index.vue
'
)
!==
-
1
},
source
(
code
)
{
return
code
.
replace
(
`!this.$options`
,
`!this.$getVantOptions`
)
.
replace
(
`this.$options()`
,
`this.$getVantOptions()`
)
// onLoad 与 onError 是生命周期函数名,需要替换为其他
return
code
.
replace
(
/onLoad/g
,
'
onImageLoad
'
)
.
replace
(
/onError/g
,
'
onImageError
'
)
}
}]
}]
const
PATCHS
=
[
...
VANTS
const
PATCH
_VUE
S
=
[
...
VANT
_VUE
S
]
module
.
exports
=
function
patch
(
src
,
dest
)
{
const
options
=
PATCHS
.
find
(
patch
=>
patch
.
test
(
src
))
function
patchAsset
(
src
,
dest
)
{
const
options
=
PATCH
_ASSET
S
.
find
(
patch
=>
patch
.
test
(
src
))
if
(
options
)
{
console
.
log
(
`write:
${
dest
}
`
)
fs
.
outputFileSync
(
dest
,
options
.
source
(
fs
.
readFileSync
(
src
).
toString
()))
return
true
}
return
false
}
function
patchVue
(
file
)
{
const
options
=
PATCH_VUES
.
find
(
patch
=>
patch
.
test
(
file
))
if
(
options
)
{
file
.
content
=
options
.
source
(
file
.
content
)
}
}
module
.
exports
=
{
vue
:
patchVue
,
asset
:
patchAsset
}
packages/uni-migration/lib/mp-weixin/transform/template-transformer/transform/traverse.js
浏览文件 @
9e5c0d33
...
...
@@ -64,10 +64,14 @@ function transformFor(attribs) {
//处理 wx:for-item="index"
)
attribs
[
'
v-for
'
]
=
`(
${
vItem
}
,
${
vIndex
}
) in (
${
parseMustache
(
vFor
)}
)`
if
(
vKey
)
{
vKey
===
'
*this
'
?
(
vKey
=
vItem
)
:
(
vKey
=
vItem
+
'
.
'
+
vKey
)
attribs
[
'
:key
'
]
=
vKey
attribs
[
'
v-for
'
]
=
`(
${
vItem
}
,
${
vIndex
}
) in (
${
parseMustache
(
vFor
)}
)`
if
(
vKey
)
{
if
(
vKey
===
'
*this
'
)
{
vKey
=
vItem
}
else
if
(
vKey
!==
vItem
)
{
vKey
=
vItem
+
'
.
'
+
vKey
}
attribs
[
'
:key
'
]
=
vKey
}
delete
attribs
[
FOR
.
for
]
...
...
packages/uni-mp-weixin/dist/mp.js
浏览文件 @
9e5c0d33
import
Vue
from
'
vue
'
;
function
parseData
(
data
,
vueComponentOptions
)
{
if
(
!
data
)
{
return
...
...
@@ -397,6 +399,34 @@ function proxy (target, sourceKey, key) {
Object
.
defineProperty
(
target
,
key
,
sharedPropertyDefinition
);
}
function
setDataByExprPath
(
exprPath
,
value
,
data
)
{
const
keys
=
exprPath
.
replace
(
/
\[(\d
+
?)\]
/g
,
'
.$1
'
).
split
(
'
.
'
);
keys
.
reduce
((
obj
,
key
,
idx
)
=>
{
if
(
idx
===
keys
.
length
-
1
)
{
obj
[
key
]
=
value
;
}
else
{
if
(
typeof
obj
[
key
]
===
'
undefined
'
)
{
obj
[
key
]
=
{};
}
return
obj
[
key
]
}
},
data
);
return
keys
.
length
===
1
}
function
setData
(
data
,
callback
)
{
if
(
!
isPlainObject
(
data
))
{
return
}
Object
.
keys
(
data
).
forEach
(
key
=>
{
if
(
setDataByExprPath
(
key
,
data
[
key
],
this
.
data
))
{
!
hasOwn
(
this
,
key
)
&&
proxy
(
this
,
SOURCE_KEY
,
key
);
}
});
this
.
$forceUpdate
();
isFn
(
callback
)
&&
this
.
$nextTick
(
callback
);
}
const
PROP_DEFAULT_VALUES
=
{
String
:
''
,
Number
:
0
,
...
...
@@ -474,24 +504,24 @@ function initProperties (vm, instanceData) {
return
value
},
set
(
newVal
)
{
const
oldVal
=
value
;
/* eslint-disable no-self-compare */
if
(
newVal
===
value
||
(
newVal
!==
newVal
&&
value
!==
value
))
{
return
}
if
(
observer
)
{
const
oldVal
=
value
;
/* eslint-disable no-self-compare */
if
(
newVal
===
value
||
(
newVal
!==
newVal
&&
value
!==
value
))
{
return
}
value
=
newVal
;
observe
(
observer
,
vm
,
newVal
,
oldVal
);
}
else
{
value
=
newVal
;
}
// 触发渲染
vm
.
$forceUpdate
();
}
});
}
}
function
updateProperties
(
vm
)
{
const
properties
=
vm
.
$options
.
mpOptions
.
properties
;
const
properties
=
vm
.
$options
.
mpOptions
&&
vm
.
$options
.
mpOptions
.
properties
;
const
propsData
=
vm
.
$options
.
propsData
;
if
(
propsData
&&
properties
)
{
Object
.
keys
(
properties
).
forEach
(
key
=>
{
...
...
@@ -526,20 +556,7 @@ function initState (vm) {
properties
:
propertyDefinition
});
vm
.
setData
=
(
data
,
callback
)
=>
{
// TODO data path: array[0].text,object.text
if
(
!
isPlainObject
(
data
))
{
return
}
Object
.
keys
(
data
).
forEach
(
key
=>
{
vm
.
data
[
key
]
=
data
[
key
];
if
(
!
hasOwn
(
vm
,
key
))
{
proxy
(
vm
,
SOURCE_KEY
,
key
);
}
});
vm
.
$forceUpdate
();
isFn
(
callback
)
&&
vm
.
$nextTick
(
callback
);
};
vm
.
setData
=
setData
;
initProperties
(
vm
,
instanceData
);
...
...
@@ -568,6 +585,8 @@ function initMethods (vm) {
/* eslint-disable no-mixed-operators */
return
vm
.
_$relationNodes
&&
vm
.
_$relationNodes
[
relationKey
]
||
[]
};
vm
.
_$updateProperties
=
updateProperties
;
}
function
initRelationHandlers
(
type
,
handler
,
target
,
ctx
,
handlerCtx
)
{
...
...
@@ -696,9 +715,6 @@ var polyfill = {
mounted
()
{
handleObservers
(
this
);
},
beforeUpdate
()
{
updateProperties
(
this
);
},
beforeDestroy
()
{
handleRelations
(
this
,
'
unlinked
'
);
}
...
...
@@ -742,6 +758,9 @@ function Component (options) {
function
Behavior
(
options
)
{
return
options
}
}
const
nextTick
=
Vue
.
nextTick
;
export
{
Behavior
,
Component
,
Page
,
getDate
,
getRegExp
};
export
default
uni
;
export
{
Behavior
,
Component
,
Page
,
getDate
,
getRegExp
,
nextTick
};
packages/vue-cli-plugin-uni/lib/app-plus/index.js
浏览文件 @
9e5c0d33
...
...
@@ -21,8 +21,9 @@ const runtimePath = '@dcloudio/uni-mp-weixin/dist/mp.js'
function
getProvides
()
{
return
{
'
__f__
'
:
[
path
.
resolve
(
__dirname
,
'
../format-log.js
'
),
'
default
'
],
'
wx
'
:
[
'
@dcloudio/uni-app-plus/dist/uni.js
'
,
'
default
'
],
'
Page
'
:
[
runtimePath
,
'
Page
'
],
'
wx
'
:
[
runtimePath
,
'
default
'
],
'
wx.nextTick
'
:
[
runtimePath
,
'
nextTick
'
],
'
Page
'
:
[
runtimePath
,
'
Page
'
],
'
Component
'
:
[
runtimePath
,
'
Component
'
],
'
Behavior
'
:
[
runtimePath
,
'
Behavior
'
],
'
getDate
'
:
[
runtimePath
,
'
getDate
'
],
...
...
src/core/runtime/mp/index.js
浏览文件 @
9e5c0d33
import
Vue
from
'
vue
'
import
{
parsePage
}
from
'
./parser/page-parser
'
...
...
@@ -30,4 +32,8 @@ export function Component (options) {
export
function
Behavior
(
options
)
{
return
options
}
}
export
const
nextTick
=
Vue
.
nextTick
export
default
uni
src/core/runtime/mp/polyfill/index.js
浏览文件 @
9e5c0d33
...
...
@@ -13,11 +13,7 @@ import {
import
{
handleObservers
}
from
'
./observers
'
import
{
updateProperties
}
from
'
./state/properties
'
}
from
'
./observers
'
export
default
{
beforeCreate
()
{
...
...
@@ -31,9 +27,6 @@ export default {
mounted
()
{
handleObservers
(
this
)
},
beforeUpdate
()
{
updateProperties
(
this
)
},
beforeDestroy
()
{
handleRelations
(
this
,
'
unlinked
'
)
}
...
...
src/core/runtime/mp/polyfill/methods.js
浏览文件 @
9e5c0d33
import
{
updateProperties
}
from
'
./state/properties
'
export
function
initMethods
(
vm
)
{
const
oldEmit
=
vm
.
$emit
vm
.
triggerEvent
=
(
eventName
,
detail
,
options
)
=>
{
...
...
@@ -18,4 +22,6 @@ export function initMethods (vm) {
/* eslint-disable no-mixed-operators */
return
vm
.
_$relationNodes
&&
vm
.
_$relationNodes
[
relationKey
]
||
[]
}
vm
.
_$updateProperties
=
updateProperties
}
src/core/runtime/mp/polyfill/state/data.js
0 → 100644
浏览文件 @
9e5c0d33
import
{
isFn
,
hasOwn
,
isPlainObject
}
from
'
uni-shared
'
import
{
proxy
}
from
'
./proxy
'
import
{
SOURCE_KEY
}
from
'
../../constants
'
function
setDataByExprPath
(
exprPath
,
value
,
data
)
{
const
keys
=
exprPath
.
replace
(
/
\[(\d
+
?)\]
/g
,
'
.$1
'
).
split
(
'
.
'
)
keys
.
reduce
((
obj
,
key
,
idx
)
=>
{
if
(
idx
===
keys
.
length
-
1
)
{
obj
[
key
]
=
value
}
else
{
if
(
typeof
obj
[
key
]
===
'
undefined
'
)
{
obj
[
key
]
=
{}
}
return
obj
[
key
]
}
},
data
)
return
keys
.
length
===
1
}
export
function
setData
(
data
,
callback
)
{
if
(
!
isPlainObject
(
data
))
{
return
}
Object
.
keys
(
data
).
forEach
(
key
=>
{
if
(
setDataByExprPath
(
key
,
data
[
key
],
this
.
data
))
{
!
hasOwn
(
this
,
key
)
&&
proxy
(
this
,
SOURCE_KEY
,
key
)
}
})
this
.
$forceUpdate
()
isFn
(
callback
)
&&
this
.
$nextTick
(
callback
)
}
src/core/runtime/mp/polyfill/state/index.js
浏览文件 @
9e5c0d33
import
{
isFn
,
hasOwn
,
isPlainObject
}
from
'
uni-shared
'
import
{
SOURCE_KEY
}
from
'
../../constants
'
...
...
@@ -12,6 +6,10 @@ import {
proxy
}
from
'
./proxy
'
import
{
setData
}
from
'
./data
'
import
{
initProperties
}
from
'
./properties
'
...
...
@@ -35,20 +33,7 @@ export function initState (vm) {
properties
:
propertyDefinition
})
vm
.
setData
=
(
data
,
callback
)
=>
{
// TODO data path: array[0].text,object.text
if
(
!
isPlainObject
(
data
))
{
return
}
Object
.
keys
(
data
).
forEach
(
key
=>
{
vm
.
data
[
key
]
=
data
[
key
]
if
(
!
hasOwn
(
vm
,
key
))
{
proxy
(
vm
,
SOURCE_KEY
,
key
)
}
})
vm
.
$forceUpdate
()
isFn
(
callback
)
&&
vm
.
$nextTick
(
callback
)
}
vm
.
setData
=
setData
initProperties
(
vm
,
instanceData
)
...
...
src/core/runtime/mp/polyfill/state/properties.js
浏览文件 @
9e5c0d33
...
...
@@ -80,24 +80,24 @@ export function initProperties (vm, instanceData) {
return
value
},
set
(
newVal
)
{
const
oldVal
=
value
/* eslint-disable no-self-compare */
if
(
newVal
===
value
||
(
newVal
!==
newVal
&&
value
!==
value
))
{
return
}
if
(
observer
)
{
const
oldVal
=
value
/* eslint-disable no-self-compare */
if
(
newVal
===
value
||
(
newVal
!==
newVal
&&
value
!==
value
))
{
return
}
value
=
newVal
observe
(
observer
,
vm
,
newVal
,
oldVal
)
}
else
{
value
=
newVal
}
// 触发渲染
vm
.
$forceUpdate
()
}
})
}
}
export
function
updateProperties
(
vm
)
{
const
properties
=
vm
.
$options
.
mpOptions
.
properties
const
properties
=
vm
.
$options
.
mpOptions
&&
vm
.
$options
.
mpOptions
.
properties
const
propsData
=
vm
.
$options
.
propsData
if
(
propsData
&&
properties
)
{
Object
.
keys
(
properties
).
forEach
(
key
=>
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录