MyPic.vue 4.3 KB
Newer Older
1 2 3 4
<template>
	<div>
		<el-container>
			<el-main>
5 6 7
				<el-select v-model="picType" placeholder="请选择" @change="queryPic">
					<el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"></el-option>
				</el-select>
8 9 10 11 12
				<el-table border :data="picList" v-loading="loading">
					<el-table-column prop="id" label="序号" width="100" sortable></el-table-column>
					<el-table-column prop="picName" label="图片名字" width="240" show-overflow-tooltip></el-table-column>
					<el-table-column align="center">
						<template slot-scope="props">
13
							<img :src="props.row.picUrl" alt="图片" height="100px" @click="showImageDialog(props.row.picUrl, props.$index)" style="cursor: pointer" />
14 15 16 17 18 19 20 21
						</template>
					</el-table-column>
					<el-table-column label="创建时间" width="170">
						<template slot-scope="props">
							{{ props.row.createTime | dateFormat }}
						</template>
					</el-table-column>
				</el-table>
22
				<el-dialog :visible.sync="imageDialogVisible" width="30%">
23 24 25 26 27 28 29 30 31
					<div style="display: flex; align-items: center; justify-content: space-between">
						<button class="arrow-button" :class="{ disabled: imageIndex === 0 }" @click="showBeforeImage" :disabled="imageIndex === 0">
							<el-icon class="custom-icon" name="arrow-left"></el-icon>
						</button>
						<img :src="enlargedImageUrl" alt="放大图片" style="width: 80%" />
						<button class="arrow-button" :class="{ disabled: imageIndex === picList.length - 1 }" @click="showNextImage" :disabled="imageIndex === picList.length - 1">
							<el-icon class="custom-icon" name="arrow-right"></el-icon>
						</button>
					</div>
32
				</el-dialog>
33

34 35 36 37 38 39 40 41 42
				<el-pagination class="pagination" background :key="elementui_page_component_key" :current-page.sync="currentPage" :page-size="pageSize" :total="total" @current-change="handleCurrentChange"></el-pagination>
			</el-main>
		</el-container>
	</div>
</template>

<script>
import axios from 'axios'
export default {
43 44 45 46 47 48 49 50 51 52 53 54
	name: 'MyPic',
	data() {
		return {
			// 用户列表数据
			picList: [],
			loading: false,
			elementui_page_component_key: 0,
			currentPage: 1,
			pageSize: 6,
			total: 0,
			imageDialogVisible: false,
			enlargedImageUrl: '',
55
			imageIndex: 0, // 当前展示的图片索引
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
			options: [
				{
					value: 0,
					label: '宝宝照片',
				},
				{
					value: 1,
					label: '学习照片',
				},
				{
					value: 2,
					label: '风景照片',
				},
				{
					value: 3,
					label: '美女照片',
				},
				{
					value: 99,
					label: '其他照片',
				},
			],
			picType: 0,
		}
	},
	created() {
		// 调用请求数据的方法
		this.queryPic()
	},
	methods: {
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
		showBeforeImage() {
			if (this.imageIndex > 0) {
				// 增加索引以显示下一张图片
				this.imageIndex--
				this.enlargedImageUrl = this.picList[this.imageIndex].picUrl
				this.imageDialogVisible = true // 打开对话框展示图片
			}
		},
		showNextImage() {
			if (this.imageIndex < this.picList.length - 1) {
				// 增加索引以显示下一张图片
				this.imageIndex++
				this.enlargedImageUrl = this.picList[this.imageIndex].picUrl
				this.imageDialogVisible = true
			}
		},
		showImageDialog(url, index) {
103 104
			this.enlargedImageUrl = url
			this.imageDialogVisible = true
105
			this.imageIndex = index
106 107 108
		},
		async queryPic() {
			this.loading = true
109
			const { data: res } = await axios.get('http://localhost:8888/picInfo/page', {
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
				params: {
					page: this.currentPage,
					pageSize: this.pageSize,
					picType: this.picType,
				},
			})
			if (res.code === 200) {
				this.picList = res.result.records
				this.total = res.result.total
			}
			this.loading = false
		},
		handleCurrentChange(currentPage) {
			this.currentPage = currentPage
			this.queryPic()
		},
	},
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
}
</script>

<style lang="less" scoped>
.el-header {
	background-color: #b3c0d1;
	color: #333;
	line-height: 60px;
}

.el-aside {
	color: #333;
}

.pagination {
	margin-top: 16px;
	text-align: right;
}
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164

.arrow-button {
	display: flex;
	align-items: center;
	justify-content: center;
	border: none;
	background-color: transparent;
	cursor: pointer;
}

.custom-icon {
	font-size: 24px; /* 调整图标大小 */
	color: #ff9900; /* 调整图标颜色 */
	margin-right: 6px; /* 调整图标与文字之间的间距 */
}

.arrow-button.disabled {
	pointer-events: none; /* 禁用点击事件 */
	opacity: 0.1; /* 添加透明度来表示禁用状态 */
}
165
</style>