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 @@