feat: update rate
parent
1f09c6e41f
commit
e00637f76c
|
@ -1,11 +1,11 @@
|
||||||
|
import { inject } from 'vue';
|
||||||
import omit from 'omit.js';
|
import omit from 'omit.js';
|
||||||
import PropTypes from '../_util/vue-types';
|
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 { ConfigConsumerProps } from '../config-provider';
|
||||||
import VcRate from '../vc-rate';
|
import VcRate from '../vc-rate';
|
||||||
import StarFilled from '@ant-design/icons-vue/StarFilled';
|
import StarFilled from '@ant-design/icons-vue/StarFilled';
|
||||||
import Tooltip from '../tooltip';
|
import Tooltip from '../tooltip';
|
||||||
import Base from '../base';
|
|
||||||
|
|
||||||
export const RateProps = {
|
export const RateProps = {
|
||||||
prefixCls: PropTypes.string,
|
prefixCls: PropTypes.string,
|
||||||
|
@ -22,13 +22,11 @@ export const RateProps = {
|
||||||
|
|
||||||
const Rate = {
|
const Rate = {
|
||||||
name: 'ARate',
|
name: 'ARate',
|
||||||
model: {
|
|
||||||
prop: 'value',
|
|
||||||
event: 'change',
|
|
||||||
},
|
|
||||||
props: RateProps,
|
props: RateProps,
|
||||||
inject: {
|
setup() {
|
||||||
configProvider: { default: () => ConfigConsumerProps },
|
return {
|
||||||
|
configProvider: inject('configProvider', ConfigConsumerProps),
|
||||||
|
};
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
characterRender(node, { index }) {
|
characterRender(node, { index }) {
|
||||||
|
@ -48,15 +46,13 @@ const Rate = {
|
||||||
const getPrefixCls = this.configProvider.getPrefixCls;
|
const getPrefixCls = this.configProvider.getPrefixCls;
|
||||||
const prefixCls = getPrefixCls('rate', customizePrefixCls);
|
const prefixCls = getPrefixCls('rate', customizePrefixCls);
|
||||||
|
|
||||||
const character = getComponentFromProp(this, 'character') || <StarFilled />;
|
const character = getComponent(this, 'character') || <StarFilled />;
|
||||||
const rateProps = {
|
const rateProps = {
|
||||||
props: {
|
character,
|
||||||
character,
|
characterRender: this.characterRender,
|
||||||
characterRender: this.characterRender,
|
prefixCls,
|
||||||
prefixCls,
|
...omit(restProps, ['tooltips']),
|
||||||
...omit(restProps, ['tooltips']),
|
...this.$attrs,
|
||||||
},
|
|
||||||
on: getListeners(this),
|
|
||||||
ref: 'refRate',
|
ref: 'refRate',
|
||||||
};
|
};
|
||||||
return <VcRate {...rateProps} />;
|
return <VcRate {...rateProps} />;
|
||||||
|
@ -64,8 +60,7 @@ const Rate = {
|
||||||
};
|
};
|
||||||
|
|
||||||
/* istanbul ignore next */
|
/* istanbul ignore next */
|
||||||
Rate.install = function(Vue) {
|
Rate.install = function(app) {
|
||||||
Vue.use(Base);
|
app.component(Rate.name, Rate);
|
||||||
Vue.component(Rate.name, Rate);
|
|
||||||
};
|
};
|
||||||
export default Rate;
|
export default Rate;
|
||||||
|
|
|
@ -1,12 +1,7 @@
|
||||||
import PropTypes from '../../_util/vue-types';
|
import PropTypes from '../../_util/vue-types';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import KeyCode from '../../_util/KeyCode';
|
import KeyCode from '../../_util/KeyCode';
|
||||||
import {
|
import { initDefaultProps, hasProp, getOptionProps, getComponent } from '../../_util/props-util';
|
||||||
initDefaultProps,
|
|
||||||
hasProp,
|
|
||||||
getOptionProps,
|
|
||||||
getComponentFromProp,
|
|
||||||
} from '../../_util/props-util';
|
|
||||||
import BaseMixin from '../../_util/BaseMixin';
|
import BaseMixin from '../../_util/BaseMixin';
|
||||||
import { getOffsetLeft } from './util';
|
import { getOffsetLeft } from './util';
|
||||||
import Star from './Star';
|
import Star from './Star';
|
||||||
|
@ -30,10 +25,7 @@ function noop() {}
|
||||||
export default {
|
export default {
|
||||||
name: 'Rate',
|
name: 'Rate',
|
||||||
mixins: [BaseMixin],
|
mixins: [BaseMixin],
|
||||||
model: {
|
inheritAttrs: false,
|
||||||
prop: 'value',
|
|
||||||
event: 'change',
|
|
||||||
},
|
|
||||||
props: initDefaultProps(rateProps, {
|
props: initDefaultProps(rateProps, {
|
||||||
defaultValue: 0,
|
defaultValue: 0,
|
||||||
count: 5,
|
count: 5,
|
||||||
|
@ -167,33 +159,31 @@ export default {
|
||||||
sValue: value,
|
sValue: value,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
this.$emit('update:value', value);
|
||||||
this.$emit('change', value);
|
this.$emit('change', value);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
render() {
|
render() {
|
||||||
const { count, allowHalf, prefixCls, disabled, tabIndex } = getOptionProps(this);
|
const { count, allowHalf, prefixCls, disabled, tabIndex } = getOptionProps(this);
|
||||||
const { sValue, hoverValue, focused } = this;
|
const { sValue, hoverValue, focused } = this;
|
||||||
|
const { class: className, style } = this.$attrs;
|
||||||
const stars = [];
|
const stars = [];
|
||||||
const disabledClass = disabled ? `${prefixCls}-disabled` : '';
|
const disabledClass = disabled ? `${prefixCls}-disabled` : '';
|
||||||
const character = getComponentFromProp(this, 'character');
|
const character = getComponent(this, 'character');
|
||||||
const characterRender = this.characterRender || this.$scopedSlots.characterRender;
|
const characterRender = this.characterRender || this.$slots.characterRender;
|
||||||
for (let index = 0; index < count; index++) {
|
for (let index = 0; index < count; index++) {
|
||||||
const starProps = {
|
const starProps = {
|
||||||
props: {
|
index,
|
||||||
index,
|
count,
|
||||||
count,
|
disabled,
|
||||||
disabled,
|
prefixCls: `${prefixCls}-star`,
|
||||||
prefixCls: `${prefixCls}-star`,
|
allowHalf,
|
||||||
allowHalf,
|
value: hoverValue === undefined ? sValue : hoverValue,
|
||||||
value: hoverValue === undefined ? sValue : hoverValue,
|
character,
|
||||||
character,
|
characterRender,
|
||||||
characterRender,
|
focused,
|
||||||
focused,
|
onClick: this.onClick,
|
||||||
},
|
onHover: this.onHover,
|
||||||
on: {
|
|
||||||
click: this.onClick,
|
|
||||||
hover: this.onHover,
|
|
||||||
},
|
|
||||||
key: index,
|
key: index,
|
||||||
ref: `stars${index}`,
|
ref: `stars${index}`,
|
||||||
};
|
};
|
||||||
|
@ -201,7 +191,8 @@ export default {
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<ul
|
<ul
|
||||||
class={classNames(prefixCls, disabledClass)}
|
class={classNames(prefixCls, disabledClass, className)}
|
||||||
|
style={style}
|
||||||
onMouseleave={disabled ? noop : this.onMouseLeave}
|
onMouseleave={disabled ? noop : this.onMouseLeave}
|
||||||
tabIndex={disabled ? -1 : tabIndex}
|
tabIndex={disabled ? -1 : tabIndex}
|
||||||
onFocus={disabled ? noop : this.onFocus}
|
onFocus={disabled ? noop : this.onFocus}
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
import PropTypes from '../../_util/vue-types';
|
import PropTypes from '../../_util/vue-types';
|
||||||
import BaseMixin from '../../_util/BaseMixin';
|
import BaseMixin from '../../_util/BaseMixin';
|
||||||
import { getComponentFromProp } from '../../_util/props-util';
|
import { getComponent } from '../../_util/props-util';
|
||||||
function noop() {}
|
function noop() {}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'Star',
|
name: 'Star',
|
||||||
mixins: [BaseMixin],
|
mixins: [BaseMixin],
|
||||||
|
inheritAttrs: false,
|
||||||
props: {
|
props: {
|
||||||
value: PropTypes.number,
|
value: PropTypes.number,
|
||||||
index: PropTypes.number,
|
index: PropTypes.number,
|
||||||
|
@ -65,7 +66,7 @@ export default {
|
||||||
value,
|
value,
|
||||||
} = this;
|
} = this;
|
||||||
|
|
||||||
const character = getComponentFromProp(this, 'character');
|
const character = getComponent(this, 'character');
|
||||||
let star = (
|
let star = (
|
||||||
<li class={this.getClassName()}>
|
<li class={this.getClassName()}>
|
||||||
<div
|
<div
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<script>
|
<script>
|
||||||
import demo from '../antdv-demo/docs/progress/demo/index';
|
import demo from '../antdv-demo/docs/rate/demo/index';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
import '@babel/polyfill';
|
import '@babel/polyfill';
|
||||||
import { createApp } from 'vue';
|
import { createApp } from 'vue';
|
||||||
import App from './App.vue';
|
import App from './App.vue';
|
||||||
import { Button, Upload, Icon, Modal, Progress, notification, message } from 'ant-design-vue';
|
import { Rate, Button, Upload, Icon, Modal, Progress, notification, message } from 'ant-design-vue';
|
||||||
import 'ant-design-vue/style.js';
|
import 'ant-design-vue/style.js';
|
||||||
|
|
||||||
const basic = {
|
const basic = {
|
||||||
render() {
|
render() {
|
||||||
return this.$slots.default && this.$slots.default();
|
return this.$slots?.default();
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
const app = createApp(App);
|
const app = createApp(App);
|
||||||
|
@ -23,4 +23,5 @@ app
|
||||||
.use(Icon)
|
.use(Icon)
|
||||||
.use(Modal)
|
.use(Modal)
|
||||||
.use(Progress)
|
.use(Progress)
|
||||||
|
.use(Rate)
|
||||||
.mount('#app');
|
.mount('#app');
|
||||||
|
|
Loading…
Reference in New Issue