import type { RecordSetValues } from '/@/api/ai/chat';
|
|
export class RecordSet {
|
names: string[];
|
values: Array<any[]>;
|
title: string;
|
constructor(data: RecordSetValues) {
|
this.names = data.names ?? [];
|
this.values = data.values ?? [];
|
this.title = data.title;
|
}
|
|
generateHTML() {
|
const thList = this.names.map((item) => {
|
return ` <th class="text-left py-3 px-4 uppercase font-semibold text-sm">${item}</th>`;
|
});
|
const trList = this.values.map((item) => {
|
const tdList = ((item??[])).map((subItem) => ` <td class="text-left py-3 px-4">${subItem}</td>`);
|
return ` <tr>
|
${tdList}
|
</tr>`;
|
});
|
return `
|
<div class="md:px-32 py-8 w-full">
|
<div class="shadow overflow-hidden rounded border-b border-gray-200">
|
<table class="min-w-full bg-white">
|
<thead class="bg-gray-800 text-white">
|
<tr>
|
${thList}
|
</tr>
|
</thead>
|
<tbody class="text-gray-700">
|
${trList}
|
</tbody>
|
</table>
|
</div>
|
</div>`;
|
}
|
}
|
|
|
|
const record = new RecordSet({
|
"json_ok": true,
|
"question": "昨日五一广场压力",
|
"answer_type": "recordset",
|
"values": {
|
"names": [
|
"yesterday",
|
"max_pressure"
|
],
|
"values": [
|
[
|
"2024-06-28 00:00:00",
|
24.378
|
],
|
[
|
"2024-06-29 00:00:00",
|
24.276
|
]
|
],
|
"type": "records",
|
"title": "昨日五一广场(D_GW_04)的最大压力值"
|
}
|
}.values)
|
|
const html = record.generateHTML();
|