From 65d5f5ae867557cba5e51884f8a214b58ea1b1d2 Mon Sep 17 00:00:00 2001 From: Gsh <15170702455@163.com> Date: Mon, 4 Aug 2025 23:11:42 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=8A=A0=E8=BD=BD=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E3=80=81vip=E7=8A=B6=E6=80=81=E4=BC=98=E5=8C=96=E3=80=81apikey?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Yi.Ai.Vue3/.build/plugins/index.ts | 24 ++++++ Yi.Ai.Vue3/index.html | 36 +------- Yi.Ai.Vue3/package.json | 2 + Yi.Ai.Vue3/pnpm-lock.yaml | 85 ++++++++++++++++++- .../src/components/ModelSelect/index.vue | 18 ++-- .../components/APIKeyManagement.vue | 10 +-- .../components/Header/components/Avatar.vue | 25 +++--- Yi.Ai.Vue3/src/layouts/index.vue | 24 +++++- .../pages/chat/layouts/chatWithId/index.vue | 4 +- Yi.Ai.Vue3/src/stores/modules/chat.ts | 10 +-- Yi.Ai.Vue3/src/utils/user.ts | 27 +++--- 11 files changed, 172 insertions(+), 93 deletions(-) diff --git a/Yi.Ai.Vue3/.build/plugins/index.ts b/Yi.Ai.Vue3/.build/plugins/index.ts index c3b16160..8138f0ca 100644 --- a/Yi.Ai.Vue3/.build/plugins/index.ts +++ b/Yi.Ai.Vue3/.build/plugins/index.ts @@ -1,10 +1,14 @@ import type { ConfigEnv, PluginOption } from 'vite'; import path from 'node:path'; import vue from '@vitejs/plugin-vue'; +import { visualizer } from 'rollup-plugin-visualizer'; import UnoCSS from 'unocss/vite'; import AutoImport from 'unplugin-auto-import/vite'; import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'; + import Components from 'unplugin-vue-components/vite'; +import viteCompression from 'vite-plugin-compression'; + import envTyped from 'vite-plugin-env-typed'; import createSvgIcon from './svg-icon'; @@ -33,6 +37,26 @@ function plugins({ mode, command }: ConfigEnv): PluginOption[] { dts: path.join(root, 'types', 'components.d.ts'), }), createSvgIcon(command === 'build'), + + // ✅ Gzip 构建产物压缩(仅生产构建) + command === 'build' + && viteCompression({ + verbose: true, + disable: false, + threshold: 10240, + algorithm: 'gzip', + ext: '.gz', + }), + + // ✅ 构建分析图(仅生产构建) + command === 'build' + && visualizer({ + filename: './dist/stats.html', + open: false, // 打包后自动打开分析图(true 可开启) + gzipSize: true, + brotliSize: true, + }), + ]; } diff --git a/Yi.Ai.Vue3/index.html b/Yi.Ai.Vue3/index.html index ad58c31d..eb48f78d 100644 --- a/Yi.Ai.Vue3/index.html +++ b/Yi.Ai.Vue3/index.html @@ -111,49 +111,19 @@ -
+
意心Ai
海外地址,仅首次访问预计加载约10秒
-
0%
-
-
-
+
- -
- + diff --git a/Yi.Ai.Vue3/package.json b/Yi.Ai.Vue3/package.json index c7700039..34e7d9a7 100644 --- a/Yi.Ai.Vue3/package.json +++ b/Yi.Ai.Vue3/package.json @@ -67,6 +67,7 @@ "postcss": "8.4.31", "postcss-html": "1.5.0", "prettier": "^3.6.2", + "rollup-plugin-visualizer": "^6.0.3", "sass-embedded": "^1.89.2", "stylelint": "^16.21.1", "stylelint-config-html": "^1.1.0", @@ -81,6 +82,7 @@ "unplugin-auto-import": "^19.3.0", "unplugin-vue-components": "^28.8.0", "vite": "^6.3.5", + "vite-plugin-compression": "^0.5.1", "vite-plugin-env-typed": "^0.0.2", "vite-plugin-svg-icons": "^2.0.1", "vue-tsc": "^3.0.1" diff --git a/Yi.Ai.Vue3/pnpm-lock.yaml b/Yi.Ai.Vue3/pnpm-lock.yaml index ececbd1a..94c2661e 100644 --- a/Yi.Ai.Vue3/pnpm-lock.yaml +++ b/Yi.Ai.Vue3/pnpm-lock.yaml @@ -117,6 +117,9 @@ importers: prettier: specifier: ^3.6.2 version: 3.6.2 + rollup-plugin-visualizer: + specifier: ^6.0.3 + version: 6.0.3(rollup@4.41.1) sass-embedded: specifier: ^1.89.2 version: 1.89.2 @@ -159,6 +162,9 @@ importers: vite: specifier: ^6.3.5 version: 6.3.5(@types/node@22.15.30)(jiti@2.4.2)(sass-embedded@1.89.2)(yaml@2.8.0) + vite-plugin-compression: + specifier: ^0.5.1 + version: 0.5.1(vite@6.3.5(@types/node@22.15.30)(jiti@2.4.2)(sass-embedded@1.89.2)(yaml@2.8.0)) vite-plugin-env-typed: specifier: ^0.0.2 version: 0.0.2(vite@6.3.5(@types/node@22.15.30)(jiti@2.4.2)(sass-embedded@1.89.2)(yaml@2.8.0)) @@ -1813,6 +1819,10 @@ packages: resolution: {integrity: sha512-rBMvIzlpA8v6E+SJZoo++HAYqsLrkg7MSfIinMPFhmkorw7X+dOXVJQs+QT69zGkzMyfDnIMN2Wid1+NbL3T+A==} engines: {node: '>= 0.4'} + define-lazy-prop@2.0.0: + resolution: {integrity: sha512-Ds09qNh8yw3khSjiJjiUInaGX9xlqZDY7JVryGxdxV7NPeuqQfplOpQ66yJFZut3jLa5zOwkXw1g9EI2uKh4Og==} + engines: {node: '>=8'} + define-properties@1.2.1: resolution: {integrity: sha512-8QmQKqEASLd5nx0U1B1okLElbUuuttJ/AnYmRXbbbGDWh6uS208EjD4Xqq/I9wK7u0v6O08XhTWnt5XtEbR6Dg==} engines: {node: '>= 0.4'} @@ -2731,6 +2741,11 @@ packages: resolution: {integrity: sha512-JCNNGbwWZEVaSPtS45mdtrneRWJFp07LLmykxeFV5F6oBvNF8vHSfJuJgoT472pSfk+Mf8VnlrspaFBHWM8JAw==} engines: {node: '>= 0.4'} + is-docker@2.2.1: + resolution: {integrity: sha512-F+i2BKsFrH66iaUFc0woD8sLy8getkwTwtOBjvs56Cx4CgJDeKQeqfz8wAYiSb8JOprWhHH5p77PbmYCvvUuXQ==} + engines: {node: '>=8'} + hasBin: true + is-extendable@0.1.1: resolution: {integrity: sha512-5BMULNob1vgFX6EjQw5izWDxrecWK9AM72rugNr0TFldMOi0fj6Jk+zeKIt0xGj4cEfQIJth4w3OKWOJ4f+AFw==} engines: {node: '>=0.10.0'} @@ -2859,6 +2874,10 @@ packages: resolution: {integrity: sha512-eXK1UInq2bPmjyX6e3VHIzMLobc4J94i4AWn+Hpq3OU5KkrRC96OAcR3PRJ/pGu6m8TRnBHP9dkXQVsT/COVIA==} engines: {node: '>=0.10.0'} + is-wsl@2.2.0: + resolution: {integrity: sha512-fKzAra0rGJUUBwGBgNkHZuToZcn+TtXHpeCgmkMJMMYx1sQDYaCSyjJBSCa2nH1DGm7s3n1oBnohoVTBaN7Lww==} + engines: {node: '>=8'} + isarray@1.0.0: resolution: {integrity: sha512-VLghIWNM6ELQzo7zwmcg0NmTVyWKYjvIeM83yjp0wRDTmUnrM678fQbcKBo6n2CJEF0szoG//ytg+TKla89ALQ==} @@ -3414,6 +3433,10 @@ packages: resolution: {integrity: sha512-VXJjc87FScF88uafS3JllDgvAm+c/Slfz06lorj2uAY34rlUu0Nt+v8wreiImcrgAjjIHp1rXpTDlLOGw29WwQ==} engines: {node: '>=18'} + open@8.4.2: + resolution: {integrity: sha512-7x81NCL719oNbsq/3mh+hVrAWmFuEYUqrq/Iw3kUzH8ReypT9QQ0BLoJS7/G9k6N81XjW4qHWtjWwe/9eLy1EQ==} + engines: {node: '>=12'} + optionator@0.9.4: resolution: {integrity: sha512-6IpQ7mKUxRcZNLIObR0hz7lxsapSSIYNZJwXPGeF0mTVqGKFIXj1DQcMoT22S3ROcLyY/rz0PWaWZ9ayWmad9g==} engines: {node: '>= 0.8.0'} @@ -3859,6 +3882,19 @@ packages: rfdc@1.4.1: resolution: {integrity: sha512-q1b3N5QkRUWUl7iyylaaj3kOpIT0N2i9MqIEQXP73GVsN9cw3fdx8X63cEmWhJGi2PPCF23Ijp7ktmd39rawIA==} + rollup-plugin-visualizer@6.0.3: + resolution: {integrity: sha512-ZU41GwrkDcCpVoffviuM9Clwjy5fcUxlz0oMoTXTYsK+tcIFzbdacnrr2n8TXcHxbGKKXtOdjxM2HUS4HjkwIw==} + engines: {node: '>=18'} + hasBin: true + peerDependencies: + rolldown: 1.x || ^1.0.0-beta + rollup: 2.x || 3.x || 4.x + peerDependenciesMeta: + rolldown: + optional: true + rollup: + optional: true + rollup@4.41.1: resolution: {integrity: sha512-cPmwD3FnFv8rKMBc1MxWCwVQFxwf1JEmSX3iQXrRVVG15zerAIXRjMFVWnd5Q5QvgKF7Aj+5ykXFhUl+QGnyOw==} engines: {node: '>=18.0.0', npm: '>=8.0.0'} @@ -4106,6 +4142,10 @@ packages: resolution: {integrity: sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==} engines: {node: '>=0.10.0'} + source-map@0.7.6: + resolution: {integrity: sha512-i5uvt8C3ikiWeNZSVZNWcfZPItFQOsYTUAOkcUPGd8DqDy1uOUikjt5dG+uRlwyvR108Fb9DOd4GvXfT0N2/uQ==} + engines: {node: '>= 12'} + space-separated-tokens@2.0.2: resolution: {integrity: sha512-PEGlAwrG8yXGXRjW32fGbg66JAlOAwbObuqVoJpv/mRgoWDQfgH1wDPvtzWyUSNAXBGSk8h755YDbbcEy3SH2Q==} @@ -4606,6 +4646,11 @@ packages: vfile@6.0.3: resolution: {integrity: sha512-KzIbH/9tXat2u30jf+smMwFCsno4wHVdNmzFyL+T/L3UGqqk6JKfVqOFOZEpZSHADH1k40ab6NUIXZq422ov3Q==} + vite-plugin-compression@0.5.1: + resolution: {integrity: sha512-5QJKBDc+gNYVqL/skgFAP81Yuzo9R+EAf19d+EtsMF/i8kFUpNi3J/H01QD3Oo8zBQn+NzoCIFkpPLynoOzaJg==} + peerDependencies: + vite: '>=2.0.0' + vite-plugin-env-typed@0.0.2: resolution: {integrity: sha512-IloScAeDfhG81diZuvoozs73LvELSG7h3q5Eim035TUbFpou4FanMLpVZqD0lZNH2oMMHILbzx6udmkg3/NFbA==} peerDependencies: @@ -6634,6 +6679,8 @@ snapshots: es-errors: 1.3.0 gopd: 1.2.0 + define-lazy-prop@2.0.0: {} + define-properties@1.2.1: dependencies: define-data-property: 1.1.4 @@ -7800,6 +7847,8 @@ snapshots: is-accessor-descriptor: 1.0.1 is-data-descriptor: 1.0.1 + is-docker@2.2.1: {} + is-extendable@0.1.1: {} is-extendable@1.0.1: @@ -7909,6 +7958,10 @@ snapshots: is-windows@1.0.2: {} + is-wsl@2.2.0: + dependencies: + is-docker: 2.2.1 + isarray@1.0.0: {} isarray@2.0.5: {} @@ -8668,6 +8721,12 @@ snapshots: dependencies: mimic-function: 5.0.1 + open@8.4.2: + dependencies: + define-lazy-prop: 2.0.0 + is-docker: 2.2.1 + is-wsl: 2.2.0 + optionator@0.9.4: dependencies: deep-is: 0.1.4 @@ -9109,6 +9168,15 @@ snapshots: rfdc@1.4.1: {} + rollup-plugin-visualizer@6.0.3(rollup@4.41.1): + dependencies: + open: 8.4.2 + picomatch: 4.0.3 + source-map: 0.7.6 + yargs: 17.7.2 + optionalDependencies: + rollup: 4.41.1 + rollup@4.41.1: dependencies: '@types/estree': 1.0.7 @@ -9388,6 +9456,8 @@ snapshots: source-map@0.6.1: {} + source-map@0.7.6: {} + space-separated-tokens@2.0.2: {} spawndamnit@3.0.1: @@ -9826,7 +9896,7 @@ snapshots: unctx@2.4.1: dependencies: - acorn: 8.14.1 + acorn: 8.15.0 estree-walker: 3.0.3 magic-string: 0.30.17 unplugin: 2.3.5 @@ -9865,14 +9935,14 @@ snapshots: unimport@5.0.1: dependencies: - acorn: 8.14.1 + acorn: 8.15.0 escape-string-regexp: 5.0.0 estree-walker: 3.0.3 local-pkg: 1.1.1 magic-string: 0.30.17 mlly: 1.7.4 pathe: 2.0.3 - picomatch: 4.0.2 + picomatch: 4.0.3 pkg-types: 2.1.0 scule: 1.3.0 strip-literal: 3.0.0 @@ -10042,6 +10112,15 @@ snapshots: '@types/unist': 3.0.3 vfile-message: 4.0.2 + vite-plugin-compression@0.5.1(vite@6.3.5(@types/node@22.15.30)(jiti@2.4.2)(sass-embedded@1.89.2)(yaml@2.8.0)): + dependencies: + chalk: 4.1.2 + debug: 4.4.1 + fs-extra: 10.1.0 + vite: 6.3.5(@types/node@22.15.30)(jiti@2.4.2)(sass-embedded@1.89.2)(yaml@2.8.0) + transitivePeerDependencies: + - supports-color + vite-plugin-env-typed@0.0.2(vite@6.3.5(@types/node@22.15.30)(jiti@2.4.2)(sass-embedded@1.89.2)(yaml@2.8.0)): dependencies: handlebars: 4.7.8 diff --git a/Yi.Ai.Vue3/src/components/ModelSelect/index.vue b/Yi.Ai.Vue3/src/components/ModelSelect/index.vue index 3d368c48..4d78347a 100644 --- a/Yi.Ai.Vue3/src/components/ModelSelect/index.vue +++ b/Yi.Ai.Vue3/src/components/ModelSelect/index.vue @@ -8,19 +8,15 @@ import Popover from '@/components/Popover/index.vue'; import SvgIcon from '@/components/SvgIcon/index.vue'; import { useUserStore } from '@/stores'; import { useModelStore } from '@/stores/modules/model'; +import { isUserVip } from '@/utils/user'; const router = useRouter(); -// 用户角色 -const isUserRoleVip = computed(() => { - const roles = userStore.userInfo?.roles ?? []; - return roles.some(role => role.roleCode === 'YiXinAi-Vip'); -}); const userStore = useUserStore(); const modelStore = useModelStore(); // 检查模型是否可用 function isModelAvailable(item: GetSessionListVO) { - return isUserRoleVip.value || item.modelId?.includes('DeepSeek-R1-0528') || userStore.userInfo?.user?.userName === 'cc'; + return isUserVip() || item.modelId?.includes('DeepSeek-R1-0528') || userStore.userInfo?.user?.userName === 'cc'; } onMounted(async () => { @@ -64,22 +60,22 @@ function handleModelClick(item: GetSessionListVO) { ElMessageBox.confirm( `
-

${isUserRoleVip.value ? 'YiXinAI-VIP 会员' : '成为 YiXinAI-VIP'}

+

${isUserVip() ? 'YiXinAI-VIP 会员' : '成为 YiXinAI-VIP'}

${ - isUserRoleVip.value + isUserVip() ? '您已是尊贵会员,享受全部 AI 模型与专属服务。感谢支持!' : '解锁所有 AI 模型,无限加速,专属客服,尽享尊贵体验。' }

${ - isUserRoleVip.value + isUserVip() ? '

您可随时访问产品页面查看更多特权内容。

' : '

点击下方按钮,立即升级为 VIP 会员!

' }
`, - isUserRoleVip.value ? '会员状态' : '会员尊享', + isUserVip() ? '会员状态' : '会员尊享', { confirmButtonText: '前往产品页面', cancelButtonText: '关闭', @@ -92,7 +88,7 @@ function handleModelClick(item: GetSessionListVO) { .then(() => { router.push({ name: 'products', // 使用命名路由 - query: { from: isUserRoleVip.value ? 'vip' : 'user' }, // 可选:添加来源标识 + query: { from: isUserVip() ? 'vip' : 'user' }, // 可选:添加来源标识 }); }) .catch(() => { diff --git a/Yi.Ai.Vue3/src/components/userPersonalCenter/components/APIKeyManagement.vue b/Yi.Ai.Vue3/src/components/userPersonalCenter/components/APIKeyManagement.vue index 90112870..f2cd708a 100644 --- a/Yi.Ai.Vue3/src/components/userPersonalCenter/components/APIKeyManagement.vue +++ b/Yi.Ai.Vue3/src/components/userPersonalCenter/components/APIKeyManagement.vue @@ -3,7 +3,7 @@ import { CircleCheck } from '@element-plus/icons-vue'; import { ElMessage, ElMessageBox } from 'element-plus'; import { onMounted, ref } from 'vue'; import { useRouter } from 'vue-router'; -import { applyApiKey, getApiKey, getRechargeLog } from '@/api/model/index.ts'; +import { applyApiKey, getApiKey } from '@/api/model/index.ts'; import { isUserVip } from '@/utils/user'; const apiKey = ref(''); @@ -29,8 +29,6 @@ const router = useRouter(); async function fetchApiKey() { try { const res = await getApiKey(); - const res2 = await getRechargeLog(); - console.log('re2', res2); if (res.data?.apiKey) { apiKey.value = res.data.apiKey; displayedKey.value = res.data.apiKey; @@ -43,7 +41,7 @@ async function fetchApiKey() { // 领取密钥 async function handleClaim() { - if (!isUserVip) { + if (!isUserVip()) { ElMessageBox.confirm( `
@@ -172,7 +170,7 @@ onMounted(async () => { element-loading-background="rgba(122, 122, 122, 0.8)" > -
+
@@ -239,7 +237,7 @@ onMounted(async () => {
-
+

使用说明

diff --git a/Yi.Ai.Vue3/src/layouts/components/Header/components/Avatar.vue b/Yi.Ai.Vue3/src/layouts/components/Header/components/Avatar.vue index f28a923c..16956268 100644 --- a/Yi.Ai.Vue3/src/layouts/components/Header/components/Avatar.vue +++ b/Yi.Ai.Vue3/src/layouts/components/Header/components/Avatar.vue @@ -5,16 +5,12 @@ import Popover from '@/components/Popover/index.vue'; import SvgIcon from '@/components/SvgIcon/index.vue'; import { useUserStore } from '@/stores'; import { useSessionStore } from '@/stores/modules/session'; -import { userProfilePicture } from '@/utils/user'; +import { getUserProfilePicture, isUserVip } from '@/utils/user'; const router = useRouter(); const userStore = useUserStore(); const sessionStore = useSessionStore(); -const userRole = computed(() => { - const roles = userStore.userInfo?.roles ?? []; - return roles.some(role => role.roleCode === 'YiXinAi-Vip') ? 'vip' : 'user'; -}); // const src = computed( // () => userStore.userInfo?.avatar ?? 'https://avatars.githubusercontent.com/u/76239030', @@ -126,26 +122,25 @@ function handleClick(item: any) { } function openVipGuide() { - const isVip = userRole.value === 'vip' || userStore.userInfo?.user?.userName === 'cc'; ElMessageBox.confirm( `
-

${isVip ? 'YiXinAI-VIP 会员' : '成为 YiXinAI-VIP'}

+

${isUserVip() ? 'YiXinAI-VIP 会员' : '成为 YiXinAI-VIP'}

${ - isVip + isUserVip() ? '您已是尊贵会员,享受全部 AI 模型与专属服务。感谢支持!' : '解锁所有 AI 模型,无限加速,专属客服,尽享尊贵体验。' }

${ - isVip + isUserVip() ? '

您可随时访问产品页面查看更多特权内容。

' : '

点击下方按钮,立即升级为 VIP 会员!

' }
`, - isVip ? '会员状态' : '会员尊享', + isUserVip() ? '会员状态' : '会员尊享', { confirmButtonText: '前往产品页面', cancelButtonText: '关闭', @@ -158,7 +153,7 @@ function openVipGuide() { .then(() => { router.push({ name: 'products', // 使用命名路由 - query: { from: userRole.value }, // 可选:添加来源标识 + query: { from: isUserVip() ? 'vip' : 'user' }, // 可选:添加来源标识 }); }) .catch(() => { @@ -180,7 +175,7 @@ function openVipGuide() {
YiXinAI-VIP @@ -206,20 +201,20 @@ function openVipGuide() { :popover-style="popoverStyle" >