feat(dealer/customer): 重构日期选择和处理逻辑
- 替换 DatePicker 组件为 Calendar 组件 - 优化日期格式化和解析逻辑,支持多种日期格式- 更新日期选择器的交互方式 - 调整相关组件和样式
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
export const ENV_CONFIG = {
|
export const ENV_CONFIG = {
|
||||||
// 开发环境
|
// 开发环境
|
||||||
development: {
|
development: {
|
||||||
API_BASE_URL: 'https://cms-api.websoft.top/api',
|
API_BASE_URL: 'http://127.0.0.1:9200/api',
|
||||||
APP_NAME: '开发环境',
|
APP_NAME: '开发环境',
|
||||||
DEBUG: 'true',
|
DEBUG: 'true',
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import {useEffect, useState, useRef} from "react";
|
import {useEffect, useState, useRef} from "react";
|
||||||
import {Loading, CellGroup, Cell, Input, Form, DatePicker, Popup} from '@nutui/nutui-react-taro'
|
import {Loading, CellGroup, Cell, Input, Form, Calendar} from '@nutui/nutui-react-taro'
|
||||||
import {Edit, Calendar} from '@nutui/icons-react-taro'
|
import {Edit, Calendar as CalendarIcon} from '@nutui/icons-react-taro'
|
||||||
import Taro from '@tarojs/taro'
|
import Taro from '@tarojs/taro'
|
||||||
import {useRouter} from '@tarojs/taro'
|
import {useRouter} from '@tarojs/taro'
|
||||||
import {View,Text} from '@tarojs/components'
|
import {View,Text} from '@tarojs/components'
|
||||||
@@ -41,22 +41,67 @@ const AddShopDealerApply = () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 格式化日期为 YYYY-MM-DD
|
// 格式化日期为数据库格式 YYYY-MM-DD HH:mm:ss
|
||||||
const formatDate = (date: Date): string => {
|
const formatDateForDatabase = (dateStr: string): string => {
|
||||||
const year = date.getFullYear()
|
if (!dateStr) return ''
|
||||||
const month = String(date.getMonth() + 1).padStart(2, '0')
|
|
||||||
const day = String(date.getDate()).padStart(2, '0')
|
let parts: string[] = []
|
||||||
return `${year}-${month}-${day}`
|
|
||||||
|
// 处理不同的日期格式
|
||||||
|
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 handleApplyTimeConfirm = (param: string[]) => {
|
||||||
const selectedDate = values[0]
|
const selectedDate = param[3] // 选中的日期字符串 (YYYY-M-D)
|
||||||
const formattedDate = formatDate(selectedDate)
|
const formattedDate = formatDateForDatabase(selectedDate) // 转换为数据库格式
|
||||||
setApplyTime(formattedDate)
|
setApplyTime(selectedDate) // 保存原始格式用于显示
|
||||||
setShowApplyTimePicker(false)
|
setShowApplyTimePicker(false)
|
||||||
|
|
||||||
// 更新表单数据
|
// 更新表单数据(使用数据库格式)
|
||||||
if (formRef.current) {
|
if (formRef.current) {
|
||||||
formRef.current.setFieldsValue({
|
formRef.current.setFieldsValue({
|
||||||
applyTime: formattedDate
|
applyTime: formattedDate
|
||||||
@@ -65,13 +110,13 @@ const AddShopDealerApply = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 处理合同日期选择
|
// 处理合同日期选择
|
||||||
const handleContractDateConfirm = (_: any, values: Date[]) => {
|
const handleContractDateConfirm = (param: string[]) => {
|
||||||
const selectedDate = values[0]
|
const selectedDate = param[3] // 选中的日期字符串 (YYYY-M-D)
|
||||||
const formattedDate = formatDate(selectedDate)
|
const formattedDate = formatDateForDatabase(selectedDate) // 转换为数据库格式
|
||||||
setContractDate(formattedDate)
|
setContractDate(selectedDate) // 保存原始格式用于显示
|
||||||
setShowContractDatePicker(false)
|
setShowContractDatePicker(false)
|
||||||
|
|
||||||
// 更新表单数据
|
// 更新表单数据(使用数据库格式)
|
||||||
if (formRef.current) {
|
if (formRef.current) {
|
||||||
formRef.current.setFieldsValue({
|
formRef.current.setFieldsValue({
|
||||||
contractDate: formattedDate
|
contractDate: formattedDate
|
||||||
@@ -91,12 +136,12 @@ const AddShopDealerApply = () => {
|
|||||||
setIsEditMode(true);
|
setIsEditMode(true);
|
||||||
setExistingApply(dealerApply)
|
setExistingApply(dealerApply)
|
||||||
|
|
||||||
// 初始化日期数据
|
// 初始化日期数据(从数据库格式转换为显示格式)
|
||||||
if (dealerApply.applyTime) {
|
if (dealerApply.applyTime) {
|
||||||
setApplyTime(dealerApply.applyTime)
|
setApplyTime(extractDateFromDatabase(dealerApply.applyTime))
|
||||||
}
|
}
|
||||||
if (dealerApply.contractTime) {
|
if (dealerApply.contractTime) {
|
||||||
setContractDate(dealerApply.contractTime)
|
setContractDate(extractDateFromDatabase(dealerApply.contractTime))
|
||||||
}
|
}
|
||||||
|
|
||||||
Taro.setNavigationBarTitle({title: '签约'})
|
Taro.setNavigationBarTitle({title: '签约'})
|
||||||
@@ -120,9 +165,9 @@ const AddShopDealerApply = () => {
|
|||||||
refereeId: 33534,
|
refereeId: 33534,
|
||||||
applyStatus: 10,
|
applyStatus: 10,
|
||||||
auditTime: undefined,
|
auditTime: undefined,
|
||||||
// 确保日期数据正确提交
|
// 确保日期数据正确提交(使用数据库格式)
|
||||||
applyTime: applyTime || values.applyTime,
|
applyTime: values.applyTime || (applyTime ? formatDateForDatabase(applyTime) : ''),
|
||||||
contractDate: contractDate || values.contractDate
|
contractDate: values.contractDate || (contractDate ? formatDateForDatabase(contractDate) : '')
|
||||||
};
|
};
|
||||||
|
|
||||||
// 如果是编辑模式,添加现有申请的id
|
// 如果是编辑模式,添加现有申请的id
|
||||||
@@ -215,7 +260,7 @@ const AddShopDealerApply = () => {
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<View className="flex items-center">
|
<View className="flex items-center">
|
||||||
<Calendar size={16} color="#999" className="mr-2" />
|
<CalendarIcon size={16} color="#999" className="mr-2" />
|
||||||
<Text style={{ color: applyTime ? '#333' : '#999' }}>
|
<Text style={{ color: applyTime ? '#333' : '#999' }}>
|
||||||
{applyTime || '请选择签约时间'}
|
{applyTime || '请选择签约时间'}
|
||||||
</Text>
|
</Text>
|
||||||
@@ -232,7 +277,7 @@ const AddShopDealerApply = () => {
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<View className="flex items-center">
|
<View className="flex items-center">
|
||||||
<Calendar size={16} color="#999" className="mr-2" />
|
<CalendarIcon size={16} color="#999" className="mr-2" />
|
||||||
<Text style={{ color: contractDate ? '#333' : '#999' }}>
|
<Text style={{ color: contractDate ? '#333' : '#999' }}>
|
||||||
{contractDate || '请选择合同生效起止时间'}
|
{contractDate || '请选择合同生效起止时间'}
|
||||||
</Text>
|
</Text>
|
||||||
@@ -246,32 +291,20 @@ const AddShopDealerApply = () => {
|
|||||||
</Form>
|
</Form>
|
||||||
|
|
||||||
{/* 签约时间选择器 */}
|
{/* 签约时间选择器 */}
|
||||||
<Popup
|
<Calendar
|
||||||
visible={showApplyTimePicker}
|
visible={showApplyTimePicker}
|
||||||
position="bottom"
|
defaultValue={applyTime}
|
||||||
onClose={() => setShowApplyTimePicker(false)}
|
onClose={() => setShowApplyTimePicker(false)}
|
||||||
>
|
onConfirm={handleApplyTimeConfirm}
|
||||||
<DatePicker
|
/>
|
||||||
title="选择签约时间"
|
|
||||||
type="date"
|
|
||||||
onConfirm={() => handleApplyTimeConfirm}
|
|
||||||
onClose={() => setShowApplyTimePicker(false)}
|
|
||||||
/>
|
|
||||||
</Popup>
|
|
||||||
|
|
||||||
{/* 合同日期选择器 */}
|
{/* 合同日期选择器 */}
|
||||||
<Popup
|
<Calendar
|
||||||
visible={showContractDatePicker}
|
visible={showContractDatePicker}
|
||||||
position="bottom"
|
defaultValue={contractDate}
|
||||||
onClose={() => setShowContractDatePicker(false)}
|
onClose={() => setShowContractDatePicker(false)}
|
||||||
>
|
onConfirm={handleContractDateConfirm}
|
||||||
<DatePicker
|
/>
|
||||||
title="选择合同日期"
|
|
||||||
type="date"
|
|
||||||
onConfirm={() => handleContractDateConfirm}
|
|
||||||
onClose={() => setShowContractDatePicker(false)}
|
|
||||||
/>
|
|
||||||
</Popup>
|
|
||||||
|
|
||||||
{/* 审核状态显示(仅在编辑模式下显示) */}
|
{/* 审核状态显示(仅在编辑模式下显示) */}
|
||||||
{isEditMode && (
|
{isEditMode && (
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ export default function navTo(url: string, isLogin = false) {
|
|||||||
|
|
||||||
|
|
||||||
// 转base64
|
// 转base64
|
||||||
export function fileToBase64(filePath) {
|
export function fileToBase64(filePath: string) {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
let fileManager = Taro.getFileSystemManager();
|
let fileManager = Taro.getFileSystemManager();
|
||||||
fileManager.readFile({
|
fileManager.readFile({
|
||||||
@@ -35,7 +35,7 @@ export function fileToBase64(filePath) {
|
|||||||
* 转义微信富文本图片样式
|
* 转义微信富文本图片样式
|
||||||
* @param htmlText
|
* @param htmlText
|
||||||
*/
|
*/
|
||||||
export function wxParse(htmlText) {
|
export function wxParse(htmlText: string) {
|
||||||
// Replace <img> tags with max-width, height and margin styles to remove spacing
|
// Replace <img> tags with max-width, height and margin styles to remove spacing
|
||||||
htmlText = htmlText.replace(/\<img/gi, '<img style="max-width:100%;height:auto;margin:0;padding:0;display:block;"');
|
htmlText = htmlText.replace(/\<img/gi, '<img style="max-width:100%;height:auto;margin:0;padding:0;display:block;"');
|
||||||
|
|
||||||
|
|||||||
@@ -1,116 +0,0 @@
|
|||||||
/**
|
|
||||||
* 兼容旧版API的请求工具
|
|
||||||
* 这个文件是为了保持向后兼容性,让现有的API代码能够正常工作
|
|
||||||
* 逐步迁移完成后可以删除此文件
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { getRaw, postRaw, putRaw, delRaw } from './request';
|
|
||||||
import { BaseUrl, TenantId } from "@/config/app";
|
|
||||||
import Taro from '@tarojs/taro';
|
|
||||||
|
|
||||||
let baseUrl = BaseUrl;
|
|
||||||
|
|
||||||
// 开发环境
|
|
||||||
if (process.env.NODE_ENV === 'development') {
|
|
||||||
// baseUrl = 'http://localhost:9200/api'
|
|
||||||
}
|
|
||||||
|
|
||||||
// 兼容旧版的request函数
|
|
||||||
export function request<T>(options: any): Promise<T> {
|
|
||||||
const token = Taro.getStorageSync('access_token');
|
|
||||||
const header: Record<string, string> = {
|
|
||||||
'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<T>(url, null, config);
|
|
||||||
case 'POST':
|
|
||||||
return postRaw<T>(url, options.data, config);
|
|
||||||
case 'PUT':
|
|
||||||
return putRaw<T>(url, options.data, config);
|
|
||||||
case 'DELETE':
|
|
||||||
return delRaw<T>(url, options.data, config);
|
|
||||||
default:
|
|
||||||
return getRaw<T>(url, null, config);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 兼容旧版的便捷方法
|
|
||||||
export function get<T>(url: string, data?: any): Promise<T> {
|
|
||||||
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<T>(url, null, { showError: false });
|
|
||||||
}
|
|
||||||
|
|
||||||
export function post<T>(url: string, data?: any): Promise<T> {
|
|
||||||
if (url.indexOf('http') === -1) {
|
|
||||||
url = baseUrl + url;
|
|
||||||
}
|
|
||||||
return postRaw<T>(url, data, { showError: false });
|
|
||||||
}
|
|
||||||
|
|
||||||
export function put<T>(url: string, data?: any): Promise<T> {
|
|
||||||
if (url.indexOf('http') === -1) {
|
|
||||||
url = baseUrl + url;
|
|
||||||
}
|
|
||||||
return putRaw<T>(url, data, { showError: false });
|
|
||||||
}
|
|
||||||
|
|
||||||
export function del<T>(url: string, data?: any): Promise<T> {
|
|
||||||
if (url.indexOf('http') === -1) {
|
|
||||||
url = baseUrl + url;
|
|
||||||
}
|
|
||||||
return delRaw<T>(url, data, { showError: false });
|
|
||||||
}
|
|
||||||
|
|
||||||
export default {
|
|
||||||
request,
|
|
||||||
get,
|
|
||||||
post,
|
|
||||||
put,
|
|
||||||
del
|
|
||||||
};
|
|
||||||
Reference in New Issue
Block a user