From 91ba2115c308e23970b29eda638b1b725a92966a Mon Sep 17 00:00:00 2001 From: Linzp Date: Wed, 7 Jan 2026 14:45:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=86=E6=95=B0=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 44 +++++++++++++++++++++++++++++++++++++ doc/base.js | 3 +++ doc/example.json | 18 +++++++++++++++ doc/score.js | 33 ++++++++++++++++++++++++++++ package.json | 2 +- src/Score/index.js | 26 ++++++++++++++-------- src/Score/style.module.scss | 18 ++------------- 7 files changed, 118 insertions(+), 26 deletions(-) create mode 100644 doc/score.js diff --git a/README.md b/README.md index 90e0d7b..ccfce2d 100644 --- a/README.md +++ b/README.md @@ -76,6 +76,9 @@ const BaseExample = () => { InfoPage.InfoPage.Part + + xxxx + ); }; @@ -850,6 +853,47 @@ render(); ``` +- 评分 +- 展示评分组件 +- _InfoPage(@kne/current-lib_info-page),(@kne/current-lib_info-page/dist/index.css),antd(antd) + +```jsx +const { Score } = _InfoPage; +const { Flex } = antd; + +const BaseExample = () => { + return ( + + + + + + + + + + + + + + + + + + + + + + + + + ); +}; + +render(); + +``` + ### API diff --git a/doc/base.js b/doc/base.js index 2537ab9..5051007 100644 --- a/doc/base.js +++ b/doc/base.js @@ -23,6 +23,9 @@ const BaseExample = () => { InfoPage.InfoPage.Part + + xxxx + ); }; diff --git a/doc/example.json b/doc/example.json index b465623..1d659df 100644 --- a/doc/example.json +++ b/doc/example.json @@ -152,6 +152,24 @@ "packageName": "antd" } ] + }, + { + "title": "评分", + "description": "展示评分组件", + "code": "./score.js", + "scope": [ + { + "name": "_InfoPage", + "packageName": "@kne/current-lib_info-page" + }, + { + "packageName": "@kne/current-lib_info-page/dist/index.css" + }, + { + "name": "antd", + "packageName": "antd" + } + ] } ] } diff --git a/doc/score.js b/doc/score.js new file mode 100644 index 0000000..3f02ed9 --- /dev/null +++ b/doc/score.js @@ -0,0 +1,33 @@ +const { Score } = _InfoPage; +const { Flex } = antd; + +const BaseExample = () => { + return ( + + + + + + + + + + + + + + + + + + + + + + + + + ); +}; + +render(); diff --git a/package.json b/package.json index a12b0f3..6966561 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@kne/info-page", - "version": "0.2.3", + "version": "0.2.4", "description": "一般用在复杂的详情展示页面,InfoPage提供了一个标准的展示信息的格式", "syntax": { "esmodules": true diff --git a/src/Score/index.js b/src/Score/index.js index b9f4d70..33f5ee5 100644 --- a/src/Score/index.js +++ b/src/Score/index.js @@ -3,16 +3,24 @@ import classnames from 'classnames'; import { Row, Col } from 'antd'; import style from './style.module.scss'; -const ScoreItem = ({ score, staticScore }) => { +const ScoreItem = ({ score, total, staticScore, getLevel, levelColors = ['#f1f1f1', '#f66969', '#ffb566', '#a2de91'] }) => { score = Number.isNaN(score) ? 0 : Number(score); + const level = ( + getLevel || + (score => { + if (score <= total / 3) return 1; + if (score <= (total * 2) / 3) return 2; + if (score > (total * 2) / 3) return 3; + }) + )(score); + + const color = staticScore > score ? levelColors[0] : levelColors[level]; return (
score, - [style['low-score']]: score < 3, - [style['middle-score']]: score === 3, - [style['high-score']]: score > 3 - })} + className={classnames('score-item', style['score-item'])} + style={{ + '--score-item-color': color + }} /> ); }; @@ -21,8 +29,8 @@ const Score = ({ className, value, gap = 4, total = 5 }) => { return ( {Array.from({ length: total }).map((n, index) => ( - - + + ))} diff --git a/src/Score/style.module.scss b/src/Score/style.module.scss index 7fded4d..74b6268 100644 --- a/src/Score/style.module.scss +++ b/src/Score/style.module.scss @@ -12,20 +12,6 @@ .score-item { width: 100%; height: 14px; - - &.is-grey { - background: #f1f1f1 !important; - } - - &.low-score { - background: #f66969; - } - - &.middle-score { - background: #ffb566; - } - - &.high-score { - background: #a2de91; - } + background: var(--score-item-color); + min-width: 10px; } \ No newline at end of file