mirror of https://github.com/halo-dev/halo-admin
Reactor util.js.
parent
ae5ffd9d3a
commit
a98566e4cd
|
@ -0,0 +1,23 @@
|
|||
import service from '@/utils/service'
|
||||
|
||||
const baseUrl = '/api/admin/journals'
|
||||
|
||||
const journalApi = {}
|
||||
|
||||
journalApi.query = params => {
|
||||
return service({
|
||||
url: baseUrl,
|
||||
params: params,
|
||||
method: 'get'
|
||||
})
|
||||
}
|
||||
|
||||
journalApi.create = (journal) => {
|
||||
return service({
|
||||
url: baseUrl,
|
||||
data: journal,
|
||||
method: 'post'
|
||||
})
|
||||
}
|
||||
|
||||
export default journalApi
|
|
@ -1,3 +1,5 @@
|
|||
import moment from 'moment'
|
||||
import 'moment/locale/zh-cn'
|
||||
/**
|
||||
* 触发 window.resize
|
||||
*/
|
||||
|
@ -22,24 +24,28 @@ export function removeLoadingAnimate(id = '', timeout = 1500) {
|
|||
}, timeout)
|
||||
}
|
||||
|
||||
function pluralize(time, label) {
|
||||
if (time === 1) {
|
||||
return time + label
|
||||
}
|
||||
return time + label
|
||||
}
|
||||
|
||||
/**
|
||||
* time ago
|
||||
* @param {*} time
|
||||
*/
|
||||
export function timeAgo(time) {
|
||||
const between = (Date.now() - Number(time)) / 1000
|
||||
if (between < 3600) {
|
||||
return pluralize(~~(between / 60), ' 分钟前')
|
||||
} else if (between < 86400) {
|
||||
return pluralize(~~(between / 3600), ' 小时前')
|
||||
var currentTime = new Date().getTime()
|
||||
var between = currentTime - time
|
||||
var days = Math.floor(between / (24 * 3600 * 1000))
|
||||
if (days === 0) {
|
||||
var leave1 = between % (24 * 3600 * 1000)
|
||||
var hours = Math.floor(leave1 / (3600 * 1000))
|
||||
if (hours === 0) {
|
||||
var leave2 = leave1 % (3600 * 1000)
|
||||
var minutes = Math.floor(leave2 / (60 * 1000))
|
||||
if (minutes === 0) {
|
||||
var leave3 = leave2 % (60 * 1000)
|
||||
var seconds = Math.round(leave3 / 1000)
|
||||
return seconds + ' 秒前'
|
||||
}
|
||||
return minutes + ' 分钟前'
|
||||
}
|
||||
return hours + ' 小时前'
|
||||
}
|
||||
if (days < 5) {
|
||||
return days + ' 天前'
|
||||
} else {
|
||||
return pluralize(~~(between / 86400), ' 天前')
|
||||
return moment(time).format('YYYY-MM-DD HH:mm:ss')
|
||||
}
|
||||
}
|
||||
|
|
|
@ -67,7 +67,8 @@
|
|||
<a-list
|
||||
itemLayout="vertical"
|
||||
:pagination="pagination"
|
||||
:dataSource="listData"
|
||||
:dataSource="journals"
|
||||
:loading="listLoading"
|
||||
>
|
||||
<a-list-item
|
||||
slot="renderItem"
|
||||
|
@ -119,6 +120,8 @@
|
|||
</template>
|
||||
|
||||
<script>
|
||||
import journalApi from '@/api/journal'
|
||||
|
||||
const listData = []
|
||||
for (let i = 0; i < 50; i++) {
|
||||
listData.push({
|
||||
|
@ -135,18 +138,41 @@ export default {
|
|||
data() {
|
||||
return {
|
||||
listData,
|
||||
listLoading: false,
|
||||
visible: false,
|
||||
pagination: {
|
||||
onChange: page => {
|
||||
console.log(page)
|
||||
},
|
||||
pageSize: 10
|
||||
page: 1,
|
||||
size: 10,
|
||||
sort: null
|
||||
},
|
||||
queryParam: {
|
||||
page: 0,
|
||||
size: 10,
|
||||
sort: null,
|
||||
keyword: null
|
||||
},
|
||||
actions: [{ type: 'star-o', text: '156' }, { type: 'like-o', text: '156' }, { type: 'message', text: '2' }],
|
||||
journal: {}
|
||||
journals: {}
|
||||
}
|
||||
},
|
||||
created() {
|
||||
this.loadJournals()
|
||||
},
|
||||
methods: {
|
||||
loadJournals(isSearch) {
|
||||
this.queryParam.page = this.pagination.page - 1
|
||||
this.queryParam.size = this.pagination.size
|
||||
this.queryParam.sort = this.pagination.sort
|
||||
if (isSearch) {
|
||||
this.queryParam.page = 0
|
||||
}
|
||||
this.listLoading = true
|
||||
journalApi.query(this.queryParam).then(response => {
|
||||
this.journals = response.data.data.content
|
||||
this.pagination.total = response.data.data.total
|
||||
this.listLoading = false
|
||||
})
|
||||
},
|
||||
handleNew() {
|
||||
this.visible = true
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue