Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
yangkaifeng
uni-app
提交
b0766b44
U
uni-app
项目概览
yangkaifeng
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
3
Star
1
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,发现更多精彩内容 >>
提交
b0766b44
编写于
3月 04, 2019
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(runtime): createApp,createPage,createComponent and Vue@2.6.8
上级
ccf4ebdb
变更
12
展开全部
显示空白变更内容
内联
并排
Showing
12 changed file
with
1493 addition
and
467 deletion
+1493
-467
build/rollup.config.js
build/rollup.config.js
+3
-1
build/vue.config.js
build/vue.config.js
+1
-1
package.json
package.json
+94
-89
packages/uni-h5/dist/index.css
packages/uni-h5/dist/index.css
+1
-1
packages/uni-h5/dist/index.umd.min.js
packages/uni-h5/dist/index.umd.min.js
+1
-1
packages/uni-mp-weixin/dist/index.js
packages/uni-mp-weixin/dist/index.js
+301
-1
src/core/runtime/index.js
src/core/runtime/index.js
+4
-0
src/core/runtime/wrapper/create-app.js
src/core/runtime/wrapper/create-app.js
+34
-0
src/core/runtime/wrapper/create-component.js
src/core/runtime/wrapper/create-component.js
+87
-0
src/core/runtime/wrapper/create-page.js
src/core/runtime/wrapper/create-page.js
+62
-0
src/core/runtime/wrapper/util.js
src/core/runtime/wrapper/util.js
+152
-0
yarn.lock
yarn.lock
+753
-373
未找到文件。
build/rollup.config.js
浏览文件 @
b0766b44
...
...
@@ -22,6 +22,7 @@ const PLATFORMS = {
}
const
platform
=
PLATFORMS
[
process
.
env
.
UNI_PLATFORM
]
module
.
exports
=
{
input
:
'
src/core/runtime/index.js
'
,
output
:
{
...
...
@@ -37,5 +38,6 @@ module.exports = {
__GLOBAL__
:
platform
.
prefix
,
__PLATFORM_TITLE__
:
platform
.
title
})
]
],
external
:
[
'
vue
'
]
}
build/vue.config.js
浏览文件 @
b0766b44
...
...
@@ -7,7 +7,7 @@ const pkgPath = resolve('package.json')
const
webpackConfig
=
require
(
'
./webpack.config.js
'
)
module
.
exports
=
{
baseUrl
:
'
/
'
,
publicPath
:
'
/
'
,
outputDir
:
resolve
(
'
./packages/uni-
'
+
process
.
env
.
UNI_PLATFORM
+
'
/dist
'
),
lintOnSave
:
true
,
// or error
runtimeCompiler
:
false
,
...
...
package.json
浏览文件 @
b0766b44
...
...
@@ -14,13 +14,15 @@
"dependencies"
:
{},
"private"
:
true
,
"devDependencies"
:
{
"
@vue/cli-plugin-babel
"
:
"
^3.1
.1
"
,
"
@vue/cli-plugin-eslint
"
:
"
^3.1.4
"
,
"
@vue/cli-plugin-unit-mocha
"
:
"
^3.1
.1
"
,
"
@vue/cli-service
"
:
"
^3.1.2
"
,
"
@vue/cli-plugin-babel
"
:
"
^3.4
.1
"
,
"
@vue/cli-plugin-eslint
"
:
"
^3.4.1
"
,
"
@vue/cli-plugin-unit-mocha
"
:
"
^3.4
.1
"
,
"
@vue/cli-service
"
:
"
^3.4.1
"
,
"
@vue/test-utils
"
:
"
^1.0.0-beta.25
"
,
"
babel-eslint
"
:
"
^10.0.1
"
,
"
babylon
"
:
"
^6.18.0
"
,
"
browserslist
"
:
"
^4.4.2
"
,
"
caniuse-lite
"
:
"
^1.0.30000940
"
,
"
chai
"
:
"
^4.1.2
"
,
"
cross-env
"
:
"
^5.2.0
"
,
"
eslint
"
:
"
^5.5.0
"
,
...
...
@@ -37,9 +39,9 @@
"
rollup-plugin-alias
"
:
"
^1.4.0
"
,
"
rollup-plugin-replace
"
:
"
^2.1.0
"
,
"
strip-json-comments
"
:
"
^2.0.1
"
,
"
vue
"
:
"
^2.5.17
"
,
"
vue
"
:
"
^2.6.8
"
,
"
vue-router
"
:
"
^3.0.1
"
,
"
vue-template-compiler
"
:
"
^2.5.17
"
,
"
vue-template-compiler
"
:
"
^2.6.8
"
,
"
webpack
"
:
"
^4.18.0
"
,
"
webpack-bundle-analyzer
"
:
"
^3.0.3
"
,
"
webpack-virtual-modules
"
:
"
^0.1.10
"
...
...
@@ -54,6 +56,9 @@
"standard"
],
"globals"
:
{
"App"
:
true
,
"Page"
:
true
,
"Component"
:
true
,
"getApp"
:
true
,
"getCurrentPages"
:
true
,
"plus"
:
true
,
...
...
packages/uni-h5/dist/index.css
浏览文件 @
b0766b44
此差异已折叠。
点击以展开。
packages/uni-h5/dist/index.umd.min.js
浏览文件 @
b0766b44
此差异已折叠。
点击以展开。
packages/uni-mp-weixin/dist/index.js
浏览文件 @
b0766b44
import
Vue
from
'
vue
'
;
const
_toString
=
Object
.
prototype
.
toString
;
const
hasOwnProperty
=
Object
.
prototype
.
hasOwnProperty
;
...
...
@@ -17,6 +19,8 @@ function hasOwn (obj, key) {
return
hasOwnProperty
.
call
(
obj
,
key
)
}
function
noop
()
{}
const
SYNC_API_RE
=
/hideKeyboard|upx2px|canIUse|^create|Sync$|Manager$/
;
const
CONTEXT_API_RE
=
/^create|Manager$/
;
...
...
@@ -264,6 +268,301 @@ var api = /*#__PURE__*/Object.freeze({
});
function
initHooks
(
mpOptions
,
hooks
)
{
hooks
.
forEach
(
hook
=>
{
mpOptions
[
hook
]
=
function
(
args
)
{
this
.
$vm
.
__call_hook
(
hook
,
args
);
};
});
}
function
getData
(
data
)
{
if
(
typeof
data
===
'
function
'
)
{
try
{
return
data
()
}
catch
(
e
)
{
console
.
warn
(
'
根据 Vue 的 data 函数初始化小程序 data 失败,请尽量确保 data 函数中不访问 vm 对象,否则可能影响首次数据渲染速度。
'
);
}
return
{}
}
return
data
||
{}
}
const
PROP_TYPES
=
[
String
,
Number
,
Boolean
,
Object
,
Array
,
null
];
function
getProperties
(
props
)
{
const
properties
=
{};
if
(
Array
.
isArray
(
props
))
{
// ['title']
props
.
forEach
(
key
=>
{
properties
[
key
]
=
null
;
});
}
else
if
(
isPlainObject
(
props
))
{
// {title:{type:String,default:''},content:String}
Object
.
keys
(
props
).
forEach
(
key
=>
{
const
opts
=
props
[
key
];
if
(
isPlainObject
(
opts
))
{
// title:{type:String,default:''}
let
value
=
opts
[
'
default
'
];
if
(
isFn
(
value
))
{
value
=
value
();
}
properties
[
key
]
=
{
type
:
PROP_TYPES
.
includes
(
opts
.
type
)
?
opts
.
type
:
null
,
value
};
}
else
{
// content:String
properties
[
key
]
=
PROP_TYPES
.
includes
(
opts
)
?
opts
:
null
;
}
});
}
return
properties
}
function
wrapper$1
(
event
)
{
event
.
stopPropagation
=
noop
;
event
.
preventDefault
=
noop
;
event
.
target
=
event
.
target
||
{};
event
.
detail
=
event
.
detail
||
{};
// TODO 又得兼容 mpvue 的 mp 对象
event
.
mp
=
event
;
event
.
target
=
Object
.
assign
({},
event
.
target
,
event
.
detail
);
return
event
}
function
processEventArgs
(
event
,
args
=
[],
isCustom
)
{
if
(
isCustom
&&
!
args
.
length
)
{
// 无参数,直接传入 detail 数组
return
event
.
detail
}
const
ret
=
[];
args
.
forEach
(
arg
=>
{
if
(
arg
===
'
$event
'
)
{
ret
.
push
(
isCustom
?
event
.
detail
[
0
]
:
event
);
}
else
{
ret
.
push
(
arg
);
}
});
return
ret
}
const
ONCE
=
'
~
'
;
const
CUSTOM
=
'
^
'
;
function
handleEvent
(
event
)
{
event
=
wrapper$1
(
event
);
// [['tap',[['handle',[1,2,a]],['handle1',[1,2,a]]]]]
const
eventOpts
=
(
event
.
currentTarget
||
event
.
target
).
dataset
.
eventOpts
;
if
(
!
eventOpts
)
{
return
console
.
warn
(
`事件信息不存在`
)
}
// [['handle',[1,2,a]],['handle1',[1,2,a]]]
const
eventType
=
event
.
type
;
eventOpts
.
forEach
(
eventOpt
=>
{
let
type
=
eventOpt
[
0
];
const
eventsArray
=
eventOpt
[
1
];
const
isCustom
=
type
.
charAt
(
0
)
===
CUSTOM
;
type
=
isCustom
?
type
.
slice
(
1
)
:
type
;
const
isOnce
=
type
.
charAt
(
0
)
===
ONCE
;
type
=
isOnce
?
type
.
slice
(
1
)
:
type
;
if
(
eventsArray
&&
eventType
===
type
)
{
eventsArray
.
forEach
(
eventArray
=>
{
const
handler
=
this
.
$vm
[
eventArray
[
0
]];
if
(
isOnce
)
{
if
(
handler
.
once
)
{
return
}
handler
.
once
=
true
;
}
handler
.
apply
(
this
.
$vm
,
processEventArgs
(
event
,
eventArray
[
1
],
isCustom
));
});
}
});
}
function
handleLink
(
event
)
{
event
.
detail
.
$parent
=
this
.
$vm
;
}
function
initRefs
(
vm
)
{
const
mpInstance
=
vm
.
$mp
[
vm
.
mpType
];
Object
.
defineProperty
(
vm
,
'
$refs
'
,
{
get
()
{
const
$refs
=
Object
.
create
(
null
);
const
components
=
mpInstance
.
selectAllComponents
(
'
.__ref__
'
);
components
.
forEach
(
component
=>
{
const
id
=
component
.
id
;
$refs
[
id
]
=
component
.
$vm
;
});
const
forComponents
=
mpInstance
.
selectAllComponents
(
'
.__ref-in-for__
'
);
forComponents
.
forEach
(
component
=>
{
const
id
=
component
.
id
;
if
(
!
$refs
[
id
])
{
$refs
[
id
]
=
[];
}
$refs
[
id
].
push
(
component
.
$vm
);
});
return
$refs
}
});
}
const
hooks
=
[
'
onShow
'
,
'
onHide
'
,
'
onError
'
,
'
onPageNotFound
'
];
function
createApp
(
vueOptions
)
{
vueOptions
=
vueOptions
.
default
||
vueOptions
;
const
appOptions
=
{
onLaunch
(
args
)
{
this
.
$vm
=
new
Vue
(
vueOptions
);
this
.
$vm
.
mpType
=
'
app
'
;
this
.
$vm
.
$mp
=
{
app
:
this
};
this
.
$vm
.
$mount
();
this
.
$vm
.
__call_hook
(
'
onLaunch
'
,
args
);
}
};
initHooks
(
appOptions
,
hooks
);
App
(
appOptions
);
return
vueOptions
}
const
hooks$1
=
[
'
onShow
'
,
'
onHide
'
,
'
onPullDownRefresh
'
,
'
onReachBottom
'
,
'
onShareAppMessage
'
,
'
onPageScroll
'
,
'
onResize
'
,
'
onTabItemTap
'
,
'
onBackPress
'
,
'
onNavigationBarButtonTap
'
,
'
onNavigationBarSearchInputChanged
'
,
'
onNavigationBarSearchInputConfirmed
'
,
'
onNavigationBarSearchInputClicked
'
];
function
createPage
(
vueOptions
)
{
vueOptions
=
vueOptions
.
default
||
vueOptions
;
const
pageOptions
=
{
data
:
getData
(
vueOptions
.
data
),
onLoad
(
args
)
{
this
.
$vm
=
new
Vue
(
vueOptions
);
this
.
$vm
.
mpType
=
'
page
'
;
this
.
$vm
.
$mp
=
{
data
:
{},
page
:
this
};
initRefs
(
this
.
$vm
);
this
.
$vm
.
$mount
();
this
.
$vm
.
__call_hook
(
'
onLoad
'
,
args
);
},
onReady
()
{
this
.
$vm
.
_isMounted
=
true
;
this
.
$vm
.
__call_hook
(
'
onReady
'
);
},
onUnload
()
{
this
.
$vm
.
__call_hook
(
'
onUnload
'
);
this
.
$vm
.
$destroy
();
},
__e
:
handleEvent
,
__l
:
handleLink
};
initHooks
(
pageOptions
,
hooks$1
);
return
Page
(
pageOptions
)
}
function
createComponent
(
vueOptions
)
{
vueOptions
=
vueOptions
.
default
||
vueOptions
;
const
properties
=
getProperties
(
vueOptions
.
props
);
const
VueComponent
=
Vue
.
extend
(
vueOptions
);
const
componentOptions
=
{
options
:
{
multipleSlots
:
true
,
addGlobalClass
:
true
},
data
:
getData
(
vueOptions
.
data
),
properties
,
lifetimes
:
{
attached
()
{
// props的处理,一个是直接 与 mp 的 properties 对接,另一个是要做成 reactive,且排除掉 render watch
const
options
=
{
propsData
:
this
.
properties
,
$component
:
this
};
// 初始化 vue 实例
this
.
$vm
=
new
VueComponent
(
options
);
this
.
$vm
.
mpType
=
'
component
'
;
this
.
$vm
.
$mp
=
{
data
:
{},
component
:
this
};
initRefs
(
this
.
$vm
);
// 初始化渲染数据
this
.
$vm
.
$mount
();
},
ready
()
{
this
.
triggerEvent
(
'
__l
'
,
this
.
$vm
);
const
eventId
=
this
.
dataset
.
eventId
;
if
(
eventId
)
{
const
listeners
=
this
.
$vm
.
$parent
.
$mp
.
listeners
;
if
(
listeners
)
{
const
listenerOpts
=
listeners
[
eventId
];
Object
.
keys
(
listenerOpts
).
forEach
(
eventType
=>
{
listenerOpts
[
eventType
].
forEach
(
handler
=>
{
this
.
$vm
[
handler
.
once
?
'
$once
'
:
'
$on
'
](
eventType
,
handler
);
});
});
}
}
this
.
$vm
.
_isMounted
=
true
;
this
.
$vm
.
__call_hook
(
'
mounted
'
);
},
detached
()
{
this
.
$vm
.
$destroy
();
}
},
pageLifetimes
:
{
show
(
args
)
{
this
.
$vm
.
__call_hook
(
'
onPageShow
'
,
args
);
},
hide
()
{
this
.
$vm
.
__call_hook
(
'
onPageHide
'
);
},
resize
(
size
)
{
this
.
$vm
.
__call_hook
(
'
onPageResize
'
,
size
);
}
},
methods
:
{
__e
:
handleEvent
,
__l
:
handleLink
}
};
return
Component
(
componentOptions
)
}
let
uni
=
{};
if
(
typeof
Proxy
!==
'
undefined
'
)
{
...
...
@@ -312,3 +611,4 @@ if (typeof Proxy !== 'undefined') {
var
uni$1
=
uni
;
export
default
uni$1
;
export
{
createApp
,
createPage
,
createComponent
};
src/core/runtime/index.js
浏览文件 @
b0766b44
...
...
@@ -65,4 +65,8 @@ if (typeof Proxy !== 'undefined') {
})
}
export
*
from
'
./wrapper/create-app
'
export
*
from
'
./wrapper/create-page
'
export
*
from
'
./wrapper/create-component
'
export
default
uni
src/core/runtime/wrapper/create-app.js
0 → 100644
浏览文件 @
b0766b44
import
Vue
from
'
vue
'
import
{
initHooks
}
from
'
./util
'
const
hooks
=
[
'
onShow
'
,
'
onHide
'
,
'
onError
'
,
'
onPageNotFound
'
]
export
function
createApp
(
vueOptions
)
{
vueOptions
=
vueOptions
.
default
||
vueOptions
const
appOptions
=
{
onLaunch
(
args
)
{
this
.
$vm
=
new
Vue
(
vueOptions
)
this
.
$vm
.
mpType
=
'
app
'
this
.
$vm
.
$mp
=
{
app
:
this
}
this
.
$vm
.
$mount
()
this
.
$vm
.
__call_hook
(
'
onLaunch
'
,
args
)
}
}
initHooks
(
appOptions
,
hooks
)
App
(
appOptions
)
return
vueOptions
}
src/core/runtime/wrapper/create-component.js
0 → 100644
浏览文件 @
b0766b44
import
Vue
from
'
vue
'
import
{
getData
,
initRefs
,
initMethods
,
handleLink
,
handleEvent
,
getProperties
}
from
'
./util
'
export
function
createComponent
(
vueOptions
)
{
vueOptions
=
vueOptions
.
default
||
vueOptions
const
properties
=
getProperties
(
vueOptions
.
props
)
const
VueComponent
=
Vue
.
extend
(
vueOptions
)
const
componentOptions
=
{
options
:
{
multipleSlots
:
true
,
addGlobalClass
:
true
},
data
:
getData
(
vueOptions
.
data
),
properties
,
lifetimes
:
{
attached
()
{
// props的处理,一个是直接 与 mp 的 properties 对接,另一个是要做成 reactive,且排除掉 render watch
const
options
=
{
propsData
:
this
.
properties
,
$component
:
this
}
// 初始化 vue 实例
this
.
$vm
=
new
VueComponent
(
options
)
this
.
$vm
.
mpType
=
'
component
'
this
.
$vm
.
$mp
=
{
data
:
{},
component
:
this
}
initRefs
(
this
.
$vm
)
// 初始化渲染数据
this
.
$vm
.
$mount
()
},
ready
()
{
this
.
triggerEvent
(
'
__l
'
,
this
.
$vm
)
const
eventId
=
this
.
dataset
.
eventId
if
(
eventId
)
{
const
listeners
=
this
.
$vm
.
$parent
.
$mp
.
listeners
if
(
listeners
)
{
const
listenerOpts
=
listeners
[
eventId
]
Object
.
keys
(
listenerOpts
).
forEach
(
eventType
=>
{
listenerOpts
[
eventType
].
forEach
(
handler
=>
{
this
.
$vm
[
handler
.
once
?
'
$once
'
:
'
$on
'
](
eventType
,
handler
)
})
})
}
}
this
.
$vm
.
_isMounted
=
true
this
.
$vm
.
__call_hook
(
'
mounted
'
)
},
detached
()
{
this
.
$vm
.
$destroy
()
}
},
pageLifetimes
:
{
show
(
args
)
{
this
.
$vm
.
__call_hook
(
'
onPageShow
'
,
args
)
},
hide
()
{
this
.
$vm
.
__call_hook
(
'
onPageHide
'
)
},
resize
(
size
)
{
this
.
$vm
.
__call_hook
(
'
onPageResize
'
,
size
)
}
},
methods
:
{
__e
:
handleEvent
,
__l
:
handleLink
}
}
initMethods
(
componentOptions
.
methods
,
vueOptions
)
return
Component
(
componentOptions
)
}
src/core/runtime/wrapper/create-page.js
0 → 100644
浏览文件 @
b0766b44
import
Vue
from
'
vue
'
import
{
getData
,
initRefs
,
initHooks
,
initMethods
,
handleLink
,
handleEvent
}
from
'
./util
'
const
hooks
=
[
'
onShow
'
,
'
onHide
'
,
'
onPullDownRefresh
'
,
'
onReachBottom
'
,
'
onShareAppMessage
'
,
'
onPageScroll
'
,
'
onResize
'
,
'
onTabItemTap
'
,
'
onBackPress
'
,
'
onNavigationBarButtonTap
'
,
'
onNavigationBarSearchInputChanged
'
,
'
onNavigationBarSearchInputConfirmed
'
,
'
onNavigationBarSearchInputClicked
'
]
export
function
createPage
(
vueOptions
)
{
vueOptions
=
vueOptions
.
default
||
vueOptions
const
pageOptions
=
{
data
:
getData
(
vueOptions
.
data
),
onLoad
(
args
)
{
this
.
$vm
=
new
Vue
(
vueOptions
)
this
.
$vm
.
mpType
=
'
page
'
this
.
$vm
.
$mp
=
{
data
:
{},
page
:
this
}
initRefs
(
this
.
$vm
)
this
.
$vm
.
$mount
()
this
.
$vm
.
__call_hook
(
'
onLoad
'
,
args
)
},
onReady
()
{
this
.
$vm
.
_isMounted
=
true
this
.
$vm
.
__call_hook
(
'
onReady
'
)
},
onUnload
()
{
this
.
$vm
.
__call_hook
(
'
onUnload
'
)
this
.
$vm
.
$destroy
()
},
__e
:
handleEvent
,
__l
:
handleLink
}
initHooks
(
pageOptions
,
hooks
)
initMethods
(
pageOptions
,
vueOptions
)
return
Page
(
pageOptions
)
}
src/core/runtime/wrapper/util.js
0 → 100644
浏览文件 @
b0766b44
import
{
isFn
,
noop
,
isPlainObject
}
from
'
uni-shared
'
export
function
initHooks
(
mpOptions
,
hooks
)
{
hooks
.
forEach
(
hook
=>
{
mpOptions
[
hook
]
=
function
(
args
)
{
this
.
$vm
.
__call_hook
(
hook
,
args
)
}
})
}
export
function
initMethods
(
mpOptions
,
vueOptions
)
{
// if (vueOptions.methods) {
// Object.assign(mpOptions, vueOptions.methods)
// }
}
export
function
getData
(
data
)
{
if
(
typeof
data
===
'
function
'
)
{
try
{
return
data
()
}
catch
(
e
)
{
console
.
warn
(
'
根据 Vue 的 data 函数初始化小程序 data 失败,请尽量确保 data 函数中不访问 vm 对象,否则可能影响首次数据渲染速度。
'
)
}
return
{}
}
return
data
||
{}
}
const
PROP_TYPES
=
[
String
,
Number
,
Boolean
,
Object
,
Array
,
null
]
export
function
getProperties
(
props
)
{
const
properties
=
{}
if
(
Array
.
isArray
(
props
))
{
// ['title']
props
.
forEach
(
key
=>
{
properties
[
key
]
=
null
})
}
else
if
(
isPlainObject
(
props
))
{
// {title:{type:String,default:''},content:String}
Object
.
keys
(
props
).
forEach
(
key
=>
{
const
opts
=
props
[
key
]
if
(
isPlainObject
(
opts
))
{
// title:{type:String,default:''}
let
value
=
opts
[
'
default
'
]
if
(
isFn
(
value
))
{
value
=
value
()
}
properties
[
key
]
=
{
type
:
PROP_TYPES
.
includes
(
opts
.
type
)
?
opts
.
type
:
null
,
value
}
}
else
{
// content:String
properties
[
key
]
=
PROP_TYPES
.
includes
(
opts
)
?
opts
:
null
}
})
}
return
properties
}
function
wrapper
(
event
)
{
event
.
stopPropagation
=
noop
event
.
preventDefault
=
noop
event
.
target
=
event
.
target
||
{}
event
.
detail
=
event
.
detail
||
{}
// TODO 又得兼容 mpvue 的 mp 对象
event
.
mp
=
event
event
.
target
=
Object
.
assign
({},
event
.
target
,
event
.
detail
)
return
event
}
function
processEventArgs
(
event
,
args
=
[],
isCustom
)
{
if
(
isCustom
&&
!
args
.
length
)
{
// 无参数,直接传入 detail 数组
return
event
.
detail
}
const
ret
=
[]
args
.
forEach
(
arg
=>
{
if
(
arg
===
'
$event
'
)
{
ret
.
push
(
isCustom
?
event
.
detail
[
0
]
:
event
)
}
else
{
ret
.
push
(
arg
)
}
})
return
ret
}
const
ONCE
=
'
~
'
const
CUSTOM
=
'
^
'
export
function
handleEvent
(
event
)
{
event
=
wrapper
(
event
)
// [['tap',[['handle',[1,2,a]],['handle1',[1,2,a]]]]]
const
eventOpts
=
(
event
.
currentTarget
||
event
.
target
).
dataset
.
eventOpts
if
(
!
eventOpts
)
{
return
console
.
warn
(
`事件信息不存在`
)
}
// [['handle',[1,2,a]],['handle1',[1,2,a]]]
const
eventType
=
event
.
type
eventOpts
.
forEach
(
eventOpt
=>
{
let
type
=
eventOpt
[
0
]
const
eventsArray
=
eventOpt
[
1
]
const
isCustom
=
type
.
charAt
(
0
)
===
CUSTOM
type
=
isCustom
?
type
.
slice
(
1
)
:
type
const
isOnce
=
type
.
charAt
(
0
)
===
ONCE
type
=
isOnce
?
type
.
slice
(
1
)
:
type
if
(
eventsArray
&&
eventType
===
type
)
{
eventsArray
.
forEach
(
eventArray
=>
{
const
handler
=
this
.
$vm
[
eventArray
[
0
]]
if
(
isOnce
)
{
if
(
handler
.
once
)
{
return
}
handler
.
once
=
true
}
handler
.
apply
(
this
.
$vm
,
processEventArgs
(
event
,
eventArray
[
1
],
isCustom
))
})
}
})
}
export
function
handleLink
(
event
)
{
event
.
detail
.
$parent
=
this
.
$vm
}
export
function
initRefs
(
vm
)
{
const
mpInstance
=
vm
.
$mp
[
vm
.
mpType
]
Object
.
defineProperty
(
vm
,
'
$refs
'
,
{
get
()
{
const
$refs
=
Object
.
create
(
null
)
const
components
=
mpInstance
.
selectAllComponents
(
'
.__ref__
'
)
components
.
forEach
(
component
=>
{
const
id
=
component
.
id
$refs
[
id
]
=
component
.
$vm
})
const
forComponents
=
mpInstance
.
selectAllComponents
(
'
.__ref-in-for__
'
)
forComponents
.
forEach
(
component
=>
{
const
id
=
component
.
id
if
(
!
$refs
[
id
])
{
$refs
[
id
]
=
[]
}
$refs
[
id
].
push
(
component
.
$vm
)
})
return
$refs
}
})
}
yarn.lock
浏览文件 @
b0766b44
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录