补充了日志九宫格图片上传功能

pull/25/head
guqing 2019-06-12 21:29:48 +08:00
parent ab66b9acb4
commit 9859fcfd74
3 changed files with 196 additions and 25 deletions

View File

@ -0,0 +1,100 @@
<template>
<div class="clearfix">
<a-upload
:name="name"
:customRequest="handleUpload"
listType="picture-card"
:fileList="fileList"
@preview="handlePreview"
@change="handleChange"
>
<div v-if="fileList.length < 9" id="plus-photo-uploadbox">
<a-icon type="plus" />
<div class="ant-upload-text">Upload</div>
</div>
</a-upload>
<a-modal :visible="previewVisible" :footer="null" @cancel="handleCancel">
<img alt="example" style="width: 100%" :src="previewImage" />
</a-modal>
</div>
</template>
<script>
import axios from 'axios'
import attachmentApi from '@/api/attachment'
export default {
data () {
return {
name: 'file',
previewVisible: false,
previewImage: '',
fileList: [],
uploadHandler: attachmentApi.upload
}
},
methods: {
handleCancel () {
this.previewVisible = false
},
handlePreview (file) {
this.previewImage = file.url || file.thumbUrl
this.previewVisible = true
},
handleChange ({ fileList }) {
this.fileList = fileList
},
handleUpload(option) {
this.$log.debug('Uploading option', option)
const CancelToken = axios.CancelToken
const source = CancelToken.source()
const data = new FormData()
data.append(this.name, option.file)
this.uploadHandler(
data,
progressEvent => {
if (progressEvent.total > 0) {
progressEvent.percent = (progressEvent.loaded / progressEvent.total) * 100
}
this.$log.debug('Uploading percent: ', progressEvent.percent)
option.onProgress(progressEvent)
},
source.token,
option.file
)
.then(response => {
this.$log.debug('Uploaded successfully', response)
option.onSuccess(response, option.file)
this.$emit('success', response, option.file)
})
.catch(error => {
this.$log.debug('Failed to upload file', error)
option.onError(error, error.response)
this.$emit('failure', error, option.file)
})
return {
abort: () => {
this.$log.debug('Upload operation aborted by the user')
source.cancel('Upload operation canceled by the user.')
}
}
}
},
}
</script>
<style>
/* you can make up upload button and sample style by using stylesheets */
.ant-upload-select-picture-card i {
font-size: 32px;
color: #999;
}
.ant-upload-select-picture-card .ant-upload-text {
margin-top: 8px;
color: #666;
}
.ant-upload-list-picture-card {
/* 将浮动恢复为默认值,避免出现纵向换行情况 */
float: initial;
}
</style>

View File

@ -199,12 +199,27 @@
v-model="journal.content"
placeholder="写点什么吧..."
/>
</a-form-item>
<a-form-item>
<a-button
type="primary"
@click="handleCreateJournalClick"
>保存</a-button>
</a-form-item>
<!-- 日志图片上传 -->
<a-form-item v-show="showMoreOptions">
<UploadPhoto></UploadPhoto>
<!-- <a-collapse :bordered="false">
<a-collapse-panel key="1">
</a-collapse-panel>
</a-collapse> -->
</a-form-item>
<a-form-item>
<a-button
type="primary"
@click="handleCreateJournalClick"
>保存</a-button>
<a href="javascript:;" class="more-options-btn"
type="default"
@click="handleUploadPhotoWallClick"
>更多选项<a-icon type="down" /></a>
</a-form-item>
</a-form>
</a-card>
@ -317,7 +332,8 @@ import postApi from '@/api/post'
import logApi from '@/api/log'
import adminApi from '@/api/admin'
import journalApi from '@/api/journal'
import countTo from 'vue-count-to'
import countTo from 'vue-count-to'
import UploadPhoto from '../../components/Upload/UploadPhoto.vue'
export default {
name: 'Dashboard',
mixins: [mixin, mixinDevice],
@ -325,10 +341,12 @@ export default {
PageView,
AnalysisCard,
RecentCommentTab,
countTo
countTo,
UploadPhoto
},
data() {
return {
return {
showMoreOptions: false,
startVal: 0,
logType: logApi.logType,
activityLoading: true,
@ -397,7 +415,7 @@ export default {
}
next()
},
methods: {
methods: {
loadOptions() {
optionApi.listAll(this.keys).then(response => {
this.options = response.data.data
@ -430,7 +448,11 @@ export default {
this.$message.success('发表成功!')
this.journal = {}
})
},
},
handleUploadPhotoWallClick(){
//
this.showMoreOptions = !this.showMoreOptions
},
handleShowLogDrawer() {
this.logDrawerVisiable = true
this.loadLogs()
@ -457,4 +479,12 @@ export default {
}
}
}
</script>
</script>
<style scoped="scoped">
.more-options-btn{
margin-left: 15px;
text-decoration: none;
}
</style>

View File

@ -138,24 +138,33 @@
>
<a-icon type="info-circle-o" />
</a-tooltip>
</template>
</template>
<template slot="footer">
<a-button
key="submit"
type="primary"
@click="createOrUpdateJournal"
>
>
发布
</a-button>
</template>
</template>
<a-form layout="vertical">
<a-form-item>
<a-input
type="textarea"
:autosize="{ minRows: 8 }"
v-model="journal.content"
/>
</a-form-item>
/>
</a-form-item>
<a-form-item v-show="showMoreOptions">
<UploadPhoto @success="handlerPhotoUploadSuccess"></UploadPhoto>
</a-form-item>
<a-form-item>
<a href="javascript:;" class="more-options-btn"
type="default"
@click="handleUploadPhotoWallClick"
>更多选项<a-icon type="down" /></a>
</a-form-item>
</a-form>
</a-modal>
@ -231,12 +240,13 @@ import { mixin, mixinDevice } from '@/utils/mixin.js'
import journalApi from '@/api/journal'
import journalCommentApi from '@/api/journalComment'
import userApi from '@/api/user'
import UploadPhoto from '@/components/Upload/UploadPhoto.vue'
export default {
mixins: [mixin, mixinDevice],
components: { JournalCommentTree },
components: { JournalCommentTree, UploadPhoto },
data() {
return {
return {
showMoreOptions: false,
title: '发表',
listLoading: false,
visible: false,
@ -255,17 +265,38 @@ export default {
},
journals: [],
comments: [],
journal: {},
journal: {
id: null,
content: '',
photos: []
},
journalPhotos: [],
selectComment: null,
replyComment: {},
user: {}
user: {},
}
},
created() {
this.loadJournals()
this.loadUser()
},
methods: {
methods: {
handlerPhotoUploadSuccess(response, file){
var callData = response.data.data
var photo = {
name: callData.name,
url: callData.path,
thumbnail: callData.thumbPath,
suffix: callData.suffix,
width: callData.width,
height: callData.height
}
this.journalPhotos.push(photo)
},
handleUploadPhotoWallClick(){
//
this.showMoreOptions = !this.showMoreOptions
},
loadJournals(isSearch) {
this.queryParam.page = this.pagination.page - 1
this.queryParam.size = this.pagination.size
@ -329,7 +360,10 @@ export default {
this.handleCommentShow(this.journal)
})
},
createOrUpdateJournal() {
createOrUpdateJournal() {
//
this.journal.photos = this.journalPhotos
if (this.journal.id) {
journalApi.update(this.journal.id, this.journal).then(response => {
this.$message.success('更新成功!')
@ -355,4 +389,11 @@ export default {
}
}
}
</script>
</script>
<style scoped="scoped">
.more-options-btn{
margin-left: 15px;
text-decoration: none;
}
</style>