Files
platforms/frontend/platform_admin/scripts/check-contract-attachment-control.mjs

54 lines
1.8 KiB
JavaScript
Raw Normal View History

/**
* 功能检查合同附件控件保持独立单一文件输入键盘可访问及事件转发契约
* 版本v1.0.0
*/
import assert from 'node:assert/strict';
import { readFile } from 'node:fs/promises';
const componentPath = new URL(
'../src/views/resource/ContractAttachmentField.vue',
import.meta.url,
);
const formPath = new URL(
'../src/views/resource/ResourceFieldForm.vue',
import.meta.url,
);
const [component, form] = await Promise.all([
readFile(componentPath, 'utf8'),
readFile(formPath, 'utf8'),
]);
assert.equal(
component.includes('v-for='),
false,
'合同附件组件不得在 v-for 中持有模板引用',
);
assert.match(component, /ref="fileInput"/u, '组件必须持有唯一文件输入引用');
assert.match(
component,
/fileInput\.value\?\.click\(\)/u,
'点击区域必须调用单一文件输入元素',
);
assert.match(component, /@keydown\.enter\.prevent="openPicker"/u);
assert.match(component, /@keydown\.space\.prevent="openPicker"/u);
assert.match(component, /@drop\.prevent="selectDroppedFile"/u);
assert.match(component, /:tabindex="disabled \? -1 : 0"/u);
assert.match(component, /<a-space @click\.stop @keydown\.stop>/u);
assert.match(form, /<ContractAttachmentField/u);
assert.equal(
form.includes('ref="attachmentInput"'),
false,
'通用字段循环不得重新持有文件输入引用',
);
for (const marker of [
'@select="(file) => emit(\'select-attachment\', file)"',
'@remove="emit(\'remove-attachment\')"',
'@clear-selection="emit(\'clear-attachment-selection\')"',
'@preview="emit(\'preview-attachment\')"',
]) {
assert.ok(form.includes(marker), `ResourceFieldForm 缺少事件转发:${marker}`);
}
console.log('合同附件控件检查通过:单一引用、键盘入口、拖拽和事件转发均有效。');