This commit is contained in:
Ling53666
2025-08-18 09:11:51 +08:00
commit 02554225da
2516 changed files with 133155 additions and 0 deletions

View File

@ -0,0 +1 @@
.ant-rate{display:inline-flex;font-size:24px;user-select:none}.ant-rate-container{display:flex}.ant-rate-star{position:relative;margin-right:4px;line-height:1}.ant-rate-star:last-child{margin-right:0}.ant-rate-star-icon{color:#eee}.ant-rate-star-icon-active{color:#ff9f18}.ant-rate-star-icon-half-active{position:absolute;left:0;top:0;width:50%;overflow:hidden}

View File

@ -0,0 +1,45 @@
<view
class="ant-rate {{className || ''}}"
style="{{style}}"
>
<view
id="ant-rate-container{{$id ? '-' + $id : ''}}"
class="ant-rate-container"
onTouchMove="handleStarMove"
onTouchEnd="handleStarMoveEnd"
>
<block
a:for="{{count}}"
a:for-index="index"
a:for-item="item"
>
<view
class="ant-rate-star"
onTap="handleStarTap"
data-rate="{{index}}"
style="margin-right: {{index === count - 1 ? 0 : gutter + 'px'}}"
>
<view
a:if="{{allowHalf && (displayValue !== null ? displayValue : mixin.value) === index + 0.5}}"
class="ant-rate-star-icon-active {{characterClassName || ''}} {{characterActiveClassName || ''}} ant-rate-star-icon-half-active"
>
<slot
name="character"
index="{{index}}"
isActive="{{true}}"
>
<ant-icon type="StarFill"></ant-icon>
</slot>
</view>
<view class="ant-rate-star-icon {{(displayValue !== null ? displayValue : mixin.value) >= index + 1 ? 'ant-rate-star-icon-active' + ' ' + (characterClassName || '') + ' ' + (characterActiveClassName || '') : characterClassName}}">
<slot
name="character"
index="{{index}}"
>
<ant-icon type="StarFill"></ant-icon>
</slot>
</view>
</view>
</block>
</view>
</view>

View File

@ -0,0 +1 @@
export {};

View File

@ -0,0 +1,147 @@
import { __assign, __awaiter, __generator } from "tslib";
import { Component, triggerEvent, getValueFromProps } from '../_util/simply';
import { RateDefaultProps } from './props';
import createValue from '../mixins/value';
import { getInstanceBoundingClientRect } from '../_util/jsapi/get-instance-bounding-client-rect';
Component(RateDefaultProps, {
getInstance: function () {
if (this.$id) {
return my;
}
return this;
},
getRate: function (clientX) {
return __awaiter(this, void 0, void 0, function () {
var _a, gutter, count, allowHalf, _b, left, width, halfRateWidth, num, halfRateCount, val, rate;
return __generator(this, function (_c) {
switch (_c.label) {
case 0:
_a = getValueFromProps(this, [
'gutter',
'count',
'allowHalf',
]), gutter = _a[0], count = _a[1], allowHalf = _a[2];
return [4 /*yield*/, getInstanceBoundingClientRect(this.getInstance(), "#ant-rate-container".concat(this.$id ? "-".concat(this.$id) : ''))];
case 1:
_b = _c.sent(), left = _b.left, width = _b.width;
halfRateWidth = (width - (count - 1) * gutter) / count / 2;
num = clientX - left;
halfRateCount = 0;
/* eslint-disable no-constant-condition */
while (true) {
val = halfRateWidth * halfRateCount +
gutter * Math.floor(halfRateCount / 2);
if (halfRateCount >= count * 2 || num <= val) {
break;
}
halfRateCount++;
}
rate = allowHalf
? halfRateCount * 0.5
: Math.ceil(halfRateCount * 0.5);
return [2 /*return*/, rate];
}
});
});
},
handleStarTap: function (e) {
return __awaiter(this, void 0, void 0, function () {
var _a, readonly, allowClear, _b, clientX, x, clickX, rateValue, rate;
return __generator(this, function (_c) {
switch (_c.label) {
case 0:
_a = getValueFromProps(this, [
'readonly',
'allowClear',
]), readonly = _a[0], allowClear = _a[1];
if (readonly) {
return [2 /*return*/];
}
_b = e.detail, clientX = _b.clientX, x = _b.x;
clickX = typeof x === 'number' ? x : clientX;
rateValue = this.getValue();
return [4 /*yield*/, this.getRate(clickX)];
case 1:
rate = _c.sent();
if (rateValue === rate && allowClear) {
rate = 0;
}
if (!this.isControlled()) {
this.update(rate);
}
if (rateValue !== rate) {
triggerEvent(this, 'change', rate);
}
return [2 /*return*/];
}
});
});
},
handleStarMove: function (e) {
return __awaiter(this, void 0, void 0, function () {
var readonly, touches, clientX, rate;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
readonly = getValueFromProps(this, ['readonly'])[0];
if (readonly) {
return [2 /*return*/];
}
touches = e.touches;
clientX = touches[0].clientX;
if (!this.moveRate) {
this.moveRate = {
originalRate: this.getValue(),
};
}
return [4 /*yield*/, this.getRate(clientX)];
case 1:
rate = _a.sent();
if (this.moveRate) {
this.moveRate = __assign(__assign({}, this.moveRate), { currentRate: rate });
if (this.isControlled()) {
this.setData({ displayValue: rate });
}
else {
this.update(rate);
}
}
return [2 /*return*/];
}
});
});
},
handleStarMoveEnd: function () {
var readonly = getValueFromProps(this, 'readonly');
if (readonly) {
return;
}
if (!this.moveRate) {
return;
}
var _a = this.moveRate, currentRate = _a.currentRate, originalRate = _a.originalRate;
this.moveRate = null;
if (this.isControlled()) {
this.setData({ displayValue: null });
}
if (currentRate !== originalRate) {
triggerEvent(this, 'change', currentRate);
}
},
}, { displayValue: null }, [
createValue({
transformValue: function (value) {
var allowHalf = getValueFromProps(this, 'allowHalf');
if (allowHalf) {
return {
needUpdate: true,
value: value % 0.5 !== 0 ? Math.round(value) : value,
};
}
return {
needUpdate: true,
value: Math.ceil(value),
};
},
}),
]);

View File

@ -0,0 +1,6 @@
{
"component": true,
"usingComponents": {
"ant-icon": "../Icon/index"
}
}

View File

@ -0,0 +1,44 @@
import { IBaseProps } from '../_util/base';
export interface IRateProps extends IBaseProps {
/**
* @description 当前星级
*/
value: number;
/**
* description 初始星级
*/
defaultValue: number;
/**
* description 间距
*/
gutter: number;
/**
* @description 是否允许半星
*/
allowHalf: boolean;
/**
* @description 是否允许再次点击后清除
*/
allowClear: boolean;
/**
* @description star 总数
*/
count: number;
/**
* @description 自定义字符选中状态类名
*/
characterActiveClassName: string;
/**
* @description 自定义字符类名
*/
characterClassName: string;
/**
* @description 是否只读
*/
readonly: boolean;
/**
* @description 打分结束回调
*/
onChange?: (rate: number) => void;
}
export declare const RateDefaultProps: Partial<IRateProps>;

View File

@ -0,0 +1,11 @@
export var RateDefaultProps = {
value: null,
defaultValue: null,
gutter: 4,
allowHalf: false,
allowClear: true,
count: 5,
characterActiveClassName: '',
characterClassName: '',
readonly: false,
};