Skip to content

Commit

Permalink
增加 withLoading 的方法
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaojinzi123 committed May 23, 2024
1 parent b350e99 commit 66aa76e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,21 @@ class LoginUseCaseImpl(
}

@IntentProcess
@BusinessUseCase.AutoLoading
// @BusinessUseCase.AutoLoading
private suspend fun login(
intent: LoginIntent.Submit,
) {
delay(1000)
val name = nameStateOb.first()
val password = passwordStateOb.first()
AppServices
.userSpi
?.login(
name = name,
password = password,
)
withLoading {
delay(1000)
val name = nameStateOb.first()
val password = passwordStateOb.first()
AppServices
.userSpi
?.login(
name = name,
password = password,
)
}
confirmDialog(
// title = "提示".toStringItemDto(),
content = "登录成功".toStringItemDto(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,19 @@ open class BusinessUseCaseImpl(
ReactiveTemplate.errorHandle.invoke(error)
}

protected suspend fun <R> withLoading(block: suspend () -> R): R {
showLoading()
return runCatching {
block()
}.run {
hideLoading()
this.exceptionOrNull()?.run {
throw this
}
this.getOrThrow()
}
}

/**
* 自定义拦截处理, 判断是否有注解 AutoLoading 注解, 然后执行前后加上 loading 的显示和隐藏
*/
Expand Down

0 comments on commit 66aa76e

Please sign in to comment.