From 5d51d312dcba2ddafda5eb58e7c5c350d9632f85 Mon Sep 17 00:00:00 2001 From: "bai.zixv" Date: Fri, 30 Aug 2024 14:11:14 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E8=B7=B3=E8=BD=AC=E9=A1=B5=E9=9D=A2=20(#1499)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: wjh Reviewed-on: https://git.daoyoucloud.com/daoyoucloud/tachybase/pulls/1499 --- .../grid-card/gridCardBlockSettings.ts | 59 ++++++++++++++++++- .../antd/grid-card/GridCard.Item.tsx | 4 +- .../schema-component/antd/grid-card/hooks.ts | 12 ++++ .../plugin-sancongtou/src/client/index.tsx | 5 ++ .../src/client/pages/testPage/testPage.tsx | 46 +++++++++++++++ 5 files changed, 123 insertions(+), 3 deletions(-) create mode 100644 packages/plugins/@hera/plugin-sancongtou/src/client/pages/testPage/testPage.tsx diff --git a/packages/core/client/src/modules/blocks/data-blocks/grid-card/gridCardBlockSettings.ts b/packages/core/client/src/modules/blocks/data-blocks/grid-card/gridCardBlockSettings.ts index aaf0e34ed..ed9d1f9e0 100644 --- a/packages/core/client/src/modules/blocks/data-blocks/grid-card/gridCardBlockSettings.ts +++ b/packages/core/client/src/modules/blocks/data-blocks/grid-card/gridCardBlockSettings.ts @@ -1,4 +1,5 @@ import { useMemo } from 'react'; +import { useCollection, useCollectionFields, useCollectionManager, useDataSource } from '@tachybase/client'; import { ArrayItems } from '@tachybase/components'; import { ISchema, useField, useFieldSchema } from '@tachybase/schema'; @@ -7,7 +8,7 @@ import { useTranslation } from 'react-i18next'; import { SchemaSettings } from '../../../../application/schema-settings/SchemaSettings'; import { useFormBlockContext } from '../../../../block-provider'; -import { useCollection_deprecated, useSortFields } from '../../../../collection-manager'; +import { useCollection_deprecated, useCollectionFieldsOptions, useSortFields } from '../../../../collection-manager'; import { removeNullCondition, useDesignable } from '../../../../schema-component'; import { defaultColumnCount, @@ -301,6 +302,10 @@ export const gridCardBlockSettings = new SchemaSettings({ }, }; }, + useVisible() { + const fieldSchema = useFieldSchema(); + return fieldSchema['x-decorator-props']?.['linkConfig']?.['link']; + }, }, { name: 'setInfiniteScroll', @@ -326,6 +331,58 @@ export const gridCardBlockSettings = new SchemaSettings({ }; }, }, + { + name: 'setLinkConfig', + type: 'modal', + useComponentProps() { + const { t } = useTranslation(); + const collection = useCollection(); + const fieldSchema = useFieldSchema(); + const fields = useSortFields(fieldSchema['x-decorator-props']?.['collection'] || collection.name); + const { dn } = useDesignable(); + const dataSource = useDataSource(); + return { + title: t('Set LinkConfig'), + schema: { + type: 'object', + title: 'Set LinkConfig', + properties: { + link: { + type: 'string', + title: t('Link'), + required: true, + 'x-decorator': 'FormItem', + 'x-component': 'Input', + default: fieldSchema['x-decorator-props']?.['linkConfig']?.['link'] || '', + }, + fields: { + type: 'object', + title: t('Field'), + 'x-decorator': 'FormItem', + 'x-component': 'Select', + enum: fields, + default: fieldSchema['x-decorator-props']?.['linkConfig']?.['fields'] || null, + 'x-component-props': { + multiple: true, + }, + }, + }, + }, + onSubmit: (value) => { + fieldSchema['x-decorator-props']['linkConfig'] = { + ...fieldSchema['x-decorator-props']?.['linkConfig'], + link: value.link, + fields: value.fields, + linkDataSource: dataSource.key, + linkCollection: collection.name, + }; + dn.emit('patch', { + schema: { 'x-uid': fieldSchema['x-uid'], 'x-decorator-props': fieldSchema['x-decorator-props'] }, + }); + }, + }; + }, + }, { name: 'ConvertReferenceToDuplicate', Component: SchemaSettingsTemplate, diff --git a/packages/core/client/src/schema-component/antd/grid-card/GridCard.Item.tsx b/packages/core/client/src/schema-component/antd/grid-card/GridCard.Item.tsx index d11865fd7..023df983c 100644 --- a/packages/core/client/src/schema-component/antd/grid-card/GridCard.Item.tsx +++ b/packages/core/client/src/schema-component/antd/grid-card/GridCard.Item.tsx @@ -9,7 +9,7 @@ import { withDynamicSchemaProps } from '../../../application/hoc/withDynamicSche import { useCollection } from '../../../data-source'; import { useCollectionParentRecordData } from '../../../data-source/collection-record/CollectionRecordProvider'; import { RecordProvider } from '../../../record-provider'; -import { useGridCardDetailUrl } from './hooks'; +import { useGridCardDetailUrl, useGridCustomPageUrl } from './hooks'; const useStyles = createStyles(({ css }) => { return { @@ -42,7 +42,7 @@ export const GridCardItem = withDynamicSchemaProps((props) => { const parentRecordData = useCollectionParentRecordData(); const navigate = useNavigate(); const { styles } = useStyles(); - const detailUrl = useGridCardDetailUrl({ collection, field, fieldSchema }); + const detailUrl = useGridCustomPageUrl({ field, fieldSchema }); // XXX: 实现的有些丑陋, 需要想想有没有更好的办法 const handleClick = () => { // 1. 依赖schema的层级,不合适 diff --git a/packages/core/client/src/schema-component/antd/grid-card/hooks.ts b/packages/core/client/src/schema-component/antd/grid-card/hooks.ts index ac2c64a26..e8ef5db93 100644 --- a/packages/core/client/src/schema-component/antd/grid-card/hooks.ts +++ b/packages/core/client/src/schema-component/antd/grid-card/hooks.ts @@ -20,3 +20,15 @@ export const useGridCardDetailUrl = ({ collection, field, fieldSchema }) => { return `/mobile/${name}/${datasource}/${collectionName}/${primaryKeyValue}`; }; + +export const useGridCustomPageUrl = ({ field, fieldSchema }) => { + const { linkCollection, fields, linkDataSource, link } = + fieldSchema?.parent?.parent?.['x-decorator-props']?.['linkConfig'] || {}; + const { record } = field; + let options = '?'; + fields.forEach((item, index) => { + if (!record[item]) return; + return (options += `${index === 0 ? '' : '&'}${item}=${record[item]}`); + }); + return `${link}/${linkDataSource}/${linkCollection}${options}`; +}; diff --git a/packages/plugins/@hera/plugin-sancongtou/src/client/index.tsx b/packages/plugins/@hera/plugin-sancongtou/src/client/index.tsx index 306442104..13f62ece2 100644 --- a/packages/plugins/@hera/plugin-sancongtou/src/client/index.tsx +++ b/packages/plugins/@hera/plugin-sancongtou/src/client/index.tsx @@ -4,6 +4,7 @@ import { Plugin } from '@tachybase/client'; import { ShareProduct } from './custom-components/ShareProduct'; import { ShowDetail } from './custom-components/ShowDetail'; import { CardDetailSC, SCCardDetail } from './pages/CardDetail.schema'; +import { TestPage } from './pages/testPage/testPage'; import { getPathProductDetail } from './utils/path'; export class PluginSancongtouClient extends Plugin { @@ -48,6 +49,10 @@ export class PluginSancongtouClient extends Plugin { }), Component: CardDetailSC, }); + this.app.router.add('mobile.testPage', { + path: '/mobile/:name/detail/:dataSource/:collection', + Component: TestPage, + }); } } diff --git a/packages/plugins/@hera/plugin-sancongtou/src/client/pages/testPage/testPage.tsx b/packages/plugins/@hera/plugin-sancongtou/src/client/pages/testPage/testPage.tsx new file mode 100644 index 000000000..82881e401 --- /dev/null +++ b/packages/plugins/@hera/plugin-sancongtou/src/client/pages/testPage/testPage.tsx @@ -0,0 +1,46 @@ +import React, { useState } from 'react'; +import { css, useRequest } from '@tachybase/client'; + +import { useLocation, useParams } from 'react-router-dom'; + +export const TestPage = () => { + const search = useLocation().search; + const { dataSource, collection } = useParams(); + const filter = {}; + if (search.includes('?')) { + const options = search.slice(1).split('&'); + options.forEach((item) => { + const filterValue = item.split('='); + filter[filterValue[0]] = filterValue[1]; + }); + } + const { data } = useRequest({ + resource: collection, + action: 'list', + params: { + filter, + appends: ['main_images'], + }, + }); + return ( + data?.data && ( +
+ {data.data?.map((item) => { + return ( +
+ {item.main_images?.map((image) => { + return ; + })} +
+ ); + })} +
+ ) + ); +};