2019-03-18 20:00:00 +08:00
|
|
|
import omit from 'omit.js';
|
2019-01-12 11:33:27 +08:00
|
|
|
import PropTypes from '../_util/vue-types';
|
2019-03-18 20:00:00 +08:00
|
|
|
import { getOptionProps, getComponentFromProp } from '../_util/props-util';
|
|
|
|
import { ConfigConsumerProps } from '../config-provider';
|
2019-01-12 11:33:27 +08:00
|
|
|
import VcRate from '../vc-rate';
|
|
|
|
import Icon from '../icon';
|
2019-03-18 20:00:00 +08:00
|
|
|
import Tooltip from '../tooltip';
|
2019-08-28 10:50:19 +08:00
|
|
|
import Base from '../base';
|
2018-03-21 15:45:01 +08:00
|
|
|
|
|
|
|
export const RateProps = {
|
|
|
|
prefixCls: PropTypes.string,
|
|
|
|
count: PropTypes.number,
|
|
|
|
value: PropTypes.value,
|
|
|
|
defaultValue: PropTypes.value,
|
|
|
|
allowHalf: PropTypes.bool,
|
|
|
|
allowClear: PropTypes.bool,
|
2019-03-18 20:00:00 +08:00
|
|
|
tooltips: PropTypes.arrayOf(PropTypes.string),
|
2018-03-21 15:45:01 +08:00
|
|
|
disabled: PropTypes.bool,
|
|
|
|
character: PropTypes.any,
|
2018-06-06 10:46:54 +08:00
|
|
|
autoFocus: PropTypes.bool,
|
2019-01-12 11:33:27 +08:00
|
|
|
};
|
2018-03-21 15:45:01 +08:00
|
|
|
|
2018-09-19 13:21:57 +08:00
|
|
|
const Rate = {
|
2018-04-08 21:17:20 +08:00
|
|
|
name: 'ARate',
|
2018-03-21 15:45:01 +08:00
|
|
|
model: {
|
|
|
|
prop: 'value',
|
|
|
|
event: 'change',
|
|
|
|
},
|
2019-03-18 20:00:00 +08:00
|
|
|
props: RateProps,
|
|
|
|
inject: {
|
2019-09-11 22:35:25 +08:00
|
|
|
configProvider: { default: () => ConfigConsumerProps },
|
2019-03-18 20:00:00 +08:00
|
|
|
},
|
2018-03-21 15:45:01 +08:00
|
|
|
methods: {
|
2019-01-12 11:33:27 +08:00
|
|
|
focus() {
|
|
|
|
this.$refs.refRate.focus();
|
2018-03-21 15:45:01 +08:00
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
blur() {
|
|
|
|
this.$refs.refRate.blur();
|
2018-03-21 15:45:01 +08:00
|
|
|
},
|
2019-03-18 20:00:00 +08:00
|
|
|
characterRender(node, { index }) {
|
|
|
|
const { tooltips } = this.$props;
|
|
|
|
if (!tooltips) return node;
|
|
|
|
const tooltipsProps = {
|
|
|
|
props: {
|
|
|
|
title: tooltips[index],
|
|
|
|
},
|
|
|
|
};
|
|
|
|
return <Tooltip {...tooltipsProps}>{node}</Tooltip>;
|
|
|
|
},
|
2018-03-21 15:45:01 +08:00
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
render() {
|
2019-03-18 20:00:00 +08:00
|
|
|
const { prefixCls: customizePrefixCls, ...restProps } = getOptionProps(this);
|
2019-09-11 22:35:25 +08:00
|
|
|
const getPrefixCls = this.configProvider.getPrefixCls;
|
2019-03-18 20:00:00 +08:00
|
|
|
const prefixCls = getPrefixCls('rate', customizePrefixCls);
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
const character = getComponentFromProp(this, 'character') || (
|
|
|
|
<Icon type="star" theme="filled" />
|
|
|
|
);
|
2018-03-21 15:45:01 +08:00
|
|
|
const rateProps = {
|
|
|
|
props: {
|
|
|
|
character,
|
2019-03-18 20:00:00 +08:00
|
|
|
characterRender: this.characterRender,
|
|
|
|
prefixCls,
|
|
|
|
...omit(restProps, ['tooltips']),
|
2018-03-21 15:45:01 +08:00
|
|
|
},
|
|
|
|
on: this.$listeners,
|
|
|
|
ref: 'refRate',
|
2019-01-12 11:33:27 +08:00
|
|
|
};
|
|
|
|
return <VcRate {...rateProps} />;
|
2018-03-21 15:45:01 +08:00
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
};
|
2018-03-21 15:45:01 +08:00
|
|
|
|
2018-09-19 13:21:57 +08:00
|
|
|
/* istanbul ignore next */
|
2019-01-12 11:33:27 +08:00
|
|
|
Rate.install = function(Vue) {
|
2019-08-28 10:50:19 +08:00
|
|
|
Vue.use(Base);
|
2019-01-12 11:33:27 +08:00
|
|
|
Vue.component(Rate.name, Rate);
|
|
|
|
};
|
|
|
|
export default Rate;
|