吴雨瞳添加了注释

master
wyt 4 months ago
parent 2510f7a58a
commit 8a19cb6bf9

@ -1,52 +1,73 @@
<template>
<el-card class="main-card">
<!-- 页面标题使用当前路由名称 -->
<div class="title">{{ this.$route.name }}</div>
<!-- 操作区域包含全选功能和批量操作按钮 -->
<div class="operation">
<div class="all-check">
<!-- 全选复选框indeterminate表示半选状态 -->
<el-checkbox :indeterminate="isIndeterminate" v-model="checkAll" @change="handleCheckAllChange">
全选
</el-checkbox>
<!-- 显示已选择的照片数量 -->
<div class="check-count">已选择{{ selectPhotoIds.length }}</div>
</div>
<!-- 批量恢复按钮将选中照片从回收站恢复选择为空时禁用 -->
<el-button
type="success"
@click="updatePhotoDelete(null)"
:disabled="selectPhotoIds.length == 0"
size="small"
icon="el-icon-deleteItem">
type="success"
@click="updatePhotoDelete(null)"
:disabled="selectPhotoIds.length == 0"
size="small"
icon="el-icon-deleteItem">
批量恢复
</el-button>
<!-- 批量删除按钮彻底删除选中照片选择为空时禁用 -->
<el-button
type="danger"
@click="batchDeletePhoto = true"
:disabled="selectPhotoIds.length == 0"
size="small"
icon="el-icon-deleteItem">
type="danger"
@click="batchDeletePhoto = true"
:disabled="selectPhotoIds.length == 0"
size="small"
icon="el-icon-deleteItem">
批量删除
</el-button>
</div>
<!-- 照片列表容器加载状态时显示loading -->
<el-row class="photo-container" :gutter="10" v-loading="loading">
<!-- 当回收站为空时显示空状态 -->
<el-empty v-if="photos.length == 0" description="暂无照片" />
<!-- 复选框组用于选择照片进行批量操作 -->
<el-checkbox-group v-model="selectPhotoIds" @change="handleCheckedPhotoChange">
<!-- 遍历照片列表生成照片项 -->
<el-col :md="4" v-for="item of photos" :key="item.id">
<el-checkbox :label="item.id">
<div class="photo-item">
<!-- 照片显示支持预览 -->
<el-image fit="cover" class="photo-img" :src="item.photoSrc" :preview-photoSrc-list="photos" />
<!-- 照片名称 -->
<div class="photo-name">{{ item.photoName }}</div>
</div>
</el-checkbox>
</el-col>
</el-checkbox-group>
</el-row>
<!-- 分页组件 -->
<el-pagination
:hide-on-single-page="true"
class="pagination-container"
@size-change="sizeChange"
@current-change="currentChange"
:current-page="current"
:page-size="size"
:total="count"
layout="prev, pager, next" />
:hide-on-single-page="true"
class="pagination-container"
@size-change="sizeChange"
@current-change="currentChange"
:current-page="current"
:page-size="size"
:total="count"
layout="prev, pager, next" />
<!-- 批量删除确认弹窗 -->
<el-dialog :visible.sync="batchDeletePhoto" width="30%">
<div class="dialog-title-container" slot="title"><i class="el-icon-warning" style="color: #ff9900" />提示</div>
<div style="font-size: 1rem">是否删除选中照片</div>
@ -60,97 +81,115 @@
<script>
export default {
//
created() {
this.listPhotos()
},
data: function () {
return {
loading: true,
batchDeletePhoto: false,
isIndeterminate: false,
checkAll: false,
photos: [],
photoIds: [],
selectPhotoIds: [],
current: 1,
size: 18,
count: 0
loading: true, //
batchDeletePhoto: false, //
isIndeterminate: false, //
checkAll: false, //
photos: [], //
photoIds: [], // ID
selectPhotoIds: [], // ID
current: 1, //
size: 18, //
count: 0 //
}
},
methods: {
//
listPhotos() {
this.axios
.get('/api/admin/photos', {
params: {
current: this.current,
size: this.size,
isDelete: 1
}
})
.then(({ data }) => {
this.photos = data.data.records
this.count = data.data.count
this.loading = false
})
.get('/api/admin/photos', {
params: {
current: this.current, //
size: this.size, //
isDelete: 1 // 1
}
})
.then(({ data }) => {
this.photos = data.data.records //
this.count = data.data.count //
this.loading = false //
})
},
//
sizeChange(size) {
this.size = size
this.listPhotos()
this.listPhotos() //
},
//
currentChange(current) {
this.current = current
this.listPhotos()
this.listPhotos() //
},
//
updatePhotoDelete(id) {
var param = {}
if (id == null) {
param = { ids: this.selectPhotoIds, isDelete: 0 }
// 使ID
param = { ids: this.selectPhotoIds, isDelete: 0 } // isDelete=0
} else {
// 使ID
param = { ids: [id], isDelete: 0 }
}
this.axios.put('/api/admin/photos/delete', param).then(({ data }) => {
if (data.flag) {
//
this.$notify.success({
title: '成功',
message: data.message
})
this.listPhotos()
this.listPhotos() //
} else {
//
this.$notify.error({
title: '失败',
message: data.message
})
}
})
this.batchDeletePhoto = false
this.batchDeletePhoto = false //
},
//
deletePhotos() {
this.axios.delete('/api/admin/photos', { data: this.selectPhotoIds }).then(({ data }) => {
if (data.flag) {
//
this.$notify.success({
title: '成功',
message: data.message
})
this.listPhotos()
this.listPhotos() //
} else {
//
this.$notify.error({
title: '失败',
message: data.message
})
}
})
this.batchDeletePhoto = false
this.batchDeletePhoto = false //
},
// /
handleCheckAllChange(val) {
// ID
this.selectPhotoIds = val ? this.photoIds : []
this.isIndeterminate = false
this.isIndeterminate = false //
},
//
handleCheckedPhotoChange(value) {
let checkedCount = value.length
const checkedCount = value.length
//
this.checkAll = checkedCount === this.photoIds.length
// 0
this.isIndeterminate = checkedCount > 0 && checkedCount < this.photoIds.length
}
},
// photosID
watch: {
photos() {
this.photoIds = []
@ -163,34 +202,40 @@ export default {
</script>
<style scoped>
/* 操作区域样式 */
.operation {
display: flex;
justify-content: flex-end;
margin-top: 2.25rem;
margin-bottom: 2rem;
}
/* 全选区域样式 */
.all-check {
display: inline-flex;
align-items: center;
margin-right: 1rem;
}
/* 已选数量样式 */
.check-count {
margin-left: 1rem;
font-size: 12px;
}
/* 照片项样式 */
.photo-item {
position: relative;
cursor: pointer;
margin-bottom: 1rem;
}
/* 照片图片样式 */
.photo-img {
width: 100%;
height: 7rem;
border-radius: 4px;
}
/* 照片名称样式 */
.photo-name {
font-size: 14px;
margin-top: 0.3rem;
text-align: center;
}
</style>
</style>
Loading…
Cancel
Save