Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat:新增签名组件增加回显 #11297

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions docs/zh-CN/components/form/input-date.md
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,41 @@ order: 13
}
```

### 通过 props env moment 自定义控制

经常在表单遇到开始时间和结束时间表单项分开的,但又有联动,规则还复杂,valueFormat 又是特定格式,而不是默认的时间戳格式(这样 minDate 和 maxDate 就会失效),等等限制。可以通过 `props env moment` 字符函数将表单项转为 Moment 格式,就方便许多,以及更灵活,比如下面例子:需要禁用某些日期,开始时间小于结束时间,结束时间大于开始时间,通过 props env moment 更灵活配置。

```schema: scope="body"
{
"type": "form",
"debug": true,
"api": "/api/mock2/form/saveForm",
"body": [
{
"type": "input-date",
"name": "start",
"label": "开始时间",
"required": true,
"valueFormat": "YYYY-MM-DD HH:mm:ss",
"placeholder": "请选择日期以及时间",
"displayFormat": "YYYY-MM-DD HH:mm:ss",
"disabledDate": "if(!props.data.end)return;const moment = props.env.moment();const maxDate = moment(props.data.end).valueOf();return currentDate.valueOf() > maxDate"
},
{
"type": "input-date",
"name": "end",
"label": "结束时间",
"required": true,
"valueFormat": "YYYY-MM-DD HH:mm:ss",
"placeholder": "请选择日期以及时间",
"displayFormat": "YYYY-MM-DD HH:mm:ss",
"disabledDate": "console.log(props);if(!props.data.start)return false;const moment = props.env.moment();const minDate = moment(props.data.start).valueOf();return currentDate.valueOf() < minDate"
},

]
}
```

## 快捷键

你也可以配置`shortcuts`属性支持快捷选择日期
Expand Down
5 changes: 4 additions & 1 deletion packages/amis-core/src/factory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import type {RendererEnv} from './env';
import {OnEventProps, RendererEvent} from './utils/renderer-event';
import {Placeholder} from './renderers/Placeholder';
import {StatusScopedProps} from './StatusScoped';
import moment from 'moment';

export interface TestFunc {
(
Expand Down Expand Up @@ -135,6 +136,7 @@ export interface RenderOptions
session?: string;
theme?: string;
fetcher?: (config: FetcherConfig) => Promise<fetcherResult>;
moment?: () => typeof moment;
}

const renderers: Array<RendererConfig> = [];
Expand Down Expand Up @@ -537,7 +539,8 @@ export const defaultOptions: RenderOptions = {
* 过滤 html 标签,可用来添加 xss 保护逻辑
*/
filterHtml: (input: string) => input,
isMobile: isMobile
isMobile: isMobile,
moment: () => moment
};

export const stores: {
Expand Down
1 change: 0 additions & 1 deletion packages/amis-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
"react-textarea-autosize": "8.3.3",
"react-transition-group": "4.4.2",
"react-visibility-sensor": "5.1.1",
"smooth-signature": "^1.0.15",
"sortablejs": "1.15.0",
"tinymce": "^6.1.2",
"tslib": "^2.3.1",
Expand Down
8 changes: 7 additions & 1 deletion packages/amis-ui/src/components/Signature.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import React from 'react';
import {themeable, ThemeProps} from 'amis-core';
import {LocaleProps, localeable} from 'amis-core';
import {resizeSensor} from 'amis-core';
import SmoothSignature from 'smooth-signature';
import {SmoothSignature} from '../utils';
import Button from './Button';
import {Icon} from '../index';
import Modal from './Modal';
Expand Down Expand Up @@ -118,6 +118,12 @@ const Signature: React.FC<ISignatureProps> = props => {
[width, height, fullScreen]
);

React.useEffect(() => {
if (data && sign && sign !== null) {
sign.loadFromBase64(data);
}
}, [data, sign]);

function embedCanvasRef(ref: HTMLCanvasElement) {
if (open && ref && !sign) {
initCanvas(ref);
Expand Down
3 changes: 3 additions & 0 deletions packages/amis-ui/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import SmoothSignature from './smoothSignature';

export {SmoothSignature};
Loading
Loading