Sfoglia il codice sorgente

feat: 颜色面板生成

wjc 2 giorni fa
parent
commit
2378f5bd5c

+ 3 - 0
components.d.ts

@@ -23,10 +23,13 @@ declare module 'vue' {
     NutButton: typeof import('nutui-uniapp/components/button/button.vue')['default']
     NutCheckbox: typeof import('nutui-uniapp/components/checkbox/checkbox.vue')['default']
     NutConfigProvider: typeof import('nutui-uniapp/components/configprovider/configprovider.vue')['default']
+    NutDialog: (typeof import('nutui-uniapp/components/dialog/dialog.vue'))['default']
     NutDivider: typeof import('nutui-uniapp/components/divider/divider.vue')['default']
     NutForm: typeof import('nutui-uniapp/components/form/form.vue')['default']
     NutFormItem: typeof import('nutui-uniapp/components/formitem/formitem.vue')['default']
     NutInput: typeof import('nutui-uniapp/components/input/input.vue')['default']
+    NutSwiper: (typeof import('nutui-uniapp/components/swiper/swiper.vue'))['default']
+    NutSwiperItem: (typeof import('nutui-uniapp/components/swiperitem/swiperitem.vue'))['default']
     NutTabbar: typeof import('nutui-uniapp/components/tabbar/tabbar.vue')['default']
     NutTabbarItem: typeof import('nutui-uniapp/components/tabbaritem/tabbaritem.vue')['default']
   }

+ 8 - 4
package.json

