Move background to database.

hikari
PeterAlbus 12 months ago
parent 970e560e74
commit 5a0d9f088a

@ -0,0 +1,10 @@
/**
* @description
* @author PeterAlbus
* @time 2023-08-15
*/
import http from './httpConfig';
import { backgroundUrl } from "@/services/urlConfig";
export const fetchBackgroundList = () => http.get({},backgroundUrl.getBackgroundList);

@ -4,7 +4,11 @@ import qs from "qs";
import { ElMessage } from "element-plus"; import { ElMessage } from "element-plus";
import { BASE_URL } from "@/services/urlConfig"; import { BASE_URL } from "@/services/urlConfig";
export interface HttpResult {
code: number;
message: string;
data: any;
}
// 可能需要自定义添加些配置 // 可能需要自定义添加些配置
// interface AxiosRequestConfig extends _AxiosRequestConfig {} // interface AxiosRequestConfig extends _AxiosRequestConfig {}
// interface AxiosResponse extends _AxiosResponse { } // interface AxiosResponse extends _AxiosResponse { }

@ -74,3 +74,9 @@ export const messageUrl:any = {
getUnreadMessageCount: "/message/getUnreadMessageCount", getUnreadMessageCount: "/message/getUnreadMessageCount",
readMessage: "/message/readMessage" readMessage: "/message/readMessage"
} }
export const backgroundUrl:any = {
getBackgroundList: "/background/queryAll",
addBackground: "/background/add",
deleteBackground: "/background/delete",
}

@ -1,5 +1,5 @@
<template> <template>
<div class="home-banner" :style="{background:'url('+backgrounds[randomIndex]+') fixed center center',backgroundSize:'cover',OBackgroundSize:'cover',MozBackgroundSize:'cover'}"> <div class="home-banner" :style="backgroundStyle">
<div class="banner-container"> <div class="banner-container">
<div> <div>
<el-avatar :size="150" src="https://file.peteralbus.com/assets/blog/imgs/blog_avatar.png"></el-avatar> <el-avatar :size="150" src="https://file.peteralbus.com/assets/blog/imgs/blog_avatar.png"></el-avatar>
@ -103,6 +103,8 @@ import {ElMessage} from "element-plus";
import FriendLinks from "@/components/FriendLinks.vue" import FriendLinks from "@/components/FriendLinks.vue"
import PersonalInfo from "@/components/PersonalInfo.vue" import PersonalInfo from "@/components/PersonalInfo.vue"
import { fetchBlogList } from "@/services/blogApi"; import { fetchBlogList } from "@/services/blogApi";
import { fetchBackgroundList } from "@/services/backgroundApi";
import { HttpResult } from "@/services/httpConfig";
const blogList = ref([ const blogList = ref([
{ {
@ -152,21 +154,38 @@ const copyQuotes=()=>{
ElMessage.success("复制成功!点击右键可换一句") ElMessage.success("复制成功!点击右键可换一句")
} }
const backgrounds=[ const backgrounds=ref([
'https://file.peteralbus.com/assets/blog/static/background/background-lumine.jpg', {
// 'https://file.peteralbus.com/assets/blog/static/background/background-kazuha.jpg', url:'',
// 'https://file.peteralbus.com/assets/blog/static/background/background-blueeyes.jpg', description:'无'
'https://file.peteralbus.com/assets/blog/static/background/background-girl1.jpg', }
// 'https://file.peteralbus.com/assets/blog/static/background/background-mountain1.jpg', ])
'https://file.peteralbus.com/assets/blog/static/background/background-nogamenolife.jpg',
// 'https://file.peteralbus.com/assets/blog/static/background/background-ai1.jpg', const getBackgrounds = () => {
// 'https://file.peteralbus.com/assets/blog/static/background/background-ai2.jpg', fetchBackgroundList().then((res:HttpResult) => {
'https://file.peteralbus.com/assets/blog/static/background/background_ygo_1_1440p.jpg', backgrounds.value = []
'https://file.peteralbus.com/assets/blog/static/background/background_1440pba.jpg', res.data.map((item: any) => {
'https://file.peteralbus.com/assets/blog/static/background/background_1440psekiro.jpg', if (item.isShow) {
] backgrounds.value.push({
url: item.backgroundUrl,
const randomIndex=Math.floor(Math.random()*backgrounds.length) description: item.description
})
}
})
randomIndex.value=Math.floor(Math.random()*backgrounds.value.length)
})
}
const backgroundStyle = computed(() => {
return {
backgroundImage: `url(${backgrounds.value[randomIndex.value].url})`,
backgroundSize: 'cover',
OBackgroundSize: 'cover',
MozBackgroundSize: 'cover'
}
})
const randomIndex=ref(Math.floor(Math.random()*backgrounds.value.length))
// const randomIndex=4 // const randomIndex=4
const getBlogList=function () { const getBlogList=function () {
@ -176,6 +195,7 @@ const getBlogList=function () {
} }
onMounted(()=>{ onMounted(()=>{
getBackgrounds()
getBlogList() getBlogList()
getQuotes() getQuotes()
}) })
@ -191,7 +211,8 @@ const topBlogs=computed(()=>{
}) })
const recentBlogs = computed (function () { const recentBlogs = computed (function () {
const recentBlogs = blogList.value.reverse(); const blogListCopy = blogList.value;
const recentBlogs = blogListCopy.reverse();
return recentBlogs.slice(0, 10); return recentBlogs.slice(0, 10);
}) })

Loading…
Cancel
Save