mirror of https://github.com/halo-dev/halo-admin
补充了日志九宫格图片上传功能
parent
ab66b9acb4
commit
9859fcfd74
|
@ -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>
|
|
@ -200,11 +200,26 @@
|
|||
placeholder="写点什么吧..."
|
||||
/>
|
||||
</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>
|
||||
|
@ -318,6 +333,7 @@ import logApi from '@/api/log'
|
|||
import adminApi from '@/api/admin'
|
||||
import journalApi from '@/api/journal'
|
||||
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 {
|
||||
showMoreOptions: false,
|
||||
startVal: 0,
|
||||
logType: logApi.logType,
|
||||
activityLoading: true,
|
||||
|
@ -431,6 +449,10 @@ export default {
|
|||
this.journal = {}
|
||||
})
|
||||
},
|
||||
handleUploadPhotoWallClick(){
|
||||
// 是否显示上传照片墙组件
|
||||
this.showMoreOptions = !this.showMoreOptions
|
||||
},
|
||||
handleShowLogDrawer() {
|
||||
this.logDrawerVisiable = true
|
||||
this.loadLogs()
|
||||
|
@ -458,3 +480,11 @@ export default {
|
|||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped="scoped">
|
||||
.more-options-btn{
|
||||
margin-left: 15px;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
</style>
|
||||
|
|
|
@ -156,6 +156,15 @@
|
|||
v-model="journal.content"
|
||||
/>
|
||||
</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 {
|
||||
showMoreOptions: false,
|
||||
title: '发表',
|
||||
listLoading: false,
|
||||
visible: false,
|
||||
|
@ -255,10 +265,15 @@ export default {
|
|||
},
|
||||
journals: [],
|
||||
comments: [],
|
||||
journal: {},
|
||||
journal: {
|
||||
id: null,
|
||||
content: '',
|
||||
photos: []
|
||||
},
|
||||
journalPhotos: [],
|
||||
selectComment: null,
|
||||
replyComment: {},
|
||||
user: {}
|
||||
user: {},
|
||||
}
|
||||
},
|
||||
created() {
|
||||
|
@ -266,6 +281,22 @@ export default {
|
|||
this.loadUser()
|
||||
},
|
||||
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
|
||||
|
@ -330,6 +361,9 @@ export default {
|
|||
})
|
||||
},
|
||||
createOrUpdateJournal() {
|
||||
// 给属性填充数据
|
||||
this.journal.photos = this.journalPhotos
|
||||
|
||||
if (this.journal.id) {
|
||||
journalApi.update(this.journal.id, this.journal).then(response => {
|
||||
this.$message.success('更新成功!')
|
||||
|
@ -356,3 +390,10 @@ export default {
|
|||
}
|
||||
}
|
||||
</script>
|
||||
<style scoped="scoped">
|
||||
.more-options-btn{
|
||||
margin-left: 15px;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
</style>
|
||||
|
|
Loading…
Reference in New Issue