优化任务附件字段展示

This commit is contained in:
andy
2026-07-12 20:42:04 +08:00
parent eda3e70873
commit c3dad8eae9
2 changed files with 326 additions and 5 deletions

View File

@@ -138,4 +138,131 @@ describe('ReservationTaskFieldRenderer', () => {
expect(wrapper.text()).toContain('客人姓名为必填项')
expect(wrapper.find('textarea').attributes('aria-invalid')).toBe('true')
})
it('renders file fields as attachment items instead of raw JSON', () => {
const i18n = createI18n({
legacy: false,
locale: 'zh-CN',
messages: {
'zh-CN': zhCN,
},
})
const fileField: ReservationTaskFieldResult = {
...fields[0]!,
row_number: 3,
display_area: '证据',
field_path: 'attachments',
display_name: '相关附件',
editable: 'N',
input_editable: 'N',
file_display: 'Y',
required_rule: 'N',
notes: '附件、图片、PDF、表格证据展示。',
value: null,
}
const wrapper = mount(ReservationTaskFieldRenderer, {
props: {
fields: [fileField],
modelValue: {
attachments: [
{
id: 'att-1',
name: 'WYNDHAM LIANTAI 2026 UPDATE BOOKING 12-05-2026 NO.1.xlsx',
content_type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
},
{
id: 'att-2',
file_name: 'Rooming List.pdf',
mime_type: 'application/pdf',
},
],
},
readOnly: true,
validationErrors: {},
},
global: {
plugins: [i18n],
},
})
expect(wrapper.findAll('.field-file-item')).toHaveLength(2)
expect(wrapper.text()).toContain('WYNDHAM LIANTAI 2026 UPDATE BOOKING 12-05-2026 NO.1.xlsx')
expect(wrapper.text()).toContain('Rooming List.pdf')
expect(wrapper.text()).toContain('Excel')
expect(wrapper.text()).toContain('PDF')
expect(wrapper.text()).not.toContain('{"id"')
expect(wrapper.text()).not.toContain('"name"')
expect(wrapper.text()).not.toContain('content_type')
})
it('only renders http and https attachment urls as links', () => {
const i18n = createI18n({
legacy: false,
locale: 'zh-CN',
messages: {
'zh-CN': zhCN,
},
})
const fileField: ReservationTaskFieldResult = {
...fields[0]!,
row_number: 3,
display_area: '证据',
field_path: 'attachments',
display_name: '相关附件',
editable: 'N',
input_editable: 'N',
file_display: 'Y',
required_rule: 'N',
notes: null,
value: null,
}
const wrapper = mount(ReservationTaskFieldRenderer, {
props: {
fields: [fileField],
modelValue: {
attachments: [
{
id: 'safe-1',
name: '安全附件.pdf',
external_url: 'https://oss.example/safe.pdf',
},
{
id: 'unsafe-js',
name: '脚本附件.pdf',
external_url: 'javascript:alert(1)',
},
{
id: 'unsafe-data',
name: '内联数据附件.pdf',
download_url: 'data:text/html;base64,PHNjcmlwdD5iYWQoKTwvc2NyaXB0Pg==',
},
{
id: 'unsafe-file',
name: '本地文件附件.pdf',
oss_url: 'file:///tmp/private.pdf',
},
],
},
readOnly: true,
validationErrors: {},
},
global: {
plugins: [i18n],
},
})
const links = wrapper.findAll('.field-file-item a')
expect(links).toHaveLength(1)
expect(links[0]?.text()).toBe('安全附件.pdf')
expect(links[0]?.attributes('href')).toBe('https://oss.example/safe.pdf')
expect(wrapper.text()).toContain('脚本附件.pdf')
expect(wrapper.text()).toContain('内联数据附件.pdf')
expect(wrapper.text()).toContain('本地文件附件.pdf')
expect(wrapper.html()).not.toContain('javascript:alert')
expect(wrapper.html()).not.toContain('data:text/html')
expect(wrapper.html()).not.toContain('file:///tmp/private.pdf')
})
})