|
@@ -1,295 +0,0 @@
|
|
|
-<template>
|
|
|
|
|
- <CollapseContainer
|
|
|
|
|
- class="sys-container"
|
|
|
|
|
- title="公告管理"
|
|
|
|
|
- :canExpan="false"
|
|
|
|
|
- helpMessage="公告管理"
|
|
|
|
|
- >
|
|
|
|
|
- <BasicTable
|
|
|
|
|
- ref="tableRef"
|
|
|
|
|
- @register="registerTable"
|
|
|
|
|
- rowKey="id"
|
|
|
|
|
- @selectionChange="selectionChange"
|
|
|
|
|
- @rowClick="rowClick"
|
|
|
|
|
- @rowDbClick="handleEdit"
|
|
|
|
|
- showTableSetting
|
|
|
|
|
- :canResize="true"
|
|
|
|
|
- :pagination="{
|
|
|
|
|
- pageSize: 10,
|
|
|
|
|
- defaultPageSize: 10,
|
|
|
|
|
- showSizeChanger: false,
|
|
|
|
|
- }"
|
|
|
|
|
- >
|
|
|
|
|
- <template #toolbar>
|
|
|
|
|
- <div class="tool-btn-wrap">
|
|
|
|
|
- <a-button type="primary" @click="addRole">添加</a-button>
|
|
|
|
|
- <a-button color="error" :disabled="disable_btn" @click="deleteBatches">删除</a-button>
|
|
|
|
|
- </div>
|
|
|
|
|
- </template>
|
|
|
|
|
- <template #form-custom>custom-slot</template>
|
|
|
|
|
- <template #action="{ record }">
|
|
|
|
|
- <TableAction :actions="createActions(record)" stopButtonPropagation />
|
|
|
|
|
- </template>
|
|
|
|
|
- </BasicTable>
|
|
|
|
|
- <Popup @register="addRegister" :popupData="popupData" @saveData="saveData" />
|
|
|
|
|
- </CollapseContainer>
|
|
|
|
|
-</template>
|
|
|
|
|
-<script lang="ts">
|
|
|
|
|
- import { defineComponent, reactive, ref, toRefs, unref, createVNode } from 'vue';
|
|
|
|
|
- import { CollapseContainer } from '/@/components/Container/index';
|
|
|
|
|
- import Popup from './popup.vue';
|
|
|
|
|
- import { useMessage } from '/@/hooks/web/useMessage';
|
|
|
|
|
- import { useModal } from '/@/components/Modal';
|
|
|
|
|
- import { Modal } from 'ant-design-vue';
|
|
|
|
|
- import { ExclamationCircleOutlined } from '@ant-design/icons-vue';
|
|
|
|
|
- import { getFormConfig, columns } from './data';
|
|
|
|
|
- import moment from 'moment';
|
|
|
|
|
- import { getNoticeList, addNotice, editNotice, deleteNotice, deleteBatchesNotice } from '/@/api/sys/news';
|
|
|
|
|
- import {
|
|
|
|
|
- BasicTable,
|
|
|
|
|
- useTable,
|
|
|
|
|
- TableAction,
|
|
|
|
|
- ActionItem,
|
|
|
|
|
- EditRecordRow,
|
|
|
|
|
- TableActionType,
|
|
|
|
|
- } from '/@/components/Table';
|
|
|
|
|
-
|
|
|
|
|
- interface PopupData {
|
|
|
|
|
- title: string;
|
|
|
|
|
- }
|
|
|
|
|
- interface Btn {
|
|
|
|
|
- disable_btn: boolean;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- export default defineComponent({
|
|
|
|
|
- name: 'Notice',
|
|
|
|
|
- components: { CollapseContainer, BasicTable, TableAction, Popup },
|
|
|
|
|
- setup() {
|
|
|
|
|
- const { createMessage } = useMessage();
|
|
|
|
|
- const { success, error } = createMessage;
|
|
|
|
|
- const tableRef = ref<Nullable<TableActionType>>(null);
|
|
|
|
|
- const currentEditKeyRef = ref('');
|
|
|
|
|
- const popupData = reactive<PopupData>({
|
|
|
|
|
- title: '添加',
|
|
|
|
|
- });
|
|
|
|
|
- const btn = reactive<Btn>({
|
|
|
|
|
- disable_btn: true,
|
|
|
|
|
- });
|
|
|
|
|
- const [registerTable] = useTable({
|
|
|
|
|
- rowSelection: {
|
|
|
|
|
- type: 'checkbox',
|
|
|
|
|
- },
|
|
|
|
|
- columns: columns,
|
|
|
|
|
- // clickToRowSelect: false, // 点击行不勾选
|
|
|
|
|
- api: getNoticeList,
|
|
|
|
|
- useSearchForm: true,
|
|
|
|
|
- beforeFetch: beforeFetch,
|
|
|
|
|
- afterFetch: afterFetch,
|
|
|
|
|
- formConfig: getFormConfig(),
|
|
|
|
|
- actionColumn: {
|
|
|
|
|
- width: 160,
|
|
|
|
|
- title: '操作',
|
|
|
|
|
- dataIndex: 'action',
|
|
|
|
|
- slots: { customRender: 'action' },
|
|
|
|
|
- fixed: undefined,
|
|
|
|
|
- },
|
|
|
|
|
- tableSetting: {
|
|
|
|
|
- // redo: false,
|
|
|
|
|
- size: false,
|
|
|
|
|
- },
|
|
|
|
|
- showIndexColumn: false,
|
|
|
|
|
- bordered: true,
|
|
|
|
|
- });
|
|
|
|
|
- const [register, { openModal }] = useModal();
|
|
|
|
|
- const [addRegister, { openModal: openPopup }] = useModal();
|
|
|
|
|
- function getTableAction() {
|
|
|
|
|
- // 获取组件
|
|
|
|
|
- const tableAction = unref(tableRef);
|
|
|
|
|
- if (!tableAction) {
|
|
|
|
|
- throw new Error('tableAction is null');
|
|
|
|
|
- }
|
|
|
|
|
- return tableAction;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 请求之前处理
|
|
|
|
|
- function beforeFetch(params) {
|
|
|
|
|
- for (let k in params) {
|
|
|
|
|
- if (k !== 'page' && k !== 'pageSize' && k !== 'field' && k !== 'order') {
|
|
|
|
|
- if (params[k] === '') {
|
|
|
|
|
- delete params[k];
|
|
|
|
|
- } else {
|
|
|
|
|
- if (!params.filter) {
|
|
|
|
|
- params.filter = {};
|
|
|
|
|
- }
|
|
|
|
|
- params.filter[k] = params[k];
|
|
|
|
|
- delete params[k];
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- params.filter = JSON.stringify(params.filter);
|
|
|
|
|
- params.offset = params.page;
|
|
|
|
|
- params.limit = params.pageSize;
|
|
|
|
|
- delete params.page;
|
|
|
|
|
- delete params.pageSize;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- function afterFetch(result) {
|
|
|
|
|
- console.log(`result`, result);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- function addRole() {
|
|
|
|
|
- popupData.title = '添加';
|
|
|
|
|
- openPopup(true, {});
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- function handleEdit(record: EditRecordRow) {
|
|
|
|
|
- currentEditKeyRef.value = record.id; // record.key
|
|
|
|
|
- popupData.title = '编辑';
|
|
|
|
|
- const data = getTableAction().getDataSource();
|
|
|
|
|
- data.map((item) => {
|
|
|
|
|
- if (item.id === record.id) {
|
|
|
|
|
- record = item;
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
- openPopup(true, record);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- async function handleDelete(record: Recordable) {
|
|
|
|
|
- console.log(record);
|
|
|
|
|
- await deleteNotice({ id: record.id }).then((res) => {
|
|
|
|
|
- console.log(res);
|
|
|
|
|
- getTableAction().reload();
|
|
|
|
|
- success('删除成功!');
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- function selectionChange() {
|
|
|
|
|
- const keys = getTableAction().getSelectRowKeys();
|
|
|
|
|
- if (keys.length) {
|
|
|
|
|
- btn.disable_btn = false;
|
|
|
|
|
- } else {
|
|
|
|
|
- btn.disable_btn = true;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- function rowClick() {
|
|
|
|
|
- const keys = getTableAction().getSelectRowKeys();
|
|
|
|
|
- if (keys.length) {
|
|
|
|
|
- btn.disable_btn = false;
|
|
|
|
|
- } else {
|
|
|
|
|
- btn.disable_btn = true;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- async function deleteBatches() {
|
|
|
|
|
- const keys = await getTableAction().getSelectRowKeys();
|
|
|
|
|
- const count = keys.length;
|
|
|
|
|
- const ids = keys.toString();
|
|
|
|
|
- if (!ids) {
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- Modal.confirm({
|
|
|
|
|
- title: '删除提示',
|
|
|
|
|
- icon: createVNode(ExclamationCircleOutlined),
|
|
|
|
|
- content: '确定删除选中的' + count + '项?',
|
|
|
|
|
- okText: '确定',
|
|
|
|
|
- okType: 'danger',
|
|
|
|
|
- cancelText: '取消',
|
|
|
|
|
- maskClosable: true,
|
|
|
|
|
- async onOk() {
|
|
|
|
|
- await deleteBatchesNotice({ ids }).then((res) => {
|
|
|
|
|
- console.log(res);
|
|
|
|
|
- getTableAction().reload();
|
|
|
|
|
- success('删除成功!');
|
|
|
|
|
- getTableAction().setSelectedRowKeys([]);
|
|
|
|
|
- });
|
|
|
|
|
- },
|
|
|
|
|
- onCancel() {
|
|
|
|
|
- console.log('Cancel');
|
|
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- async function saveData(params: any) {
|
|
|
|
|
- const data = params.data;
|
|
|
|
|
- const closeModel = params.closeModal;
|
|
|
|
|
- if (!data.id) {
|
|
|
|
|
- await addNotice(data).then((res) => {
|
|
|
|
|
- console.log(res);
|
|
|
|
|
- getTableAction().reload();
|
|
|
|
|
- closeModel();
|
|
|
|
|
- success('创建成功!');
|
|
|
|
|
- });
|
|
|
|
|
- console.log('----------add---');
|
|
|
|
|
- } else {
|
|
|
|
|
- await editNotice(data).then((res) => {
|
|
|
|
|
- console.log(res);
|
|
|
|
|
- getTableAction().reload();
|
|
|
|
|
- closeModel();
|
|
|
|
|
- success('修改成功!');
|
|
|
|
|
- });
|
|
|
|
|
- console.log('----------edit---');
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- function createActions(record: EditRecordRow): ActionItem[] {
|
|
|
|
|
- return [
|
|
|
|
|
- {
|
|
|
|
|
- label: '编辑',
|
|
|
|
|
- icon: 'ant-design:edit-outlined',
|
|
|
|
|
- color: 'warning',
|
|
|
|
|
- onClick: handleEdit.bind(null, record),
|
|
|
|
|
- },
|
|
|
|
|
- {
|
|
|
|
|
- label: '删除',
|
|
|
|
|
- color: 'error',
|
|
|
|
|
- icon: 'ic:outline-delete-outline',
|
|
|
|
|
- popConfirm: {
|
|
|
|
|
- title: '是否确认删除',
|
|
|
|
|
- confirm: handleDelete.bind(null, record),
|
|
|
|
|
- },
|
|
|
|
|
- },
|
|
|
|
|
- ];
|
|
|
|
|
- }
|
|
|
|
|
- return {
|
|
|
|
|
- popupData,
|
|
|
|
|
- tableRef,
|
|
|
|
|
- registerTable,
|
|
|
|
|
- addRole,
|
|
|
|
|
- handleEdit,
|
|
|
|
|
- deleteBatches,
|
|
|
|
|
- createActions,
|
|
|
|
|
- getTableAction,
|
|
|
|
|
- rowClick,
|
|
|
|
|
- selectionChange,
|
|
|
|
|
- addRegister,
|
|
|
|
|
- saveData,
|
|
|
|
|
- openModal,
|
|
|
|
|
- register,
|
|
|
|
|
- ...toRefs(btn),
|
|
|
|
|
- };
|
|
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
-</script>
|
|
|
|
|
-<style scoped>
|
|
|
|
|
- .ant-calendar-picker {
|
|
|
|
|
- width: 100%;
|
|
|
|
|
- }
|
|
|
|
|
- @media (max-width: 639px) {
|
|
|
|
|
- .sys-container .vben-basic-table-header__toolbar > * {
|
|
|
|
|
- margin-right: 3px;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- .sys-container .vben-basic-table .ant-table-wrapper {
|
|
|
|
|
- padding: 3px;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- .vben-basic-table-header__toolbar {
|
|
|
|
|
- justify-content: space-between;
|
|
|
|
|
- }
|
|
|
|
|
- .tool-btn-wrap {
|
|
|
|
|
- flex: 1;
|
|
|
|
|
- }
|
|
|
|
|
- .tool-btn-wrap button {
|
|
|
|
|
- margin-right: 5px;
|
|
|
|
|
- }
|
|
|
|
|
-</style>
|
|
|