|
|
|
@ -225,6 +225,7 @@ public class JxUIPane<T> extends ModernUIPane<T> {
|
|
|
|
|
private String variable; |
|
|
|
|
private String expression; |
|
|
|
|
private InjectJsCallback callback; |
|
|
|
|
private final Map<String, Object> namespacePropertyMap; |
|
|
|
|
private final Map<String, Object> propertyMap; |
|
|
|
|
private final Map<String, PropertyBuild> buildPropertyMap; |
|
|
|
|
private Object variableProperty; |
|
|
|
@ -238,6 +239,7 @@ public class JxUIPane<T> extends ModernUIPane<T> {
|
|
|
|
|
this.variable = DEFAULT_VARIABLE; |
|
|
|
|
this.expression = DEFAULT_EXPRESSION; |
|
|
|
|
this.callback = null; |
|
|
|
|
this.namespacePropertyMap = new HashMap<>(); |
|
|
|
|
this.propertyMap = new HashMap<>(); |
|
|
|
|
this.buildPropertyMap = new HashMap<>(); |
|
|
|
|
this.variableProperty = null; |
|
|
|
@ -334,6 +336,12 @@ public class JxUIPane<T> extends ModernUIPane<T> {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 设置该前端页面做数据交换所使用的对象 |
|
|
|
|
* 相当于: |
|
|
|
|
* const namespace = "Pool"; |
|
|
|
|
* 调用: |
|
|
|
|
* window[namespace]; |
|
|
|
|
* 默认下结构如: |
|
|
|
|
* window.Pool |
|
|
|
|
* |
|
|
|
|
* @param namespace 对象名 |
|
|
|
|
*/ |
|
|
|
@ -345,6 +353,12 @@ public class JxUIPane<T> extends ModernUIPane<T> {
|
|
|
|
|
/** |
|
|
|
|
* java端往js端传数据时使用的变量名字 |
|
|
|
|
* 默认值为 data |
|
|
|
|
* 相当于: |
|
|
|
|
* const variable = "data"; |
|
|
|
|
* 调用: |
|
|
|
|
* window[namespace][variable]; |
|
|
|
|
* 默认下结构如: |
|
|
|
|
* window.Pool.data |
|
|
|
|
* |
|
|
|
|
* @param name 变量的名字 |
|
|
|
|
*/ |
|
|
|
@ -364,16 +378,19 @@ public class JxUIPane<T> extends ModernUIPane<T> {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 注入一个java对象到js中,绑定在全局变量 window的 |
|
|
|
|
* property指定的变量。这个方法仅在在加载的网页上执 |
|
|
|
|
* 行 JavaScript 之前注入 |
|
|
|
|
* 注入一个java对象到js中,绑定在全局变量window的指定变量variable。 |
|
|
|
|
* variable 可由 {@link #namespace(String)} 设置,默认值为 data |
|
|
|
|
* 这个方法仅在在加载的网页上执行 JavaScript 之前注入 |
|
|
|
|
* 相当于: |
|
|
|
|
* window[namespace][property] = javaObject |
|
|
|
|
* 默认下: |
|
|
|
|
* window.Pool[property] = javaObject |
|
|
|
|
* |
|
|
|
|
* @param property 属性 |
|
|
|
|
* @param obj java对象 |
|
|
|
|
* @param obj java对象 |
|
|
|
|
* @return 链式对象 |
|
|
|
|
*/ |
|
|
|
|
public JxUIPane.Builder<T> property(String property, @Nullable Object obj) { |
|
|
|
|
this.propertyMap.put(property, obj); |
|
|
|
|
public JxUIPane.Builder<T> bindNamespace(String property, @Nullable Object obj) { |
|
|
|
|
this.namespacePropertyMap.put(property, obj); |
|
|
|
|
return this; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -381,25 +398,49 @@ public class JxUIPane<T> extends ModernUIPane<T> {
|
|
|
|
|
* 注入一个java对象到js中,绑定在全局变量window的指定变量variable。 |
|
|
|
|
* variable 可由 {@link #variable(String)} 设置,默认值为 data |
|
|
|
|
* 这个方法仅在在加载的网页上执行 JavaScript 之前注入 |
|
|
|
|
* 相当于: |
|
|
|
|
* window[namespace][variable] = javaObject |
|
|
|
|
* 默认下: |
|
|
|
|
* window.Pool.data = javaObject |
|
|
|
|
* |
|
|
|
|
* @param obj java对象 |
|
|
|
|
* @return 链式对象 |
|
|
|
|
*/ |
|
|
|
|
public JxUIPane.Builder<T> property(@NotNull Object obj) { |
|
|
|
|
public JxUIPane.Builder<T> bindVariable(@NotNull Object obj) { |
|
|
|
|
this.variableProperty = obj; |
|
|
|
|
return this; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 注入一个java对象到js中,绑定在全局变量 window的 |
|
|
|
|
* property指定的变量。这个方法仅在在加载的网页上执 |
|
|
|
|
* 行 JavaScript 之前注入 |
|
|
|
|
* 相当于: |
|
|
|
|
* window[property] = javaObject |
|
|
|
|
* |
|
|
|
|
* @param property 属性 |
|
|
|
|
* @param obj java对象 |
|
|
|
|
* @return 链式对象 |
|
|
|
|
* @see #bindWindow(String, PropertyBuild) |
|
|
|
|
*/ |
|
|
|
|
public JxUIPane.Builder<T> bindWindow(String property, @Nullable Object obj) { |
|
|
|
|
this.propertyMap.put(property, obj); |
|
|
|
|
return this; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 注入一个java对象到js中。绑定在全局变量 window的property指定的变量。 |
|
|
|
|
* PropertyBuild用于动态生成绑定属性。个方法仅在在加载的网页上执行 |
|
|
|
|
* JavaScript 之前注入 |
|
|
|
|
* 相当于: |
|
|
|
|
* window[property] = javaObject |
|
|
|
|
* |
|
|
|
|
* @param property 属性构建器 |
|
|
|
|
* @param obj java对象 |
|
|
|
|
* @return 链式对象 |
|
|
|
|
* @see #bindWindow(String, Object) |
|
|
|
|
*/ |
|
|
|
|
public JxUIPane.Builder<T> buildProperty(String property, PropertyBuild obj) { |
|
|
|
|
public JxUIPane.Builder<T> bindWindow(String property, PropertyBuild obj) { |
|
|
|
|
buildPropertyMap.put(property, obj); |
|
|
|
|
return this; |
|
|
|
|
} |
|
|
|
@ -442,6 +483,11 @@ public class JxUIPane<T> extends ModernUIPane<T> {
|
|
|
|
|
executeJsObject(frame, WINDOW) |
|
|
|
|
.ifPresent(window -> window.putProperty(key, value.build(window)))); |
|
|
|
|
} |
|
|
|
|
if (!namespacePropertyMap.isEmpty()) { |
|
|
|
|
namespacePropertyMap.forEach((key, value) -> |
|
|
|
|
executeJsObject(frame, WINDOW + DOT + namespace) |
|
|
|
|
.ifPresent(pool -> pool.putProperty(key, value))); |
|
|
|
|
} |
|
|
|
|
if (variableProperty != null) { |
|
|
|
|
executeJsObject(frame, WINDOW + DOT + namespace) |
|
|
|
|
.ifPresent(pool -> pool.putProperty(variable, variableProperty)); |
|
|
|
|