2020-06-26 12:57:05 +08:00
|
|
|
import { inject } from 'vue';
|
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';
|
2020-06-26 12:57:05 +08:00
|
|
|
import { getOptionProps, getComponent } from '../_util/props-util';
|
2020-09-30 10:47:18 +08:00
|
|
|
import { defaultConfigProvider } from '../config-provider';
|
2019-01-12 11:33:27 +08:00
|
|
|
import VcRate from '../vc-rate';
|
2020-04-04 22:03:18 +08:00
|
|
|
import StarFilled from '@ant-design/icons-vue/StarFilled';
|
2019-03-18 20:00:00 +08:00
|
|
|
import Tooltip from '../tooltip';
|
2018-03-21 15:45:01 +08:00
|
|
|
|
|
|
|
export const RateProps = {
|
|
|
|
prefixCls: PropTypes.string,
|
|
|
|
count: PropTypes.number,
|
|
|
|
value: PropTypes.value,
|
|
|
|
defaultValue: PropTypes.value,
|
2020-10-10 18:16:28 +08:00
|
|
|
allowHalf: PropTypes.looseBool,
|
|
|
|
allowClear: PropTypes.looseBool,
|
2019-03-18 20:00:00 +08:00
|
|
|
tooltips: PropTypes.arrayOf(PropTypes.string),
|
2020-10-10 18:16:28 +08:00
|
|
|
disabled: PropTypes.looseBool,
|
2018-03-21 15:45:01 +08:00
|
|
|
character: PropTypes.any,
|
2020-10-10 18:16:28 +08:00
|
|
|
autofocus: PropTypes.looseBool,
|
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',
|
2019-03-18 20:00:00 +08:00
|
|
|
props: RateProps,
|
2020-06-26 12:57:05 +08:00
|
|
|
setup() {
|
|
|
|
return {
|
2020-09-30 10:47:18 +08:00
|
|
|
configProvider: inject('configProvider', defaultConfigProvider),
|
2020-06-26 12:57:05 +08:00
|
|
|
};
|
2019-03-18 20:00:00 +08:00
|
|
|
},
|
2018-03-21 15:45:01 +08:00
|
|
|
methods: {
|
2020-03-07 19:45:13 +08:00
|
|
|
characterRender(node, { index }) {
|
|
|
|
const { tooltips } = this.$props;
|
|
|
|
if (!tooltips) return node;
|
|
|
|
return <Tooltip title={tooltips[index]}>{node}</Tooltip>;
|
|
|
|
},
|
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-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);
|
|
|
|
|
2020-06-26 12:57:05 +08:00
|
|
|
const character = getComponent(this, 'character') || <StarFilled />;
|
2018-03-21 15:45:01 +08:00
|
|
|
const rateProps = {
|
2020-06-26 12:57:05 +08:00
|
|
|
character,
|
|
|
|
characterRender: this.characterRender,
|
|
|
|
prefixCls,
|
|
|
|
...omit(restProps, ['tooltips']),
|
|
|
|
...this.$attrs,
|
2018-03-21 15:45:01 +08:00
|
|
|
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 */
|
2020-06-26 12:57:05 +08:00
|
|
|
Rate.install = function(app) {
|
|
|
|
app.component(Rate.name, Rate);
|
2020-10-13 19:14:56 +08:00
|
|
|
return app;
|
2019-01-12 11:33:27 +08:00
|
|
|
};
|
|
|
|
export default Rate;
|