fix: 优化筛选组件文本情况时加2s延迟,轮播图没有数据时添加提示 close #735 (#738)

Reviewed-on: daoyoucloud/tachycode#738
Co-authored-by: wjh <wwwjh0710@163.com>
Co-committed-by: wjh <wwwjh0710@163.com>
This commit is contained in:
wjh 2024-04-16 21:02:13 +08:00 committed by sealday
parent c7c497659d
commit 9d1d490f6e
4 changed files with 67 additions and 28 deletions

View File

@ -0,0 +1,5 @@
---
"@hera/plugin-mobile": patch
---
优化筛选组件在文本框情况时候延迟2s轮播图组件没有数据添加提示

View File

@ -2,38 +2,54 @@ import { BlockItem, css, useDesignable, useRequest, withDynamicSchemaProps } fro
import { useFieldSchema } from '@nocobase/schema'; import { useFieldSchema } from '@nocobase/schema';
import { Swiper } from 'antd-mobile'; import { Swiper } from 'antd-mobile';
import React, { useEffect, useState } from 'react'; import React, { useEffect, useState } from 'react';
import { useNavigate } from 'react-router-dom';
export const SwiperBlock = withDynamicSchemaProps((props) => { export const SwiperBlock = withDynamicSchemaProps((props) => {
const { fieldValue, data, changeNav } = props; const { fieldValue, data, changeNav } = props;
if (!data) return; if (!data) return;
const items = data['data'] const items = data['data'].length
?.map((imgItem, index) => { ? data['data']
return imgItem[fieldValue] ? ( .map((imgItem, index) => {
<Swiper.Item key={index}> return imgItem[fieldValue][0]?.url ? (
<Swiper.Item key={index}>
<div
className={swiperStyle}
style={{
backgroundImage: `url(${imgItem[fieldValue][0]?.url})`,
backgroundSize: '100% 100%',
backgroundAttachment: 'fixed',
}}
onClick={() => {
changeNav(imgItem);
}}
></div>
</Swiper.Item>
) : (
<Swiper.Item key={index}>
<div
className={swiperStyle}
style={{
backgroundColor: '#e0e0e0',
}}
>
</div>
</Swiper.Item>
);
})
.filter(Boolean)
: [
<Swiper.Item key={0}>
<div <div
className={css` className={swiperStyle}
height: 20vh;
color: #ffffff;
display: flex;
justify-content: center;
align-items: center;
font-size: 48px;
user-select: none;
`}
style={{ style={{
backgroundImage: `url(${imgItem[fieldValue][0].url})`, backgroundColor: '#e0e0e0',
backgroundSize: '100% 100%',
backgroundAttachment: 'fixed',
}} }}
onClick={() => { >
changeNav(imgItem);
}} </div>
></div> </Swiper.Item>,
</Swiper.Item> ];
) : null;
})
.filter(Boolean);
return ( return (
<BlockItem> <BlockItem>
<Swiper loop autoplay> <Swiper loop autoplay>
@ -42,3 +58,13 @@ export const SwiperBlock = withDynamicSchemaProps((props) => {
</BlockItem> </BlockItem>
); );
}); });
const swiperStyle = css`
height: 20vh;
color: #ffffff;
display: flex;
justify-content: center;
align-items: center;
font-size: 25px;
user-select: none;
`;

View File

@ -8,6 +8,7 @@ import {
import React from 'react'; import React from 'react';
import { createGridCardBlockSchema } from '../../schma-block/schema-create/createGridCardBlockSchma'; import { createGridCardBlockSchema } from '../../schma-block/schema-create/createGridCardBlockSchma';
import { ISchema } from '@nocobase/schema'; import { ISchema } from '@nocobase/schema';
import { Toast } from 'antd-mobile';
export const SwiperBlockInitializer = () => { export const SwiperBlockInitializer = () => {
const { insert } = useSchemaInitializer(); const { insert } = useSchemaInitializer();
@ -17,7 +18,10 @@ export const SwiperBlockInitializer = () => {
const onCreateBlockSchema = async ({ item }) => { const onCreateBlockSchema = async ({ item }) => {
const collection = cm.getCollection(item.name); const collection = cm.getCollection(item.name);
const value = collection.fields.find((field) => field.interface === 'attachment'); const value = collection.fields.find((field) => field.interface === 'attachment');
if (!value) return; if (!value) {
Toast.show({ content: '当前数据源暂无可加载数据' });
return;
}
const schema: ISchema = { const schema: ISchema = {
type: 'void', type: 'void',
name: item.name, name: item.name,

View File

@ -1,4 +1,4 @@
import { useMemo, useState } from 'react'; import { useMemo, useRef, useState } from 'react';
import { useFieldSchema } from '@nocobase/schema'; import { useFieldSchema } from '@nocobase/schema';
import { useCollection, useCollectionManager, useDesignable, useDesigner } from '@nocobase/client'; import { useCollection, useCollectionManager, useDesignable, useDesigner } from '@nocobase/client';
import { import {
@ -79,10 +79,14 @@ export const useTabSearchCollapsibleInputItemAction = (props) => {
setCustomLabelKey(label as string); setCustomLabelKey(label as string);
}; };
const onInputChange = (v) => { const onInputChange = (v) => {
const timeout = { current: null };
clearTimeout(timeout.current);
const inputValue = v.target?.value || v; const inputValue = v.target?.value || v;
setValue(inputValue); setValue(inputValue);
if (inputValue === '') { if (inputValue === '') {
onSelect(inputValue); timeout.current = setTimeout(() => {
onSelect(inputValue);
}, 2000);
} }
}; };
const onButtonClick = () => { const onButtonClick = () => {