feat(react-web-next): 新增.editorconfig和.prettierrc配置文件,添加public/.gitkeep占位文件

This commit is contained in:
2025-09-23 10:32:35 +08:00
parent 10ddfd6f75
commit 408b500b6a
199 changed files with 16850 additions and 34874 deletions
@@ -0,0 +1,204 @@
import React, { useRef, useState } from 'react';
import { PageContainer, ProForm, ProFormSelect, ProFormText, ProTable } from '@ant-design/pro-components';
import type { ActionType } from '@ant-design/pro-components';
import { DatePicker, Form, Input, InputNumber, Modal, Select, Space, Tag, message } from 'antd';
import { PlusOutlined } from '@ant-design/icons';
import { ActionBar, GlassCard, GradientButton, SearchBarPlus } from '@/components/ui';
import { ordersApi } from '@/services/orders';
import moment from 'moment';
const { RangePicker } = DatePicker;
const COUPON_TYPES = [
{ label: '满减券', value: 1 },
{ label: '折扣券', value: 2 },
{ label: '代金券', value: 3 },
];
const STATUS_OPTIONS = [
{ label: '未使用', value: 0 },
{ label: '已使用', value: 1 },
{ label: '已过期', value: 2 },
{ label: '已作废', value: 3 },
];
const SOURCE_OPTIONS = [
{ label: '携程', value: 1 },
{ label: '后台发放', value: 2 },
];
const CouponPage: React.FC = () => {
const actionRef = useRef<ActionType>();
const [searchParams, setSearchParams] = useState<Record<string, any>>({});
const [open, setOpen] = useState(false);
const [editing, setEditing] = useState<any | null>(null);
const [form] = Form.useForm();
const columns: any[] = [
{ dataIndex: 'index', valueType: 'indexBorder', width: 48 },
{ title: '优惠券编号', dataIndex: 'couponNo', width: 160 },
{ title: '优惠券名称', dataIndex: 'couponName', width: 200 },
{ title: '类型', dataIndex: 'couponType', width: 100, render: (v: number) => COUPON_TYPES.find(i => i.value === v)?.label || '-' },
{ title: '金额/折扣', key: 'amount', width: 120, render: (_: any, r: any) => r.couponType === 2 ? `${r.discountRate}%` : `¥${r.amount}` },
{ title: '使用门槛', dataIndex: 'minAmount', width: 100, render: (v: number) => v ? `¥${v}` : '-' },
{ title: '状态', dataIndex: 'status', width: 100, render: (v: number) => { const color = v === 0 ? 'green' : v === 1 ? 'blue' : v === 2 ? 'orange' : 'red'; return <Tag color={color}>{STATUS_OPTIONS.find(i => i.value === v)?.label || '-'}</Tag>; } },
{ title: '用户手机号', dataIndex: 'userPhone', width: 140 },
{ title: '来源', dataIndex: 'source', width: 100, render: (v: number) => SOURCE_OPTIONS.find(i => i.value === v)?.label || '-' },
{ title: '有效期', key: 'validTime', width: 220, render: (_: any, r: any) => (<div><div>{r.validStartTime ? moment(r.validStartTime).format('YYYY-MM-DD HH:mm') : '-'}</div><div>~</div><div>{r.validEndTime ? moment(r.validEndTime).format('YYYY-MM-DD HH:mm') : '-'}</div></div>) },
{ title: '创建时间', dataIndex: 'createTime', valueType: 'dateTime', width: 180 },
{ title: '操作', key: 'action', width: 160, fixed: 'right', render: (_: any, record: any) => (
<Space size="small">
<a onClick={() => handleView(record)}>查看</a>
<a onClick={() => handleEdit(record)}>编辑</a>
<a style={{ color: '#1677ff' }} onClick={() => handleDelete(record)}>删除</a>
</Space>
) },
];
const handleView = (record: any) => {
setEditing(record);
form.setFieldsValue({
...record,
validTime: record.validStartTime && record.validEndTime ? [moment(record.validStartTime), moment(record.validEndTime)] : undefined,
});
setOpen(true);
};
const handleEdit = (record: any) => {
setEditing(record);
form.setFieldsValue({
...record,
validTime: record.validStartTime && record.validEndTime ? [moment(record.validStartTime), moment(record.validEndTime)] : undefined,
});
setOpen(true);
};
const handleDelete = async (record: any) => {
Modal.confirm({
title: '确认删除该优惠券?',
onOk: async () => {
const hide = message.loading('正在删除...');
try {
await ordersApi.deleteCoupon(record.id);
message.success('删除成功');
actionRef.current?.reload();
} catch (e) {
message.error('删除失败');
} finally { hide(); }
},
});
};
const handleAdd = () => {
setEditing(null);
form.resetFields();
setOpen(true);
};
return (
<PageContainer header={{ title: '优惠券管理' }}>
<SearchBarPlus
defaultCollapsed={false}
split
span={8}
onTenantChanged={() => actionRef.current?.reload()}
onFinish={async (values) => setSearchParams(values)}
>
<ProFormText name="couponNo" label="优惠券编号" />
<ProFormText name="couponName" label="优惠券名称" />
<ProFormText name="userPhone" label="手机号" />
<ProFormSelect name="couponType" label="类型" options={COUPON_TYPES} />
<ProFormSelect name="status" label="状态" options={STATUS_OPTIONS} />
<ProFormSelect name="source" label="来源" options={SOURCE_OPTIONS} />
</SearchBarPlus>
<ActionBar left={<GradientButton size="middle" type="primary" icon={<PlusOutlined />} onClick={handleAdd}>新增</GradientButton>} />
<GlassCard>
<ProTable<any>
rowKey="id"
actionRef={actionRef}
request={(p) => ordersApi.getCouponList({ ...p, ...searchParams })}
columns={columns}
scroll={{ x: 1200 }}
search={false}
pagination={{ showSizeChanger: true, showQuickJumper: true }}
toolBarRender={false}
/>
</GlassCard>
<Modal
title={editing ? '编辑优惠券' : '新增优惠券'}
open={open}
onCancel={() => setOpen(false)}
onOk={async () => {
try {
const values = await form.validateFields();
const payload: any = { ...values };
if (values.validTime && values.validTime.length === 2) {
payload.validStartTime = values.validTime[0].format('YYYY-MM-DD HH:mm:ss');
payload.validEndTime = values.validTime[1].format('YYYY-MM-DD HH:mm:ss');
}
delete payload.validTime;
const hide = message.loading('保存中...');
if (editing && editing.id) {
await ordersApi.updateCoupon(editing.id, payload);
} else {
await ordersApi.createCoupon(payload);
}
hide();
message.success('保存成功');
setOpen(false);
actionRef.current?.reload();
} catch (e) {
if ((e as any)?.errorFields) return; // 表单校验
message.error('保存失败');
}
}}
destroyOnClose
maskClosable={false}
>
<Form form={form} layout="vertical" preserve={false}>
<Form.Item name="couponName" label="优惠券名称" rules={[{ required: true, message: '请输入优惠券名称' }]}>
<Input placeholder="请输入优惠券名称" />
</Form.Item>
<Form.Item name="couponType" label="优惠券类型" rules={[{ required: true, message: '请选择优惠券类型' }]}>
<Select options={COUPON_TYPES} style={{ width: '100%' }} placeholder="请选择优惠券类型" />
</Form.Item>
<Form.Item noStyle shouldUpdate={(prev, cur) => prev.couponType !== cur.couponType}>
{({ getFieldValue }) => getFieldValue('couponType') === 2 ? (
<Form.Item name="discountRate" label="折扣率(%)" rules={[{ required: true, message: '请输入折扣率' }]}>
<InputNumber min={1} max={99} style={{ width: '100%' }} placeholder="请输入折扣率" />
</Form.Item>
) : (
<Form.Item name="amount" label="优惠券面额" rules={[{ required: true, message: '请输入优惠券面额' }]}>
<InputNumber min={0} style={{ width: '100%' }} placeholder="请输入优惠券面额" />
</Form.Item>
)}
</Form.Item>
<Form.Item name="minAmount" label="使用门槛">
<InputNumber min={0} style={{ width: '100%' }} placeholder="请输入使用门槛" />
</Form.Item>
<Form.Item name="userPhone" label="用户手机号" rules={[{ required: true, message: '请输入用户手机号' }]}>
<Input placeholder="请输入用户手机号" />
</Form.Item>
<Form.Item name="source" label="来源" rules={[{ required: true, message: '请选择来源' }]}>
<Select options={SOURCE_OPTIONS} style={{ width: '100%' }} placeholder="请选择来源" />
</Form.Item>
<Form.Item name="ctripCouponId" label="携程优惠券ID">
<Input placeholder="当来源为携程时需填写" />
</Form.Item>
<Form.Item name="validTime" label="有效期" rules={[{ required: true, message: '请选择有效期' }]}>
<RangePicker showTime format="YYYY-MM-DD HH:mm:ss" style={{ width: '100%' }} />
</Form.Item>
<Form.Item name="remark" label="备注">
<Input.TextArea rows={3} placeholder="请输入备注" />
</Form.Item>
</Form>
</Modal>
</PageContainer>
);
};
export default CouponPage;