From 1b6fc90d599a191c95e502ac155936618f051ee6 Mon Sep 17 00:00:00 2001
From: icssoa <615206459@qq.com>
Date: Sun, 7 Sep 2025 11:08:01 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=20cl-text=20=E7=BB=84?=
=?UTF-8?q?=E4=BB=B6=E7=9A=84=E5=AD=97=E4=BD=93=E5=A4=A7=E5=B0=8F=E5=92=8C?=
=?UTF-8?q?=E9=A2=9C=E8=89=B2=EF=BC=8C=E5=9C=A8=20pt=20=E9=85=8D=E7=BD=AE?=
=?UTF-8?q?=E4=B8=AD=E6=97=A0=E9=9C=80=E6=B7=BB=E5=8A=A0=20!=20=E7=AC=A6?=
=?UTF-8?q?=E5=8F=B7?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
components/tabbar.uvue | 4 +-
cool/utils/comm.ts | 70 ----------------
cool/utils/device.ts | 70 ++++++++++++++++
cool/utils/index.ts | 1 +
cool/utils/rect.ts | 2 +-
cool/utils/tailwind.ts | 28 +++++++
package.json | 2 +-
pages/demo/basic/image.uvue | 28 ++++++-
pages/demo/basic/text.uvue | 12 ++-
pages/demo/components/item.uvue | 2 +-
pages/demo/components/tips.uvue | 2 +-
pages/demo/data/filter-bar.uvue | 12 +--
pages/demo/data/list.uvue | 25 +++++-
pages/demo/data/pagination.uvue | 4 +-
pages/demo/data/timeline.uvue | 2 +-
pages/demo/data/tree.uvue | 4 +-
pages/demo/data/waterfall.uvue | 2 +-
pages/demo/feedback/action-sheet.uvue | 2 +-
pages/demo/form/checkbox.uvue | 18 +++-
pages/demo/form/form.uvue | 2 +-
pages/demo/form/radio.uvue | 12 ++-
pages/demo/form/select.uvue | 4 +-
pages/demo/form/textarea.uvue | 2 +-
pages/set/general.uvue | 11 +++
pages/template/shop/shopping-cart.uvue | 12 +--
pages/user/components/login/phone.uvue | 4 +-
pages/user/components/login/wx.uvue | 2 +-
pages/user/edit-name.uvue | 4 +-
pages/user/login.uvue | 10 +--
.../cl-action-sheet/cl-action-sheet.uvue | 2 +-
.../cool-ui/components/cl-badge/cl-badge.uvue | 2 +-
.../components/cl-banner/cl-banner.uvue | 1 +
.../components/cl-button/cl-button.uvue | 2 +-
.../components/cl-cascader/cl-cascader.uvue | 2 +-
.../components/cl-checkbox/cl-checkbox.uvue | 4 +-
.../components/cl-cropper/cl-cropper.uvue | 4 +-
.../cool-ui/components/cl-empty/cl-empty.uvue | 2 +-
.../cl-filter-item/cl-filter-item.uvue | 2 +-
.../components/cl-form-item/cl-form-item.uvue | 2 +-
.../cool-ui/components/cl-icon/cl-icon.uvue | 75 ++++++++++-------
.../cl-keyboard-car/cl-keyboard-car.uvue | 4 +-
.../cl-keyboard-number.uvue | 10 +--
.../cl-keyboard-password.uvue | 12 +--
.../cl-pagination/cl-pagination.uvue | 39 +++++----
.../cl-picker-view/cl-picker-view.uvue | 6 +-
.../cool-ui/components/cl-popup/cl-popup.uvue | 2 +-
.../cool-ui/components/cl-radio/cl-radio.uvue | 4 +-
.../cl-select-date/cl-select-date.uvue | 4 +-
.../cl-select-trigger/cl-select-trigger.uvue | 8 +-
.../cool-ui/components/cl-tabs/cl-tabs.uvue | 2 +-
.../cool-ui/components/cl-tag/cl-tag.uvue | 2 +-
.../cool-ui/components/cl-text/cl-text.uvue | 82 ++++++++++++-------
.../components/cl-textarea/cl-textarea.uvue | 2 +-
.../cl-timeline-item/cl-timeline-item.uvue | 6 +-
.../cool-ui/components/cl-toast/cl-toast.uvue | 3 +-
.../components/cl-topbar/cl-topbar.uvue | 2 +-
.../components/cl-upload/cl-upload.uvue | 6 +-
57 files changed, 406 insertions(+), 239 deletions(-)
create mode 100644 cool/utils/tailwind.ts
diff --git a/components/tabbar.uvue b/components/tabbar.uvue
index 3873116..7c9ce7d 100644
--- a/components/tabbar.uvue
+++ b/components/tabbar.uvue
@@ -23,8 +23,8 @@
v-if="item.text != null"
:pt="{
className: parseClass([
- '!text-xs mt-1',
- [path == item.pagePath, '!text-primary-500', '!text-surface-400']
+ 'text-xs mt-1',
+ [path == item.pagePath, 'text-primary-500', 'text-surface-400']
])
}"
>{{ t(item.text!) }} {
- // #ifdef MP
- return true;
- // #endif
-
- return false;
-};
-
-/**
- * 检查是否为App环境
- * @returns 是否为App环境
- */
-export const isApp = (): boolean => {
- // #ifdef APP
- return true;
- // #endif
-
- return false;
-};
-
-/**
- * 检查是否为App-IOS环境
- * @returns 是否为App-IOS环境
- */
-export const isAppIOS = (): boolean => {
- // #ifdef APP-IOS
- return true;
- // #endif
- return false;
-};
-
-/**
- * 检查是否为App-Android环境
- * @returns 是否为App-Android环境
- */
-export const isAppAndroid = (): boolean => {
- // #ifdef APP-ANDROID
- return true;
- // #endif
- return false;
-};
-
-/**
- * 检查是否为H5环境
- * @returns 是否为H5环境
- */
-export const isH5 = (): boolean => {
- // #ifdef H5
- return true;
- // #endif
-
- return false;
-};
-
-/**
- * 检查是否为鸿蒙环境
- * @returns 是否为鸿蒙环境
- */
-export const isHarmony = (): boolean => {
- // #ifdef APP-HARMONY
- return true;
- // #endif
-
- return false;
-};
diff --git a/cool/utils/device.ts b/cool/utils/device.ts
index 0d51a0d..b5f73c2 100644
--- a/cool/utils/device.ts
+++ b/cool/utils/device.ts
@@ -1,3 +1,73 @@
+/**
+ * 检查是否为小程序环境
+ * @returns 是否为小程序环境
+ */
+export const isMp = (): boolean => {
+ // #ifdef MP
+ return true;
+ // #endif
+
+ return false;
+};
+
+/**
+ * 检查是否为App环境
+ * @returns 是否为App环境
+ */
+export const isApp = (): boolean => {
+ // #ifdef APP
+ return true;
+ // #endif
+
+ return false;
+};
+
+/**
+ * 检查是否为App-IOS环境
+ * @returns 是否为App-IOS环境
+ */
+export const isAppIOS = (): boolean => {
+ // #ifdef APP-IOS
+ return true;
+ // #endif
+ return false;
+};
+
+/**
+ * 检查是否为App-Android环境
+ * @returns 是否为App-Android环境
+ */
+export const isAppAndroid = (): boolean => {
+ // #ifdef APP-ANDROID
+ return true;
+ // #endif
+ return false;
+};
+
+/**
+ * 检查是否为H5环境
+ * @returns 是否为H5环境
+ */
+export const isH5 = (): boolean => {
+ // #ifdef H5
+ return true;
+ // #endif
+
+ return false;
+};
+
+/**
+ * 检查是否为鸿蒙环境
+ * @returns 是否为鸿蒙环境
+ */
+export const isHarmony = (): boolean => {
+ // #ifdef APP-HARMONY
+ return true;
+ // #endif
+
+ return false;
+};
+
/**
* 获取设备像素比
* @returns 设备像素比
diff --git a/cool/utils/index.ts b/cool/utils/index.ts
index a1282c2..90c3e69 100644
--- a/cool/utils/index.ts
+++ b/cool/utils/index.ts
@@ -1,3 +1,4 @@
+export * from "./tailwind";
export * from "./comm";
export * from "./day";
export * from "./device";
diff --git a/cool/utils/rect.ts b/cool/utils/rect.ts
index 8cf64d6..13aeb62 100644
--- a/cool/utils/rect.ts
+++ b/cool/utils/rect.ts
@@ -1,6 +1,6 @@
import { config } from "@/config";
import { router } from "../router";
-import { isH5, isHarmony } from "./comm";
+import { isH5, isHarmony } from "./device";
import { ctx } from "../ctx";
import { getPx } from "./parse";
diff --git a/cool/utils/tailwind.ts b/cool/utils/tailwind.ts
new file mode 100644
index 0000000..bf47477
--- /dev/null
+++ b/cool/utils/tailwind.ts
@@ -0,0 +1,28 @@
+/**
+ * 判断 Tailwind class 字符串中是否包含文本颜色类(如 text-red, text-red-500, text-sky 等)
+ * @param className 传入的 class 字符串
+ * @returns 是否包含文本颜色类
+ */
+export function hasTextColor(className: string): boolean {
+ if (className == "") return false;
+
+ const regex =
+ /\btext-(primary|surface|red|blue|green|yellow|purple|pink|indigo|gray|grey|black|white|orange|amber|lime|emerald|teal|cyan|sky|violet|fuchsia|rose|slate|zinc|neutral|stone)(?:-\d+)?\b/;
+
+ return regex.test(className);
+}
+
+/**
+ * 判断 Tailwind class 字符串中是否包含字体大小类
+ * 支持如 text-xs, text-sm, text-base, text-lg, text-xl, 以及 text-[22px]、text-[22rpx] 等自定义写法
+ * @param className 传入的 class 字符串
+ * @returns 是否包含字体大小类
+ */
+export function hasTextSize(className: string): boolean {
+ if (className == "") return false;
+
+ const regex =
+ /\btext-(xs|sm|md|base|lg|xl|2xl|3xl|4xl|5xl|6xl|7xl|8xl|9xl|\[\d+[a-zA-Z%]*\])\b/;
+
+ return regex.test(className);
+}
diff --git a/package.json b/package.json
index 9ac5cc5..3ef52b1 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "cool-unix",
- "version": "8.0.20",
+ "version": "8.0.21",
"license": "MIT",
"scripts": {
"build-ui": "node ./uni_modules/cool-ui/scripts/generate-types.js",
diff --git a/pages/demo/basic/image.uvue b/pages/demo/basic/image.uvue
index 2b48aaa..399998d 100644
--- a/pages/demo/basic/image.uvue
+++ b/pages/demo/basic/image.uvue
@@ -9,22 +9,42 @@
- aspectFill
+ aspectFill
- aspectFit
+ aspectFit
- heightFix
+ heightFix
- scaleToFill
+ scaleToFill
diff --git a/pages/demo/basic/text.uvue b/pages/demo/basic/text.uvue
index 0a0be4e..1e3c18e 100644
--- a/pages/demo/basic/text.uvue
+++ b/pages/demo/basic/text.uvue
@@ -6,7 +6,17 @@
- 云想衣裳花想容,春风拂槛露华浓。
+ 明月松间照,清泉石上流。
+ 举头望明月,低头思故乡。
+ 春眠不觉晓,处处闻啼鸟。
+ 劝君更尽一杯酒,西出阳关无故人。
+ 孤帆远影碧空尽,唯见长江天际流。
+ 大漠孤烟直,长河落日圆。
diff --git a/pages/demo/components/item.uvue b/pages/demo/components/item.uvue
index 301df78..1ceffa2 100644
--- a/pages/demo/components/item.uvue
+++ b/pages/demo/components/item.uvue
@@ -1,6 +1,6 @@
- {{
+ {{
label
}}
diff --git a/pages/demo/components/tips.uvue b/pages/demo/components/tips.uvue
index 1df7da8..a3affe1 100644
--- a/pages/demo/components/tips.uvue
+++ b/pages/demo/components/tips.uvue
@@ -2,7 +2,7 @@
diff --git a/pages/demo/data/filter-bar.uvue b/pages/demo/data/filter-bar.uvue
index 7cc0999..e7b311c 100644
--- a/pages/demo/data/filter-bar.uvue
+++ b/pages/demo/data/filter-bar.uvue
@@ -43,13 +43,13 @@
- {{
+ {{
JSON.stringify(filterForm, null, 4)
}}
- {{
+ {{
JSON.stringify(searchForm, null, 4)
}}
@@ -84,7 +84,7 @@
]
]),
label: {
- className: '!text-sm'
+ className: 'text-sm'
}
}"
>
@@ -147,7 +147,7 @@
]
]),
label: {
- className: '!text-sm'
+ className: 'text-sm'
}
}"
>
@@ -177,7 +177,7 @@
]
]),
label: {
- className: '!text-sm'
+ className: 'text-sm'
}
}"
>
@@ -207,7 +207,7 @@
]
]),
label: {
- className: '!text-sm'
+ className: 'text-sm'
}
}"
>
diff --git a/pages/demo/data/list.uvue b/pages/demo/data/list.uvue
index 2f71a8e..b31c4af 100644
--- a/pages/demo/data/list.uvue
+++ b/pages/demo/data/list.uvue
@@ -8,7 +8,15 @@
-
+
615206459
@@ -25,6 +33,21 @@
+
+
+
+
+
diff --git a/pages/demo/data/pagination.uvue b/pages/demo/data/pagination.uvue
index 9a66f26..c13cde3 100644
--- a/pages/demo/data/pagination.uvue
+++ b/pages/demo/data/pagination.uvue
@@ -38,7 +38,7 @@
{{ t("上一页") }}
@@ -47,7 +47,7 @@
{{ t("下一页") }}
diff --git a/pages/demo/data/timeline.uvue b/pages/demo/data/timeline.uvue
index 5a31c7a..4ab0303 100644
--- a/pages/demo/data/timeline.uvue
+++ b/pages/demo/data/timeline.uvue
@@ -49,7 +49,7 @@
{{ t("优选灵活配置混合A") }}
- {{ t("1000元起") }}
+ {{ t("1000元起") }}
{{
diff --git a/pages/demo/data/tree.uvue b/pages/demo/data/tree.uvue
index 771d2ea..3d38537 100644
--- a/pages/demo/data/tree.uvue
+++ b/pages/demo/data/tree.uvue
@@ -43,7 +43,7 @@
{{ halfCheckedKeys.join("、") }}
@@ -65,7 +65,7 @@
{{ expandedKeys.join("、") }}
diff --git a/pages/demo/data/waterfall.uvue b/pages/demo/data/waterfall.uvue
index da7e840..70557d5 100644
--- a/pages/demo/data/waterfall.uvue
+++ b/pages/demo/data/waterfall.uvue
@@ -27,7 +27,7 @@
- {{
+ {{
item["likeCount"]
}}
diff --git a/pages/demo/feedback/action-sheet.uvue b/pages/demo/feedback/action-sheet.uvue
index 8e87289..9053127 100644
--- a/pages/demo/feedback/action-sheet.uvue
+++ b/pages/demo/feedback/action-sheet.uvue
@@ -57,7 +57,7 @@
- {{ item.label }}
+ {{ item.label }}
diff --git a/pages/demo/form/checkbox.uvue b/pages/demo/form/checkbox.uvue
index 37963d6..dbc6fc0 100644
--- a/pages/demo/form/checkbox.uvue
+++ b/pages/demo/form/checkbox.uvue
@@ -77,7 +77,23 @@
{
'!bg-surface-700': isDark && isCustom
}
- ])
+ ]),
+ icon: {
+ className: parseClass([
+ [
+ isCustom && checked3.includes(item.value as string),
+ 'text-red-500'
+ ]
+ ])
+ },
+ label: {
+ className: parseClass([
+ [
+ isCustom && checked3.includes(item.value as string),
+ 'text-red-500'
+ ]
+ ])
+ }
}"
>
{{ item.label }}
diff --git a/pages/demo/form/form.uvue b/pages/demo/form/form.uvue
index f085a76..6c29e58 100644
--- a/pages/demo/form/form.uvue
+++ b/pages/demo/form/form.uvue
@@ -141,7 +141,7 @@
- {{
+ {{
JSON.stringify(formData, null, 4)
}}
diff --git a/pages/demo/form/radio.uvue b/pages/demo/form/radio.uvue
index 39563ba..daa932f 100644
--- a/pages/demo/form/radio.uvue
+++ b/pages/demo/form/radio.uvue
@@ -66,7 +66,17 @@
{
'!bg-surface-700': isDark && isCustom
}
- ])
+ ]),
+ icon: {
+ className: parseClass([
+ [isCustom && item.value == checked3, 'text-red-500']
+ ])
+ },
+ label: {
+ className: parseClass([
+ [isCustom && item.value == checked3, 'text-red-500']
+ ])
+ }
}"
>
{{ item.label }}
diff --git a/pages/demo/form/select.uvue b/pages/demo/form/select.uvue
index 8d23bf8..a23b9a7 100644
--- a/pages/demo/form/select.uvue
+++ b/pages/demo/form/select.uvue
@@ -53,7 +53,7 @@
@@ -120,7 +120,7 @@ type Form = {
};
const form = reactive
@@ -88,7 +88,7 @@
{{ endPlaceholder }}
diff --git a/uni_modules/cool-ui/components/cl-select-trigger/cl-select-trigger.uvue b/uni_modules/cool-ui/components/cl-select-trigger/cl-select-trigger.uvue
index 4381b0a..c5c030b 100644
--- a/uni_modules/cool-ui/components/cl-select-trigger/cl-select-trigger.uvue
+++ b/uni_modules/cool-ui/components/cl-select-trigger/cl-select-trigger.uvue
@@ -18,7 +18,7 @@
:pt="{
className: parseClass([
{
- '!text-surface-400': isDisabled
+ 'text-surface-400': isDisabled
},
pt.text?.className
])
@@ -30,7 +30,7 @@
@@ -42,7 +42,7 @@
@@ -51,7 +51,7 @@
:name="pt.icon?.name ?? arrowIcon"
:size="pt.icon?.size ?? 32"
:pt="{
- className: `!text-surface-400 ${pt.icon?.className}`
+ className: `text-surface-400 ${pt.icon?.className}`
}"
>
diff --git a/uni_modules/cool-ui/components/cl-tabs/cl-tabs.uvue b/uni_modules/cool-ui/components/cl-tabs/cl-tabs.uvue
index cf33a2d..849dda7 100644
--- a/uni_modules/cool-ui/components/cl-tabs/cl-tabs.uvue
+++ b/uni_modules/cool-ui/components/cl-tabs/cl-tabs.uvue
@@ -40,7 +40,7 @@
className: parseClass([
[
item.isActive && color == '' && unColor == '',
- showSlider ? '!text-white' : '!text-primary-500'
+ showSlider ? 'text-white' : 'text-primary-500'
],
pt.text?.className
])
diff --git a/uni_modules/cool-ui/components/cl-tag/cl-tag.uvue b/uni_modules/cool-ui/components/cl-tag/cl-tag.uvue
index 93a535a..1228060 100644
--- a/uni_modules/cool-ui/components/cl-tag/cl-tag.uvue
+++ b/uni_modules/cool-ui/components/cl-tag/cl-tag.uvue
@@ -23,7 +23,7 @@
diff --git a/uni_modules/cool-ui/components/cl-text/cl-text.uvue b/uni_modules/cool-ui/components/cl-text/cl-text.uvue
index bc96fa6..126ff9e 100644
--- a/uni_modules/cool-ui/components/cl-text/cl-text.uvue
+++ b/uni_modules/cool-ui/components/cl-text/cl-text.uvue
@@ -3,20 +3,10 @@
import { computed, type PropType } from "vue";
-import { isDark, parsePt, useCache } from "@/cool";
+import { ctx, hasTextColor, hasTextSize, isDark, parsePt, useCache } from "@/cool";
import type { ClTextType } from "../../types";
import { useSize } from "../../hooks";
@@ -170,12 +150,46 @@ const pt = computed(() => parsePt(props.pt));
// 文本大小
const { getSize, getLineHeight, ptClassName } = useSize(() => pt.value.className ?? "");
+// 文本颜色
+const color = computed(() => {
+ if (props.color != "") {
+ switch (props.color) {
+ case "primary":
+ return ctx.color["primary-500"] as string;
+ case "success":
+ return "#22c55e";
+ case "warn":
+ return "#eab308";
+ case "error":
+ return "#ef4444";
+ case "info":
+ return isDark.value
+ ? (ctx.color["surface-300"] as string)
+ : (ctx.color["surface-500"] as string);
+ case "dark":
+ return ctx.color["surface-700"] as string;
+ case "light":
+ return ctx.color["surface-50"] as string;
+ case "disabled":
+ return ctx.color["surface-400"] as string;
+ default:
+ return props.color;
+ }
+ }
+
+ return isDark.value ? "white" : (ctx.color["surface-700"] as string);
+});
+
+// 是否默认大小
+const isDefaultSize = computed(() => !hasTextSize(pt.value.className ?? ""));
+
// 文本样式
const textStyle = computed(() => {
const style = {};
- if (props.color != "") {
- style["color"] = props.color;
+ // 判断是不是有颜色样式
+ if (!hasTextColor(ptClassName.value)) {
+ style["color"] = color.value;
}
// 字号
@@ -295,8 +309,6 @@ const content = computed(() => {
diff --git a/uni_modules/cool-ui/components/cl-textarea/cl-textarea.uvue b/uni_modules/cool-ui/components/cl-textarea/cl-textarea.uvue
index 7e8d997..8b2d66c 100644
--- a/uni_modules/cool-ui/components/cl-textarea/cl-textarea.uvue
+++ b/uni_modules/cool-ui/components/cl-textarea/cl-textarea.uvue
@@ -51,7 +51,7 @@
/>
{{ value.length }} / {{ maxlength }}
diff --git a/uni_modules/cool-ui/components/cl-timeline-item/cl-timeline-item.uvue b/uni_modules/cool-ui/components/cl-timeline-item/cl-timeline-item.uvue
index fd9fc9c..d526ce6 100644
--- a/uni_modules/cool-ui/components/cl-timeline-item/cl-timeline-item.uvue
+++ b/uni_modules/cool-ui/components/cl-timeline-item/cl-timeline-item.uvue
@@ -29,7 +29,7 @@
:pt="{
className: parseClass([
`mb-1 !font-bold ${pt.title?.className}`,
- [isDark, '!text-white', '!text-surface-900']
+ [isDark, 'text-white', 'text-surface-900']
])
}"
>{{ title }}{{ content }}
@@ -48,7 +48,7 @@
{{ date }}
diff --git a/uni_modules/cool-ui/components/cl-topbar/cl-topbar.uvue b/uni_modules/cool-ui/components/cl-topbar/cl-topbar.uvue
index de16e3b..72e6116 100644
--- a/uni_modules/cool-ui/components/cl-topbar/cl-topbar.uvue
+++ b/uni_modules/cool-ui/components/cl-topbar/cl-topbar.uvue
@@ -31,7 +31,7 @@
{{ title }}
diff --git a/uni_modules/cool-ui/components/cl-upload/cl-upload.uvue b/uni_modules/cool-ui/components/cl-upload/cl-upload.uvue
index a5b5bc3..9ce3357 100644
--- a/uni_modules/cool-ui/components/cl-upload/cl-upload.uvue
+++ b/uni_modules/cool-ui/components/cl-upload/cl-upload.uvue
@@ -58,7 +58,7 @@
:name="icon"
:pt="{
className: parseClass([
- [isDark, '!text-white', '!text-surface-400'],
+ [isDark, 'text-white', 'text-surface-400'],
pt.icon?.className
])
}"
@@ -68,8 +68,8 @@