Update from Vibe Studio

This commit is contained in:
Vibe Studio
2026-01-16 02:20:32 +00:00
parent a4605e311a
commit 71de1506ca
28603 changed files with 2179459 additions and 0 deletions

View File

@@ -0,0 +1,14 @@
import type { ReactNode } from 'react';
import React from 'react';
import 'antd/lib/input-number/style';
export type PercentPropInt = {
prefix?: ReactNode;
suffix?: ReactNode;
text?: number | string;
precision?: number;
showColor?: boolean;
showSymbol?: boolean | ((value: any) => boolean);
placeholder?: string;
};
declare const _default: React.ForwardRefExoticComponent<import("@ant-design/pro-provider").BaseProFieldFC & import("@ant-design/pro-provider").ProRenderFieldPropsType & PercentPropInt & React.RefAttributes<any>>;
export default _default;

View File

@@ -0,0 +1,91 @@
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import { useIntl } from '@ant-design/pro-provider';
import { InputNumber } from 'antd';
import React, { Fragment, useMemo } from 'react';
import { getColorByRealValue, getRealTextWithPrecision, getSymbolByRealValue, toNumber } from "./util";
// 兼容代码-----------
import "antd/es/input-number/style";
//------------
import { jsx as _jsx } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
/**
* 百分比组件
*
* @param PercentPropInt
*/
var FieldPercent = function FieldPercent(_ref, ref) {
var text = _ref.text,
prefix = _ref.prefix,
precision = _ref.precision,
_ref$suffix = _ref.suffix,
suffix = _ref$suffix === void 0 ? '%' : _ref$suffix,
mode = _ref.mode,
_ref$showColor = _ref.showColor,
showColor = _ref$showColor === void 0 ? false : _ref$showColor,
render = _ref.render,
renderFormItem = _ref.renderFormItem,
fieldProps = _ref.fieldProps,
placeholder = _ref.placeholder,
propsShowSymbol = _ref.showSymbol;
var intl = useIntl();
var placeholderValue = placeholder || intl.getMessage('tableForm.inputPlaceholder', '请输入');
var realValue = useMemo(function () {
return typeof text === 'string' && text.includes('%') ? toNumber(text.replace('%', '')) : toNumber(text);
}, [text]);
var showSymbol = useMemo(function () {
if (typeof propsShowSymbol === 'function') {
return propsShowSymbol === null || propsShowSymbol === void 0 ? void 0 : propsShowSymbol(text);
}
return propsShowSymbol;
}, [propsShowSymbol, text]);
if (mode === 'read') {
/** 颜色有待确定, 根据提供 colors: ['正', '负'] | boolean */
var style = showColor ? {
color: getColorByRealValue(realValue)
} : {};
var dom = /*#__PURE__*/_jsxs("span", {
style: style,
ref: ref,
children: [prefix && /*#__PURE__*/_jsx("span", {
children: prefix
}), showSymbol && /*#__PURE__*/_jsxs(Fragment, {
children: [getSymbolByRealValue(realValue), " "]
}), getRealTextWithPrecision(Math.abs(realValue), precision), suffix && suffix]
});
if (render) {
return render(text, _objectSpread(_objectSpread({
mode: mode
}, fieldProps), {}, {
prefix: prefix,
precision: precision,
showSymbol: showSymbol,
suffix: suffix
}), dom);
}
return dom;
}
if (mode === 'edit' || mode === 'update') {
var _dom = /*#__PURE__*/_jsx(InputNumber, _objectSpread({
ref: ref,
formatter: function formatter(value) {
if (value && prefix) {
return "".concat(prefix, " ").concat(value).replace(/\B(?=(\d{3})+(?!\d)$)/g, ',');
}
return value;
},
parser: function parser(value) {
return value ? value.replace(/.*\s|,/g, '') : '';
},
placeholder: placeholderValue
}, fieldProps));
if (renderFormItem) {
return renderFormItem(text, _objectSpread({
mode: mode
}, fieldProps), _dom);
}
return _dom;
}
return null;
};
export default /*#__PURE__*/React.forwardRef(FieldPercent);

View File

@@ -0,0 +1,11 @@
/** 获取展示符号 */
export declare function getSymbolByRealValue(realValue: number): "-" | "+" | null;
/** 获取颜色 */
export declare function getColorByRealValue(realValue: number /** ,color: string */): "#52c41a" | "#ff4d4f" | "#595959";
/** 获取到最后展示的数字 */
export declare function getRealTextWithPrecision(realValue: number, precision?: number): string | number;
/**
* 转化为数字
* @copy from https://github.com/toss/es-toolkit/blob/32a183828c244d675f46810935e45dfefec81a54/src/compat/util/toNumber.ts#L19
*/
export declare function toNumber(value: any): number;

View File

@@ -0,0 +1,36 @@
import _typeof from "@babel/runtime/helpers/esm/typeof";
/** 获取展示符号 */
export function getSymbolByRealValue(realValue) {
if (realValue === 0) {
return null;
}
if (realValue > 0) {
return '+';
}
return '-';
}
/** 获取颜色 */
export function getColorByRealValue(realValue) {
if (realValue === 0) {
return '#595959';
}
return realValue > 0 ? '#ff4d4f' : '#52c41a';
}
/** 获取到最后展示的数字 */
export function getRealTextWithPrecision(realValue) {
var precision = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 2;
return precision >= 0 ? realValue === null || realValue === void 0 ? void 0 : realValue.toFixed(precision) : realValue;
}
/**
* 转化为数字
* @copy from https://github.com/toss/es-toolkit/blob/32a183828c244d675f46810935e45dfefec81a54/src/compat/util/toNumber.ts#L19
*/
export function toNumber(value) {
if (_typeof(value) === 'symbol' || value instanceof Symbol) {
return NaN;
}
return Number(value);
}