diff --git a/public/icons/game_video.png b/public/icons/game_video.png
new file mode 100644
index 0000000..78ac72c
Binary files /dev/null and b/public/icons/game_video.png differ
diff --git a/src/layout/adder/WidgetAdder.tsx b/src/layout/adder/WidgetAdder.tsx
index 10d3ec0..d1bb661 100644
--- a/src/layout/adder/WidgetAdder.tsx
+++ b/src/layout/adder/WidgetAdder.tsx
@@ -34,7 +34,13 @@ export const WidgetItem = defineComponent({
'text-black/80': !isGame.value
})}
>
- {props.content.label}
+ {props.content.name === 'gameVideo'
+ ? useLayoutStore().state.current === 0
+ ? '游戏视频'
+ : useLayoutStore().state.current === 1
+ ? '学习视频'
+ : '娱乐视频'
+ : props.content.label}
- {props.content.description}
+ {props.content.description === 'gameVideoDesc'
+ ? useLayoutStore().state.current === 0
+ ? '热门游戏视频'
+ : useLayoutStore().state.current === 1
+ ? '热门学习视频'
+ : '热门娱乐视频'
+ : props.content.description}
diff --git a/src/layout/grid/BlockWrapper.tsx b/src/layout/grid/BlockWrapper.tsx
index ba1fe5d..2183e1a 100644
--- a/src/layout/grid/BlockWrapper.tsx
+++ b/src/layout/grid/BlockWrapper.tsx
@@ -26,7 +26,7 @@ export default defineComponent({
const hover = ref(false)
return () => (
-
-
- {props.block.link ? (
- props.block.link.startsWith('id:') ? (
- // 文件夹
-
- ) : (
- // 链接
-
- )
+
+ {props.block.link ? (
+ props.block.link.startsWith('id:') ? (
+ // 文件夹
+
) : (
- // 小组件
-
- )}
-
- {settings.state.showBlockLabel && (
-
- {layout.getLabel(props.block)}
-
+ // 链接
+
+ )
+ ) : (
+ // 小组件
+
)}
+ {settings.state.showBlockLabel && (
+
+ {layout.getLabel(props.block)}
+
+ )}
)
}
diff --git a/src/layout/useLayoutStore.ts b/src/layout/useLayoutStore.ts
index 2e3198e..0000802 100644
--- a/src/layout/useLayoutStore.ts
+++ b/src/layout/useLayoutStore.ts
@@ -22,6 +22,7 @@ const defaultLayout: Layout = {
export default defineStore('layout', () => {
const state = reactive(defaultLayout)
const ready = ref(false)
+
db.getItem
('layout').then((res) => {
if (res) {
Object.assign(state, res)
@@ -96,10 +97,18 @@ export default defineStore('layout', () => {
const dir = state.dir[block.link.slice(3)]
if (dir) return dir.label
}
+ // 处理不同的组件的名称
+ if (block.name === 'gameVideo') {
+ console.log(state.currentPage);
+ console.log(block);
+
+ return state.current === 0 ? '游戏视频' : state.current === 1 ? '学习视频' : '娱乐视频'
+ }
return block.label || ''
}
+
const changeBackground = (url: string) => {
- state.content[state.current].background = url
+ state.content[state.current].background = url
}
return {
state,
diff --git a/src/utils/tool.ts b/src/utils/tool.ts
new file mode 100644
index 0000000..97ab530
--- /dev/null
+++ b/src/utils/tool.ts
@@ -0,0 +1,9 @@
+/**
+ * 生成随机数
+ * @param min 最小值
+ * @param max 最大值
+ * @returns 随机数
+ */
+export function randomNum(min: number, max: number) {
+ return Math.floor(Math.random() * (max - min + 1)) + min;
+}
\ No newline at end of file
diff --git a/src/widgets/gameVideo/Large.tsx b/src/widgets/gameVideo/Large.tsx
new file mode 100644
index 0000000..cccbd51
--- /dev/null
+++ b/src/widgets/gameVideo/Large.tsx
@@ -0,0 +1,103 @@
+import useLayoutStore from '@/layout/useLayoutStore'
+import request from '@/utils/request'
+import { addIcons, OhVueIcon } from 'oh-vue-icons'
+import { computed, defineComponent, onMounted, ref, watch, type CSSProperties } from 'vue'
+import { FaChevronLeft } from 'oh-vue-icons/icons'
+import type { CarouselRef } from 'ant-design-vue/es/carousel'
+import { randomNum } from '@/utils/tool'
+addIcons(FaChevronLeft)
+interface Owner {
+ face: string
+ mid: number
+ name: string
+}
+
+interface GameData {
+ _id: string
+ aid: number
+ ctime: number
+ duration: number
+ owner: Owner
+ pic: string
+ rid: string
+ time: string
+ title: string
+ type: string
+}
+export default defineComponent(() => {
+ const list = ref([])
+ const currentIndex = ref(-1)
+
+ const current = computed(() => {
+ if (currentIndex.value === -1) {
+ return null
+ } else {
+ return list.value[currentIndex.value]
+ }
+ })
+ watch(
+ () => useLayoutStore().state.current,
+ (val) => {
+ const type = val === 0 ? 'game' : val === 1 ? 'study' : 'entertainment'
+ request('GET', `/api/hotVideo?type=${type}`).then((res) => {
+ list.value = res
+ currentIndex.value = randomNum(0, list.value.length)
+ })
+ },
+ {
+ immediate: true
+ }
+ )
+ onMounted(() => {
+ setInterval(() => {
+ currentIndex.value = currentIndex.value === list.value.length - 1 ? 0 : currentIndex.value + 1
+ }, 5000)
+ })
+ return () => (
+
+ {
+
+
+
+ {current.value?.title}
+
+ {current.value?.owner.name}
+
+
{
+ e.stopPropagation()
+
+ currentIndex.value =
+ currentIndex.value === 0 ? list.value.length - 1 : currentIndex.value - 1
+ }}
+ class="absolute hidden bottom-[20px] group-hover:flex items-center justify-center left-[0px] w-[22px] h-[22px] bg-white/30 rounded"
+ >
+
+
+
{
+ e.stopPropagation()
+ currentIndex.value =
+ currentIndex.value === list.value.length - 1 ? 0 : currentIndex.value + 1
+ }}
+ class="absolute hidden bottom-[20px] group-hover:flex items-center justify-center right-[0px] rotate-180 w-[22px] h-[22px] bg-white/30 rounded"
+ >
+
+
+
+ }
+
+ )
+})
diff --git a/src/widgets/gameVideo/index.ts b/src/widgets/gameVideo/index.ts
new file mode 100644
index 0000000..93d74e8
--- /dev/null
+++ b/src/widgets/gameVideo/index.ts
@@ -0,0 +1,18 @@
+import asyncLoader from '@/utils/asyncLoader'
+import type { Widget } from '..'
+
+export default {
+ name: 'gameVideo',
+ label: 'gameVideo',
+ description: 'gameVideoDesc',
+ icon: '/icons/game_video.png',
+ modal: null,
+ list: [
+ {
+ w: 4,
+ h: 2,
+ label: '大',
+ component: asyncLoader(() => import('./Large'))
+ }
+ ]
+} as Widget
diff --git a/src/widgets/index.ts b/src/widgets/index.ts
index 3afb210..1b6e83f 100644
--- a/src/widgets/index.ts
+++ b/src/widgets/index.ts
@@ -7,6 +7,7 @@ import eat from './eat'
import discount from './discount'
import hotspot from './hotspot'
import constellation from './constellation'
+import gameVideo from './gameVideo'
export interface Widget {
name: string // 小组件类型唯一标识
label: string // 小组件名称
@@ -21,4 +22,4 @@ export interface Widget {
}[] // 不同尺寸小组件块
}
-export default [calendar, weather, weApply, gameNews, eat, discount, hotspot, constellation] as Widget[]
+export default [calendar, weather, weApply, gameNews, eat, discount, hotspot, constellation, gameVideo] as Widget[]
diff --git a/src/widgets/video/Large.tsx b/src/widgets/video/Large.tsx
deleted file mode 100644
index b83de91..0000000
--- a/src/widgets/video/Large.tsx
+++ /dev/null
@@ -1,9 +0,0 @@
-import { defineComponent } from 'vue'
-
-export default defineComponent(() => {
- return () => (
-
- large
-
- )
-})
diff --git a/src/widgets/video/Middle.tsx b/src/widgets/video/Middle.tsx
deleted file mode 100644
index 53edc23..0000000
--- a/src/widgets/video/Middle.tsx
+++ /dev/null
@@ -1,10 +0,0 @@
-import { defineComponent } from 'vue'
-
-export default defineComponent(() => {
-
- return () => (
-
- middle
-
- )
-})
diff --git a/src/widgets/video/Modal.tsx b/src/widgets/video/Modal.tsx
deleted file mode 100644
index 9890740..0000000
--- a/src/widgets/video/Modal.tsx
+++ /dev/null
@@ -1,12 +0,0 @@
-import { defineComponent } from 'vue'
-
-export default defineComponent(() => {
- return () => (
-
- )
-})
diff --git a/src/widgets/video/Small.tsx b/src/widgets/video/Small.tsx
deleted file mode 100644
index bf0a763..0000000
--- a/src/widgets/video/Small.tsx
+++ /dev/null
@@ -1,14 +0,0 @@
-import { defineComponent } from 'vue'
-
-export default defineComponent(() => {
- return () => (
-
-
-
- )
-})
diff --git a/src/widgets/video/index.ts b/src/widgets/video/index.ts
deleted file mode 100644
index 46a5db7..0000000
--- a/src/widgets/video/index.ts
+++ /dev/null
@@ -1,30 +0,0 @@
-import asyncLoader from '@/utils/asyncLoader'
-import type { Widget } from '..'
-
-export default {
- name: 'gameNews',
- label: '游戏资讯',
- description: '游戏资讯',
- icon: '/icons/game_news_icon.png',
- modal: asyncLoader(() => import('./Modal')),
- list: [
- {
- w: 2,
- h: 1,
- label: '小',
- component: asyncLoader(() => import('./Small'))
- },
- {
- w: 2,
- h: 2,
- label: '中',
- component: asyncLoader(() => import('./Middle'))
- },
- {
- w: 4,
- h: 2,
- label: '大',
- component: asyncLoader(() => import('./Large'))
- }
- ]
-} as Widget
diff --git a/src/widgets/video/useVideoStore.tsx b/src/widgets/video/useVideoStore.tsx
deleted file mode 100644
index fc596da..0000000
--- a/src/widgets/video/useVideoStore.tsx
+++ /dev/null
@@ -1,34 +0,0 @@
-import useLayoutStore from '@/layout/useLayoutStore'
-import request from '@/utils/request'
-import { defineStore } from 'pinia'
-import { computed, ref, watch } from 'vue'
-
-type HotType = {
- desc: string
- hotScore: string
- index: number
- picurl: string
- title: string
- url: string
-}
-export const PlatformList = new Map([
- ['baidu', '百度'],
- ['weibo', '微博'],
- ['bilibili', 'B站']
-] as const)
-
-export default defineStore('video', () => {
- const videoList = ref([])
- const layout = useLayoutStore()
- const type = ref('baidu')
- const getNews = async (type: string) => {
- const res = request('GET', `/api/hotList?type=${type}`)
- }
- watch(
- () => layout.state.current,
- (val) => {
- console.log('videoList', val)
- }
- )
- return {}
-})