Optimized photo wall and other details.

hikari
PeterAlbus 1 year ago
parent 57957da06b
commit 02c0307a0e

1
components.d.ts vendored

@ -37,6 +37,7 @@ declare module '@vue/runtime-core' {
MessageBox: typeof import('./src/components/MessageBox.vue')['default'] MessageBox: typeof import('./src/components/MessageBox.vue')['default']
MusicPlayer: typeof import('./src/components/MusicPlayer.vue')['default'] MusicPlayer: typeof import('./src/components/MusicPlayer.vue')['default']
PersonalInfo: typeof import('./src/components/PersonalInfo.vue')['default'] PersonalInfo: typeof import('./src/components/PersonalInfo.vue')['default']
PhotoItem: typeof import('./src/components/PhotoItem.vue')['default']
RouterLink: typeof import('vue-router')['RouterLink'] RouterLink: typeof import('vue-router')['RouterLink']
RouterView: typeof import('vue-router')['RouterView'] RouterView: typeof import('vue-router')['RouterView']
TopNavBar: typeof import('./src/components/TopNavBar.vue')['default'] TopNavBar: typeof import('./src/components/TopNavBar.vue')['default']

@ -1,5 +1,5 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="zh">
<head> <head>
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<link rel="icon" href="/favicon.ico" /> <link rel="icon" href="/favicon.ico" />

@ -106,6 +106,21 @@ a {
padding: 10px; padding: 10px;
} }
.blog-description .blog-description-title {
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: start;
}
.blog-description .blog-description-title.title-text {
white-space: nowrap;
display: inline-block;
max-width: calc(100% - 65px);
overflow: hidden;
text-overflow: ellipsis;
}
.info { .info {
height: 20px; height: 20px;
} }

@ -0,0 +1,107 @@
<template>
<div class="photo-item">
<div class="photo-delete-button"
v-if="userStore.userId"
@click="deletePhoto">
删除
</div>
<el-image :src="imgThumb"
:alt="imgName"
style="width: 100%"
:preview-src-list="[imgSrc]"
:hide-on-click-modal="true"
fit="cover" lazy>
<template #placeholder>
<div class="image-slot">
加载中<span class="dot">...</span>
</div>
</template>
</el-image>
<span class="paragraph">{{imgName}}</span>
</div>
</template>
<script setup lang="ts">
import { useUserStore } from "@/stores/user";
import { ElMessage, ElMessageBox } from "element-plus";
import { deletePhotoById } from "@/services/photoApi";
const userStore = useUserStore();
const props = defineProps({
imgId: {
type: String,
default() {
return ''
},
},
imgThumb: {
type: String,
default() {
return ''
},
},
imgSrc: {
type: String,
default() {
return ''
},
},
imgName: {
type: String,
default() {
return ''
},
}
});
const emits = defineEmits(['deletePhoto']);
const deletePhoto = () => {
ElMessageBox.confirm(
'确认删除这张图片吗?',
'警告',
{
confirmButtonText: '确认',
cancelButtonText: '取消',
type: 'warning',
}
)
.then(() => {
deletePhotoById(props.imgId.toString()).then(() => {
ElMessage({
type: 'success',
message: "删除成功!",
})
emits('deletePhoto')
})
})
.catch()
}
</script>
<style scoped>
.photo-item {
position: relative;
}
.photo-item .photo-delete-button {
position: absolute;
right: 5px;
bottom: 3px;
width: 30px;
height: 20px;
z-index: 2;
display: none;
cursor: pointer;
background: red;
border-radius: 4px;
color: white;
font-size: 12px;
}
.photo-item:hover .photo-delete-button {
display: flex;
justify-content: center;
align-items: center;
}
</style>

@ -42,7 +42,9 @@
<el-col :span="16"> <el-col :span="16">
<div class="blog-description"> <div class="blog-description">
<router-link :to="{ path: '/blog',query:{id:item.blogId}}"> <router-link :to="{ path: '/blog',query:{id:item.blogId}}">
<h4>{{ item.blogTitle }}&emsp;<el-tag size="small">{{ getType(item.blogType) }}</el-tag> <h4 class="blog-description-title">
<span class="title-text">{{item.blogTitle}}&emsp;</span>
<el-tag size="small">{{getType(item.blogType)}}</el-tag>
</h4> </h4>
</router-link> </router-link>
<p style="height: 110px">{{ item.blogDescription }}</p> <p style="height: 110px">{{ item.blogDescription }}</p>
@ -67,8 +69,9 @@
<el-col :span="16"> <el-col :span="16">
<div class="blog-description"> <div class="blog-description">
<router-link :to="{ path: '/blog',query:{id:item.blogId}}"> <router-link :to="{ path: '/blog',query:{id:item.blogId}}">
<h4 style="height: 40px"><span style="white-space: nowrap">{{ item.blogTitle }}&emsp;</span> <h4 style="height: 40px" class="blog-description-title">
<el-tag size="small">{{ getType(item.blogType) }}</el-tag> <span class="title-text">{{item.blogTitle}}&emsp;</span>
<el-tag size="small">{{getType(item.blogType)}}</el-tag>
</h4> </h4>
</router-link> </router-link>
<p style="height: 90px;overflow: hidden">{{ item.blogDescription }}</p> <p style="height: 90px;overflow: hidden">{{ item.blogDescription }}</p>

