✨ 消息中心模块
This commit is contained in:
parent
129d40d0bf
commit
e48475bba3
91
components/common/notification/list.vue
Normal file
91
components/common/notification/list.vue
Normal file
@ -0,0 +1,91 @@
|
||||
<template>
|
||||
<client-only>
|
||||
<el-row>
|
||||
<el-col v-for="notification in notifications.notifications" :key="notification.idNotification">
|
||||
<el-col v-if="notification.dataType == 0">
|
||||
<el-col :xs="9" :sm="11" :xl="11">
|
||||
<el-link :underline="false" @click="onRouter(notification)" style="font-size: 1.1em;"
|
||||
v-html="notification.dataSummary"></el-link>
|
||||
<el-col>{{ notification.createdTime }}</el-col>
|
||||
</el-col>
|
||||
<el-col :xs="3" :sm="1" :xl="1" class="mr-3">
|
||||
<el-link v-if="notification.hasRead === '0'" :underline="false" @click="read(notification.idNotification)">
|
||||
<i class="el-icon-check"></i>
|
||||
</el-link>
|
||||
</el-col>
|
||||
</el-col>
|
||||
<el-col v-else-if="notification.dataType == 1">
|
||||
<el-col :xs="9" :sm="11" :xl="11">
|
||||
<el-link :underline="false" style="font-size: 1.1em;" v-html="notification.dataSummary"></el-link>
|
||||
<el-col>{{ notification.createdTime }}</el-col>
|
||||
</el-col>
|
||||
<el-col :xs="3" :sm="1" :xl="1" class="mr-3">
|
||||
<el-link v-if="notification.hasRead === '0'" :underline="false" @click="read(notification.idNotification)">
|
||||
<i class="el-icon-check"></i>
|
||||
</el-link>
|
||||
</el-col>
|
||||
</el-col>
|
||||
<el-col v-else>
|
||||
<el-col :xs="21" :sm="23" :xl="23">
|
||||
<el-link :underline="false" style="font-size: 1.1em;" v-html="notification.dataSummary"></el-link>
|
||||
<el-col>{{ notification.createdTime }}</el-col>
|
||||
</el-col>
|
||||
<el-col :xs="3" :sm="1" :xl="1" class="text-right" style="padding-right: 1rem;">
|
||||
<el-link v-if="notification.hasRead === '0'" :underline="false" @click="read(notification.idNotification)">
|
||||
<i class="el-icon-check" style="font-weight: bold;"></i>
|
||||
</el-link>
|
||||
</el-col>
|
||||
</el-col>
|
||||
<el-col>
|
||||
<el-divider></el-divider>
|
||||
</el-col>
|
||||
</el-col>
|
||||
<el-col>
|
||||
<div class="vertical-container text-center">
|
||||
<el-pagination v-show="notifications.pagination.total > 10" v-model="notifications.pagination"
|
||||
layout="prev, pager, next"
|
||||
:current-page="notifications.pagination.currentPage"
|
||||
:total="notifications.pagination.total"
|
||||
@current-change="currentChange">
|
||||
</el-pagination>
|
||||
</div>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</client-only>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
name: "NotificationList",
|
||||
props: {
|
||||
notifications: {
|
||||
type: Object
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
currentChange(page) {
|
||||
this.$emit('currentChange', page);
|
||||
},
|
||||
read(id) {
|
||||
let _ts = this;
|
||||
this.$axios.$put('/api/notification/read/' + id).then(function () {
|
||||
_ts.currentChange(1);
|
||||
});
|
||||
},
|
||||
onRouter(notification) {
|
||||
if ('0' === notification.dataType) {
|
||||
if (notification.hasRead === '0') {
|
||||
this.read(notification.idNotification);
|
||||
}
|
||||
this.$router.push({
|
||||
path: '/article/' + notification.dataId
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
</style>
|
44
pages/notification.vue
Normal file
44
pages/notification.vue
Normal file
@ -0,0 +1,44 @@
|
||||
<template>
|
||||
<el-row class="wrapper">
|
||||
<el-col style="margin-bottom: 1rem;">
|
||||
<h1>通知</h1>
|
||||
</el-col>
|
||||
<notification-list :notifications="notifications" @currentChange="currentChangeNotification"></notification-list>
|
||||
</el-row>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import NotificationList from '~/components/common/notification/list';
|
||||
import {mapState} from 'vuex';
|
||||
|
||||
export default {
|
||||
name: "Notification",
|
||||
components: {
|
||||
NotificationList
|
||||
},
|
||||
fetch({store, error}) {
|
||||
return Promise.all([
|
||||
store
|
||||
.dispatch('notification/fetchList')
|
||||
.catch(err => error({statusCode: 404}))
|
||||
])
|
||||
},
|
||||
computed: {
|
||||
...mapState({
|
||||
notifications: state => state.notification.list.data,
|
||||
user: state => state.oauth
|
||||
})
|
||||
},
|
||||
methods: {
|
||||
currentChangeNotification(page) {
|
||||
this.$store.dispatch('notification/fetchList', {
|
||||
page: page
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
</style>
|
52
store/notification.js
Normal file
52
store/notification.js
Normal file
@ -0,0 +1,52 @@
|
||||
export const NOTIFICATION_API_PATH = '/api/notification'
|
||||
|
||||
const getDefaultListData = () => {
|
||||
return {
|
||||
notifications: [],
|
||||
pagination: {}
|
||||
}
|
||||
}
|
||||
|
||||
export const state = () => {
|
||||
return {
|
||||
list: {
|
||||
fetching: false,
|
||||
data: getDefaultListData()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const mutations = {
|
||||
// 消息列表
|
||||
updateListFetching(state, action) {
|
||||
state.list.fetching = action
|
||||
},
|
||||
updateListData(state, action) {
|
||||
state.list.data = action
|
||||
}
|
||||
}
|
||||
|
||||
export const actions = {
|
||||
// 获取消息列表
|
||||
fetchList({commit}, params = {}) {
|
||||
// 清空已有数据
|
||||
commit('updateListData', getDefaultListData())
|
||||
commit('updateListFetching', true)
|
||||
let data = {
|
||||
page: params.page || 1
|
||||
}
|
||||
|
||||
return this.$axios
|
||||
.$get(`${NOTIFICATION_API_PATH}/all`, {
|
||||
params: data
|
||||
})
|
||||
.then(response => {
|
||||
commit('updateListFetching', false);
|
||||
commit('updateListData', response);
|
||||
})
|
||||
.catch(error => {
|
||||
console.log(error);
|
||||
commit('updateListFetching', false);
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user