浏览代码

refine code

czhen 3 年之前
父节点
当前提交
84913cafab
共有 2 个文件被更改,包括 4 次插入3 次删除
  1. 2 2
      client/src/pages/query/Query.tsx
  2. 2 1
      client/src/utils/Format.ts

+ 2 - 2
client/src/pages/query/Query.tsx

@@ -82,8 +82,8 @@ const Query: FC<{
   );
   );
 
 
   const csvDataMemo = useMemo(() => {
   const csvDataMemo = useMemo(() => {
-    const headers = fields?.map(i => i.name);
-    if (headers && queryResult) {
+    const headers: string[] = fields?.map(i => i.name);
+    if (headers?.length && queryResult?.length) {
       return generateCsvData(headers, queryResult);
       return generateCsvData(headers, queryResult);
     }
     }
     return '';
     return '';

+ 2 - 1
client/src/utils/Format.ts

@@ -201,7 +201,8 @@ export const generateCsvData = (headers: string[], rows: any[]) => {
       if (typeof val === 'string') {
       if (typeof val === 'string') {
         prev += val;
         prev += val;
       } else if (typeof val === 'object') {
       } else if (typeof val === 'object') {
-        prev += `"[${val}]"`;
+        // Use double quote to ensure csv display correctly
+        prev += `"${JSON.stringify(val)}"`;
       } else {
       } else {
         prev += `${val}`;
         prev += `${val}`;
       }
       }