feat: 评分 动作

This commit is contained in:
liuzedong02 2022-02-21 15:47:37 +08:00
parent 0b32350151
commit 690baef6a0
2 changed files with 29 additions and 3 deletions

View File

@ -15,8 +15,26 @@ export default {
body: [
{
name: "input-rating",
type: "input-rating",
option: "事件",
type: "action",
label: 'clear触发器',
level: 'primary',
onEvent: {
click: {
actions: [
{
actionType: 'clear',
componentId: 'clear-input-rating-receiver',
description: '点击清空指定输入框的内容'
}
]
}
}
},
{
name: 'rate',
id: 'clear-input-rating-receiver',
type: 'input-rating',
value: 3,
onEvent: {
change: {
actions: [

View File

@ -1,6 +1,7 @@
import React from 'react';
import {FormItem, FormControlProps, FormBaseControl} from './Item';
import {autobind, createObject} from '../../utils/helper';
import {Action} from '../../types';
import Rating, {textPositionType} from '../../components/Rating';
/**
@ -85,6 +86,13 @@ export default class RatingControl extends React.Component<RatingProps, any> {
readOnly: false
};
doAction(action: Action, data: object, throwErrors: boolean) {
const {resetValue} = this.props;
if (action.actionType && ['clear', 'reset'].includes(action.actionType)) {
this.handleChange(resetValue ?? '');
}
}
async dispatchChangeEvent(eventName: string, eventData: any = {}) {
const {dispatchEvent, data} = this.props;
let rendererEvent = await dispatchEvent(
@ -98,7 +106,7 @@ export default class RatingControl extends React.Component<RatingProps, any> {
}
@autobind
async handleChange(value: number) {
async handleChange(value: any) {
const {onChange} = this.props;
const prevented = await this.dispatchChangeEvent('change', value);