Browse Source

fix: theme hex show-alpha

richard1015 3 years ago
parent
commit
613b177abf

+ 6 - 1
src/sites/doc/components/ThemeSetting/Index.vue

@@ -10,7 +10,12 @@
           >)</p
         >
         <div>
-          <n-color-picker v-if="item.inputType === 'color'" :modes="['rgb', 'hex']" v-model:value="item.value" />
+          <n-color-picker
+            v-if="['hex', 'rgb'].includes(item.inputType)"
+            :show-alpha="item.inputType != 'hex'"
+            :modes="['hex', 'rgb']"
+            v-model:value="item.value"
+          />
           <n-input v-else v-model:value="item.value" type="text" />
         </div>
       </li>

+ 7 - 3
src/sites/doc/components/ThemeSetting/helper.ts

@@ -25,8 +25,12 @@ const getInputType = (value: string) => {
     return 'number';
   }
   if (/^#[A-Za-z0-9]+$/.test(value)) {
-    return 'color';
+    return 'hex';
   }
+  if (/^(rgb|hsl)a?\((\s*\/?\s*[+-]?\d*(\.\d+)?%?,?\s*){3,5}\)/gim.test(value)) {
+    return 'rgb';
+  }
+
   return 'input';
 };
 const loadScript = async (url: string) =>
@@ -133,7 +137,7 @@ const extractStyle = (style: string) => {
 export const getSassStyle = async (name: string): Promise<void> => {
   if (!store.rawStyles[name]) {
     const style = await getGithubRawFile(
-      `https://raw.githubusercontent.com/jdf2e/nutui/next/src/packages/__VUE/${name}/index.scss`
+      `/devRaw/jd-platform-opensource/nutui/raw/next/src/packages/__VUE/${name}/index.scss`
     );
     store.rawStyles[name] = style;
   }
@@ -164,7 +168,7 @@ export const useThemeEditor = function (): Obj {
   onMounted(async () => {
     if (!store.init) {
       await Promise.all([
-        getSassVariables('https://raw.githubusercontent.com/jdf2e/nutui/next/src/packages/styles/variables.scss'),
+        getSassVariables('/devRaw/jd-platform-opensource/nutui/raw/next/src/packages/styles/variables.scss'),
         loadScript('https://cdnout.com/sass.js/sass.sync.min.js')
       ]);
       store.init = true;

+ 5 - 0
vite.config.ts

@@ -18,6 +18,11 @@ export default defineConfig({
         target: 'https://nutui.jd.com',
         changeOrigin: true,
         rewrite: (path) => path.replace(/^\/devServer/, '')
+      },
+      '/devRaw': {
+        target: 'https://gitee.com',
+        changeOrigin: true,
+        rewrite: (path) => path.replace(/^\/devRaw/, '')
       }
     }
   },