fix(payment): 修正导入提示的服务端依赖判定键缺失

- 补全 is_known_dep_key 白名单:加入 only_pass_s 与 vip_exchange[time],其默认值统一按空字符串处理
- 修复服务端 !=/checked 类依赖因默认值缺失而错判的问题:自定义卡密的两条导入提示此前会被同时判为可见,导致四条提示全部铺开
- 服务端预判与行内 JS 求值器语义现已逐条对齐,任意状态下最多显示 1 条导入提示
This commit is contained in:
2026-09-16 22:46:26 +08:00
parent ef9409cee6
commit cb84c88792
+38 -9
View File
@@ -856,17 +856,29 @@ class PayChargeCards {
}
/**
* 服务端按表单默认值预判依赖可见性(求值规则与行内 JS 一致)。
* 参考主题 CSF 的 dependency 在 DOM ready 后才隐藏不满足项,首帧会闪现全部字段;
* 此处在渲染期直接置 display:none,修正「导入提醒初始全部显示」的问题。
* 服务端按表单默认值预判依赖可见性(求值规则与行内 JS 完全一致)。
* 仅在表单渲染默认值(添加方式=系统自动生成、类型=余额)下,把不满足依赖的行标记为初始隐藏,
* 避免四条导入提示首帧铺开。
*
* 注意:已知键必须覆盖 field_row/submessage_row 用到的所有依赖键,否则该键的判定会与 JS 不一致,
* 出现「服务端判可见、JS 判隐藏」之类的错配(例如自定义卡密的两条导入提示同时铺开)。
*
* @param array<int,array{key:string,op:string,val:string}> $deps
*/
private function deps_visible(array $deps): bool {
foreach ($deps as $dep) {
$v = (string) $this->default_form_value((string) ($dep['key'] ?? ''));
$key = (string) ($dep['key'] ?? '');
$val = (string) ($dep['val'] ?? '');
switch ((string) ($dep['op'] ?? '')) {
$op = (string) ($dep['op'] ?? '');
if (!$this->is_known_dep_key($key)) {
// 未登记的键:不做服务端判定,交 JS 处理。
continue;
}
$v = (string) $this->default_form_value($key);
switch ($op) {
case '==':
if ($v !== $val) {
return false;
@@ -897,9 +909,24 @@ class PayChargeCards {
return true;
}
/**
* 可在服务端求值的字段键(须完整覆盖表单依赖中使用的键,与 default_form_value 保持一致)。
*/
private function is_known_dep_key(string $key): bool {
static $known = [
'add_type',
'type',
'auto_top_s',
'only_pass_s',
'vip_exchange[time]',
'export_format',
'status',
];
return in_array($key, $known, true);
}
/**
* 表单字段的初始默认值(须与 field_row/button_set/spinner 渲染的默认值保持同步)。
* 未列出的键按空字符串处理,与行内 JS formVal 找不到元素时返回 '' 的行为一致。
*/
private function default_form_value(string $key): string {
switch ($key) {
@@ -907,13 +934,15 @@ class PayChargeCards {
return 'auto';
case 'type':
return 'balance';
case 'export_format':
return 'xls';
case 'status':
return 'all';
// 未勾选的 checkbox/switcher 与空文本,在依赖求值中均等价于空字符串。
case 'auto_top_s':
case 'only_pass_s':
return '';
case 'vip_exchange[time]':
return '';
case 'vip_exchange[unit]':
return 'month';
default:
return '';
}