Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
foreign
/
customer-service
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
ef42d6c7
authored
Jul 13, 2021
by
panjiangyi
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
buttonThrottle
parent
1f1dc90c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
2 deletions
chat-list.vue
utils/button-throttle.ts
chat-list.vue
View file @
ef42d6c7
...
...
@@ -68,9 +68,10 @@
</
template
>
<
script
lang=
"ts"
>
// import buttonThrottle from "@/utils/button-throttle";
import
{
Component
,
Prop
,
Vue
}
from
"vue-property-decorator"
;
import
buttonThrottle
from
"../utils/button-throttle"
;
import
{
chatStore
,
ChatStore
}
from
"@/customer-service/store/model"
;
// import { popupService } from "@/views/common-module/component/element-upgrades/fast-service-popup";
import
{
formatTime
,
TimeFormatRule
}
from
"@/customer-service/utils/time"
;
...
...
@@ -166,7 +167,7 @@ export default class ChatList extends Vue {
});
}
//
@buttonThrottle()
@
buttonThrottle
()
private
async
search
()
{
this
.
searchKeyword
=
this
.
searchKeyword
.
trim
();
if
(
!
this
.
searchKeyword
)
{
...
...
utils/button-throttle.ts
0 → 100644
View file @
ef42d6c7
function
changeCursor
(
btn
:
EventTarget
|
null
)
{
if
(
btn
==
null
)
{
return
()
=>
null
;
}
const
btnHTMLElement
=
btn
as
HTMLElement
;
const
oldCursor
=
btnHTMLElement
.
style
.
cursor
;
btnHTMLElement
.
style
.
cursor
=
"wait"
;
return
()
=>
{
btnHTMLElement
.
style
.
cursor
=
oldCursor
;
};
}
/*
* 请保证被包装的方法的参数列表最后一个是点击事件的参数
*/
export
default
function
buttonThrottle
()
{
let
pending
=
false
;
return
function
(
target
:
any
,
name
:
string
):
any
{
const
btnClickFunc
=
target
[
name
];
const
newFunc
=
async
function
(
this
:
Vue
,
...
params
:
any
[])
{
if
(
pending
)
{
return
;
}
const
event
:
Event
=
params
[
params
.
length
-
1
];
const
btn
=
event
?.
target
;
pending
=
true
;
const
recoverCursor
=
changeCursor
(
btn
);
try
{
await
btnClickFunc
.
apply
(
this
,
params
);
}
catch
(
error
)
{
// eslint-disable-next-line no-console
console
.
error
(
error
);
}
recoverCursor
();
pending
=
false
;
};
target
[
name
]
=
newFunc
;
return
target
;
};
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment