2020-06-26 04:57:05 +00:00
|
|
|
import { inject } from 'vue';
|
2019-03-18 12:00:00 +00:00
|
|
|
import omit from 'omit.js';
|
2019-01-12 03:33:27 +00:00
|
|
|
import PropTypes from '../_util/vue-types';
|
2020-06-26 04:57:05 +00:00
|
|
|
import { getOptionProps, getComponent } from '../_util/props-util';
|
2019-03-18 12:00:00 +00:00
|
|
|
import { ConfigConsumerProps } from '../config-provider';
|
2019-01-12 03:33:27 +00:00
|
|
|
import VcRate from '../vc-rate';
|
2020-04-04 14:03:18 +00:00
|
|
|
import StarFilled from '@ant-design/icons-vue/StarFilled';
|
2019-03-18 12:00:00 +00:00
|
|
|
import Tooltip from '../tooltip';
|
2018-03-21 07:45:01 +00: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 12:00:00 +00:00
|
|
|
tooltips: PropTypes.arrayOf(PropTypes.string),
|
2018-03-21 07:45:01 +00:00
|
|
|
disabled: PropTypes.bool,
|
|
|
|
character: PropTypes.any,
|
2018-06-06 02:46:54 +00:00
|
|
|
autoFocus: PropTypes.bool,
|
2019-01-12 03:33:27 +00:00
|
|
|
};
|
2018-03-21 07:45:01 +00:00
|
|
|
|
2018-09-19 05:21:57 +00:00
|
|
|
const Rate = {
|
2018-04-08 13:17:20 +00:00
|
|
|
name: 'ARate',
|
2019-03-18 12:00:00 +00:00
|
|
|
props: RateProps,
|
2020-06-26 04:57:05 +00:00
|
|
|
setup() {
|
|
|
|
return {
|
|
|
|
configProvider: inject('configProvider', ConfigConsumerProps),
|
|
|
|
};
|
2019-03-18 12:00:00 +00:00
|
|
|
},
|
2018-03-21 07:45:01 +00:00
|
|
|
methods: {
|
2020-03-07 11:45:13 +00:00
|
|
|
characterRender(node, { index }) {
|
|
|
|
const { tooltips } = this.$props;
|
|
|
|
if (!tooltips) return node;
|
|
|
|
return <Tooltip title={tooltips[index]}>{node}</Tooltip>;
|
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
focus() {
|
|
|
|
this.$refs.refRate.focus();
|
2018-03-21 07:45:01 +00:00
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
blur() {
|
|
|
|
this.$refs.refRate.blur();
|
2018-03-21 07:45:01 +00:00
|
|
|
},
|
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
render() {
|
2019-03-18 12:00:00 +00:00
|
|
|
const { prefixCls: customizePrefixCls, ...restProps } = getOptionProps(this);
|
2019-09-11 14:35:25 +00:00
|
|
|
const getPrefixCls = this.configProvider.getPrefixCls;
|
2019-03-18 12:00:00 +00:00
|
|
|
const prefixCls = getPrefixCls('rate', customizePrefixCls);
|
|
|
|
|
2020-06-26 04:57:05 +00:00
|
|
|
const character = getComponent(this, 'character') || <StarFilled />;
|
2018-03-21 07:45:01 +00:00
|
|
|
const rateProps = {
|
2020-06-26 04:57:05 +00:00
|
|
|
character,
|
|
|
|
characterRender: this.characterRender,
|
|
|
|
prefixCls,
|
|
|
|
...omit(restProps, ['tooltips']),
|
|
|
|
...this.$attrs,
|
2018-03-21 07:45:01 +00:00
|
|
|
ref: 'refRate',
|
2019-01-12 03:33:27 +00:00
|
|
|
};
|
|
|
|
return <VcRate {...rateProps} />;
|
2018-03-21 07:45:01 +00:00
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
};
|
2018-03-21 07:45:01 +00:00
|
|
|
|
2018-09-19 05:21:57 +00:00
|
|
|
/* istanbul ignore next */
|
2020-06-26 04:57:05 +00:00
|
|
|
Rate.install = function(app) {
|
|
|
|
app.component(Rate.name, Rate);
|
2019-01-12 03:33:27 +00:00
|
|
|
};
|
|
|
|
export default Rate;
|