501 lines
14 KiB
HTML
501 lines
14 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="zh-CN">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
|
<title>图片上传 - 图片收集小程序</title>
|
|
<!-- 引入Vue.js -->
|
|
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.min.js"></script>
|
|
<!-- 引入Element UI CSS -->
|
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/element-ui@2.15.8/lib/theme-chalk/index.css">
|
|
<!-- 引入Element UI JavaScript -->
|
|
<script src="https://cdn.jsdelivr.net/npm/element-ui@2.15.8/lib/index.js"></script>
|
|
<!-- 引入Font Awesome -->
|
|
<link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
|
|
<style>
|
|
body {
|
|
margin: 0;
|
|
padding: 0;
|
|
height: 100vh;
|
|
background-color: #f5f7fa;
|
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
|
|
padding-top: env(safe-area-inset-top);
|
|
overflow-x: hidden;
|
|
}
|
|
.container {
|
|
height: 100vh;
|
|
display: flex;
|
|
flex-direction: column;
|
|
}
|
|
.header {
|
|
background-color: #1989fa;
|
|
color: white;
|
|
padding: 15px;
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
position: sticky;
|
|
top: 0;
|
|
z-index: 100;
|
|
}
|
|
.header-title {
|
|
font-size: 18px;
|
|
font-weight: bold;
|
|
}
|
|
.header-action {
|
|
font-size: 16px;
|
|
}
|
|
.content {
|
|
flex: 1;
|
|
padding: 15px;
|
|
overflow-y: auto;
|
|
}
|
|
.card {
|
|
background-color: white;
|
|
border-radius: 8px;
|
|
padding: 15px;
|
|
margin-bottom: 15px;
|
|
box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.05);
|
|
}
|
|
.upload-area {
|
|
border: 2px dashed #dcdfe6;
|
|
border-radius: 8px;
|
|
padding: 30px;
|
|
text-align: center;
|
|
cursor: pointer;
|
|
transition: all 0.3s;
|
|
background-color: #fafafa;
|
|
}
|
|
.upload-area:hover {
|
|
border-color: #1989fa;
|
|
background-color: #ecf5ff;
|
|
}
|
|
.upload-icon {
|
|
font-size: 48px;
|
|
color: #dcdfe6;
|
|
margin-bottom: 10px;
|
|
}
|
|
.upload-text {
|
|
font-size: 16px;
|
|
color: #606266;
|
|
margin-bottom: 5px;
|
|
}
|
|
.upload-hint {
|
|
font-size: 12px;
|
|
color: #909399;
|
|
}
|
|
.preview-list {
|
|
display: grid;
|
|
grid-template-columns: repeat(3, 1fr);
|
|
gap: 10px;
|
|
margin-top: 15px;
|
|
}
|
|
.preview-item {
|
|
position: relative;
|
|
border-radius: 8px;
|
|
overflow: hidden;
|
|
padding-bottom: 100%;
|
|
background-color: #f5f7fa;
|
|
}
|
|
.preview-item img {
|
|
position: absolute;
|
|
top: 0;
|
|
left: 0;
|
|
width: 100%;
|
|
height: 100%;
|
|
object-fit: cover;
|
|
}
|
|
.delete-btn {
|
|
position: absolute;
|
|
top: 5px;
|
|
right: 5px;
|
|
background-color: rgba(0, 0, 0, 0.5);
|
|
color: white;
|
|
border: none;
|
|
border-radius: 50%;
|
|
width: 20px;
|
|
height: 20px;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
font-size: 12px;
|
|
}
|
|
.progress-container {
|
|
position: absolute;
|
|
bottom: 0;
|
|
left: 0;
|
|
right: 0;
|
|
background-color: rgba(0, 0, 0, 0.5);
|
|
padding: 5px;
|
|
}
|
|
.progress-bar {
|
|
height: 4px;
|
|
background-color: rgba(255, 255, 255, 0.3);
|
|
border-radius: 2px;
|
|
overflow: hidden;
|
|
}
|
|
.progress-fill {
|
|
height: 100%;
|
|
background-color: #1989fa;
|
|
transition: width 0.3s;
|
|
}
|
|
.form-item {
|
|
margin-bottom: 20px;
|
|
}
|
|
.form-label {
|
|
font-size: 14px;
|
|
font-weight: 500;
|
|
color: #303133;
|
|
margin-bottom: 8px;
|
|
}
|
|
.tag-list {
|
|
display: flex;
|
|
flex-wrap: wrap;
|
|
gap: 8px;
|
|
margin-top: 8px;
|
|
}
|
|
.tag {
|
|
padding: 4px 12px;
|
|
border-radius: 12px;
|
|
font-size: 12px;
|
|
cursor: pointer;
|
|
transition: all 0.3s;
|
|
}
|
|
.tag-default {
|
|
background-color: #f0f2f5;
|
|
color: #606266;
|
|
}
|
|
.tag-selected {
|
|
background-color: #ecf5ff;
|
|
color: #1989fa;
|
|
border-color: #1989fa;
|
|
border: 1px solid;
|
|
}
|
|
.submit-btn {
|
|
width: 100%;
|
|
margin-top: 20px;
|
|
}
|
|
.department-info {
|
|
display: flex;
|
|
align-items: center;
|
|
padding: 10px;
|
|
background-color: #f0f9eb;
|
|
border-radius: 4px;
|
|
font-size: 14px;
|
|
}
|
|
.department-icon {
|
|
font-size: 16px;
|
|
color: #67c23a;
|
|
margin-right: 8px;
|
|
}
|
|
.textarea-container {
|
|
position: relative;
|
|
}
|
|
.char-count {
|
|
position: absolute;
|
|
bottom: 5px;
|
|
right: 10px;
|
|
font-size: 12px;
|
|
color: #909399;
|
|
}
|
|
input[type="file"] {
|
|
display: none;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div id="app">
|
|
<div class="container">
|
|
<!-- 顶部导航栏 -->
|
|
<div class="header">
|
|
<div class="header-action" @click="goBack">取消</div>
|
|
<div class="header-title">图片上传</div>
|
|
<div class="header-action" @click="handleSubmit">保存</div>
|
|
</div>
|
|
|
|
<!-- 主内容区 -->
|
|
<div class="content">
|
|
<!-- 图片选择区域 -->
|
|
<div class="card">
|
|
<div class="form-label">选择图片</div>
|
|
<label for="file-upload" class="upload-area">
|
|
<i class="fa fa-cloud-upload upload-icon"></i>
|
|
<div class="upload-text">点击或拖拽上传</div>
|
|
<div class="upload-hint">支持JPG、PNG格式,单张不超过2MB</div>
|
|
<input
|
|
type="file"
|
|
id="file-upload"
|
|
accept="image/*"
|
|
multiple
|
|
@change="handleFileSelect"
|
|
>
|
|
</label>
|
|
|
|
<!-- 已选择图片预览 -->
|
|
<div v-if="selectedImages.length > 0" class="preview-list">
|
|
<div
|
|
v-for="(image, index) in selectedImages"
|
|
:key="index"
|
|
class="preview-item"
|
|
>
|
|
<img :src="image.url" :alt="'预览图 ' + (index + 1)">
|
|
<button class="delete-btn" @click="removeImage(index)">
|
|
<i class="fa fa-times"></i>
|
|
</button>
|
|
<div v-if="image.uploading" class="progress-container">
|
|
<div class="progress-bar">
|
|
<div class="progress-fill" :style="{ width: image.progress + '%' }"></div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- 图片信息表单 -->
|
|
<div class="card">
|
|
<div class="form-label">图片信息</div>
|
|
|
|
<!-- 所属部门显示 -->
|
|
<div class="department-info mb-4">
|
|
<i class="fa fa-building department-icon"></i>
|
|
<span>所属部门:{{ currentDepartment }}</span>
|
|
</div>
|
|
|
|
<!-- 标题输入框 -->
|
|
<div class="form-item">
|
|
<div class="form-label">标题</div>
|
|
<el-input
|
|
v-model="imageForm.title"
|
|
placeholder="请输入图片标题"
|
|
maxlength="50"
|
|
show-word-limit
|
|
></el-input>
|
|
</div>
|
|
|
|
<!-- 描述文本域 -->
|
|
<div class="form-item">
|
|
<div class="form-label">描述</div>
|
|
<div class="textarea-container">
|
|
<el-input
|
|
v-model="imageForm.description"
|
|
type="textarea"
|
|
:rows="3"
|
|
placeholder="请输入图片描述"
|
|
maxlength="200"
|
|
></el-input>
|
|
<div class="char-count">{{ imageForm.description.length }}/200</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- 分类标签选择器 -->
|
|
<div class="form-item">
|
|
<div class="form-label">分类标签(可多选)</div>
|
|
<div class="tag-list">
|
|
<div
|
|
v-for="tag in availableTags"
|
|
:key="tag.value"
|
|
class="tag"
|
|
:class="{ 'tag-selected': imageForm.tags.includes(tag.value), 'tag-default': !imageForm.tags.includes(tag.value) }"
|
|
@click="toggleTag(tag.value)"
|
|
>
|
|
{{ tag.label }}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- 关联任务选择器 -->
|
|
<div class="form-item">
|
|
<div class="form-label">关联任务(可选)</div>
|
|
<el-select
|
|
v-model="imageForm.taskId"
|
|
placeholder="请选择关联任务"
|
|
filterable
|
|
>
|
|
<el-option
|
|
v-for="task in availableTasks"
|
|
:key="task.id"
|
|
:label="task.name"
|
|
:value="task.id"
|
|
></el-option>
|
|
</el-select>
|
|
</div>
|
|
|
|
<!-- 提交按钮 -->
|
|
<el-button
|
|
type="primary"
|
|
class="submit-btn"
|
|
:loading="submitting"
|
|
@click="handleSubmit"
|
|
>
|
|
提交
|
|
</el-button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
new Vue({
|
|
el: '#app',
|
|
data() {
|
|
return {
|
|
selectedImages: [],
|
|
imageForm: {
|
|
title: '',
|
|
description: '',
|
|
tags: [],
|
|
taskId: ''
|
|
},
|
|
availableTags: [
|
|
{ label: '产品包装', value: 'product_package' },
|
|
{ label: '活动现场', value: 'event' },
|
|
{ label: '办公环境', value: 'office' },
|
|
{ label: '员工活动', value: 'employee' },
|
|
{ label: '客户交流', value: 'customer' },
|
|
{ label: '其他', value: 'other' }
|
|
],
|
|
availableTasks: [
|
|
{ id: 1, name: '产品包装收集' },
|
|
{ id: 2, name: '活动现场拍摄' },
|
|
{ id: 3, name: '办公环境更新' }
|
|
],
|
|
currentDepartment: '市场部',
|
|
submitting: false,
|
|
uploading: false
|
|
}
|
|
},
|
|
methods: {
|
|
// 处理文件选择
|
|
handleFileSelect(event) {
|
|
const files = event.target.files;
|
|
if (files && files.length > 0) {
|
|
// 限制最多上传9张
|
|
const maxFiles = 9 - this.selectedImages.length;
|
|
const filesToAdd = Math.min(files.length, maxFiles);
|
|
|
|
if (filesToAdd === 0) {
|
|
this.$message.warning('最多只能上传9张图片');
|
|
return;
|
|
}
|
|
|
|
for (let i = 0; i < filesToAdd; i++) {
|
|
const file = files[i];
|
|
|
|
// 检查文件类型
|
|
if (!file.type.match('image/jpeg') && !file.type.match('image/png')) {
|
|
this.$message.error('只能上传JPG或PNG格式的图片');
|
|
continue;
|
|
}
|
|
|
|
// 检查文件大小
|
|
if (file.size > 2 * 1024 * 1024) {
|
|
this.$message.error('图片大小不能超过2MB');
|
|
continue;
|
|
}
|
|
|
|
// 创建预览URL
|
|
const reader = new FileReader();
|
|
reader.onload = (e) => {
|
|
this.selectedImages.push({
|
|
file: file,
|
|
url: e.target.result,
|
|
uploading: false,
|
|
progress: 0
|
|
});
|
|
};
|
|
reader.readAsDataURL(file);
|
|
}
|
|
|
|
// 清空input,允许重复选择相同文件
|
|
event.target.value = '';
|
|
}
|
|
},
|
|
|
|
// 移除图片
|
|
removeImage(index) {
|
|
this.selectedImages.splice(index, 1);
|
|
},
|
|
|
|
// 切换标签选择
|
|
toggleTag(tagValue) {
|
|
const index = this.imageForm.tags.indexOf(tagValue);
|
|
if (index > -1) {
|
|
this.imageForm.tags.splice(index, 1);
|
|
} else {
|
|
this.imageForm.tags.push(tagValue);
|
|
}
|
|
},
|
|
|
|
// 模拟上传进度
|
|
simulateUpload() {
|
|
this.selectedImages.forEach((image, index) => {
|
|
image.uploading = true;
|
|
image.progress = 0;
|
|
|
|
const interval = setInterval(() => {
|
|
image.progress += 10;
|
|
if (image.progress >= 100) {
|
|
clearInterval(interval);
|
|
image.uploading = false;
|
|
}
|
|
}, 200);
|
|
});
|
|
},
|
|
|
|
// 提交表单
|
|
handleSubmit() {
|
|
// 表单验证
|
|
if (this.selectedImages.length === 0) {
|
|
this.$message.error('请至少选择一张图片');
|
|
return;
|
|
}
|
|
|
|
if (!this.imageForm.title.trim()) {
|
|
this.$message.error('请输入图片标题');
|
|
return;
|
|
}
|
|
|
|
this.submitting = true;
|
|
this.uploading = true;
|
|
|
|
// 模拟上传
|
|
this.simulateUpload();
|
|
|
|
// 模拟提交请求
|
|
setTimeout(() => {
|
|
this.submitting = false;
|
|
this.$message.success('上传成功');
|
|
// 重置表单
|
|
this.selectedImages = [];
|
|
this.imageForm = {
|
|
title: '',
|
|
description: '',
|
|
tags: [],
|
|
taskId: ''
|
|
};
|
|
// 返回首页
|
|
setTimeout(() => {
|
|
window.location.href = 'user-home.html';
|
|
}, 1000);
|
|
}, 2000);
|
|
},
|
|
|
|
// 返回上一页
|
|
goBack() {
|
|
if (this.selectedImages.length > 0 || this.imageForm.title || this.imageForm.description) {
|
|
this.$confirm('确定要离开吗?当前编辑内容将会丢失。', '提示', {
|
|
confirmButtonText: '确定',
|
|
cancelButtonText: '取消',
|
|
type: 'warning'
|
|
}).then(() => {
|
|
window.history.back();
|
|
});
|
|
} else {
|
|
window.history.back();
|
|
}
|
|
}
|
|
}
|
|
})
|
|
</script>
|
|
</body>
|
|
</html> |