This commit is contained in:
2026-07-20 11:50:47 +08:00
parent 95d43746f6
commit 019ed28d37
401 changed files with 61622 additions and 23869 deletions
@@ -19,17 +19,16 @@
:wrapper-col="{ md: { span: 24 }, sm: { span: 24 } }"
layout="vertical"
>
<a-form-item label="文章分类" name="categoryId">
<a-form-item label="知识库分类" name="categoryId">
<category-select
:data="categoryList"
placeholder="请选择文章分类"
placeholder="请选择知识库分类"
v-model:value="form.categoryId"
/>
</a-form-item>
<a-form-item label="文章标题" name="title">
<a-input
allow-clear
:maxlength="20"
placeholder="请输入文章标题"
v-model:value="form.title"
/>
@@ -56,10 +55,8 @@
/>
</div>
</a-form-item>
<a-form-item label="文章来源" name="source">
<source-select
v-model:value="form.source"
/>
<a-form-item label="简介" name="source">
<a-input v-model:value="form.source" />
</a-form-item>
<a-form-item label="展现方式" name="showType">
<a-radio-group v-model:value="form.showType">
@@ -203,7 +200,7 @@ const rules = reactive<Record<string, Rule[]>>({
{
required: true,
type: "number",
message: "请选择文章分类",
message: "请选择知识库分类",
trigger: "blur"
}
],
@@ -267,7 +264,7 @@ const onUpload = (item) => {
url: data.url,
status: "done"
});
form.image = data.path;
form.image = data.url;
message.success("上传成功");
})
.catch((e) => {
@@ -421,7 +418,7 @@ watch(
if (props.data.image) {
images.value.push({
uid: 1,
url: FILE_THUMBNAIL + props.data.image,
url: props.data.image,
status: "done"
});
}
+1 -1
View File
@@ -10,7 +10,7 @@
<div>
<ele-toolbar theme="default">
<a-space :size="10">
<span>文章分类</span>
<span>知识库分类</span>
<a-button
v-permission="'cms:article:save'"
type="primary"
+1 -1
View File
@@ -32,7 +32,7 @@
<a-image
:width="45"
v-if="record.image"
:src="FILE_THUMBNAIL + record.image"
:src="record.image"
:preview="false"
/>
</template>
@@ -0,0 +1,165 @@
<!-- 编辑弹窗 -->
<template>
<ele-modal
:width="800"
:visible="visible"
:maskClosable="false"
:maxable="maxable"
:title="isUpdate ? '编辑' : '添加'"
:body-style="{ paddingBottom: '28px' }"
@update:visible="updateVisible"
@ok="save"
>
<a-form
ref="formRef"
:model="form"
:rules="rules"
:label-col="styleResponsive ? { md: 4, sm: 5, xs: 24 } : { flex: '90px' }"
:wrapper-col="
styleResponsive ? { md: 19, sm: 19, xs: 24 } : { flex: '1' }
"
>
<a-form-item label="" name="articleId">
<a-input
allow-clear
placeholder="请输入"
v-model:value="form.articleId"
/>
</a-form-item>
<a-form-item label="" name="userId">
<a-input
allow-clear
placeholder="请输入"
v-model:value="form.userId"
/>
</a-form-item>
<a-form-item label="状态, 0正常, 1冻结" name="status">
<a-radio-group v-model:value="form.status">
<a-radio :value="1">显示</a-radio>
<a-radio :value="0">隐藏</a-radio>
</a-radio-group>
</a-form-item>
<a-form-item label="是否删除, 0否, 1是" name="deleted">
<a-input
allow-clear
placeholder="请输入是否删除, 0否, 1是"
v-model:value="form.deleted"
/>
</a-form-item>
<a-form-item label="修改时间" name="updateTime">
<a-input
allow-clear
placeholder="请输入修改时间"
v-model:value="form.updateTime"
/>
</a-form-item>
</a-form>
</ele-modal>
</template>
<script lang="ts" setup>
import { ref, reactive, watch } from 'vue';
import { Form, message } from 'ant-design-vue';
import { assignObject, uuid } from 'ele-admin-pro';
import { addArticleCollect, updateArticleCollect } from '@/api/cms/articleCollect';
import { ArticleCollect } from '@/api/cms/articleCollect/model';
import { useThemeStore } from '@/store/modules/theme';
import { storeToRefs } from 'pinia';
import { FormInstance } from 'ant-design-vue/es/form';
import { FileRecord } from '@/api/system/file/model';
// 是否是修改
const isUpdate = ref(false);
const useForm = Form.useForm;
// 是否开启响应式布局
const themeStore = useThemeStore();
const { styleResponsive } = storeToRefs(themeStore);
const props = defineProps<{
// 弹窗是否打开
visible: boolean;
// 修改回显的数据
data?: ArticleCollect | null;
}>();
const emit = defineEmits<{
(e: 'done'): void;
(e: 'update:visible', visible: boolean): void;
}>();
// 提交状态
const loading = ref(false);
// 是否显示最大化切换按钮
const maxable = ref(true);
// 表格选中数据
const formRef = ref<FormInstance | null>(null);
// 用户信息
const form = reactive<ArticleCollect>({
id: undefined,
articleId: undefined,
userId: undefined,
status: undefined,
deleted: undefined,
tenantId: undefined,
createTime: undefined,
updateTime: undefined,
});
/* 更新visible */
const updateVisible = (value: boolean) => {
emit('update:visible', value);
};
// 表单验证规则
const rules = reactive({
});
const { resetFields } = useForm(form, rules);
/* 保存编辑 */
const save = () => {
if (!formRef.value) {
return;
}
formRef.value
.validate()
.then(() => {
loading.value = true;
const formData = {
...form
};
const saveOrUpdate = isUpdate.value ? updateArticleCollect : addArticleCollect;
saveOrUpdate(formData)
.then((msg) => {
loading.value = false;
message.success(msg);
updateVisible(false);
emit('done');
})
.catch((e) => {
loading.value = false;
message.error(e.message);
});
})
.catch(() => {});
};
watch(
() => props.visible,
(visible) => {
if (visible) {
if (props.data) {
assignObject(form, props.data);
isUpdate.value = true;
} else {
isUpdate.value = false;
}
} else {
resetFields();
}
},
{ immediate: true }
);
</script>
@@ -0,0 +1,42 @@
<!-- 搜索表单 -->
<template>
<a-space :size="10" style="flex-wrap: wrap">
<a-button type="primary" class="ele-btn-icon" @click="add">
<template #icon>
<PlusOutlined />
</template>
<span>添加</span>
</a-button>
</a-space>
</template>
<script lang="ts" setup>
import { PlusOutlined } from '@ant-design/icons-vue';
import type { GradeParam } from '@/api/user/grade/model';
import { watch } from 'vue';
const props = withDefaults(
defineProps<{
// 选中的角色
selection?: [];
}>(),
{}
);
const emit = defineEmits<{
(e: 'search', where?: GradeParam): void;
(e: 'add'): void;
(e: 'remove'): void;
(e: 'batchMove'): void;
}>();
// 新增
const add = () => {
emit('add');
};
watch(
() => props.selection,
() => {}
);
</script>
+245
View File
@@ -0,0 +1,245 @@
<template>
<div class="page">
<div class="ele-body">
<a-card :bordered="false" :body-style="{ padding: '16px' }">
<ele-pro-table
ref="tableRef"
row-key="id"
:columns="columns"
:datasource="datasource"
:customRow="customRow"
tool-class="ele-toolbar-form"
class="sys-org-table"
>
<template #toolbar>
<search
@search="reload"
:selection="selection"
@add="openEdit"
@remove="removeBatch"
@batchMove="openMove"
/>
</template>
<template #bodyCell="{ column, record }">
<template v-if="column.key === 'image'">
<a-image :src="record.image" :width="50" />
</template>
<template v-if="column.key === 'status'">
<a-tag v-if="record.status === 1" color="green">显示</a-tag>
<a-tag v-if="record.status === 0" color="red">隐藏</a-tag>
</template>
<template v-if="column.key === 'action'">
<a-space>
<a @click="openEdit(record)">修改</a>
<a-divider type="vertical" />
<a-popconfirm
title="确定要删除此记录吗?"
@confirm="remove(record)"
>
<a class="ele-text-danger">删除</a>
</a-popconfirm>
</a-space>
</template>
</template>
</ele-pro-table>
</a-card>
<!-- 编辑弹窗 -->
<ArticleCollectEdit v-model:visible="showEdit" :data="current" @done="reload" />
</div>
</div>
</template>
<script lang="ts" setup>
import { createVNode, ref } from 'vue';
import { message, Modal } from 'ant-design-vue';
import { ExclamationCircleOutlined } from '@ant-design/icons-vue';
import type { EleProTable } from 'ele-admin-pro';
import { toDateString } from 'ele-admin-pro';
import type {
DatasourceFunction,
ColumnItem
} from 'ele-admin-pro/es/ele-pro-table/types';
import Search from './components/search.vue';
import ArticleCollectEdit from './components/articleCollectEdit.vue';
import { pageArticleCollect, removeArticleCollect, removeBatchArticleCollect } from '@/api/cms/articleCollect';
import type { ArticleCollect, ArticleCollectParam } from '@/api/cms/articleCollect/model';
// 表格实例
const tableRef = ref<InstanceType<typeof EleProTable> | null>(null);
// 表格选中数据
const selection = ref<ArticleCollect[]>([]);
// 当前编辑数据
const current = ref<ArticleCollect | null>(null);
// 是否显示编辑弹窗
const showEdit = ref(false);
// 是否显示批量移动弹窗
const showMove = ref(false);
// 加载状态
const loading = ref(true);
// 表格数据源
const datasource: DatasourceFunction = ({
page,
limit,
where,
orders,
filters
}) => {
if (filters) {
where.status = filters.status;
}
return pageArticleCollect({
...where,
...orders,
page,
limit
});
};
// 表格列配置
const columns = ref<ColumnItem[]>([
{
title: '',
dataIndex: 'id',
key: 'id',
align: 'center',
width: 90,
},
{
title: '',
dataIndex: 'articleId',
key: 'articleId',
align: 'center',
},
{
title: '',
dataIndex: 'userId',
key: 'userId',
align: 'center',
},
{
title: '状态, 0正常, 1冻结',
dataIndex: 'status',
key: 'status',
align: 'center',
},
{
title: '是否删除, 0否, 1是',
dataIndex: 'deleted',
key: 'deleted',
align: 'center',
},
{
title: '注册时间',
dataIndex: 'createTime',
key: 'createTime',
align: 'center',
sorter: true,
ellipsis: true,
customRender: ({ text }) => toDateString(text, 'yyyy-MM-dd')
},
{
title: '修改时间',
dataIndex: 'updateTime',
key: 'updateTime',
align: 'center',
},
{
title: '操作',
key: 'action',
width: 180,
fixed: 'right',
align: 'center',
hideInSetting: true
}
]);
/* 搜索 */
const reload = (where?: ArticleCollectParam) => {
selection.value = [];
tableRef?.value?.reload({ where: where });
};
/* 打开编辑弹窗 */
const openEdit = (row?: ArticleCollect) => {
current.value = row ?? null;
showEdit.value = true;
};
/* 打开批量移动弹窗 */
const openMove = () => {
showMove.value = true;
};
/* 删除单个 */
const remove = (row: ArticleCollect) => {
const hide = message.loading('请求中..', 0);
removeArticleCollect(row.id)
.then((msg) => {
hide();
message.success(msg);
reload();
})
.catch((e) => {
hide();
message.error(e.message);
});
};
/* 批量删除 */
const removeBatch = () => {
if (!selection.value.length) {
message.error('请至少选择一条数据');
return;
}
Modal.confirm({
title: '提示',
content: '确定要删除选中的记录吗?',
icon: createVNode(ExclamationCircleOutlined),
maskClosable: true,
onOk: () => {
const hide = message.loading('请求中..', 0);
removeBatchArticleCollect(selection.value.map((d) => d.id))
.then((msg) => {
hide();
message.success(msg);
reload();
})
.catch((e) => {
hide();
message.error(e.message);
});
}
});
};
/* 查询 */
const query = () => {
loading.value = true;
};
/* 自定义行属性 */
const customRow = (record: ArticleCollect) => {
return {
// 行点击事件
onClick: () => {
// console.log(record);
},
// 行双击事件
onDblclick: () => {
openEdit(record);
}
};
};
query();
</script>
<script lang="ts">
export default {
name: 'ArticleCollect'
};
</script>
<style lang="less" scoped></style>
@@ -0,0 +1,173 @@
<!-- 编辑弹窗 -->
<template>
<ele-modal
:width="800"
:visible="visible"
:maskClosable="false"
:maxable="maxable"
:title="isUpdate ? '编辑' : '添加'"
:body-style="{ paddingBottom: '28px' }"
@update:visible="updateVisible"
@ok="save"
>
<a-form
ref="formRef"
:model="form"
:rules="rules"
:label-col="styleResponsive ? { md: 4, sm: 5, xs: 24 } : { flex: '90px' }"
:wrapper-col="
styleResponsive ? { md: 19, sm: 19, xs: 24 } : { flex: '1' }
"
>
<a-form-item label="" name="articleId">
<a-input
allow-clear
placeholder="请输入"
v-model:value="form.articleId"
/>
</a-form-item>
<a-form-item label="" name="userId">
<a-input
allow-clear
placeholder="请输入"
v-model:value="form.userId"
/>
</a-form-item>
<a-form-item label="" name="content">
<a-input
allow-clear
placeholder="请输入"
v-model:value="form.content"
/>
</a-form-item>
<a-form-item label="状态, 0正常, 1冻结" name="status">
<a-radio-group v-model:value="form.status">
<a-radio :value="1">显示</a-radio>
<a-radio :value="0">隐藏</a-radio>
</a-radio-group>
</a-form-item>
<a-form-item label="是否删除, 0否, 1是" name="deleted">
<a-input
allow-clear
placeholder="请输入是否删除, 0否, 1是"
v-model:value="form.deleted"
/>
</a-form-item>
<a-form-item label="修改时间" name="updateTime">
<a-input
allow-clear
placeholder="请输入修改时间"
v-model:value="form.updateTime"
/>
</a-form-item>
</a-form>
</ele-modal>
</template>
<script lang="ts" setup>
import { ref, reactive, watch } from 'vue';
import { Form, message } from 'ant-design-vue';
import { assignObject, uuid } from 'ele-admin-pro';
import { addArticleComment, updateArticleComment } from '@/api/cms/articleComment';
import { ArticleComment } from '@/api/cms/articleComment/model';
import { useThemeStore } from '@/store/modules/theme';
import { storeToRefs } from 'pinia';
import { FormInstance } from 'ant-design-vue/es/form';
import { FileRecord } from '@/api/system/file/model';
// 是否是修改
const isUpdate = ref(false);
const useForm = Form.useForm;
// 是否开启响应式布局
const themeStore = useThemeStore();
const { styleResponsive } = storeToRefs(themeStore);
const props = defineProps<{
// 弹窗是否打开
visible: boolean;
// 修改回显的数据
data?: ArticleComment | null;
}>();
const emit = defineEmits<{
(e: 'done'): void;
(e: 'update:visible', visible: boolean): void;
}>();
// 提交状态
const loading = ref(false);
// 是否显示最大化切换按钮
const maxable = ref(true);
// 表格选中数据
const formRef = ref<FormInstance | null>(null);
// 用户信息
const form = reactive<ArticleComment>({
id: undefined,
articleId: undefined,
userId: undefined,
content: undefined,
status: undefined,
deleted: undefined,
tenantId: undefined,
createTime: undefined,
updateTime: undefined,
});
/* 更新visible */
const updateVisible = (value: boolean) => {
emit('update:visible', value);
};
// 表单验证规则
const rules = reactive({
});
const { resetFields } = useForm(form, rules);
/* 保存编辑 */
const save = () => {
if (!formRef.value) {
return;
}
formRef.value
.validate()
.then(() => {
loading.value = true;
const formData = {
...form
};
const saveOrUpdate = isUpdate.value ? updateArticleComment : addArticleComment;
saveOrUpdate(formData)
.then((msg) => {
loading.value = false;
message.success(msg);
updateVisible(false);
emit('done');
})
.catch((e) => {
loading.value = false;
message.error(e.message);
});
})
.catch(() => {});
};
watch(
() => props.visible,
(visible) => {
if (visible) {
if (props.data) {
assignObject(form, props.data);
isUpdate.value = true;
} else {
isUpdate.value = false;
}
} else {
resetFields();
}
},
{ immediate: true }
);
</script>
@@ -0,0 +1,42 @@
<!-- 搜索表单 -->
<template>
<a-space :size="10" style="flex-wrap: wrap">
<a-button type="primary" class="ele-btn-icon" @click="add">
<template #icon>
<PlusOutlined />
</template>
<span>添加</span>
</a-button>
</a-space>
</template>
<script lang="ts" setup>
import { PlusOutlined } from '@ant-design/icons-vue';
import type { GradeParam } from '@/api/user/grade/model';
import { watch } from 'vue';
const props = withDefaults(
defineProps<{
// 选中的角色
selection?: [];
}>(),
{}
);
const emit = defineEmits<{
(e: 'search', where?: GradeParam): void;
(e: 'add'): void;
(e: 'remove'): void;
(e: 'batchMove'): void;
}>();
// 新增
const add = () => {
emit('add');
};
watch(
() => props.selection,
() => {}
);
</script>
+251
View File
@@ -0,0 +1,251 @@
<template>
<div class="page">
<div class="ele-body">
<a-card :bordered="false" :body-style="{ padding: '16px' }">
<ele-pro-table
ref="tableRef"
row-key="id"
:columns="columns"
:datasource="datasource"
:customRow="customRow"
tool-class="ele-toolbar-form"
class="sys-org-table"
>
<template #toolbar>
<search
@search="reload"
:selection="selection"
@add="openEdit"
@remove="removeBatch"
@batchMove="openMove"
/>
</template>
<template #bodyCell="{ column, record }">
<template v-if="column.key === 'image'">
<a-image :src="record.image" :width="50" />
</template>
<template v-if="column.key === 'status'">
<a-tag v-if="record.status === 1" color="green">显示</a-tag>
<a-tag v-if="record.status === 0" color="red">隐藏</a-tag>
</template>
<template v-if="column.key === 'action'">
<a-space>
<a @click="openEdit(record)">修改</a>
<a-divider type="vertical" />
<a-popconfirm
title="确定要删除此记录吗?"
@confirm="remove(record)"
>
<a class="ele-text-danger">删除</a>
</a-popconfirm>
</a-space>
</template>
</template>
</ele-pro-table>
</a-card>
<!-- 编辑弹窗 -->
<ArticleCommentEdit v-model:visible="showEdit" :data="current" @done="reload" />
</div>
</div>
</template>
<script lang="ts" setup>
import { createVNode, ref } from 'vue';
import { message, Modal } from 'ant-design-vue';
import { ExclamationCircleOutlined } from '@ant-design/icons-vue';
import type { EleProTable } from 'ele-admin-pro';
import { toDateString } from 'ele-admin-pro';
import type {
DatasourceFunction,
ColumnItem
} from 'ele-admin-pro/es/ele-pro-table/types';
import Search from './components/search.vue';
import ArticleCommentEdit from './components/articleCommentEdit.vue';
import { pageArticleComment, removeArticleComment, removeBatchArticleComment } from '@/api/cms/articleComment';
import type { ArticleComment, ArticleCommentParam } from '@/api/cms/articleComment/model';
// 表格实例
const tableRef = ref<InstanceType<typeof EleProTable> | null>(null);
// 表格选中数据
const selection = ref<ArticleComment[]>([]);
// 当前编辑数据
const current = ref<ArticleComment | null>(null);
// 是否显示编辑弹窗
const showEdit = ref(false);
// 是否显示批量移动弹窗
const showMove = ref(false);
// 加载状态
const loading = ref(true);
// 表格数据源
const datasource: DatasourceFunction = ({
page,
limit,
where,
orders,
filters
}) => {
if (filters) {
where.status = filters.status;
}
return pageArticleComment({
...where,
...orders,
page,
limit
});
};
// 表格列配置
const columns = ref<ColumnItem[]>([
{
title: '',
dataIndex: 'id',
key: 'id',
align: 'center',
width: 90,
},
{
title: '',
dataIndex: 'articleId',
key: 'articleId',
align: 'center',
},
{
title: '',
dataIndex: 'userId',
key: 'userId',
align: 'center',
},
{
title: '',
dataIndex: 'content',
key: 'content',
align: 'center',
},
{
title: '状态, 0正常, 1冻结',
dataIndex: 'status',
key: 'status',
align: 'center',
},
{
title: '是否删除, 0否, 1是',
dataIndex: 'deleted',
key: 'deleted',
align: 'center',
},
{
title: '注册时间',
dataIndex: 'createTime',
key: 'createTime',
align: 'center',
sorter: true,
ellipsis: true,
customRender: ({ text }) => toDateString(text, 'yyyy-MM-dd')
},
{
title: '修改时间',
dataIndex: 'updateTime',
key: 'updateTime',
align: 'center',
},
{
title: '操作',
key: 'action',
width: 180,
fixed: 'right',
align: 'center',
hideInSetting: true
}
]);
/* 搜索 */
const reload = (where?: ArticleCommentParam) => {
selection.value = [];
tableRef?.value?.reload({ where: where });
};
/* 打开编辑弹窗 */
const openEdit = (row?: ArticleComment) => {
current.value = row ?? null;
showEdit.value = true;
};
/* 打开批量移动弹窗 */
const openMove = () => {
showMove.value = true;
};
/* 删除单个 */
const remove = (row: ArticleComment) => {
const hide = message.loading('请求中..', 0);
removeArticleComment(row.id)
.then((msg) => {
hide();
message.success(msg);
reload();
})
.catch((e) => {
hide();
message.error(e.message);
});
};
/* 批量删除 */
const removeBatch = () => {
if (!selection.value.length) {
message.error('请至少选择一条数据');
return;
}
Modal.confirm({
title: '提示',
content: '确定要删除选中的记录吗?',
icon: createVNode(ExclamationCircleOutlined),
maskClosable: true,
onOk: () => {
const hide = message.loading('请求中..', 0);
removeBatchArticleComment(selection.value.map((d) => d.id))
.then((msg) => {
hide();
message.success(msg);
reload();
})
.catch((e) => {
hide();
message.error(e.message);
});
}
});
};
/* 查询 */
const query = () => {
loading.value = true;
};
/* 自定义行属性 */
const customRow = (record: ArticleComment) => {
return {
// 行点击事件
onClick: () => {
// console.log(record);
},
// 行双击事件
onDblclick: () => {
openEdit(record);
}
};
};
query();
</script>
<script lang="ts">
export default {
name: 'ArticleComment'
};
</script>
<style lang="less" scoped></style>
@@ -0,0 +1,358 @@
<!-- 编辑弹窗 -->
<template>
<ele-modal
:width="1000"
:visible="visible"
:maskClosable="false"
:maxable="maxable"
:confirm-loading="loading"
:title="isUpdate ? '编辑稿件' : '添加稿件'"
:body-style="{ paddingBottom: '28px' }"
@update:visible="updateVisible"
@ok="save"
>
<a-form
ref="formRef"
:model="form"
:rules="rules"
:label-col="
styleResponsive ? { md: 4, sm: 5, xs: 24 } : { flex: '100px' }
"
:wrapper-col="
styleResponsive ? { md: 19, sm: 19, xs: 24 } : { flex: '1' }
"
>
<a-form-item label="标题" name="title">
<a-input
allow-clear
placeholder="请输入稿件标题"
v-model:value="form.title"
/>
</a-form-item>
<a-form-item label="内容" name="content">
<div class="editor-wrapper">
<Toolbar
class="editor-toolbar"
:editor="editorRef"
:defaultConfig="toolbarConfig"
mode="default"
/>
<Editor
v-model="contentHtml"
class="editor-content"
:defaultConfig="editorConfig"
mode="default"
@onCreated="handleCreated"
/>
</div>
<div class="editor-tip">支持直接粘贴内容,粘贴图片时会自动上传。</div>
</a-form-item>
<a-form-item label="封面" name="cover">
<ele-image-upload
v-model:value="coverList"
:limit="1"
:drag="true"
:upload-handler="uploadHandler"
@upload="onUpload"
/>
</a-form-item>
<a-form-item label="排序" name="sortNumber">
<a-input-number
:min="0"
:max="9999"
class="ele-fluid"
placeholder="请输入排序号"
v-model:value="form.sortNumber"
/>
</a-form-item>
<a-form-item label="状态" name="status">
<a-radio-group v-model:value="form.status">
<a-radio :value="1">显示</a-radio>
<a-radio :value="0">隐藏</a-radio>
</a-radio-group>
</a-form-item>
</a-form>
</ele-modal>
</template>
<script lang="ts" setup>
import { shallowRef, ref, reactive, watch, onBeforeUnmount } from 'vue';
import { Form, message } from 'ant-design-vue';
import { assignObject } from 'ele-admin-pro';
import { addManuscript, updateManuscript } from '@/api/cms/manuscript';
import { Manuscript } from '@/api/cms/manuscript/model';
import { useThemeStore } from '@/store/modules/theme';
import { storeToRefs } from 'pinia';
import { FormInstance } from 'ant-design-vue/es/form';
import { uploadFile } from '@/api/system/file';
import type { ItemType } from 'ele-admin-pro/es/ele-image-upload/types';
import { Editor, Toolbar } from '@wangeditor/editor-for-vue';
import type {
IDomEditor,
IEditorConfig,
IToolbarConfig
} from '@wangeditor/editor';
import '@wangeditor/editor/dist/css/style.css';
const isUpdate = ref(false);
const useForm = Form.useForm;
const themeStore = useThemeStore();
const { styleResponsive } = storeToRefs(themeStore);
const props = defineProps<{
visible: boolean;
data?: Manuscript | null;
}>();
const emit = defineEmits<{
(e: 'done'): void;
(e: 'update:visible', visible: boolean): void;
}>();
const loading = ref(false);
const maxable = ref(true);
const formRef = ref<FormInstance | null>(null);
const editorRef = shallowRef<IDomEditor>();
const contentHtml = ref('');
const coverList = ref<ItemType[]>([]);
const toolbarConfig: Partial<IToolbarConfig> = {
excludeKeys: ['group-video']
};
const editorConfig: Partial<IEditorConfig> = {
placeholder: '请输入稿件内容,支持粘贴图片自动上传',
MENU_CONF: {
uploadImage: {
allowedFileTypes: ['image/*'],
maxFileSize: 2 * 1024 * 1024,
base64LimitSize: 0,
async customUpload(file: File, insertFn: (url: string) => void) {
if (!file.type.startsWith('image/')) {
message.error('只能上传图片');
return;
}
try {
const result = await uploadFile(file);
insertFn(result.url);
} catch (e: any) {
message.error(e.message || '图片上传失败');
}
}
}
}
};
const form = reactive<Manuscript>({
id: undefined,
title: undefined,
content: undefined,
cover: undefined,
deleted: undefined,
tenantId: undefined,
createTime: undefined,
updateTime: undefined,
userId: undefined,
sortNumber: 0,
status: 1
});
const updateVisible = (value: boolean) => {
emit('update:visible', value);
};
const hasEditorContent = (html?: string) => {
const text = String(html || '')
.replace(/<style[^>]*>[\s\S]*?<\/style>/gi, '')
.replace(/<script[^>]*>[\s\S]*?<\/script>/gi, '')
.replace(/<[^>]+>/g, '')
.replace(/&nbsp;/gi, '')
.trim();
return !!text || /<img\b/i.test(String(html || ''));
};
const rules = reactive({
title: [
{
required: true,
type: 'string',
whitespace: true,
message: '请输入稿件标题',
trigger: 'blur'
}
],
content: [
{
validator: async () => {
if (!hasEditorContent(contentHtml.value)) {
return Promise.reject(new Error('请输入稿件内容'));
}
return Promise.resolve();
},
trigger: 'change'
}
],
sortNumber: [
{
required: true,
type: 'number',
message: '请输入排序号',
trigger: 'change'
}
]
});
const { resetFields, validate } = useForm(form, rules);
const handleCreated = (editor: IDomEditor) => {
editorRef.value = editor;
};
const uploadHandler = (file: File) => {
const item: ItemType = {
file,
uid: (file as any).uid,
name: file.name
};
if (!file.type.startsWith('image/')) {
message.error('只能选择图片');
return;
}
if (file.size / 1024 / 1024 > 2) {
message.error('大小不能超过 2MB');
return;
}
onUpload(item);
};
const onUpload = (item: ItemType) => {
const { file } = item;
uploadFile(file as File)
.then((data) => {
coverList.value = [
{
uid: data.id,
url: data.url,
status: 'done'
}
];
form.cover = data.url;
message.success('上传成功');
})
.catch((e) => {
message.error(e.message);
});
};
const resetEditor = () => {
contentHtml.value = '';
};
const save = async () => {
if (!formRef.value) {
return;
}
try {
await formRef.value.validate();
loading.value = true;
const formData = {
...form,
content: contentHtml.value
};
const saveOrUpdate = isUpdate.value ? updateManuscript : addManuscript;
const msg = await saveOrUpdate(formData);
message.success(msg);
updateVisible(false);
emit('done');
} catch (e: any) {
if (!e?.errorFields) {
message.error(e.message || '保存失败');
}
} finally {
loading.value = false;
}
};
watch(contentHtml, () => {
form.content = contentHtml.value;
validate('content').catch(() => {});
});
watch(
coverList,
(list) => {
if (!list.length) {
form.cover = '';
}
},
{ deep: true }
);
watch(
() => props.visible,
(visible) => {
if (visible) {
if (props.data) {
assignObject(form, props.data);
contentHtml.value = props.data.content || '';
coverList.value = props.data.cover
? [
{
uid: props.data.id || 1,
url: props.data.cover,
status: 'done'
}
]
: [];
isUpdate.value = true;
} else {
resetFields();
resetEditor();
coverList.value = [];
form.status = 1;
form.sortNumber = 0;
isUpdate.value = false;
}
} else {
resetFields();
resetEditor();
coverList.value = [];
}
},
{ immediate: true }
);
onBeforeUnmount(() => {
const editor = editorRef.value;
if (editor != null) {
editor.destroy();
}
});
</script>
<style lang="less" scoped>
.editor-wrapper {
border: 1px solid #d9d9d9;
border-radius: 6px;
overflow: hidden;
}
.editor-toolbar {
border-bottom: 1px solid #f0f0f0;
}
.editor-content {
min-height: 360px;
}
.editor-content :deep(.w-e-text-container) {
min-height: 360px;
}
.editor-tip {
margin-top: 8px;
color: #999;
font-size: 12px;
line-height: 1.5;
}
</style>
@@ -0,0 +1,177 @@
<template>
<ele-modal
:width="860"
:visible="visible"
:maskClosable="false"
:maxable="maxable"
:confirm-loading="loading"
title="审核历史"
:body-style="{ paddingBottom: '28px' }"
@update:visible="updateVisible"
@ok="save"
>
<a-alert
v-if="!data?.id"
type="warning"
show-icon
message="未选择稿件,无法新增审核记录"
style="margin-bottom: 12px"
/>
<a-descriptions
v-if="data?.id"
size="small"
:column="2"
style="margin-bottom: 12px"
>
<a-descriptions-item label="稿件ID">
{{ data?.id }}
</a-descriptions-item>
<a-descriptions-item label="标题">
{{ data?.title || '-' }}
</a-descriptions-item>
</a-descriptions>
<div style="overflow-y: auto; padding: 10px 0" class="ele-scrollbar-hover">
<a-timeline v-if="historyData.length > 0">
<a-timeline-item
v-for="item in historyData"
:key="item.id"
:color="item.status === 1 ? 'green' : item.status === 0 ? 'red' : 'gray'"
>
<div style="margin-bottom: 8px">
<span style="color: rgba(0, 0, 0, 0.45)">
{{ toDateString(item.createTime, 'yyyy-MM-dd HH:mm:ss') }}
</span>
<a-tag
:color="item.status === 1 ? 'success' : item.status === 0 ? 'error' : 'default'"
style="margin-left: 8px"
>
{{ item.status === 1 ? '通过' : item.status === 0 ? '不通过' : '-' }}
</a-tag>
</div>
<div v-if="item.user?.realName" style="margin-bottom: 4px">
<span style="font-weight: 500">审核人:</span>
<span>{{ item.user.realName }}</span>
</div>
<div v-if="item.content" style="color: rgba(0, 0, 0, 0.85)">
{{ item.content }}
</div>
</a-timeline-item>
</a-timeline>
<a-empty v-else description="暂无审核记录" :image="simpleImage" />
</div>
</ele-modal>
</template>
<script lang="ts" setup>
import { computed, reactive, ref, watch } from 'vue';
import { Form, message, Empty } from 'ant-design-vue';
import type { FormInstance } from 'ant-design-vue/es/form';
import { toDateString } from 'ele-admin-pro';
import { storeToRefs } from 'pinia';
import { useThemeStore } from '@/store/modules/theme';
import { addReviewList } from '@/api/gxmu/reviewList';
import type { ReviewList } from '@/api/gxmu/reviewList/model';
import type { Manuscript } from '@/api/cms/manuscript/model';
const REVIEW_MODULE = 'cms_manuscript';
const props = defineProps<{
visible: boolean;
data?: Manuscript | null;
}>();
const emit = defineEmits<{
(e: 'done'): void;
(e: 'update:visible', visible: boolean): void;
}>();
const themeStore = useThemeStore();
const { styleResponsive } = storeToRefs(themeStore);
const useForm = Form.useForm;
const loading = ref(false);
const maxable = ref(true);
const formRef = ref<FormInstance | null>(null);
const simpleImage = Empty.PRESENTED_IMAGE_SIMPLE;
const form = reactive<ReviewList>({
module: REVIEW_MODULE,
pk: undefined,
status: undefined,
content: undefined
});
const rules = reactive({
status: [
{ required: true, type: 'number', message: '请选择审核状态', trigger: 'change' }
]
});
const { resetFields } = useForm(form, rules);
const updateVisible = (value: boolean) => {
emit('update:visible', value);
};
const historyData = computed(() => {
const list = props.data?.reviewList ?? [];
return [...list].reverse();
});
const save = () => {
if (!props.data?.id) {
message.error('未选择稿件');
return;
}
if (!formRef.value) {
return;
}
formRef.value
.validate()
.then(() => {
loading.value = true;
const payload: ReviewList = {
module: REVIEW_MODULE,
pk: props.data?.id,
status: form.status,
content: form.content
};
addReviewList(payload)
.then((msg) => {
loading.value = false;
message.success(msg);
updateVisible(false);
emit('done');
})
.catch((e) => {
loading.value = false;
message.error(e.message);
});
})
.catch(() => {});
};
watch(
() => props.visible,
(visible) => {
if (visible) {
form.module = REVIEW_MODULE;
form.pk = props.data?.id;
form.status = undefined;
form.content = undefined;
} else {
resetFields();
}
},
{ immediate: true }
);
</script>
<style lang="less" scoped>
.ele-scrollbar-hover :deep(.ant-timeline-item-last > .ant-timeline-item-content) {
min-height: auto;
}
</style>
@@ -0,0 +1,42 @@
<!-- 搜索表单 -->
<template>
<a-space :size="10" style="flex-wrap: wrap">
<a-button type="primary" class="ele-btn-icon" @click="add">
<template #icon>
<PlusOutlined />
</template>
<span>添加</span>
</a-button>
</a-space>
</template>
<script lang="ts" setup>
import { PlusOutlined } from '@ant-design/icons-vue';
import type { GradeParam } from '@/api/user/grade/model';
import { watch } from 'vue';
const props = withDefaults(
defineProps<{
// 选中的角色
selection?: [];
}>(),
{}
);
const emit = defineEmits<{
(e: 'search', where?: GradeParam): void;
(e: 'add'): void;
(e: 'remove'): void;
(e: 'batchMove'): void;
}>();
// 新增
const add = () => {
emit('add');
};
watch(
() => props.selection,
() => {}
);
</script>
+276
View File
@@ -0,0 +1,276 @@
<template>
<div class="page">
<div class="ele-body">
<a-card :bordered="false" :body-style="{ padding: '16px' }">
<ele-pro-table
ref="tableRef"
row-key="id"
:columns="columns"
:datasource="datasource"
:customRow="customRow"
tool-class="ele-toolbar-form"
class="sys-org-table"
>
<template #toolbar>
<search
@search="reload"
:selection="selection"
@add="openEdit"
@remove="removeBatch"
@batchMove="openMove"
/>
</template>
<template #bodyCell="{ column, record }">
<template v-if="column.key === 'cover'">
<a-image :src="record.cover" :width="50" />
</template>
<template v-if="column.key === 'currentReviewStatus'">
<template v-if="getLastReview(record)?.status === 1">
<a-tag color="green">通过</a-tag>
</template>
<template v-else-if="getLastReview(record)?.status === 2">
<a-tag color="red">不通过</a-tag>
</template>
<template v-else>
<a-tag>未审核</a-tag>
</template>
</template>
<template v-if="column.key === 'status'">
<a-tag v-if="record.status === 0">待审核</a-tag>
<a-tag v-if="record.status === 1" color="green">显示</a-tag>
</template>
<template v-if="column.key === 'action'">
<a-space>
<a @click="openEdit(record)">修改</a>
<a-divider type="vertical" />
<a @click="openReviewModal(record)">审核历史</a>
<a-divider type="vertical" />
<a-popconfirm
title="确定要删除此记录吗?"
@confirm="remove(record)"
>
<a class="ele-text-danger">删除</a>
</a-popconfirm>
</a-space>
</template>
</template>
</ele-pro-table>
</a-card>
<!-- 编辑弹窗 -->
<ManuscriptEdit v-model:visible="showEdit" :data="current" @done="reload" />
<!-- 新增审核记录弹窗 -->
<ReviewRecordModal
v-model:visible="showReviewModal"
:data="reviewTarget"
@done="reload"
/>
</div>
</div>
</template>
<script lang="ts" setup>
import { createVNode, ref } from 'vue';
import { message, Modal } from 'ant-design-vue';
import { ExclamationCircleOutlined } from '@ant-design/icons-vue';
import type { EleProTable } from 'ele-admin-pro';
import { toDateString } from 'ele-admin-pro';
import type {
DatasourceFunction,
ColumnItem
} from 'ele-admin-pro/es/ele-pro-table/types';
import Search from './components/search.vue';
import ManuscriptEdit from './components/manuscriptEdit.vue';
import ReviewRecordModal from './components/reviewRecordModal.vue';
import { pageManuscript, removeManuscript, removeBatchManuscript } from '@/api/cms/manuscript';
import type { Manuscript, ManuscriptParam } from '@/api/cms/manuscript/model';
import type { ReviewList } from '@/api/gxmu/reviewList/model';
// 表格实例
const tableRef = ref<InstanceType<typeof EleProTable> | null>(null);
// 表格选中数据
const selection = ref<Manuscript[]>([]);
// 当前编辑数据
const current = ref<Manuscript | null>(null);
// 是否显示编辑弹窗
const showEdit = ref(false);
// 是否显示新增审核记录弹窗
const showReviewModal = ref(false);
// 当前要新增审核记录的稿件
const reviewTarget = ref<Manuscript | null>(null);
// 是否显示批量移动弹窗
const showMove = ref(false);
// 加载状态
const loading = ref(true);
// 表格数据源
const datasource: DatasourceFunction = ({
page,
limit,
where,
orders,
filters
}) => {
if (filters) {
where.status = filters.status;
}
return pageManuscript({
...where,
...orders,
page,
limit
});
};
// 表格列配置
const columns = ref<ColumnItem[]>([
{
title: 'ID',
dataIndex: 'id',
key: 'id',
align: 'center',
width: 90,
},
{
title: '标题',
dataIndex: 'title',
key: 'title',
align: 'center',
},
{
title: '封面',
dataIndex: 'cover',
key: 'cover',
align: 'center',
},
{
title: '创建时间',
dataIndex: 'createTime',
key: 'createTime',
align: 'center',
sorter: true,
ellipsis: true,
customRender: ({ text }) => toDateString(text, 'yyyy-MM-dd HH:mm:ss')
},
{
title: '状态',
dataIndex: 'status',
key: 'status',
align: 'center',
},
{
title: '当前审核状态',
dataIndex: 'reviewList',
key: 'currentReviewStatus',
align: 'center',
width: 140
},
{
title: '操作',
key: 'action',
width: 260,
fixed: 'right',
align: 'center',
hideInSetting: true
}
]);
/* 搜索 */
const reload = (where?: ManuscriptParam) => {
selection.value = [];
tableRef?.value?.reload({ where: where });
};
/* 打开编辑弹窗 */
const openEdit = (row?: Manuscript) => {
current.value = row ?? null;
showEdit.value = true;
};
const getLastReview = (row: Manuscript): ReviewList | undefined => {
const list = row.reviewList ?? [];
return list.length ? list[list.length - 1] : undefined;
};
/* 打开新增审核记录弹窗 */
const openReviewModal = (row: Manuscript) => {
reviewTarget.value = row;
showReviewModal.value = true;
};
/* 打开批量移动弹窗 */
const openMove = () => {
showMove.value = true;
};
/* 删除单个 */
const remove = (row: Manuscript) => {
const hide = message.loading('请求中..', 0);
removeManuscript(row.id)
.then((msg) => {
hide();
message.success(msg);
reload();
})
.catch((e) => {
hide();
message.error(e.message);
});
};
/* 批量删除 */
const removeBatch = () => {
if (!selection.value.length) {
message.error('请至少选择一条数据');
return;
}
Modal.confirm({
title: '提示',
content: '确定要删除选中的记录吗?',
icon: createVNode(ExclamationCircleOutlined),
maskClosable: true,
onOk: () => {
const hide = message.loading('请求中..', 0);
removeBatchManuscript(selection.value.map((d) => d.id))
.then((msg) => {
hide();
message.success(msg);
reload();
})
.catch((e) => {
hide();
message.error(e.message);
});
}
});
};
/* 查询 */
const query = () => {
loading.value = true;
};
/* 自定义行属性 */
const customRow = (record: Manuscript) => {
return {
// 行点击事件
onClick: () => {
// console.log(record);
},
// 行双击事件
onDblclick: () => {
openEdit(record);
}
};
};
query();
</script>
<script lang="ts">
export default {
name: 'Manuscript'
};
</script>
<style lang="less" scoped></style>