Skip to content

Commit

Permalink
feat: add news list page with search and pagination, implement news d…
Browse files Browse the repository at this point in the history
…etail page with media features
  • Loading branch information
speedhigh committed Aug 7, 2024
1 parent 783378c commit 8a3aea9
Show file tree
Hide file tree
Showing 26 changed files with 1,268 additions and 662 deletions.
6 changes: 6 additions & 0 deletions components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@ export {}
/* prettier-ignore */
declare module 'vue' {
export interface GlobalComponents {
AccB: typeof import('./src/components/AccB.vue')['default']
AudioPlayer: typeof import('./src/components/AudioPlayer.vue')['default']
AutocompleteTag: typeof import('./src/components/AutocompleteTag.vue')['default']
AutoTag: typeof import('./src/components/AutoTag.vue')['default']
BackToTop: typeof import('./src/components/BackToTop.vue')['default']
BaseNavbar: typeof import('./src/components/BaseNavbar.vue')['default']
BasePagination: typeof import('./src/components/BasePagination.vue')['default']
LazyLoadImage: typeof import('./src/components/LazyLoadImage.vue')['default']
RouterLink: typeof import('vue-router')['RouterLink']
RouterView: typeof import('vue-router')['RouterView']
VideoPlayer: typeof import('./src/components/VideoPlayer.vue')['default']
}
}
3 changes: 2 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
<meta charset="UTF-8" />
<link rel="icon" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="responsive-news-portal" />
<meta name="description"
content="Discover the latest news, insights, and stories from around the world. Stay up-to-date with current events and explore in-depth articles that matter to you." />
<link rel="stylesheet" href="/loading.css" />
<title>responsive-news-portal</title>
</head>
Expand Down
18 changes: 11 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,27 @@
"preview": "vite preview"
},
"dependencies": {
"@types/nprogress": "^0.2.3",
"@vueuse/core": "^10.11.0",
"vue": "^3.4.31",
"vue-router": "4"
"nprogress": "^0.2.0",
"pinia": "^2.2.0",
"pinia-plugin-persistedstate": "^3.2.1",
"vue": "^3.4.35",
"vue-router": "^4.4.2"
},
"devDependencies": {
"@stefanobartoletti/eslint-config": "^3.0.1",
"@vitejs/plugin-vue": "^5.0.5",
"autoprefixer": "^10.4.19",
"@vitejs/plugin-vue": "^5.1.2",
"autoprefixer": "^10.4.20",
"eslint": "^9.8.0",
"postcss": "^8.4.40",
"postcss": "^8.4.41",
"tailwind-scrollbar": "^3.1.0",
"tailwindcss": "^3.4.7",
"ts-node": "^10.9.2",
"typescript": "^5.5.4",
"unplugin-auto-import": "^0.18.2",
"unplugin-vue-components": "^0.27.3",
"vite": "^5.3.4",
"vue-tsc": "^2.0.24"
"vite": "^5.3.5",
"vue-tsc": "^2.0.29"
}
}
445 changes: 251 additions & 194 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,24 @@
</router-view>
</view>
</template>

<style>
#nprogress .bar {
background: #0064c8 !important;
}
/* 设置滚动条滑块的样式 */
/* 1,滚动条 */
::-webkit-scrollbar {
width: 6px;
cursor: pointer;
height: 0px;
}
::-webkit-scrollbar-thumb {
width: 4px;
background-color: rgba(0, 0, 0, 0.25);
border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
background-color: rgba(0, 0, 0, 0.4);
}
</style>
104 changes: 104 additions & 0 deletions src/components/AudioPlayer.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<template>
<div class="flex w-full max-w-full items-center rounded-lg bg-white p-4">
<!-- 播放/暂停按钮 -->
<button
class="f-c-c mr-4 w-12 shrink-0 sm:w-16 md:w-20"
@click="togglePlay"
>
<span v-if="isPlaying">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" class="size-5">
<path d="M5.75 3a.75.75 0 0 0-.75.75v12.5c0 .414.336.75.75.75h1.5a.75.75 0 0 0 .75-.75V3.75A.75.75 0 0 0 7.25 3h-1.5ZM12.75 3a.75.75 0 0 0-.75.75v12.5c0 .414.336.75.75.75h1.5a.75.75 0 0 0 .75-.75V3.75a.75.75 0 0 0-.75-.75h-1.5Z" />
</svg>
</span>
<span v-else>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" class="size-5">
<path d="M6.3 2.84A1.5 1.5 0 0 0 4 4.11v11.78a1.5 1.5 0 0 0 2.3 1.27l9.344-5.891a1.5 1.5 0 0 0 0-2.538L6.3 2.841Z" />
</svg>

</span>
</button>
<!-- 音频信息和进度条 -->
<div class="flex-1">
<div class="line-1 text-sm font-semibold sm:text-base">{{ props.trackTitle }}</div>
<div class="mt-2 text-xs text-gray-500">{{ formatTime(currentTime) }} / {{ formatTime(duration) }}</div>
<input v-model="currentTime" type="range" min="0" :max="duration" class="mt-2 w-full" @input="seek" />
</div>
<!-- 隐藏的音频元素 -->
<audio ref="audio" :src="props.audioSrc" @timeupdate="updateTime" @loadedmetadata="updateDuration"></audio>
</div>
</template>

<script setup lang="ts">
// 定义组件的 props 类型
interface Props {
audioSrc: string
trackTitle: string
}
// 使用 withDefaults 设置默认值
const props = withDefaults(defineProps<Props>(), {
audioSrc: 'https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3',
trackTitle: 'Sample Track',
})
// 定义播放状态和时间相关的响应式变量
const isPlaying: Ref<boolean> = ref(false)
const currentTime: Ref<number> = ref(0)
const duration: Ref<number> = ref(0)
const audio: Ref<HTMLAudioElement | null> = ref(null)
// 播放/暂停音频的函数
const togglePlay = (): void => {
if (isPlaying.value) {
audio.value?.pause()
}
else {
audio.value?.play()
}
isPlaying.value = !isPlaying.value
}
// 更新当前播放时间的函数
const updateTime = (): void => {
if (audio.value) {
currentTime.value = audio.value.currentTime
}
}
// 更新音频总时长的函数
const updateDuration = (): void => {
if (audio.value) {
duration.value = audio.value.duration
}
}
// 跳转到指定时间的函数
const seek = (): void => {
if (audio.value) {
audio.value.currentTime = currentTime.value
}
}
// 监听播放和暂停事件
onMounted((): void => {
if (audio.value) {
audio.value.addEventListener('play', () => (isPlaying.value = true))
audio.value.addEventListener('pause', () => (isPlaying.value = false))
}
})
// 移除播放和暂停事件监听器
onUnmounted((): void => {
if (audio.value) {
audio.value.removeEventListener('play', () => (isPlaying.value = true))
audio.value.removeEventListener('pause', () => (isPlaying.value = false))
}
})
// 格式化时间为 mm:ss 格式
const formatTime = (time: number): string => {
const minutes = Math.floor(time / 60)
const seconds = Math.floor(time % 60)
return `${minutes}:${seconds < 10 ? '0' : ''}${seconds}`
}
</script>
Loading

0 comments on commit 8a3aea9

Please sign in to comment.