Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
zuiqiangwanggong
vue-vben-admin
提交
bdce8453
V
vue-vben-admin
项目概览
zuiqiangwanggong
/
vue-vben-admin
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vue-vben-admin
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
bdce8453
编写于
10月 30, 2020
作者:
V
vben
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
perf(button): delete the button component useless code
上级
fb0c7763
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
95 addition
and
52 deletion
+95
-52
src/components/Button/index.vue
src/components/Button/index.vue
+46
-40
src/components/ClickOutSide/index.vue
src/components/ClickOutSide/index.vue
+2
-0
src/components/Scrollbar/src/Bar.tsx
src/components/Scrollbar/src/Bar.tsx
+1
-1
src/setup/directives/repeatClick.ts
src/setup/directives/repeatClick.ts
+24
-0
src/types/global.d.ts
src/types/global.d.ts
+6
-9
src/utils/domUtils.ts
src/utils/domUtils.ts
+16
-2
未找到文件。
src/components/Button/index.vue
浏览文件 @
bdce8453
<
template
>
<Button
v-bind=
"getBindValue"
:class=
"[getColor, $attrs.class]"
>
<!--
<template
#[item]=
"data"
v-for=
"item in Object.keys($slots)"
>
<slot
:name=
"item"
v-bind=
"data"
/>
</
template
>
-->
<template
#default
="
data
"
>
<Icon
:icon=
"preIcon"
class=
"mr-1
"
v-if=
"preIcon"
/>
<Icon
:icon=
"preIcon"
:class=
"
{ 'mr-1': !getIsCircleBtn }
" v-if="preIcon" />
<slot
v-bind=
"data"
/>
<Icon
:icon=
"postIcon"
class=
"ml-1
"
v-if=
"postIcon"
/>
<Icon
:icon=
"postIcon"
:class=
"
{ 'ml-1': !getIsCircleBtn }
" v-if="postIcon" />
</
template
>
</Button>
</template>
<
script
lang=
"ts"
>
import
{
PropType
}
from
'
vue
'
;
import
{
defineComponent
,
computed
,
unref
}
from
'
vue
'
;
import
{
defineComponent
,
computed
}
from
'
vue
'
;
import
{
Button
}
from
'
ant-design-vue
'
;
// import { extendSlots } from '/@/utils/helper/tsxHelper';
import
{
useThrottle
}
from
'
/@/hooks/core/useThrottle
'
;
import
{
isFunction
}
from
'
/@/utils/is
'
;
//
import { useThrottle } from '/@/hooks/core/useThrottle';
//
import { isFunction } from '/@/utils/is';
import
Icon
from
'
/@/components/Icon
'
;
export
default
defineComponent
({
name
:
'
AButton
'
,
...
...
@@ -30,18 +27,18 @@
default
:
'
default
'
,
},
// 节流防抖类型 throttle debounce
throttle
:
{
type
:
String
as
PropType
<
'
throttle
'
|
'
debounce
'
>
,
default
:
'
throttle
'
,
},
//
throttle: {
//
type: String as PropType
<
'
throttle
'
|
'
debounce
'
>
,
//
default: 'throttle',
//
},
color
:
{
type
:
String
as
PropType
<
'
error
'
|
'
warning
'
|
'
success
'
|
''
>
,
},
// 防抖节流时间
throttleTime
:
{
type
:
Number
as
PropType
<
number
>
,
default
:
0
,
},
//
//
防抖节流时间
//
throttleTime: {
//
type: Number as PropType
<
number
>
,
// default: 5
0,
//
},
loading
:
{
type
:
Boolean
as
PropType
<
boolean
>
,
default
:
false
,
...
...
@@ -58,30 +55,38 @@
},
},
setup
(
props
,
{
attrs
})
{
const
getListeners
=
computed
(()
=>
{
const
{
throttle
,
throttleTime
=
0
}
=
props
;
// 是否开启节流防抖
const
throttleType
=
throttle
!
.
toLowerCase
();
const
isDebounce
=
throttleType
===
'
debounce
'
;
const
openThrottle
=
[
'
throttle
'
,
'
debounce
'
].
includes
(
throttleType
)
&&
throttleTime
>
0
;
const
getIsCircleBtn
=
computed
(()
=>
{
return
attrs
.
shape
===
'
circle
'
;
});
// const getListeners = computed(() => {
// const { throttle, throttleTime = 0 } = props;
// // 是否开启节流防抖
// const throttleType = throttle!.toLowerCase();
// const isDebounce = throttleType === 'debounce';
// const openThrottle = ['throttle', 'debounce'].includes(throttleType) && throttleTime > 0;
// if (!openThrottle) {
// return {
// ...attrs,
// };
// }
const
on
:
{
onClick
?:
Fn
;
}
=
{};
//
const on: {
//
onClick?: Fn;
//
} = {};
if
(
attrs
.
onClick
&&
isFunction
(
attrs
.
onClick
)
&&
openThrottle
)
{
const
[
handler
]
=
useThrottle
(
attrs
.
onClick
as
any
,
throttleTime
!
,
{
debounce
:
isDebounce
,
immediate
:
tru
e
,
});
on
.
onClick
=
handler
;
}
//
if (attrs.onClick && isFunction(attrs.onClick) && openThrottle) {
//
const [handler] = useThrottle(attrs.onClick as any, throttleTime!, {
//
debounce: isDebounce,
// immediate: fals
e,
//
});
//
on.onClick = handler;
//
}
return
{
...
attrs
,
...
on
,
};
});
//
return {
//
...attrs,
//
...on,
//
};
//
});
const
getColor
=
computed
(()
=>
{
const
res
:
string
[]
=
[];
...
...
@@ -92,9 +97,10 @@
});
const
getBindValue
=
computed
(():
any
=>
{
return
{
...
unref
(
getListeners
)
,
...
props
};
return
{
...
attrs
,
...
props
};
});
return
{
getBindValue
,
getColor
};
return
{
getBindValue
,
getColor
,
getIsCircleBtn
};
},
});
</
script
>
src/components/ClickOutSide/index.vue
浏览文件 @
bdce8453
...
...
@@ -12,9 +12,11 @@
setup
(
_
,
{
emit
})
{
const
wrapRef
=
ref
<
Nullable
<
HTMLDivElement
|
null
>>
(
null
);
useClickOutside
(
wrapRef
as
Ref
<
HTMLDivElement
>
,
()
=>
{
emit
(
'
clickOutside
'
);
});
return
{
wrapRef
};
},
});
...
...
src/components/Scrollbar/src/Bar.tsx
浏览文件 @
bdce8453
...
...
@@ -17,7 +17,7 @@ export default defineComponent({
setup
(
props
)
{
const
thumbRef
=
ref
<
Nullable
<
HTMLDivElement
>>
(
null
);
const
elRef
=
ref
<
Nullable
<
HTMLDivElement
>>
(
null
);
const
commonState
=
reactive
<
KeyString
>
({});
const
commonState
=
reactive
<
Indexable
>
({});
const
getBarRef
=
computed
(()
=>
{
return
BAR_MAP
[
props
.
vertical
?
'
vertical
'
:
'
horizontal
'
];
});
...
...
src/setup/directives/repeatClick.ts
0 → 100644
浏览文件 @
bdce8453
import
{
on
,
once
}
from
'
/@/utils/domUtils
'
;
export
default
{
beforeMount
(
el
:
Element
,
binding
:
any
)
{
let
interval
:
ReturnType
<
typeof
setInterval
>
|
null
=
null
;
let
startTime
=
0
;
const
handler
=
()
=>
binding
.
value
&&
binding
.
value
();
const
clear
=
()
=>
{
if
(
Date
.
now
()
-
startTime
<
100
)
{
handler
();
}
interval
&&
clearInterval
(
interval
);
interval
=
null
;
};
on
(
el
,
'
mousedown
'
,
(
e
)
=>
{
if
((
e
as
any
).
button
!==
0
)
return
;
startTime
=
Date
.
now
();
once
(
document
as
any
,
'
mouseup
'
,
clear
);
interval
&&
clearInterval
(
interval
);
interval
=
setInterval
(
handler
,
100
);
});
},
};
src/types/global.d.ts
浏览文件 @
bdce8453
...
...
@@ -23,15 +23,12 @@ declare type RefType<T> = T | null;
declare
type
CustomizedHTMLElement
<
T
>
=
HTMLElement
&
T
;
declare
type
Indexable
<
T
>
=
{
declare
type
Indexable
<
T
=
any
>
=
{
[
key
:
string
]:
T
;
};
declare
type
Hash
<
T
>
=
Indexable
<
T
>
;
declare
type
KeyString
<
T
=
any
>
=
{
[
key
:
string
]:
T
;
};
type
DeepPartial
<
T
>
=
{
declare
type
DeepPartial
<
T
>
=
{
[
P
in
keyof
T
]?:
T
[
P
]
extends
(
infer
U
)[]
?
RecursivePartial
<
U
>
[]
:
T
[
P
]
extends
object
...
...
@@ -39,11 +36,11 @@ type DeepPartial<T> = {
:
T
[
P
];
};
type
SelectOptions
=
{
declare
type
SelectOptions
=
{
label
:
string
;
value
:
any
;
}[];
type
EmitType
=
(
event
:
string
,
...
args
:
any
[])
=>
void
;
declare
type
EmitType
=
(
event
:
string
,
...
args
:
any
[])
=>
void
;
type
TargetContext
=
'
_self
'
|
'
_blank
'
;
declare
type
TargetContext
=
'
_self
'
|
'
_blank
'
;
src/utils/domUtils.ts
浏览文件 @
bdce8453
...
...
@@ -15,9 +15,11 @@ export function getBoundingClientRect(element: Element): DOMRect | number {
}
return
element
.
getBoundingClientRect
();
}
const
trim
=
function
(
string
:
string
)
{
return
(
string
||
''
).
replace
(
/^
[\s\u
FEFF
]
+|
[\s\u
FEFF
]
+$/g
,
''
);
};
/* istanbul ignore next */
export
function
hasClass
(
el
:
Element
,
cls
:
string
)
{
if
(
!
el
||
!
cls
)
return
false
;
...
...
@@ -28,6 +30,7 @@ export function hasClass(el: Element, cls: string) {
return
(
'
'
+
el
.
className
+
'
'
).
indexOf
(
'
'
+
cls
+
'
'
)
>
-
1
;
}
}
/* istanbul ignore next */
export
function
addClass
(
el
:
Element
,
cls
:
string
)
{
if
(
!
el
)
return
;
...
...
@@ -130,7 +133,7 @@ export function hackCss(attr: string, value: string) {
/* istanbul ignore next */
export
const
on
=
function
(
element
:
HTMLElement
|
Document
|
Window
,
element
:
Element
|
HTMLElement
|
Document
|
Window
,
event
:
string
,
handler
:
EventListenerOrEventListenerObject
):
void
{
...
...
@@ -141,7 +144,7 @@ export const on = function (
/* istanbul ignore next */
export
const
off
=
function
(
element
:
HTMLElement
|
Document
|
Window
,
element
:
Element
|
HTMLElement
|
Document
|
Window
,
event
:
string
,
handler
:
Fn
):
void
{
...
...
@@ -149,3 +152,14 @@ export const off = function (
element
.
removeEventListener
(
event
,
handler
,
false
);
}
};
/* istanbul ignore next */
export
const
once
=
function
(
el
:
HTMLElement
,
event
:
string
,
fn
:
EventListener
):
void
{
const
listener
=
function
(
this
:
any
,
...
args
:
unknown
[])
{
if
(
fn
)
{
fn
.
apply
(
this
,
args
);
}
off
(
el
,
event
,
listener
);
};
on
(
el
,
event
,
listener
);
};
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录