Complete photo list.

pull/9/head
ruibaby 2019-04-25 23:27:58 +08:00
parent 4bf752b23d
commit 0f2f72a1e3
2 changed files with 85 additions and 26 deletions

View File

@ -20,6 +20,14 @@ photoApi.create = (photo) => {
}) })
} }
photoApi.update = (photoId, photo) => {
return service({
url: `${baseUrl}/${photoId}`,
method: 'put',
data: photo
})
}
photoApi.delete = photoId => { photoApi.delete = photoId => {
return service({ return service({
url: `${baseUrl}/${photoId}`, url: `${baseUrl}/${photoId}`,

View File

@ -54,6 +54,7 @@
<a-button <a-button
type="primary" type="primary"
icon="plus" icon="plus"
@click="handleAddClick"
>添加</a-button> >添加</a-button>
</div> </div>
</a-card> </a-card>
@ -74,7 +75,7 @@
hoverable hoverable
@click="showDrawer(item)" @click="showDrawer(item)"
> >
<div class="attach-thumb"> <div class="photo-thumb">
<img :src="item.thumbnail"> <img :src="item.thumbnail">
</div> </div>
<a-card-meta> <a-card-meta>
@ -120,8 +121,11 @@
:loading="drawerLoading" :loading="drawerLoading"
:paragraph="{rows: 8}" :paragraph="{rows: 8}"
> >
<div class="attach-detail-img"> <div class="photo-detail-img">
<img :src="photo.url"> <img
:src="photo.url || 'https://os.alipayobjects.com/rmsportal/mgesTPFxodmIwpi.png'"
@click="showThumbDrawer"
>
</div> </div>
</a-skeleton> </a-skeleton>
</a-col> </a-col>
@ -133,6 +137,23 @@
:paragraph="{rows: 8}" :paragraph="{rows: 8}"
> >
<a-list itemLayout="horizontal"> <a-list itemLayout="horizontal">
<a-list-item>
<a-list-item-meta>
<template
slot="description"
v-if="editable"
>
<a-input v-model="photo.thumbnail" />
</template>
<template
slot="description"
v-else
>{{ photo.thumbnail }}</template>
<span slot="title">
缩略图地址
</span>
</a-list-item-meta>
</a-list-item>
<a-list-item> <a-list-item>
<a-list-item-meta> <a-list-item-meta>
<template <template
@ -218,6 +239,11 @@
</a-skeleton> </a-skeleton>
</a-col> </a-col>
</a-row> </a-row>
<AttachmentSelectDrawer
v-model="thumDrawerVisible"
@listenToSelect="selectPhotoThumb"
:drawerWidth="460"
/>
<a-divider /> <a-divider />
<div class="bottom-control"> <div class="bottom-control">
<a-button <a-button
@ -229,7 +255,7 @@
<a-button <a-button
type="primary" type="primary"
style="marginRight: 8px" style="marginRight: 8px"
@click="handleEditClick" @click="handleCreateOrUpdate"
v-else v-else
>保存</a-button> >保存</a-button>
<a-popconfirm <a-popconfirm
@ -246,16 +272,21 @@
</template> </template>
<script> <script>
import AttachmentSelectDrawer from '../../attachment/components/AttachmentSelectDrawer'
import { mixin, mixinDevice } from '@/utils/mixin.js' import { mixin, mixinDevice } from '@/utils/mixin.js'
import photoApi from '@/api/photo' import photoApi from '@/api/photo'
export default { export default {
components: {
AttachmentSelectDrawer
},
mixins: [mixin, mixinDevice], mixins: [mixin, mixinDevice],
data() { data() {
return { return {
drawerVisiable: false, drawerVisiable: false,
drawerLoading: false, drawerLoading: false,
listLoading: true, listLoading: true,
thumDrawerVisible: false,
photo: {}, photo: {},
photos: [], photos: [],
editable: false, editable: false,
@ -268,9 +299,7 @@ export default {
page: 0, page: 0,
size: 18, size: 18,
sort: null, sort: null,
keyword: null, keyword: null
mediaType: null,
attachmentType: null
} }
} }
}, },
@ -292,6 +321,19 @@ export default {
this.listLoading = false this.listLoading = false
}) })
}, },
handleCreateOrUpdate() {
if (this.photo.id) {
photoApi.update(this.photo.id, this.photo).then(response => {
this.$message.success('照片更新成功')
})
} else {
photoApi.create(this.photo).then(response => {
this.$message.success('照片添加成功')
this.photo = response.data.data
})
}
this.editable = false
},
showDrawer(photo) { showDrawer(photo) {
this.photo = photo this.photo = photo
this.drawerVisiable = true this.drawerVisiable = true
@ -302,26 +344,35 @@ export default {
this.pagination.size = size this.pagination.size = size
this.loadPhotos() this.loadPhotos()
}, },
handleAddClick() {
this.editable = true
this.drawerVisiable = true
},
handleEditClick() { handleEditClick() {
this.editable = true this.editable = true
}, },
handleDeletePhoto() { handleDeletePhoto() {
photoApi.delete(this.photo.id).then(response => { photoApi.delete(this.photo.id).then(response => {
this.$message.success('删除成功!') this.$message.success('删除成功!')
this.onClose() this.onDrawerClose()
this.loadPhotos()
}) })
}, },
showThumbDrawer() {
this.thumDrawerVisible = true
},
selectPhotoThumb(data) {
this.photo.url = data.path
this.thumDrawerVisible = false
},
resetParam() { resetParam() {
this.queryParam.keyword = null this.queryParam.keyword = null
this.queryParam.mediaType = null
this.queryParam.attachmentType = null
this.loadPhotos()
},
handleDelete(attachment) {
this.loadPhotos() this.loadPhotos()
}, },
onDrawerClose() { onDrawerClose() {
this.drawerVisiable = false this.drawerVisiable = false
this.photo = {}
this.editable = false
} }
} }
} }
@ -336,7 +387,7 @@ export default {
padding-bottom: 12px; padding-bottom: 12px;
} }
.attach-thumb { .photo-thumb {
width: 100%; width: 100%;
margin: 0 auto; margin: 0 auto;
position: relative; position: relative;
@ -355,7 +406,7 @@ export default {
padding: 0.8rem; padding: 0.8rem;
} }
.attach-detail-img img { .photo-detail-img img {
width: 100%; width: 100%;
} }