Files
sunProduct/src/views/system/NoticePc/index.vue

222 lines
7.7 KiB
Vue

<template>
<div class="p-2 h-full flex flex-col">
<Pageheader></Pageheader>
<transition :enter-active-class="proxy?.animate.searchAnimate.enter" :leave-active-class="proxy?.animate.searchAnimate.leave">
<div v-show="showSearch" class="mb-[10px]">
<el-card shadow="hover">
<el-form ref="queryFormRef" :model="queryParams" @submit.prevent="handleQuery" :inline="true">
<el-form-item label="公告标题" prop="noticeTitle">
<el-input v-model="queryParams.noticeTitle" placeholder="请输入公告标题" clearable @keyup.enter="handleQuery" />
</el-form-item>
<el-form-item>
<el-button type="primary" @click="handleQuery">搜索</el-button>
<el-button @click="resetQuery">重置</el-button>
</el-form-item>
</el-form>
</el-card>
</div>
</transition>
<el-card shadow="never" class="flex-1">
<template #header>
<el-row :gutter="10" class="mb8">
<right-toolbar
:disable-delete="multiple"
:disable-edit="single"
:show-add="checkPermi(['notice:notice:add'])"
:show-edit="checkPermi(['notice:notice:edit'])"
:show-delete="checkPermi(['notice:notice:remove'])"
@update:add="handleAdd"
@update:edit="handleUpdate()"
@update:delete="handleDelete()"
></right-toolbar>
</el-row>
</template>
<el-table v-loading="loading" border :data="noticeList" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" align="center" />
<el-table-column label="公告标题" align="center" prop="noticeTitle" />
<!-- <el-table-column label="作者" width="120" align="center" prop="author" />-->
<!-- <el-table-column label="紧急程度" align="center" prop="urgencyLevel">-->
<!-- <template #default="scope">-->
<!-- <dict-tag :options="com_noticepc_level" :value="scope.row.urgencyLevel"></dict-tag>-->
<!-- </template>-->
<!-- </el-table-column>-->
<el-table-column label="发布状态" align="center" prop="publishStatus">
<template #default="scope">
<dict-tag :options="com_publish_status" :value="scope.row.publishStatus"></dict-tag>
</template>
</el-table-column>
<el-table-column label="已读" width="120" align="center" prop="readNum">
<template #default="scope">
<span>{{ scope.row.readNum ?? '--' }} 人</span>
</template>
</el-table-column>
<el-table-column label="未读" width="120" align="center" prop="unReadNum">
<template #default="scope">
<span>{{ scope.row.unReadNum ?? '--' }} 人</span>
</template>
</el-table-column>
<el-table-column label="发布人" align="center" prop="publishBy" />
<el-table-column label="发布日期" align="center" prop="publishTime" width="100">
<template #default="scope">
<span>{{ parseTime(scope.row.publishTime, '{y}-{m}-{d}') }}</span>
</template>
</el-table-column>
<el-table-column label="操作" align="center" width="220" fixed="right" class-name="small-padding fixed-width">
<template #default="scope">
<el-button link type="primary" @click="handleMain(scope.row)">详情</el-button>
<el-button link type="primary" @click="handleUpdate(scope.row)" v-has-permi="['notice:notice:edit']">编辑</el-button>
<el-button link type="primary" @click="handleDelete(scope.row)" v-has-permi="['notice:notice:remove']">删除</el-button>
</template>
</el-table-column>
</el-table>
<pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList" />
</el-card>
<el-dialog v-model="MainForm.visible" title="公告详情">
<div class="w-full h-full">
<div v-html="MainForm.content"></div>
</div>
<template #footer>
<div class="dialog-footer">
<el-button @click="MainForm.visible = false">关闭</el-button>
</div>
</template>
</el-dialog>
</div>
</template>
<script setup name="Notice" lang="ts">
import { listNotice, delNotice } from '@/api/system/NoticePc';
import { NoticeVO, NoticeQuery, NoticeForm } from '@/api/system/NoticePc/type';
import { checkPermi } from '@/utils/permission';
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
const { com_noticepc_level } = toRefs<any>(proxy?.useDict('com_noticepc_level'));
const { com_publish_status } = toRefs<any>(proxy?.useDict('com_publish_status'));
const noticeList = ref<NoticeVO[]>([]);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref<Array<string | number>>([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const queryFormRef = ref<ElFormInstance>();
const initFormData: NoticeForm = {
noticeId: undefined,
noticeTitle: undefined,
noticeContent: undefined,
author: undefined,
urgencyLevel: undefined,
publishStatus: undefined,
publishBy: undefined,
publishTime: undefined
};
const data = reactive<PageData<NoticeForm, NoticeQuery>>({
form: { ...initFormData },
queryParams: {
pageNum: 1,
pageSize: 10,
noticeTitle: undefined,
noticeContent: undefined,
author: undefined,
urgencyLevel: undefined,
publishStatus: undefined,
publishBy: undefined,
publishTime: undefined,
params: {}
},
rules: {
noticeId: [{ required: true, message: '公告ID不能为空', trigger: 'blur' }],
noticeTitle: [{ required: true, message: '公告标题不能为空', trigger: 'blur' }],
urgencyLevel: [{ required: true, message: '紧急程度不能为空', trigger: 'blur' }],
publishStatus: [{ required: true, message: '发布状态不能为空', trigger: 'change' }]
}
});
const { queryParams } = toRefs(data);
/** 查询公告信息列表 */
const getList = async () => {
loading.value = true;
listNotice(queryParams.value)
.then((res) => {
noticeList.value = res.rows;
total.value = res.total;
})
.finally(() => {
loading.value = false;
});
};
/** 搜索按钮操作 */
const handleQuery = () => {
queryParams.value.pageNum = 1;
getList();
};
/** 重置按钮操作 */
const resetQuery = () => {
queryFormRef.value?.resetFields();
handleQuery();
};
/** 多选框选中数据 */
const handleSelectionChange = (selection: NoticeVO[]) => {
ids.value = selection.map((item) => item.noticeId);
single.value = selection.length != 1;
multiple.value = !selection.length;
};
const router = useRouter();
/** 新增按钮操作 */
const handleAdd = () => {
router.push({
path: '/repair/addNoticePc'
});
};
/** 修改按钮操作 */
const handleUpdate = (row?: NoticeVO) => {
const _id = row?.noticeId || ids.value[0];
router.push({
path: '/repair/editNoticePc',
query: {
id: _id
}
});
};
const MainForm = ref({
visible: false,
content: ''
});
/** 详情按钮操作 */
const handleMain = (row: NoticeVO) => {
MainForm.value.visible = true;
MainForm.value.content = row.noticeContent;
};
/** 删除按钮操作 */
const handleDelete = async (row?: NoticeVO) => {
const _noticeIds = row?.noticeId || ids.value;
await proxy?.$modal.confirm('该信息删除后无法恢复,确定要删除吗?').finally(() => (loading.value = false));
await delNotice(_noticeIds);
proxy?.$modal.msgSuccess('删除成功');
await getList();
};
onMounted(() => {
getList();
});
</script>
<style lang="scss" scoped>
.el-table {
height: calc(100% - 80px);
}
</style>