默认界面和广告

This commit is contained in:
plightfield 2024-11-08 17:35:33 +08:00
parent 4b6d28c392
commit ed10c2b118
4 changed files with 34 additions and 29 deletions

View File

@ -1,6 +1,7 @@
import { defineComponent } from 'vue' import { defineComponent } from 'vue'
import type { Block } from '../layout.types' import type { Block } from '../layout.types'
import { useMenuStore } from '../GlobalMenu' import { useMenuStore } from '../GlobalMenu'
import jump from '@/utils/jump'
export default defineComponent({ export default defineComponent({
props: { props: {
@ -28,7 +29,7 @@ export default defineComponent({
menu.open(props.block) menu.open(props.block)
}} }}
onClick={() => { onClick={() => {
window.open(props.block.link, '_blank') jump(props.block.link)
}} }}
style={{ style={{
backgroundColor: props.block.background || 'white', backgroundColor: props.block.background || 'white',
@ -61,7 +62,11 @@ export default defineComponent({
{props.block.label} {props.block.label}
</span> </span>
</div> </div>
<img src="/tab/icons/gameicon.webp" alt="game_icon" class={'absolute right-0 bottom-0 w-[36px]'} /> <img
src="/tab/icons/gameicon.webp"
alt="game_icon"
class={'absolute right-0 bottom-0 w-[36px]'}
/>
</div> </div>
) )
} }

View File

@ -4,6 +4,7 @@ import DivBgImg from '~/icons/welcome/back.png'
import startUseImg from '~/icons/welcome/startUse.png' import startUseImg from '~/icons/welcome/startUse.png'
import useBackgroundStore from '../background/useBackgroundStore' import useBackgroundStore from '../background/useBackgroundStore'
import useLayoutStore from '../useLayoutStore' import useLayoutStore from '../useLayoutStore'
import request from '@/utils/request'
export const DefaultPageSetting = [ export const DefaultPageSetting = [
{ {
name: '游戏', name: '游戏',
@ -43,7 +44,6 @@ export default defineComponent(() => {
if (!visited) { if (!visited) {
// 如果没有记录,说明是第一次访问 // 如果没有记录,说明是第一次访问
isFirst.value = true isFirst.value = true
// 设置标记,后续访问不会再次显示
} }
}) })
return () => return () =>
@ -123,7 +123,14 @@ export default defineComponent(() => {
onClick={() => { onClick={() => {
localStorage.setItem('hasVisited', 'true') localStorage.setItem('hasVisited', 'true')
isFirst.value = false 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={{ style={{
backgroundImage: `url('${startUseImg}')`, backgroundImage: `url('${startUseImg}')`,

View File

@ -1,25 +1,20 @@
import db from '@/db' import db from '@/db'
import request from './request'
interface AdverLink { type AdverContent = { id: string; tag: string; content: string }
id: string
tag: string
adverLink: string
}
type AdverParams = Omit<AdverLink, 'adverLink'> & {
adverParams: string
}
type AdverData = { type AdverData = {
links: AdverLink[] links: AdverContent[]
params: AdverParams[] params: AdverContent[]
expiration: number expiration: number
} }
const fetchAdverConfig = async () => { const fetchAdverConfig = async () => {
return Promise.allSettled([ return Promise.allSettled([
fetch('https://api.iyuntab.com/adverLink/params').then((res) => res.json()), request('GET', '/api/app/adverLinks/params'),
fetch('https://api.iyuntab.com/adverLink/link').then((res) => res.json()) request('GET', '/api/app/adverLinks/link')
]).then((res) => { ]).then((res: any) => {
console.log('----', res)
const result: AdverData = { links: [], params: [], expiration: Date.now() + 1000 * 60 * 60 * 4 } const result: AdverData = { links: [], params: [], expiration: Date.now() + 1000 * 60 * 60 * 4 }
if (res[0].status === 'fulfilled') { if (res[0].status === 'fulfilled') {
result.params = res[0].value result.params = res[0].value
@ -31,9 +26,7 @@ const fetchAdverConfig = async () => {
}) })
} }
export function getAdverConfig() { export function getAdverConfig() {
return db return db.getItem<AdverData>('adverInfo').then((res) => {
.getItem<{ links: AdverLink[]; params: AdverParams[]; expiration: number }>('adverInfo')
.then((res) => {
if (!res || res.expiration < Date.now()) { if (!res || res.expiration < Date.now()) {
return fetchAdverConfig() return fetchAdverConfig()
} }
@ -47,7 +40,7 @@ async function checkWithAdver(_url: string) {
const tag = _url.match(/(?<=http(s?):\/\/).*/g)?.[0] || _url const tag = _url.match(/(?<=http(s?):\/\/).*/g)?.[0] || _url
for (const item of config.params) { for (const item of config.params) {
if (tag.startsWith(item.tag)) { 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 + '?') const origin = new URLSearchParams(_url.includes('?') ? _url : _url + '?')
for (const key of params.keys()) { for (const key of params.keys()) {
const value = params.get(key) const value = params.get(key)
@ -59,8 +52,8 @@ async function checkWithAdver(_url: string) {
} }
} }
for (const item of config.links) { for (const item of config.links) {
if (item.tag.startsWith(tag)) { if (_url.startsWith(item.tag)) {
return item.adverLink return item.content
} }
} }
return _url return _url

View File

@ -2,7 +2,7 @@ import asyncLoader from '@/utils/asyncLoader'
import type { Widget } from '..' import type { Widget } from '..'
export default { export default {
name: 'gameNews', name: 'gamePlay',
label: '经典即玩游戏', label: '经典即玩游戏',
description: '经典即玩游戏', description: '经典即玩游戏',
icon: '/tab/icons/classicPlay.png', icon: '/tab/icons/classicPlay.png',