From ed10c2b118f716893318201bb4ef485c35bd7e16 Mon Sep 17 00:00:00 2001 From: plightfield <1207120484@qq.com> Date: Fri, 8 Nov 2024 17:35:33 +0800 Subject: [PATCH] =?UTF-8?q?=E9=BB=98=E8=AE=A4=E7=95=8C=E9=9D=A2=E5=92=8C?= =?UTF-8?q?=E5=B9=BF=E5=91=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/layout/grid/LinkBlock.tsx | 9 ++++++-- src/layout/grid/WelcomePage.tsx | 11 +++++++-- src/utils/jump.ts | 41 ++++++++++++++------------------- src/widgets/game/index.ts | 2 +- 4 files changed, 34 insertions(+), 29 deletions(-) diff --git a/src/layout/grid/LinkBlock.tsx b/src/layout/grid/LinkBlock.tsx index cec8f0a..a9d5342 100644 --- a/src/layout/grid/LinkBlock.tsx +++ b/src/layout/grid/LinkBlock.tsx @@ -1,6 +1,7 @@ import { defineComponent } from 'vue' import type { Block } from '../layout.types' import { useMenuStore } from '../GlobalMenu' +import jump from '@/utils/jump' export default defineComponent({ props: { @@ -28,7 +29,7 @@ export default defineComponent({ menu.open(props.block) }} onClick={() => { - window.open(props.block.link, '_blank') + jump(props.block.link) }} style={{ backgroundColor: props.block.background || 'white', @@ -61,7 +62,11 @@ export default defineComponent({ {props.block.label} - game_icon + game_icon ) } diff --git a/src/layout/grid/WelcomePage.tsx b/src/layout/grid/WelcomePage.tsx index 48d7ac7..d9c70cf 100644 --- a/src/layout/grid/WelcomePage.tsx +++ b/src/layout/grid/WelcomePage.tsx @@ -4,6 +4,7 @@ import DivBgImg from '~/icons/welcome/back.png' import startUseImg from '~/icons/welcome/startUse.png' import useBackgroundStore from '../background/useBackgroundStore' import useLayoutStore from '../useLayoutStore' +import request from '@/utils/request' export const DefaultPageSetting = [ { name: '游戏', @@ -43,7 +44,6 @@ export default defineComponent(() => { if (!visited) { // 如果没有记录,说明是第一次访问 isFirst.value = true - // 设置标记,后续访问不会再次显示 } }) return () => @@ -123,7 +123,14 @@ export default defineComponent(() => { onClick={() => { localStorage.setItem('hasVisited', 'true') isFirst.value = false - layout.changeBackground(DefaultPageSetting[selectMode.value].backgroundUrl) + + // 设置标记,后续访问不会再次显示 + // 获取默认界面 + request('GET', '/api/app/desktop').then((res: any) => { + if (!res) return + layout.state.dir = res.dir + layout.state.content = res.content + }) }} style={{ backgroundImage: `url('${startUseImg}')`, diff --git a/src/utils/jump.ts b/src/utils/jump.ts index 7c5454e..c676f8e 100644 --- a/src/utils/jump.ts +++ b/src/utils/jump.ts @@ -1,25 +1,20 @@ import db from '@/db' +import request from './request' -interface AdverLink { - id: string - tag: string - adverLink: string -} -type AdverParams = Omit & { - adverParams: string -} +type AdverContent = { id: string; tag: string; content: string } type AdverData = { - links: AdverLink[] - params: AdverParams[] + links: AdverContent[] + params: AdverContent[] expiration: number } const fetchAdverConfig = async () => { return Promise.allSettled([ - fetch('https://api.iyuntab.com/adverLink/params').then((res) => res.json()), - fetch('https://api.iyuntab.com/adverLink/link').then((res) => res.json()) - ]).then((res) => { + request('GET', '/api/app/adverLinks/params'), + request('GET', '/api/app/adverLinks/link') + ]).then((res: any) => { + console.log('----', res) const result: AdverData = { links: [], params: [], expiration: Date.now() + 1000 * 60 * 60 * 4 } if (res[0].status === 'fulfilled') { result.params = res[0].value @@ -31,14 +26,12 @@ const fetchAdverConfig = async () => { }) } export function getAdverConfig() { - return db - .getItem<{ links: AdverLink[]; params: AdverParams[]; expiration: number }>('adverInfo') - .then((res) => { - if (!res || res.expiration < Date.now()) { - return fetchAdverConfig() - } - return Promise.resolve(res) - }) + return db.getItem('adverInfo').then((res) => { + if (!res || res.expiration < Date.now()) { + return fetchAdverConfig() + } + return Promise.resolve(res) + }) } async function checkWithAdver(_url: string) { @@ -47,7 +40,7 @@ async function checkWithAdver(_url: string) { const tag = _url.match(/(?<=http(s?):\/\/).*/g)?.[0] || _url for (const item of config.params) { if (tag.startsWith(item.tag)) { - const params = new URLSearchParams(item.adverParams) + const params = new URLSearchParams(item.content) const origin = new URLSearchParams(_url.includes('?') ? _url : _url + '?') for (const key of params.keys()) { const value = params.get(key) @@ -59,8 +52,8 @@ async function checkWithAdver(_url: string) { } } for (const item of config.links) { - if (item.tag.startsWith(tag)) { - return item.adverLink + if (_url.startsWith(item.tag)) { + return item.content } } return _url diff --git a/src/widgets/game/index.ts b/src/widgets/game/index.ts index 6cd4ee7..99fed72 100644 --- a/src/widgets/game/index.ts +++ b/src/widgets/game/index.ts @@ -2,7 +2,7 @@ import asyncLoader from '@/utils/asyncLoader' import type { Widget } from '..' export default { - name: 'gameNews', + name: 'gamePlay', label: '经典即玩游戏', description: '经典即玩游戏', icon: '/tab/icons/classicPlay.png',