From 61815bef45dc35851fe6485e00dc9e4402b6e8fb Mon Sep 17 00:00:00 2001 From: Joe Date: Fri, 5 Jul 2024 17:32:25 +0800 Subject: [PATCH] up --- config/routes.ts | 6 + src/access.ts | 2 + src/constants.ts | 18 + src/pages/BusinessList/add.tsx | 313 +++++++++++++++--- src/pages/BusinessList/index.tsx | 4 +- src/pages/ProductList/add.tsx | 252 ++++++++++++++ src/pages/ProductList/index.tsx | 9 +- src/services/pop-b2b2c/errorController.ts | 30 +- .../pbcBusinessApprovalController.ts | 15 + .../pop-b2b2c/pbcProductController.ts | 15 + src/services/pop-b2b2c/typings.d.ts | 2 + 11 files changed, 601 insertions(+), 65 deletions(-) create mode 100644 src/pages/ProductList/add.tsx diff --git a/config/routes.ts b/config/routes.ts index fe12c29..afc829f 100644 --- a/config/routes.ts +++ b/config/routes.ts @@ -97,6 +97,12 @@ export default [ access: 'productQuery', component: './ProductList', }, + { + name: '新增商品', + path: 'add', + hideInMenu: true, + component: './ProductList/add', + }, { name: '详情', path: 'detail/:id', diff --git a/src/access.ts b/src/access.ts index 6d11de4..3312b20 100644 --- a/src/access.ts +++ b/src/access.ts @@ -22,6 +22,7 @@ export default function access(initialState: { currentUser?: API.PbcUsersVO | un business: false, businessQuery: false, businessSave: false, + businessAdd: false, businessUpdateState: false, member: false, memberQuery: false, @@ -36,6 +37,7 @@ export default function access(initialState: { currentUser?: API.PbcUsersVO | un productCategoryDelete: false, product: false, productQuery: false, + productAdd: false, productUpdateState: false, content: false, contentQuery: false, diff --git a/src/constants.ts b/src/constants.ts index 94c51c3..c10c18b 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -92,6 +92,24 @@ const Constants = { link: '链接', share: '买家' }, + /** + * 证件类型 + */ + pbcBusinessHeadUserNoType: { + 0: '居民身份证', + 1: '港澳居民来往内地通行证', + 2: '台湾居民来往大陆通行证' + }, + // 手机正则 + PHONE_PATTERN: /^(?:(0\d{2,3}-)?\d{7,8}|1[3-9]\d{9})$/, + //邮箱正则 + EMAIL_PATTERN: /^[A-Za-z0-9\u4e00-\u9fa5._%+-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/, + // 统一社会信用代码 + USCC_PATTERN: /[^_IOZSVa-z\W]{2}\d{6}[^_IOZSVa-z\W]{10}$/, + // 身份证件号码 + IDCARD_PATTERN: /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/, + HRP_PATTERN: /^([A-Z]\d{6,10}(\(\w{1}\))?)$/, + MTP_PATTERN: /^\d{8}|^[a-zA-Z0-9]{10}|^\d{18}$/, }; export default Constants; diff --git a/src/pages/BusinessList/add.tsx b/src/pages/BusinessList/add.tsx index f2076f2..85bf785 100644 --- a/src/pages/BusinessList/add.tsx +++ b/src/pages/BusinessList/add.tsx @@ -1,51 +1,59 @@ import Constants from '@/constants'; -import { - adminChangeBusinessInfoUsingPost, - getPbcBusinessByIdUsingPost, -} from '@/services/pop-b2b2c/pbcBusinessController'; +import { addBusinessForAdminUsingPost } from '@/services/pop-b2b2c/pbcBusinessApprovalController'; import { getCities } from '@/utils/cities'; -import { CheckCircleOutlined, InfoCircleOutlined, PlusCircleOutlined } from '@ant-design/icons'; import { ProCard, - ProConfigProvider, - ProDescriptions, ProForm, ProFormCascader, ProFormDatePicker, + ProFormInstance, ProFormSelect, - ProFormSwitch, ProFormText, ProFormTextArea, ProFormUploadButton, } from '@ant-design/pro-components'; import { PageContainer } from '@ant-design/pro-layout'; -import { useAccess, useParams, useSearchParams } from '@umijs/max'; -import { Button, Col, Image, message, Row, Tag } from 'antd'; -import { RcFile } from 'antd/es/upload'; -import React, { useEffect, useState } from 'react'; +import { Button, Col, message, Row } from 'antd'; +import Upload, { RcFile } from 'antd/es/upload'; +import moment from 'moment'; +import React, { useRef, useState } from 'react'; const Detail: React.FC = () => { - const params = useParams(); - const [searchParams] = useSearchParams(); - const access: any = useAccess(); - const isEdit = searchParams.get('isEdit') === '1'; const [cities] = useState(() => getCities()) - const [info, setInfo] = useState({}); + const formRef = useRef(); - const getInfo = () => { - if (params.id) { - getPbcBusinessByIdUsingPost({ pbcId: parseInt(params.id) }).then((res) => { - if (res.retcode && res.data) { - setInfo(res.data); - } - }); - } - }; + const onSave = () => { + formRef.current?.submit() + } - useEffect(() => { - getInfo(); - }, []); + const onSubmit = async (values: any) => { + const [pbcBusinessProvince, pbcBusinessCity, pbcBusinessArea] = values.pbcZone; + const params: API.PbcBusinessDTO = { + ...values, + pbcState: values.pbcState ? 1 : 0, + pbcBusinessProvince, + pbcBusinessCity, + pbcBusinessArea, + pbcBusinessStartDate: moment(values.pbcBusinessStartDate, 'YYYY-MM-DD'), + pbcBusinessLogo: values.pbcBusinessLogo.filter((e: any) => e.response && e.response.data).map((e: any) => e.response.data).join(','), + pbcBusinessImage: values.pbcBusinessImage.filter((e: any) => e.response && e.response.data).map((e: any) => e.response.data).join(','), + pbcBusinessPosterUrl: values.pbcBusinessPosterUrl.filter((e: any) => e.response && e.response.data).map((e: any) => e.response.data).join(','), + pbcBusinessHeadUserNoBackUrl: values.pbcBusinessHeadUserNoBackUrl.filter((e: any) => e.response && e.response.data).map((e: any) => e.response.data).join(','), + pbcBusinessHeadUserNoFrontUrl: values.pbcBusinessHeadUserNoFrontUrl.filter((e: any) => e.response && e.response.data).map((e: any) => e.response.data).join(','), + pbcBusinessLicenseUrl: values.pbcBusinessLicenseUrl.filter((e: any) => e.response && e.response.data).map((e: any) => e.response.data).join(','), + pbcZone: undefined + } + const msg = await addBusinessForAdminUsingPost(params) + if (msg.retcode) { + message.success("创建成功!") + history.back(); + return true + } else { + message.error(msg.retmsg) + return false + } + } return ( = () => { > 返回 , - ]} > - + - + - + - + {/* - + */} - + - + @@ -92,18 +109,27 @@ const Detail: React.FC = () => { - + - + - + - + @@ -116,8 +142,32 @@ const Detail: React.FC = () => { name="pbcBusinessLogo" fieldProps={{ name: 'file', + accept: 'image/*', + headers: { + authorization: localStorage.getItem('token') ?? '', + }, + action: '/oss/imgUpload', + beforeUpload(file: RcFile) { + const isLt2M = file.size / 1024 / 1024 < 10; + if (!isLt2M) { + message.error('图片大小不能超过10MB!'); + } + return isLt2M || Upload.LIST_IGNORE; + }, + onPreview: async (file) => { + + if (file.uid === '-1') { + window.open(file.url); + } + if (file.response && file.response.retcode) { + window.open(file.response.data); + } + }, listType: 'picture-card', }} + rules={[ + { required: true, message: '请上传商户LOGO' }, + ]} max={1} /> @@ -129,8 +179,32 @@ const Detail: React.FC = () => { name="pbcBusinessImage" fieldProps={{ name: 'file', + accept: 'image/*', + headers: { + authorization: localStorage.getItem('token') ?? '', + }, + action: '/oss/imgUpload', + beforeUpload(file: RcFile) { + const isLt2M = file.size / 1024 / 1024 < 10; + if (!isLt2M) { + message.error('图片大小不能超过10MB!'); + } + return isLt2M || Upload.LIST_IGNORE; + }, + onPreview: async (file) => { + + if (file.uid === '-1') { + window.open(file.url); + } + if (file.response && file.response.retcode) { + window.open(file.response.data); + } + }, listType: 'picture-card', }} + rules={[ + { required: true, message: '请上传商户图片' }, + ]} /> @@ -141,8 +215,32 @@ const Detail: React.FC = () => { name="pbcBusinessPosterUrl" fieldProps={{ name: 'file', + accept: 'image/*', + headers: { + authorization: localStorage.getItem('token') ?? '', + }, + action: '/oss/imgUpload', + beforeUpload(file: RcFile) { + const isLt2M = file.size / 1024 / 1024 < 10; + if (!isLt2M) { + message.error('图片大小不能超过10MB!'); + } + return isLt2M || Upload.LIST_IGNORE; + }, + onPreview: async (file) => { + + if (file.uid === '-1') { + window.open(file.url); + } + if (file.response && file.response.retcode) { + window.open(file.response.data); + } + }, listType: 'picture-card', }} + rules={[ + { required: true, message: '请上传商户海报' }, + ]} /> @@ -150,24 +248,69 @@ const Detail: React.FC = () => { - + - + + + + + + + + + { + if (e) { + const values = formRef.current?.getFieldsValue() + formRef.current?.setFieldsValue({...values, pbcBusinessHeadUserNo: null, pbcBusinessHeadUserNoBackUrl: null, pbcBusinessHeadUserNoFrontUrl: null}) + } + }} /> - + { + if (!value) return Promise.resolve() + const pbcBusinessHeadUserNoType = parseInt(formRef.current?.getFieldValue("pbcBusinessHeadUserNoType")) + let flag = false + if (pbcBusinessHeadUserNoType === 0) { + flag = Constants.IDCARD_PATTERN.test(value) + } else if (pbcBusinessHeadUserNoType === 1) { + flag = Constants.HRP_PATTERN.test(value) + } else if (pbcBusinessHeadUserNoType === 2) { + flag = Constants.MTP_PATTERN.test(value) + } + return flag ? Promise.resolve() : Promise.reject(`请输入合法的身份号码`) + } + }, + ]} /> - + - + - + @@ -177,9 +320,33 @@ const Detail: React.FC = () => { name="pbcBusinessHeadUserNoBackUrl" fieldProps={{ name: 'file', + accept: 'image/*', + headers: { + authorization: localStorage.getItem('token') ?? '', + }, + action: '/oss/imgUpload', + beforeUpload(file: RcFile) { + const isLt2M = file.size / 1024 / 1024 < 10; + if (!isLt2M) { + message.error('图片大小不能超过10MB!'); + } + return isLt2M || Upload.LIST_IGNORE; + }, + onPreview: async (file) => { + + if (file.uid === '-1') { + window.open(file.url); + } + if (file.response && file.response.retcode) { + window.open(file.response.data); + } + }, listType: 'picture-card', }} max={1} + rules={[ + { required: true, message: '请上传身份证人像面' }, + ]} /> @@ -188,16 +355,42 @@ const Detail: React.FC = () => { name="pbcBusinessHeadUserNoFrontUrl" fieldProps={{ name: 'file', + accept: 'image/*', + headers: { + authorization: localStorage.getItem('token') ?? '', + }, + action: '/oss/imgUpload', + beforeUpload(file: RcFile) { + const isLt2M = file.size / 1024 / 1024 < 10; + if (!isLt2M) { + message.error('图片大小不能超过10MB!'); + } + return isLt2M || Upload.LIST_IGNORE; + }, + onPreview: async (file) => { + + if (file.uid === '-1') { + window.open(file.url); + } + if (file.response && file.response.retcode) { + window.open(file.response.data); + } + }, listType: 'picture-card', }} max={1} + rules={[ + { required: true, message: '请上传身份证国徽面' }, + ]} /> - + @@ -207,8 +400,32 @@ const Detail: React.FC = () => { name="pbcBusinessLicenseUrl" fieldProps={{ name: 'file', + accept: 'image/*', + headers: { + authorization: localStorage.getItem('token') ?? '', + }, + action: '/oss/imgUpload', + beforeUpload(file: RcFile) { + const isLt2M = file.size / 1024 / 1024 < 10; + if (!isLt2M) { + message.error('图片大小不能超过10MB!'); + } + return isLt2M || Upload.LIST_IGNORE; + }, + onPreview: async (file) => { + + if (file.uid === '-1') { + window.open(file.url); + } + if (file.response && file.response.retcode) { + window.open(file.response.data); + } + }, listType: 'picture-card', }} + rules={[ + { required: true, message: '请上传营业执照' }, + ]} /> diff --git a/src/pages/BusinessList/index.tsx b/src/pages/BusinessList/index.tsx index 6f7f447..63c1ad7 100644 --- a/src/pages/BusinessList/index.tsx +++ b/src/pages/BusinessList/index.tsx @@ -174,7 +174,9 @@ const TableList: React.FC<{}> = () => { }} toolbar={{ actions: [ - + + + ] }} pagination={{ diff --git a/src/pages/ProductList/add.tsx b/src/pages/ProductList/add.tsx new file mode 100644 index 0000000..2569120 --- /dev/null +++ b/src/pages/ProductList/add.tsx @@ -0,0 +1,252 @@ +import Constants from '@/constants'; +import { addOrUpdateProductForAdminUsingPost } from '@/services/pop-b2b2c/pbcProductController'; +import { getCities } from '@/utils/cities'; +import { + ProCard, + ProForm, + ProFormCascader, + ProFormInstance, + ProFormSelect, + ProFormText, + ProFormTextArea, + ProFormUploadButton, +} from '@ant-design/pro-components'; +import { PageContainer } from '@ant-design/pro-layout'; +import { Button, Col, message, Row } from 'antd'; +import Upload, { RcFile } from 'antd/es/upload'; +import moment from 'moment'; +import React, { useRef, useState } from 'react'; + +const Detail: React.FC = () => { + const [cities] = useState(() => getCities()) + + const formRef = useRef(); + + const onSave = () => { + formRef.current?.submit() + } + + const onSubmit = async (values: any) => { + const [pbcBusinessProvince, pbcBusinessCity, pbcBusinessArea] = values.pbcZone; + const params: API.PbcProductDTO = { + ...values, + pbcState: values.pbcState ? 1 : 0, + pbcBusinessProvince, + pbcBusinessCity, + pbcBusinessArea, + pbcBusinessStartDate: moment(values.pbcBusinessStartDate, 'YYYY-MM-DD'), + pbcBusinessLogo: values.pbcBusinessLogo.filter((e: any) => e.response && e.response.data).map((e: any) => e.response.data).join(','), + pbcBusinessImage: values.pbcBusinessImage.filter((e: any) => e.response && e.response.data).map((e: any) => e.response.data).join(','), + pbcBusinessPosterUrl: values.pbcBusinessPosterUrl.filter((e: any) => e.response && e.response.data).map((e: any) => e.response.data).join(','), + pbcBusinessHeadUserNoBackUrl: values.pbcBusinessHeadUserNoBackUrl.filter((e: any) => e.response && e.response.data).map((e: any) => e.response.data).join(','), + pbcBusinessHeadUserNoFrontUrl: values.pbcBusinessHeadUserNoFrontUrl.filter((e: any) => e.response && e.response.data).map((e: any) => e.response.data).join(','), + pbcBusinessLicenseUrl: values.pbcBusinessLicenseUrl.filter((e: any) => e.response && e.response.data).map((e: any) => e.response.data).join(','), + pbcZone: undefined + } + const msg = await addOrUpdateProductForAdminUsingPost(params) + if (msg.retcode) { + message.success("创建成功!") + history.back(); + return true + } else { + message.error(msg.retmsg) + return false + } + } + + return ( + { + history.back(); + }} + > + 返回 + , + + ]} + > + + + + + + + + + + {/* + + */} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + { + + if (file.uid === '-1') { + window.open(file.url); + } + if (file.response && file.response.retcode) { + window.open(file.response.data); + } + }, + listType: 'picture-card', + }} + rules={[ + { required: true, message: '请上传商户LOGO' }, + ]} + max={1} + /> + + + + + { + + if (file.uid === '-1') { + window.open(file.url); + } + if (file.response && file.response.retcode) { + window.open(file.response.data); + } + }, + listType: 'picture-card', + }} + rules={[ + { required: true, message: '请上传商户图片' }, + ]} + /> + + + + + { + + if (file.uid === '-1') { + window.open(file.url); + } + if (file.response && file.response.retcode) { + window.open(file.response.data); + } + }, + listType: 'picture-card', + }} + rules={[ + { required: true, message: '请上传商户海报' }, + ]} + /> + + + + + + ); +}; + +export default Detail; diff --git a/src/pages/ProductList/index.tsx b/src/pages/ProductList/index.tsx index b2ba960..d23eead 100644 --- a/src/pages/ProductList/index.tsx +++ b/src/pages/ProductList/index.tsx @@ -7,7 +7,7 @@ import { } from '@/services/pop-b2b2c/pbcProductController'; import { ActionType, ProColumns, ProTable } from '@ant-design/pro-components'; import { PageContainer } from '@ant-design/pro-layout'; -import { Access, Link, useAccess } from '@umijs/max'; +import { Access, Link, useAccess, history } from '@umijs/max'; import { Button, message } from 'antd'; import React, { useRef } from 'react'; @@ -176,6 +176,13 @@ const TableList: React.FC<{}> = () => { defaultPageSize: 20, showSizeChanger: true, }} + toolbar={{ + actions: [ + + + + ] + }} scroll={{ y: 'calc(100vh - 320px)', }} diff --git a/src/services/pop-b2b2c/errorController.ts b/src/services/pop-b2b2c/errorController.ts index f29cc7f..5f0967b 100644 --- a/src/services/pop-b2b2c/errorController.ts +++ b/src/services/pop-b2b2c/errorController.ts @@ -2,41 +2,41 @@ /* eslint-disable */ import request from '@/utils/request'; -/** error GET /error */ -export async function errorUsingGet(options?: { [key: string]: any }) { - return request>('/error', { +/** errorHtml GET /error */ +export async function errorHtmlUsingGet(options?: { [key: string]: any }) { + return request('/error', { method: 'GET', ...(options || {}), }); } -/** error PUT /error */ -export async function errorUsingPut(options?: { [key: string]: any }) { - return request>('/error', { +/** errorHtml PUT /error */ +export async function errorHtmlUsingPut(options?: { [key: string]: any }) { + return request('/error', { method: 'PUT', ...(options || {}), }); } -/** error POST /error */ -export async function errorUsingPost(options?: { [key: string]: any }) { - return request>('/error', { +/** errorHtml POST /error */ +export async function errorHtmlUsingPost(options?: { [key: string]: any }) { + return request('/error', { method: 'POST', ...(options || {}), }); } -/** error DELETE /error */ -export async function errorUsingDelete(options?: { [key: string]: any }) { - return request>('/error', { +/** errorHtml DELETE /error */ +export async function errorHtmlUsingDelete(options?: { [key: string]: any }) { + return request('/error', { method: 'DELETE', ...(options || {}), }); } -/** error PATCH /error */ -export async function errorUsingPatch(options?: { [key: string]: any }) { - return request>('/error', { +/** errorHtml PATCH /error */ +export async function errorHtmlUsingPatch(options?: { [key: string]: any }) { + return request('/error', { method: 'PATCH', ...(options || {}), }); diff --git a/src/services/pop-b2b2c/pbcBusinessApprovalController.ts b/src/services/pop-b2b2c/pbcBusinessApprovalController.ts index 5051bbe..b0e0c03 100644 --- a/src/services/pop-b2b2c/pbcBusinessApprovalController.ts +++ b/src/services/pop-b2b2c/pbcBusinessApprovalController.ts @@ -2,6 +2,21 @@ /* eslint-disable */ import request from '@/utils/request'; +/** addBusinessForAdmin 管理员后台新增商户 POST /b2b2c/pbcbusinessapproval/addBusinessForAdmin */ +export async function addBusinessForAdminUsingPost( + body: API.PbcBusinessDTO, + options?: { [key: string]: any }, +) { + return request('/b2b2c/pbcbusinessapproval/addBusinessForAdmin', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + data: body, + ...(options || {}), + }); +} + /** addBusinessApproval 商家新增或者修改认证申请 POST /b2b2c/pbcbusinessapproval/addorupdatebusinessapproval */ export async function addBusinessApprovalUsingPost( body: API.PbcBusinessDTO, diff --git a/src/services/pop-b2b2c/pbcProductController.ts b/src/services/pop-b2b2c/pbcProductController.ts index db83960..a64f22b 100644 --- a/src/services/pop-b2b2c/pbcProductController.ts +++ b/src/services/pop-b2b2c/pbcProductController.ts @@ -17,6 +17,21 @@ export async function addOrUpdateProductUsingPost( }); } +/** 管理员新增或者修改商品 管理员接口 POST /b2b2c/pbcproduct/api/addOrUpdateProductForAdmin */ +export async function addOrUpdateProductForAdminUsingPost( + body: API.PbcProductDTO, + options?: { [key: string]: any }, +) { + return request('/b2b2c/pbcproduct/api/addOrUpdateProductForAdmin', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + data: body, + ...(options || {}), + }); +} + /** 更改商品状态,state 1是上架,2是下架,3是待审核,4是审核失败 更改商品状态 GET /b2b2c/pbcproduct/api/changeproductstate */ export async function changeProductStateForAdminUsingGet( // 叠加生成的Param类型 (非body参数swagger默认没有生成对象) diff --git a/src/services/pop-b2b2c/typings.d.ts b/src/services/pop-b2b2c/typings.d.ts index 0608469..6c33d4e 100644 --- a/src/services/pop-b2b2c/typings.d.ts +++ b/src/services/pop-b2b2c/typings.d.ts @@ -1637,6 +1637,8 @@ declare namespace API { pageSize?: number; /** 商户id */ pbcBusinessId?: number; + /** 商户名称 */ + pbcBusinessName?: string; /** 主键 */ pbcId?: number; /** 商品细分类id,也就是三级类目id */