This commit is contained in:
kunfei 2023-01-16 11:59:53 +08:00
parent 17e0544e07
commit a5f45e9e98
2 changed files with 28 additions and 3 deletions

View File

@ -52,8 +52,8 @@ interface BaseSource : JsExtensions {
fun loginUi(): List<RowUi>? { fun loginUi(): List<RowUi>? {
return GSON.fromJsonArray<RowUi>(loginUi).onFailure { return GSON.fromJsonArray<RowUi>(loginUi).onFailure {
it.printOnDebug() it.printOnDebug()
}.getOrNull() }.getOrNull()
} }
fun getLoginJs(): String? { fun getLoginJs(): String? {
@ -66,7 +66,9 @@ interface BaseSource : JsExtensions {
} }
} }
// 调用login函数 实现登录请求 /**
* 调用login函数 实现登录请求
*/
fun login() { fun login() {
val loginJs = getLoginJs() val loginJs = getLoginJs()
if (!loginJs.isNullOrBlank()) { if (!loginJs.isNullOrBlank()) {
@ -198,6 +200,21 @@ interface BaseSource : JsExtensions {
return CacheManager.get("sourceVariable_${getKey()}") return CacheManager.get("sourceVariable_${getKey()}")
} }
/**
* 保存数据
*/
fun put(key: String, value: String): String {
CacheManager.put("v_${getKey()}_${key}", value)
return value
}
/**
* 获取保存的数据
*/
fun get(key: String): String {
return CacheManager.get("v_${getKey()}_${key}") ?: ""
}
/** /**
* 执行JS * 执行JS
*/ */

View File

@ -610,13 +610,20 @@ class AnalyzeRule(
XPath, Json, Default, Js, Regex XPath, Json, Default, Js, Regex
} }
/**
* 保存数据
*/
fun put(key: String, value: String): String { fun put(key: String, value: String): String {
chapter?.putVariable(key, value) chapter?.putVariable(key, value)
?: book?.putVariable(key, value) ?: book?.putVariable(key, value)
?: ruleData?.putVariable(key, value) ?: ruleData?.putVariable(key, value)
?: source?.put(key, value)
return value return value
} }
/**
* 获取保存的数据
*/
fun get(key: String): String { fun get(key: String): String {
when (key) { when (key) {
"bookName" -> book?.let { "bookName" -> book?.let {
@ -629,6 +636,7 @@ class AnalyzeRule(
return chapter?.getVariable(key) return chapter?.getVariable(key)
?: book?.getVariable(key) ?: book?.getVariable(key)
?: ruleData?.getVariable(key) ?: ruleData?.getVariable(key)
?: source?.get(key)
?: "" ?: ""
} }