Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
m0_68066342
uni-app
提交
4ed4bcc8
U
uni-app
项目概览
m0_68066342
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
4ed4bcc8
编写于
3月 04, 2019
作者:
Q
qiang
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'dev' of github.com:dcloudio/uni-app into dev
# Conflicts: # package.json # yarn.lock
上级
abb10b13
b0766b44
变更
12
展开全部
显示空白变更内容
内联
并排
Showing
12 changed file
with
747 addition
and
101 deletion
+747
-101
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
+7
-7
未找到文件。
build/rollup.config.js
浏览文件 @
4ed4bcc8
...
...
@@ -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
浏览文件 @
4ed4bcc8
...
...
@@ -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
浏览文件 @
4ed4bcc8
...
...
@@ -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
浏览文件 @
4ed4bcc8
此差异已折叠。
点击以展开。
packages/uni-h5/dist/index.umd.min.js
浏览文件 @
4ed4bcc8
此差异已折叠。
点击以展开。
packages/uni-mp-weixin/dist/index.js
浏览文件 @
4ed4bcc8
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
浏览文件 @
4ed4bcc8
...
...
@@ -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
浏览文件 @
4ed4bcc8
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
浏览文件 @
4ed4bcc8
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
浏览文件 @
4ed4bcc8
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
浏览文件 @
4ed4bcc8
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
浏览文件 @
4ed4bcc8
...
...
@@ -724,7 +724,7 @@
version "3.4.1"
resolved "https://registry.yarnpkg.com/@vue/cli-overlay/-/cli-overlay-3.4.1.tgz#f850c2f8d7cd42b475d03ec6658ccf2ec9830511"
"@vue/cli-plugin-babel@^3.
1
.1":
"@vue/cli-plugin-babel@^3.
4
.1":
version "3.4.1"
resolved "https://registry.yarnpkg.com/@vue/cli-plugin-babel/-/cli-plugin-babel-3.4.1.tgz#f84fe329966ab5c82c80da1bd62da4db4089090b"
dependencies:
...
...
@@ -734,7 +734,7 @@
babel-loader "^8.0.5"
webpack ">=4 < 4.29"
"@vue/cli-plugin-eslint@^3.
1.4
":
"@vue/cli-plugin-eslint@^3.
4.1
":
version "3.4.1"
resolved "https://registry.yarnpkg.com/@vue/cli-plugin-eslint/-/cli-plugin-eslint-3.4.1.tgz#59896379e12d68aefcdccac28c691cb6e23e5720"
dependencies:
...
...
@@ -747,7 +747,7 @@
eslint "^4.19.1"
eslint-plugin-vue "^4.7.1"
"@vue/cli-plugin-unit-mocha@^3.
1
.1":
"@vue/cli-plugin-unit-mocha@^3.
4
.1":
version "3.4.1"
resolved "https://registry.yarnpkg.com/@vue/cli-plugin-unit-mocha/-/cli-plugin-unit-mocha-3.4.1.tgz#e15f790e97af22c4b41638fbcd30e34a743af9d2"
dependencies:
...
...
@@ -757,7 +757,7 @@
mocha "^5.2.0"
mocha-webpack "^2.0.0-beta.0"
"@vue/cli-service@^3.
1.2
":
"@vue/cli-service@^3.
4.1
":
version "3.4.1"
resolved "https://registry.yarnpkg.com/@vue/cli-service/-/cli-service-3.4.1.tgz#65ef3ed00b8e6eeeca736308a703c264cfa280cc"
dependencies:
...
...
@@ -1784,7 +1784,7 @@ caniuse-api@^3.0.0:
lodash.memoize "^4.1.2"
lodash.uniq "^4.5.0"
caniuse-lite@^1.0.0, caniuse-lite@^1.0.30000939:
caniuse-lite@^1.0.0, caniuse-lite@^1.0.30000939
, caniuse-lite@^1.0.30000940
:
version "1.0.30000940"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30000940.tgz#19f2b1497fbfa5b96b615963097c3757f27989ce"
...
...
@@ -7198,7 +7198,7 @@ vue-style-loader@^4.1.0:
hash-sum "^1.0.2"
loader-utils "^1.0.2"
vue-template-compiler@^2.
5.17
:
vue-template-compiler@^2.
6.8
:
version "2.6.8"
resolved "https://registry.yarnpkg.com/vue-template-compiler/-/vue-template-compiler-2.6.8.tgz#750802604595134775b9c53141b9850b35255e1c"
dependencies:
...
...
@@ -7209,7 +7209,7 @@ vue-template-es2015-compiler@^1.9.0:
version "1.9.1"
resolved "https://registry.yarnpkg.com/vue-template-es2015-compiler/-/vue-template-es2015-compiler-1.9.1.tgz#1ee3bc9a16ecbf5118be334bb15f9c46f82f5825"
vue@^2.
5.17
:
vue@^2.
6.8
:
version "2.6.8"
resolved "https://registry.yarnpkg.com/vue/-/vue-2.6.8.tgz#f21cbc536bfc14f7d1d792a137bb12f69e60ea91"
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录