gerson
2024-09-07 37179a65229455f540dc3ca62d31c4716e15d12d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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();