wms-naivevue/src/views/dashboard/message/index.vue
2024-12-13 13:56:14 +08:00

224 lines
5.3 KiB
Vue

<template>
<PageWrapper>
<n-card>
<n-tabs v-model="activeName" @update:value="handleClick">
<n-tab-pane
:name="item.value"
:tab="item.configName"
v-for="(item, index) in messageTypeList"
>
<template #tab>
<n-badge :value="item.number ? item.number : ''" class="item" :offset="[10, 2]">
<span class="t1">{{ item.name }}</span>
</n-badge>
</template>
</n-tab-pane>
</n-tabs>
<BasicTable
:columns="columns"
:actionColumn="actionColumn"
:request="loadDataTable"
:row-key="(row) => row.id"
ref="tableRef"
@update:checked-row-keys="onSelectionChange"
:autoScrollX="true"
>
<template #tableTitle>
<n-space>
<n-button type="primary" @click="handleSetRead()"> 批量确认 </n-button>
<n-button type="error" @click="handleDelete()" :disabled="!selectionData.length">
<template #icon>
<n-icon>
<DeleteOutlined />
</n-icon>
</template>
删除
</n-button>
</n-space>
</template>
</BasicTable>
</n-card>
<editDialog
v-if="editVisible"
:messageId="messageId"
v-model:visible="editVisible"
ref="createModalRef"
@success="reloadTable('noRefresh')"
/>
</PageWrapper>
</template>
<script lang="ts" setup>
import { reactive, ref, h, nextTick, defineAsyncComponent, onMounted } from 'vue';
import { EyeOutlined, DeleteOutlined, CheckOutlined } from '@vicons/antd';
import { TableAction } from '@/components/Table';
import {
getMessageProfile,
messageDelete,
messageBatchDelete,
setRead,
} from '@/api/dashboard/message';
import { columns } from './columns';
import editDialog from './edit.vue';
import { useMessage, useDialog } from 'naive-ui';
import { renderIcon } from '@/utils';
/**
* 定义参数
*/
const messageId = ref(0);
const message = useMessage();
const dialog = useDialog();
const activeName = ref(1);
const editVisible = ref(false);
const createModalRef = ref();
const selectionData = ref([]);
const tableRef = ref();
/**
* 定义查询参数
*/
const formParams = reactive({
type: 1,
});
/**
* 定义数据源
*/
const messageTypeList = ref([
{
name: '系统通知',
value: 1,
},
{
name: '用户私信',
value: 2,
},
{
name: '代办事项',
value: 3,
},
]);
/**
* 加载数据列表
* @param res 参数
*/
const loadDataTable = async (res: any) => {
selectionData.value = [];
const result = await getMessageProfile({ ...formParams, ...res });
let item = messageTypeList.value.find((item, index) => item.value == activeName.value);
item.number = result.number;
return result;
};
/**
* 定义操作栏
*/
const actionColumn = reactive({
width: 280,
title: '操作',
align: 'center',
key: 'action',
fixed: 'right',
render(record) {
return h(TableAction as any, {
style: 'button',
actions: [
{
label: '确认',
icon: renderIcon(CheckOutlined),
type: 'info',
onClick: handleSetRead.bind(null, record),
},
{
label: '详情',
icon: renderIcon(EyeOutlined),
type: 'info',
onClick: handleDetail.bind(null, record),
},
{
label: '删除',
icon: renderIcon(DeleteOutlined),
type: 'error',
onClick: handleDelete.bind(null, record),
},
],
});
},
});
/**
* 刷新数据列表
* @param noRefresh 参数
*/
function reloadTable(noRefresh = '') {
tableRef.value.reload(noRefresh ? {} : { pageNo: 1 });
}
/**
* 执行点击事件
* @param e 参数
*/
const handleClick = (e) => {
activeName.value = e;
formParams.type = e;
reloadTable();
};
/**
* 执行查看详情
* @param record 参数
*/
const handleDetail = async (record) => {
messageId.value = record.id;
editVisible.value = true;
await nextTick();
createModalRef.value.openModal();
};
/**
* 执行删除
* @param record 参数
*/
async function handleDelete(record) {
dialog.warning({
title: '提示',
content: '确定要删除?',
positiveText: '确定',
negativeText: '取消',
onPositiveClick: async () => {
record.id ? await messageDelete(record.id) : await messageBatchDelete(selectionData.value);
message.success('删除成功');
reloadTable();
},
});
}
/**
* 执行设置已读
* @param id 参数
*/
async function handleSetRead(id) {
dialog.warning({
title: '提示',
content: '确定标记为已读?',
positiveText: '确定',
negativeText: '取消',
onPositiveClick: async () => {
record.id ? await setRead(record.id) : await setRead(rowKeys.value);
message.success('删除成功');
reloadTable();
},
});
}
/**
* 数据行选中事件
* @param value 参数
*/
function onSelectionChange(value) {
selectionData.value = value;
}
</script>