From e00637f76c8afcf718c735b2fc448f1120c0f1ac Mon Sep 17 00:00:00 2001
From: tangjinzhou <415800467@qq.com>
Date: Fri, 26 Jun 2020 12:57:05 +0800
Subject: [PATCH] feat: update rate
---
components/rate/index.jsx | 33 ++++++++++-------------
components/vc-rate/src/Rate.jsx | 47 +++++++++++++--------------------
components/vc-rate/src/Star.jsx | 5 ++--
examples/App.vue | 2 +-
examples/index.js | 5 ++--
5 files changed, 40 insertions(+), 52 deletions(-)
diff --git a/components/rate/index.jsx b/components/rate/index.jsx
index d6d7eb411..c10fc3e42 100644
--- a/components/rate/index.jsx
+++ b/components/rate/index.jsx
@@ -1,11 +1,11 @@
+import { inject } from 'vue';
import omit from 'omit.js';
import PropTypes from '../_util/vue-types';
-import { getOptionProps, getComponentFromProp, getListeners } from '../_util/props-util';
+import { getOptionProps, getComponent } from '../_util/props-util';
import { ConfigConsumerProps } from '../config-provider';
import VcRate from '../vc-rate';
import StarFilled from '@ant-design/icons-vue/StarFilled';
import Tooltip from '../tooltip';
-import Base from '../base';
export const RateProps = {
prefixCls: PropTypes.string,
@@ -22,13 +22,11 @@ export const RateProps = {
const Rate = {
name: 'ARate',
- model: {
- prop: 'value',
- event: 'change',
- },
props: RateProps,
- inject: {
- configProvider: { default: () => ConfigConsumerProps },
+ setup() {
+ return {
+ configProvider: inject('configProvider', ConfigConsumerProps),
+ };
},
methods: {
characterRender(node, { index }) {
@@ -48,15 +46,13 @@ const Rate = {
const getPrefixCls = this.configProvider.getPrefixCls;
const prefixCls = getPrefixCls('rate', customizePrefixCls);
- const character = getComponentFromProp(this, 'character') || ;
+ const character = getComponent(this, 'character') || ;
const rateProps = {
- props: {
- character,
- characterRender: this.characterRender,
- prefixCls,
- ...omit(restProps, ['tooltips']),
- },
- on: getListeners(this),
+ character,
+ characterRender: this.characterRender,
+ prefixCls,
+ ...omit(restProps, ['tooltips']),
+ ...this.$attrs,
ref: 'refRate',
};
return ;
@@ -64,8 +60,7 @@ const Rate = {
};
/* istanbul ignore next */
-Rate.install = function(Vue) {
- Vue.use(Base);
- Vue.component(Rate.name, Rate);
+Rate.install = function(app) {
+ app.component(Rate.name, Rate);
};
export default Rate;
diff --git a/components/vc-rate/src/Rate.jsx b/components/vc-rate/src/Rate.jsx
index 3fce65bec..5838411dd 100644
--- a/components/vc-rate/src/Rate.jsx
+++ b/components/vc-rate/src/Rate.jsx
@@ -1,12 +1,7 @@
import PropTypes from '../../_util/vue-types';
import classNames from 'classnames';
import KeyCode from '../../_util/KeyCode';
-import {
- initDefaultProps,
- hasProp,
- getOptionProps,
- getComponentFromProp,
-} from '../../_util/props-util';
+import { initDefaultProps, hasProp, getOptionProps, getComponent } from '../../_util/props-util';
import BaseMixin from '../../_util/BaseMixin';
import { getOffsetLeft } from './util';
import Star from './Star';
@@ -30,10 +25,7 @@ function noop() {}
export default {
name: 'Rate',
mixins: [BaseMixin],
- model: {
- prop: 'value',
- event: 'change',
- },
+ inheritAttrs: false,
props: initDefaultProps(rateProps, {
defaultValue: 0,
count: 5,
@@ -167,33 +159,31 @@ export default {
sValue: value,
});
}
+ this.$emit('update:value', value);
this.$emit('change', value);
},
},
render() {
const { count, allowHalf, prefixCls, disabled, tabIndex } = getOptionProps(this);
const { sValue, hoverValue, focused } = this;
+ const { class: className, style } = this.$attrs;
const stars = [];
const disabledClass = disabled ? `${prefixCls}-disabled` : '';
- const character = getComponentFromProp(this, 'character');
- const characterRender = this.characterRender || this.$scopedSlots.characterRender;
+ const character = getComponent(this, 'character');
+ const characterRender = this.characterRender || this.$slots.characterRender;
for (let index = 0; index < count; index++) {
const starProps = {
- props: {
- index,
- count,
- disabled,
- prefixCls: `${prefixCls}-star`,
- allowHalf,
- value: hoverValue === undefined ? sValue : hoverValue,
- character,
- characterRender,
- focused,
- },
- on: {
- click: this.onClick,
- hover: this.onHover,
- },
+ index,
+ count,
+ disabled,
+ prefixCls: `${prefixCls}-star`,
+ allowHalf,
+ value: hoverValue === undefined ? sValue : hoverValue,
+ character,
+ characterRender,
+ focused,
+ onClick: this.onClick,
+ onHover: this.onHover,
key: index,
ref: `stars${index}`,
};
@@ -201,7 +191,8 @@ export default {
}
return (