feat(LoginUI): 按钮支持调用登录URL规则里的函数
This commit is contained in:
@@ -49,9 +49,10 @@ interface BaseSource : JsExtensions {
|
||||
}
|
||||
}
|
||||
|
||||
// 调用login函数 实现登录请求
|
||||
fun login() {
|
||||
getLoginJs()?.let {
|
||||
evalJS(it)
|
||||
evalJS("$it\nif(typeof login=='function'){login.apply(this);}else{throw('Function login not implements!!!')}")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -70,10 +70,12 @@ class SourceLoginDialog : BaseDialogFragment(R.layout.dialog_login, true) {
|
||||
context?.openUrl(rowUi.action!!)
|
||||
} else {
|
||||
// JavaScript
|
||||
rowUi.action?.let {
|
||||
rowUi.action?.let { buttonFunctionJS ->
|
||||
kotlin.runCatching {
|
||||
source.evalJS(it) {
|
||||
put("result", getLoginData(loginUi))
|
||||
source.getLoginJs()?.let { loginJS ->
|
||||
source.evalJS("$loginJS\n$buttonFunctionJS") {
|
||||
put("result", getLoginData(loginUi))
|
||||
}
|
||||
}
|
||||
}.onFailure {
|
||||
AppLog.put("LoginUI Button ${rowUi.name} JavaScript error", it)
|
||||
@@ -128,18 +130,16 @@ class SourceLoginDialog : BaseDialogFragment(R.layout.dialog_login, true) {
|
||||
dismiss()
|
||||
}
|
||||
} else if (source.putLoginInfo(GSON.toJson(loginData))) {
|
||||
source.getLoginJs()?.let {
|
||||
try {
|
||||
source.evalJS(it)
|
||||
context?.toastOnUi(R.string.success)
|
||||
withContext(Main) {
|
||||
dismiss()
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
AppLog.put("登录出错\n${e.localizedMessage}", e)
|
||||
context?.toastOnUi("登录出错\n${e.localizedMessage}")
|
||||
e.printOnDebug()
|
||||
try {
|
||||
source.login()
|
||||
context?.toastOnUi(R.string.success)
|
||||
withContext(Main) {
|
||||
dismiss()
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
AppLog.put("登录出错\n${e.localizedMessage}", e)
|
||||
context?.toastOnUi("登录出错\n${e.localizedMessage}")
|
||||
e.printOnDebug()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user