From 44cca54cda2ec10569f83084741c829159a2afde Mon Sep 17 00:00:00 2001 From: hzgotb Date: Fri, 24 Feb 2023 01:07:50 +0800 Subject: [PATCH 1/5] perf: improves modify theme color logic (#428) --- src/layouts/setting.vue | 14 -------------- src/store/modules/setting.ts | 29 ++++++++++++++++------------- 2 files changed, 16 insertions(+), 27 deletions(-) diff --git a/src/layouts/setting.vue b/src/layouts/setting.vue index 5ff6172..09a5d71 100644 --- a/src/layouts/setting.vue +++ b/src/layouts/setting.vue @@ -95,7 +95,6 @@ import { ref, computed, onMounted, watchEffect } from 'vue'; import { MessagePlugin } from 'tdesign-vue-next'; import type { PopupVisibleChangeContext } from 'tdesign-vue-next'; -import { Color } from 'tvision-color'; import useClipboard from 'vue-clipboard3'; import { useSettingStore } from '@/store'; @@ -104,7 +103,6 @@ import ColorContainer from '@/components/color/index.vue'; import STYLE_CONFIG from '@/config/style'; import { DEFAULT_COLOR_OPTIONS } from '@/config/color'; -import { insertThemeStylesheet, generateColorMap } from '@/utils/color'; import SettingDarkIcon from '@/assets/assets-setting-dark.svg'; import SettingLightIcon from '@/assets/assets-setting-light.svg'; @@ -150,19 +148,7 @@ const showSettingPanel = computed({ }); const changeColor = (hex: string) => { - const { colors: newPalette, primary: brandColorIndex } = Color.getColorGradations({ - colors: [hex], - step: 10, - remainInput: false, // 是否保留输入 不保留会矫正不合适的主题色 - })[0]; - const { mode } = settingStore; - - const colorMap = generateColorMap(hex, newPalette, mode as 'light' | 'dark', brandColorIndex); - - settingStore.addColor({ [hex]: colorMap }); formData.value.brandTheme = hex; - settingStore.updateConfig({ ...formData.value, brandTheme: hex }); - insertThemeStylesheet(hex, colorMap, mode as 'light' | 'dark'); }; onMounted(() => { diff --git a/src/store/modules/setting.ts b/src/store/modules/setting.ts index 222973f..e076bc5 100644 --- a/src/store/modules/setting.ts +++ b/src/store/modules/setting.ts @@ -1,7 +1,7 @@ import { defineStore } from 'pinia'; import { Color } from 'tvision-color'; import keys from 'lodash/keys'; -import { LIGHT_CHART_COLORS, DARK_CHART_COLORS, TColorSeries } from '@/config/color'; +import { LIGHT_CHART_COLORS, DARK_CHART_COLORS } from '@/config/color'; import { insertThemeStylesheet, generateColorMap } from '@/utils/color'; import STYLE_CONFIG from '@/config/style'; import { store } from '@/store'; @@ -51,21 +51,24 @@ export const useSettingStore = defineStore('setting', { this.chartColors = isDarkMode ? DARK_CHART_COLORS : LIGHT_CHART_COLORS; }, changeBrandTheme(brandTheme: string) { - const { colors: newPalette, primary: brandColorIndex } = Color.getColorGradations({ - colors: [brandTheme], - step: 10, - remainInput: false, // 是否保留输入 不保留会矫正不合适的主题色 - })[0]; - const { mode } = this; - const colorMap = generateColorMap(brandTheme, newPalette, mode as 'light' | 'dark', brandColorIndex); - + const mode = this.displayMode; + // 以主题色加显示模式作为键 + const colorKey = `${brandTheme}[${mode}]`; + let colorMap = this.colorList[colorKey]; + // 如果不存在色阶,就需要计算 + if (colorMap === undefined) { + const [{ colors: newPalette, primary: brandColorIndex }] = Color.getColorGradations({ + colors: [brandTheme], + step: 10, + remainInput: false, // 是否保留输入 不保留会矫正不合适的主题色 + }); + colorMap = generateColorMap(brandTheme, newPalette, mode as 'light' | 'dark', brandColorIndex); + this.colorList[colorKey] = colorMap; + } + // TODO 需要解决不停切换时有反复插入 style 的问题 insertThemeStylesheet(brandTheme, colorMap, mode as 'light' | 'dark'); - document.documentElement.setAttribute('theme-color', brandTheme); }, - addColor(payload: TColorSeries) { - this.colorList = { ...this.colorList, ...payload }; - }, updateConfig(payload: Partial) { for (const key in payload) { if (payload[key] !== undefined) { From ca0abd6ba06d7a839f6277347d3b042101033e35 Mon Sep 17 00:00:00 2001 From: Henry Date: Mon, 27 Feb 2023 14:33:08 +0800 Subject: [PATCH 2/5] fix: stylelint (#436) --- stylelint.config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stylelint.config.js b/stylelint.config.js index ff75d1b..6c8629b 100644 --- a/stylelint.config.js +++ b/stylelint.config.js @@ -4,7 +4,7 @@ module.exports = { plugins: ['stylelint-less'], overrides: [ { - files: ['**/*.vue'], + files: ['**/*.html', '**/*.vue'], customSyntax: 'postcss-html', }, { From 715e8824512aebf309b40eb80540025ae5f140dc Mon Sep 17 00:00:00 2001 From: Henry Date: Tue, 7 Mar 2023 11:21:04 +0800 Subject: [PATCH 3/5] fix: globEager deprecated (#439) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: globEager deprecated * Update .vscode/settings.json Co-authored-by: 悠静萝莉 --------- Co-authored-by: 悠静萝莉 --- .vscode/settings.json | 11 ++++++++++- src/router/index.ts | 4 ++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 6d8a55b..9f7e7d1 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -21,5 +21,14 @@ "editor.formatOnSave": true, "editor.defaultFormatter": "dbaeumer.vscode-eslint" }, - "cSpell.words": ["tdesign", "tvision", "echarts", "nprogress", "commitlint", "stylelint", "pinia", "qrcode"] + "cSpell.words": [ + "tdesign", + "tvision", + "echarts", + "nprogress", + "commitlint", + "stylelint", + "pinia", + "qrcode" + ], } diff --git a/src/router/index.ts b/src/router/index.ts index b7b3c16..a89704a 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -4,10 +4,10 @@ import uniq from 'lodash/uniq'; const env = import.meta.env.MODE || 'development'; // 导入homepage相关固定路由 -const homepageModules = import.meta.globEager('./modules/**/homepage.ts'); +const homepageModules = import.meta.glob('./modules/**/homepage.ts', { eager: true }); // 导入modules非homepage相关固定路由 -const fixedModules = import.meta.globEager('./modules/**/!(homepage).ts'); +const fixedModules = import.meta.glob('./modules/**/!(homepage).ts', { eager: true }); // 其他固定路由 const defaultRouterList: Array = [ From 78eed605e4d723d41b9ae034a2b34de4d06ea4a7 Mon Sep 17 00:00:00 2001 From: liweijie0812 <674416404@qq.com> Date: Wed, 15 Mar 2023 15:34:36 +0800 Subject: [PATCH 4/5] =?UTF-8?q?perf:=20=E6=8E=A5=E5=8F=A3=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E7=A1=AC=E7=BC=96=E7=A0=81=E8=B0=83=E6=95=B4=E5=88=B0?= =?UTF-8?q?=E7=8E=AF=E5=A2=83=E5=8F=98=E9=87=8F=20(#445)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * perf: 接口配置硬编码调整到环境变量 * perf: 接口配置硬编码调整到环境变量 --- .env | 3 +++ .env.development | 3 +++ .env.site | 3 +++ .env.test | 5 +++++ .gitignore | 2 ++ src/config/proxy.ts | 27 --------------------------- src/types/env.d.ts | 5 +++++ src/utils/request/index.ts | 5 ++--- vite.config.ts | 4 ++-- 9 files changed, 25 insertions(+), 32 deletions(-) create mode 100644 .env.test delete mode 100644 src/config/proxy.ts create mode 100644 src/types/env.d.ts diff --git a/.env b/.env index 14498f0..2dd71fd 100644 --- a/.env +++ b/.env @@ -1,2 +1,5 @@ # 打包路径 根据项目不同按需配置 VITE_BASE_URL = / +VITE_IS_REQUEST_PROXY = true +VITE_API_URL = https://service-bv448zsw-1257786608.gz.apigw.tencentcs.com +VITE_API_URL_PREFIX = /api \ No newline at end of file diff --git a/.env.development b/.env.development index 79debef..d475e5c 100644 --- a/.env.development +++ b/.env.development @@ -1,2 +1,5 @@ # 打包路径 VITE_BASE_URL = / +VITE_IS_REQUEST_PROXY = true +VITE_API_URL = https://service-exndqyuk-1257786608.gz.apigw.tencentcs.com +VITE_API_URL_PREFIX = /api \ No newline at end of file diff --git a/.env.site b/.env.site index 6011a5c..7e1e855 100644 --- a/.env.site +++ b/.env.site @@ -1,2 +1,5 @@ # 打包路径 根据项目不同按需配置 VITE_BASE_URL = https://static.tdesign.tencent.com/starter/vue-next/ +VITE_IS_REQUEST_PROXY = true +VITE_API_URL = https://service-bv448zsw-1257786608.gz.apigw.tencentcs.com +VITE_API_URL_PREFIX = /api \ No newline at end of file diff --git a/.env.test b/.env.test new file mode 100644 index 0000000..d278ac2 --- /dev/null +++ b/.env.test @@ -0,0 +1,5 @@ +# 打包路径 根据项目不同按需配置 +VITE_BASE_URL = / +VITE_IS_REQUEST_PROXY = true +VITE_API_URL = https://service-exndqyuk-1257786608.gz.apigw.tencentcs.com +VITE_API_URL_PREFIX = /api \ No newline at end of file diff --git a/.gitignore b/.gitignore index d481268..bb6ed77 100755 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,5 @@ yarn-error.log yarn.lock package-lock.json pnpm-lock.yaml +.env.local +.env.*.local diff --git a/src/config/proxy.ts b/src/config/proxy.ts deleted file mode 100644 index 3218a38..0000000 --- a/src/config/proxy.ts +++ /dev/null @@ -1,27 +0,0 @@ -export default { - isRequestProxy: true, - development: { - // 开发环境接口请求 - host: 'https://service-exndqyuk-1257786608.gz.apigw.tencentcs.com', - // 开发环境 cdn 路径 - cdn: '', - }, - test: { - // 测试环境接口地址 - host: 'https://service-exndqyuk-1257786608.gz.apigw.tencentcs.com', - // 测试环境 cdn 路径 - cdn: '', - }, - release: { - // 正式环境接口地址 - host: 'https://service-bv448zsw-1257786608.gz.apigw.tencentcs.com', - // 正式环境 cdn 路径 - cdn: '', - }, - site: { - // TDesign部署特殊需要 与release功能一致 - host: 'https://service-bv448zsw-1257786608.gz.apigw.tencentcs.com', - // 正式环境 cdn 路径 - cdn: '', - }, -}; diff --git a/src/types/env.d.ts b/src/types/env.d.ts new file mode 100644 index 0000000..6ca1ddb --- /dev/null +++ b/src/types/env.d.ts @@ -0,0 +1,5 @@ +export interface ImportMetaEnv { + readonly VITE_IS_REQUEST_PROXY: string; + readonly VITE_API_URL: string; + readonly VITE_API_URL_PREFIX: string; +} diff --git a/src/utils/request/index.ts b/src/utils/request/index.ts index 1db3ef6..250d8e3 100644 --- a/src/utils/request/index.ts +++ b/src/utils/request/index.ts @@ -4,7 +4,6 @@ import merge from 'lodash/merge'; import type { InternalAxiosRequestConfig } from 'axios'; import type { AxiosTransform, CreateAxiosOptions } from './AxiosTransform'; import { VAxios } from './Axios'; -import proxy from '@/config/proxy'; import { joinTimestamp, formatRequestDate, setObjToUrlParams } from './utils'; import { TOKEN_NAME } from '@/config/global'; import { ContentTypeEnum } from '@/constants'; @@ -12,7 +11,7 @@ import { ContentTypeEnum } from '@/constants'; const env = import.meta.env.MODE || 'development'; // 如果是mock模式 或 没启用直连代理 就不配置host 会走本地Mock拦截 或 Vite 代理 -const host = env === 'mock' || !proxy.isRequestProxy ? '' : proxy[env].host; +const host = env === 'mock' || import.meta.env.VITE_IS_REQUEST_PROXY !== 'true' ? '' : import.meta.env.VITE_API_URL; // 数据处理,方便区分多种处理方式 const transform: AxiosTransform = { @@ -172,7 +171,7 @@ function createAxios(opt?: Partial) { // 接口前缀 // 例如: https://www.baidu.com/api // urlPrefix: '/api' - urlPrefix: '/api', + urlPrefix: import.meta.env.VITE_API_URL_PREFIX, // 是否返回原生响应头 比如:需要获取响应头时使用该属性 isReturnNativeResponse: false, // 需要对返回数据进行处理 diff --git a/vite.config.ts b/vite.config.ts index 5bd2498..2e3dc45 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -10,7 +10,7 @@ const CWD = process.cwd(); // https://vitejs.dev/config/ export default ({ mode }: ConfigEnv): UserConfig => { - const { VITE_BASE_URL } = loadEnv(mode, CWD); + const { VITE_BASE_URL, VITE_API_URL_PREFIX } = loadEnv(mode, CWD); return { base: VITE_BASE_URL, resolve: { @@ -45,7 +45,7 @@ export default ({ mode }: ConfigEnv): UserConfig => { port: 3002, host: '0.0.0.0', proxy: { - '/api': 'http://127.0.0.1:3000/', + [VITE_API_URL_PREFIX]: 'http://127.0.0.1:3000/', }, }, }; From 2f1f2ae8910b1126f78597085ea8925c575207f2 Mon Sep 17 00:00:00 2001 From: yuyang Date: Wed, 15 Mar 2023 15:57:20 +0800 Subject: [PATCH 5/5] chore: release 0.7.3 (#449) --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 538360b..8adc0de 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tdesign-vue-next-starter", - "version": "0.7.2", + "version": "0.7.3", "scripts": { "dev:mock": "vite --open --mode mock", "dev": "vite --open --mode development",