@@ -21,6 +21,7 @@
   "author": "",
   "license": "ISC",
   "dependencies": {
+    "@ctrl/tinycolor": "^4.2.0",
     "@dcloudio/uni-app": "3.0.0-4050620250312001",
     "@dcloudio/uni-app-harmony": "3.0.0-4050620250312001",
     "@dcloudio/uni-app-plus": "3.0.0-4050620250312001",
@@ -44,6 +45,7 @@
     "pinia": "2.3.1",
     "pinia-plugin-persistedstate": "^3.2.1",
     "qs": "6.9.6",
+    "theme-colors": "^0.1.0",
     "unocss": "^66.3.3",
     "vue": "^3.5.13",
     "vue-i18n": "9.1.9",
@@ -59,6 +61,7 @@
     "@dcloudio/vite-plugin-uni": "3.0.0-4050620250312001",
     "@eslint/js": "9.31.0",
     "@iconify/utils": "^2.1.23",
+    "@stylistic/stylelint-plugin": "^2.1.3",
     "@types/eslint": "^9.6.1",
     "@types/node": "^20.12.12",
     "@typescript-eslint/eslint-plugin": "^8.37.0",
@@ -97,15 +100,16 @@
     "prettier-plugin-tailwindcss": "^0.7.2",
     "sass": "^1.77.2",
     "sass-loader": "^14.2.1",
-    "stylelint": "16.0.2",
+    "stylelint": "16.12.0",
     "stylelint-config-prettier": "^9.0.5",
-    "stylelint-config-recess-order": "^5.0.1",
+    "stylelint-config-recess-order": "5.1.1",
     "stylelint-config-recommended": "^14.0.0",
-    "stylelint-config-recommended-scss": "^14.0.0",
+    "stylelint-config-recommended-scss": "^14.1.0",
     "stylelint-config-recommended-vue": "^1.0.0",
-    "stylelint-config-standard": "^40.0.0",
+    "stylelint-config-standard": "^34.0.0",
     "stylelint-order": "^6.0.4",
     "stylelint-prettier": "^5.0.0",
+    "stylelint-scss": "^6.10.0",
     "svgo": "^3.3.2",
     "typescript": "^5.4.5",
     "unocss-applet": "^0.12.2",

File diff suppressed because it is too large
+ 253 - 208
pnpm-lock.yaml


+ 13 - 1
src/components/MConfigProvider/index.vue

@@ -1,3 +1,10 @@
+<!--
+ * @Author: wjc
+ * @Date: 2025-04-09 10:19:11
+ * @LastEditors: wjc
+ * @LastEditTime: 2026-01-22 09:42:46
+ * @Description: 
+-->
 <template>
   <page-meta>
     <!-- 微信小程序非自定义组件不支持 v-bind(2025-1-16),兼容处理 -->
@@ -8,7 +15,12 @@
       :animation="originNavBarStyle.animation"
     />
   </page-meta>
-  <nut-config-provider :theme="theme" class="bg-bg-page h-full" :class="[userStore.theme]">
+  <nut-config-provider
+    :theme="theme"
+    class="bg-bg-page h-full"
+    id="__uni-starter-styles__"
+    :class="[userStore.theme]"
+  >
     <slot></slot>
   </nut-config-provider>
 </template>

+ 9 - 2
src/pages/splash/index.vue

@@ -21,7 +21,7 @@
     </template>
     <nut-swiper v-else height="100vh" :loop="false" :autoplay="0" @change="onTapSwiper">
       <nut-swiper-item v-for="item in list" :key="item">
-        <image :src="item" mode="aspectFit" class="h-100vh w-full" />
+        <image :src="item" mode="scaleToFill" class="h-100vh w-full" />
       </nut-swiper-item>
     </nut-swiper>
   </view>
@@ -82,18 +82,24 @@
 <style scoped lang="scss">
   .splash-container {
     @apply h-full;
+
     :deep(.wd-swiper) {
       @apply h-full;
     }
+
     .splash-mask {
       @apply flex flex-col items-center text-center;
+
       .text {
         @apply color-text-1 text-24px mt-20px flex items-center text-center;
+
         letter-spacing: 10px;
         writing-mode: vertical-rl;
+
         .vue {
           @apply text-28px font-600 bg-bg-primary;
-          letter-spacing: 0px;
+
+          letter-spacing: 0;
           background: linear-gradient(315deg, #42d392 25%, #647eff);
           background-clip: text;
           writing-mode: horizontal-tb;
@@ -101,6 +107,7 @@
         }
       }
     }
+
     :deep(.wd-swiper__track) {
       @apply rounded-0px;
     }

+ 2 - 5
src/static/styles/comm.scss

@@ -1,10 +1,7 @@
 .btn-default {
-  @apply text-14px p-12px bg-bg-page;
-  border-radius: 20px !important;
+  @apply text-14px p-12px bg-bg-page !rounded-[20px];
 }
 
 .btn-primary {
-  @apply text-14px p-12px color-white;
-  background: var(--color-primary) !important;
-  border-radius: 20px !important;
+  @apply text-14px p-12px color-white !bg-primary !rounded-[20px];
 }

+ 134 - 0
src/utils/css-var.ts

@@ -0,0 +1,134 @@
+/*
+ * @Author: wjc
+ * @Date: 2026-01-19 16:52:19
+ * @LastEditors: wjc
+ * @LastEditTime: 2026-01-22 09:43:34
+ * @Description:
+ */
+import { TinyColor } from '@ctrl/tinycolor'
+import { getColors } from 'theme-colors'
+
+interface ColorItem {
+  alias?: string
+  color: string
+  name: string
+}
+
+/**
+ * 生成颜色变量的函数
+ * @param colorItems 颜色项数组,每个项包含颜色、名称和可选的别名
+ * @returns 颜色变量的记录对象,键为 CSS 变量名,值为颜色值:
+ * @example
+ * --primary-500: #505050;
+ * --primary-400: #c0c0c0;
+ * --primary-300: #d0d0d0;
+ * --primary-200: #e0e0e0;
+ * --primary-100: #f0f0f0;
+ * --primary-50: #fafafa;
+ */
+function generatorColorVariables(colorItems: ColorItem[]) {
+  const colorVariables: Record<string, string> = {}
+
+  colorItems.forEach(({ alias, color, name }) => {
+    if (color) {
+      const colorsMap = getColors(new TinyColor(color).toHexString())
+
+      let mainColor = colorsMap['500']
+
+      const colorKeys = Object.keys(colorsMap)
+
+      colorKeys.forEach((key) => {
+        const colorValue = colorsMap[key]
+
+        if (colorValue) {
+          colorVariables[`--${name}-${key}`] = colorValue
+          if (alias) {
+            colorVariables[`--${alias}-${key}`] = colorValue
+          }
+
+          if (key === '500') {
+            mainColor = colorValue
+          }
+        }
+      })
+      if (alias && mainColor) {
+        colorVariables[`--${alias}`] = mainColor
+      }
+    }
+  })
+  return colorVariables
+}
+
+/**
+ * 将 CSS 颜色变量设置到根元素样式中
+ * @param variables 要更新的 CSS 变量与其新值的映射
+ */
+function setCSSVariables(
+  variables: { [key: string]: string },
+  id = '__uni-starter-styles__'
+): void {
+  // 获取或创建内联样式表元素
+  const styleElement = document.querySelector(`#${id}`) || document.createElement('style')
+
+  styleElement.id = id
+
+  // 构建要更新的 CSS 变量的样式文本
+  let cssText = ':root, page {'
+  for (const key in variables) {
+    if (Object.prototype.hasOwnProperty.call(variables, key)) {
+      cssText += `${key}: ${variables[key]};`
+    }
+  }
+  cssText += '}'
+
+  // 将样式文本赋值给内联样式表
+  styleElement.textContent = cssText
+
+  // 将内联样式表添加到文档头部
+  if (!document.querySelector(`#${id}`)) {
+    setTimeout(() => {
+      document.head.append(styleElement)
+    })
+  }
+}
+
+/**
+ * 更新主要的 CSS 变量
+ * @param  preference - 当前偏好设置对象,它的颜色值将被转换成 HSL 格式并设置为 CSS 变量。
+ */
+export function updateMainColorVariables(theme: any) {
+  // 当修改到颜色变量时,更新 css 变量
+  const root = document.documentElement
+  if (!root) {
+    return
+  }
+  if (!theme) {
+    return
+  }
+  const { colorDestructive, colorPrimary, colorSuccess, colorWarning } = theme
+
+  const colorVariables = generatorColorVariables([
+    { color: colorPrimary, name: 'primary' },
+    { alias: 'warning', color: colorWarning, name: 'yellow' },
+    { alias: 'success', color: colorSuccess, name: 'green' },
+    { alias: 'destructive', color: colorDestructive, name: 'red' },
+  ])
+
+  // 要设置的 CSS 变量映射
+  const colorMappings = {
+    '--green-500': '--success',
+    '--primary-500': '--primary',
+    '--red-500': '--destructive',
+    '--yellow-500': '--warning',
+  }
+
+  // 统一处理颜色变量的更新
+  Object.entries(colorMappings).forEach(([sourceVar, targetVar]) => {
+    const colorValue = colorVariables[sourceVar]
+    if (colorValue) {
+      document.documentElement.style.setProperty(targetVar, colorValue)
+    }
+  })
+
+  setCSSVariables(colorVariables)
+}

+ 28 - 1
stylelint.config.mjs

@@ -24,6 +24,34 @@ export default {
       customSyntax: 'postcss-scss',
       extends: ['stylelint-config-recommended-scss', 'stylelint-config-recommended-vue/scss'],
       files: ['*.scss', '**/*.scss'],
+      rules: {
+        'scss/at-rule-no-unknown': [
+          true,
+          {
+            ignoreAtRules: [
+              'extends',
+              'ignores',
+              'include',
+              'mixin',
+              'if',
+              'else',
+              'media',
+              'for',
+              'at-root',
+              'tailwind',
+              'apply',
+              'variants',
+              'responsive',
+              'screen',
+              'function',
+              'each',
+              'use',
+              'forward',
+              'return',
+            ],
+          },
+        ],
+      },
     },
   ],
   plugins: [
@@ -33,7 +61,6 @@ export default {
     'stylelint-scss',
   ],
   rules: {
-    'at-rule-no-deprecated': null,
     'at-rule-no-unknown': [
       true,
       {

+ 3 - 3
uno.config.ts

@@ -72,7 +72,7 @@ export default defineConfig({
       },
       // cdn: 'https://esm.sh/'
       collections: {
-        custom: FileSystemIconLoader('./src/static/icons/'),
+        custom: FileSystemIconLoader('./src/static/icons/') as any,
         ep: () => import('@iconify-json/ep/icons.json').then((i) => i.default),
       },
     }),
@@ -98,9 +98,9 @@ export default defineConfig({
     'flex-center': 'flex justify-center items-center',
     'flex-x-center': 'flex justify-center',
     'flex-y-center': 'flex items-center',
-    // 文本溢出显示省略号
+    // 单行文本溢出显示省略号
     'text-overflow': 'overflow-hidden whitespace-nowrap text-ellipsis',
-    // 文本溢出换行
+    // 多行文本溢出显示省略号
     'text-break': 'whitespace-normal break-all break-words',
   },
   theme: {

Some files were not shown because too many files changed in this diff