From f8c338c2c8801ae9a7ef9e180a698d9d045730fd Mon Sep 17 00:00:00 2001 From: wangtianqi Date: Tue, 15 Oct 2024 17:47:45 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=86=E7=B1=BB=E5=88=9B=E5=BB=BA=E5=AE=8C?= =?UTF-8?q?=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../console/category/upsert/index.ts | 40 +++++++++ .../console/category/upsert/style.module.less | 3 + .../console/category/upsert/web.pc.tsx | 52 +++++++++++ src/features/Console.ts | 2 +- src/pages/console/category/list/index.ts | 2 +- .../console/category/list/locales/zh_CN.json | 5 +- src/pages/console/category/list/web.pc.tsx | 86 ++++++++++++++----- 7 files changed, 164 insertions(+), 26 deletions(-) create mode 100644 src/components/console/category/upsert/index.ts create mode 100644 src/components/console/category/upsert/style.module.less create mode 100644 src/components/console/category/upsert/web.pc.tsx diff --git a/src/components/console/category/upsert/index.ts b/src/components/console/category/upsert/index.ts new file mode 100644 index 0000000..666232e --- /dev/null +++ b/src/components/console/category/upsert/index.ts @@ -0,0 +1,40 @@ +import { extraFileProjection } from "@project/utils/projection"; + +export default OakComponent({ + entity: 'category', + isList: false, + projection: { + id: 1, + name: 1, + description: 1, + extraFile$entity: { + $entity: 'extraFile', + data: extraFileProjection, + filter: { + tag1: 'cover', + }, + sorter: [ + { + $attr: { + sort: 1, + }, + $direction: 'asc', + }, + ], + }, + }, + formData({ data }) { + return { + item: data, + }; + }, + lifetimes: { + ready() { + if (this.isCreation()) { + this.update({ + creatorId: features.token.getUserId(), + }); + } + }, + }, +}); diff --git a/src/components/console/category/upsert/style.module.less b/src/components/console/category/upsert/style.module.less new file mode 100644 index 0000000..e52fa8c --- /dev/null +++ b/src/components/console/category/upsert/style.module.less @@ -0,0 +1,3 @@ +.editor { + height: 100%; +} diff --git a/src/components/console/category/upsert/web.pc.tsx b/src/components/console/category/upsert/web.pc.tsx new file mode 100644 index 0000000..e78014c --- /dev/null +++ b/src/components/console/category/upsert/web.pc.tsx @@ -0,0 +1,52 @@ +import React from 'react'; +import { EntityDict } from '@project/oak-app-domain'; +import { RowWithActions, WebComponentProps } from 'oak-frontend-base'; +import Styles from './style.module.less'; +import { Button, Form, Input } from 'antd'; + +const CategoryUpsert = ( + props: WebComponentProps< + EntityDict, + 'category', + false, + { + item: RowWithActions + } + > +) => { + const { item } = props.data; + const { update, t } = props.methods; + + return ( +
+ {item ? ( +
+ + { + update({ name: e.target.value }); + }} + type='text' + placeholder={t('category:attr.name')} + /> + + + { + update({ description: e.target.value }); + }} + type='text' + placeholder={t('category:attr.description')} + /> + +
+ ) : ( +
No item
+ )} +
+ ); +}; + +export default CategoryUpsert; diff --git a/src/features/Console.ts b/src/features/Console.ts index 0e9202a..14e78bc 100644 --- a/src/features/Console.ts +++ b/src/features/Console.ts @@ -54,7 +54,7 @@ const menus: IMenu[] = [ url: '/relation/entityList', parent: 'System', }, - // category + // category { name: 'categoryManage', icon: 'stealth', diff --git a/src/pages/console/category/list/index.ts b/src/pages/console/category/list/index.ts index e18551c..c8d3251 100644 --- a/src/pages/console/category/list/index.ts +++ b/src/pages/console/category/list/index.ts @@ -48,7 +48,7 @@ export default OakComponent({ ], formData({ data }) { return { - list: data, + list: data.filter(item => (item.$$createAt$$ as number) > 1), }; }, actions: ['create', 'update', 'remove'], diff --git a/src/pages/console/category/list/locales/zh_CN.json b/src/pages/console/category/list/locales/zh_CN.json index 22f2a6a..5f1f279 100644 --- a/src/pages/console/category/list/locales/zh_CN.json +++ b/src/pages/console/category/list/locales/zh_CN.json @@ -1,4 +1,5 @@ { "pageHeader": "分类列表", - "author": "作者" -} \ No newline at end of file + "author": "作者", + "createCategory": "创建分类" +} diff --git a/src/pages/console/category/list/web.pc.tsx b/src/pages/console/category/list/web.pc.tsx index 120c197..761fbb8 100644 --- a/src/pages/console/category/list/web.pc.tsx +++ b/src/pages/console/category/list/web.pc.tsx @@ -7,7 +7,8 @@ import { } from 'oak-frontend-base'; import PageHeader from 'oak-frontend-base/es/components/pageHeader2'; import { ListPro } from '@project/components/AbstractComponents'; -import { Button, message } from 'antd'; +import { Button, message, Modal } from 'antd'; +import CategoryUpsert from '@project/components/console/category/upsert'; /** * 分类列表 @@ -25,7 +26,10 @@ const CategoryList = ( > ) => { const { list, oakFullpath } = props.data; - const { t } = props.methods; + const { t, navigateTo, updateItem, execute, addItem, clean, removeItem } = + props.methods; + + const [upsertId, setUpsertId] = React.useState(null); const attrs: OakAbsAttrDef[] = [ 'name', @@ -39,27 +43,65 @@ const CategoryList = ( }, ]; + const onAction = (row: any, action: string) => { + switch (action) { + case 'update': + setUpsertId(row.id); + break; + case 'remove': + removeItem(row.id); + execute(); + break; + default: + message.error('Unknown action'); + } + }; + return ( - { - message.info('create'); - }} - > - {t('common::action.create')} - - } - > - - + <> + { + setUpsertId(addItem({})); + }} + > + {t('common::action.create')} + + } + > + + + { + clean(); + setUpsertId(null); + }} + onOk={() => { + execute(); + setUpsertId(null); + }} + destroyOnClose + zIndex={10} + > + {oakFullpath && upsertId && ( + + )} + + ); };