wms_vue/src/view/announce/index.vue

170 lines
4.9 KiB
Vue
Raw Normal View History

2025-08-07 15:16:23 +08:00
<template>
2025-11-06 14:25:31 +08:00
<a-list-layout ref="pageRef">
<template #search>
<pro-query :searchParam="searchParam" @on-search="search"></pro-query>
</template>
<pro-table ref="tableRef" :fetch="fetch" :columns="columns" :toolbar="toolbar" :operate="operate"
:param="state.param" :pagination="pagination"
:row-selection="{ selectedRowKeys: state.selectedRowKeys, onChange: onSelectChange }">
</pro-table>
<save :visible="state.visibleSave" @close="closeSave"></save>
<edit :visible="state.visibleEdit" @close="closeEdit" :record="state.recordEdit"></edit>
<info :visible="state.visibleInfo" @close="closeInfo" :record="state.recordInfo"></info>
</a-list-layout>
2025-08-07 15:16:23 +08:00
</template>
<script>
2025-11-04 14:04:50 +08:00
import save from './modal/save.vue';
import edit from './modal/edit.vue';
import info from './modal/info.vue';
2025-11-06 14:25:31 +08:00
import { message, Modal as modal } from '@hwork/ant-design-vue';
2025-08-07 15:16:23 +08:00
import { ExclamationCircleOutlined } from '@ant-design/icons-vue';
import { page, remove, removeBatch } from "@/api/module/announce";
import { reactive, createVNode, ref } from 'vue';
const removeKey = "remove";
const removeBatchKey = "removeBatch";
export default {
components: {
save,
edit,
info,
},
setup() {
const tableRef = ref();
/// 开关
2025-11-06 14:25:31 +08:00
const converFormat = [{ label: "已发布", value: true }, { label: "未发布", value: false }];
2025-08-07 15:16:23 +08:00
/// 列配置
const columns = [
{ dataIndex: "title", key: "title", title: "公告标题" },
{ dataIndex: "content", key: "content", title: "公告内容" },
{ dataIndex: "createName", key: "createName", title: "发布人" },
{ dataIndex: "state", key: "state", title: "状态", conver: converFormat },
{ dataIndex: "createTime", key: "createTime", title: "发布时间" },
];
/// 数据来源 [模拟]
const fetch = async (param) => {
var response = await page(param);
return {
total: response.data.total,
data: response.data.record,
};
};
/// 删除配置
const removeMethod = (record) => {
message.loading({ content: "提交中...", key: removeKey });
remove({ "id": record.id }).then((response) => {
if (response.success) {
message.success({ content: "删除成功", key: removeKey, duration: 1 })
tableRef.value.reload()
} else {
message.error({ content: "删除失败", key: removeKey, duration: 1 })
}
})
}
/// 批量删除
const removeBatchMethod = (ids) => {
2025-11-06 14:25:31 +08:00
modal.confirm({
2025-08-07 15:16:23 +08:00
title: '您是否确定要删除选择公告?',
icon: createVNode(ExclamationCircleOutlined),
okText: '确定',
cancelText: '取消',
onOk() {
message.loading({ content: "提交中...", key: removeBatchKey });
2025-11-06 14:25:31 +08:00
removeBatch({ "ids": ids }).then((response) => {
if (response.success) {
message.success({ content: "删除成功", key: removeBatchKey, duration: 1 })
2025-08-07 15:16:23 +08:00
tableRef.value.reload()
2025-11-06 14:25:31 +08:00
} else {
message.error({ content: "删除失败", key: removeBatchKey, duration: 1 })
2025-08-07 15:16:23 +08:00
}
})
}
});
}
/// 工具栏
const toolbar = [
2025-11-06 14:25:31 +08:00
{ label: "新增", event: function () { state.visibleSave = true } },
{ label: "删除", event: function () { removeBatchMethod(state.selectedRowKeys) } },
2025-08-07 15:16:23 +08:00
];
/// 行操作
const operate = [
2025-11-06 14:25:31 +08:00
{ label: "查看", event: function (record) { state.visibleInfo = true, state.recordInfo = record } },
{ label: "修改", event: function (record) { state.visibleEdit = true, state.recordEdit = record } },
{ label: "删除", isDel: true, delEvent: function (record) { removeMethod(record) }, cancelEvent: (record) => { } },
2025-08-07 15:16:23 +08:00
];
/// 分页参数
const pagination = {
pageNum: 1,
pageSize: 10,
}
/// 外置参数 - 当参数改变时, 重新触发 fetch 函数
const state = reactive({
selectedRowKeys: [],
param: {},
visibleSave: false,
visibleEdit: false,
visibleInfo: false,
recordEdit: {},
recordInfo: {},
})
2025-11-06 14:25:31 +08:00
2025-08-07 15:16:23 +08:00
const searchParam = [
2025-11-06 14:25:31 +08:00
{ key: "title", type: "input", label: "公告标题" },
2025-08-07 15:16:23 +08:00
]
2025-11-06 14:25:31 +08:00
const search = function (value) {
2025-08-07 15:16:23 +08:00
state.param = value
}
2025-11-06 14:25:31 +08:00
const closeSave = function () {
2025-08-07 15:16:23 +08:00
tableRef.value.reload()
state.visibleSave = false
}
2025-11-06 14:25:31 +08:00
const closeEdit = function () {
2025-08-07 15:16:23 +08:00
tableRef.value.reload()
state.visibleEdit = false
}
2025-11-06 14:25:31 +08:00
const closeInfo = function () {
2025-08-07 15:16:23 +08:00
state.visibleInfo = false
}
const onSelectChange = selectedRowKeys => {
state.selectedRowKeys = selectedRowKeys;
};
return {
2025-11-06 14:25:31 +08:00
state,
fetch,
toolbar,
columns,
operate,
pagination,
2025-08-07 15:16:23 +08:00
search,
searchParam,
2025-11-06 14:25:31 +08:00
2025-08-07 15:16:23 +08:00
closeSave,
closeEdit,
closeInfo,
2025-11-06 14:25:31 +08:00
2025-08-07 15:16:23 +08:00
onSelectChange,
tableRef
};
},
};
2025-11-06 14:25:31 +08:00
</script>