@ -12,6 +12,7 @@
:boxShadow="false" :subfield="false" :boxShadow="false" :subfield="false"
defaultOpen="preview" :editable="false" defaultOpen="preview" :editable="false"
codeStyle="xcode" :toolbarsFlag="false" codeStyle="xcode" :toolbarsFlag="false"
:toolbars="{}" :shortCut="false"
/> />
</div> </div>
</el-col> </el-col>

@ -12,6 +12,7 @@
:boxShadow="false" :subfield="false" :boxShadow="false" :subfield="false"
defaultOpen="preview" :editable="false" defaultOpen="preview" :editable="false"
codeStyle="xcode" :toolbarsFlag="false" codeStyle="xcode" :toolbarsFlag="false"
:toolbars="{}" :shortCut="false"
/> />
</div> </div>
</el-col> </el-col>

@ -22,6 +22,8 @@
<Plus /> <Plus />
</el-icon> </el-icon>
</el-upload> </el-upload>
&emsp;
<el-button type="danger" v-if="imageUrl" @click="deleteBlogAvatarFile"></el-button>
</el-form-item> </el-form-item>
<el-form-item label="作者:" prop="blogAuthor"> <el-form-item label="作者:" prop="blogAuthor">
<el-input v-model="blog.blogAuthor" placeholder="作者" :prefix-icon="User"></el-input> <el-input v-model="blog.blogAuthor" placeholder="作者" :prefix-icon="User"></el-input>
@ -175,6 +177,10 @@ const beforeAvatarUpload = (file: UploadRawFile) => {
if (!isLt2M) { if (!isLt2M) {
ElMessage.error("图片大小不能超过2M"); ElMessage.error("图片大小不能超过2M");
} }
if(isIMG && isLt2M && imageUrl.value) {
deleteBlogAvatarFile()
}
return isIMG && isLt2M; return isIMG && isLt2M;
}; };
@ -194,6 +200,11 @@ const deleteImage = (info:any) => {
}) })
} }
const deleteBlogAvatarFile = () => {
deletePhotoByUrl(imageUrl.value)
imageUrl.value = ""
}
const onSubmit = async (formEl: FormInstance | undefined) => { const onSubmit = async (formEl: FormInstance | undefined) => {
if (!formEl) return; if (!formEl) return;
await formEl.validate((valid, fields) => { await formEl.validate((valid, fields) => {
@ -221,25 +232,6 @@ onMounted(() => {
</script> </script>
<style scoped> <style scoped>
.banner {
position: relative;
top: 0;
left: 0;
right: 0;
height: 30vh;
background: url("../assets/background.jpg") fixed center center;
text-align: center;
color: #fff !important;
}
.banner-container {
position: absolute;
width: 100%;
margin-top: 13vh;
line-height: 1.5;
color: #eee;
}
.blog-content { .blog-content {
text-align: left; text-align: left;
} }

@ -33,7 +33,10 @@
<el-col :span="16"> <el-col :span="16">
<div class="blog-description"> <div class="blog-description">
<router-link :to="{ path: '/blog',query:{id:item.blogId}}"> <router-link :to="{ path: '/blog',query:{id:item.blogId}}">
<h4 style="height: 40px"><span style="white-space: nowrap">{{item.blogTitle}}&emsp;</span><el-tag size="small">{{getType(item.blogType)}}</el-tag></h4> <h4 style="height: 40px" class="blog-description-title">
<span class="title-text">{{item.blogTitle}}&emsp;</span>
<el-tag size="small">{{getType(item.blogType)}}</el-tag>
</h4>
</router-link> </router-link>
<p style="height: 90px;overflow: hidden">{{item.blogDescription}}</p> <p style="height: 90px;overflow: hidden">{{item.blogDescription}}</p>
<p class="info"> <p class="info">

@ -9,48 +9,30 @@
<el-card class="photo" <el-card class="photo"
v-for="item in photoLeft" :key="item.imgId" v-for="item in photoLeft" :key="item.imgId"
shadow="hover" :body-style="{ padding: '0px' }"> shadow="hover" :body-style="{ padding: '0px' }">
<a :href="item.imgSrc" target="_blank"> <PhotoItem :imgName="item.imgName" :imgId="item.imgId.toString()"
<el-image :src="item.imgThumb" style="width: 100%" fit="cover" lazy> :imgSrc="item.imgSrc" :imgThumb="item.imgThumb"
<template #placeholder> @deletePhoto="getPhotoList"
<div class="image-slot"> ></PhotoItem>
加载中<span class="dot">...</span>
</div>
</template>
</el-image>
<span class="paragraph">{{item.imgName}}</span>
</a>
</el-card> </el-card>
</el-col> </el-col>
<el-col :span="7" :offset="1"> <el-col :span="7" :offset="1">
<el-card class="photo" <el-card class="photo"
v-for="item in photoMid" :key="item.imgId" v-for="item in photoMid" :key="item.imgId"
shadow="hover" :body-style="{ padding: '0px' }"> shadow="hover" :body-style="{ padding: '0px' }">
<a :href="item.imgSrc" target="_blank"> <PhotoItem :imgName="item.imgName" :imgId="item.imgId.toString()"
<el-image :src="item.imgThumb" style="width: 100%" fit="cover" lazy> :imgSrc="item.imgSrc" :imgThumb="item.imgThumb"
<template #placeholder> @deletePhoto="getPhotoList"
<div class="image-slot"> ></PhotoItem>
加载中<span class="dot">...</span>
</div>
</template>
</el-image>
<span class="paragraph">{{item.imgName}}</span>
</a>
</el-card> </el-card>
</el-col> </el-col>
<el-col :span="7" :offset="1"> <el-col :span="7" :offset="1">
<el-card class="photo" <el-card class="photo"
v-for="item in photoRight" :key="item.imgId" v-for="item in photoRight" :key="item.imgId"
shadow="hover" :body-style="{ padding: '0px' }"> shadow="hover" :body-style="{ padding: '0px' }">
<a :href="item.imgSrc" target="_blank"> <PhotoItem :imgName="item.imgName" :imgId="item.imgId.toString()"
<el-image :src="item.imgThumb" style="width: 100%" fit="cover" lazy> :imgSrc="item.imgSrc" :imgThumb="item.imgThumb"
<template #placeholder> @deletePhoto="getPhotoList"
<div class="image-slot"> ></PhotoItem>
加载中<span class="dot">...</span>
</div>
</template>
</el-image>
<span class="paragraph">{{item.imgName}}</span>
</a>
</el-card> </el-card>
</el-col> </el-col>
</el-row> </el-row>
@ -70,6 +52,7 @@
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 Banner from '@/components/Banner.vue' import Banner from '@/components/Banner.vue'
import PhotoItem from "@/components/PhotoItem.vue";
import { computed, onMounted, Ref, ref } from "vue"; import { computed, onMounted, Ref, ref } from "vue";
import { fetchPhotoList } from "@/services/photoApi"; import { fetchPhotoList } from "@/services/photoApi";

@ -67,15 +67,15 @@ const onFileChange = (file: UploadFile, fileList: UploadFile[]) => {
const beforeAvatarUpload = (file: UploadRawFile) => { const beforeAvatarUpload = (file: UploadRawFile) => {
const isIMG = file.type === "image/jpeg" || file.type === "image/png" || file.type === "image/gif"; const isIMG = file.type === "image/jpeg" || file.type === "image/png" || file.type === "image/gif";
const isLt10M = file.size / 1024 / 1024 < 10; const isLt50M = file.size / 1024 / 1024 < 50;
if (!isIMG) { if (!isIMG) {
ElMessage.error("选择的文件不是图片!"); ElMessage.error("选择的文件不是图片!");
} }
if (!isLt10M) { if (!isLt50M) {
ElMessage.error("图片大小不能超过10M"); ElMessage.error("图片大小不能超过50M");
} }
return isIMG && isLt10M; return isIMG && isLt50M;
}; };
const upData = computed(() => { const upData = computed(() => {

@ -155,7 +155,7 @@ import {
ElMessageBox, ElMessageBox,
ElUpload ElUpload
} from "element-plus"; } from "element-plus";
import type { FormInstance, UploadFile, UploadProgressEvent, UploadRawFile } from "element-plus"; import type { FormInstance, UploadRawFile } from "element-plus";
import { useUserStore } from "@/stores/user"; import { useUserStore } from "@/stores/user";
import { computed, reactive, ref } from "vue"; import { computed, reactive, ref } from "vue";
import { import {

Loading…
Cancel
Save