优化company/profile

This commit is contained in:
2024-09-20 16:11:55 +08:00
parent e298d960e7
commit ed4b4afda0
74 changed files with 2392 additions and 8130 deletions

View File

@@ -1,332 +1,428 @@
<template>
<div class="page">
<div class="ele-body">
<a-card :bordered="false" :body-style="{ padding: '16px' }">
<ele-pro-table
ref="tableRef"
row-key="cmsNavigationId"
:columns="columns"
:datasource="datasource"
:customRow="customRow"
tool-class="ele-toolbar-form"
class="sys-org-table"
>
<template #toolbar>
<search
<div class="ele-body">
<a-card :bordered="false">
<!-- 表格 -->
<ele-pro-table
ref="tableRef"
row-key="navigationId"
:columns="columns"
:datasource="datasource"
:parse-data="parseData"
:need-page="false"
:customRow="customRow"
:expand-icon-column-index="1"
:expanded-row-keys="expandedRowKeys"
:scroll="{ x: 1200 }"
cache-key="proCmsNavigationTable"
@done="onDone"
@expand="onExpand"
>
<template #toolbar>
<a-space>
<a-button type="primary" class="ele-btn-icon" @click="openEdit()">
<template #icon>
<plus-outlined />
</template>
<span>新建</span>
</a-button>
<a-button type="dashed" class="ele-btn-icon" @click="expandAll">
展开
</a-button>
<a-button type="dashed" class="ele-btn-icon" @click="foldAll">
折叠
</a-button>
<a-divider type="vertical" />
<a-radio-group v-model:value="position" @change="reload">
<a-radio-button :value="1">顶部</a-radio-button>
<a-radio-button :value="2">底部</a-radio-button>
<a-radio-button :value="0">不限</a-radio-button>
</a-radio-group>
<a-divider type="vertical" />
<!-- 搜索表单 -->
<a-input-search
allow-clear
v-model:value="searchText"
placeholder="请输入搜索关键词"
@search="reload"
:selection="selection"
@add="openEdit"
@remove="removeBatch"
@batchMove="openMove"
@pressEnter="reload"
/>
</a-space>
</template>
<template #bodyCell="{ column, record, index }">
<template v-if="column.key === 'path'">
<span class="cursor-pointer" v-if="isDirectory(record)"></span>
<span
v-else
@click="
openSpmUrl(
`https://${record.tenantId}.wsdns.cn${record.path}`,
record,
record.navigationId
)
"
class="ele-text-placeholder cursor-pointer"
>{{ record.path }}</span
>
</template>
<template #bodyCell="{ column, record }">
<template v-if="column.key === 'image'">
<a-image :src="record.image" :width="50" />
<template v-if="column.key === 'component'">
<template v-if="!isDirectory(record)">
<span class="ele-text-placeholder">{{ record.component }}</span>
</template>
<template v-if="column.key === 'status'">
<a-tag v-if="record.status === 0" color="green">显示</a-tag>
<a-tag v-if="record.status === 1" 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 v-else>
<span></span>
</template>
</template>
</ele-pro-table>
</a-card>
<template v-if="column.key === 'model'">
<text class="ele-text-placeholder">{{ record.modelName }}</text>
</template>
<template v-if="column.key === 'type'">
<a-tag v-if="isExternalLink(record.path)" color="purple"
>外部链接</a-tag
>
<a-tag v-else-if="index === 0" color="orange">首页</a-tag>
<a-tag v-else-if="isExternalLink(record.component)" color="orange">
内链
</a-tag>
<span v-else-if="isDirectory(record)"></span>
<a-tag v-else>{{ record.modelName }}</a-tag>
</template>
<template v-else-if="column.key === 'title'">
<a-avatar
:size="22"
shape="square"
:src="`${record.image}`"
style="margin-right: 10px"
v-if="record.image"
/>
<span class="cursor-pointer" v-if="isDirectory(record)">{{
record.title
}}</span>
<span
v-else
@click="openSpmUrl(record.path, record, record.navigationId)"
class="cursor-pointer"
>{{ record.title }}</span
>
</template>
<template v-if="column.key === 'showIndex'">
<a-tag v-if="record.showIndex === 1" color="green">显示</a-tag>
<span v-else></span>
</template>
<template v-if="column.key === 'position'">
<a-space>
<span v-if="record.top === 0" class="ele-text-placeholder"
>顶部</span
>
<span v-if="record.bottom === 0" class="ele-text-placeholder"
>底部</span
>
<span v-if="record.top === 0 || record.bottom === 0"></span>
</a-space>
</template>
<template v-if="column.key === 'hide'">
<span v-if="record.hide === 0" class="ele-text-success">显示</span>
<span v-if="record.hide === 1" class="ele-text-placeholder"
>隐藏</span
>
</template>
<template v-else-if="column.key === 'action'">
<a-space>
<a-tooltip :title="`配置SEO及页面内容`">
<a class="text-fuchsia-300" @click="openDesign(record)">设计</a>
</a-tooltip>
<a-divider type="vertical" />
<a-tooltip :title="`添加子分类`">
<a @click="openEdit(null, record.navigationId)">添加</a>
</a-tooltip>
<!-- 编辑弹窗 -->
<CmsNavigationEdit v-model:visible="showEdit" :data="current" @done="reload" />
</div>
<a-divider type="vertical" />
<a @click="openEdit(record)">修改</a>
<a-divider type="vertical" />
<a-popconfirm
placement="topRight"
title="确定要删除此菜单吗?"
@confirm="remove(record)"
>
<a class="ele-text-danger">删除</a>
</a-popconfirm>
</a-space>
</template>
</template>
</ele-pro-table>
</a-card>
<!-- 编辑弹窗 -->
<CmsNavigationEdit
v-model:visible="showEdit"
:data="current"
:parent-id="parentId"
:navigation-list="navigationData"
:position="position"
@done="reload"
/>
<!-- 页面编辑弹窗 -->
<DesignEdit
v-model:visible="showDesignEdit"
:data="design"
:category-id="categoryId"
@done="reload"
/>
<!-- 页面组件弹窗 -->
<Components
v-model:visible="showDesignRecordEdit"
:data="current"
:category-id="categoryId"
@done="reload"
/>
</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 { ref } from 'vue';
import { message } from 'ant-design-vue/es';
import { PlusOutlined } from '@ant-design/icons-vue';
import type {
DatasourceFunction,
ColumnItem
ColumnItem,
EleProTableDone
} from 'ele-admin-pro/es/ele-pro-table/types';
import Search from './components/search.vue';
import CmsNavigationEdit from './components/cmsNavigationEdit.vue';
import { pageCmsNavigation, removeCmsNavigation, removeBatchCmsNavigation } from '@/api/cms/cmsNavigation';
import type { CmsNavigation, CmsNavigationParam } from '@/api/cms/cmsNavigation/model';
import {
messageLoading,
toDateString,
isExternalLink,
toTreeData,
eachTreeData
} from 'ele-admin-pro/es';
import type { EleProTable } from 'ele-admin-pro/es';
import CmsNavigationEdit from './components/navigation-edit.vue';
import DesignEdit from './components/design-edit.vue';
import Components from './components/components.vue';
import {
listCmsNavigation,
removeCmsNavigation
} from '@/api/cms/cmsNavigation';
import type {
CmsNavigation,
CmsNavigationParam
} from '@/api/cms/cmsNavigation/model';
import { openSpmUrl } from '@/utils/common';
import { getSiteInfo } from '@/api/layout';
import { CmsDesign } from '@/api/cms/cmsDesign/model';
import router from '@/router';
// 表格实例
const tableRef = ref<InstanceType<typeof EleProTable> | null>(null);
// 表格选中数据
const selection = ref<CmsNavigation[]>([]);
// 当前编辑数据
const current = ref<CmsNavigation | 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 pageCmsNavigation({
...where,
...orders,
page,
limit
});
};
// 表格列配置
const columns = ref<ColumnItem[]>([
{
title: 'ID',
dataIndex: 'navigationId',
key: 'navigationId',
align: 'center',
width: 90,
width: 80
},
{
title: '上级id, 0是顶级',
dataIndex: 'parentId',
key: 'parentId',
align: 'center',
},
{
title: '菜单名称',
title: '栏目名称',
dataIndex: 'title',
key: 'title',
align: 'center',
showSorterTooltip: false,
ellipsis: true
},
{
title: '路由地址',
dataIndex: 'path',
key: 'path'
},
{
title: '组件路径',
dataIndex: 'component',
hideInTable: true,
key: 'component'
},
{
title: '模型',
dataIndex: 'model',
key: 'model',
align: 'center',
width: 120
},
{
title: '标识',
dataIndex: 'code',
key: 'code',
align: 'center',
},
{
title: '菜单路由地址',
dataIndex: 'path',
key: 'path',
align: 'center',
},
{
title: '菜单组件地址, 目录可为空',
dataIndex: 'component',
key: 'component',
align: 'center',
},
{
title: '打开位置',
dataIndex: 'target',
key: 'target',
align: 'center',
},
{
title: '菜单图标',
dataIndex: 'icon',
key: 'icon',
align: 'center',
},
{
title: '图标颜色',
dataIndex: 'color',
key: 'color',
align: 'center',
},
{
title: '是否隐藏, 0否, 1是(仅注册路由不显示在左侧菜单)',
dataIndex: 'hide',
key: 'hide',
align: 'center',
},
{
title: '可见类型 0所有人 1登录可见 2密码可见',
dataIndex: 'permission',
key: 'permission',
align: 'center',
},
{
title: '访问密码',
dataIndex: 'password',
key: 'password',
align: 'center',
},
{
title: '位置 0不限 1顶部 2底部',
title: '位置',
dataIndex: 'position',
key: 'position',
align: 'center',
width: 120
},
{
title: '仅在顶部显示',
dataIndex: 'top',
key: 'top',
title: '状态',
dataIndex: 'hide',
key: 'hide',
align: 'center',
width: 120,
showSorterTooltip: false,
customRender: ({ text }) => ['显示', '隐藏'][text]
},
{
title: '仅在底部显示',
dataIndex: 'bottom',
key: 'bottom',
align: 'center',
},
{
title: '菜单侧栏选中的path',
dataIndex: 'active',
key: 'active',
align: 'center',
},
{
title: '其它路由元信息',
dataIndex: 'meta',
key: 'meta',
align: 'center',
},
{
title: 'css样式',
dataIndex: 'style',
key: 'style',
align: 'center',
},
{
title: '父级栏目路由',
dataIndex: 'parentPath',
key: 'parentPath',
align: 'center',
},
{
title: '父级栏目名称',
dataIndex: 'parentName',
key: 'parentName',
align: 'center',
},
{
title: '模型名称',
dataIndex: 'modelName',
key: 'modelName',
align: 'center',
},
{
title: '类型(已废弃)',
dataIndex: 'type',
key: 'type',
align: 'center',
},
{
title: '绑定的页面(已废弃)',
dataIndex: 'pageId',
key: 'pageId',
align: 'center',
},
{
title: '是否微信小程序菜单',
dataIndex: 'isMpWeixin',
key: 'isMpWeixin',
align: 'center',
},
{
title: '用户ID',
dataIndex: 'userId',
key: 'userId',
align: 'center',
},
{
title: '设为首页',
dataIndex: 'home',
key: 'home',
align: 'center',
},
{
title: '排序(数字越小越靠前)',
title: '排序',
dataIndex: 'sortNumber',
key: 'sortNumber',
align: 'center',
},
{
title: '备注',
dataIndex: 'comments',
key: 'comments',
align: 'center',
},
{
title: '是否删除, 0否, 1是',
dataIndex: 'deleted',
key: 'deleted',
align: 'center',
},
{
title: '状态, 0正常, 1冻结',
dataIndex: 'status',
key: 'status',
align: 'center',
width: 120,
showSorterTooltip: false
},
{
title: '创建时间',
dataIndex: 'createTime',
key: 'createTime',
align: 'center',
sorter: true,
showSorterTooltip: false,
ellipsis: true,
customRender: ({ text }) => toDateString(text, 'yyyy-MM-dd')
hideInTable: true,
width: 180,
customRender: ({ text }) => toDateString(text)
},
{
title: '操作',
key: 'action',
width: 180,
fixed: 'right',
width: 240,
align: 'center',
hideInSetting: true
fixed: 'right'
}
]);
/* 搜索 */
// 当前编辑数据
const current = ref<CmsNavigation | null>(null);
// 当前选中页面
const design = ref<CmsDesign>();
// 是否显示编辑弹窗
const showEdit = ref(false);
// 编辑内容
const showDesignEdit = ref(false);
// 页面组件
const showDesignRecordEdit = ref(false);
// 上级分类id
const parentId = ref<number>();
const categoryId = ref<number>();
// 分类数据
const navigationData = ref<CmsNavigation[]>([]);
// 表格展开的行
const expandedRowKeys = ref<number[]>([]);
const searchText = ref('');
const position = ref(1);
const tenantId = ref<number>();
const domain = ref<string>();
getSiteInfo().then((data) => {
tenantId.value = data.tenantId;
domain.value = data.domain;
});
// 表格数据源
const datasource: DatasourceFunction = ({ where }) => {
where = {};
where.keywords = searchText.value;
// where.position = position.value;
where.top = 0;
where.bottom = undefined;
if (position.value == 1) {
where.top = 0;
where.bottom = undefined;
}
if (position.value == 2) {
where.top = undefined;
where.bottom = 0;
}
if (position.value == 0) {
where.top = undefined;
where.bottom = undefined;
}
where.isMpWeixin = false;
return listCmsNavigation({ ...where });
};
/* 数据转为树形结构 */
const parseData = (data: CmsNavigation[]) => {
return toTreeData({
data: data.map((d) => {
return { ...d, key: d.navigationId, value: d.navigationId };
}),
idField: 'navigationId',
parentIdField: 'parentId'
});
};
/* 表格渲染完成回调 */
const onDone: EleProTableDone<CmsNavigation> = ({ data }) => {
navigationData.value = data;
};
/* 刷新表格 */
const reload = (where?: CmsNavigationParam) => {
selection.value = [];
tableRef?.value?.reload({ where: where });
tableRef?.value?.reload({ where });
};
/* 打开编辑弹窗 */
const openEdit = (row?: CmsNavigation) => {
const openEdit = (row?: CmsNavigation | null, id?: number) => {
current.value = row ?? null;
parentId.value = id;
showEdit.value = true;
};
/* 打开批量移动弹窗 */
const openMove = () => {
showMove.value = true;
// 跳转模型内容列表
const openDesign = (row?: CmsNavigation) => {
categoryId.value = row?.navigationId;
showDesignEdit.value = true;
return;
// if (row && isDirectory(row)) {
// categoryId.value = row?.navigationId;
// showDesignEdit.value = true;
// return;
// }
// TODO 单页模型
// if (row?.model == 'custom') {
// router.push({
// path: `/cms/design`,
// query: {
// id: row.navigationId,
// type: row.model
// }
// });
// return;
// }
// TODO 文章列表
// if (row?.model === 'article') {
// router.push({
// path: `/cms/article`,
// query: {
// id: row.navigationId,
// type: row.model
// }
// });
// return;
// }
// TODO 产品列表
// if (row?.model === 'product') {
// router.push({
// path: '/goods/index',
// query: { categoryId: row.navigationId, type: row.type }
// });
// return;
// }
};
const openLayout = (row?: CmsNavigation) => {
current.value = row ?? null;
categoryId.value = row?.navigationId;
showDesignRecordEdit.value = true;
};
/* 删除单个 */
const remove = (row: CmsNavigation) => {
const hide = message.loading('请求中..', 0);
removeCmsNavigation(row.cmsNavigationId)
console.log(row);
if (row.children?.length) {
message.error('请先删除子节点');
return;
}
const hide = messageLoading('请求中..', 0);
removeCmsNavigation(row.navigationId)
.then((msg) => {
hide();
message.success(msg);
@@ -338,36 +434,39 @@
});
};
/* 批量删除 */
const removeBatch = () => {
if (!selection.value.length) {
message.error('请至少选择一条数据');
return;
}
Modal.confirm({
title: '提示',
content: '确定要删除选中的记录吗?',
icon: createVNode(ExclamationCircleOutlined),
maskClosable: true,
onOk: () => {
const hide = message.loading('请求中..', 0);
removeBatchCmsNavigation(selection.value.map((d) => d.cmsNavigationId))
.then((msg) => {
hide();
message.success(msg);
reload();
})
.catch((e) => {
hide();
message.error(e.message);
});
/* 展开全部 */
const expandAll = () => {
let keys: number[] = [];
eachTreeData(navigationData.value, (d) => {
if (d.children && d.children.length && d.navigationId) {
keys.push(d.navigationId);
}
});
expandedRowKeys.value = keys;
};
/* 查询 */
const query = () => {
loading.value = true;
/* 折叠全部 */
const foldAll = () => {
expandedRowKeys.value = [];
};
/* 点击展开图标时触发 */
const onExpand = (expanded: boolean, record: CmsNavigation) => {
if (expanded) {
expandedRowKeys.value = [
...expandedRowKeys.value,
record.navigationId as number
];
} else {
expandedRowKeys.value = expandedRowKeys.value.filter(
(d) => d !== record.navigationId
);
}
};
/* 判断是否是目录 */
const isDirectory = (d: CmsNavigation) => {
return !!d.children?.length;
};
/* 自定义行属性 */
@@ -383,7 +482,6 @@
}
};
};
query();
</script>
<script lang="ts">
@@ -391,5 +489,3 @@
name: 'CmsNavigation'
};
</script>
<style lang="less" scoped></style>