优化修复网站导航的bug

This commit is contained in:
2024-08-28 23:55:01 +08:00
parent 31ec8e057a
commit 2655874948
34 changed files with 1764 additions and 849 deletions
+304 -198
View File
@@ -1,220 +1,292 @@
<template>
<div class="ele-body">
<a-card :bordered="false" :body-style="{ padding: '16px' }">
<ele-split-layout
width="266px"
allow-collapse
:right-style="{ overflow: 'hidden' }"
:style="{ minHeight: 'calc(100vh - 152px)' }"
>
<div>
<ele-toolbar theme="default">
<a-space :size="10">
<a-button
type="primary"
:size="`small`"
class="ele-btn-icon"
@click="openEdit()"
<div class="page">
<div class="ele-body">
<a-card :bordered="false" :body-style="{ padding: '16px' }">
<ele-pro-table
ref="tableRef"
row-key="articleId"
:columns="columns"
:datasource="datasource"
:customRow="customRow"
:scroll="{ x: 1200 }"
tool-class="ele-toolbar-form"
class="sys-org-table"
>
<template #toolbar>
<search
@search="reload"
:selection="selection"
:navigationList="navigationList"
:merchantId="merchantId"
:model="model"
@add="openEdit"
@remove="removeBatch"
@batchMove="openMove"
/>
</template>
<template #bodyCell="{ column, record }">
<template v-if="column.key === 'title'">
<a
@click="
openSpmUrl(
`/article/detail/${record.articleId}.html`,
record,
record.articleId
)
"
>{{ record.title }}</a
>
<template #icon>
<plus-outlined />
</template>
</a-button>
<a-button
type="primary"
:size="`small`"
:disabled="!current"
class="ele-btn-icon"
@click="openEdit(current)"
</template>
<template v-if="column.key === 'type'">
<a-tag v-if="record.type === 0">虚拟文章</a-tag>
<a-tag v-if="record.type === 1">实物文章</a-tag>
</template>
<template v-if="column.key === 'image'">
<a-image :src="record.image" :width="80" />
</template>
<template v-if="column.key === 'salePrice'">
¥{{ formatNumber(record.salePrice) }}
</template>
<template v-if="column.key === 'status'">
<a-tag
:color="record.status == 0 ? 'green' : 'red'"
class="cursor-pointer"
@click="onUpdate(record)"
>{{ record.statusText }}</a-tag
>
<template #icon>
<edit-outlined />
</template>
</a-button>
<a-button
danger
type="primary"
:size="`small`"
:disabled="!current"
class="ele-btn-icon"
@click="remove"
>
<template #icon>
<delete-outlined />
</template>
</a-button>
</a-space>
</ele-toolbar>
<div class="ele-border-split sys-category-list">
<a-tree
:tree-data="data"
v-model:expanded-keys="expandedRowKeys"
v-model:selected-keys="selectedRowKeys"
@select="onTreeSelect"
>
<template #title="{ type, key: treeKey, title }">
<a-dropdown :trigger="['contextmenu']">
<span>{{ title }}</span>
<template #overlay v-if="type == 0">
<a-menu
@click="
({ key: menuKey }) =>
onContextMenuClick(treeKey, menuKey)
"
>
<a-menu-item key="1">修改</a-menu-item>
<a-menu-item key="2">删除</a-menu-item>
</a-menu>
</template>
</a-dropdown>
</template>
</a-tree>
</div>
</div>
<template #content>
<list
v-if="current"
:category-list="data"
:data="current"
:category-id="current.categoryId"
/>
</template>
</ele-split-layout>
</a-card>
<!-- 编辑弹窗 -->
<category-edit
v-model:visible="showEdit"
:data="editData"
:category-list="data"
:category-id="current?.categoryId"
@done="query"
/>
</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>
<!-- 编辑弹窗 -->
<ArticleEdit
v-model:visible="showEdit"
:navigationList="navigationList"
:data="current"
@done="reload"
/>
</div>
</div>
</template>
<script lang="ts" setup>
import { createVNode, ref } from 'vue';
import { createVNode, ref, watch } from 'vue';
import { message, Modal } from 'ant-design-vue';
import { ExclamationCircleOutlined } from '@ant-design/icons-vue';
import type { EleProTable } from 'ele-admin-pro';
import type {
DatasourceFunction,
ColumnItem
} from 'ele-admin-pro/es/ele-pro-table/types';
import Search from './components/search.vue';
import ArticleEdit from './components/articleEdit.vue';
import {
PlusOutlined,
EditOutlined,
DeleteOutlined,
ExclamationCircleOutlined
} from '@ant-design/icons-vue';
import { toTreeData, eachTreeData } from 'ele-admin-pro';
import List from './list.vue';
import CategoryEdit from './components/category-edit.vue';
import {
listArticleCategory,
removeArticleCategory
} from '@/api/cms/category';
import { ArticleCategory } from '@/api/cms/category/model';
pageArticle,
removeArticle,
removeBatchArticle
} from '@/api/cms/article';
import type { Article, ArticleParam } from '@/api/cms/article/model';
import { formatNumber } from 'ele-admin-pro/es';
import router from '@/router';
import { toTreeData } from 'ele-admin-pro';
import { openSpmUrl } from '@/utils/common';
import { getSiteDomain } from '@/utils/domain';
import { listNavigation } from '@/api/cms/navigation';
import { Navigation } from '@/api/cms/navigation/model';
// 加载状态
const loading = ref(true);
// 表格实例
const tableRef = ref<InstanceType<typeof EleProTable> | null>(null);
// 树形数据
const data = ref<ArticleCategory[]>([]);
// 树展开的key
const expandedRowKeys = ref<number[]>([]);
// 树选中的key
const selectedRowKeys = ref<number[]>([]);
// 选中数据
const current = ref<ArticleCategory | any>(null);
// 是否显示表单弹窗
// 表格选中数据
const selection = ref<Article[]>([]);
// 当前编辑数据
const current = ref<Article | null>(null);
// 是否显示编辑弹窗
const showEdit = ref(false);
// 是否显示批量移动弹窗
const showMove = ref(false);
// 店铺ID
const merchantId = ref<number>();
// 栏目ID
const categoryId = ref<number>();
// 当前模型
const model = ref<number>();
// 网站域名
const domain = getSiteDomain();
// 随机数
const token = ref<any>('');
// 栏目数据
const navigationList = ref<Navigation[]>();
// 编辑回显数据
const editData = ref<ArticleCategory | null>(null);
// 表格数据源
const datasource: DatasourceFunction = ({ page, limit, where, orders }) => {
if (categoryId.value) {
where.categoryId = categoryId.value;
}
return pageArticle({
...where,
...orders,
page,
limit
});
};
/* 查询 */
const query = () => {
loading.value = true;
listArticleCategory()
.then((list) => {
loading.value = false;
const eks: number[] = [];
list.forEach((d) => {
d.key = d.categoryId;
d.value = d.categoryId;
if (typeof d.categoryId === 'number') {
eks.push(d.categoryId);
}
});
expandedRowKeys.value = eks;
data.value = toTreeData({
data: list.map((d) => {
d.disabled = d.type != 0;
return d;
}),
idField: 'categoryId',
parentIdField: 'parentId'
});
if (list.length) {
if (typeof list[0].categoryId === 'number') {
selectedRowKeys.value = [list[0].categoryId];
}
current.value = list[0];
} else {
selectedRowKeys.value = [];
current.value = null;
}
// 表格列配置
const columns = ref<ColumnItem[]>([
{
title: 'ID',
dataIndex: 'articleId',
key: 'articleId',
align: 'center',
width: 90
},
{
title: '文章标题',
dataIndex: 'title',
key: 'title'
},
{
title: '封面图',
dataIndex: 'image',
key: 'image',
width: 120,
align: 'center'
},
{
title: '所属栏目',
dataIndex: 'categoryId',
key: 'categoryId',
align: 'center',
hideInTable: true
},
{
title: '实际阅读量',
dataIndex: 'actualViews',
key: 'actualViews',
sorter: true,
width: 120,
align: 'center'
},
{
title: '虚拟阅读量',
dataIndex: 'virtualViews',
key: 'virtualViews',
width: 120,
align: 'center'
},
{
title: '推荐',
dataIndex: 'recommend',
key: 'recommend',
sorter: true,
align: 'center',
hideInTable: true
},
{
title: '状态',
dataIndex: 'status',
key: 'status',
sorter: true,
width: 120,
align: 'center'
},
{
title: '排序号',
dataIndex: 'sortNumber',
key: 'sortNumber',
sorter: true,
align: 'center',
hideInTable: true
},
{
title: '创建时间',
dataIndex: 'createTime',
key: 'createTime',
align: 'center',
width: 180,
sorter: true
},
{
title: '操作',
key: 'action',
width: 180,
fixed: 'right',
align: 'center',
hideInSetting: true
}
]);
/* 搜索 */
const reload = (where?: ArticleParam) => {
selection.value = [];
tableRef?.value?.reload({ where: where });
};
/* 打开编辑弹窗 */
const openEdit = (row?: Article) => {
current.value = row ?? null;
showEdit.value = true;
};
/* 打开批量移动弹窗 */
const openMove = () => {
showMove.value = true;
};
const onUpdate = (row?: Article) => {
// const isShow = row?.isShow == 0 ? 1 : 0;
// updateArticle({ ...row, isShow }).then((msg) => {
// message.success(msg);
// reload();
// });
};
/* 删除单个 */
const remove = (row: Article) => {
const hide = message.loading('请求中..', 0);
removeArticle(row.articleId)
.then((msg) => {
hide();
message.success(msg);
reload();
})
.catch((e) => {
loading.value = false;
hide();
message.error(e.message);
});
};
/* 选择数据 */
const onTreeSelect = () => {
current.value = {};
eachTreeData(data.value, (d) => {
if (
typeof d.categoryId === 'number' &&
selectedRowKeys.value.includes(d.categoryId)
) {
current.value = d;
return false;
}
});
};
const onContextMenuClick = (treeKey: number, menuKey: number) => {
// 修改
if (menuKey == 1) {
openEdit(current.value);
/* 批量删除 */
const removeBatch = () => {
if (!selection.value.length) {
message.error('请至少选择一条数据');
return;
}
// 删除
if (menuKey == 2) {
remove();
}
};
/* 打开编辑弹窗 */
const openEdit = (item?: ArticleCategory | null) => {
editData.value = item ?? null;
showEdit.value = true;
};
/* 删除 */
const remove = () => {
Modal.confirm({
title: '提示',
content: '确定要删除选中的分类吗?',
content: '确定要删除选中的记录吗?',
icon: createVNode(ExclamationCircleOutlined),
maskClosable: true,
onOk: () => {
const hide = message.loading('请求中..', 0);
removeArticleCategory(current.value?.categoryId)
removeBatchArticle(selection.value.map((d) => d.articleId))
.then((msg) => {
hide();
message.success(msg);
query();
reload();
})
.catch((e) => {
hide();
@@ -224,21 +296,55 @@
});
};
query();
/* 自定义行属性 */
const customRow = (record: Article) => {
return {
// 行点击事件
onClick: () => {
// console.log(record);
},
// 行双击事件
onDblclick: () => {
openEdit(record);
}
};
};
// 加载栏目数据
if (!navigationList.value) {
listNavigation({}).then((res) => {
navigationList.value = toTreeData({
data: res?.map((d) => {
d.value = d.navigationId;
d.label = d.title;
if (d.type != 2) {
d.disabled = true;
}
return d;
}),
idField: 'navigationId',
parentIdField: 'parentId'
});
});
}
watch(
() => router.currentRoute.value.query,
(query) => {
if (query) {
categoryId.value = Number(query.categoryId);
model.value = Number(query.type);
reload();
}
},
{ immediate: true }
);
</script>
<script lang="ts">
export default {
name: 'ArticleIndex'
name: 'ArticleV2'
};
</script>
<style lang="less" scoped>
.sys-category-list {
padding: 12px 6px;
height: calc(100vh - 242px);
border-width: 1px;
border-style: solid;
overflow: auto;
}
</style>
<style lang="less" scoped></style>