Commit 4be7af52 authored by xhx's avatar xhx

消息

parent 1b9bb8e2
...@@ -4,7 +4,8 @@ const columns:Array<column>= ...@@ -4,7 +4,8 @@ const columns:Array<column>=
{ {
title:'发布时间', title:'发布时间',
align:'center', align:'center',
dataIndex:'time' dataIndex:'time',
scopedSlots: { customRender: 'time' },
}, },
{ {
title:'消息标题', title:'消息标题',
...@@ -20,12 +21,14 @@ const columns:Array<column>= ...@@ -20,12 +21,14 @@ const columns:Array<column>=
{ {
title:'显示类型', title:'显示类型',
align:'center', align:'center',
dataIndex:'type' dataIndex:'type',
scopedSlots: { customRender: 'type' },
}, },
{ {
title:'状态', title:'状态',
align:'center', align:'center',
dataIndex:'state' dataIndex:'state',
scopedSlots: { customRender: 'status' },
}, },
{ {
title:'操作', title:'操作',
......
import baseAxios from '../index'
export default class NotifyService {
static instance: NotifyService
static getInstance() {
if (!NotifyService.instance) {
NotifyService.instance = new NotifyService()
}
return NotifyService.instance
}
/**
* 新增消息
* @param data
* @returns
*/
addNotify(data: {
content: string,
notify_type: number,
title: string
}) {
return baseAxios({
url: '/notify/admin/add',
method: 'post',
data,
})
}
/**
* 删除消息
* @param uuid
* @returns
*/
removeNotify(uuid: string) {
return baseAxios({
url: '/notify/admin/delete',
method: 'delete',
params: {
uuid
},
})
}
/**
* 消息列表
* @param data
* @returns
*/
notifyList(data: {
end_time?: number,
limit: number,
notify_status: number,
notify_type: number,
offset: number,
start_time?: number
}) {
return baseAxios({
url: '/notify/admin/list',
method: 'post',
data,
})
}
/**
* 修改消息
* @param data
* @returns
*/
modifyNotify(data: {
content: string,
notify_type: number,
title: string,
uuid: string
}) {
return baseAxios({
url: '/notify/admin/modify',
method: 'post',
data,
})
}
/**
* 修改消息状态
* @param data
* @returns
*/
modifyNotifyStatus(data: {
notify_status: number,
uuid: string
}) {
return baseAxios({
url: '/notify/admin/modify/status',
method: 'post',
data,
})
}
}
...@@ -3,8 +3,8 @@ ...@@ -3,8 +3,8 @@
<p class=" text-2xl font-bold mb-5">消息管理</p> <p class=" text-2xl font-bold mb-5">消息管理</p>
<!-- 消息分类 --> <!-- 消息分类 -->
<span class=" mr-3">消息分类</span> <span class=" mr-3">消息分类</span>
<a-select :default-value="msgType[0]" style="width: 120px; margin-right:10px;"> <a-select :default-value="1" style="width: 120px; margin-right:10px;">
<a-select-option v-for="(type,i) in msgType" :key="i">{{type}}</a-select-option> <a-select-option v-for="type in msgType" :key="type.value">{{ type.label }}</a-select-option>
</a-select> </a-select>
<!-- 操作 --> <!-- 操作 -->
<a-button type="primary" style=" margin-right:10px;" @click="query">查询</a-button> <a-button type="primary" style=" margin-right:10px;" @click="query">查询</a-button>
...@@ -12,12 +12,12 @@ ...@@ -12,12 +12,12 @@
<!-- 发布弹窗 --> <!-- 发布弹窗 -->
<a-modal v-model="show" title="发布消息" :centered="true" footer=""> <a-modal v-model="show" title="发布消息" :centered="true" footer="">
<a-form-model :model="form" :label-col="labelCol" :wrapper-col="wrapperCol" ref="ruleForm" :rules="rules"> <a-form-model :model="form" :label-col="labelCol" :wrapper-col="wrapperCol" ref="ruleForm" :rules="rules">
<a-form-model-item label="模板名称" :required="true" prop="module"> <!-- <a-form-model-item label="模板名称" :required="true" prop="module">
<a-input v-model="form.module" placeholder="请输入模板名称" style="width: 200px"/> <a-input v-model="form.module" placeholder="请输入模板名称" style="width: 200px"/>
</a-form-model-item> </a-form-model-item> -->
<a-form-model-item label="消息分类" :required="true" prop="type"> <a-form-model-item label="消息分类" :required="true" prop="type">
<a-select :default-value="msgType[0]" style="width: 200px" v-model="form.type"> <a-select :default-value="1" style="width: 200px" v-model="form.type">
<a-select-option v-for="(type,i) in msgType" :key="i">{{type}}</a-select-option> <a-select-option v-for="type in msgType" :key="type.value">{{type.label}}</a-select-option>
</a-select> </a-select>
</a-form-model-item> </a-form-model-item>
<a-form-model-item label="消息标题" :required="true" prop="title" > <a-form-model-item label="消息标题" :required="true" prop="title" >
...@@ -38,23 +38,46 @@ ...@@ -38,23 +38,46 @@
<p class=" text-base">{{current.content}}</p> <p class=" text-base">{{current.content}}</p>
</a-modal> </a-modal>
<!-- 消息列表 --> <!-- 消息列表 -->
<a-table :columns="columns" :data-source="list" style=" text-align: center; margin-top:40px;" bordered > <a-table
:columns="columns"
:data-source="list"
style=" text-align: center; margin-top:40px;"
bordered
:pagination="pagination"
@change="tableChange">
<!-- 发布时间 -->
<span slot="time" slot-scope="text,record">
{{ record.created_at | format }}
</span>
<!-- 新闻内容 --> <!-- 新闻内容 -->
<span slot="content" slot-scope="text,record"> <span slot="content" slot-scope="text,record">
<a href="javascript:;" @click="showModal(record)">查看</a> <a href="javascript:;" @click="showModal(record)">查看</a>
</span> </span>
<!-- 显示类型 -->
<span slot="type" slot-scope="text,record">
{{ record.notify_type === 1 ? '滚动通知' : '系统消息' }}
</span>
<!-- 状态 -->
<span slot="status" slot-scope="text,record">
{{ record.notify_status === 1 ? '待发布' : '已发布' }}
</span>
<!-- 操作 --> <!-- 操作 -->
<span slot="action" slot-scope="text,record"> <span slot="action" slot-scope="text,record">
<a v-if="record.state=='已下架'" <a v-if="record.notify_status==1"
@click="add(record.key)"> @click="add(record)">
上架 上架
</a> </a>
<a v-else <a v-else
@click="remove(record.key)"> @click="remove(record)">
下架 下架
</a> </a>
<a-divider type="vertical" /> <a-divider type="vertical" />
<a @click="onDelete(record.key)"> <a v-show="record.notify_status === 1"
@click="onEdit(record)">
编辑
</a>
<a-divider v-show="record.notify_status === 1" type="vertical" />
<a @click="onDelete(record)">
删除 删除
</a> </a>
</span> </span>
...@@ -76,14 +99,22 @@ ...@@ -76,14 +99,22 @@
<script lang="ts"> <script lang="ts">
import Vue from 'vue'; import Vue from 'vue';
import { columns } from '@/const/columns/msgColumns' import { columns } from '@/const/columns/msgColumns'
import { FormModel } from 'ant-design-vue' import { FormModel, message } from 'ant-design-vue'
import { msg } from '@/types/msg' import { msg } from '@/types/msg'
import { msgList } from '@/mock/index'
import { modal } from './const' import { modal } from './const'
import timerange from '@/components/TimePicker/index.vue' import timerange from '@/components/TimePicker/index.vue'
import Notify from '@/service/Notify/index'
import Filter from '@/filter/index'
const notify = new Notify()
export default Vue.extend({ export default Vue.extend({
components:{ timerange }, components:{ timerange },
filters: {
format(value: string) {
return Filter.formatDate(value)
}
},
computed:{ computed:{
columns(){ columns(){
return columns return columns
...@@ -93,46 +124,111 @@ export default Vue.extend({ ...@@ -93,46 +124,111 @@ export default Vue.extend({
msgType:{ msgType:{
type:Array, type:Array,
default(){ default(){
return ['滚动通知','系统消息'] return [
// {
// label: '全部',
// value: 0
// },
{
label: '滚动通知',
value: 1
},
{
label: '系统消息',
value: 2
}
]
} }
} }
}, },
created() {
this.getList()
},
methods:{ methods:{
getList() {
notify.notifyList({
limit: this.pagination.defaultPageSize,
offset: (this.pagination.current - 1) * this.pagination.defaultPageSize,
notify_status: 0,
// notify_type: this.form.type
notify_type: 0
}).then(res => {
this.list = res.data.items
this.pagination.total = res.data.total
})
},
tableChange(e: {current: number}) {
this.pagination.current = e.current
this.getList()
},
add(record:any){ add(record:any){
this.type = modal.on this.type = modal.on
this.showActionModal = true this.showActionModal = true
this.uuid = record.uuid
this.title = '上架消息' this.title = '上架消息'
this.text = '确定上架该消息吗?' this.text = '确定上架该消息吗?'
}, },
remove(record:any){ remove(record:any){
this.type = modal.off this.type = modal.off
this.showActionModal = true this.showActionModal = true
this.uuid = record.uuid
this.title = '下架消息' this.title = '下架消息'
this.text = '确定下架该消息吗?' this.text = '确定下架该消息吗?'
}, },
onEdit(record: any) {
this.form = {
title: record.title,
content: record.content,
type: record.notify_type
}
this.btnType = 'edit'
this.uuid = record.uuid
this.show = true
},
onDelete(record:any){ onDelete(record:any){
this.type = modal.delete this.type = modal.delete
this.showActionModal = true this.showActionModal = true
this.uuid = record.uuid
this.title = '删除消息' this.title = '删除消息'
this.text = '确定删除该消息吗?' this.text = '确定删除该消息吗?'
}, },
setStatus(status: number, msg: string) {
notify.modifyNotifyStatus({
notify_status: status,
uuid: this.uuid
}).then(res => {
if (res.code === 200) {
message.success(msg)
this.getList()
}
})
},
removeNotify() {
notify.removeNotify(this.uuid).then(res => {
if (res.code === 200) {
message.success('删除成功')
this.getList()
}
})
},
onOk(record:any){ onOk(record:any){
if( this.type == modal.on){ if( this.type == modal.on){
this.setStatus(2, '发布成功')
} else if( this.type == modal.off){ } else if( this.type == modal.off){
this.setStatus(1, '下架成功')
} else if( this.type == modal.delete){ } else if( this.type == modal.delete){
this.removeNotify()
} }
this.showActionModal = false this.showActionModal = false
}, },
query(){ query(){
this.getList()
}, },
publish(){ publish(){
this.resetForm() this.resetForm()
this.show = true this.show = true
this.btnType = 'add'
}, },
showModal(current:object){ showModal(current:object){
this.visible = true this.visible = true
...@@ -141,12 +237,43 @@ export default Vue.extend({ ...@@ -141,12 +237,43 @@ export default Vue.extend({
handleOk(){ handleOk(){
this.visible = false this.visible = false
}, },
addNotice() {
notify.addNotify({
content: this.form.content,
notify_type: this.form.type,
title: this.form.title
}).then(res => {
if (res.code === 200) {
message.success('新增成功')
this.show = false
this.getList()
}
})
},
editNotice() {
notify.modifyNotify({
content: this.form.content,
notify_type: this.form.type,
title: this.form.title,
uuid: this.uuid
}).then(res => {
if (res.code === 200) {
message.success('编辑成功')
this.show = false
this.getList()
}
})
},
onSubmit() { onSubmit() {
(this.$refs.ruleForm as FormModel).validate(valid => { (this.$refs.ruleForm as FormModel).validate(valid => {
if (valid) { if (valid) {
this.show = false if (this.btnType === 'add') {
this.addNotice()
} else {
this.editNotice()
}
} else { } else {
console.log('error submit!!'); message.error('请先填写表单内容')
return false; return false;
} }
}); });
...@@ -158,22 +285,21 @@ export default Vue.extend({ ...@@ -158,22 +285,21 @@ export default Vue.extend({
this.form[m as formtype] = '' this.form[m as formtype] = ''
}) })
}, },
edit(record:msg){ // edit(record:msg){
let form = this.form // let form = this.form
type msgtype = keyof msg // type msgtype = keyof msg
type formtype = keyof typeof form // type formtype = keyof typeof form
Object.keys(this.form).map(m=>{ // Object.keys(this.form).map(m=>{
this.form[m as formtype] = record[m as msgtype ] // this.form[m as formtype] = record[m as msgtype ]
}) // })
this.show = true // this.show = true
}, // },
}, },
data(){ data(){
const list = msgList
const rules={ const rules={
module: [ // module: [
{ required: true, message: '请输入模板名称', trigger: 'blur' }, // { required: true, message: '请输入模板名称', trigger: 'blur' },
], // ],
type: [ type: [
{ required: true, message: '请选择消息分类', trigger: 'blur' }, { required: true, message: '请选择消息分类', trigger: 'blur' },
], ],
...@@ -195,14 +321,21 @@ export default Vue.extend({ ...@@ -195,14 +321,21 @@ export default Vue.extend({
labelCol: { span: 4 }, labelCol: { span: 4 },
wrapperCol: { span: 14 }, wrapperCol: { span: 14 },
form: { form: {
name: '', // name: '',
title:'', title:'',
type:'', type: 1,
content:'', content:'',
module:'' // module:''
}, },
rules, rules,
list uuid: "",
list: [],
pagination: {
current: 1,
defaultPageSize: 10,
total: 0
},
btnType: 'add'
} }
} }
}) })
......
<template> <template>
<div> <div>
<p class=" text-2xl font-bold mb-5 ">{{title}}</p> <p class=" text-2xl font-bold mb-5 ">{{ title }}</p>
<p class=" text-gray-400">发布时间:{{time}} <span class=" ml-2">作者:{{name}}</span></p> <p class=" text-gray-400">发布时间:{{ time | format }} <span class=" ml-2">作者:{{ name }}</span></p>
<div class="text-left p-5" v-html="content"></div> <div class="text-left p-5" v-html="content"></div>
<!-- <p class="text-left p-5">{{content}}</p> --> <!-- <p class="text-left p-5">{{content}}</p> -->
</div> </div>
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
<script lang="ts"> <script lang="ts">
import Vue from 'vue' import Vue from 'vue'
import News from '@/service/News/index' import News from '@/service/News/index'
import Filter from '@/filter/index'
const news = new News() const news = new News()
...@@ -22,6 +23,11 @@ export default Vue.extend({ ...@@ -22,6 +23,11 @@ export default Vue.extend({
content:'' content:''
} }
}, },
filters: {
format(value: string) {
return Filter.formatDate(value)
}
},
methods: { methods: {
getDetails() { getDetails() {
const type = this.$route.query.type const type = this.$route.query.type
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
@change="tableChange"> @change="tableChange">
<!-- 发布时间 --> <!-- 发布时间 -->
<span slot="created_at" slot-scope="text,record"> <span slot="created_at" slot-scope="text,record">
{{ record.created_at }} {{ record.created_at | format }}
</span> </span>
<!-- 新闻内容 --> <!-- 新闻内容 -->
<span slot="content" slot-scope="text,record"> <span slot="content" slot-scope="text,record">
...@@ -86,17 +86,20 @@ import { getDate } from '@/utils/days/index' ...@@ -86,17 +86,20 @@ import { getDate } from '@/utils/days/index'
import timerange from '@/components//TimePicker/index.vue' import timerange from '@/components//TimePicker/index.vue'
import News from '@/service/News/index' import News from '@/service/News/index'
import { message } from 'ant-design-vue' import { message } from 'ant-design-vue'
import Filter from '@/filter/index'
const news = new News() const news = new News()
export default Vue.extend({ export default Vue.extend({
components:{ timerange }, components:{ timerange },
filters: {
format(value: string) {
return Filter.formatDate(value)
}
},
computed:{ computed:{
columns(){ columns(){
return columns return columns
},
getTime() {
} }
}, },
props:{ props:{
...@@ -140,7 +143,6 @@ export default Vue.extend({ ...@@ -140,7 +143,6 @@ export default Vue.extend({
}, },
methods:{ methods:{
tableChange(e: any) { tableChange(e: any) {
console.log(e)
this.pagination.current = e.current this.pagination.current = e.current
this.getList() this.getList()
}, },
...@@ -155,9 +157,9 @@ export default Vue.extend({ ...@@ -155,9 +157,9 @@ export default Vue.extend({
console.log(res) console.log(res)
this.list = res.data.items this.list = res.data.items
this.pagination.total = res.data.total this.pagination.total = res.data.total
if (this.searchPageReqParams.title) { // if (this.searchPageReqParams.title) {
this.findTitle() // this.findTitle()
} // }
}) })
}, },
findTitle() { findTitle() {
...@@ -168,7 +170,11 @@ export default Vue.extend({ ...@@ -168,7 +170,11 @@ export default Vue.extend({
}, },
query(){ query(){
console.log(this.searchPageReqParams); console.log(this.searchPageReqParams);
this.getList() if (this.searchPageReqParams.title) {
this.findTitle()
} else {
this.getList()
}
}, },
getNewTime(startTime:number,endTime:number){ getNewTime(startTime:number,endTime:number){
this.searchPageReqParams.start_time = startTime this.searchPageReqParams.start_time = startTime
...@@ -234,6 +240,7 @@ export default Vue.extend({ ...@@ -234,6 +240,7 @@ export default Vue.extend({
}) })
}, },
handleOk(record:any){ handleOk(record:any){
console.log(record)
if( this.type == modal.on){ if( this.type == modal.on){
this.setStatus(2, '上架成功') this.setStatus(2, '上架成功')
} else if( this.type == modal.off){ } else if( this.type == modal.off){
...@@ -244,7 +251,7 @@ export default Vue.extend({ ...@@ -244,7 +251,7 @@ export default Vue.extend({
} }
this.show = false this.show = false
}, },
toDetail(key:string, type:number|undefined){ toDetail(key:string, type:string){
this.$router.push({name:'newsDetail',query:{key:key,type:type}}) this.$router.push({name:'newsDetail',query:{key:key,type:type}})
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment