消息管理
This commit is contained in:
parent
337df8e1e4
commit
adaebac926
68
src/views/data/message/columns.ts
Normal file
68
src/views/data/message/columns.ts
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
import { h } from 'vue';
|
||||||
|
|
||||||
|
export const columns = [
|
||||||
|
{
|
||||||
|
type: 'selection',
|
||||||
|
width: 50,
|
||||||
|
fixed: 'left',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'ID',
|
||||||
|
key: 'id',
|
||||||
|
fixed: 'left',
|
||||||
|
width: 50,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '消息标题',
|
||||||
|
key: 'title',
|
||||||
|
width: 100,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '消息类型',
|
||||||
|
key: 'type',
|
||||||
|
width: 100,
|
||||||
|
render(record) {
|
||||||
|
let typeText = '';
|
||||||
|
switch (record.type) {
|
||||||
|
case 1:
|
||||||
|
typeText = '系统通知';
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
typeText = '用户私信';
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
typeText = '代办事项';
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return h('span', typeText || '-');
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '业务类型',
|
||||||
|
key: 'bizType',
|
||||||
|
width: 100,
|
||||||
|
render(record) {
|
||||||
|
return h('span', record.bizType == 1 ? '订单' : '其他');
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '消息状态',
|
||||||
|
key: 'status',
|
||||||
|
width: 100,
|
||||||
|
render(record) {
|
||||||
|
return h('span', record.status === 1 ? '已读' : '未读');
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '创建人',
|
||||||
|
width: 100,
|
||||||
|
key: 'createUser',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '创建时间',
|
||||||
|
key: 'createTime',
|
||||||
|
width: 180,
|
||||||
|
},
|
||||||
|
];
|
118
src/views/data/message/edit.vue
Normal file
118
src/views/data/message/edit.vue
Normal file
@ -0,0 +1,118 @@
|
|||||||
|
<template>
|
||||||
|
<basicModal @register="modalRegister" ref="modalRef" class="basicModal basicFormModal">
|
||||||
|
<template #default>
|
||||||
|
<n-descriptions
|
||||||
|
class="margin-top"
|
||||||
|
:column="2"
|
||||||
|
bordered
|
||||||
|
:labelStyle="{ width: '120px' }"
|
||||||
|
label-placement="left"
|
||||||
|
>
|
||||||
|
<n-descriptions-item label="消息标题">
|
||||||
|
{{ formData.title }}
|
||||||
|
</n-descriptions-item>
|
||||||
|
<n-descriptions-item label="消息类型">
|
||||||
|
{{ getTyepText(formData.type) }}
|
||||||
|
</n-descriptions-item>
|
||||||
|
<n-descriptions-item label="业务类型">
|
||||||
|
{{ formData.bizType == 1 ? '订单' : '其他' }}
|
||||||
|
</n-descriptions-item>
|
||||||
|
<n-descriptions-item label="消息状态">
|
||||||
|
{{ formData.status == 1 ? '已读' : '未读' }}
|
||||||
|
</n-descriptions-item>
|
||||||
|
<n-descriptions-item label="消息内容">
|
||||||
|
{{ formData.content }}
|
||||||
|
</n-descriptions-item>
|
||||||
|
</n-descriptions>
|
||||||
|
</template>
|
||||||
|
<template #action>
|
||||||
|
<n-button @click="handleClose">取消</n-button>
|
||||||
|
</template>
|
||||||
|
</basicModal>
|
||||||
|
</template>
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import { getMessageDetail } from '@/api/data/message';
|
||||||
|
import { onMounted, ref } from 'vue';
|
||||||
|
import { useModal } from '@/components/Modal';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 定义参数变量
|
||||||
|
*/
|
||||||
|
const emit = defineEmits(['success', 'update:visible']);
|
||||||
|
const formData = ref({});
|
||||||
|
const [modalRegister, { openModal, setSubLoading }] = useModal({
|
||||||
|
title: '消息详情',
|
||||||
|
subBtuText: '确定',
|
||||||
|
width: 800,
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 定义接收的参数
|
||||||
|
*/
|
||||||
|
const props = defineProps({
|
||||||
|
visible: {
|
||||||
|
type: Boolean,
|
||||||
|
required: true,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
|
messageId: {
|
||||||
|
type: Number,
|
||||||
|
required: true,
|
||||||
|
default: 0,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 关闭窗体
|
||||||
|
*/
|
||||||
|
const handleClose = () => {
|
||||||
|
emit('update:visible', false);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置表单数据
|
||||||
|
*/
|
||||||
|
const setFormData = async () => {
|
||||||
|
const data = await getMessageDetail(props.messageId);
|
||||||
|
formData.value = data;
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* 获取类型描述
|
||||||
|
* @param type 类型
|
||||||
|
*/
|
||||||
|
const getTyepText = (type) => {
|
||||||
|
let typeText = '';
|
||||||
|
switch (type) {
|
||||||
|
case 1:
|
||||||
|
typeText = '系统通知';
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
typeText = '用户私信 ';
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
typeText = '代办事项';
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return typeText;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 钩子函数
|
||||||
|
*/
|
||||||
|
onMounted(() => {
|
||||||
|
if (props.messageId) {
|
||||||
|
setFormData();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
//导出方法
|
||||||
|
defineExpose({
|
||||||
|
openModal,
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
<style lang="less" scoped>
|
||||||
|
:deep(.ant-descriptions__body .ant-descriptions__table .ant-descriptions__cell) {
|
||||||
|
word-break: break-all;
|
||||||
|
}
|
||||||
|
</style>
|
178
src/views/data/message/index.vue
Normal file
178
src/views/data/message/index.vue
Normal file
@ -0,0 +1,178 @@
|
|||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<n-card :bordered="false" class="pt-3 mb-3 proCard">
|
||||||
|
<BasicForm @register="register" @submit="handleSubmit" @reset="handleReset">
|
||||||
|
<template #statusSlot="{ model, field }">
|
||||||
|
<n-input v-model:value="model[field]" />
|
||||||
|
</template>
|
||||||
|
</BasicForm>
|
||||||
|
</n-card>
|
||||||
|
<n-card :bordered="false" class="proCard">
|
||||||
|
<BasicTable
|
||||||
|
:columns="columns"
|
||||||
|
:request="loadDataTable"
|
||||||
|
:row-key="(row) => row.id"
|
||||||
|
ref="basicTableRef"
|
||||||
|
:actionColumn="actionColumn"
|
||||||
|
@update:checked-row-keys="onCheckedRow"
|
||||||
|
:autoScrollX="true"
|
||||||
|
>
|
||||||
|
<template #tableTitle>
|
||||||
|
<n-space>
|
||||||
|
<n-button
|
||||||
|
type="error"
|
||||||
|
@click="handleDelete"
|
||||||
|
:disabled="!rowKeys.length"
|
||||||
|
v-perm="['sys:message:batchDelete']"
|
||||||
|
>
|
||||||
|
<template #icon>
|
||||||
|
<n-icon>
|
||||||
|
<DeleteOutlined />
|
||||||
|
</n-icon>
|
||||||
|
</template>
|
||||||
|
删除
|
||||||
|
</n-button>
|
||||||
|
</n-space>
|
||||||
|
</template>
|
||||||
|
</BasicTable>
|
||||||
|
</n-card>
|
||||||
|
<editDialog
|
||||||
|
ref="createModalRef"
|
||||||
|
:messageId="messageId"
|
||||||
|
v-if="editVisible"
|
||||||
|
v-model:visible="editVisible"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import { h, nextTick, reactive, ref, unref } from 'vue';
|
||||||
|
import { useMessage, useDialog } from 'naive-ui';
|
||||||
|
import { TableAction } from '@/components/Table';
|
||||||
|
import { BasicForm, useForm } from '@/components/Form/index';
|
||||||
|
import { getMessageList, messageDelete, messageBatchDelete } from '@/api/data/message';
|
||||||
|
import { columns } from './columns';
|
||||||
|
import { DeleteOutlined, EyeOutlined } from '@vicons/antd';
|
||||||
|
import editDialog from './edit.vue';
|
||||||
|
import { basicModal, useModal } from '@/components/Modal';
|
||||||
|
import { schemas } from './querySchemas';
|
||||||
|
import { renderIcon } from '@/utils';
|
||||||
|
|
||||||
|
const message = useMessage();
|
||||||
|
const dialog = useDialog();
|
||||||
|
const basicTableRef = ref();
|
||||||
|
const createModalRef = ref();
|
||||||
|
const editVisible = ref(false);
|
||||||
|
const messageId = ref(0);
|
||||||
|
const rowKeys = ref([]);
|
||||||
|
|
||||||
|
const showModal = ref(false);
|
||||||
|
const formParams = reactive({
|
||||||
|
title: '',
|
||||||
|
bizType: '',
|
||||||
|
type: '',
|
||||||
|
status: '',
|
||||||
|
});
|
||||||
|
|
||||||
|
const actionColumn = reactive({
|
||||||
|
width: 200,
|
||||||
|
title: '操作',
|
||||||
|
align: 'center',
|
||||||
|
key: 'action',
|
||||||
|
fixed: 'right',
|
||||||
|
render(record) {
|
||||||
|
return h(TableAction as any, {
|
||||||
|
style: 'button',
|
||||||
|
actions: [
|
||||||
|
{
|
||||||
|
label: '详情',
|
||||||
|
icon: renderIcon(EyeOutlined),
|
||||||
|
type: 'info',
|
||||||
|
onClick: handleDetail.bind(null, record),
|
||||||
|
auth: ['sys:message:detail'],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '删除',
|
||||||
|
icon: renderIcon(DeleteOutlined),
|
||||||
|
type: 'error',
|
||||||
|
onClick: handleDelete.bind(null, record),
|
||||||
|
auth: ['sys:message:delete'],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
function addTable() {
|
||||||
|
showModal.value = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
const loadDataTable = async (res) => {
|
||||||
|
rowKeys.value = [];
|
||||||
|
const result = await getMessageList({ ...formParams, ...res });
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
function onCheckedRow(keys) {
|
||||||
|
rowKeys.value = keys;
|
||||||
|
}
|
||||||
|
|
||||||
|
function reloadTable(noRefresh = '') {
|
||||||
|
basicTableRef.value.reload(noRefresh ? {} : { pageNo: 1 });
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleSubmit(values: Recordable) {
|
||||||
|
for (const key in formParams) {
|
||||||
|
formParams[key] = '';
|
||||||
|
}
|
||||||
|
for (const key in values) {
|
||||||
|
formParams[key] = values[key];
|
||||||
|
}
|
||||||
|
reloadTable();
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleReset(values: Recordable) {
|
||||||
|
for (const key in formParams) {
|
||||||
|
formParams[key] = '';
|
||||||
|
}
|
||||||
|
for (const key in values) {
|
||||||
|
formParams[key] = values[key];
|
||||||
|
}
|
||||||
|
reloadTable();
|
||||||
|
}
|
||||||
|
|
||||||
|
const [register, {}] = useForm({
|
||||||
|
gridProps: { cols: '1 s:1 m:2 l:3 xl:4 2xl:4' },
|
||||||
|
labelWidth: 80,
|
||||||
|
schemas,
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 执行查看
|
||||||
|
*/
|
||||||
|
async function handleDetail(record: Recordable) {
|
||||||
|
messageId.value = record.id;
|
||||||
|
editVisible.value = true;
|
||||||
|
await nextTick();
|
||||||
|
createModalRef.value.openModal();
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 执行删除
|
||||||
|
* @param id 参数
|
||||||
|
*/
|
||||||
|
async function handleDelete(record) {
|
||||||
|
dialog.warning({
|
||||||
|
title: '提示',
|
||||||
|
content: '确定要删除?',
|
||||||
|
positiveText: '确定',
|
||||||
|
negativeText: '取消',
|
||||||
|
onPositiveClick: async () => {
|
||||||
|
record.id ? await messageDelete(record.id) : await messageBatchDelete(rowKeys.value);
|
||||||
|
message.success('删除成功');
|
||||||
|
reloadTable();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="less" scoped></style>
|
72
src/views/data/message/querySchemas.ts
Normal file
72
src/views/data/message/querySchemas.ts
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
import { FormSchema } from '@/components/Form/index';
|
||||||
|
export const schemas: FormSchema[] = [
|
||||||
|
{
|
||||||
|
field: 'title',
|
||||||
|
component: 'NInput',
|
||||||
|
label: '消息标题',
|
||||||
|
componentProps: {
|
||||||
|
placeholder: '请输入消息标题',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'type',
|
||||||
|
component: 'NSelect',
|
||||||
|
label: '消息类型',
|
||||||
|
componentProps: {
|
||||||
|
placeholder: '请选择消息类型',
|
||||||
|
clearable: true,
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
label: '系统通知',
|
||||||
|
value: 1,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '用户私信',
|
||||||
|
value: 2,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '代办事项',
|
||||||
|
value: 3,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'bizType',
|
||||||
|
component: 'NSelect',
|
||||||
|
label: '业务类型',
|
||||||
|
componentProps: {
|
||||||
|
placeholder: '请选择业务类型',
|
||||||
|
clearable: true,
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
label: '订单',
|
||||||
|
value: 1,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '其他',
|
||||||
|
value: 2,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'status',
|
||||||
|
component: 'NSelect',
|
||||||
|
label: '消息状态',
|
||||||
|
componentProps: {
|
||||||
|
placeholder: '请选择消息状态',
|
||||||
|
clearable: true,
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
label: '未读',
|
||||||
|
value: 0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '已读',
|
||||||
|
value: 1,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
Loading…
Reference in New Issue
Block a user