fix: change the interface options override of the field
This commit is contained in:
parent
32a8483336
commit
f24d948f83
@ -13,7 +13,7 @@ describe('models.collection', () => {
|
||||
|
||||
afterEach(() => app.database.close());
|
||||
|
||||
it.only('import', async () => {
|
||||
it('import', async () => {
|
||||
await app.database.getModel('collections').import({
|
||||
title: '示例',
|
||||
name: 'examples',
|
||||
|
@ -0,0 +1,23 @@
|
||||
import { Agent, getAgent, getApp } from '../';
|
||||
import { Application } from '@nocobase/server';
|
||||
import * as types from '../../interfaces/types';
|
||||
jest.setTimeout(30000);
|
||||
import { FieldModel } from '../../models';
|
||||
describe('models.field', () => {
|
||||
let app: Application;
|
||||
let agent: Agent;
|
||||
|
||||
beforeEach(async () => {
|
||||
app = await getApp();
|
||||
agent = getAgent(app);
|
||||
});
|
||||
|
||||
afterEach(() => app.database.close());
|
||||
|
||||
it('updatedAt', async () => {
|
||||
const Field = app.database.getModel('fields');
|
||||
const field = new Field();
|
||||
field.setInterface('updatedAt');
|
||||
expect(field.get()).toMatchObject(types.updatedAt.options)
|
||||
});
|
||||
});
|
@ -209,6 +209,17 @@ export default {
|
||||
type: 'drawerSelect',
|
||||
},
|
||||
},
|
||||
{
|
||||
interface: 'boolean',
|
||||
type: 'virtual',
|
||||
name: 'showTime',
|
||||
title: '显示时间',
|
||||
defaultValue: false,
|
||||
component: {
|
||||
type: 'boolean',
|
||||
showInForm: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
interface: 'boolean',
|
||||
type: 'boolean',
|
||||
|
@ -3,8 +3,9 @@ import * as types from '../interfaces/types';
|
||||
import _ from 'lodash';
|
||||
|
||||
export default async function (model: FieldModel) {
|
||||
model.generateNameIfNull();
|
||||
if (model.get('interface')) {
|
||||
model.setInterface(model.get('interface'));
|
||||
}
|
||||
// 生成随机 name 要放最后
|
||||
model.generateNameIfNull();
|
||||
}
|
||||
|
@ -85,7 +85,7 @@ export const percent = {
|
||||
sortable: true,
|
||||
precision: 0,
|
||||
component: {
|
||||
type: 'number',
|
||||
type: 'percent',
|
||||
suffix: '%',
|
||||
},
|
||||
},
|
||||
@ -205,7 +205,7 @@ export const datetime = {
|
||||
options: {
|
||||
interface: 'datetime',
|
||||
type: 'date',
|
||||
dateonly: false, // dateonly
|
||||
showTime: false,
|
||||
filterable: true,
|
||||
sortable: true,
|
||||
format: 'YYYY-MM-DD HH:mm:ss',
|
||||
@ -349,6 +349,8 @@ export const createdAt = {
|
||||
options: {
|
||||
interface: 'createdAt',
|
||||
type: 'date',
|
||||
name: 'created_at',
|
||||
showTime: true,
|
||||
required: true,
|
||||
filterable: true,
|
||||
sortable: true,
|
||||
@ -375,6 +377,8 @@ export const updatedAt = {
|
||||
options: {
|
||||
interface: 'updatedAt',
|
||||
type: 'date',
|
||||
name: 'updated_at',
|
||||
showTime: true,
|
||||
required: true,
|
||||
filterable: true,
|
||||
sortable: true,
|
||||
|
@ -22,8 +22,16 @@ export class FieldModel extends BaseModel {
|
||||
|
||||
setInterface(value) {
|
||||
const { options } = types[value];
|
||||
let args = [];
|
||||
// 如果是新数据或 interface 不相等,interface options 放后
|
||||
if (this.isNewRecord || this.get('interface') !== value) {
|
||||
args = [this.get(), options];
|
||||
} else {
|
||||
// 已存在的数据更新,不相等,interface options 放前面
|
||||
args = [options, this.get()];
|
||||
}
|
||||
// @ts-ignore
|
||||
const values = Utils.merge(options, this.get());
|
||||
const values = Utils.merge(...args);
|
||||
this.set(values);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user