From 8728ae862bd765a6387376dd9ac79016d5d89f48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E5=BF=A0=E6=9E=97?= <170083662@qq.com> Date: Sun, 7 Sep 2025 10:28:42 +0800 Subject: [PATCH] =?UTF-8?q?feat(dealer/customer):=20=E9=87=8D=E6=9E=84?= =?UTF-8?q?=E6=97=A5=E6=9C=9F=E9=80=89=E6=8B=A9=E5=92=8C=E5=A4=84=E7=90=86?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 替换 DatePicker 组件为 Calendar 组件 - 优化日期格式化和解析逻辑,支持多种日期格式- 更新日期选择器的交互方式 - 调整相关组件和样式 --- config/env.ts | 2 +- src/dealer/customer/add.tsx | 125 +++++++++++++++++++++++------------- src/utils/common.ts | 4 +- src/utils/request-legacy.ts | 116 --------------------------------- 4 files changed, 82 insertions(+), 165 deletions(-) delete mode 100644 src/utils/request-legacy.ts diff --git a/config/env.ts b/config/env.ts index de8e281..c3f95e2 100644 --- a/config/env.ts +++ b/config/env.ts @@ -2,7 +2,7 @@ export const ENV_CONFIG = { // 开发环境 development: { - API_BASE_URL: 'https://cms-api.websoft.top/api', + API_BASE_URL: 'http://127.0.0.1:9200/api', APP_NAME: '开发环境', DEBUG: 'true', }, diff --git a/src/dealer/customer/add.tsx b/src/dealer/customer/add.tsx index 22143be..809b393 100644 --- a/src/dealer/customer/add.tsx +++ b/src/dealer/customer/add.tsx @@ -1,6 +1,6 @@ import {useEffect, useState, useRef} from "react"; -import {Loading, CellGroup, Cell, Input, Form, DatePicker, Popup} from '@nutui/nutui-react-taro' -import {Edit, Calendar} from '@nutui/icons-react-taro' +import {Loading, CellGroup, Cell, Input, Form, Calendar} from '@nutui/nutui-react-taro' +import {Edit, Calendar as CalendarIcon} from '@nutui/icons-react-taro' import Taro from '@tarojs/taro' import {useRouter} from '@tarojs/taro' import {View,Text} from '@tarojs/components' @@ -41,22 +41,67 @@ const AddShopDealerApply = () => { } } - // 格式化日期为 YYYY-MM-DD - const formatDate = (date: Date): string => { - const year = date.getFullYear() - const month = String(date.getMonth() + 1).padStart(2, '0') - const day = String(date.getDate()).padStart(2, '0') - return `${year}-${month}-${day}` + // 格式化日期为数据库格式 YYYY-MM-DD HH:mm:ss + const formatDateForDatabase = (dateStr: string): string => { + if (!dateStr) return '' + + let parts: string[] = [] + + // 处理不同的日期格式 + if (dateStr.includes('/')) { + // 处理 YYYY/MM/DD 或 YYYY/M/D 格式 + parts = dateStr.split('/') + } else if (dateStr.includes('-')) { + // 处理 YYYY-MM-DD 或 YYYY-M-D 格式 + parts = dateStr.split('-') + } else { + return dateStr + } + + if (parts.length !== 3) return dateStr + + const year = parts[0] + const month = parts[1].padStart(2, '0') + const day = parts[2].padStart(2, '0') + + return `${year}-${month}-${day} 00:00:00` + } + + // 从数据库格式提取日期部分用于显示和Calendar组件 + const extractDateFromDatabase = (dateTimeStr: string): string => { + if (!dateTimeStr) return '' + + // 处理不同的输入格式 + let dateStr = '' + if (dateTimeStr.includes(' ')) { + // 从 "YYYY-MM-DD HH:mm:ss" 格式中提取日期部分 + dateStr = dateTimeStr.split(' ')[0] + } else { + dateStr = dateTimeStr + } + + // 转换为Calendar组件需要的格式 (YYYY-M-D) + if (dateStr.includes('-')) { + const parts = dateStr.split('-') + if (parts.length === 3) { + const year = parts[0] + const month = parseInt(parts[1]).toString() // 去掉前导0 + const day = parseInt(parts[2]).toString() // 去掉前导0 + return `${year}-${month}-${day}` + } + } + + return dateStr } // 处理签约时间选择 - const handleApplyTimeConfirm = (_: any, values: Date[]) => { - const selectedDate = values[0] - const formattedDate = formatDate(selectedDate) - setApplyTime(formattedDate) + const handleApplyTimeConfirm = (param: string[]) => { + const selectedDate = param[3] // 选中的日期字符串 (YYYY-M-D) + const formattedDate = formatDateForDatabase(selectedDate) // 转换为数据库格式 + setApplyTime(selectedDate) // 保存原始格式用于显示 setShowApplyTimePicker(false) - // 更新表单数据 + // 更新表单数据(使用数据库格式) if (formRef.current) { formRef.current.setFieldsValue({ applyTime: formattedDate @@ -65,13 +110,13 @@ const AddShopDealerApply = () => { } // 处理合同日期选择 - const handleContractDateConfirm = (_: any, values: Date[]) => { - const selectedDate = values[0] - const formattedDate = formatDate(selectedDate) - setContractDate(formattedDate) + const handleContractDateConfirm = (param: string[]) => { + const selectedDate = param[3] // 选中的日期字符串 (YYYY-M-D) + const formattedDate = formatDateForDatabase(selectedDate) // 转换为数据库格式 + setContractDate(selectedDate) // 保存原始格式用于显示 setShowContractDatePicker(false) - // 更新表单数据 + // 更新表单数据(使用数据库格式) if (formRef.current) { formRef.current.setFieldsValue({ contractDate: formattedDate @@ -91,12 +136,12 @@ const AddShopDealerApply = () => { setIsEditMode(true); setExistingApply(dealerApply) - // 初始化日期数据 + // 初始化日期数据(从数据库格式转换为显示格式) if (dealerApply.applyTime) { - setApplyTime(dealerApply.applyTime) + setApplyTime(extractDateFromDatabase(dealerApply.applyTime)) } if (dealerApply.contractTime) { - setContractDate(dealerApply.contractTime) + setContractDate(extractDateFromDatabase(dealerApply.contractTime)) } Taro.setNavigationBarTitle({title: '签约'}) @@ -120,9 +165,9 @@ const AddShopDealerApply = () => { refereeId: 33534, applyStatus: 10, auditTime: undefined, - // 确保日期数据正确提交 - applyTime: applyTime || values.applyTime, - contractDate: contractDate || values.contractDate + // 确保日期数据正确提交(使用数据库格式) + applyTime: values.applyTime || (applyTime ? formatDateForDatabase(applyTime) : ''), + contractDate: values.contractDate || (contractDate ? formatDateForDatabase(contractDate) : '') }; // 如果是编辑模式,添加现有申请的id @@ -215,7 +260,7 @@ const AddShopDealerApply = () => { }} > - + {applyTime || '请选择签约时间'} @@ -232,7 +277,7 @@ const AddShopDealerApply = () => { }} > - + {contractDate || '请选择合同生效起止时间'} @@ -246,32 +291,20 @@ const AddShopDealerApply = () => { {/* 签约时间选择器 */} - setShowApplyTimePicker(false)} - > - handleApplyTimeConfirm} - onClose={() => setShowApplyTimePicker(false)} - /> - + onConfirm={handleApplyTimeConfirm} + /> {/* 合同日期选择器 */} - setShowContractDatePicker(false)} - > - handleContractDateConfirm} - onClose={() => setShowContractDatePicker(false)} - /> - + onConfirm={handleContractDateConfirm} + /> {/* 审核状态显示(仅在编辑模式下显示) */} {isEditMode && ( diff --git a/src/utils/common.ts b/src/utils/common.ts index 16c379d..e338604 100644 --- a/src/utils/common.ts +++ b/src/utils/common.ts @@ -18,7 +18,7 @@ export default function navTo(url: string, isLogin = false) { // 转base64 -export function fileToBase64(filePath) { +export function fileToBase64(filePath: string) { return new Promise((resolve) => { let fileManager = Taro.getFileSystemManager(); fileManager.readFile({ @@ -35,7 +35,7 @@ export function fileToBase64(filePath) { * 转义微信富文本图片样式 * @param htmlText */ -export function wxParse(htmlText) { +export function wxParse(htmlText: string) { // Replace tags with max-width, height and margin styles to remove spacing htmlText = htmlText.replace(/\(options: any): Promise { - const token = Taro.getStorageSync('access_token'); - const header: Record = { - 'Content-Type': 'application/json', - 'TenantId': Taro.getStorageSync('TenantId') || TenantId - }; - - if (token) { - header['Authorization'] = token; - } - - // 构建完整URL - let url = options.url; - if (url.indexOf('http') === -1) { - url = baseUrl + url; - } - - // 根据方法调用对应的新请求函数 - const method = (options.method || 'GET').toUpperCase(); - const config = { - header: { ...header, ...options.header }, - showError: false // 让API层自己处理错误 - }; - - switch (method) { - case 'GET': - return getRaw(url, null, config); - case 'POST': - return postRaw(url, options.data, config); - case 'PUT': - return putRaw(url, options.data, config); - case 'DELETE': - return delRaw(url, options.data, config); - default: - return getRaw(url, null, config); - } -} - -// 兼容旧版的便捷方法 -export function get(url: string, data?: any): Promise { - if (url.indexOf('http') === -1) { - url = baseUrl + url; - } - - if (data) { - // 处理查询参数 - if (data.params) { - // 如果data有params属性,使用params作为查询参数 - const queryString = Object.keys(data.params) - .filter(key => data.params[key] !== undefined && data.params[key] !== null) - .map(key => `${encodeURIComponent(key)}=${encodeURIComponent(data.params[key])}`) - .join('&'); - if (queryString) { - url += `?${queryString}`; - } - } else { - // 否则直接使用data作为查询参数 - const queryString = Object.keys(data) - .filter(key => data[key] !== undefined && data[key] !== null) - .map(key => `${encodeURIComponent(key)}=${encodeURIComponent(data[key])}`) - .join('&'); - if (queryString) { - url += `?${queryString}`; - } - } - } - - return getRaw(url, null, { showError: false }); -} - -export function post(url: string, data?: any): Promise { - if (url.indexOf('http') === -1) { - url = baseUrl + url; - } - return postRaw(url, data, { showError: false }); -} - -export function put(url: string, data?: any): Promise { - if (url.indexOf('http') === -1) { - url = baseUrl + url; - } - return putRaw(url, data, { showError: false }); -} - -export function del(url: string, data?: any): Promise { - if (url.indexOf('http') === -1) { - url = baseUrl + url; - } - return delRaw(url, data, { showError: false }); -} - -export default { - request, - get, - post, - put, - del -};