Complete journal list.

pull/9/head
ruibaby 2019-04-26 01:37:19 +08:00
parent 13774a856f
commit 4389b0a2a7
4 changed files with 92 additions and 47 deletions

View File

@ -20,4 +20,12 @@ journalApi.create = (journal) => {
}) })
} }
journalApi.update = (journalId, journal) => {
return service({
url: `${baseUrl}/${journalId}`,
data: journal,
method: 'put'
})
}
export default journalApi export default journalApi

View File

@ -14,11 +14,11 @@ Vue.filter('NumberFormat', function(value) {
return intPartFormat return intPartFormat
}) })
Vue.filter('dayjs', function(dataStr, pattern = 'YYYY-MM-DD HH:mm:ss') { Vue.filter('dayjs', function(dataStr, pattern = 'YYYY-MM-DD HH:mm') {
return moment(dataStr).format(pattern) return moment(dataStr).format(pattern)
}) })
Vue.filter('moment', function(dataStr, pattern = 'YYYY-MM-DD HH:mm:ss') { Vue.filter('moment', function(dataStr, pattern = 'YYYY-MM-DD HH:mm') {
return moment(dataStr).format(pattern) return moment(dataStr).format(pattern)
}) })

View File

@ -46,6 +46,6 @@ export function timeAgo(time) {
if (days < 5) { if (days < 5) {
return days + ' 天前' return days + ' 天前'
} else { } else {
return moment(time).format('YYYY-MM-DD HH:mm:ss') return moment(time).format('YYYY-MM-DD HH:mm')
} }
} }

View File

@ -20,18 +20,6 @@
<a-input /> <a-input />
</a-form-item> </a-form-item>
</a-col> </a-col>
<a-col
:md="6"
:sm="24"
>
<a-form-item label="年月份">
<a-select placeholder="请选择年月">
<a-select-option value="2019-01">2019-01</a-select-option>
<a-select-option value="2019-02">2019-02</a-select-option>
<a-select-option value="2019-03">2019-03</a-select-option>
</a-select>
</a-form-item>
</a-col>
<a-col <a-col
:md="6" :md="6"
:sm="24" :sm="24"
@ -48,8 +36,11 @@
:sm="24" :sm="24"
> >
<span class="table-page-search-submitButtons"> <span class="table-page-search-submitButtons">
<a-button type="primary">查询</a-button> <a-button
<a-button style="margin-left: 8px;">重置</a-button> type="primary"
@click="loadJournals(true)"
>查询</a-button>
<a-button style="margin-left: 8px;" @click="resetParam"></a-button>
</span> </span>
</a-col> </a-col>
</a-row> </a-row>
@ -66,7 +57,7 @@
<div style="margin-top:15px"> <div style="margin-top:15px">
<a-list <a-list
itemLayout="vertical" itemLayout="vertical"
:pagination="pagination" :pagination="false"
:dataSource="journals" :dataSource="journals"
:loading="listLoading" :loading="listLoading"
> >
@ -75,22 +66,45 @@
slot-scope="item, index" slot-scope="item, index"
:key="index" :key="index"
> >
<a <template
slot="actions" slot="actions"
@click="handleEdit(item)" v-for="{type, text} in actions"
>编辑</a> >
<a slot="actions">删除</a> <span :key="type">
<a-list-item-meta :description="item.description"> <a-icon
:type="type"
style="margin-right: 8px"
/>
{{ text }}
</span>
</template>
<template slot="extra">
<a <a
slot="title" href="javascript:void(0);"
>{{ item.content }}</a> @click="handleEdit(item)"
>编辑</a>
<a-divider type="vertical" />
<a href="javascript:void(0);">删除</a>
</template>
<a-list-item-meta :description="item.content">
<span slot="title">{{ item.createTime | moment }}</span>
<a-avatar <a-avatar
slot="avatar" slot="avatar"
size="large" size="large"
src="https://gravatar.loli.net/avatar/7cc7f29278071bd4dce995612d428834?s=256&d=mm"
/> />
</a-list-item-meta> </a-list-item-meta>
{{ item.content }}
</a-list-item> </a-list-item>
<template>
<a-pagination
class="pagination"
:total="pagination.total"
:pageSizeOptions="['1', '2', '5', '10', '20', '50', '100']"
showSizeChanger
@showSizeChange="onPaginationChange"
@change="onPaginationChange"
/>
</template>
</a-list> </a-list>
</div> </div>
</a-card> </a-card>
@ -98,17 +112,23 @@
</a-row> </a-row>
<a-modal <a-modal
title="新建" :title="title"
v-model="visible" v-model="visible"
> >
<template slot="footer">
<a-button
key="submit"
type="primary"
@click="createOrUpdateJournal"
>
发布
</a-button>
</template>
<a-form layout="vertical"> <a-form layout="vertical">
<a-form-item label="标题:"> <a-form-item>
<a-input v-model="journal.title" />
</a-form-item>
<a-form-item label="内容:">
<a-input <a-input
type="textarea" type="textarea"
:autosize="{ minRows: 5 }" :autosize="{ minRows: 8 }"
v-model="journal.content" v-model="journal.content"
/> />
</a-form-item> </a-form-item>
@ -120,22 +140,10 @@
<script> <script>
import journalApi from '@/api/journal' import journalApi from '@/api/journal'
const listData = []
for (let i = 0; i < 50; i++) {
listData.push({
href: '#',
title: `Title ${i}`,
avatar: 'https://gravatar.loli.net/avatar/7cc7f29278071bd4dce995612d428834?s=256&d=mm',
description: '2019-04-12 09:00:00',
content:
'这是一条日志,这是一条日志,这是一条日志,这是一条日志,这是一条日志,这是一条日志,这是一条日志,这是一条日志,这是一条日志,这是一条日志,这是一条日志,这是一条日志,这是一条日志,这是一条日志,这是一条日志,这是一条日志'
})
}
export default { export default {
data() { data() {
return { return {
listData, title: '发表',
listLoading: false, listLoading: false,
visible: false, visible: false,
pagination: { pagination: {
@ -149,7 +157,7 @@ export default {
sort: null, sort: null,
keyword: null keyword: null
}, },
actions: [{ type: 'star-o', text: '156' }, { type: 'like-o', text: '156' }, { type: 'message', text: '2' }], actions: [{ type: 'like-o', text: '28031230' }, { type: 'message', text: '2' }],
journals: [], journals: [],
journal: {} journal: {}
} }
@ -173,14 +181,43 @@ export default {
}) })
}, },
handleNew() { handleNew() {
this.title = '新建'
this.visible = true this.visible = true
this.journal = {}
}, },
handleEdit(item) { handleEdit(item) {
this.title = '编辑'
this.journal = item this.journal = item
this.visible = true this.visible = true
},
createOrUpdateJournal() {
if (this.journal.id) {
journalApi.update(this.journal.id, this.journal).then(response => {
this.$message.success('更新成功!')
})
} else {
journalApi.create(this.journal).then(response => {
this.$message.success('发表成功!')
})
}
this.visible = false
this.loadJournals()
},
onPaginationChange(page, pageSize) {
this.$log.debug(`Current: ${page}, PageSize: ${pageSize}`)
this.pagination.page = page
this.pagination.size = pageSize
this.loadJournals()
},
resetParam() {
this.queryParam.keyword = null
this.loadJournals()
} }
} }
} }
</script> </script>
<style> <style scoped>
.pagination {
margin-top: 1rem;
}
</style> </style>