xuhuajiao 3 years ago
parent
commit
a09482c706
  1. BIN
      public/favicon.ico
  2. 2
      src/api/material/material.js
  3. 218
      src/views/components/upload.vue
  4. 4
      src/views/content/material/materialList/index.vue
  5. 30
      src/views/content/theme/index.vue

BIN
public/favicon.ico

2
src/api/material/material.js

@ -28,7 +28,7 @@ export function deleteMaterialFolder(parameter) {
}
// 编辑 - 素材库
export function saveMaterial(parameter) {
export function FetchSaveMaterial(parameter) {
return request({
url: 'api/material/save',
method: 'post',

218
src/views/components/upload.vue

@ -1,13 +1,12 @@
<template>
<div class="components_upload">
<div v-if="isTheme">
<!-- <div v-if="isTheme">
<el-button class="cont_upload_btn" round type="primary">选择文件</el-button>
<input id="upFile" ref="inputfile" type="file" name="upFile" @change="changeFile($event)" />
</div>
<el-button v-if="!isTheme" class="cont_upload_btn" round type="primary">上传</el-button>
<input v-if="!isTheme" id="upFile" type="file" name="upFile" @change="changeFile($event)" />
<!-- <input type="button" name="开始上传" value="开始上传" class="start_upload" @click="uploadFile()" /> -->
<!-- <img v-if="coverUrl" :src="coverUrl" alt="封面" /> -->
</div> -->
<el-button class="cont_upload_btn" round type="primary">{{ isTheme ? '选择文件' : '上传' }}</el-button>
<input id="upFile" type="file" name="upFile" @change="changeFile($event)" />
<input v-if="isTheme" type="button" name="开始上传" value="开始上传" class="start_upload" @click="uploadFile()" />
<!-- 上传列表layer -->
<div v-if="!isTheme" class="upload_layer">
@ -22,32 +21,33 @@
<el-table-column align="center" prop="fileNames" label="文件名" />
<el-table-column align="center" prop="formatType" label="类型" />
<el-table-column align="center" prop="fileSize" label="大小" />
<el-table-column align="center" prop="filePercent" label="状态">
<template>
<el-table-column align="center" prop="filePercentTxt" label="状态">
<template slot-scope="scope">
<div class="loadingModal" :style="{ 'height': '100%' }">
<el-progress
v-if="scope.row.filePercent != 0 && scope.row.filePercent != 100"
:stroke-width="6"
:percentage="filePercent"
:color="colors"
:percentage="scope.row.filePercent"
/>
<span v-else>{{ scope.row.filePercentTxt }}</span>
</div>
</template>
</el-table-column>
<el-table-column align="center" prop="handle" label="操作">
<template slot-scope="scope">
<el-button
<!-- <el-button
type="primary"
round
class="on_off_btn"
style="width: 50px; display: inline-block;"
@click="end(scope.$index, scope.row)"
>{{ loading_txt }}</el-button>
@click="controlUpload(scope.$index)"
>{{ uploadStatus ?'暂停':'继续' }}</el-button> -->
<el-button
type="info"
round
style="width: 50px; display: inline-block;"
class="upload_delt"
@click="handleRecord(scope.$index, scope.row)"
@click="deltUpload(scope.$index)"
>删除</el-button>
</template>
</el-table-column>
@ -66,8 +66,7 @@
<script>
import * as qiniu from 'qiniu-js'
import { getQiniuToken, FectchUploadTokenAndOps } from '@/api/upload/upload'
// var observable
let observable
export default {
name: 'Qiniu',
props: {
@ -82,51 +81,51 @@ export default {
token: '',
baseurl: 'qiniu.aiyxlib.com',
fileData: [],
uploadFileUrl: null,
filePercent: 0,
fileNames: '',
formatType: '',
postfix: '',
fileSize: '',
duration: 0,
uploadListVisible: false,
loading_txt: '暂停',
colors: '#1e9f4c',
uploadListData: [],
filePercentTxt: '上传中',
subscription: '',
uploadFileUrl: null,
filePercent: 0,
uploadStatus: false,
isActiveType: null
}
},
mounted() {
this.getQiniuToken()
localStorage.removeItem('compareName')
},
methods: {
changeFile(e) {
//
this.file = e.target.files[0]
console.log(this.file)
this.$emit('getName', this.file.name)
this.formatType = this.file.type.substring(0, this.file.type.indexOf('/'))
if (this.isActiveType == 0) {
this.$message.error('请上传图片文件!')
return
if (this.formatType != 'image') {
this.$message.error('请上传图片文件!')
return
}
} else if (this.isActiveType == 1) {
this.$message.error('请上传视频文件!')
return
if (this.formatType != 'video') {
this.$message.error('请上传视频文件!')
return
}
} else if (this.isActiveType == 2) {
this.$message.error('请上传音频文件!')
return
if (this.formatType != 'audio') {
this.$message.error('请上传音频文件!')
return
}
}
this.formatType = this.file.type.substring(0, this.file.type.indexOf('/'))
console.log('formatType', this.formatType)
this.fileNames = this.file.name
console.log('fileNames', this.fileNames)
this.postfix = this.fileNames.substring(
this.fileNames.lastIndexOf('.') + 1,
this.fileNames.length
)
console.log(this.postfix)
this.fileSize = this.file.size
console.log('fileSize', this.fileSize)
if (this.formatType === 'image') {
const isJPG = this.file.type === 'image/jpeg' || this.file.type === 'image/png' || this.file.type === 'image/bmp' || this.file.type === 'image/gif'
const isLt2M = this.file.size / 1024 / 1024 < 4
@ -137,16 +136,30 @@ export default {
this.$message.error('图片大小不能超过 4MB !')
}
}
this.fileData.push({
fileNames: this.fileNames,
formatType: this.formatType,
fileSize: this.fileSize,
filePercent: this.filePercent
})
setTimeout(() => {
this.uploadFile()
}, 1000)
console.log(this.fileData)
const isRepeat = this.fileData.map(item => item.key).indexOf(this.fileNames)
if (isRepeat == -1) {
this.fileData.push({
fileNames: this.fileNames,
formatType: this.formatType,
fileSize: this.fileSize,
filePercent: 0,
filePercentTxt: '上传中',
key: this.fileNames,
uploadStatus: false
})
if (!this.isTheme) {
setTimeout(() => {
this.uploadFile()
}, 1000)
}
} else {
if (!this.isTheme) {
this.$message({
message: '该素材上传列表内已存在~',
type: 'info'
})
}
}
// this.getOpsToken()
this.uploadListVisible = true
},
@ -178,7 +191,7 @@ export default {
retryCount: 3
}
const token = this.token
const observable = qiniu.upload(
observable = qiniu.upload(
this.file,
name,
token,
@ -199,6 +212,10 @@ export default {
uploadFile() {
// VUEthis _this this
const _this = this
_this.filePercent = 0
_this.uploadStatus = false
let compareChunks = []
var finishedAttr = []
// token
const token = _this.token
//
@ -212,47 +229,76 @@ export default {
mimeType: null
}
//
var observable = qiniu.upload(_this.file, _this.file.name, token, putExtra, { resumingByFileSize: 4 * 1024 * 1024 }, config)
observable = qiniu.upload(_this.file, _this.file.name, token, putExtra, { resumingByFileSize: 4 * 1024 * 1024 }, config)
//
var observer = {
//
next(res) {
//
_this.filePercent = parseInt(res.total.percent)
// _this.filePercentTxt = ''
// if (_this.filePercent == 100) {
// _this.filePercentTxt = ''
// }
_this.fileData.forEach(item => {
console.log(item)
item.filePercent = parseInt(res.total.percent)
})
_this.$set(_this.fileData, 0, _this.fileData[0])
},
//
error(err) {
console.log(err)
},
//
complete(res) {
_this.filePercentTxt = '上传成功'
_this.fileData[0].filePercentTxt = _this.filePercentTxt
_this.uploadFileUrl = 'http://' + _this.baseurl + '/' + res.key
//
_this.getVideoDuration(_this.uploadFileUrl)
setTimeout(() => {
_this.$emit('saveMaterial')
}, 200)
document.getElementById('upFile').value = ''
document.getElementById('upLoadFile').value = ''
localStorage.setItem('currentFile', _this.file.name)
//
var next = function(res) {
const currentFile = localStorage.getItem('currentFile')
const index = _this.fileData.map((item) => item.key).indexOf(currentFile)
var chunks = res.chunks || []
var total = res.total
// chunk
for (var i = 0; i < chunks.length; i++) {
if (chunks[i].percent === 0 || finishedAttr[i]) {
continue
}
if (compareChunks[i].percent === chunks[i].percent) {
continue
}
if (chunks[i].percent === 100) {
finishedAttr[i] = true
}
}
compareChunks = chunks
_this.filePercent = parseInt(total.percent)
_this.$nextTick(function() {
_this.fileData[index].filePercent = _this.filePercent
})
}
//
var error = function(err) {
console.log(err)
}
//
var complete = function(res) {
const index = _this.fileData.map((item) => item.key).indexOf(res.key)
_this.uploadFileUrl = 'http://' + _this.baseurl + '/' + res.key
//
_this.getVideoDuration(_this.uploadFileUrl)
_this.$nextTick(function() {
_this.fileData[index].filePercentTxt = '上传成功'
_this.fileData[index].filePercent = 100
})
setTimeout(() => {
_this.$emit('saveMaterial')
}, 200)
document.getElementById('upFile').value = ''
document.getElementById('upLoadFile').value = ''
localStorage.removeItem('currentFile')
// localStorage.removeItem('currentCompareName')
}
var subObject = {
next: next,
error: error,
complete: complete
}
_this.controlUpload = function() {
_this.uploadStatus = !_this.uploadStatus
if (_this.uploadStatus) {
_this.subscription = observable.subscribe(subObject) // sdkobservable
} else {
_this.subscription.unsubscribe()
}
}
_this.controlUpload()
//
var subscription = observable.subscribe(observer)
// subscription.unsubscribe()
// subscription = observable.subscribe(observer)
},
deltUpload(index) {
this.subscription.unsubscribe()
this.fileData.splice(index, 1)
}
}
}
</script>
@ -260,7 +306,6 @@ export default {
<style lang="scss" scoped>
.components_upload{
position: relative;
// width: 100%;
}
#upFile,
#upLoadFile{
@ -296,5 +341,12 @@ export default {
width: 60px;
}
}
::v-deep .el-progress-bar__outer{
background-color: transparent;
}
::v-deep .el-progress-bar__inner {
background-image: linear-gradient(to right, #40cbfe, #3a8aeb)
}
</style>

4
src/views/content/material/materialList/index.vue

@ -119,7 +119,7 @@
</template>
<script>
import { getMaterialList, saveMaterialFolder, deleteMaterialFolder, saveMaterial, deleteMyMaterial, moveMyMaterial } from '@/api/material/material'
import { getMaterialList, saveMaterialFolder, deleteMaterialFolder, FetchSaveMaterial, deleteMyMaterial, moveMyMaterial } from '@/api/material/material'
import Upload from '@/views/components/upload'
import UploadCover from '@/views/components/upload_cover'
import { getSeconds, getFileFormat } from '@/utils/index.js'
@ -508,7 +508,7 @@ export default {
this.materialImgPath = checkedMaterial[0].img_path
},
//
saveMaterial() {
FetchSaveMaterial() {
if (!this.isEditMaterial) {
const formatType = this.$refs.uploadMaterial.formatType
this.uploadFileUrl = this.$refs.uploadMaterial.uploadFileUrl

30
src/views/content/theme/index.vue

@ -91,12 +91,13 @@
<el-input v-model="uploadForm.material_name" style="width:336px" />
</el-form-item>
<el-form-item class="upload_source" label="上传内容" prop="deposit_url">
<Upload ref="uploadMaterial" :is-theme="isTheme" @getName="getBeforeUploadTxt" @saveMaterial="saveMaterial" />
<span v-if="beforeUploadTxt" class="before_upload">已选择文件{{ beforeUploadTxt }}</span>
<div v-if="formatType != -1" class="source_cont">
<img v-if="formatType==0" :src="uploadForm.deposit_url" alt="" width="150" />
<video v-if="formatType==1" :src="uploadForm.deposit_url" controls width="200"></video>
<audio v-if="formatType==2" :src="uploadForm.deposit_url" controls></audio>
</div>
<Upload ref="uploadMaterial" :is-theme="isTheme" @saveMaterial="saveMaterial" />
</el-form-item>
<el-form-item v-if="formatType != 0" label="添加封面" prop="img_path">
<UploadCover ref="childUpload" />
@ -165,7 +166,7 @@
<script>
import { FetchAddOrEdit, FetchThemeHistoryList, FetchUpdateThemeState, FetchFindThemeClassDetails } from '@/api/theme/theme.js'
import { saveMaterial } from '@/api/material/material'
import { FetchSaveMaterial } from '@/api/material/material'
import ThemeGalleryList from '@/views/components/ThemeGalleryList'
import MyAlbum from '@/views/components/MyAlbum'
import Upload from '@/views/components/upload'
@ -246,7 +247,8 @@ export default {
page: 1,
size: 10,
total: 0,
selectContVisible: true
selectContVisible: true,
beforeUploadTxt: null
}
},
watch: {
@ -401,6 +403,10 @@ export default {
this.uploadTitle = '新增'
this.uploadForm.device_direction = 0
},
getBeforeUploadTxt(name) {
console.log(name)
this.beforeUploadTxt = name
},
// -
editUploadTheme(row) {
this.isEditTheme = true
@ -496,7 +502,7 @@ export default {
// this.uploadForm.orga_id = this.orga_id
this.uploadForm.store_type = 2
setTimeout(() => {
saveMaterial(this.uploadForm).then(res => {
FetchSaveMaterial(this.uploadForm).then(res => {
if (res.code === 200) {
this.$message({
message: '上传素材成功',
@ -652,9 +658,19 @@ export default {
.upload_source {
::v-deep .el-form-item__content{
display: flex;
position: relative;
}
.before_upload{
// position: absolute;
// left: 0;
// top: 126px;
width: 130px;
margin-left: 10px;
font-size: 12px;
line-height: 22px;
}
.source_cont{
margin-right: 20px;
margin-left: 20px;
p{
font-size: 12px;
padding: 0 10px;
@ -689,7 +705,7 @@ export default {
height: 34px;
font-size: 14px;
left: 50%;
top: 14px;
top: 21px;
margin-left: -50px;
}
#upFile{
@ -704,7 +720,7 @@ export default {
border: none;
background: linear-gradient(to right, #fc8c6f, #fa544e);
border-radius: 34px;
margin: 10px auto;
margin: 10px auto 0 auto;
}
}
.tag_list{

Loading…
Cancel
Save