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>
|
|
@ -199,12 +199,27 @@
|
||||||
v-model="journal.content"
|
v-model="journal.content"
|
||||||
placeholder="写点什么吧..."
|
placeholder="写点什么吧..."
|
||||||
/>
|
/>
|
||||||
</a-form-item>
|
</a-form-item>
|
||||||
<a-form-item>
|
|
||||||
<a-button
|
<!-- 日志图片上传 -->
|
||||||
type="primary"
|
<a-form-item v-show="showMoreOptions">
|
||||||
@click="handleCreateJournalClick"
|
<UploadPhoto></UploadPhoto>
|
||||||
>保存</a-button>
|
<!-- <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-item>
|
||||||
</a-form>
|
</a-form>
|
||||||
</a-card>
|
</a-card>
|
||||||
|
@ -317,7 +332,8 @@ import postApi from '@/api/post'
|
||||||
import logApi from '@/api/log'
|
import logApi from '@/api/log'
|
||||||
import adminApi from '@/api/admin'
|
import adminApi from '@/api/admin'
|
||||||
import journalApi from '@/api/journal'
|
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 {
|
export default {
|
||||||
name: 'Dashboard',
|
name: 'Dashboard',
|
||||||
mixins: [mixin, mixinDevice],
|
mixins: [mixin, mixinDevice],
|
||||||
|
@ -325,10 +341,12 @@ export default {
|
||||||
PageView,
|
PageView,
|
||||||
AnalysisCard,
|
AnalysisCard,
|
||||||
RecentCommentTab,
|
RecentCommentTab,
|
||||||
countTo
|
countTo,
|
||||||
|
UploadPhoto
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
|
showMoreOptions: false,
|
||||||
startVal: 0,
|
startVal: 0,
|
||||||
logType: logApi.logType,
|
logType: logApi.logType,
|
||||||
activityLoading: true,
|
activityLoading: true,
|
||||||
|
@ -397,7 +415,7 @@ export default {
|
||||||
}
|
}
|
||||||
next()
|
next()
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
loadOptions() {
|
loadOptions() {
|
||||||
optionApi.listAll(this.keys).then(response => {
|
optionApi.listAll(this.keys).then(response => {
|
||||||
this.options = response.data.data
|
this.options = response.data.data
|
||||||
|
@ -430,7 +448,11 @@ export default {
|
||||||
this.$message.success('发表成功!')
|
this.$message.success('发表成功!')
|
||||||
this.journal = {}
|
this.journal = {}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
handleUploadPhotoWallClick(){
|
||||||
|
// 是否显示上传照片墙组件
|
||||||
|
this.showMoreOptions = !this.showMoreOptions
|
||||||
|
},
|
||||||
handleShowLogDrawer() {
|
handleShowLogDrawer() {
|
||||||
this.logDrawerVisiable = true
|
this.logDrawerVisiable = true
|
||||||
this.loadLogs()
|
this.loadLogs()
|
||||||
|
@ -457,4 +479,12 @@ export default {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<style scoped="scoped">
|
||||||
|
.more-options-btn{
|
||||||
|
margin-left: 15px;
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
</style>
|
||||||
|
|
|
@ -138,24 +138,33 @@
|
||||||
>
|
>
|
||||||
<a-icon type="info-circle-o" />
|
<a-icon type="info-circle-o" />
|
||||||
</a-tooltip>
|
</a-tooltip>
|
||||||
</template>
|
</template>
|
||||||
<template slot="footer">
|
<template slot="footer">
|
||||||
<a-button
|
<a-button
|
||||||
key="submit"
|
key="submit"
|
||||||
type="primary"
|
type="primary"
|
||||||
@click="createOrUpdateJournal"
|
@click="createOrUpdateJournal"
|
||||||
>
|
>
|
||||||
发布
|
发布
|
||||||
</a-button>
|
</a-button>
|
||||||
</template>
|
</template>
|
||||||
<a-form layout="vertical">
|
<a-form layout="vertical">
|
||||||
<a-form-item>
|
<a-form-item>
|
||||||
<a-input
|
<a-input
|
||||||
type="textarea"
|
type="textarea"
|
||||||
:autosize="{ minRows: 8 }"
|
:autosize="{ minRows: 8 }"
|
||||||
v-model="journal.content"
|
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-form>
|
||||||
</a-modal>
|
</a-modal>
|
||||||
|
|
||||||
|
@ -231,12 +240,13 @@ import { mixin, mixinDevice } from '@/utils/mixin.js'
|
||||||
import journalApi from '@/api/journal'
|
import journalApi from '@/api/journal'
|
||||||
import journalCommentApi from '@/api/journalComment'
|
import journalCommentApi from '@/api/journalComment'
|
||||||
import userApi from '@/api/user'
|
import userApi from '@/api/user'
|
||||||
|
import UploadPhoto from '@/components/Upload/UploadPhoto.vue'
|
||||||
export default {
|
export default {
|
||||||
mixins: [mixin, mixinDevice],
|
mixins: [mixin, mixinDevice],
|
||||||
components: { JournalCommentTree },
|
components: { JournalCommentTree, UploadPhoto },
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
|
showMoreOptions: false,
|
||||||
title: '发表',
|
title: '发表',
|
||||||
listLoading: false,
|
listLoading: false,
|
||||||
visible: false,
|
visible: false,
|
||||||
|
@ -255,17 +265,38 @@ export default {
|
||||||
},
|
},
|
||||||
journals: [],
|
journals: [],
|
||||||
comments: [],
|
comments: [],
|
||||||
journal: {},
|
journal: {
|
||||||
|
id: null,
|
||||||
|
content: '',
|
||||||
|
photos: []
|
||||||
|
},
|
||||||
|
journalPhotos: [],
|
||||||
selectComment: null,
|
selectComment: null,
|
||||||
replyComment: {},
|
replyComment: {},
|
||||||
user: {}
|
user: {},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
this.loadJournals()
|
this.loadJournals()
|
||||||
this.loadUser()
|
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) {
|
loadJournals(isSearch) {
|
||||||
this.queryParam.page = this.pagination.page - 1
|
this.queryParam.page = this.pagination.page - 1
|
||||||
this.queryParam.size = this.pagination.size
|
this.queryParam.size = this.pagination.size
|
||||||
|
@ -329,7 +360,10 @@ export default {
|
||||||
this.handleCommentShow(this.journal)
|
this.handleCommentShow(this.journal)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
createOrUpdateJournal() {
|
createOrUpdateJournal() {
|
||||||
|
// 给属性填充数据
|
||||||
|
this.journal.photos = this.journalPhotos
|
||||||
|
|
||||||
if (this.journal.id) {
|
if (this.journal.id) {
|
||||||
journalApi.update(this.journal.id, this.journal).then(response => {
|
journalApi.update(this.journal.id, this.journal).then(response => {
|
||||||
this.$message.success('更新成功!')
|
this.$message.success('更新成功!')
|
||||||
|
@ -355,4 +389,11 @@ export default {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
<style scoped="scoped">
|
||||||
|
.more-options-btn{
|
||||||
|
margin-left: 15px;
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
</style>
|
||||||
|
|
Loading…
Reference in New Issue