测试表单可修改

This commit is contained in:
wong
2026-01-06 11:07:53 +08:00
parent ea2dd8cab2
commit 228d59402f
2 changed files with 47 additions and 11 deletions

View File

@@ -4,7 +4,8 @@ import { generateSign } from "./utils/sign";
// API配置
const API_BASE_URL = "https://ckbapi.quwanzhi.com/v1/api";
const API_KEY = "v3pzy-zcfkg-96jio-7xgh6-14kio";
// 默认API Key用于测试
export const DEFAULT_API_KEY = "v3pzy-zcfkg-96jio-7xgh6-14kio";
export interface SubmitLeadParams {
phone: string;
@@ -24,17 +25,24 @@ export interface SubmitLeadResponse {
/**
* 提交线索到存客宝
* @param params 线索参数
* @param apiKey API密钥必填
*/
export async function submitLead(
params: SubmitLeadParams,
apiKey: string,
): Promise<SubmitLeadResponse> {
if (!apiKey) {
throw new Error("apiKey不能为空");
}
try {
// 生成时间戳(秒级)
const timestamp = Math.floor(Date.now() / 1000);
// 构建请求参数
const requestParams: Record<string, any> = {
apiKey: API_KEY,
apiKey: apiKey,
timestamp,
phone: params.phone,
name: params.name,
@@ -56,7 +64,7 @@ export async function submitLead(
}
// 生成签名
const sign = generateSign(requestParams, API_KEY);
const sign = generateSign(requestParams, apiKey);
requestParams.sign = sign;
// 发送请求

View File

@@ -1,8 +1,8 @@
import React, { useState } from "react";
import React, { useState, useEffect } from "react";
import { Popup, Form, Input, TextArea, Button, Toast } from "antd-mobile";
import { CloseOutlined } from "@ant-design/icons";
import styles from "./TestFormModal.module.scss";
import { submitLead } from "../api";
import { submitLead, DEFAULT_API_KEY } from "../api";
interface TestFormModalProps {
visible: boolean;
@@ -11,6 +11,7 @@ interface TestFormModalProps {
}
export interface TestFormValues {
apiKey: string;
phone: string;
name: string;
source: string;
@@ -30,13 +31,19 @@ const TestFormModal: React.FC<TestFormModalProps> = ({
const values = await form.validateFields();
setLoading(true);
// 获取API Key如果没有输入则使用默认值
const apiKey = values.apiKey?.trim() || DEFAULT_API_KEY;
// 调用API提交数据
const result = await submitLead({
phone: values.phone,
name: values.name,
source: values.source,
remark: values.remark || undefined,
});
const result = await submitLead(
{
phone: values.phone,
name: values.name,
source: values.source,
remark: values.remark || undefined,
},
apiKey,
);
// 调用提交回调(如果提供)
if (onSubmit) {
@@ -64,9 +71,18 @@ const TestFormModal: React.FC<TestFormModalProps> = ({
const handleClose = () => {
form.resetFields();
// 重置时恢复默认API Key
form.setFieldsValue({ apiKey: DEFAULT_API_KEY });
onClose();
};
// 初始化表单默认值
useEffect(() => {
if (visible) {
form.setFieldsValue({ apiKey: DEFAULT_API_KEY });
}
}, [visible, form]);
return (
<Popup
visible={visible}
@@ -114,6 +130,18 @@ const TestFormModal: React.FC<TestFormModalProps> = ({
</div>
}
>
<Form.Item
label="API Key"
name="apiKey"
rules={[]}
extra="留空则使用默认API Key"
>
<Input
placeholder={`默认: ${DEFAULT_API_KEY}`}
defaultValue={DEFAULT_API_KEY}
/>
</Form.Item>
<Form.Item
label="手机号"
name="phone"