mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 05:36:05 +00:00
fix: import with big date (#5356)
This commit is contained in:
parent
442a881ba2
commit
259b0b707a
@ -12,6 +12,7 @@ import { TemplateCreator } from '../services/template-creator';
|
|||||||
import { XlsxImporter } from '../services/xlsx-importer';
|
import { XlsxImporter } from '../services/xlsx-importer';
|
||||||
import XLSX from 'xlsx';
|
import XLSX from 'xlsx';
|
||||||
import * as process from 'node:process';
|
import * as process from 'node:process';
|
||||||
|
import moment from 'moment';
|
||||||
|
|
||||||
describe('xlsx importer', () => {
|
describe('xlsx importer', () => {
|
||||||
let app: MockServer;
|
let app: MockServer;
|
||||||
@ -25,6 +26,68 @@ describe('xlsx importer', () => {
|
|||||||
await app.destroy();
|
await app.destroy();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('import with date field', () => {
|
||||||
|
let User;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
User = app.db.collection({
|
||||||
|
name: 'users',
|
||||||
|
fields: [
|
||||||
|
{
|
||||||
|
type: 'string',
|
||||||
|
name: 'name',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'date',
|
||||||
|
name: 'date',
|
||||||
|
interface: 'datetime',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
await app.db.sync();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should import with date', async () => {
|
||||||
|
const columns = [
|
||||||
|
{
|
||||||
|
dataIndex: ['name'],
|
||||||
|
defaultTitle: '姓名',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
dataIndex: ['date'],
|
||||||
|
defaultTitle: '日期',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const templateCreator = new TemplateCreator({
|
||||||
|
collection: User,
|
||||||
|
columns,
|
||||||
|
});
|
||||||
|
|
||||||
|
const template = await templateCreator.run();
|
||||||
|
|
||||||
|
const worksheet = template.Sheets[template.SheetNames[0]];
|
||||||
|
|
||||||
|
XLSX.utils.sheet_add_aoa(worksheet, [['test', 77383]], { origin: 'A2' });
|
||||||
|
|
||||||
|
const importer = new XlsxImporter({
|
||||||
|
collectionManager: app.mainDataSource.collectionManager,
|
||||||
|
collection: User,
|
||||||
|
columns,
|
||||||
|
workbook: template,
|
||||||
|
});
|
||||||
|
|
||||||
|
await importer.run();
|
||||||
|
|
||||||
|
expect(await User.repository.count()).toBe(1);
|
||||||
|
|
||||||
|
const user = await User.repository.findOne();
|
||||||
|
|
||||||
|
expect(moment(user.get('date')).format('YYYY-MM-DD')).toBe('2111-11-12');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('import with select fields', () => {
|
describe('import with select fields', () => {
|
||||||
let User;
|
let User;
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
|
@ -223,7 +223,7 @@ export class XlsxImporter extends EventEmitter {
|
|||||||
|
|
||||||
getData() {
|
getData() {
|
||||||
const firstSheet = this.firstSheet();
|
const firstSheet = this.firstSheet();
|
||||||
const rows = XLSX.utils.sheet_to_json(firstSheet, { header: 1, defval: null, raw: false });
|
const rows = XLSX.utils.sheet_to_json(firstSheet, { header: 1, defval: null });
|
||||||
|
|
||||||
if (this.options.explain) {
|
if (this.options.explain) {
|
||||||
rows.shift();
|
rows.shift();
|
||||||
|
Loading…
Reference in New Issue
Block a user