12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010 |
- <template>
- <div class="app-container">
- <div v-loading.fullscreen.lock="loadingFull" />
- <el-tabs v-model="classParams.type">
- <el-tab-pane label="图片" name="0" />
- <el-tab-pane label="视频" name="1" />
- </el-tabs>
- <div style="margin-bottom: 20px;">
- <el-input v-model="searchParams.search_name" placeholder="分类名称" style="width: 300px" />
- <el-select v-model="searchParams.activity_id" style="width: 300px" placeholder="关联活动">
- <el-option label="全部" value="" />
- <el-option
- v-for="item in season_list"
- :key="`${item.season}_${item.type}`"
- :label="item.name"
- :value="item.id"
- />
- </el-select>
- <el-button type="primary" @click="searchParams.page_index = 1; getClassList()">搜索</el-button>
- <el-button type="primary" @click="fileType = true; fileVis = true">添加目录</el-button>
- </div>
- <el-collapse v-model="classActived" accordion @change="toggleImgList">
- <el-collapse-item v-for="item in classList" :key="item.id" :name="JSON.stringify(item)">
- <template slot="title">
- <div class="photo_title_container">
- <p>{{ item.imgclass_name }}</p>
- <template v-if="+classParams.type === 0">
- <div v-if="item.is_old">
- <el-button type="text" @click.stop="submitDeleteClass(item.id)">删除目录</el-button>
- <el-button type="text" @click.stop="setEditClass(item)">修改目录</el-button>
- <el-button type="text" @click.stop="setUploadImg(item.id)">{{ +classParams.type === 0 ? '添加图片' : '添加视频' }}</el-button>
- <el-button type="text" @click.stop="setMachDeleteImg">批量删除</el-button>
- <el-button type="text" @click.stop="setSeleceAllImg(item)">
- {{ item.isSelectAll ? '已全选' : '全选' }}
- </el-button>
- </div>
- <div v-else>
- <el-button type="text" @click.stop="submitDeleteClass(item.id)">删除目录</el-button>
- <el-button type="text" @click.stop="setEditClass(item)">修改目录</el-button>
- <el-button type="text" @click.stop="addClassify(item)">添加分类</el-button>
- </div>
- </template>
- <template v-else>
- <div>
- <el-button type="text" @click.stop="submitDeleteClass(item.id)">删除目录</el-button>
- <el-button type="text" @click.stop="setEditClass(item)">修改目录</el-button>
- <el-button type="text" @click.stop="setUploadImg(item.id)">{{ +classParams.type === 0 ? '添加图片' : '添加视频' }}</el-button>
- <el-button type="text" @click.stop="setMachDeleteImg">批量删除</el-button>
- <el-button type="text" @click.stop="setSeleceAllImg(item)">
- {{ item.isSelectAll ? '已全选' : '全选' }}
- </el-button>
- </div>
- </template>
- <!-- <ul class="controls_container">
- <el-tooltip class="item" effect="dark" content="删除目录" placement="top">
- <li class="controls_item" @click.stop="submitDeleteClass(item.id)"><i class="el-icon-folder-delete" /></li>
- </el-tooltip>
- <el-tooltip class="item" effect="dark" content="修改目录" placement="top">
- <li class="controls_item" @click.stop="setEditClass(item)"><i class="el-icon-edit-outline" /></li>
- </el-tooltip>
- <el-tooltip class="item" effect="dark" :content="+classParams.type === 0 ? '添加图片' : '添加视频'" placement="top">
- <li class="controls_item" @click.stop="setUploadImg(item.id)"><i class="el-icon-plus" /></li>
- </el-tooltip>
- <el-tooltip class="item" effect="dark" content="批量删除" placement="top">
- <li class="controls_item" @click.stop="setMachDeleteImg"><i class="el-icon-delete" /></li>
- </el-tooltip>
- <el-tooltip class="item" effect="dark" content="全选" placement="top">
- <li class="controls_item" :class="item.isSelectAll ? 'controls_item_active' : ''" @click.stop="setSeleceAllImg(item)"><i class="el-icon-aim" /></li>
- </el-tooltip>
- </ul> -->
- </div>
- </template>
- <template v-if="+classParams.type === 0 && !item.is_old">
- <template v-if="showClassIfy">
- <!-- <ul class="controls_container">
- <el-tooltip class="item" effect="dark" content="返回" placement="top">
- <li class="controls_item" @click="showClassIfy = false"><i class="el-icon-refresh-left" /></li>
- </el-tooltip>
- </ul> -->
- <el-button type="text" @click="showClassIfy = false">返回</el-button>
- <el-button type="text" @click.stop="setClassifyUploadImg">上传图片</el-button>
- <el-button type="text" @click.stop="setMachDeleteImg">批量删除</el-button>
- <template v-if="classIfyImgList.length > 0">
- <div class="class_img_list">
- <div
- v-for="btem in classIfyImgList"
- :key="btem.id"
- class="class_img_item"
- >
- <el-image
- :src="btem.thumbnail"
- fit="fill"
- :preview-src-list="[btem.img_url]"
- class="class_img"
- />
- <div class="class_img_controls">
- <el-tooltip class="item" effect="dark" content="选择批量删除" placement="top">
- <el-checkbox v-model="deleteImgs[btem.id]" />
- </el-tooltip>
- <el-tooltip class="item" effect="dark" content="删除图片" placement="top">
- <i class="el-icon-delete-solid control_detele" @click="submitDeleteImgOne(btem.id)" />
- </el-tooltip>
- </div>
- </div>
- </div>
- <div class="flex_center">
- <pagination
- :total="classIfyImgTotal"
- :page.sync="classImgParmas.page_index"
- :limit.sync="classImgParmas.page_size"
- @pagination="updateShowImgs"
- @updata:limit="updateShowImgs"
- />
- </div>
- </template>
- <div v-else class="photo_no">
- <i class="el-icon-receiving" />
- <p class="text">该分类暂无图片</p>
- </div>
- </template>
- <template v-else>
- <div v-if="classifyList.length > 0" class="classList">
- <div
- v-for="cItem in classifyList"
- :key="cItem.id"
- class="classItem"
- @click="showClassIfyImg(cItem.id)"
- >
- <i class="el-icon-folder-opened classItem-icon" />
- <p class="classItem-name">{{ cItem.image_name }}</p>
- <div style="width: 100%">
- <el-button type="text" @click.stop="updateClassify(cItem)">修改</el-button>
- <el-button type="text" @click.stop="toDeleteClassify(cItem.id)">删除</el-button>
- </div>
- </div>
- </div>
- <div v-else class="photo_no">
- <i class="el-icon-receiving" />
- <p class="text">暂无分类</p>
- </div>
- </template>
- </template>
- <template v-else>
- <div v-if="classImgList.length > 0">
- <div class="class_img_list">
- <div
- v-for="btem in classImgList"
- :key="btem.id"
- class="class_img_item"
- >
- <el-image
- v-if="+classParams.type === 0"
- :src="btem.thumbnail"
- fit="fill"
- :preview-src-list="[btem.img_url]"
- class="class_img"
- />
- <div v-else>
- <video :src="btem.img_url" controls class="class_video" />
- </div>
- <div class="class_img_controls">
- <el-tooltip class="item" effect="dark" content="选择批量删除" placement="top">
- <el-checkbox v-model="deleteImgs[btem.id]" />
- </el-tooltip>
- <el-tooltip class="item" effect="dark" :content="+classParams.type ? '删除视频' : '删除图片'" placement="top">
- <i class="el-icon-delete-solid control_detele" @click="submitDeleteImgOne(btem.id)" />
- </el-tooltip>
- </div>
- </div>
- </div>
- <div class="flex_center">
- <pagination
- :total="classImgTotal"
- :page.sync="classImgParmas.page_index"
- :limit.sync="classImgParmas.page_size"
- @pagination="updateShowImgs"
- />
- </div>
- </div>
- <div v-else class="photo_no">
- <i class="el-icon-receiving" />
- <p class="text">暂无内容</p>
- </div>
- </template>
- </el-collapse-item>
- </el-collapse>
- <pagination
- :total="classTotal"
- :page.sync="searchParams.page_index"
- :limit.sync="searchParams.page_size"
- @pagination="getClassList"
- />
- <!-- 添加分类名 -->
- <el-dialog
- :title="fileType ? '添加目录' : '修改目录'"
- :visible.sync="fileVis"
- width="500px"
- :close-on-click-modal="false"
- :before-close="resetClassParams"
- >
- <el-form ref="classForm" label-width="80px" :model="classParams" :rules="classRule" :hide-required-asterisk="true">
- <el-form-item label="分类名称:" prop="title">
- <el-input v-model="classParams.title" type="text" />
- </el-form-item>
- <el-form-item label="关联活动:" prop="activity_id">
- <el-select v-model="classParams.activity_id" style="width: 100%">
- <el-option
- v-for="item in season_list"
- :key="`${item.season}_${item.type}`"
- :label="item.name"
- :value="item.id"
- />
- </el-select>
- </el-form-item>
- <el-form-item label="排序:" prop="sort">
- <el-input v-model="classParams.sort" type="text" placeholder="数字越大越靠上" />
- </el-form-item>
- <el-form-item>
- <el-button v-if="fileType" type="primary" size="small" @click="submitAddClass">添加</el-button>
- <el-button v-else type="primary" size="small" @click="submitEditClass">修改</el-button>
- <el-button size="small" @click="resetClassParams">取消</el-button>
- </el-form-item>
- </el-form>
- </el-dialog>
- <!-- 上传图片 -->
- <el-dialog
- :title="+classParams.type === 0 ? '上传图片' : '上传视频'"
- :visible.sync="imgVis"
- width="800px"
- :close-on-click-modal="false"
- :before-close="updateShowImgs"
- >
- <div v-if="+classParams.type === 0">
- <el-upload
- class="upload-demo"
- drag
- action=""
- multiple
- accept=".jpg, .jpeg, .png"
- :http-request="submitUploadImg"
- :show-file-list="false"
- >
- <i class="el-icon-upload" />
- <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
- <div slot="tip" class="el-upload__tip">只能上传jpg/jpeg/png文件, 且图片最大不超过3M</div>
- </el-upload>
- </div>
- <div v-else>
- <el-upload
- class="upload-demo"
- drag
- action=""
- accept=".mp4"
- :http-request="submitUploadVideo"
- :show-file-list="false"
- >
- <i class="el-icon-upload" />
- <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
- <div slot="tip" class="el-upload__tip">上传视频类型为: .mp4 后缀的文件类型, 且视频最大不超过45M</div>
- </el-upload>
- </div>
- <ul class="upload_list_container">
- <li v-for="(item, i) in uploadImgs" :key="`upload_img_${i}`" class="upload_item">
- <p class="img_name">{{ item.name }}</p>
- <el-progress :percentage="item.progress" style="width: 300px" />
- </li>
- </ul>
- </el-dialog>
- <!-- 添加/修改分类 -->
- <el-dialog
- :title="dialog.classifyType ? '添加分类' : '修改分类'"
- :visible.sync="dialog.classify"
- width="520px"
- :close-on-click-modal="false"
- :before-close="resetClassIfy"
- >
- <el-form ref="classifyForm" label-width="100px" :rules="classifyRules" :model="classifyForm">
- <el-form-item label="分类名称:" prop="image_name">
- <el-input v-model="classifyForm.image_name" type="text" />
- </el-form-item>
- <el-form-item label="排序:" prop="sort">
- <el-input v-model="classifyForm.sort" type="text" />
- </el-form-item>
- </el-form>
- <template slot="footer">
- <el-button @click="resetClassIfy">取消</el-button>
- <el-button type="primary" @click="toPublishClassify">{{ dialog.classifyType ? '添加' : '修改' }}</el-button>
- </template>
- </el-dialog>
- </div>
- </template>
- <script>
- import {
- addClass,
- getClassList,
- deleteClass,
- editClass,
- uploadImg,
- getClassImgList,
- deleteClassImg,
- uploadVideo,
- getChildClass,
- getChildImg,
- addUpdateFolder,
- deleteFolder,
- uploadClassifyImg,
- deleteFolderImg
- } from '@/api/photo'
- export default {
- data() {
- return {
- fileVis: false,
- fileType: true,
- loadingFull: false,
- imgVis: false,
- classParams: {
- activity_id: '',
- title: '',
- sort: '',
- type: '0',
- id: ''
- },
- searchParams: {
- page_index: 1,
- page_size: 10,
- search_name: '',
- activity_id: ''
- },
- classRule: {
- activity_id: [
- { required: true, message: '请选请关联活动', trigger: 'change' }
- ],
- title: [
- { required: true, message: '请填写分类名称', trigger: 'blur' }
- ],
- sort: [
- { required: true, message: '请填写排序大小', trigger: 'blur' }
- ]
- },
- classList: [],
- classTotal: 0,
- uploadClassId: '',
- uploadImgs: [],
- classActived: [],
- classImgParmas: {
- page_index: 1,
- page_size: 80
- },
- classImgList: [],
- classImgTotal: 0,
- deleteImgs: {},
- isSelectAll: false,
- classifyList: [],
- classifyTotal: 0,
- classifyImgParams: {
- id: '',
- page_index: 1,
- page_size: 80
- },
- showClassIfy: false,
- classIfyImgList: [],
- classIfyImgTotal: 0,
- dialog: {
- classify: false,
- classifyType: true
- },
- classifyForm: {
- image_name: '',
- sort: '',
- image_class_id: '',
- id: '',
- data: null
- },
- classifyRules: {
- image_name: [
- { required: true, message: '请填写分类名称', trigger: 'blur' }
- ],
- sort: [
- { required: true, message: '请填写排序', trigger: 'blur' }
- ]
- }
- }
- },
- computed: {
- season_list() {
- return this.$store.state.user.season_list
- }
- },
- watch: {
- 'classParams.type'() {
- this.getClassList()
- }
- },
- created() {
- this.getClassList()
- },
- methods: {
- // 删除分类
- toDeleteClassify(id) {
- this.$confirm('确认删除这个分类吗?', '提示', {
- confirmButtonText: '确定',
- cancelButtonText: '取消',
- type: 'warning'
- }).then(() => {
- this.loadingFull = true
- deleteFolder({ id }).then(res => {
- this.loadingFull = false
- if (res.code === 200) {
- this.$message.success('删除分类成功')
- this.toggleImgList(this.classifyForm.data)
- } else {
- this.$message.error(res.message || '删除分类失败')
- }
- }).catch(() => {
- this.loadingFull = false
- this.$message.error('删除分类失败')
- })
- }).catch(() => {})
- },
- addClassify(data) {
- this.classifyForm.data = JSON.stringify(data)
- this.classifyForm.image_class_id = data.id
- this.dialog.classify = true
- this.dialog.classifyType = true
- },
- // 重置分类
- resetClassIfy() {
- this.classifyForm.image_name = ''
- this.classifyForm.sort = ''
- this.classifyForm.image_class_id = ''
- this.classifyForm.id = ''
- this.dialog.classify = false
- this.dialog.classifyType = false
- },
- // 修改分类
- updateClassify(data) {
- this.classifyForm.id = data.id
- this.classifyForm.image_name = data.image_name
- this.classifyForm.sort = data.sort
- this.dialog.classify = true
- this.dialog.classifyType = false
- },
- // 增加修改分类
- toPublishClassify() {
- this.$refs.classifyForm.validate(valid => {
- if (valid) {
- const { id, image_class_id, sort, image_name, data } = this.classifyForm
- const params = this.dialog.classifyType ? {
- image_class_id, sort, image_name
- } : {
- id, image_name, sort
- }
- this.loadingFull = true
- addUpdateFolder(params).then(res => {
- this.loadingFull = false
- if (res.code === 200) {
- this.$message.success(this.classifyType ? '添加成功' : '修改成功')
- this.toggleImgList(data)
- this.resetClassIfy()
- } else {
- this.$message.error(res.message || this.classifyType ? '添加分类失败' : '修改分类失败')
- }
- }).catch(() => {
- this.loadingFull = false
- this.$message.error(this.classifyType ? '添加分类失败' : '修改分类失败')
- })
- } else {
- return false
- }
- })
- },
- // 重置添加分类
- resetClassParams() {
- this.classParams.activity_id = ''
- this.classParams.title = ''
- this.classParams.sort = ''
- this.classParams.id = ''
- this.fileVis = false
- this.fileType = true
- },
- // 获取分类列表
- getClassList() {
- const params = Object.assign({}, this.searchParams)
- params.type = this.classParams.type
- this.loadingFull = true
- getClassList(params).then(res => {
- this.loadingFull = false
- if (res.code === 200) {
- this.classList = res.data.list.map(item => {
- item.isSelectAll = false
- return item
- })
- this.classTotal = res.data.total
- } else {
- this.$message.error(res.message || '获取相册失败')
- }
- }).catch(() => {
- this.loadingFull = false
- this.$message.error('获取相册失败')
- })
- },
- // 添加分类
- submitAddClass() {
- this.$refs.classForm.validate((valid) => {
- if (valid) {
- this.loadingFull = true
- addClass(this.classParams).then(res => {
- this.loadingFull = false
- if (res.code === 200) {
- this.$message.success('添加分类成功')
- this.resetClassParams()
- this.getClassList()
- } else {
- this.$message.error(res.message || '添加分类失败')
- }
- }).catch(() => {
- this.loadingFull = false
- this.$message.error('添加分类失败')
- })
- } else {
- return false
- }
- })
- },
- // 删除分类
- submitDeleteClass(id) {
- this.$confirm('确认删除这个分类目录', '提示', {
- confirmButtonText: '确定',
- cancelButtonText: '取消',
- type: 'warning'
- }).then(() => {
- this.loadingFull = true
- deleteClass({ id }).then(res => {
- this.loadingFull = false
- if (res.code === 200) {
- this.$message.success('删除分类成功')
- this.getClassList()
- } else {
- this.$message.error(res.message || '删除分类失败')
- }
- }).catch((e) => {
- this.loadingFull = false
- this.$message.error('删除分类失败')
- })
- }).catch(() => {})
- },
- // 修改分类
- setEditClass(item) {
- const { imgclass_name, activity_id, sort, id } = item
- this.classParams.title = imgclass_name
- this.classParams.sort = sort
- this.classParams.activity_id = activity_id
- this.classParams.id = id
- this.fileType = false
- this.fileVis = true
- },
- submitEditClass() {
- this.$refs.classForm.validate((valid) => {
- if (valid) {
- this.loadingFull = true
- editClass(this.classParams).then(res => {
- this.loadingFull = false
- if (res.code === 200) {
- this.$message.success('修改分类成功')
- this.resetClassParams()
- this.getClassList()
- } else {
- this.$message.error(res.message || '修改分类成功')
- }
- }).catch(() => {
- this.loadingFull = false
- this.$message.error('修改分类成功')
- })
- } else {
- return false
- }
- })
- },
- // 显示分类图片
- showClassIfyImg(id) {
- this.uploadClassId = id
- this.classifyImgParams.id = id
- this.showClassIfy = true
- this.getClassifyImg()
- },
- // 获取分类图片
- getClassifyImg() {
- this.loadingFull = true
- getChildImg(this.classifyImgParams).then(res => {
- this.loadingFull = false
- if (res.code === 200) {
- this.classIfyImgList = res.data.list
- this.classIfyImgTotal = res.data.total
- } else {
- this.$message.error(res.message || '获取图片失败')
- }
- }).catch(() => {
- this.loadingFull = false
- this.$message.error('获取图片失败')
- })
- },
- resetShowImgs() {
- this.deleteImgs = {}
- this.classImgList = []
- this.classImgTotal = 0
- this.classIfyImgList = []
- this.showClassIfy = false
- this.classList.forEach(item => {
- this.$set(item, 'isSelectAll', false)
- })
- },
- // 获取图片列表
- toggleImgList(data) {
- if (!data) return false
- data = JSON.parse(data)
- this.resetShowImgs()
- if (!data.is_old && +this.classParams.type === 0) {
- this.loadingFull = true
- this.classifyForm.data = JSON.stringify(data)
- getChildClass({ id: data.id }).then(res => {
- this.loadingFull = false
- if (res.code === 200) {
- this.classifyList = res.data.list
- this.classifyTotal = res.data.total
- } else {
- this.$message.error(res.message || '获取分类失败')
- }
- }).catch(() => {
- this.loadingFull = false
- this.$message.error('获取分类失败')
- })
- } else {
- console.log(this.classImgParmas)
- const { page_index, page_size } = this.classImgParmas
- this.classifyForm.data = ''
- this.loadingFull = true
- getClassImgList({
- id: data.id,
- page_index,
- page_size
- }).then(res => {
- this.loadingFull = false
- if (res.code === 200) {
- this.classImgList = res.data.list
- this.classImgTotal = res.data.total
- } else {
- this.$message.error(res.message || '获取图片失败')
- }
- }).catch(() => {
- this.loadingFull = false
- this.$message.error('获取图片失败')
- })
- }
- },
- // 上传完成更新图片
- updateShowImgs({ page, limit }) {
- if (this.imgVis) {
- this.uploadImgs = []
- this.imgVis = false
- }
- if (+this.classParams.type === 1 && this.classifyForm.data) {
- if (page) {
- this.classifyImgParams.page_size = limit
- this.classifyImgParams.page_index = page
- }
- this.getClassifyImg()
- } else {
- if (this.classActived) {
- if (page) {
- this.classImgParmas.page_index = page
- this.classImgParmas.page_size = limit
- }
- this.toggleImgList(this.classActived)
- }
- }
- },
- // 上传分类图片
- setClassifyUploadImg(id) {
- this.imgVis = true
- },
- // 上传图片
- setUploadImg(id) {
- this.uploadClassId = id
- this.imgVis = true
- },
- submitUploadImg(params) {
- if (!this.uploadClassId) {
- this.$message.error('获取分类Id失败')
- this.imgVis = false
- return false
- }
- const file = params.file
- const { size } = file
- if (size > 1024 * 1024 * 3) {
- this.$message.error('图片体积最大为3M')
- return false
- }
- this.uploadImgs.push({
- file,
- name: file.name,
- progress: 0
- })
- if (this.classifyForm.data) {
- const formData = new FormData()
- formData.append('file', file)
- formData.append('id', this.uploadClassId)
- const _this = this
- const _i = this.uploadImgs.length - 1
- uploadClassifyImg(formData, ({ loaded, total }) => {
- const complete = (loaded / total * 100) | 0
- _this.uploadImgs[_i].progress = complete
- }).then(res => {
- if (res.code === 200) {
- this.$message.success('上传图片成功')
- } else {
- this.$message.error(res.message || '上传图片失败')
- }
- }).catch((e) => {
- this.$message.error('上传图片失败')
- })
- } else {
- this.uploadImg(file, this.uploadImgs.length - 1)
- }
- },
- uploadImg(file, i) {
- const _this = this
- const formData = new FormData()
- formData.append('file', file)
- formData.append('id', this.uploadClassId)
- formData.append('type', this.classParams.type)
- uploadImg(formData, ({ loaded, total }) => {
- const complete = (loaded / total * 100) | 0
- _this.uploadImgs[i].progress = complete
- }).then(res => {
- if (res.code === 200) {
- this.$message.success('上传图片成功')
- } else {
- this.$message.error(res.message || '上传图片失败')
- }
- }).catch((e) => {
- console.log(e)
- this.$message.error('上传图片失败')
- })
- },
- // 全选图片
- setSeleceAllImg(data) {
- data.isSelectAll = !data.isSelectAll
- if (data.isSelectAll) {
- this.classImgList.forEach(item => {
- this.$set(this.deleteImgs, item.id, true)
- })
- } else {
- const obj = Object.assign({}, this.deleteImgs)
- Object.keys(obj).forEach(id => {
- this.$set(this.deleteImgs, id, false)
- })
- }
- },
- // 批量删除
- setMachDeleteImg() {
- const obj = Object.assign({}, this.deleteImgs)
- const selectedArr = Object.keys(obj).filter(id => obj[id])
- if (selectedArr.length === 0) {
- this.$message.error('请至少选择一个')
- return false
- }
- this.$confirm('是否确认删除选择图片?', '提示', {
- confirmButtonText: '确定',
- cancelButtonText: '取消',
- type: 'warning'
- }).then(() => {
- this.submitDeleteImg(selectedArr)
- }).catch(() => {})
- },
- // 单个删除
- submitDeleteImgOne(id) {
- this.$confirm(`是否确认删除该${+this.classParams.type ? '视频' : '图片'}?`, '提示', {
- confirmButtonText: '确定',
- cancelButtonText: '取消',
- type: 'warning'
- }).then(() => {
- this.submitDeleteImg([id])
- }).catch(() => {})
- },
- // 提交删除
- submitDeleteImg(ids) {
- if (this.classifyForm.data) {
- deleteFolderImg({ ids }).then(res => {
- if (res.code === 200) {
- this.$message.success('删除图片成功')
- this.deleteImgs = {}
- this.getClassifyImg()
- } else {
- this.$message.error(res.message || '删除图片失败')
- }
- }).catch(() => {
- this.$message.error('删除图片失败')
- })
- } else {
- deleteClassImg({ ids }).then(res => {
- if (res.code === 200) {
- this.$message.success('删除图片成功')
- this.deleteImgs = {}
- this.updateShowImgs()
- } else {
- this.$message.error(res.message || '删除图片失败')
- }
- }).catch(() => {
- this.$message.error('删除图片失败')
- })
- }
- },
- // 上传视频
- submitUploadVideo(params) {
- const file = params.file
- const { size, type } = file
- if (size > 45 * 1024 * 1024) {
- this.$message.error('视频最大不超过45M')
- return false
- }
- const fileType = ['video/mp4']
- console.log(type)
- if (!fileType.includes(type)) {
- this.$message.error('上传视频类型不是mp4类型')
- return false
- }
- this.uploadImgs.push({
- file,
- name: file.name,
- progress: 0
- })
- this.uploadVideo(file, this.uploadImgs.length - 1)
- },
- uploadVideo(file, i) {
- const _this = this
- const formData = new FormData()
- formData.append('file', file)
- formData.append('id', this.uploadClassId)
- formData.append('type', this.classParams.type)
- uploadVideo(formData, ({ loaded, total }) => {
- const complete = (loaded / total * 100) | 0
- _this.uploadImgs[i].progress = complete
- }).then(res => {
- if (res.code === 200) {
- this.$message.success('上传视频成功')
- } else {
- this.$message.error(res.message || '上传视频失败')
- }
- }).catch(() => {
- this.$message.error('上传视频失败')
- })
- }
- }
- }
- </script>
- <style scoped lang="scss">
- /deep/ .el-tree-node__content {
- height: auto;
- }
- .photo_title_container {
- display: flex;
- justify-content: space-between;
- align-items: center;
- flex: 1;
- padding-right: 20px;
- // height: 48px;
- // line-height: 48px;
- }
- .controls_container {
- list-style: none;
- display: flex;
- align-items: center;
- justify-content: flex-start;
- padding: 0;
- .controls_item {
- width: 25px;
- height: 25px;
- display: flex;
- justify-content: center;
- align-items: center;
- background: #cccccc;
- color: #ffffff;
- margin-right: 10px;
- border-radius: 2px;
- font-size: 14px;
- cursor: pointer;
- &:hover {
- background: #409EFF !important;
- }
- }
- .controls_item_active {
- background: #409EFF !important;
- }
- }
- .photo_no {
- display: flex;
- align-items: center;
- justify-content: center;
- padding: 100px;
- font-size: 100px;
- display: flex;
- justify-content: center;
- align-items: center;
- flex-direction: column;
- color: #cccccc;
- .text {
- font-size: 18px;
- font-weight: 500;
- }
- }
- /deep/ .el-upload{
- width: 100%;
- .el-upload-dragger{
- width: 100%;
- }
- }
- .upload_list_container {
- list-style: none;
- padding: 0;
- max-height: 500px;
- overflow-y: scroll;
- .upload_item {
- list-style: none;
- margin-bottom: 15px;
- display: flex;
- justify-content: space-between;
- align-items: center;
- .img_name {
- flex: 1;
- overflow: hidden;
- text-overflow: ellipsis;
- white-space: nowrap;
- padding-right: 10px;
- margin: 0;
- }
- }
- }
- .class_img_list {
- display: flex;
- justify-content: flex-start;
- flex-wrap: wrap;
- .class_img_item {
- margin-right: 10px;
- margin-bottom: 10px;
- position: relative;
- .class_img {
- width: 100px;
- height: 100px;
- }
- .class_video {
- width: 400px;
- }
- .class_img_controls {
- display: flex;
- justify-content: space-between;
- align-items: center;
- .control_detele {
- font-size: 14px;
- }
- i {
- cursor: pointer;
- }
- }
- }
- }
- /deep/ .pagination-container{
- padding: 0;
- }
- .flex_center {
- display: flex;
- justify-content: center;
- align-items: center;
- }
- .classList {
- display: flex;
- align-items: center;
- justify-content: flex-start;
- flex-wrap: wrap;
- .classItem {
- display: flex;
- justify-content: center;
- align-items: flex-start;
- flex-direction: column;
- cursor: pointer;
- margin-right: 20px;
- margin-bottom: 20px;
- &-icon {
- width: 130px;
- height: 130px;
- background: #f5f7fa;
- border: 1px solid #f1f1f1;
- font-size: 100px;
- display: flex;
- align-items: center;
- justify-content: center;
- }
- &-name {
- line-height: 30px;
- height: 30px;
- text-align: center;
- margin: 0;
- font-size: 12px;
- overflow: hidden;
- text-overflow: ellipsis;
- white-space: nowrap;
- }
- }
- }
- </style>
|