2024-05-16 18:54:30 +08:00
|
|
|
<template>
|
|
|
|
|
<div class="search-box flex">
|
|
|
|
|
<div class="search-box-input flex-1">
|
|
|
|
|
<n-input
|
|
|
|
|
v-model:value="searchValue"
|
|
|
|
|
size="medium"
|
|
|
|
|
round
|
|
|
|
|
:placeholder="hotSearchKeyword"
|
2024-12-28 16:43:52 +08:00
|
|
|
class="border dark:border-gray-600 border-gray-200"
|
2024-05-16 18:54:30 +08:00
|
|
|
@keydown.enter="search"
|
|
|
|
|
>
|
|
|
|
|
<template #prefix>
|
|
|
|
|
<i class="iconfont icon-search"></i>
|
|
|
|
|
</template>
|
|
|
|
|
<template #suffix>
|
2024-12-27 18:27:01 +08:00
|
|
|
<n-dropdown trigger="hover" :options="searchTypeOptions" @select="selectSearchType">
|
|
|
|
|
<div class="w-20 px-3 flex justify-between items-center">
|
|
|
|
|
<div>{{ searchTypeOptions.find((item) => item.key === store.state.searchType)?.label }}</div>
|
2024-05-16 18:54:30 +08:00
|
|
|
<i class="iconfont icon-xiasanjiaoxing"></i>
|
2024-12-27 18:27:01 +08:00
|
|
|
</div>
|
|
|
|
|
</n-dropdown>
|
2024-05-16 18:54:30 +08:00
|
|
|
</template>
|
|
|
|
|
</n-input>
|
|
|
|
|
</div>
|
2024-12-27 18:27:01 +08:00
|
|
|
<n-popover trigger="hover" placement="bottom" :show-arrow="false" raw>
|
|
|
|
|
<template #trigger>
|
|
|
|
|
<div class="user-box">
|
|
|
|
|
<n-avatar
|
|
|
|
|
v-if="store.state.user"
|
2024-12-28 16:43:52 +08:00
|
|
|
class="cursor-pointer"
|
2024-12-27 18:27:01 +08:00
|
|
|
circle
|
|
|
|
|
size="medium"
|
|
|
|
|
:src="getImgUrl(store.state.user.avatarUrl)"
|
|
|
|
|
@click="selectItem('user')"
|
|
|
|
|
/>
|
|
|
|
|
<div v-else class="mx-2 rounded-full cursor-pointer text-sm" @click="toLogin">登录</div>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
<div class="user-popover">
|
|
|
|
|
<div v-if="store.state.user" class="user-header" @click="selectItem('user')">
|
|
|
|
|
<n-avatar circle size="small" :src="getImgUrl(store.state.user?.avatarUrl)" />
|
|
|
|
|
<span class="username">{{ store.state.user?.nickname || 'Theodore' }}</span>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="menu-items">
|
|
|
|
|
<div v-if="!store.state.user" class="menu-item" @click="toLogin">
|
|
|
|
|
<i class="iconfont ri-login-box-line"></i>
|
|
|
|
|
<span>去登录</span>
|
|
|
|
|
</div>
|
2024-12-28 16:43:52 +08:00
|
|
|
<!-- 切换主题 -->
|
2024-12-27 18:27:01 +08:00
|
|
|
<div class="menu-item" @click="selectItem('set')">
|
|
|
|
|
<i class="iconfont ri-settings-3-line"></i>
|
|
|
|
|
<span>设置</span>
|
|
|
|
|
</div>
|
2024-12-28 16:43:52 +08:00
|
|
|
<div class="menu-item">
|
|
|
|
|
<i class="iconfont" :class="isDarkTheme ? 'ri-moon-line' : 'ri-sun-line'"></i>
|
|
|
|
|
<span>主题</span>
|
|
|
|
|
<n-switch v-model:value="isDarkTheme" class="ml-auto">
|
|
|
|
|
<template #checked>
|
|
|
|
|
<i class="ri-moon-line"></i>
|
|
|
|
|
</template>
|
|
|
|
|
<template #unchecked>
|
|
|
|
|
<i class="ri-sun-line"></i>
|
|
|
|
|
</template>
|
|
|
|
|
</n-switch>
|
|
|
|
|
</div>
|
2024-12-27 18:27:01 +08:00
|
|
|
<div class="menu-item" @click="toGithubRelease">
|
|
|
|
|
<i class="iconfont ri-refresh-line"></i>
|
|
|
|
|
<span>当前版本</span>
|
|
|
|
|
<span class="download-btn">{{ config.version }}</span>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</n-popover>
|
|
|
|
|
|
2024-12-15 14:13:13 +08:00
|
|
|
<coffee :alipay-q-r="alipay" :wechat-q-r="wechat">
|
2024-12-07 23:20:31 +08:00
|
|
|
<div class="github" @click="toGithub">
|
|
|
|
|
<i class="ri-github-fill"></i>
|
|
|
|
|
</div>
|
|
|
|
|
</coffee>
|
2024-05-16 18:54:30 +08:00
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
2024-12-28 16:43:52 +08:00
|
|
|
import { onMounted, ref, watchEffect } from 'vue';
|
2024-05-16 18:54:30 +08:00
|
|
|
import { useRouter } from 'vue-router';
|
|
|
|
|
import { useStore } from 'vuex';
|
|
|
|
|
|
2024-12-27 18:27:01 +08:00
|
|
|
import config from '@/../package.json';
|
2024-05-16 18:54:30 +08:00
|
|
|
import { getSearchKeyword } from '@/api/home';
|
|
|
|
|
import { getUserDetail, logout } from '@/api/login';
|
2024-12-15 14:13:13 +08:00
|
|
|
import alipay from '@/assets/alipay.png';
|
|
|
|
|
import wechat from '@/assets/wechat.png';
|
2024-12-07 23:20:31 +08:00
|
|
|
import Coffee from '@/components/Coffee.vue';
|
2024-05-16 18:54:30 +08:00
|
|
|
import { SEARCH_TYPES, USER_SET_OPTIONS } from '@/const/bar-const';
|
|
|
|
|
import { getImgUrl } from '@/utils';
|
|
|
|
|
|
|
|
|
|
const router = useRouter();
|
|
|
|
|
const store = useStore();
|
|
|
|
|
const userSetOptions = ref(USER_SET_OPTIONS);
|
|
|
|
|
|
|
|
|
|
// 推荐热搜词
|
|
|
|
|
const hotSearchKeyword = ref('搜索点什么吧...');
|
|
|
|
|
const hotSearchValue = ref('');
|
|
|
|
|
const loadHotSearchKeyword = async () => {
|
|
|
|
|
const { data } = await getSearchKeyword();
|
|
|
|
|
hotSearchKeyword.value = data.data.showKeyword;
|
|
|
|
|
hotSearchValue.value = data.data.realkeyword;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const loadPage = async () => {
|
|
|
|
|
const token = localStorage.getItem('token');
|
|
|
|
|
if (!token) return;
|
|
|
|
|
const { data } = await getUserDetail();
|
|
|
|
|
store.state.user = data.profile;
|
|
|
|
|
localStorage.setItem('user', JSON.stringify(data.profile));
|
|
|
|
|
};
|
|
|
|
|
|
2024-05-22 12:07:48 +08:00
|
|
|
loadPage();
|
|
|
|
|
|
2024-05-16 18:54:30 +08:00
|
|
|
watchEffect(() => {
|
|
|
|
|
if (store.state.user) {
|
|
|
|
|
userSetOptions.value = USER_SET_OPTIONS;
|
|
|
|
|
} else {
|
|
|
|
|
userSetOptions.value = USER_SET_OPTIONS.filter((item) => item.key !== 'logout');
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const toLogin = () => {
|
|
|
|
|
router.push('/login');
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 页面初始化
|
|
|
|
|
onMounted(() => {
|
|
|
|
|
loadHotSearchKeyword();
|
|
|
|
|
loadPage();
|
|
|
|
|
});
|
|
|
|
|
|
2024-12-28 16:43:52 +08:00
|
|
|
const isDarkTheme = computed({
|
|
|
|
|
get: () => store.state.theme === 'dark',
|
|
|
|
|
set: () => store.commit('toggleTheme'),
|
|
|
|
|
});
|
|
|
|
|
|
2024-05-16 18:54:30 +08:00
|
|
|
// 搜索词
|
|
|
|
|
const searchValue = ref('');
|
|
|
|
|
const search = () => {
|
|
|
|
|
const { value } = searchValue;
|
|
|
|
|
if (value === '') {
|
|
|
|
|
searchValue.value = hotSearchValue.value;
|
2024-05-22 19:20:57 +08:00
|
|
|
return;
|
2024-05-16 18:54:30 +08:00
|
|
|
}
|
2024-05-22 19:20:57 +08:00
|
|
|
|
2024-09-12 17:28:51 +08:00
|
|
|
if (router.currentRoute.value.path === '/search') {
|
|
|
|
|
store.state.searchValue = value;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-22 19:20:57 +08:00
|
|
|
router.push({
|
|
|
|
|
path: '/search',
|
|
|
|
|
query: {
|
|
|
|
|
keyword: value,
|
|
|
|
|
},
|
|
|
|
|
});
|
2024-05-16 18:54:30 +08:00
|
|
|
};
|
|
|
|
|
|
2024-05-21 10:16:30 +08:00
|
|
|
const selectSearchType = (key: number) => {
|
2024-09-12 17:28:51 +08:00
|
|
|
store.state.searchType = key;
|
2024-05-16 18:54:30 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const searchTypeOptions = ref(SEARCH_TYPES);
|
|
|
|
|
|
2024-05-21 10:16:30 +08:00
|
|
|
const selectItem = async (key: string) => {
|
2024-05-16 18:54:30 +08:00
|
|
|
// switch 判断
|
|
|
|
|
switch (key) {
|
|
|
|
|
case 'logout':
|
|
|
|
|
logout().then(() => {
|
|
|
|
|
store.state.user = null;
|
|
|
|
|
localStorage.clear();
|
2024-05-22 12:07:48 +08:00
|
|
|
router.push('/login');
|
2024-05-16 18:54:30 +08:00
|
|
|
});
|
|
|
|
|
break;
|
|
|
|
|
case 'login':
|
|
|
|
|
router.push('/login');
|
|
|
|
|
break;
|
|
|
|
|
case 'set':
|
|
|
|
|
router.push('/set');
|
|
|
|
|
break;
|
2024-12-27 18:27:01 +08:00
|
|
|
case 'user':
|
|
|
|
|
router.push('/user');
|
|
|
|
|
break;
|
2024-05-16 18:54:30 +08:00
|
|
|
default:
|
|
|
|
|
}
|
|
|
|
|
};
|
2024-12-05 21:57:14 +08:00
|
|
|
|
|
|
|
|
const toGithub = () => {
|
|
|
|
|
window.open('https://github.com/algerkong/AlgerMusicPlayer', '_blank');
|
|
|
|
|
};
|
2024-12-27 18:27:01 +08:00
|
|
|
|
|
|
|
|
const toGithubRelease = () => {
|
|
|
|
|
window.open('https://github.com/algerkong/AlgerMusicPlayer/releases', '_blank');
|
|
|
|
|
};
|
2024-05-16 18:54:30 +08:00
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
|
.user-box {
|
2024-12-28 16:43:52 +08:00
|
|
|
@apply ml-4 flex text-lg justify-center items-center rounded-full transition-colors duration-200;
|
|
|
|
|
@apply border dark:border-gray-600 border-gray-200 hover:border-gray-400 dark:hover:border-gray-400;
|
|
|
|
|
@apply bg-light dark:bg-gray-800;
|
2024-05-16 18:54:30 +08:00
|
|
|
}
|
2024-12-28 16:43:52 +08:00
|
|
|
|
2024-05-16 18:54:30 +08:00
|
|
|
.search-box {
|
|
|
|
|
@apply pb-4 pr-4;
|
|
|
|
|
}
|
2024-12-28 16:43:52 +08:00
|
|
|
|
2024-05-16 18:54:30 +08:00
|
|
|
.search-box-input {
|
|
|
|
|
@apply relative;
|
2024-12-28 16:43:52 +08:00
|
|
|
|
|
|
|
|
:deep(.n-input) {
|
|
|
|
|
@apply bg-gray-50 dark:bg-black;
|
|
|
|
|
|
|
|
|
|
.n-input__input-el {
|
|
|
|
|
@apply text-gray-900 dark:text-white;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.n-input__prefix {
|
|
|
|
|
@apply text-gray-500 dark:text-gray-400;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-16 18:54:30 +08:00
|
|
|
}
|
2024-05-23 17:12:35 +08:00
|
|
|
|
|
|
|
|
.mobile {
|
|
|
|
|
.search-box {
|
|
|
|
|
@apply pl-4;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-12-05 21:57:14 +08:00
|
|
|
|
|
|
|
|
.github {
|
2024-12-28 16:43:52 +08:00
|
|
|
@apply cursor-pointer text-gray-900 dark:text-gray-100 hover:text-gray-600 dark:hover:text-gray-400 text-xl ml-4 rounded-full flex justify-center items-center px-2 h-full;
|
|
|
|
|
@apply border dark:border-gray-600 border-gray-200 bg-light dark:bg-black;
|
2024-12-05 21:57:14 +08:00
|
|
|
}
|
2024-12-27 18:27:01 +08:00
|
|
|
|
|
|
|
|
.user-popover {
|
|
|
|
|
@apply min-w-[280px] p-0 rounded-xl overflow-hidden;
|
2024-12-28 16:43:52 +08:00
|
|
|
@apply bg-light dark:bg-black;
|
|
|
|
|
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
|
2024-12-27 18:27:01 +08:00
|
|
|
|
|
|
|
|
.user-header {
|
2024-12-28 16:43:52 +08:00
|
|
|
@apply flex items-center gap-2 p-3 cursor-pointer;
|
|
|
|
|
@apply border-b dark:border-gray-700 border-gray-100 hover:bg-gray-100 dark:hover:bg-gray-700;
|
2024-12-27 18:27:01 +08:00
|
|
|
|
|
|
|
|
.username {
|
2024-12-28 16:43:52 +08:00
|
|
|
@apply text-sm font-medium text-gray-900 dark:text-gray-200;
|
2024-12-27 18:27:01 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.menu-items {
|
|
|
|
|
@apply py-1;
|
|
|
|
|
|
|
|
|
|
.menu-item {
|
|
|
|
|
@apply flex items-center px-3 py-2 text-sm cursor-pointer;
|
2024-12-28 16:43:52 +08:00
|
|
|
@apply text-gray-700 dark:text-gray-300;
|
2024-12-27 18:27:01 +08:00
|
|
|
transition: background-color 0.2s;
|
|
|
|
|
|
|
|
|
|
&:hover {
|
2024-12-28 16:43:52 +08:00
|
|
|
@apply bg-gray-100 dark:bg-gray-700;
|
2024-12-27 18:27:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
i {
|
2024-12-28 16:43:52 +08:00
|
|
|
@apply mr-1 text-lg text-gray-500 dark:text-gray-400;
|
2024-12-27 18:27:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.download-btn {
|
2024-12-28 16:43:52 +08:00
|
|
|
@apply ml-auto text-xs px-2 py-0.5 rounded;
|
|
|
|
|
@apply bg-gray-100 dark:bg-gray-700 text-gray-600 dark:text-gray-300;
|
2024-12-27 18:27:01 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-16 18:54:30 +08:00
|
|
|
</style>
|