Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-app
提交
caa87deb
U
uni-app
项目概览
DCloud
/
uni-app
3 个月 前同步成功
通知
725
Star
38705
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
caa87deb
编写于
5月 17, 2021
作者:
D
DCloud_LXH
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
chore: eventBus、canvas、showActionSheet
上级
38e534db
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
137 addition
and
198 deletion
+137
-198
packages/uni-api/src/protocols/ui/showActionSheet.ts
packages/uni-api/src/protocols/ui/showActionSheet.ts
+1
-1
packages/uni-api/src/service/base/eventBus.ts
packages/uni-api/src/service/base/eventBus.ts
+21
-69
packages/uni-api/src/service/context/canvas.ts
packages/uni-api/src/service/context/canvas.ts
+47
-34
packages/uni-core/src/helpers/TinyEmitter.ts
packages/uni-core/src/helpers/TinyEmitter.ts
+18
-6
packages/uni-core/src/helpers/index.ts
packages/uni-core/src/helpers/index.ts
+1
-0
packages/uni-h5/dist/uni-h5.cjs.js
packages/uni-h5/dist/uni-h5.cjs.js
+2
-2
packages/uni-h5/dist/uni-h5.es.js
packages/uni-h5/dist/uni-h5.es.js
+47
-86
未找到文件。
packages/uni-api/src/protocols/ui/showActionSheet.ts
浏览文件 @
caa87deb
...
...
@@ -7,7 +7,7 @@ export const ShowActionSheetProtocol: ApiProtocol<API_TYPE_SHOW_ACTION_SHEET> =
required
:
true
,
},
itemColor
:
String
,
//
popover: Object,
popover
:
Object
,
}
export
const
ShowActionSheetOptions
:
ApiOptions
<
API_TYPE_SHOW_ACTION_SHEET
>
=
{
formatArgs
:
{
...
...
packages/uni-api/src/service/base/eventBus.ts
浏览文件 @
caa87deb
...
...
@@ -13,94 +13,46 @@ import {
EmitProtocol
,
OnceProtocol
,
}
from
'
../../protocols/base/eventBus
'
import
{
Emitter
}
from
'
@dcloudio/uni-core
'
type
EventName
=
string
|
number
|
symbol
type
EventCallback
=
(...
args
:
any
)
=>
any
type
EventStopHandler
=
()
=>
void
class
Emitter
{
private
eventMap
:
Map
<
EventName
,
Array
<
EventCallback
>>
constructor
()
{
this
.
eventMap
=
new
Map
()
}
on
=
(
name
:
EventName
,
callback
:
EventCallback
):
EventStopHandler
=>
{
if
(
!
this
.
eventMap
.
has
(
name
))
{
this
.
eventMap
.
set
(
name
,
[])
}
this
.
eventMap
.
get
(
name
)
!
.
push
(
callback
)
return
()
=>
this
.
off
(
name
,
callback
)
}
once
=
(
name
:
EventName
,
callback
:
EventCallback
):
EventStopHandler
=>
{
const
listener
=
(...
args
:
any
[])
=>
{
this
.
off
(
name
,
listener
)
callback
(...
args
)
}
this
.
on
(
name
,
listener
)
return
()
=>
this
.
off
(
name
,
listener
)
}
emit
=
(
name
:
EventName
,
...
args
:
any
[]):
void
=>
{
const
cbs
=
this
.
eventMap
.
get
(
name
)
if
(
cbs
instanceof
Array
)
{
cbs
.
forEach
((
cb
)
=>
{
typeof
cb
===
'
function
'
&&
cb
(...
args
)
})
}
}
off
=
(
names
?:
EventName
|
EventName
[],
callback
?:
EventCallback
):
void
=>
{
if
(
!
names
)
{
this
.
eventMap
.
clear
()
return
}
if
(
!
(
names
instanceof
Array
))
{
names
=
[
names
]
}
if
(
typeof
callback
===
'
function
'
)
{
names
.
forEach
((
name
)
=>
{
if
(
this
.
eventMap
.
has
(
name
))
{
this
.
eventMap
.
set
(
name
,
this
.
eventMap
.
get
(
name
)
!
.
filter
((
cb
)
=>
cb
!==
callback
)
)
}
})
}
else
{
names
.
forEach
((
name
)
=>
{
this
.
eventMap
.
delete
(
name
)
})
}
}
}
const
emitter
=
new
Emitter
()
export
const
$on
=
defineSyncApi
<
API_TYPE_ON
>
(
API_ON
,
(
type
,
callback
):
EventStopHandler
=>
emitter
.
on
(
type
,
callback
),
(
name
,
callback
):
EventStopHandler
=>
{
emitter
.
on
(
name
,
callback
)
return
()
=>
emitter
.
off
(
name
,
callback
)
},
OnProtocol
)
export
const
$once
=
defineSyncApi
<
API_TYPE_ONCE
>
(
API_ONCE
,
(
type
,
callback
):
EventStopHandler
=>
emitter
.
once
(
type
,
callback
),
(
name
,
callback
):
EventStopHandler
=>
{
emitter
.
once
(
name
,
callback
)
return
()
=>
emitter
.
off
(
name
,
callback
)
},
OnceProtocol
)
export
const
$off
=
defineSyncApi
<
API_TYPE_OFF
>
(
API_OFF
,
(
type
,
callback
)
=>
{
emitter
.
off
(
type
,
callback
)
(
name
,
callback
)
=>
{
if
(
!
name
)
{
emitter
.
e
=
{}
return
}
if
(
!
Array
.
isArray
(
name
))
name
=
[
name
]
name
.
forEach
((
n
)
=>
emitter
.
off
(
n
,
callback
))
},
OffProtocol
)
export
const
$emit
=
defineSyncApi
<
API_TYPE_EMIT
>
(
API_EMIT
,
emitter
.
emit
,
(
name
,
...
args
:
any
[])
=>
{
emitter
.
emit
(
name
,
...
args
)
},
EmitProtocol
)
packages/uni-api/src/service/context/canvas.ts
浏览文件 @
caa87deb
...
...
@@ -795,20 +795,21 @@ export class CanvasContext implements UniApp.CanvasContext {
;[...
methods1
,
...
methods2
].
forEach
(
function
(
method
)
{
function
get
(
method
:
string
)
{
// @ts-ignore
let
_this
=
this
as
CanvasContext
switch
(
method
)
{
case
'
fill
'
:
case
'
stroke
'
:
return
function
()
{
_this
.
actions
.
push
({
// @ts-ignore
this
.
actions
.
push
({
method
:
method
+
'
Path
'
,
data
:
[...
_this
.
path
],
// @ts-ignore
data
:
[...
this
.
path
],
})
}
case
'
fillRect
'
:
return
function
(
x
:
number
,
y
:
number
,
width
:
number
,
height
:
number
)
{
_this
.
actions
.
push
({
// @ts-ignore
this
.
actions
.
push
({
method
:
'
fillPath
'
,
data
:
[
{
...
...
@@ -820,7 +821,8 @@ export class CanvasContext implements UniApp.CanvasContext {
}
case
'
strokeRect
'
:
return
function
(
x
:
number
,
y
:
number
,
width
:
number
,
height
:
number
)
{
_this
.
actions
.
push
({
// @ts-ignore
this
.
actions
.
push
({
method
:
'
strokePath
'
,
data
:
[
{
...
...
@@ -837,7 +839,8 @@ export class CanvasContext implements UniApp.CanvasContext {
if
(
typeof
maxWidth
===
'
number
'
)
{
data
.
push
(
maxWidth
)
}
_this
.
actions
.
push
({
// @ts-ignore
this
.
actions
.
push
({
method
,
data
,
})
...
...
@@ -864,7 +867,7 @@ export class CanvasContext implements UniApp.CanvasContext {
dWidth
=
undefined
dHeight
=
undefined
}
let
data
:
ActionsItemD
ata
var
d
ata
function
isNumber
(
e
:
any
)
{
return
typeof
e
===
'
number
'
...
...
@@ -888,14 +891,16 @@ export class CanvasContext implements UniApp.CanvasContext {
:
isNumber
(
sWidth
)
&&
isNumber
(
sHeight
)
?
[
imageResource
,
sx
,
sy
,
sWidth
,
sHeight
]
:
[
imageResource
,
sx
,
sy
]
_this
.
actions
.
push
({
// @ts-ignore
this
.
actions
.
push
({
method
,
data
,
})
}
default
:
return
function
(...
data
:
ActionsItemData
)
{
_this
.
actions
.
push
({
return
function
(...
data
:
any
)
{
// @ts-ignore
this
.
actions
.
push
({
method
,
data
,
})
...
...
@@ -906,32 +911,29 @@ export class CanvasContext implements UniApp.CanvasContext {
})
methods3
.
forEach
(
function
(
method
)
{
function
get
(
method
:
string
)
{
// @ts-ignore
let
_this
=
this
as
CanvasContext
switch
(
method
)
{
case
'
setFillStyle
'
:
case
'
setStrokeStyle
'
:
return
function
(
color
:
string
|
Data
)
{
if
(
typeof
color
!==
'
object
'
)
{
_this
.
actions
.
push
({
// @ts-ignore
this
.
actions
.
push
({
method
,
data
:
[
'
normal
'
,
checkColor
(
color
)],
})
}
else
{
_this
.
actions
.
push
({
// @ts-ignore
this
.
actions
.
push
({
method
,
data
:
[
color
.
type
as
ActionsItemType
,
color
.
data
as
ActionsItemType
,
color
.
colorStop
as
ActionsItemType
,
],
data
:
[
color
.
type
,
color
.
data
,
color
.
colorStop
],
})
}
}
case
'
setGlobalAlpha
'
:
return
function
(
alpha
:
number
)
{
alpha
=
Math
.
floor
(
255
*
parseFloat
(
alpha
as
unknown
as
string
))
_this
.
actions
.
push
({
// @ts-ignore
this
.
actions
.
push
({
method
,
data
:
[
alpha
],
})
...
...
@@ -943,41 +945,52 @@ methods3.forEach(function (method) {
blur
:
number
,
color
:
string
)
{
let
_color
=
checkColor
(
color
)
_this
.
actions
.
push
({
color
=
checkColor
(
color
)
as
any
// @ts-ignore
this
.
actions
.
push
({
method
,
data
:
[
offsetX
,
offsetY
,
blur
,
color
],
})
_this
.
state
.
shadowBlur
=
blur
_this
.
state
.
shadowColor
=
_color
_this
.
state
.
shadowOffsetX
=
offsetX
_this
.
state
.
shadowOffsetY
=
offsetY
// @ts-ignore
this
.
state
.
shadowBlur
=
blur
// @ts-ignore
this
.
state
.
shadowColor
=
color
// @ts-ignore
this
.
state
.
shadowOffsetX
=
offsetX
// @ts-ignore
this
.
state
.
shadowOffsetY
=
offsetY
}
case
'
setLineDash
'
:
return
function
(
pattern
:
Array
<
number
>
|
undefined
,
offset
:
number
)
{
pattern
=
pattern
||
[
0
,
0
]
offset
=
offset
||
0
_this
.
actions
.
push
({
// @ts-ignore
this
.
actions
.
push
({
method
,
data
:
[
pattern
,
offset
],
})
_this
.
state
.
lineDash
=
pattern
// @ts-ignore
this
.
state
.
lineDash
=
pattern
}
case
'
setFontSize
'
:
return
function
(
fontSize
:
number
)
{
_this
.
state
.
font
=
_this
.
state
.
font
.
replace
(
// @ts-ignore
this
.
state
.
font
=
this
.
state
.
font
.
replace
(
/
\d
+
\.?\d
*px/
,
fontSize
+
'
px
'
)
_this
.
state
.
fontSize
=
fontSize
_this
.
actions
.
push
({
// @ts-ignore
this
.
state
.
fontSize
=
fontSize
// @ts-ignore
this
.
actions
.
push
({
method
,
data
:
[
fontSize
],
})
}
default
:
return
function
(...
data
:
ActionsItemData
)
{
_this
.
actions
.
push
({
return
function
(...
data
:
any
)
{
// @ts-ignore
this
.
actions
.
push
({
method
,
data
,
})
...
...
packages/uni-core/src/helpers/TinyEmitter.
j
s
→
packages/uni-core/src/helpers/TinyEmitter.
t
s
浏览文件 @
caa87deb
function
E
()
{
interface
E
{
e
:
Data
on
:
(
name
:
EventName
,
callback
:
EventCallback
,
ctx
?:
any
)
=>
this
once
:
(
name
:
EventName
,
callback
:
EventCallback
,
ctx
?:
any
)
=>
this
emit
:
(
name
:
EventName
,
...
args
:
any
[])
=>
this
off
:
(
name
:
EventName
,
callback
?:
EventCallback
)
=>
this
}
const
E
=
function
()
{
// Keep this empty so it's easier to inherit from
// (via https://github.com/lipsmack from https://github.com/scottcorgan/tiny-emitter/issues/3)
}
}
as
unknown
as
{
new
():
E
}
// export type EventName = string | number | symbol
export
type
EventName
=
string
export
type
EventCallback
=
Function
E
.
prototype
=
{
on
:
function
(
name
,
callback
,
ctx
)
{
on
:
function
(
name
:
EventName
,
callback
:
EventCallback
,
ctx
?:
any
)
{
var
e
=
this
.
e
||
(
this
.
e
=
{})
;(
e
[
name
]
||
(
e
[
name
]
=
[])).
push
({
...
...
@@ -15,7 +27,7 @@ E.prototype = {
return
this
},
once
:
function
(
name
,
callback
,
ctx
)
{
once
:
function
(
name
:
EventName
,
callback
:
EventCallback
,
ctx
?:
any
)
{
var
self
=
this
function
listener
()
{
self
.
off
(
name
,
listener
)
...
...
@@ -26,7 +38,7 @@ E.prototype = {
return
this
.
on
(
name
,
listener
,
ctx
)
},
emit
:
function
(
name
)
{
emit
:
function
(
name
:
EventName
)
{
var
data
=
[].
slice
.
call
(
arguments
,
1
)
var
evtArr
=
((
this
.
e
||
(
this
.
e
=
{}))[
name
]
||
[]).
slice
()
var
i
=
0
...
...
@@ -39,7 +51,7 @@ E.prototype = {
return
this
},
off
:
function
(
name
,
c
allback
)
{
off
:
function
(
name
:
EventName
,
callback
?:
EventC
allback
)
{
var
e
=
this
.
e
||
(
this
.
e
=
{})
var
evts
=
e
[
name
]
var
liveEvents
=
[]
...
...
packages/uni-core/src/helpers/index.ts
浏览文件 @
caa87deb
...
...
@@ -5,3 +5,4 @@ export * from './page'
export
*
from
'
./scroll
'
export
*
from
'
./getRealRoute
'
export
*
from
'
./callbacks
'
export
{
default
as
Emitter
}
from
'
./TinyEmitter
'
packages/uni-h5/dist/uni-h5.cjs.js
浏览文件 @
caa87deb
...
...
@@ -115,8 +115,8 @@ const initI18nVideoMsgsOnce = /* @__PURE__ */ uniShared.once(() => {
i18n
.
add
(
uniI18n
.
LOCALE_ZH_HANT
,
normalizeMessages
(
name
,
{
danmu
:
"
\
u5F48
\
u5E55
"
,
volume
:
"
\
u97F3
\
u91CF
"
}));
}
});
function
E
()
{
}
const
E
=
function
()
{
}
;
E
.
prototype
=
{
on
:
function
(
name
,
callback2
,
ctx
)
{
var
e2
=
this
.
e
||
(
this
.
e
=
{});
...
...
packages/uni-h5/dist/uni-h5.es.js
浏览文件 @
caa87deb
...
...
@@ -188,8 +188,8 @@ const initI18nVideoMsgsOnce = /* @__PURE__ */ once(() => {
i18n.add(LOCALE_ZH_HANT, normalizeMessages(name, {danmu: "\u5F48\u5E55", volume: "\u97F3\u91CF"}));
}
});
function E
() {
}
const E = function
() {
}
;
E.prototype = {
on: function(name, callback2, ctx) {
var e2 = this.e || (this.e = {});
...
...
@@ -2010,61 +2010,27 @@ const EmitProtocol = [
required: true
}
];
class Emitter {
constructor() {
this.on = (name, callback2) => {
if (!this.eventMap.has(name)) {
this.eventMap.set(name, []);
}
this.eventMap.get(name).push(callback2);
return () => this.off(name, callback2);
};
this.once = (name, callback2) => {
const listener2 = (...args) => {
this.off(name, listener2);
callback2(...args);
};
this.on(name, listener2);
return () => this.off(name, listener2);
};
this.emit = (name, ...args) => {
const cbs = this.eventMap.get(name);
if (cbs instanceof Array) {
cbs.forEach((cb) => {
typeof cb === "function" && cb(...args);
});
}
};
this.off = (names, callback2) => {
if (!names) {
this.eventMap.clear();
return;
}
if (!(names instanceof Array)) {
names = [names];
}
if (typeof callback2 === "function") {
names.forEach((name) => {
if (this.eventMap.has(name)) {
this.eventMap.set(name, this.eventMap.get(name).filter((cb) => cb !== callback2));
}
});
} else {
names.forEach((name) => {
this.eventMap.delete(name);
});
}
};
this.eventMap = new Map();
const emitter = new E();
const $on = /* @__PURE__ */ defineSyncApi(API_ON, (name, callback2) => {
emitter.on(name, callback2);
return () => emitter.off(name, callback2);
}, OnProtocol);
const $once = /* @__PURE__ */ defineSyncApi(API_ONCE, (name, callback2) => {
emitter.once(name, callback2);
return () => emitter.off(name, callback2);
}, OnceProtocol);
const $off = /* @__PURE__ */ defineSyncApi(API_OFF, (name, callback2) => {
if (!name) {
emitter.e = {};
return;
}
}
const emitter = new Emitter();
const $on = /* @__PURE__ */ defineSyncApi(API_ON, (type, callback2) => emitter.on(type, callback2), OnProtocol);
const $once = /* @__PURE__ */ defineSyncApi(API_ONCE, (type, callback2) => emitter.once(type, callback2), OnceProtocol);
const $off = /* @__PURE__ */ defineSyncApi(API_OFF, (type, callback2) => {
emitter.off(type, callback2);
if (!Array.isArray(name))
name = [name];
name.forEach((n) => emitter.off(n, callback2));
}, OffProtocol);
const $emit = /* @__PURE__ */ defineSyncApi(API_EMIT, emitter.emit, EmitProtocol);
const $emit = /* @__PURE__ */ defineSyncApi(API_EMIT, (name, ...args) => {
emitter.emit(name, ...args);
}, EmitProtocol);
const validator = [
{
name: "id",
...
...
@@ -2853,19 +2819,18 @@ class CanvasContext {
}
[...methods1, ...methods2].forEach(function(method) {
function get(method2) {
let _this = this;
switch (method2) {
case "fill":
case "stroke":
return function() {
_
this.actions.push({
this.actions.push({
method: method2 + "Path",
data: [...
_
this.path]
data: [...this.path]
});
};
case "fillRect":
return function(x, y, width, height) {
_
this.actions.push({
this.actions.push({
method: "fillPath",
data: [
{
...
...
@@ -2877,7 +2842,7 @@ class CanvasContext {
};
case "strokeRect":
return function(x, y, width, height) {
_
this.actions.push({
this.actions.push({
method: "strokePath",
data: [
{
...
...
@@ -2894,7 +2859,7 @@ class CanvasContext {
if (typeof maxWidth === "number") {
data.push(maxWidth);
}
_
this.actions.push({
this.actions.push({
method: method2,
data
});
...
...
@@ -2911,7 +2876,7 @@ class CanvasContext {
dWidth = void 0;
dHeight = void 0;
}
let
data;
var
data;
function isNumber(e2) {
return typeof e2 === "number";
}
...
...
@@ -2926,14 +2891,14 @@ class CanvasContext {
dWidth,
dHeight
] : isNumber(sWidth) && isNumber(sHeight) ? [imageResource, sx, sy, sWidth, sHeight] : [imageResource, sx, sy];
_
this.actions.push({
this.actions.push({
method: method2,
data
});
};
default:
return function(...data) {
_
this.actions.push({
this.actions.push({
method: method2,
data
});
...
...
@@ -2944,69 +2909,64 @@ class CanvasContext {
});
methods3.forEach(function(method) {
function get(method2) {
let _this = this;
switch (method2) {
case "setFillStyle":
case "setStrokeStyle":
return function(color) {
if (typeof color !== "object") {
_
this.actions.push({
this.actions.push({
method: method2,
data: ["normal", checkColor(color)]
});
} else {
_
this.actions.push({
this.actions.push({
method: method2,
data: [
color.type,
color.data,
color.colorStop
]
data: [color.type, color.data, color.colorStop]
});
}
};
case "setGlobalAlpha":
return function(alpha) {
alpha = Math.floor(255 * parseFloat(alpha));
_
this.actions.push({
this.actions.push({
method: method2,
data: [alpha]
});
};
case "setShadow":
return function(offsetX, offsetY, blur, color) {
let _
color = checkColor(color);
_
this.actions.push({
color = checkColor(color);
this.actions.push({
method: method2,
data: [offsetX, offsetY, blur, color]
});
_
this.state.shadowBlur = blur;
_this.state.shadowColor = _
color;
_
this.state.shadowOffsetX = offsetX;
_
this.state.shadowOffsetY = offsetY;
this.state.shadowBlur = blur;
this.state.shadowColor =
color;
this.state.shadowOffsetX = offsetX;
this.state.shadowOffsetY = offsetY;
};
case "setLineDash":
return function(pattern, offset) {
pattern = pattern || [0, 0];
offset = offset || 0;
_
this.actions.push({
this.actions.push({
method: method2,
data: [pattern, offset]
});
_
this.state.lineDash = pattern;
this.state.lineDash = pattern;
};
case "setFontSize":
return function(fontSize) {
_this.state.font = _
this.state.font.replace(/\d+\.?\d*px/, fontSize + "px");
_
this.state.fontSize = fontSize;
_
this.actions.push({
this.state.font =
this.state.font.replace(/\d+\.?\d*px/, fontSize + "px");
this.state.fontSize = fontSize;
this.actions.push({
method: method2,
data: [fontSize]
});
};
default:
return function(...data) {
_
this.actions.push({
this.actions.push({
method: method2,
data
});
...
...
@@ -3846,7 +3806,8 @@ const ShowActionSheetProtocol = {
type: Array,
required: true
},
itemColor: String
itemColor: String,
popover: Object
};
const ShowActionSheetOptions = {
formatArgs: {
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录