feat(plugin-field-sequence): allow to customize date format (#4685)

* feat(plugin-field-sequence): allow to customize date format

* chore(plugin-sequence): remove debug log
This commit is contained in:
Junyi 2024-06-18 01:11:30 +08:00 committed by GitHub
parent 9bef416d51
commit 3838793c50
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 23 additions and 2 deletions

View File

@ -34,7 +34,8 @@ function RuleTypeSelect(props) {
useFormEffects(() => { useFormEffects(() => {
onFieldValueChange(`patterns.${index}.type`, (field) => { onFieldValueChange(`patterns.${index}.type`, (field) => {
setValuesIn(`patterns.${index}.options`, {}); const type = RuleTypes[field.value];
setValuesIn(`patterns.${index}.options`, type.defaults ? { ...type.defaults } : {});
}); });
}); });
@ -194,6 +195,10 @@ const RuleTypes = {
default: null, default: null,
}, },
}, },
defaults: {
digits: 4,
start: 1,
},
}, },
date: { date: {
title: `{{t("Date", { ns: "${NAMESPACE}" })}}`, title: `{{t("Date", { ns: "${NAMESPACE}" })}}`,
@ -202,6 +207,19 @@ const RuleTypes = {
return <code>{options.value}</code>; return <code>{options.value}</code>;
}, },
}, },
fieldset: {
format: {
type: 'string',
title: `{{t("Date format", { ns: "${NAMESPACE}" })}}`,
description: `{{t('Supports all formats of the Day.js library, such as "YYYYMMDD", "YYYY-MM-DD", etc.', { ns: "${NAMESPACE}" })}}`,
'x-decorator': 'FormItem',
'x-component': 'Input',
default: 'YYYYMMDD',
},
},
defaults: {
format: 'YYYYMMDD',
},
}, },
}; };
@ -384,7 +402,7 @@ export class SequenceFieldInterface extends CollectionFieldInterface {
type: 'void', type: 'void',
'x-component': 'ArrayTable.Addition', 'x-component': 'ArrayTable.Addition',
'x-component-props': { 'x-component-props': {
defaultValue: { type: 'integer', options: { digits: 1, start: 0 } }, defaultValue: { type: 'integer', options: { ...RuleTypes.integer.defaults } },
}, },
title: `{{t("Add rule", { ns: "${NAMESPACE}" })}}`, title: `{{t("Add rule", { ns: "${NAMESPACE}" })}}`,
}, },

View File

@ -9,6 +9,9 @@
"Autoincrement": "自增数字", "Autoincrement": "自增数字",
"Fixed text": "固定文本", "Fixed text": "固定文本",
"Text content": "文本内容", "Text content": "文本内容",
"Date": "日期",
"Date format": "日期格式",
"Supports all formats of the Day.js library, such as \"YYYYMMDD\", \"YYYY-MM-DD\", etc.": "支持 Day.js 库的所有格式如“YYYYMMDD”、“YYYY-MM-DD”等。",
"Rule content": "规则内容", "Rule content": "规则内容",
"{{value}} Digits": "{{value}} 位数字", "{{value}} Digits": "{{value}} 位数字",
"Digits": "位数", "Digits": "位数",