mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 23:09:19 +08:00
初始化项目
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
# \_core
|
||||
|
||||
此目录包含应用程序正常运行所需的基本视图。这些视图是应用程序布局中使用的视图。
|
||||
@@ -0,0 +1,9 @@
|
||||
<script lang="ts" setup>
|
||||
import { About } from '@vben/common-ui';
|
||||
|
||||
defineOptions({ name: 'About' });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<About />
|
||||
</template>
|
||||
@@ -0,0 +1,69 @@
|
||||
<script lang="ts" setup>
|
||||
import type { VbenFormSchema } from '@vben/common-ui';
|
||||
import type { Recordable } from '@vben/types';
|
||||
|
||||
import { computed, ref } from 'vue';
|
||||
|
||||
import { AuthenticationCodeLogin, z } from '@vben/common-ui';
|
||||
import { $t } from '@vben/locales';
|
||||
|
||||
defineOptions({ name: 'CodeLogin' });
|
||||
|
||||
const loading = ref(false);
|
||||
const CODE_LENGTH = 6;
|
||||
|
||||
const formSchema = computed((): VbenFormSchema[] => {
|
||||
return [
|
||||
{
|
||||
component: 'VbenInput',
|
||||
componentProps: {
|
||||
placeholder: $t('authentication.mobile'),
|
||||
},
|
||||
fieldName: 'phoneNumber',
|
||||
label: $t('authentication.mobile'),
|
||||
rules: z
|
||||
.string()
|
||||
.min(1, { message: $t('authentication.mobileTip') })
|
||||
.refine((v) => /^\d{11}$/.test(v), {
|
||||
message: $t('authentication.mobileErrortip'),
|
||||
}),
|
||||
},
|
||||
{
|
||||
component: 'VbenPinInput',
|
||||
componentProps: {
|
||||
codeLength: CODE_LENGTH,
|
||||
createText: (countdown: number) => {
|
||||
const text =
|
||||
countdown > 0
|
||||
? $t('authentication.sendText', [countdown])
|
||||
: $t('authentication.sendCode');
|
||||
return text;
|
||||
},
|
||||
placeholder: $t('authentication.code'),
|
||||
},
|
||||
fieldName: 'code',
|
||||
label: $t('authentication.code'),
|
||||
rules: z.string().length(CODE_LENGTH, {
|
||||
message: $t('authentication.codeTip', [CODE_LENGTH]),
|
||||
}),
|
||||
},
|
||||
];
|
||||
});
|
||||
/**
|
||||
* 异步处理登录操作
|
||||
* Asynchronously handle the login process
|
||||
* @param values 登录表单数据
|
||||
*/
|
||||
async function handleLogin(values: Recordable<any>) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(values);
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<AuthenticationCodeLogin
|
||||
:form-schema="formSchema"
|
||||
:loading="loading"
|
||||
@submit="handleLogin"
|
||||
/>
|
||||
</template>
|
||||
@@ -0,0 +1,43 @@
|
||||
<script lang="ts" setup>
|
||||
import type { VbenFormSchema } from '@vben/common-ui';
|
||||
import type { Recordable } from '@vben/types';
|
||||
|
||||
import { computed, ref } from 'vue';
|
||||
|
||||
import { AuthenticationForgetPassword, z } from '@vben/common-ui';
|
||||
import { $t } from '@vben/locales';
|
||||
|
||||
defineOptions({ name: 'ForgetPassword' });
|
||||
|
||||
const loading = ref(false);
|
||||
|
||||
const formSchema = computed((): VbenFormSchema[] => {
|
||||
return [
|
||||
{
|
||||
component: 'VbenInput',
|
||||
componentProps: {
|
||||
placeholder: 'example@example.com',
|
||||
},
|
||||
fieldName: 'email',
|
||||
label: $t('authentication.email'),
|
||||
rules: z
|
||||
.string()
|
||||
.min(1, { message: $t('authentication.emailTip') })
|
||||
.email($t('authentication.emailValidErrorTip')),
|
||||
},
|
||||
];
|
||||
});
|
||||
|
||||
function handleSubmit(value: Recordable<any>) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('reset email:', value);
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<AuthenticationForgetPassword
|
||||
:form-schema="formSchema"
|
||||
:loading="loading"
|
||||
@submit="handleSubmit"
|
||||
/>
|
||||
</template>
|
||||
@@ -0,0 +1,52 @@
|
||||
<script lang="ts" setup>
|
||||
import type { VbenFormSchema } from '@vben/common-ui';
|
||||
|
||||
import { computed, markRaw } from 'vue';
|
||||
|
||||
import { AuthenticationLogin, SliderCaptcha, z } from '@vben/common-ui';
|
||||
import { $t } from '@vben/locales';
|
||||
|
||||
import { useAuthStore } from '#/store';
|
||||
|
||||
defineOptions({ name: 'Login' });
|
||||
|
||||
const authStore = useAuthStore();
|
||||
|
||||
const formSchema = computed((): VbenFormSchema[] => {
|
||||
return [
|
||||
{
|
||||
component: 'VbenInput',
|
||||
componentProps: {
|
||||
placeholder: '请输入登录账号或手机号',
|
||||
},
|
||||
fieldName: 'account',
|
||||
label: '登录账号',
|
||||
rules: z.string().min(1, { message: '请输入登录账号或手机号' }),
|
||||
},
|
||||
{
|
||||
component: 'VbenInputPassword',
|
||||
componentProps: {
|
||||
placeholder: $t('authentication.password'),
|
||||
},
|
||||
fieldName: 'password',
|
||||
label: $t('authentication.password'),
|
||||
rules: z.string().min(1, { message: $t('authentication.passwordTip') }),
|
||||
},
|
||||
{
|
||||
component: markRaw(SliderCaptcha),
|
||||
fieldName: 'captcha',
|
||||
rules: z.boolean().refine((value) => value, {
|
||||
message: $t('authentication.verifyRequiredTip'),
|
||||
}),
|
||||
},
|
||||
];
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<AuthenticationLogin
|
||||
:form-schema="formSchema"
|
||||
:loading="authStore.loginLoading"
|
||||
@submit="authStore.authLogin"
|
||||
/>
|
||||
</template>
|
||||
@@ -0,0 +1,10 @@
|
||||
<script lang="ts" setup>
|
||||
import { AuthenticationQrCodeLogin } from '@vben/common-ui';
|
||||
import { LOGIN_PATH } from '@vben/constants';
|
||||
|
||||
defineOptions({ name: 'QrCodeLogin' });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<AuthenticationQrCodeLogin :login-path="LOGIN_PATH" />
|
||||
</template>
|
||||
@@ -0,0 +1,124 @@
|
||||
<script lang="ts" setup>
|
||||
import type { VbenFormSchema } from '@vben/common-ui';
|
||||
import type { Recordable } from '@vben/types';
|
||||
|
||||
import { computed, h } from 'vue';
|
||||
|
||||
import { AuthenticationRegister, z } from '@vben/common-ui';
|
||||
import { $t } from '@vben/locales';
|
||||
|
||||
import { useAuthStore } from '#/store';
|
||||
|
||||
defineOptions({ name: 'Register' });
|
||||
|
||||
const authStore = useAuthStore();
|
||||
|
||||
const formSchema = computed((): VbenFormSchema[] => {
|
||||
return [
|
||||
{
|
||||
component: 'VbenInput',
|
||||
componentProps: {
|
||||
placeholder: '请输入登录账号(可选)',
|
||||
},
|
||||
fieldName: 'loginCode',
|
||||
label: '登录账号',
|
||||
rules: z.string().optional(),
|
||||
},
|
||||
{
|
||||
component: 'VbenInput',
|
||||
componentProps: {
|
||||
placeholder: '请输入手机号(可选)',
|
||||
},
|
||||
fieldName: 'phone',
|
||||
label: '手机号',
|
||||
rules: z
|
||||
.string()
|
||||
.optional()
|
||||
.refine(
|
||||
(value) => {
|
||||
if (!value) return true;
|
||||
return /^1[3-9]\d{9}$/.test(value);
|
||||
},
|
||||
{ message: '请输入正确的手机号格式' },
|
||||
),
|
||||
},
|
||||
{
|
||||
component: 'VbenInputPassword',
|
||||
componentProps: {
|
||||
passwordStrength: true,
|
||||
placeholder: $t('authentication.password'),
|
||||
},
|
||||
fieldName: 'password',
|
||||
label: $t('authentication.password'),
|
||||
renderComponentContent() {
|
||||
return {
|
||||
strengthText: () => $t('authentication.passwordStrength'),
|
||||
};
|
||||
},
|
||||
rules: z.string().min(1, { message: $t('authentication.passwordTip') }),
|
||||
},
|
||||
{
|
||||
component: 'VbenInputPassword',
|
||||
componentProps: {
|
||||
placeholder: $t('authentication.confirmPassword'),
|
||||
},
|
||||
dependencies: {
|
||||
rules(values) {
|
||||
const { password } = values;
|
||||
return z
|
||||
.string({ required_error: $t('authentication.passwordTip') })
|
||||
.min(1, { message: $t('authentication.passwordTip') })
|
||||
.refine((value) => value === password, {
|
||||
message: $t('authentication.confirmPasswordTip'),
|
||||
});
|
||||
},
|
||||
triggerFields: ['password'],
|
||||
},
|
||||
fieldName: 'confirmPassword',
|
||||
label: $t('authentication.confirmPassword'),
|
||||
},
|
||||
{
|
||||
component: 'VbenCheckbox',
|
||||
fieldName: 'agreePolicy',
|
||||
renderComponentContent: () => ({
|
||||
default: () =>
|
||||
h('span', [
|
||||
$t('authentication.agree'),
|
||||
h(
|
||||
'a',
|
||||
{
|
||||
class: 'vben-link ml-1 ',
|
||||
href: '',
|
||||
},
|
||||
`${$t('authentication.privacyPolicy')} & ${$t('authentication.terms')}`,
|
||||
),
|
||||
]),
|
||||
}),
|
||||
rules: z.boolean().refine((value) => !!value, {
|
||||
message: $t('authentication.agreeTip'),
|
||||
}),
|
||||
},
|
||||
];
|
||||
});
|
||||
|
||||
function handleSubmit(value: Recordable<any>) {
|
||||
// 验证至少填写一个登录方式
|
||||
if (!value.loginCode && !value.phone) {
|
||||
// 这里可以添加错误提示
|
||||
return;
|
||||
}
|
||||
|
||||
// 移除不需要的字段
|
||||
const { confirmPassword, agreePolicy, ...registerData } = value;
|
||||
|
||||
authStore.authRegister(registerData);
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<AuthenticationRegister
|
||||
:form-schema="formSchema"
|
||||
:loading="authStore.loginLoading"
|
||||
@submit="handleSubmit"
|
||||
/>
|
||||
</template>
|
||||
@@ -0,0 +1,7 @@
|
||||
<script lang="ts" setup>
|
||||
import { Fallback } from '@vben/common-ui';
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Fallback status="coming-soon" />
|
||||
</template>
|
||||
@@ -0,0 +1,9 @@
|
||||
<script lang="ts" setup>
|
||||
import { Fallback } from '@vben/common-ui';
|
||||
|
||||
defineOptions({ name: 'Fallback403Demo' });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Fallback status="403" />
|
||||
</template>
|
||||
@@ -0,0 +1,9 @@
|
||||
<script lang="ts" setup>
|
||||
import { Fallback } from '@vben/common-ui';
|
||||
|
||||
defineOptions({ name: 'Fallback500Demo' });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Fallback status="500" />
|
||||
</template>
|
||||
@@ -0,0 +1,9 @@
|
||||
<script lang="ts" setup>
|
||||
import { Fallback } from '@vben/common-ui';
|
||||
|
||||
defineOptions({ name: 'Fallback404Demo' });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Fallback status="404" />
|
||||
</template>
|
||||
@@ -0,0 +1,9 @@
|
||||
<script lang="ts" setup>
|
||||
import { Fallback } from '@vben/common-ui';
|
||||
|
||||
defineOptions({ name: 'FallbackOfflineDemo' });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Fallback status="offline" />
|
||||
</template>
|
||||
+363
@@ -0,0 +1,363 @@
|
||||
<script lang="ts" setup>
|
||||
import { h, ref } from 'vue';
|
||||
|
||||
import { Page } from '@vben/common-ui';
|
||||
import { Button, DatePicker, Form, Input, Modal, Select, Table, message } from 'ant-design-vue';
|
||||
|
||||
import {
|
||||
createCompanyApi,
|
||||
deleteCompanyApi,
|
||||
getCompanyPageApi,
|
||||
updateCompanyApi,
|
||||
type CompanyApi as CompanyApiType
|
||||
} from '#/api/core/organization';
|
||||
|
||||
defineOptions({ name: 'CompanyManagement' });
|
||||
|
||||
// 响应式数据
|
||||
const loading = ref(false);
|
||||
const companyList = ref<CompanyApiType.CompanyInfo[]>([]);
|
||||
const total = ref(0);
|
||||
const current = ref(1);
|
||||
const pageSize = ref(10);
|
||||
const modalVisible = ref(false);
|
||||
const modalTitle = ref('');
|
||||
const isEdit = ref(false);
|
||||
const currentCompanyId = ref<number | null>(null);
|
||||
const formRef = ref();
|
||||
|
||||
// 搜索表单
|
||||
const searchForm = ref({
|
||||
name: '',
|
||||
status: undefined as number | undefined,
|
||||
});
|
||||
|
||||
// 表单数据
|
||||
const formData = ref<CompanyApiType.CreateCompanyParams>({
|
||||
name: '',
|
||||
address: '',
|
||||
contactPerson: '',
|
||||
contactPhone: '',
|
||||
email: '',
|
||||
logo: '',
|
||||
status: 1,
|
||||
expireTime: '',
|
||||
});
|
||||
|
||||
// 状态选项
|
||||
const statusOptions = [
|
||||
{ label: '禁用', value: 0 },
|
||||
{ label: '正常', value: 1 },
|
||||
];
|
||||
|
||||
// 表格列配置
|
||||
const columns = [
|
||||
{
|
||||
title: '公司名称',
|
||||
dataIndex: 'name',
|
||||
key: 'name',
|
||||
width: 200,
|
||||
},
|
||||
{
|
||||
title: '公司地址',
|
||||
dataIndex: 'address',
|
||||
key: 'address',
|
||||
width: 250,
|
||||
},
|
||||
{
|
||||
title: '联系人',
|
||||
dataIndex: 'contactPerson',
|
||||
key: 'contactPerson',
|
||||
width: 120,
|
||||
},
|
||||
{
|
||||
title: '联系电话',
|
||||
dataIndex: 'contactPhone',
|
||||
key: 'contactPhone',
|
||||
width: 150,
|
||||
},
|
||||
{
|
||||
title: '邮箱',
|
||||
dataIndex: 'email',
|
||||
key: 'email',
|
||||
width: 200,
|
||||
},
|
||||
{
|
||||
title: '状态',
|
||||
dataIndex: 'status',
|
||||
key: 'status',
|
||||
width: 100,
|
||||
customRender: ({ record }: { record: CompanyApiType.CompanyInfo }) => {
|
||||
return h('span', {
|
||||
style: { color: record.status === 1 ? '#52c41a' : '#ff4d4f' },
|
||||
}, record.status === 1 ? '正常' : '禁用');
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '订阅到期时间',
|
||||
dataIndex: 'expireTime',
|
||||
key: 'expireTime',
|
||||
width: 180,
|
||||
},
|
||||
{
|
||||
title: '创建时间',
|
||||
dataIndex: 'createTime',
|
||||
key: 'createTime',
|
||||
width: 180,
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
key: 'action',
|
||||
width: 200,
|
||||
fixed: 'right' as const,
|
||||
customRender: ({ record }: { record: CompanyApiType.CompanyInfo }) => {
|
||||
return h('div', { style: 'display: flex; gap: 8px;' }, [
|
||||
h(Button, {
|
||||
size: 'small',
|
||||
onClick: () => handleEdit(record),
|
||||
}, '编辑'),
|
||||
h(Button, {
|
||||
size: 'small',
|
||||
danger: true,
|
||||
onClick: () => handleDelete(record),
|
||||
}, '删除'),
|
||||
]);
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
// 获取公司列表
|
||||
async function fetchCompanyList() {
|
||||
try {
|
||||
loading.value = true;
|
||||
const params = {
|
||||
page: current.value,
|
||||
size: pageSize.value,
|
||||
filter: {
|
||||
name: searchForm.value.name || undefined,
|
||||
status: searchForm.value.status,
|
||||
},
|
||||
};
|
||||
const data = await getCompanyPageApi(params);
|
||||
companyList.value = data.records;
|
||||
total.value = data.total;
|
||||
} catch (error) {
|
||||
console.error('获取公司列表失败:', error);
|
||||
message.error('获取公司列表失败');
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
// 处理搜索
|
||||
function handleSearch() {
|
||||
current.value = 1;
|
||||
fetchCompanyList();
|
||||
}
|
||||
|
||||
// 处理重置
|
||||
function handleReset() {
|
||||
searchForm.value = {
|
||||
name: '',
|
||||
status: undefined,
|
||||
};
|
||||
current.value = 1;
|
||||
fetchCompanyList();
|
||||
}
|
||||
|
||||
// 处理分页变化
|
||||
function handleTableChange(pagination: any) {
|
||||
current.value = pagination.current;
|
||||
pageSize.value = pagination.pageSize;
|
||||
fetchCompanyList();
|
||||
}
|
||||
|
||||
// 处理添加公司
|
||||
function handleAdd() {
|
||||
modalTitle.value = '添加公司';
|
||||
isEdit.value = false;
|
||||
currentCompanyId.value = null;
|
||||
formData.value = {
|
||||
name: '',
|
||||
address: '',
|
||||
contactPerson: '',
|
||||
contactPhone: '',
|
||||
email: '',
|
||||
logo: '',
|
||||
status: 1,
|
||||
expireTime: '',
|
||||
};
|
||||
modalVisible.value = true;
|
||||
}
|
||||
|
||||
// 处理编辑公司
|
||||
function handleEdit(record: CompanyApiType.CompanyInfo) {
|
||||
modalTitle.value = '编辑公司';
|
||||
isEdit.value = true;
|
||||
currentCompanyId.value = record.id;
|
||||
formData.value = {
|
||||
name: record.name,
|
||||
address: record.address || '',
|
||||
contactPerson: record.contactPerson || '',
|
||||
contactPhone: record.contactPhone || '',
|
||||
email: record.email || '',
|
||||
logo: record.logo || '',
|
||||
status: record.status,
|
||||
expireTime: record.expireTime || '',
|
||||
};
|
||||
modalVisible.value = true;
|
||||
}
|
||||
|
||||
// 处理删除公司
|
||||
async function handleDelete(record: CompanyApiType.CompanyInfo) {
|
||||
try {
|
||||
await deleteCompanyApi(record.id);
|
||||
message.success('删除成功');
|
||||
await fetchCompanyList();
|
||||
} catch (error) {
|
||||
console.error('删除公司失败:', error);
|
||||
message.error('删除公司失败');
|
||||
}
|
||||
}
|
||||
|
||||
// 处理表单提交
|
||||
async function handleSubmit() {
|
||||
try {
|
||||
await formRef.value?.validate();
|
||||
|
||||
if (isEdit.value && currentCompanyId.value) {
|
||||
await updateCompanyApi(currentCompanyId.value, formData.value);
|
||||
message.success('更新成功');
|
||||
} else {
|
||||
await createCompanyApi(formData.value);
|
||||
message.success('创建成功');
|
||||
}
|
||||
|
||||
modalVisible.value = false;
|
||||
await fetchCompanyList();
|
||||
} catch (error) {
|
||||
console.error('保存公司失败:', error);
|
||||
message.error('保存公司失败');
|
||||
}
|
||||
}
|
||||
|
||||
// 初始化
|
||||
fetchCompanyList();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page title="公司管理">
|
||||
<template #description>
|
||||
<div class="text-foreground/80 mt-2">
|
||||
管理公司信息,包括公司基本信息、联系方式和订阅状态
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template #extra>
|
||||
<Button type="primary" @click="handleAdd">
|
||||
添加公司
|
||||
</Button>
|
||||
</template>
|
||||
|
||||
<!-- 搜索表单 -->
|
||||
<div class="mb-4 p-4 bg-gray-50 rounded-lg">
|
||||
<Form layout="inline" :model="searchForm">
|
||||
<Form.Item label="公司名称" name="name">
|
||||
<Input
|
||||
v-model:value="searchForm.name"
|
||||
placeholder="请输入公司名称"
|
||||
style="width: 200px;"
|
||||
@press-enter="handleSearch"
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item label="状态" name="status">
|
||||
<Select
|
||||
v-model:value="searchForm.status"
|
||||
placeholder="请选择状态"
|
||||
style="width: 120px;"
|
||||
:options="statusOptions"
|
||||
allow-clear
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item>
|
||||
<Button type="primary" @click="handleSearch">搜索</Button>
|
||||
<Button @click="handleReset" class="ml-2">重置</Button>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</div>
|
||||
|
||||
<!-- 数据表格 -->
|
||||
<Table
|
||||
:columns="columns"
|
||||
:data-source="companyList"
|
||||
:loading="loading"
|
||||
:pagination="{
|
||||
current: current,
|
||||
pageSize: pageSize,
|
||||
total: total,
|
||||
showSizeChanger: true,
|
||||
showQuickJumper: true,
|
||||
showTotal: (total, range) => `第 ${range[0]}-${range[1]} 条/共 ${total} 条`,
|
||||
}"
|
||||
row-key="id"
|
||||
@change="handleTableChange"
|
||||
/>
|
||||
|
||||
<!-- 添加/编辑模态框 -->
|
||||
<Modal
|
||||
v-model:open="modalVisible"
|
||||
:title="modalTitle"
|
||||
width="600px"
|
||||
@ok="handleSubmit"
|
||||
>
|
||||
<Form
|
||||
ref="formRef"
|
||||
:model="formData"
|
||||
:label-col="{ span: 6 }"
|
||||
:wrapper-col="{ span: 18 }"
|
||||
>
|
||||
<Form.Item label="公司名称" name="name" :rules="[{ required: true, message: '请输入公司名称' }]">
|
||||
<Input v-model:value="formData.name" placeholder="请输入公司名称" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="公司地址" name="address">
|
||||
<Input v-model:value="formData.address" placeholder="请输入公司地址" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="联系人" name="contactPerson">
|
||||
<Input v-model:value="formData.contactPerson" placeholder="请输入联系人" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="联系电话" name="contactPhone">
|
||||
<Input v-model:value="formData.contactPhone" placeholder="请输入联系电话" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="邮箱" name="email">
|
||||
<Input v-model:value="formData.email" placeholder="请输入邮箱" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="Logo" name="logo">
|
||||
<Input v-model:value="formData.logo" placeholder="请输入Logo地址" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="状态" name="status">
|
||||
<Select
|
||||
v-model:value="formData.status"
|
||||
placeholder="请选择状态"
|
||||
:options="statusOptions"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="订阅到期时间" name="expireTime">
|
||||
<DatePicker
|
||||
v-model:value="formData.expireTime"
|
||||
placeholder="请选择订阅到期时间"
|
||||
style="width: 100%;"
|
||||
show-time
|
||||
format="YYYY-MM-DD HH:mm:ss"
|
||||
/>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</Modal>
|
||||
</Page>
|
||||
</template>
|
||||
+356
@@ -0,0 +1,356 @@
|
||||
<script lang="ts" setup>
|
||||
import { computed, h, ref } from 'vue';
|
||||
|
||||
import { Page } from '@vben/common-ui';
|
||||
import { Button, Form, Input, Modal, Select, Table, message } from 'ant-design-vue';
|
||||
|
||||
import {
|
||||
createDepartmentApi,
|
||||
deleteDepartmentApi,
|
||||
getDepartmentPageApi,
|
||||
updateDepartmentApi,
|
||||
type DepartmentApi as DepartmentApiType
|
||||
} from '#/api/core/organization';
|
||||
|
||||
defineOptions({ name: 'DepartmentManagement' });
|
||||
|
||||
// 响应式数据
|
||||
const loading = ref(false);
|
||||
const departmentList = ref<DepartmentApiType.DepartmentInfo[]>([]);
|
||||
const total = ref(0);
|
||||
const current = ref(1);
|
||||
const pageSize = ref(10);
|
||||
const modalVisible = ref(false);
|
||||
const modalTitle = ref('');
|
||||
const isEdit = ref(false);
|
||||
const currentDepartmentId = ref<number | null>(null);
|
||||
const formRef = ref();
|
||||
|
||||
// 搜索表单
|
||||
const searchForm = ref({
|
||||
name: '',
|
||||
status: undefined as number | undefined,
|
||||
});
|
||||
|
||||
// 表单数据
|
||||
const formData = ref<DepartmentApiType.CreateDepartmentParams>({
|
||||
name: '',
|
||||
parentId: undefined,
|
||||
remark: '',
|
||||
status: 1,
|
||||
});
|
||||
|
||||
// 状态选项
|
||||
const statusOptions = [
|
||||
{ label: '禁用', value: 0 },
|
||||
{ label: '启用', value: 1 },
|
||||
];
|
||||
|
||||
// 父部门选项
|
||||
const parentDepartmentOptions = computed(() => {
|
||||
const options: Array<{ label: string; value: number | undefined }> = [{ label: '根部门', value: undefined }];
|
||||
|
||||
const addDepartmentOptions = (departments: DepartmentApiType.DepartmentInfo[], level = 0) => {
|
||||
departments.forEach(dept => {
|
||||
const prefix = ' '.repeat(level);
|
||||
options.push({
|
||||
label: `${prefix}${dept.name}`,
|
||||
value: dept.id,
|
||||
});
|
||||
if (dept.children && dept.children.length > 0) {
|
||||
addDepartmentOptions(dept.children, level + 1);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
addDepartmentOptions(departmentList.value);
|
||||
return options;
|
||||
});
|
||||
|
||||
// 表格列配置
|
||||
const columns = [
|
||||
{
|
||||
title: '部门名称',
|
||||
dataIndex: 'name',
|
||||
key: 'name',
|
||||
width: 200,
|
||||
},
|
||||
{
|
||||
title: '父部门',
|
||||
dataIndex: 'parentId',
|
||||
key: 'parentId',
|
||||
width: 150,
|
||||
customRender: ({ record }: { record: DepartmentApiType.DepartmentInfo }) => {
|
||||
if (!record.parentId) return '根部门';
|
||||
const parent = findParentDepartment(departmentList.value, record.parentId);
|
||||
return parent ? parent.name : '未知';
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '描述',
|
||||
dataIndex: 'remark',
|
||||
key: 'remark',
|
||||
width: 200,
|
||||
},
|
||||
{
|
||||
title: '状态',
|
||||
dataIndex: 'status',
|
||||
key: 'status',
|
||||
width: 100,
|
||||
customRender: ({ record }: { record: DepartmentApiType.DepartmentInfo }) => {
|
||||
return h('span', {
|
||||
style: { color: record.status === 1 ? '#52c41a' : '#ff4d4f' },
|
||||
}, record.status === 1 ? '启用' : '禁用');
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '创建时间',
|
||||
dataIndex: 'createTime',
|
||||
key: 'createTime',
|
||||
width: 180,
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
key: 'action',
|
||||
width: 200,
|
||||
fixed: 'right' as const,
|
||||
customRender: ({ record }: { record: DepartmentApiType.DepartmentInfo }) => {
|
||||
return h('div', { style: 'display: flex; gap: 8px;' }, [
|
||||
h(Button, {
|
||||
size: 'small',
|
||||
onClick: () => handleEdit(record),
|
||||
}, '编辑'),
|
||||
h(Button, {
|
||||
size: 'small',
|
||||
danger: true,
|
||||
onClick: () => handleDelete(record),
|
||||
}, '删除'),
|
||||
]);
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
// 查找父部门
|
||||
function findParentDepartment(departments: DepartmentApiType.DepartmentInfo[], parentId: number): DepartmentApiType.DepartmentInfo | null {
|
||||
for (const dept of departments) {
|
||||
if (dept.id === parentId) {
|
||||
return dept;
|
||||
}
|
||||
if (dept.children) {
|
||||
const found = findParentDepartment(dept.children, parentId);
|
||||
if (found) return found;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// 获取部门列表
|
||||
async function fetchDepartmentList() {
|
||||
try {
|
||||
loading.value = true;
|
||||
const params = {
|
||||
page: current.value,
|
||||
size: pageSize.value,
|
||||
filter: {
|
||||
name: searchForm.value.name || undefined,
|
||||
status: searchForm.value.status,
|
||||
},
|
||||
};
|
||||
const data = await getDepartmentPageApi(params);
|
||||
departmentList.value = data.records;
|
||||
total.value = data.total;
|
||||
} catch (error) {
|
||||
console.error('获取部门列表失败:', error);
|
||||
message.error('获取部门列表失败');
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
// 处理搜索
|
||||
function handleSearch() {
|
||||
current.value = 1;
|
||||
fetchDepartmentList();
|
||||
}
|
||||
|
||||
// 处理重置
|
||||
function handleReset() {
|
||||
searchForm.value = {
|
||||
name: '',
|
||||
status: undefined,
|
||||
};
|
||||
current.value = 1;
|
||||
fetchDepartmentList();
|
||||
}
|
||||
|
||||
// 处理分页变化
|
||||
function handleTableChange(pagination: any) {
|
||||
current.value = pagination.current;
|
||||
pageSize.value = pagination.pageSize;
|
||||
fetchDepartmentList();
|
||||
}
|
||||
|
||||
// 处理添加部门
|
||||
function handleAdd() {
|
||||
modalTitle.value = '添加部门';
|
||||
isEdit.value = false;
|
||||
currentDepartmentId.value = null;
|
||||
formData.value = {
|
||||
name: '',
|
||||
parentId: undefined as number | undefined,
|
||||
remark: '',
|
||||
status: 1,
|
||||
};
|
||||
modalVisible.value = true;
|
||||
}
|
||||
|
||||
// 处理编辑部门
|
||||
function handleEdit(record: DepartmentApiType.DepartmentInfo) {
|
||||
modalTitle.value = '编辑部门';
|
||||
isEdit.value = true;
|
||||
currentDepartmentId.value = record.id;
|
||||
formData.value = {
|
||||
name: record.name,
|
||||
parentId: record.parentId,
|
||||
remark: record.remark || '',
|
||||
status: record.status,
|
||||
};
|
||||
modalVisible.value = true;
|
||||
}
|
||||
|
||||
// 处理删除部门
|
||||
async function handleDelete(record: DepartmentApiType.DepartmentInfo) {
|
||||
try {
|
||||
await deleteDepartmentApi(record.id);
|
||||
message.success('删除成功');
|
||||
await fetchDepartmentList();
|
||||
} catch (error) {
|
||||
console.error('删除部门失败:', error);
|
||||
message.error('删除部门失败');
|
||||
}
|
||||
}
|
||||
|
||||
// 处理表单提交
|
||||
async function handleSubmit() {
|
||||
try {
|
||||
await formRef.value?.validate();
|
||||
|
||||
if (isEdit.value && currentDepartmentId.value) {
|
||||
await updateDepartmentApi(currentDepartmentId.value, formData.value);
|
||||
message.success('更新成功');
|
||||
} else {
|
||||
await createDepartmentApi(formData.value);
|
||||
message.success('创建成功');
|
||||
}
|
||||
|
||||
modalVisible.value = false;
|
||||
await fetchDepartmentList();
|
||||
} catch (error) {
|
||||
console.error('保存部门失败:', error);
|
||||
message.error('保存部门失败');
|
||||
}
|
||||
}
|
||||
|
||||
// 初始化
|
||||
fetchDepartmentList();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page title="部门管理">
|
||||
<template #description>
|
||||
<div class="text-foreground/80 mt-2">
|
||||
管理部门信息,支持层级结构,可以创建子部门
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template #extra>
|
||||
<Button type="primary" @click="handleAdd">
|
||||
添加部门
|
||||
</Button>
|
||||
</template>
|
||||
|
||||
<!-- 搜索表单 -->
|
||||
<div class="mb-4 p-4 bg-gray-50 rounded-lg">
|
||||
<Form layout="inline" :model="searchForm">
|
||||
<Form.Item label="部门名称" name="name">
|
||||
<Input
|
||||
v-model:value="searchForm.name"
|
||||
placeholder="请输入部门名称"
|
||||
style="width: 200px;"
|
||||
@press-enter="handleSearch"
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item label="状态" name="status">
|
||||
<Select
|
||||
v-model:value="searchForm.status"
|
||||
placeholder="请选择状态"
|
||||
style="width: 120px;"
|
||||
:options="statusOptions"
|
||||
allow-clear
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item>
|
||||
<Button type="primary" @click="handleSearch">搜索</Button>
|
||||
<Button @click="handleReset" class="ml-2">重置</Button>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</div>
|
||||
|
||||
<!-- 数据表格 -->
|
||||
<Table
|
||||
:columns="columns"
|
||||
:data-source="departmentList"
|
||||
:loading="loading"
|
||||
:pagination="{
|
||||
current: current,
|
||||
pageSize: pageSize,
|
||||
total: total,
|
||||
showSizeChanger: true,
|
||||
showQuickJumper: true,
|
||||
showTotal: (total, range) => `第 ${range[0]}-${range[1]} 条/共 ${total} 条`,
|
||||
}"
|
||||
row-key="id"
|
||||
@change="handleTableChange"
|
||||
/>
|
||||
|
||||
<!-- 添加/编辑模态框 -->
|
||||
<Modal
|
||||
v-model:open="modalVisible"
|
||||
:title="modalTitle"
|
||||
width="500px"
|
||||
@ok="handleSubmit"
|
||||
>
|
||||
<Form
|
||||
ref="formRef"
|
||||
:model="formData"
|
||||
:label-col="{ span: 6 }"
|
||||
:wrapper-col="{ span: 18 }"
|
||||
>
|
||||
<Form.Item label="父部门" name="parentId">
|
||||
<Select
|
||||
v-model:value="formData.parentId"
|
||||
placeholder="请选择父部门"
|
||||
:options="parentDepartmentOptions"
|
||||
allow-clear
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="部门名称" name="name" :rules="[{ required: true, message: '请输入部门名称' }]">
|
||||
<Input v-model:value="formData.name" placeholder="请输入部门名称" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="描述" name="remark">
|
||||
<Input.TextArea v-model:value="formData.remark" placeholder="请输入部门描述" :rows="3" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="状态" name="status">
|
||||
<Select
|
||||
v-model:value="formData.status"
|
||||
placeholder="请选择状态"
|
||||
:options="statusOptions"
|
||||
/>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</Modal>
|
||||
</Page>
|
||||
</template>
|
||||
+342
@@ -0,0 +1,342 @@
|
||||
<script lang="ts" setup>
|
||||
import { h, ref } from 'vue';
|
||||
|
||||
import { Page } from '@vben/common-ui';
|
||||
import { Button, Form, Input, Modal, Select, Table, message } from 'ant-design-vue';
|
||||
|
||||
import {
|
||||
createPositionApi,
|
||||
deletePositionApi,
|
||||
getPositionPageApi,
|
||||
updatePositionApi,
|
||||
type PositionApi as PositionApiType
|
||||
} from '#/api/core/organization';
|
||||
|
||||
defineOptions({ name: 'PositionManagement' });
|
||||
|
||||
// 响应式数据
|
||||
const loading = ref(false);
|
||||
const positionList = ref<PositionApiType.PositionInfo[]>([]);
|
||||
const total = ref(0);
|
||||
const current = ref(1);
|
||||
const pageSize = ref(10);
|
||||
const modalVisible = ref(false);
|
||||
const modalTitle = ref('');
|
||||
const isEdit = ref(false);
|
||||
const currentPositionId = ref<number | null>(null);
|
||||
const formRef = ref();
|
||||
|
||||
// 搜索表单
|
||||
const searchForm = ref({
|
||||
name: '',
|
||||
status: undefined as number | undefined,
|
||||
});
|
||||
|
||||
// 表单数据
|
||||
const formData = ref<PositionApiType.CreatePositionParams>({
|
||||
name: '',
|
||||
code: '',
|
||||
departmentId: undefined,
|
||||
remark: '',
|
||||
status: 1,
|
||||
});
|
||||
|
||||
// 状态选项
|
||||
const statusOptions = [
|
||||
{ label: '禁用', value: 0 },
|
||||
{ label: '启用', value: 1 },
|
||||
];
|
||||
|
||||
// 部门选项(这里需要根据实际情况获取部门列表)
|
||||
const departmentOptions = ref([
|
||||
{ label: '技术部', value: 1 },
|
||||
{ label: '产品部', value: 2 },
|
||||
{ label: '运营部', value: 3 },
|
||||
{ label: '市场部', value: 4 },
|
||||
]);
|
||||
|
||||
// 表格列配置
|
||||
const columns = [
|
||||
{
|
||||
title: '岗位名称',
|
||||
dataIndex: 'name',
|
||||
key: 'name',
|
||||
width: 150,
|
||||
},
|
||||
{
|
||||
title: '岗位编码',
|
||||
dataIndex: 'code',
|
||||
key: 'code',
|
||||
width: 120,
|
||||
},
|
||||
{
|
||||
title: '所属部门',
|
||||
dataIndex: 'departmentId',
|
||||
key: 'departmentId',
|
||||
width: 150,
|
||||
customRender: ({ record }: { record: PositionApiType.PositionInfo }) => {
|
||||
if (!record.departmentId) return '-';
|
||||
const dept = departmentOptions.value.find(d => d.value === record.departmentId);
|
||||
return dept ? dept.label : '未知部门';
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '描述',
|
||||
dataIndex: 'remark',
|
||||
key: 'remark',
|
||||
width: 200,
|
||||
},
|
||||
{
|
||||
title: '状态',
|
||||
dataIndex: 'status',
|
||||
key: 'status',
|
||||
width: 100,
|
||||
customRender: ({ record }: { record: PositionApiType.PositionInfo }) => {
|
||||
return h('span', {
|
||||
style: { color: record.status === 1 ? '#52c41a' : '#ff4d4f' },
|
||||
}, record.status === 1 ? '启用' : '禁用');
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '创建时间',
|
||||
dataIndex: 'createTime',
|
||||
key: 'createTime',
|
||||
width: 180,
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
key: 'action',
|
||||
width: 200,
|
||||
fixed: 'right' as const,
|
||||
customRender: ({ record }: { record: PositionApiType.PositionInfo }) => {
|
||||
return h('div', { style: 'display: flex; gap: 8px;' }, [
|
||||
h(Button, {
|
||||
size: 'small',
|
||||
onClick: () => handleEdit(record),
|
||||
}, '编辑'),
|
||||
h(Button, {
|
||||
size: 'small',
|
||||
danger: true,
|
||||
onClick: () => handleDelete(record),
|
||||
}, '删除'),
|
||||
]);
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
// 获取岗位列表
|
||||
async function fetchPositionList() {
|
||||
try {
|
||||
loading.value = true;
|
||||
const params = {
|
||||
page: current.value,
|
||||
size: pageSize.value,
|
||||
filter: {
|
||||
name: searchForm.value.name || undefined,
|
||||
status: searchForm.value.status,
|
||||
},
|
||||
};
|
||||
const data = await getPositionPageApi(params);
|
||||
positionList.value = data.records;
|
||||
total.value = data.total;
|
||||
} catch (error) {
|
||||
console.error('获取岗位列表失败:', error);
|
||||
message.error('获取岗位列表失败');
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
// 处理搜索
|
||||
function handleSearch() {
|
||||
current.value = 1;
|
||||
fetchPositionList();
|
||||
}
|
||||
|
||||
// 处理重置
|
||||
function handleReset() {
|
||||
searchForm.value = {
|
||||
name: '',
|
||||
status: undefined,
|
||||
};
|
||||
current.value = 1;
|
||||
fetchPositionList();
|
||||
}
|
||||
|
||||
// 处理分页变化
|
||||
function handleTableChange(pagination: any) {
|
||||
current.value = pagination.current;
|
||||
pageSize.value = pagination.pageSize;
|
||||
fetchPositionList();
|
||||
}
|
||||
|
||||
// 处理添加岗位
|
||||
function handleAdd() {
|
||||
modalTitle.value = '添加岗位';
|
||||
isEdit.value = false;
|
||||
currentPositionId.value = null;
|
||||
formData.value = {
|
||||
name: '',
|
||||
code: '',
|
||||
departmentId: undefined,
|
||||
remark: '',
|
||||
status: 1,
|
||||
};
|
||||
modalVisible.value = true;
|
||||
}
|
||||
|
||||
// 处理编辑岗位
|
||||
function handleEdit(record: PositionApiType.PositionInfo) {
|
||||
modalTitle.value = '编辑岗位';
|
||||
isEdit.value = true;
|
||||
currentPositionId.value = record.id;
|
||||
formData.value = {
|
||||
name: record.name,
|
||||
code: record.code || '',
|
||||
departmentId: record.departmentId,
|
||||
remark: record.remark || '',
|
||||
status: record.status,
|
||||
};
|
||||
modalVisible.value = true;
|
||||
}
|
||||
|
||||
// 处理删除岗位
|
||||
async function handleDelete(record: PositionApiType.PositionInfo) {
|
||||
try {
|
||||
await deletePositionApi(record.id);
|
||||
message.success('删除成功');
|
||||
await fetchPositionList();
|
||||
} catch (error) {
|
||||
console.error('删除岗位失败:', error);
|
||||
message.error('删除岗位失败');
|
||||
}
|
||||
}
|
||||
|
||||
// 处理表单提交
|
||||
async function handleSubmit() {
|
||||
try {
|
||||
await formRef.value?.validate();
|
||||
|
||||
if (isEdit.value && currentPositionId.value) {
|
||||
await updatePositionApi(currentPositionId.value, formData.value);
|
||||
message.success('更新成功');
|
||||
} else {
|
||||
await createPositionApi(formData.value);
|
||||
message.success('创建成功');
|
||||
}
|
||||
|
||||
modalVisible.value = false;
|
||||
await fetchPositionList();
|
||||
} catch (error) {
|
||||
console.error('保存岗位失败:', error);
|
||||
message.error('保存岗位失败');
|
||||
}
|
||||
}
|
||||
|
||||
// 初始化
|
||||
fetchPositionList();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page title="岗位管理">
|
||||
<template #description>
|
||||
<div class="text-foreground/80 mt-2">
|
||||
管理岗位信息,包括岗位名称、编码、所属部门和描述
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template #extra>
|
||||
<Button type="primary" @click="handleAdd">
|
||||
添加岗位
|
||||
</Button>
|
||||
</template>
|
||||
|
||||
<!-- 搜索表单 -->
|
||||
<div class="mb-4 p-4 bg-gray-50 rounded-lg">
|
||||
<Form layout="inline" :model="searchForm">
|
||||
<Form.Item label="岗位名称" name="name">
|
||||
<Input
|
||||
v-model:value="searchForm.name"
|
||||
placeholder="请输入岗位名称"
|
||||
style="width: 200px;"
|
||||
@press-enter="handleSearch"
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item label="状态" name="status">
|
||||
<Select
|
||||
v-model:value="searchForm.status"
|
||||
placeholder="请选择状态"
|
||||
style="width: 120px;"
|
||||
:options="statusOptions"
|
||||
allow-clear
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item>
|
||||
<Button type="primary" @click="handleSearch">搜索</Button>
|
||||
<Button @click="handleReset" class="ml-2">重置</Button>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</div>
|
||||
|
||||
<!-- 数据表格 -->
|
||||
<Table
|
||||
:columns="columns"
|
||||
:data-source="positionList"
|
||||
:loading="loading"
|
||||
:pagination="{
|
||||
current: current,
|
||||
pageSize: pageSize,
|
||||
total: total,
|
||||
showSizeChanger: true,
|
||||
showQuickJumper: true,
|
||||
showTotal: (total, range) => `第 ${range[0]}-${range[1]} 条/共 ${total} 条`,
|
||||
}"
|
||||
row-key="id"
|
||||
@change="handleTableChange"
|
||||
/>
|
||||
|
||||
<!-- 添加/编辑模态框 -->
|
||||
<Modal
|
||||
v-model:open="modalVisible"
|
||||
:title="modalTitle"
|
||||
width="500px"
|
||||
@ok="handleSubmit"
|
||||
>
|
||||
<Form
|
||||
ref="formRef"
|
||||
:model="formData"
|
||||
:label-col="{ span: 6 }"
|
||||
:wrapper-col="{ span: 18 }"
|
||||
>
|
||||
<Form.Item label="岗位名称" name="name" :rules="[{ required: true, message: '请输入岗位名称' }]">
|
||||
<Input v-model:value="formData.name" placeholder="请输入岗位名称" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="岗位编码" name="code">
|
||||
<Input v-model:value="formData.code" placeholder="请输入岗位编码" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="所属部门" name="departmentId">
|
||||
<Select
|
||||
v-model:value="formData.departmentId"
|
||||
placeholder="请选择所属部门"
|
||||
:options="departmentOptions"
|
||||
allow-clear
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="描述" name="remark">
|
||||
<Input.TextArea v-model:value="formData.remark" placeholder="请输入岗位描述" :rows="3" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="状态" name="status">
|
||||
<Select
|
||||
v-model:value="formData.status"
|
||||
placeholder="请选择状态"
|
||||
:options="statusOptions"
|
||||
/>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</Modal>
|
||||
</Page>
|
||||
</template>
|
||||
@@ -0,0 +1,387 @@
|
||||
<script lang="ts" setup>
|
||||
import { computed, h, ref } from 'vue';
|
||||
|
||||
import { Page } from '@vben/common-ui';
|
||||
import { Button, Form, Input, InputNumber, Modal, Select, Table, message } from 'ant-design-vue';
|
||||
|
||||
import {
|
||||
createMenuApi,
|
||||
deleteMenuApi,
|
||||
getAllMenusApi,
|
||||
getMenuDetailApi,
|
||||
updateMenuApi,
|
||||
type MenuApi as MenuApiType
|
||||
} from '#/api/core/menu';
|
||||
|
||||
defineOptions({ name: 'MenuManagement' });
|
||||
|
||||
// 响应式数据
|
||||
const loading = ref(false);
|
||||
const menuList = ref<MenuApiType.MenuInfo[]>([]);
|
||||
const modalVisible = ref(false);
|
||||
const modalTitle = ref('');
|
||||
const isEdit = ref(false);
|
||||
const currentMenuId = ref<number | null>(null);
|
||||
const formRef = ref();
|
||||
|
||||
// 表单数据
|
||||
const formData = ref<MenuApiType.CreateMenuParams>({
|
||||
parentId: 0,
|
||||
name: '',
|
||||
title: '',
|
||||
path: '',
|
||||
component: '',
|
||||
redirect: '',
|
||||
icon: '',
|
||||
order: 0,
|
||||
type: 'menu',
|
||||
visible: 1,
|
||||
status: 1,
|
||||
keepAlive: 0,
|
||||
});
|
||||
|
||||
// 菜单类型选项
|
||||
const menuTypeOptions = [
|
||||
{ label: '目录', value: 'catalog' },
|
||||
{ label: '菜单', value: 'menu' },
|
||||
{ label: '按钮', value: 'button' },
|
||||
{ label: '内联', value: 'embedded' },
|
||||
{ label: '外链', value: 'link' },
|
||||
];
|
||||
|
||||
// 状态选项
|
||||
const statusOptions = [
|
||||
{ label: '禁用', value: 0 },
|
||||
{ label: '启用', value: 1 },
|
||||
];
|
||||
|
||||
// 可见性选项
|
||||
const visibleOptions = [
|
||||
{ label: '隐藏', value: 0 },
|
||||
{ label: '显示', value: 1 },
|
||||
];
|
||||
|
||||
// 缓存选项
|
||||
const keepAliveOptions = [
|
||||
{ label: '不缓存', value: 0 },
|
||||
{ label: '缓存', value: 1 },
|
||||
];
|
||||
|
||||
// 父菜单选项
|
||||
const parentMenuOptions = computed(() => {
|
||||
const options: Array<{ label: string; value: number }> = [{ label: '根菜单', value: 0 }];
|
||||
|
||||
const addMenuOptions = (menus: MenuApiType.MenuInfo[], level = 0) => {
|
||||
menus.forEach(menu => {
|
||||
const prefix = ' '.repeat(level);
|
||||
options.push({
|
||||
label: `${prefix}${menu.title || menu.name}`,
|
||||
value: menu.id,
|
||||
});
|
||||
if (menu.children && menu.children.length > 0) {
|
||||
addMenuOptions(menu.children, level + 1);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
addMenuOptions(menuList.value);
|
||||
return options;
|
||||
});
|
||||
|
||||
// 表格列配置
|
||||
const columns = [
|
||||
{
|
||||
title: '菜单名称',
|
||||
dataIndex: 'name',
|
||||
key: 'name',
|
||||
width: 200,
|
||||
},
|
||||
{
|
||||
title: '菜单标题',
|
||||
dataIndex: 'title',
|
||||
key: 'title',
|
||||
width: 150,
|
||||
},
|
||||
{
|
||||
title: '路由路径',
|
||||
dataIndex: 'path',
|
||||
key: 'path',
|
||||
width: 200,
|
||||
},
|
||||
{
|
||||
title: '页面组件',
|
||||
dataIndex: 'component',
|
||||
key: 'component',
|
||||
width: 200,
|
||||
},
|
||||
{
|
||||
title: '图标',
|
||||
dataIndex: 'icon',
|
||||
key: 'icon',
|
||||
width: 100,
|
||||
},
|
||||
{
|
||||
title: '类型',
|
||||
dataIndex: 'type',
|
||||
key: 'type',
|
||||
width: 100,
|
||||
customRender: ({ record }: { record: MenuApiType.MenuInfo }) => {
|
||||
const typeMap: Record<string, string> = {
|
||||
catalog: '目录',
|
||||
menu: '菜单',
|
||||
button: '按钮',
|
||||
embedded: '内联',
|
||||
link: '外链',
|
||||
};
|
||||
return typeMap[record.type] || record.type;
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '排序',
|
||||
dataIndex: 'order',
|
||||
key: 'order',
|
||||
width: 80,
|
||||
},
|
||||
{
|
||||
title: '状态',
|
||||
dataIndex: 'status',
|
||||
key: 'status',
|
||||
width: 80,
|
||||
customRender: ({ record }: { record: MenuApiType.MenuInfo }) => {
|
||||
return h('span', {
|
||||
style: { color: record.status === 1 ? '#52c41a' : '#ff4d4f' },
|
||||
}, record.status === 1 ? '启用' : '禁用');
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
key: 'action',
|
||||
width: 200,
|
||||
customRender: ({ record }: { record: MenuApiType.MenuInfo }) => {
|
||||
return h('div', { style: 'display: flex; gap: 8px;' }, [
|
||||
h(Button, {
|
||||
size: 'small',
|
||||
onClick: () => handleEdit(record),
|
||||
}, '编辑'),
|
||||
h(Button, {
|
||||
size: 'small',
|
||||
danger: true,
|
||||
onClick: () => handleDelete(record),
|
||||
}, '删除'),
|
||||
]);
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
// 获取菜单列表
|
||||
async function fetchMenuList() {
|
||||
try {
|
||||
loading.value = true;
|
||||
const data = await getAllMenusApi();
|
||||
menuList.value = data;
|
||||
} catch (error) {
|
||||
console.error('获取菜单列表失败:', error);
|
||||
message.error('获取菜单列表失败');
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
// 处理添加菜单
|
||||
function handleAdd() {
|
||||
modalTitle.value = '添加菜单';
|
||||
isEdit.value = false;
|
||||
currentMenuId.value = null;
|
||||
formData.value = {
|
||||
parentId: 0,
|
||||
name: '',
|
||||
title: '',
|
||||
path: '',
|
||||
component: '',
|
||||
redirect: '',
|
||||
icon: '',
|
||||
order: 0,
|
||||
type: 'menu',
|
||||
visible: 1,
|
||||
status: 1,
|
||||
keepAlive: 0,
|
||||
};
|
||||
modalVisible.value = true;
|
||||
}
|
||||
|
||||
// 处理编辑菜单
|
||||
async function handleEdit(record: MenuApiType.MenuInfo) {
|
||||
try {
|
||||
modalTitle.value = '编辑菜单';
|
||||
isEdit.value = true;
|
||||
currentMenuId.value = record.id;
|
||||
|
||||
// 获取菜单详情
|
||||
const detail = await getMenuDetailApi(record.id);
|
||||
formData.value = {
|
||||
parentId: detail.parentId || 0,
|
||||
name: detail.name,
|
||||
title: detail.title || '',
|
||||
path: detail.path || '',
|
||||
component: detail.component || '',
|
||||
redirect: detail.redirect || '',
|
||||
icon: detail.icon || '',
|
||||
order: detail.order || 0,
|
||||
type: detail.type,
|
||||
visible: detail.visible || 1,
|
||||
status: detail.status || 1,
|
||||
keepAlive: detail.keepAlive || 0,
|
||||
};
|
||||
|
||||
modalVisible.value = true;
|
||||
} catch (error) {
|
||||
console.error('获取菜单详情失败:', error);
|
||||
message.error('获取菜单详情失败');
|
||||
}
|
||||
}
|
||||
|
||||
// 处理删除菜单
|
||||
async function handleDelete(record: MenuApiType.MenuInfo) {
|
||||
try {
|
||||
await deleteMenuApi(record.id);
|
||||
message.success('删除成功');
|
||||
await fetchMenuList();
|
||||
} catch (error) {
|
||||
console.error('删除菜单失败:', error);
|
||||
message.error('删除菜单失败');
|
||||
}
|
||||
}
|
||||
|
||||
// 处理表单提交
|
||||
async function handleSubmit() {
|
||||
try {
|
||||
await formRef.value?.validate();
|
||||
|
||||
if (isEdit.value && currentMenuId.value) {
|
||||
await updateMenuApi(currentMenuId.value, formData.value);
|
||||
message.success('更新成功');
|
||||
} else {
|
||||
await createMenuApi(formData.value);
|
||||
message.success('创建成功');
|
||||
}
|
||||
|
||||
modalVisible.value = false;
|
||||
await fetchMenuList();
|
||||
} catch (error) {
|
||||
console.error('保存菜单失败:', error);
|
||||
message.error('保存菜单失败');
|
||||
}
|
||||
}
|
||||
|
||||
// 初始化
|
||||
fetchMenuList();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page title="菜单管理">
|
||||
<template #description>
|
||||
<div class="text-foreground/80 mt-2">
|
||||
管理系统菜单,包括目录、菜单、按钮等类型的增删改查操作
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template #extra>
|
||||
<Button type="primary" @click="handleAdd">
|
||||
添加菜单
|
||||
</Button>
|
||||
</template>
|
||||
|
||||
<Table
|
||||
:columns="columns"
|
||||
:data-source="menuList"
|
||||
:loading="loading"
|
||||
:pagination="false"
|
||||
row-key="id"
|
||||
:default-expand-all-rows="true"
|
||||
:tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
|
||||
/>
|
||||
|
||||
<Modal
|
||||
v-model:open="modalVisible"
|
||||
:title="modalTitle"
|
||||
width="600px"
|
||||
@ok="handleSubmit"
|
||||
>
|
||||
<Form
|
||||
ref="formRef"
|
||||
:model="formData"
|
||||
:label-col="{ span: 6 }"
|
||||
:wrapper-col="{ span: 18 }"
|
||||
>
|
||||
<Form.Item label="父菜单" name="parentId">
|
||||
<Select
|
||||
v-model:value="formData.parentId"
|
||||
placeholder="请选择父菜单"
|
||||
:options="parentMenuOptions"
|
||||
allow-clear
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="菜单名称" name="name" :rules="[{ required: true, message: '请输入菜单名称' }]">
|
||||
<Input v-model:value="formData.name" placeholder="请输入菜单名称" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="菜单标题" name="title">
|
||||
<Input v-model:value="formData.title" placeholder="请输入菜单标题" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="路由路径" name="path">
|
||||
<Input v-model:value="formData.path" placeholder="请输入路由路径" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="页面组件" name="component">
|
||||
<Input v-model:value="formData.component" placeholder="请输入页面组件" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="重定向地址" name="redirect">
|
||||
<Input v-model:value="formData.redirect" placeholder="请输入重定向地址" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="路由图标" name="icon">
|
||||
<Input v-model:value="formData.icon" placeholder="请输入路由图标" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="排序" name="order">
|
||||
<InputNumber v-model:value="formData.order" placeholder="请输入排序" :min="0" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="菜单类型" name="type" :rules="[{ required: true, message: '请选择菜单类型' }]">
|
||||
<Select
|
||||
v-model:value="formData.type"
|
||||
placeholder="请选择菜单类型"
|
||||
:options="menuTypeOptions"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="是否显示" name="visible">
|
||||
<Select
|
||||
v-model:value="formData.visible"
|
||||
placeholder="请选择是否显示"
|
||||
:options="visibleOptions"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="状态" name="status">
|
||||
<Select
|
||||
v-model:value="formData.status"
|
||||
placeholder="请选择状态"
|
||||
:options="statusOptions"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="是否缓存" name="keepAlive">
|
||||
<Select
|
||||
v-model:value="formData.keepAlive"
|
||||
placeholder="请选择是否缓存"
|
||||
:options="keepAliveOptions"
|
||||
/>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</Modal>
|
||||
</Page>
|
||||
</template>
|
||||
@@ -0,0 +1,98 @@
|
||||
<script lang="ts" setup>
|
||||
import type { EchartsUIType } from '@vben/plugins/echarts';
|
||||
|
||||
import { onMounted, ref } from 'vue';
|
||||
|
||||
import { EchartsUI, useEcharts } from '@vben/plugins/echarts';
|
||||
|
||||
const chartRef = ref<EchartsUIType>();
|
||||
const { renderEcharts } = useEcharts(chartRef);
|
||||
|
||||
onMounted(() => {
|
||||
renderEcharts({
|
||||
grid: {
|
||||
bottom: 0,
|
||||
containLabel: true,
|
||||
left: '1%',
|
||||
right: '1%',
|
||||
top: '2 %',
|
||||
},
|
||||
series: [
|
||||
{
|
||||
areaStyle: {},
|
||||
data: [
|
||||
111, 2000, 6000, 16_000, 33_333, 55_555, 64_000, 33_333, 18_000,
|
||||
36_000, 70_000, 42_444, 23_222, 13_000, 8000, 4000, 1200, 333, 222,
|
||||
111,
|
||||
],
|
||||
itemStyle: {
|
||||
color: '#5ab1ef',
|
||||
},
|
||||
smooth: true,
|
||||
type: 'line',
|
||||
},
|
||||
{
|
||||
areaStyle: {},
|
||||
data: [
|
||||
33, 66, 88, 333, 3333, 6200, 20_000, 3000, 1200, 13_000, 22_000,
|
||||
11_000, 2221, 1201, 390, 198, 60, 30, 22, 11,
|
||||
],
|
||||
itemStyle: {
|
||||
color: '#019680',
|
||||
},
|
||||
smooth: true,
|
||||
type: 'line',
|
||||
},
|
||||
],
|
||||
tooltip: {
|
||||
axisPointer: {
|
||||
lineStyle: {
|
||||
color: '#019680',
|
||||
width: 1,
|
||||
},
|
||||
},
|
||||
trigger: 'axis',
|
||||
},
|
||||
// xAxis: {
|
||||
// axisTick: {
|
||||
// show: false,
|
||||
// },
|
||||
// boundaryGap: false,
|
||||
// data: Array.from({ length: 18 }).map((_item, index) => `${index + 6}:00`),
|
||||
// type: 'category',
|
||||
// },
|
||||
xAxis: {
|
||||
axisTick: {
|
||||
show: false,
|
||||
},
|
||||
boundaryGap: false,
|
||||
data: Array.from({ length: 18 }).map((_item, index) => `${index + 6}:00`),
|
||||
splitLine: {
|
||||
lineStyle: {
|
||||
type: 'solid',
|
||||
width: 1,
|
||||
},
|
||||
show: true,
|
||||
},
|
||||
type: 'category',
|
||||
},
|
||||
yAxis: [
|
||||
{
|
||||
axisTick: {
|
||||
show: false,
|
||||
},
|
||||
max: 80_000,
|
||||
splitArea: {
|
||||
show: true,
|
||||
},
|
||||
splitNumber: 4,
|
||||
type: 'value',
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<EchartsUI ref="chartRef" />
|
||||
</template>
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
<script lang="ts" setup>
|
||||
import type { EchartsUIType } from '@vben/plugins/echarts';
|
||||
|
||||
import { onMounted, ref } from 'vue';
|
||||
|
||||
import { EchartsUI, useEcharts } from '@vben/plugins/echarts';
|
||||
|
||||
const chartRef = ref<EchartsUIType>();
|
||||
const { renderEcharts } = useEcharts(chartRef);
|
||||
|
||||
onMounted(() => {
|
||||
renderEcharts({
|
||||
legend: {
|
||||
bottom: 0,
|
||||
data: ['访问', '趋势'],
|
||||
},
|
||||
radar: {
|
||||
indicator: [
|
||||
{
|
||||
name: '网页',
|
||||
},
|
||||
{
|
||||
name: '移动端',
|
||||
},
|
||||
{
|
||||
name: 'Ipad',
|
||||
},
|
||||
{
|
||||
name: '客户端',
|
||||
},
|
||||
{
|
||||
name: '第三方',
|
||||
},
|
||||
{
|
||||
name: '其它',
|
||||
},
|
||||
],
|
||||
radius: '60%',
|
||||
splitNumber: 8,
|
||||
},
|
||||
series: [
|
||||
{
|
||||
areaStyle: {
|
||||
opacity: 1,
|
||||
shadowBlur: 0,
|
||||
shadowColor: 'rgba(0,0,0,.2)',
|
||||
shadowOffsetX: 0,
|
||||
shadowOffsetY: 10,
|
||||
},
|
||||
data: [
|
||||
{
|
||||
itemStyle: {
|
||||
color: '#b6a2de',
|
||||
},
|
||||
name: '访问',
|
||||
value: [90, 50, 86, 40, 50, 20],
|
||||
},
|
||||
{
|
||||
itemStyle: {
|
||||
color: '#5ab1ef',
|
||||
},
|
||||
name: '趋势',
|
||||
value: [70, 75, 70, 76, 20, 85],
|
||||
},
|
||||
],
|
||||
itemStyle: {
|
||||
// borderColor: '#fff',
|
||||
borderRadius: 10,
|
||||
borderWidth: 2,
|
||||
},
|
||||
symbolSize: 0,
|
||||
type: 'radar',
|
||||
},
|
||||
],
|
||||
tooltip: {},
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<EchartsUI ref="chartRef" />
|
||||
</template>
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
<script lang="ts" setup>
|
||||
import type { EchartsUIType } from '@vben/plugins/echarts';
|
||||
|
||||
import { onMounted, ref } from 'vue';
|
||||
|
||||
import { EchartsUI, useEcharts } from '@vben/plugins/echarts';
|
||||
|
||||
const chartRef = ref<EchartsUIType>();
|
||||
const { renderEcharts } = useEcharts(chartRef);
|
||||
|
||||
onMounted(() => {
|
||||
renderEcharts({
|
||||
series: [
|
||||
{
|
||||
animationDelay() {
|
||||
return Math.random() * 400;
|
||||
},
|
||||
animationEasing: 'exponentialInOut',
|
||||
animationType: 'scale',
|
||||
center: ['50%', '50%'],
|
||||
color: ['#5ab1ef', '#b6a2de', '#67e0e3', '#2ec7c9'],
|
||||
data: [
|
||||
{ name: '外包', value: 500 },
|
||||
{ name: '定制', value: 310 },
|
||||
{ name: '技术支持', value: 274 },
|
||||
{ name: '远程', value: 400 },
|
||||
].sort((a, b) => {
|
||||
return a.value - b.value;
|
||||
}),
|
||||
name: '商业占比',
|
||||
radius: '80%',
|
||||
roseType: 'radius',
|
||||
type: 'pie',
|
||||
},
|
||||
],
|
||||
|
||||
tooltip: {
|
||||
trigger: 'item',
|
||||
},
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<EchartsUI ref="chartRef" />
|
||||
</template>
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
<script lang="ts" setup>
|
||||
import type { EchartsUIType } from '@vben/plugins/echarts';
|
||||
|
||||
import { onMounted, ref } from 'vue';
|
||||
|
||||
import { EchartsUI, useEcharts } from '@vben/plugins/echarts';
|
||||
|
||||
const chartRef = ref<EchartsUIType>();
|
||||
const { renderEcharts } = useEcharts(chartRef);
|
||||
|
||||
onMounted(() => {
|
||||
renderEcharts({
|
||||
legend: {
|
||||
bottom: '2%',
|
||||
left: 'center',
|
||||
},
|
||||
series: [
|
||||
{
|
||||
animationDelay() {
|
||||
return Math.random() * 100;
|
||||
},
|
||||
animationEasing: 'exponentialInOut',
|
||||
animationType: 'scale',
|
||||
avoidLabelOverlap: false,
|
||||
color: ['#5ab1ef', '#b6a2de', '#67e0e3', '#2ec7c9'],
|
||||
data: [
|
||||
{ name: '搜索引擎', value: 1048 },
|
||||
{ name: '直接访问', value: 735 },
|
||||
{ name: '邮件营销', value: 580 },
|
||||
{ name: '联盟广告', value: 484 },
|
||||
],
|
||||
emphasis: {
|
||||
label: {
|
||||
fontSize: '12',
|
||||
fontWeight: 'bold',
|
||||
show: true,
|
||||
},
|
||||
},
|
||||
itemStyle: {
|
||||
// borderColor: '#fff',
|
||||
borderRadius: 10,
|
||||
borderWidth: 2,
|
||||
},
|
||||
label: {
|
||||
position: 'center',
|
||||
show: false,
|
||||
},
|
||||
labelLine: {
|
||||
show: false,
|
||||
},
|
||||
name: '访问来源',
|
||||
radius: ['40%', '65%'],
|
||||
type: 'pie',
|
||||
},
|
||||
],
|
||||
tooltip: {
|
||||
trigger: 'item',
|
||||
},
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<EchartsUI ref="chartRef" />
|
||||
</template>
|
||||
@@ -0,0 +1,55 @@
|
||||
<script lang="ts" setup>
|
||||
import type { EchartsUIType } from '@vben/plugins/echarts';
|
||||
|
||||
import { onMounted, ref } from 'vue';
|
||||
|
||||
import { EchartsUI, useEcharts } from '@vben/plugins/echarts';
|
||||
|
||||
const chartRef = ref<EchartsUIType>();
|
||||
const { renderEcharts } = useEcharts(chartRef);
|
||||
|
||||
onMounted(() => {
|
||||
renderEcharts({
|
||||
grid: {
|
||||
bottom: 0,
|
||||
containLabel: true,
|
||||
left: '1%',
|
||||
right: '1%',
|
||||
top: '2 %',
|
||||
},
|
||||
series: [
|
||||
{
|
||||
barMaxWidth: 80,
|
||||
// color: '#4f69fd',
|
||||
data: [
|
||||
3000, 2000, 3333, 5000, 3200, 4200, 3200, 2100, 3000, 5100, 6000,
|
||||
3200, 4800,
|
||||
],
|
||||
type: 'bar',
|
||||
},
|
||||
],
|
||||
tooltip: {
|
||||
axisPointer: {
|
||||
lineStyle: {
|
||||
// color: '#4f69fd',
|
||||
width: 1,
|
||||
},
|
||||
},
|
||||
trigger: 'axis',
|
||||
},
|
||||
xAxis: {
|
||||
data: Array.from({ length: 12 }).map((_item, index) => `${index + 1}月`),
|
||||
type: 'category',
|
||||
},
|
||||
yAxis: {
|
||||
max: 8000,
|
||||
splitNumber: 4,
|
||||
type: 'value',
|
||||
},
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<EchartsUI ref="chartRef" />
|
||||
</template>
|
||||
@@ -0,0 +1,90 @@
|
||||
<script lang="ts" setup>
|
||||
import type { AnalysisOverviewItem } from '@vben/common-ui';
|
||||
import type { TabOption } from '@vben/types';
|
||||
|
||||
import {
|
||||
AnalysisChartCard,
|
||||
AnalysisChartsTabs,
|
||||
AnalysisOverview,
|
||||
} from '@vben/common-ui';
|
||||
import {
|
||||
SvgBellIcon,
|
||||
SvgCakeIcon,
|
||||
SvgCardIcon,
|
||||
SvgDownloadIcon,
|
||||
} from '@vben/icons';
|
||||
|
||||
import AnalyticsTrends from './analytics-trends.vue';
|
||||
import AnalyticsVisitsData from './analytics-visits-data.vue';
|
||||
import AnalyticsVisitsSales from './analytics-visits-sales.vue';
|
||||
import AnalyticsVisitsSource from './analytics-visits-source.vue';
|
||||
import AnalyticsVisits from './analytics-visits.vue';
|
||||
|
||||
const overviewItems: AnalysisOverviewItem[] = [
|
||||
{
|
||||
icon: SvgCardIcon,
|
||||
title: '用户量',
|
||||
totalTitle: '总用户量',
|
||||
totalValue: 120_000,
|
||||
value: 2000,
|
||||
},
|
||||
{
|
||||
icon: SvgCakeIcon,
|
||||
title: '访问量',
|
||||
totalTitle: '总访问量',
|
||||
totalValue: 500_000,
|
||||
value: 20_000,
|
||||
},
|
||||
{
|
||||
icon: SvgDownloadIcon,
|
||||
title: '下载量',
|
||||
totalTitle: '总下载量',
|
||||
totalValue: 120_000,
|
||||
value: 8000,
|
||||
},
|
||||
{
|
||||
icon: SvgBellIcon,
|
||||
title: '使用量',
|
||||
totalTitle: '总使用量',
|
||||
totalValue: 50_000,
|
||||
value: 5000,
|
||||
},
|
||||
];
|
||||
|
||||
const chartTabs: TabOption[] = [
|
||||
{
|
||||
label: '流量趋势',
|
||||
value: 'trends',
|
||||
},
|
||||
{
|
||||
label: '月访问量',
|
||||
value: 'visits',
|
||||
},
|
||||
];
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="p-5">
|
||||
<AnalysisOverview :items="overviewItems" />
|
||||
<AnalysisChartsTabs :tabs="chartTabs" class="mt-5">
|
||||
<template #trends>
|
||||
<AnalyticsTrends />
|
||||
</template>
|
||||
<template #visits>
|
||||
<AnalyticsVisits />
|
||||
</template>
|
||||
</AnalysisChartsTabs>
|
||||
|
||||
<div class="mt-5 w-full md:flex">
|
||||
<AnalysisChartCard class="mt-5 md:mr-4 md:mt-0 md:w-1/3" title="访问数量">
|
||||
<AnalyticsVisitsData />
|
||||
</AnalysisChartCard>
|
||||
<AnalysisChartCard class="mt-5 md:mr-4 md:mt-0 md:w-1/3" title="访问来源">
|
||||
<AnalyticsVisitsSource />
|
||||
</AnalysisChartCard>
|
||||
<AnalysisChartCard class="mt-5 md:mt-0 md:w-1/3" title="访问来源">
|
||||
<AnalyticsVisitsSales />
|
||||
</AnalysisChartCard>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,266 @@
|
||||
<script lang="ts" setup>
|
||||
import type {
|
||||
WorkbenchProjectItem,
|
||||
WorkbenchQuickNavItem,
|
||||
WorkbenchTodoItem,
|
||||
WorkbenchTrendItem,
|
||||
} from '@vben/common-ui';
|
||||
|
||||
import { ref } from 'vue';
|
||||
import { useRouter } from 'vue-router';
|
||||
|
||||
import {
|
||||
AnalysisChartCard,
|
||||
WorkbenchHeader,
|
||||
WorkbenchProject,
|
||||
WorkbenchQuickNav,
|
||||
WorkbenchTodo,
|
||||
WorkbenchTrends,
|
||||
} from '@vben/common-ui';
|
||||
import { preferences } from '@vben/preferences';
|
||||
import { useUserStore } from '@vben/stores';
|
||||
import { openWindow } from '@vben/utils';
|
||||
|
||||
import AnalyticsVisitsSource from '../analytics/analytics-visits-source.vue';
|
||||
|
||||
const userStore = useUserStore();
|
||||
|
||||
// 这是一个示例数据,实际项目中需要根据实际情况进行调整
|
||||
// url 也可以是内部路由,在 navTo 方法中识别处理,进行内部跳转
|
||||
// 例如:url: /dashboard/workspace
|
||||
const projectItems: WorkbenchProjectItem[] = [
|
||||
{
|
||||
color: '',
|
||||
content: '不要等待机会,而要创造机会。',
|
||||
date: '2021-04-01',
|
||||
group: '开源组',
|
||||
icon: 'carbon:logo-github',
|
||||
title: 'Github',
|
||||
url: 'https://github.com',
|
||||
},
|
||||
{
|
||||
color: '#3fb27f',
|
||||
content: '现在的你决定将来的你。',
|
||||
date: '2021-04-01',
|
||||
group: '算法组',
|
||||
icon: 'ion:logo-vue',
|
||||
title: 'Vue',
|
||||
url: 'https://vuejs.org',
|
||||
},
|
||||
{
|
||||
color: '#e18525',
|
||||
content: '没有什么才能比努力更重要。',
|
||||
date: '2021-04-01',
|
||||
group: '上班摸鱼',
|
||||
icon: 'ion:logo-html5',
|
||||
title: 'Html5',
|
||||
url: 'https://developer.mozilla.org/zh-CN/docs/Web/HTML',
|
||||
},
|
||||
{
|
||||
color: '#bf0c2c',
|
||||
content: '热情和欲望可以突破一切难关。',
|
||||
date: '2021-04-01',
|
||||
group: 'UI',
|
||||
icon: 'ion:logo-angular',
|
||||
title: 'Angular',
|
||||
url: 'https://angular.io',
|
||||
},
|
||||
{
|
||||
color: '#00d8ff',
|
||||
content: '健康的身体是实现目标的基石。',
|
||||
date: '2021-04-01',
|
||||
group: '技术牛',
|
||||
icon: 'bx:bxl-react',
|
||||
title: 'React',
|
||||
url: 'https://reactjs.org',
|
||||
},
|
||||
{
|
||||
color: '#EBD94E',
|
||||
content: '路是走出来的,而不是空想出来的。',
|
||||
date: '2021-04-01',
|
||||
group: '架构组',
|
||||
icon: 'ion:logo-javascript',
|
||||
title: 'Js',
|
||||
url: 'https://developer.mozilla.org/zh-CN/docs/Web/JavaScript',
|
||||
},
|
||||
];
|
||||
|
||||
// 同样,这里的 url 也可以使用以 http 开头的外部链接
|
||||
const quickNavItems: WorkbenchQuickNavItem[] = [
|
||||
{
|
||||
color: '#1fdaca',
|
||||
icon: 'ion:home-outline',
|
||||
title: '首页',
|
||||
url: '/',
|
||||
},
|
||||
{
|
||||
color: '#bf0c2c',
|
||||
icon: 'ion:grid-outline',
|
||||
title: '仪表盘',
|
||||
url: '/dashboard',
|
||||
},
|
||||
{
|
||||
color: '#e18525',
|
||||
icon: 'ion:layers-outline',
|
||||
title: '组件',
|
||||
url: '/demos/features/icons',
|
||||
},
|
||||
{
|
||||
color: '#3fb27f',
|
||||
icon: 'ion:settings-outline',
|
||||
title: '系统管理',
|
||||
url: '/demos/features/login-expired', // 这里的 URL 是示例,实际项目中需要根据实际情况进行调整
|
||||
},
|
||||
{
|
||||
color: '#4daf1bc9',
|
||||
icon: 'ion:key-outline',
|
||||
title: '权限管理',
|
||||
url: '/demos/access/page-control',
|
||||
},
|
||||
{
|
||||
color: '#00d8ff',
|
||||
icon: 'ion:bar-chart-outline',
|
||||
title: '图表',
|
||||
url: '/analytics',
|
||||
},
|
||||
];
|
||||
|
||||
const todoItems = ref<WorkbenchTodoItem[]>([
|
||||
{
|
||||
completed: false,
|
||||
content: `审查最近提交到Git仓库的前端代码,确保代码质量和规范。`,
|
||||
date: '2024-07-30 11:00:00',
|
||||
title: '审查前端代码提交',
|
||||
},
|
||||
{
|
||||
completed: true,
|
||||
content: `检查并优化系统性能,降低CPU使用率。`,
|
||||
date: '2024-07-30 11:00:00',
|
||||
title: '系统性能优化',
|
||||
},
|
||||
{
|
||||
completed: false,
|
||||
content: `进行系统安全检查,确保没有安全漏洞或未授权的访问。 `,
|
||||
date: '2024-07-30 11:00:00',
|
||||
title: '安全检查',
|
||||
},
|
||||
{
|
||||
completed: false,
|
||||
content: `更新项目中的所有npm依赖包,确保使用最新版本。`,
|
||||
date: '2024-07-30 11:00:00',
|
||||
title: '更新项目依赖',
|
||||
},
|
||||
{
|
||||
completed: false,
|
||||
content: `修复用户报告的页面UI显示问题,确保在不同浏览器中显示一致。 `,
|
||||
date: '2024-07-30 11:00:00',
|
||||
title: '修复UI显示问题',
|
||||
},
|
||||
]);
|
||||
const trendItems: WorkbenchTrendItem[] = [
|
||||
{
|
||||
avatar: 'svg:avatar-1',
|
||||
content: `在 <a>开源组</a> 创建了项目 <a>Vue</a>`,
|
||||
date: '刚刚',
|
||||
title: '威廉',
|
||||
},
|
||||
{
|
||||
avatar: 'svg:avatar-2',
|
||||
content: `关注了 <a>威廉</a> `,
|
||||
date: '1个小时前',
|
||||
title: '艾文',
|
||||
},
|
||||
{
|
||||
avatar: 'svg:avatar-3',
|
||||
content: `发布了 <a>个人动态</a> `,
|
||||
date: '1天前',
|
||||
title: '克里斯',
|
||||
},
|
||||
{
|
||||
avatar: 'svg:avatar-4',
|
||||
content: `发表文章 <a>如何编写一个Vite插件</a> `,
|
||||
date: '2天前',
|
||||
title: 'Vben',
|
||||
},
|
||||
{
|
||||
avatar: 'svg:avatar-1',
|
||||
content: `回复了 <a>杰克</a> 的问题 <a>如何进行项目优化?</a>`,
|
||||
date: '3天前',
|
||||
title: '皮特',
|
||||
},
|
||||
{
|
||||
avatar: 'svg:avatar-2',
|
||||
content: `关闭了问题 <a>如何运行项目</a> `,
|
||||
date: '1周前',
|
||||
title: '杰克',
|
||||
},
|
||||
{
|
||||
avatar: 'svg:avatar-3',
|
||||
content: `发布了 <a>个人动态</a> `,
|
||||
date: '1周前',
|
||||
title: '威廉',
|
||||
},
|
||||
{
|
||||
avatar: 'svg:avatar-4',
|
||||
content: `推送了代码到 <a>Github</a>`,
|
||||
date: '2021-04-01 20:00',
|
||||
title: '威廉',
|
||||
},
|
||||
{
|
||||
avatar: 'svg:avatar-4',
|
||||
content: `发表文章 <a>如何编写使用 Admin Vben</a> `,
|
||||
date: '2021-03-01 20:00',
|
||||
title: 'Vben',
|
||||
},
|
||||
];
|
||||
|
||||
const router = useRouter();
|
||||
|
||||
// 这是一个示例方法,实际项目中需要根据实际情况进行调整
|
||||
// This is a sample method, adjust according to the actual project requirements
|
||||
function navTo(nav: WorkbenchProjectItem | WorkbenchQuickNavItem) {
|
||||
if (nav.url?.startsWith('http')) {
|
||||
openWindow(nav.url);
|
||||
return;
|
||||
}
|
||||
if (nav.url?.startsWith('/')) {
|
||||
router.push(nav.url).catch((error) => {
|
||||
console.error('Navigation failed:', error);
|
||||
});
|
||||
} else {
|
||||
console.warn(`Unknown URL for navigation item: ${nav.title} -> ${nav.url}`);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="p-5">
|
||||
<WorkbenchHeader
|
||||
:avatar="userStore.userInfo?.avatar || preferences.app.defaultAvatar"
|
||||
>
|
||||
<template #title>
|
||||
早安, {{ userStore.userInfo?.realName }}, 开始您一天的工作吧!
|
||||
</template>
|
||||
<template #description> 今日晴,20℃ - 32℃! </template>
|
||||
</WorkbenchHeader>
|
||||
|
||||
<div class="mt-5 flex flex-col lg:flex-row">
|
||||
<div class="mr-4 w-full lg:w-3/5">
|
||||
<WorkbenchProject :items="projectItems" title="项目" @click="navTo" />
|
||||
<WorkbenchTrends :items="trendItems" class="mt-5" title="最新动态" />
|
||||
</div>
|
||||
<div class="w-full lg:w-2/5">
|
||||
<WorkbenchQuickNav
|
||||
:items="quickNavItems"
|
||||
class="mt-5 lg:mt-0"
|
||||
title="快捷导航"
|
||||
@click="navTo"
|
||||
/>
|
||||
<WorkbenchTodo :items="todoItems" class="mt-5" title="待办事项" />
|
||||
<AnalysisChartCard class="mt-5" title="访问来源">
|
||||
<AnalyticsVisitsSource />
|
||||
</AnalysisChartCard>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,159 @@
|
||||
# 电商数据中台系统
|
||||
|
||||
## 功能概述
|
||||
|
||||
这是一个基于Vue Vben Admin框架开发的电商数据中台系统,主要用于处理电商店铺的营业数据。
|
||||
|
||||
## 主要功能
|
||||
|
||||
### 1. 数据导入 (Data Import)
|
||||
|
||||
- **CSV文件上传**: 支持拖拽或点击上传CSV格式的营业数据文件
|
||||
- **数据预览**: 上传后可以预览前10条数据,了解数据结构
|
||||
- **字段映射**: 将CSV字段映射到标准字段,支持自定义字段名
|
||||
- **数据清洗**: 自动清洗和格式化数据(去除空格、数字格式化等)
|
||||
- **JSON导出**: 将处理后的数据导出为JSON格式
|
||||
|
||||
### 2. 数据分析 (Data Analysis)
|
||||
|
||||
- 数据统计和分析功能(开发中)
|
||||
|
||||
### 3. 店铺管理 (Shop Management)
|
||||
|
||||
- 店铺信息管理功能(开发中)
|
||||
|
||||
## 使用流程
|
||||
|
||||
### 数据导入流程
|
||||
|
||||
1. **上传CSV文件**
|
||||
- 点击"电商数据中台" -> "数据导入"
|
||||
- 拖拽或点击上传CSV文件
|
||||
- 系统会自动解析和验证数据
|
||||
|
||||
2. **预览数据**
|
||||
- 查看解析后的数据预览
|
||||
- 确认数据格式正确
|
||||
|
||||
3. **配置字段映射**
|
||||
- 点击"配置字段映射"按钮
|
||||
- 为每个CSV字段选择对应的标准字段
|
||||
- 可选择自定义字段名称
|
||||
- 实时预览映射后的数据
|
||||
|
||||
4. **导出JSON**
|
||||
- 确认字段映射无误后,点击"导出JSON"
|
||||
- 系统会生成包含元数据的JSON文件
|
||||
- 文件会保存到本地下载目录
|
||||
|
||||
## 支持的数据格式
|
||||
|
||||
### CSV文件要求
|
||||
|
||||
- 文件格式:`.csv`
|
||||
- 文件大小:最大10MB
|
||||
- 编码格式:UTF-8
|
||||
- 必要字段:
|
||||
- 商品
|
||||
- 订单号
|
||||
- 订单状态
|
||||
- 商品数量(件)
|
||||
- 商家实收金额(元)
|
||||
|
||||
### 标准字段映射
|
||||
|
||||
系统支持以下标准字段:
|
||||
|
||||
- `product_name`: 商品名称
|
||||
- `order_id`: 订单号
|
||||
- `order_status`: 订单状态
|
||||
- `quantity`: 商品数量
|
||||
- `product_id`: 商品ID
|
||||
- `product_spec`: 商品规格
|
||||
- `after_sale_status`: 售后状态
|
||||
- `amount`: 实收金额
|
||||
- `shop_name`: 店铺名称
|
||||
- `order_date`: 订单日期
|
||||
- `customer_id`: 客户ID
|
||||
- `payment_method`: 支付方式
|
||||
- `delivery_address`: 收货地址
|
||||
- `remark`: 备注
|
||||
|
||||
## 导出的JSON格式
|
||||
|
||||
```json
|
||||
{
|
||||
"metadata": {
|
||||
"source": "CSV导入",
|
||||
"totalRecords": 100,
|
||||
"exportTime": "2024-01-15T10:30:00.000Z",
|
||||
"fieldMappings": {
|
||||
"商品": "product_name",
|
||||
"订单号": "order_id"
|
||||
},
|
||||
"customFieldNames": {},
|
||||
"shopName": "店铺名称"
|
||||
},
|
||||
"data": [
|
||||
{
|
||||
"product_name": "商品名称",
|
||||
"order_id": "订单号",
|
||||
"order_status": "订单状态"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
## 技术栈
|
||||
|
||||
- **前端框架**: Vue 3 + TypeScript
|
||||
- **UI组件库**: Ant Design Vue
|
||||
- **构建工具**: Vite
|
||||
- **CSV解析**: PapaParse
|
||||
- **状态管理**: Pinia
|
||||
- **路由**: Vue Router
|
||||
|
||||
## 开发说明
|
||||
|
||||
### 项目结构
|
||||
|
||||
```
|
||||
src/views/ecommerce/
|
||||
├── data-import/
|
||||
│ ├── components/
|
||||
│ │ └── FieldMapping.vue # 字段映射组件
|
||||
│ └── index.vue # 数据导入主页面
|
||||
├── data-analysis/
|
||||
│ └── index.vue # 数据分析页面
|
||||
├── shop-management/
|
||||
│ └── index.vue # 店铺管理页面
|
||||
└── README.md # 说明文档
|
||||
```
|
||||
|
||||
### 工具函数
|
||||
|
||||
`src/utils/csv-utils.ts` 提供了以下工具函数:
|
||||
|
||||
- `parseCSV()`: 解析CSV文件
|
||||
- `transformDataWithMapping()`: 根据字段映射转换数据
|
||||
- `generateExportData()`: 生成导出数据
|
||||
- `downloadJSON()`: 下载JSON文件
|
||||
- `validateCSVData()`: 验证CSV数据格式
|
||||
- `cleanAndFormatData()`: 数据清洗和格式化
|
||||
|
||||
## 注意事项
|
||||
|
||||
1. 确保CSV文件格式正确,包含必要的字段
|
||||
2. 字段映射时,建议保留所有重要字段
|
||||
3. 导出的JSON文件包含完整的元数据,便于后续处理
|
||||
4. 系统会自动从文件名提取店铺名称
|
||||
5. 数据清洗会自动处理数字字段和去除空格
|
||||
|
||||
## 后续开发计划
|
||||
|
||||
- [ ] 数据分析功能
|
||||
- [ ] 店铺管理功能
|
||||
- [ ] 数据可视化图表
|
||||
- [ ] 批量数据处理
|
||||
- [ ] 数据导入历史记录
|
||||
- [ ] 数据导出模板管理
|
||||
@@ -0,0 +1,15 @@
|
||||
<template>
|
||||
<div class="p-6">
|
||||
<VbenCard title="数据分析">
|
||||
<div class="text-center py-12">
|
||||
<VbenIcon icon="lucide:bar-chart-3" class="w-16 h-16 mx-auto text-gray-400 mb-4" />
|
||||
<h3 class="text-lg font-medium text-gray-700 mb-2">数据分析功能</h3>
|
||||
<p class="text-gray-500">此功能正在开发中,敬请期待...</p>
|
||||
</div>
|
||||
</VbenCard>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
// 数据分析页面占位
|
||||
</script>
|
||||
+209
@@ -0,0 +1,209 @@
|
||||
<template>
|
||||
<div class="space-y-6">
|
||||
<!-- 字段映射说明 -->
|
||||
<div class="bg-blue-50 border border-blue-200 rounded-lg p-4">
|
||||
<div class="flex items-start space-x-2">
|
||||
<VbenIcon icon="lucide:info" class="w-5 h-5 text-blue-500 mt-0.5" />
|
||||
<div>
|
||||
<p class="font-medium text-blue-800">字段映射说明</p>
|
||||
<p class="text-sm text-blue-600 mt-1">
|
||||
请为每个CSV字段选择对应的标准字段,未映射的字段将被忽略。您也可以自定义字段名称。
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 字段映射表格 -->
|
||||
<div class="border rounded-lg">
|
||||
<VbenTable
|
||||
:columns="mappingColumns"
|
||||
:data-source="mappingData"
|
||||
:pagination="false"
|
||||
size="small"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- 数据预览 -->
|
||||
<div v-if="previewData.length > 0">
|
||||
<h4 class="text-md font-medium mb-3">映射后数据预览</h4>
|
||||
<VbenTable
|
||||
:columns="previewColumns"
|
||||
:data-source="previewData.slice(0, 5)"
|
||||
:pagination="false"
|
||||
size="small"
|
||||
:scroll="{ x: 800 }"
|
||||
/>
|
||||
<p class="text-sm text-gray-500 mt-2">
|
||||
显示前5条映射后的数据,共 {{ previewData.length }} 条记录
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<!-- 操作按钮 -->
|
||||
<div class="flex justify-end space-x-3 pt-4 border-t">
|
||||
<VbenButton @click="$emit('cancel')">
|
||||
取消
|
||||
</VbenButton>
|
||||
<VbenButton @click="handleExport" type="primary">
|
||||
导出JSON
|
||||
</VbenButton>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, watch } from 'vue'
|
||||
import { message } from 'ant-design-vue'
|
||||
import { transformDataWithMapping, generateExportData, downloadJSON } from '#/utils/csv-utils'
|
||||
|
||||
// Props
|
||||
interface Props {
|
||||
csvHeaders: string[]
|
||||
csvData: any[]
|
||||
}
|
||||
|
||||
const props = defineProps<Props>()
|
||||
|
||||
// Emits
|
||||
const emit = defineEmits<{
|
||||
confirm: [data: any]
|
||||
cancel: []
|
||||
}>()
|
||||
|
||||
// 响应式数据
|
||||
const fieldMappings = ref<Record<string, string>>({})
|
||||
const customFieldNames = ref<Record<string, string>>({})
|
||||
|
||||
// 标准字段选项
|
||||
const standardFields = [
|
||||
{ value: 'product_name', label: '商品名称' },
|
||||
{ value: 'order_id', label: '订单号' },
|
||||
{ value: 'order_status', label: '订单状态' },
|
||||
{ value: 'quantity', label: '商品数量' },
|
||||
{ value: 'product_id', label: '商品ID' },
|
||||
{ value: 'product_spec', label: '商品规格' },
|
||||
{ value: 'after_sale_status', label: '售后状态' },
|
||||
{ value: 'amount', label: '实收金额' },
|
||||
{ value: 'shop_name', label: '店铺名称' },
|
||||
{ value: 'order_date', label: '订单日期' },
|
||||
{ value: 'customer_id', label: '客户ID' },
|
||||
{ value: 'payment_method', label: '支付方式' },
|
||||
{ value: 'delivery_address', label: '收货地址' },
|
||||
{ value: 'remark', label: '备注' },
|
||||
]
|
||||
|
||||
// 计算属性
|
||||
const mappingData = computed(() => {
|
||||
return props.csvHeaders.map((header, index) => ({
|
||||
key: index,
|
||||
csvField: header,
|
||||
standardField: fieldMappings.value[header] || '',
|
||||
customName: customFieldNames.value[header] || '',
|
||||
}))
|
||||
})
|
||||
|
||||
const mappingColumns = [
|
||||
{
|
||||
title: 'CSV字段',
|
||||
dataIndex: 'csvField',
|
||||
key: 'csvField',
|
||||
width: 200,
|
||||
},
|
||||
{
|
||||
title: '标准字段',
|
||||
dataIndex: 'standardField',
|
||||
key: 'standardField',
|
||||
width: 200,
|
||||
customRender: ({ record }: any) => {
|
||||
return h('VbenSelect', {
|
||||
value: record.standardField,
|
||||
placeholder: '选择标准字段',
|
||||
allowClear: true,
|
||||
options: standardFields,
|
||||
onChange: (value: string) => {
|
||||
fieldMappings.value[record.csvField] = value
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
{
|
||||
title: '自定义字段名',
|
||||
dataIndex: 'customName',
|
||||
key: 'customName',
|
||||
width: 200,
|
||||
customRender: ({ record }: any) => {
|
||||
return h('VbenInput', {
|
||||
value: record.customName,
|
||||
placeholder: '可选:自定义字段名',
|
||||
onChange: (e: any) => {
|
||||
customFieldNames.value[record.csvField] = e.target.value
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
{
|
||||
title: '示例数据',
|
||||
dataIndex: 'example',
|
||||
key: 'example',
|
||||
ellipsis: true,
|
||||
customRender: ({ record }: any) => {
|
||||
const exampleValue = props.csvData[0]?.[record.csvField] || ''
|
||||
return exampleValue.toString().substring(0, 50) + (exampleValue.toString().length > 50 ? '...' : '')
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
const previewData = computed(() => {
|
||||
if (Object.keys(fieldMappings.value).length === 0) return []
|
||||
|
||||
return transformDataWithMapping(
|
||||
props.csvData,
|
||||
fieldMappings.value,
|
||||
customFieldNames.value
|
||||
)
|
||||
})
|
||||
|
||||
const previewColumns = computed(() => {
|
||||
const columns = Object.keys(previewData.value[0] || {}).map(field => ({
|
||||
title: field,
|
||||
dataIndex: field,
|
||||
key: field,
|
||||
width: 150,
|
||||
ellipsis: true,
|
||||
}))
|
||||
return columns
|
||||
})
|
||||
|
||||
// 监听字段映射变化,自动生成预览
|
||||
watch([fieldMappings, customFieldNames], () => {
|
||||
// 预览数据会自动更新
|
||||
}, { deep: true })
|
||||
|
||||
// 导出JSON
|
||||
const handleExport = () => {
|
||||
if (previewData.value.length === 0) {
|
||||
message.warning('请先配置字段映射')
|
||||
return
|
||||
}
|
||||
|
||||
const exportData = generateExportData(
|
||||
previewData.value,
|
||||
fieldMappings.value,
|
||||
customFieldNames.value
|
||||
)
|
||||
|
||||
// 使用工具函数下载JSON
|
||||
downloadJSON(exportData)
|
||||
|
||||
message.success('JSON文件导出成功')
|
||||
emit('confirm', exportData)
|
||||
}
|
||||
|
||||
// 导入h函数
|
||||
import { h } from 'vue'
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.ant-table-tbody > tr > td {
|
||||
padding: 8px 12px;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,355 @@
|
||||
<template>
|
||||
<div class="p-6">
|
||||
<VbenCard title="电商数据导入" class="mb-6">
|
||||
<div class="space-y-6">
|
||||
<!-- 文件拖拽上传区域 -->
|
||||
<div
|
||||
class="border-2 border-dashed border-gray-300 rounded-lg p-8 text-center transition-colors"
|
||||
:class="{ 'border-blue-500 bg-blue-50': isDragOver }"
|
||||
@dragover.prevent="handleDragOver"
|
||||
@dragleave.prevent="handleDragLeave"
|
||||
@drop.prevent="handleDrop"
|
||||
>
|
||||
<div class="space-y-4">
|
||||
<VbenIcon icon="lucide:upload" class="w-12 h-12 mx-auto text-gray-400" />
|
||||
<div>
|
||||
<p class="text-lg font-medium text-gray-700">拖拽CSV文件到此处或点击上传</p>
|
||||
<p class="text-sm text-gray-500">支持.csv格式,最大10MB</p>
|
||||
</div>
|
||||
<VbenButton @click="triggerFileInput" type="primary" ghost>
|
||||
选择文件
|
||||
</VbenButton>
|
||||
</div>
|
||||
<input
|
||||
ref="fileInputRef"
|
||||
type="file"
|
||||
accept=".csv"
|
||||
style="display: none"
|
||||
@change="handleFileSelect"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- 文件信息显示 -->
|
||||
<div v-if="uploadedFile" class="bg-green-50 border border-green-200 rounded-lg p-4">
|
||||
<div class="flex items-center justify-between">
|
||||
<div class="flex items-center space-x-2">
|
||||
<VbenIcon icon="lucide:check-circle" class="w-5 h-5 text-green-500" />
|
||||
<span class="font-medium text-green-800">文件上传成功</span>
|
||||
</div>
|
||||
<VbenButton @click="clearData" size="small" type="text" danger>
|
||||
清除数据
|
||||
</VbenButton>
|
||||
</div>
|
||||
<p class="text-sm text-green-600 mt-1">{{ uploadedFile.name }} ({{ formatFileSize(uploadedFile.size) }})</p>
|
||||
</div>
|
||||
|
||||
<!-- 数据表格 -->
|
||||
<div v-if="csvData.length > 0" class="space-y-4">
|
||||
<div class="flex items-center justify-between">
|
||||
<div class="flex items-center space-x-4">
|
||||
<h3 class="text-lg font-medium">数据预览与选择</h3>
|
||||
<div class="text-sm text-gray-500">
|
||||
共 {{ csvData.length }} 条记录,已选择 {{ selectedRows.length }} 条
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex items-center space-x-2">
|
||||
<VbenButton @click="selectAll" size="small">
|
||||
全选
|
||||
</VbenButton>
|
||||
<VbenButton @click="clearSelection" size="small">
|
||||
清空选择
|
||||
</VbenButton>
|
||||
<VbenButton @click="showFieldMapping = true" type="primary" :disabled="selectedRows.length === 0">
|
||||
配置字段映射 ({{ selectedRows.length }})
|
||||
</VbenButton>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- VxeTable 表格 -->
|
||||
<Grid
|
||||
@checkbox-change="handleCheckboxChange"
|
||||
@checkbox-all="handleCheckboxAll"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</VbenCard>
|
||||
|
||||
<!-- 字段映射弹窗 -->
|
||||
<VbenModal
|
||||
v-model:open="showFieldMapping"
|
||||
title="字段映射配置"
|
||||
width="1000px"
|
||||
:footer="null"
|
||||
>
|
||||
<FieldMapping
|
||||
:csv-headers="csvHeaders"
|
||||
:csv-data="selectedRows"
|
||||
@confirm="handleFieldMapping"
|
||||
@cancel="showFieldMapping = false"
|
||||
/>
|
||||
</VbenModal>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref } from 'vue'
|
||||
import { message } from 'ant-design-vue'
|
||||
import FieldMapping from '#/views/ecommerce/data-import/components/FieldMapping.vue'
|
||||
import { parseCSV, extractShopNameFromFilename, validateCSVData, cleanAndFormatData } from '#/utils/csv-utils'
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table'
|
||||
import type { VxeGridProps } from '#/adapter/vxe-table'
|
||||
|
||||
// 响应式数据
|
||||
const uploadedFile = ref<File | null>(null)
|
||||
const csvData = ref<any[]>([])
|
||||
const csvHeaders = ref<string[]>([])
|
||||
const showFieldMapping = ref(false)
|
||||
const isDragOver = ref(false)
|
||||
const fileInputRef = ref<HTMLInputElement>()
|
||||
const selectedRows = ref<any[]>([])
|
||||
|
||||
// VxeTable 配置
|
||||
const gridOptions: VxeGridProps<any> = {
|
||||
columns: [
|
||||
{
|
||||
type: 'checkbox',
|
||||
width: 60,
|
||||
fixed: 'left',
|
||||
},
|
||||
{
|
||||
type: 'seq',
|
||||
width: 80,
|
||||
fixed: 'left',
|
||||
title: '序号',
|
||||
},
|
||||
],
|
||||
data: [],
|
||||
height: 500,
|
||||
border: true,
|
||||
stripe: true,
|
||||
showOverflow: true,
|
||||
keepSource: true,
|
||||
checkboxConfig: {
|
||||
labelField: 'id',
|
||||
reserve: true,
|
||||
highlight: true,
|
||||
range: true,
|
||||
},
|
||||
scrollY: {
|
||||
enabled: true,
|
||||
},
|
||||
scrollX: {
|
||||
enabled: true,
|
||||
},
|
||||
}
|
||||
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
gridOptions,
|
||||
})
|
||||
|
||||
// 更新表格列配置
|
||||
const updateTableColumns = () => {
|
||||
const newColumns: any[] = [
|
||||
{
|
||||
type: 'checkbox',
|
||||
width: 60,
|
||||
fixed: 'left',
|
||||
},
|
||||
{
|
||||
type: 'seq',
|
||||
width: 80,
|
||||
fixed: 'left',
|
||||
title: '序号',
|
||||
},
|
||||
...csvHeaders.value.map((header) => ({
|
||||
field: header,
|
||||
title: header,
|
||||
width: 200,
|
||||
showOverflow: 'tooltip',
|
||||
sortable: true,
|
||||
}))
|
||||
]
|
||||
|
||||
gridApi.setGridOptions({
|
||||
columns: newColumns,
|
||||
data: csvData.value,
|
||||
})
|
||||
}
|
||||
|
||||
// 文件验证
|
||||
const validateFile = (file: File): boolean => {
|
||||
const isCSV = file.type === 'text/csv' || file.name.endsWith('.csv')
|
||||
if (!isCSV) {
|
||||
message.error('只能上传CSV格式的文件!')
|
||||
return false
|
||||
}
|
||||
|
||||
const isLt10M = file.size / 1024 / 1024 < 10
|
||||
if (!isLt10M) {
|
||||
message.error('文件大小不能超过10MB!')
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// 处理文件
|
||||
const processFile = async (file: File) => {
|
||||
if (!validateFile(file)) return
|
||||
|
||||
uploadedFile.value = file
|
||||
|
||||
try {
|
||||
// 使用工具函数解析CSV
|
||||
const result = await parseCSV(file)
|
||||
|
||||
if (result.errors.length > 0) {
|
||||
message.error('CSV文件解析失败: ' + result.errors[0].message)
|
||||
return
|
||||
}
|
||||
|
||||
// 验证数据格式
|
||||
const validation = validateCSVData(result.data)
|
||||
if (!validation.isValid) {
|
||||
message.error('数据格式验证失败: ' + validation.errors.join(', '))
|
||||
return
|
||||
}
|
||||
|
||||
// 清洗和格式化数据,并添加唯一ID
|
||||
const cleanedData = cleanAndFormatData(result.data).map((item, index) => ({
|
||||
...item,
|
||||
id: `row_${index}`,
|
||||
}))
|
||||
|
||||
csvData.value = cleanedData
|
||||
csvHeaders.value = result.headers
|
||||
selectedRows.value = []
|
||||
|
||||
// 更新表格配置
|
||||
updateTableColumns()
|
||||
|
||||
// 从文件名提取店铺名称
|
||||
const shopName = extractShopNameFromFilename(file.name)
|
||||
message.success(`成功解析 ${cleanedData.length} 条数据,店铺:${shopName}`)
|
||||
|
||||
} catch (error: any) {
|
||||
message.error('文件读取失败: ' + error.message)
|
||||
}
|
||||
}
|
||||
|
||||
// 拖拽处理
|
||||
const handleDragOver = (e: DragEvent) => {
|
||||
e.preventDefault()
|
||||
isDragOver.value = true
|
||||
}
|
||||
|
||||
const handleDragLeave = (e: DragEvent) => {
|
||||
e.preventDefault()
|
||||
isDragOver.value = false
|
||||
}
|
||||
|
||||
const handleDrop = (e: DragEvent) => {
|
||||
e.preventDefault()
|
||||
isDragOver.value = false
|
||||
|
||||
const files = e.dataTransfer?.files
|
||||
if (files && files.length > 0) {
|
||||
const file = files[0]
|
||||
if (file) {
|
||||
processFile(file)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 文件选择处理
|
||||
const triggerFileInput = () => {
|
||||
fileInputRef.value?.click()
|
||||
}
|
||||
|
||||
const handleFileSelect = (e: Event) => {
|
||||
const target = e.target as HTMLInputElement
|
||||
const files = target.files
|
||||
if (files && files.length > 0) {
|
||||
const file = files[0]
|
||||
if (file) {
|
||||
processFile(file)
|
||||
}
|
||||
}
|
||||
// 清空input值,允许重复选择同一文件
|
||||
target.value = ''
|
||||
}
|
||||
|
||||
// 表格选择处理
|
||||
const handleCheckboxChange = ({ records }: { records: any[] }) => {
|
||||
selectedRows.value = records
|
||||
}
|
||||
|
||||
const handleCheckboxAll = ({ records }: { records: any[] }) => {
|
||||
selectedRows.value = records
|
||||
}
|
||||
|
||||
// 选择操作
|
||||
const selectAll = () => {
|
||||
gridApi.grid?.setAllCheckboxRow(true)
|
||||
}
|
||||
|
||||
const clearSelection = () => {
|
||||
gridApi.grid?.clearCheckboxRow()
|
||||
}
|
||||
|
||||
// 清除数据
|
||||
const clearData = () => {
|
||||
csvData.value = []
|
||||
csvHeaders.value = []
|
||||
selectedRows.value = []
|
||||
uploadedFile.value = null
|
||||
gridApi.grid?.clearCheckboxRow()
|
||||
}
|
||||
|
||||
// 字段映射处理
|
||||
const handleFieldMapping = (mappedData: any) => {
|
||||
showFieldMapping.value = false
|
||||
// 这里可以处理映射后的数据
|
||||
console.log('映射后的数据:', mappedData)
|
||||
message.success('字段映射配置完成')
|
||||
}
|
||||
|
||||
// 格式化文件大小
|
||||
const formatFileSize = (bytes: number) => {
|
||||
if (bytes === 0) return '0 Bytes'
|
||||
const k = 1024
|
||||
const sizes = ['Bytes', 'KB', 'MB', 'GB']
|
||||
const i = Math.floor(Math.log(bytes) / Math.log(k))
|
||||
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i]
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
/* 拖拽区域样式 */
|
||||
.border-dashed {
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
.border-dashed:hover {
|
||||
border-color: #1890ff !important;
|
||||
background-color: #f0f8ff !important;
|
||||
}
|
||||
|
||||
/* VxeTable 样式调整 */
|
||||
:deep(.vxe-table) {
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
:deep(.vxe-table .vxe-header--column) {
|
||||
background-color: #fafafa;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
:deep(.vxe-table .vxe-body--row:hover) {
|
||||
background-color: #f5f5f5;
|
||||
}
|
||||
|
||||
:deep(.vxe-table .vxe-body--row.row--checked) {
|
||||
background-color: #e6f7ff;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,15 @@
|
||||
<template>
|
||||
<div class="p-6">
|
||||
<VbenCard title="店铺管理">
|
||||
<div class="text-center py-12">
|
||||
<VbenIcon icon="lucide:store" class="w-16 h-16 mx-auto text-gray-400 mb-4" />
|
||||
<h3 class="text-lg font-medium text-gray-700 mb-2">店铺管理功能</h3>
|
||||
<p class="text-gray-500">此功能正在开发中,敬请期待...</p>
|
||||
</div>
|
||||
</VbenCard>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
// 店铺管理页面占位
|
||||
</script>
|
||||
Reference in New Issue
Block a user