1
- import Comment from '@/components/Comment'
1
+ import CusdisComponent from '@/components/CusdisComponent'
2
+ import { Draggable } from '@/components/Draggable'
2
3
import { AdSlot } from '@/components/GoogleAdsense'
3
4
import replaceSearchResult from '@/components/Mark'
4
- import NotionPage from '@/components/NotionPage'
5
- import ShareBar from '@/components/ShareBar'
6
5
import { siteConfig } from '@/lib/config'
7
6
import { deepClone , isBrowser } from '@/lib/utils'
8
7
import Link from 'next/link'
9
- import { useRouter } from 'next/router'
10
8
import { createContext , useContext , useEffect , useRef , useState } from 'react'
11
9
import Announcement from './components/Announcement'
12
- import { ArticleFooter } from './components/ArticleFooter'
13
- import { ArticleInfo } from './components/ArticleInfo'
14
10
import { ArticleLock } from './components/ArticleLock'
15
11
import BlogArchiveItem from './components/BlogArchiveItem'
16
12
import { BlogListPage } from './components/BlogListPage'
17
13
import { BlogListScroll } from './components/BlogListScroll'
18
14
import { Footer } from './components/Footer'
15
+ import FullScreen from './components/FullScreen'
16
+ import { GameListIndexCombine } from './components/GameListIndexCombine'
17
+ import { GameListRelate } from './components/GameListRealate'
18
+ import { GameListRecent } from './components/GameListRecent'
19
19
import Header from './components/Header'
20
20
import NavBar from './components/NavBar'
21
21
import SearchNavBar from './components/SearchNavBar'
@@ -45,7 +45,11 @@ const LayoutBase = props => {
45
45
// 在列表中进行实时过滤
46
46
const [ filterKey , setFilterKey ] = useState ( '' )
47
47
48
- const [ filterGames , setFilterGames ] = useState ( deepClone ( allNavPages ?. filter ( item => item . recommend ) ) )
48
+ const [ filterGames , setFilterGames ] = useState (
49
+ deepClone (
50
+ allNavPages ?. filter ( item => item . tags ?. some ( t => t === siteConfig ( 'GAME_RECOMMEND_TAG' , 'Recommend' , CONFIG ) ) )
51
+ )
52
+ )
49
53
const [ recentGames , setRecentGames ] = useState ( [ ] )
50
54
const [ sideBarVisible , setSideBarVisible ] = useState ( false )
51
55
@@ -68,7 +72,7 @@ const LayoutBase = props => {
68
72
} } >
69
73
< div
70
74
id = 'theme-game'
71
- className = { `${ siteConfig ( 'FONT_STYLE' ) } w-full h-full min-h-screen justify-center dark:text-gray-300 scroll-smooth` } >
75
+ className = { `${ siteConfig ( 'FONT_STYLE' ) } w-full h-full min-h-screen justify-center bg-[#83FFE7] dark:bg-black dark:text-gray-300 scroll-smooth` } >
72
76
< Style />
73
77
{ /* 左右布局 */ }
74
78
< div id = 'wrapper' className = { 'relative flex justify-between w-full h-full mx-auto' } >
@@ -95,8 +99,9 @@ const LayoutBase = props => {
95
99
</ div >
96
100
97
101
{ /* 右侧 */ }
98
- < main className = 'flex-grow w-full overflow-x-scroll ' >
102
+ < main className = 'flex-grow w-full overflow-x-auto ' >
99
103
{ children }
104
+
100
105
< div className = 'ads w-full justify-center flex p-2' >
101
106
< AdSlot type = 'flow' />
102
107
</ div >
@@ -122,7 +127,13 @@ const LayoutBase = props => {
122
127
* @returns
123
128
*/
124
129
const LayoutIndex = props => {
125
- return < LayoutPostList { ...props } topSlot = { < Announcement { ...props } /> } />
130
+ return (
131
+ < >
132
+ < GameListRecent />
133
+ < LayoutPostList { ...props } />
134
+ < Announcement { ...props } />
135
+ </ >
136
+ )
126
137
}
127
138
128
139
/**
@@ -131,7 +142,7 @@ const LayoutIndex = props => {
131
142
* @returns
132
143
*/
133
144
const LayoutPostList = props => {
134
- const { posts, topSlot , tag } = props
145
+ const { posts, tag } = props
135
146
const { filterKey } = useGameGlobal ( )
136
147
let filteredBlogPosts = [ ]
137
148
if ( filterKey && posts ) {
@@ -146,7 +157,6 @@ const LayoutPostList = props => {
146
157
147
158
return (
148
159
< >
149
- { topSlot }
150
160
{ tag && < SearchNavBar { ...props } /> }
151
161
{ siteConfig ( 'POST_LIST_STYLE' ) === 'page' ? (
152
162
< BlogListPage { ...props } posts = { filteredBlogPosts } />
@@ -227,38 +237,159 @@ const LayoutArchive = props => {
227
237
* @returns
228
238
*/
229
239
const LayoutSlug = props => {
230
- const { post, lock, validPassword } = props
231
- const router = useRouter ( )
240
+ const { post, allNavPages, lock, validPassword } = props
241
+ const game = post
242
+ const [ loading , setLoading ] = useState ( false )
243
+ // const [url, setUrl] = useState(game?.ext?.href)
244
+ // 替换成随机推荐和相关游戏
245
+ const relateGames = allNavPages
246
+ const randomGames = allNavPages
247
+
248
+ // 将当前游戏加入到最近游玩
232
249
useEffect ( ( ) => {
233
- // 404
234
- if ( ! post ) {
235
- setTimeout (
236
- ( ) => {
237
- if ( isBrowser ) {
238
- const article = document . getElementById ( 'notion-article' )
239
- if ( ! article ) {
240
- router . push ( '/404' ) . then ( ( ) => {
241
- console . warn ( '找不到页面' , router . asPath )
242
- } )
243
- }
244
- }
245
- } ,
246
- siteConfig ( 'POST_WAITING_TIME_FOR_404' ) * 1000
247
- )
250
+ // if (!url || url !== game?.ext?.href) {
251
+ // // 游戏路径
252
+ // setUrl(game?.ext?.href)
253
+ // }
254
+
255
+ // 更新最新游戏
256
+ const recentGames = localStorage . getItem ( 'recent_games' ) ? JSON . parse ( localStorage . getItem ( 'recent_games' ) ) : [ ]
257
+
258
+ const existedIndex = recentGames . findIndex ( item => item ?. id === game ?. id )
259
+ if ( existedIndex === - 1 ) {
260
+ recentGames . unshift ( game ) // 将游戏插入到数组头部
261
+ } else {
262
+ // 如果游戏已存在于数组中,将其移至数组头部
263
+ const existingGame = recentGames . splice ( existedIndex , 1 ) [ 0 ]
264
+ recentGames . unshift ( existingGame )
265
+ }
266
+ localStorage . setItem ( 'recent_games' , JSON . stringify ( recentGames ) )
267
+
268
+ const iframe = document . getElementById ( 'game-wrapper' )
269
+
270
+ // 定义一个函数来处理iframe加载成功事件
271
+ function iframeLoaded ( ) {
272
+ if ( game ) {
273
+ setLoading ( false )
274
+ }
248
275
}
249
- } , [ post ] )
276
+
277
+ // 绑定加载事件
278
+ if ( iframe . attachEvent ) {
279
+ iframe . attachEvent ( 'onload' , iframeLoaded )
280
+ } else {
281
+ iframe . onload = iframeLoaded
282
+ }
283
+
284
+ // 更改iFrame的title
285
+ if ( document ?. getElementById ( 'game-wrapper' ) ?. contentDocument . querySelector ( 'title' ) ?. textContent ) {
286
+ document . getElementById ( 'game-wrapper' ) . contentDocument . querySelector ( 'title' ) . textContent = `${
287
+ game ?. title || ''
288
+ } - Play ${ game ?. title || '' } on ${ siteConfig ( 'TITLE' ) } `
289
+ }
290
+ } , [ game ] )
291
+
250
292
return (
251
293
< >
252
294
{ lock && < ArticleLock validPassword = { validPassword } /> }
253
295
254
296
{ ! lock && (
255
297
< div id = 'article-wrapper' className = 'px-2' >
256
298
< >
257
- < ArticleInfo post = { post } />
299
+ { /* <ArticleInfo post={post} />
258
300
<NotionPage post={post} />
259
301
<ShareBar post={post} />
260
302
<Comment frontMatter={post} />
261
- < ArticleFooter />
303
+ <ArticleFooter /> */ }
304
+ { /* 游戏区域 */ }
305
+ < div className = 'game-detail-wrapper w-full grow flex md:px-2' >
306
+ { /* 移动端返回主页按钮 */ }
307
+ < Draggable stick = 'left' >
308
+ < div
309
+ style = { { left : '0px' , top : '1rem' } }
310
+ className = 'fixed xl:hidden group space-x-1 flex items-center z-20 pr-3 pl-1 bg-[#202030] rounded-r-2xl shadow-lg ' >
311
+ < Link href = '/' className = 'px-1 py-3 hover:scale-125 duration-200 transition-all' passHref >
312
+ < i className = 'fas fa-arrow-left' />
313
+ </ Link > { ' ' }
314
+ < span
315
+ className = 'text-white font-serif'
316
+ onClick = { ( ) => {
317
+ document . querySelector ( '.game-info' ) . scrollIntoView ( {
318
+ behavior : 'smooth' ,
319
+ block : 'end' ,
320
+ inline : 'nearest'
321
+ } )
322
+ } } >
323
+ G
324
+ </ span >
325
+ </ div >
326
+ </ Draggable >
327
+
328
+ < div className = 'w-full py-1 md:py-4' >
329
+ < div className = 'bg-black w-full xl:h-[calc(100vh-8rem)] h-screen rounded-md relative' >
330
+ { /* Loading遮罩 */ }
331
+ { loading && (
332
+ < div className = 'absolute z-20 w-full xl:h-[calc(100vh-8rem)] h-screen rounded-md overflow-hidden ' >
333
+ < div className = 'z-20 absolute bg-black bg-opacity-75 w-full h-full flex flex-col gap-4 justify-center items-center' >
334
+ < h2 className = 'text-3xl text-white flex gap-2' >
335
+ < i className = 'fas fa-spinner animate-spin' > </ i >
336
+ { siteConfig ( 'TITLE' ) }
337
+ </ h2 >
338
+ < h3 className = 'text-xl text-white' > { siteConfig ( 'DESCRIPTION' ) } </ h3 >
339
+ </ div >
340
+
341
+ { /* 游戏封面图 */ }
342
+ { /* eslint-disable-next-line @next/next/no-img-element */ }
343
+ { game ?. img && < img src = { game ?. img } className = 'w-full h-full blur-md absolute top-0 left-0 z-0' /> }
344
+ </ div >
345
+ ) }
346
+
347
+ < iframe
348
+ id = 'game-wrapper'
349
+ className = { `w-full xl:h-[calc(100vh-8rem)] h-screen md:rounded-md overflow-hidden ${ game ?. ext ?. href ? '' : 'hidden' } ` }
350
+ style = { {
351
+ position : 'relative'
352
+ } }
353
+ src = { game ?. ext ?. href } > </ iframe >
354
+
355
+ { /* 游戏窗口装饰器 */ }
356
+ { game && ! loading && (
357
+ < div className = 'game-decorator bg-[#0B0D14] right-0 bottom-0 flex justify-center h-12 md:w-12 z-10 md:absolute' >
358
+ { /* 加入全屏按钮 */ }
359
+ < FullScreen />
360
+ </ div >
361
+ ) }
362
+ </ div >
363
+
364
+ { /* 游戏资讯 */ }
365
+ < div className = 'game-info dark:text-white py-4 mt-8 md:mt-0' >
366
+ < div className = 'w-full' >
367
+ < GameListRelate posts = { relateGames } />
368
+ </ div >
369
+ < h1 className = 'text-2xl px-2 py-2 xl:px-0' > { game ?. title } </ h1 >
370
+ < h2 className = 'px-2 py-2 xl:px-0' >
371
+ Play { game ?. title || '' } on { siteConfig ( 'TITLE' , '' ) }
372
+ </ h2 >
373
+ < p className = 'px-2 py-2 xl:px-0' > { siteConfig ( 'DESCRIPTION' ) } </ p >
374
+ < AdSlot />
375
+
376
+ { game && (
377
+ < div >
378
+ < div className = 'py-2 text-2xl dark:text-white' > Comment</ div >
379
+ < CusdisComponent frontMatter = { game } />
380
+ </ div >
381
+ ) }
382
+ </ div >
383
+ </ div >
384
+ </ div >
385
+
386
+ < div className = 'xl:hidden py-2' >
387
+ < Header />
388
+ </ div >
389
+ { /* 其它游戏列表 */ }
390
+ < div >
391
+ < GameListIndexCombine posts = { randomGames } />
392
+ </ div >
262
393
</ >
263
394
</ div >
264
395
) }
0 commit comments