Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useEffect, useMemo, useState } from 'react';
import { Dropdown, Input, MenuProps, message, Modal, Space, Popover, Spin, Button } from 'antd';
import { Dropdown, Input, MenuProps, message, Modal, Space, Popover, Spin, Button, DatePicker } from 'antd';
import { BaseTable, ArtColumn, useTablePipeline, features, SortItem } from 'ali-react-table';
import styled from 'styled-components';
import classnames from 'classnames';
Expand All @@ -15,7 +15,7 @@ import styles from './index.less';
// 工具函数
import { compareStrings } from '@/utils/sort';
import { downloadFile } from '@/utils/file';
import { transformInputValue } from '../../utils';
import { transformInputValue, transformDateTimeValue } from '../../utils';

// 类型定义
import { CRUD } from '@/constants';
Expand Down Expand Up @@ -72,6 +72,10 @@ export enum USER_FILLED_VALUE {
DEFAULT = 'CHAT2DB_UPDATE_TABLE_DATA_USER_FILLED_DEFAULT',
}

export enum DATE_TIME {
DATEFORMAT = 'YYYY-MM-DD HH:mm:ss',
}

const SupportBaseTable: any = styled(BaseTable)`
&.supportBaseTable {
--bgcolor: var(--color-bg-base);
Expand Down Expand Up @@ -605,6 +609,7 @@ export default function TableBox(props: ITableProps) {
const isNumber = dataType === TableDataType.NUMERIC;
const isNumericalOrder = dataType === TableDataType.CHAT2DB_ROW_NUMBER;
const colId = `${preCode}${colIndex}${name}`;
const isDateTime = dataType === TableDataType.DATETIME;

if (isNumericalOrder) {
return {
Expand Down Expand Up @@ -652,6 +657,50 @@ export default function TableBox(props: ITableProps) {
};
}

if (isDateTime) {
return {
code: colId,
name: name,
key: name,
render: (value: any, rowData) => {
const rowId = rowData[colNoCode];
const content = renderTableCellValue(value);
return (
<div
data-chat2db-general-can-copy-element
data-chat2db-edit-table-data-can-paste
data-chat2db-edit-table-data-can-right-click
className={tableCellStyle(value, rowId, colId)}
onClick={handleClickTableItem.bind(null, colId, rowId, value, false)}
onDoubleClick={handleClickTableItem.bind(null, colId, rowId, value, true)}
onContextMenu={handleClickTableItem.bind(null, colId, rowId, value, false)}
>
{editingCell?.[0] === colId && editingCell?.[1] === rowId && editingCell?.[2] ?

(
<DatePicker
showTime
format={DATE_TIME.DATEFORMAT}
value={transformDateTimeValue(editingData) as any}
onChange={(_, dateString) => {
setEditingData(String(dateString));
}}
onBlur={() => {
setEditingCell([editingCell![0], editingCell![1], false]);
updateTableData('setCell', editingData);
}}
/>
) : (
<>
<div className={styles.tableItemContent}>{content}</div>
<div className={styles.previewTableItemContent}>{content}</div>
</>
)}
</div>
);
}
};
}
return {
code: colId,
name: name,
Expand Down
7 changes: 6 additions & 1 deletion chat2db-client/src/components/SearchResult/utils.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { USER_FILLED_VALUE } from './components/TableBox/index';
import { USER_FILLED_VALUE, DATE_TIME } from './components/TableBox/index';
import dayjs from 'dayjs';

// 在input中把USER_FILLED_VALUE转换为null
export const transformInputValue = (value: string) => {
Expand All @@ -7,3 +8,7 @@ export const transformInputValue = (value: string) => {
}
return value;
};

export const transformDateTimeValue = (value: string) => {
return dayjs(value, DATE_TIME.DATEFORMAT);
};
13 changes: 11 additions & 2 deletions chat2db-client/src/layouts/GlobalLayout/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import React, { useEffect, useLayoutEffect, useState } from 'react';
import usePollRequestService, { ServiceStatus } from '@/hooks/usePollRequestService';
import i18n, { isEn } from '@/i18n';
import i18n, { isZH, isTR, isJA } from '@/i18n';
import { Button, ConfigProvider, Spin, Tooltip } from 'antd';
import antdEnUS from 'antd/locale/en_US';
import antdZhCN from 'antd/locale/zh_CN';
import antdJaJP from 'antd/locale/ja_JP';
import antdTrTR from 'antd/locale/tr_TR';
import service from '@/service/misc';
import useCopyFocusData from '@/hooks/useFocusData';
import { useTheme } from '@/hooks/useTheme';
Expand Down Expand Up @@ -93,8 +95,15 @@ const GlobalLayout = () => {
);
}

const activeLang = () => {
if (isZH) return antdZhCN;
if (isJA) return antdJaJP;
if (isTR) return antdTrTR;
return antdEnUS;
};

return (
<ConfigProvider locale={isEn ? antdEnUS : antdZhCN} theme={antdTheme}>
<ConfigProvider locale={activeLang()} theme={antdTheme}>
<div className={styles.app}>
<div className={styles.appBody}>
<Outlet />
Expand Down