下载记录、钱包账单添加加载更多;监听键盘高度优化样式
This commit is contained in:
@@ -10,6 +10,8 @@
|
||||
|
||||
|
||||
.records-container {
|
||||
padding-bottom: 50px;
|
||||
|
||||
.record-item {
|
||||
padding: 16px 0;
|
||||
|
||||
@@ -58,7 +60,10 @@
|
||||
font-size: 12px;
|
||||
text-align: center;
|
||||
position: fixed;
|
||||
bottom: 40px;
|
||||
width: calc(100% - 40px);
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
width: 100vw;
|
||||
background-color: #FFFFFF;
|
||||
padding: 20px 0;
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@ import { View, Text } from "@tarojs/components";
|
||||
|
||||
import "./index.scss";
|
||||
import httpService from "@/services/httpService";
|
||||
import Taro from "@tarojs/taro";
|
||||
import Taro, { useReachBottom } from "@tarojs/taro";
|
||||
|
||||
interface BillRecord {
|
||||
id: number;
|
||||
@@ -28,14 +28,22 @@ const DownloadBillRecords: React.FC = () => {
|
||||
limit: 20,
|
||||
});
|
||||
|
||||
const [totalPages, setTotalPages] = useState(1);
|
||||
|
||||
useReachBottom(() => {
|
||||
if (params.page < totalPages) {
|
||||
setParams({ ...params, page: params.page + 1 });
|
||||
}
|
||||
});
|
||||
useEffect(() => {
|
||||
fetchRecords();
|
||||
}, []);
|
||||
|
||||
}, [params]);
|
||||
|
||||
const fetchRecords = async () => {
|
||||
try {
|
||||
const response = await httpService.post<{ rows: BillRecord[] }>('/wallet/download_history', params);
|
||||
setRecords(response.data.rows);
|
||||
const response = await httpService.post<{ rows: BillRecord[], totalPages: number }>('/wallet/download_history', params);
|
||||
setRecords([...records, ...response.data.rows]);
|
||||
setTotalPages(response.data.totalPages);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
Taro.showToast({
|
||||
|
||||
@@ -25,7 +25,7 @@ interface History {
|
||||
interface TransactionLoadParams {
|
||||
page: number;
|
||||
limit: number;
|
||||
keyword?: string;
|
||||
keyword: string;
|
||||
}
|
||||
|
||||
const QueryTransactions = () => {
|
||||
@@ -34,18 +34,19 @@ const QueryTransactions = () => {
|
||||
const [transactions, setTransactions] = useState<Transaction[]>([]);
|
||||
const [searchHistory, setSearchHistory] = useState<History[]>([]);
|
||||
const ref = useRef<any>(null);
|
||||
const [keyword, setKeyword] = useState("");
|
||||
const [load_transactions_params, set_load_transactions_params] =
|
||||
useState<TransactionLoadParams>({
|
||||
page: 1,
|
||||
limit: 20,
|
||||
keyword: "",
|
||||
});
|
||||
|
||||
const [totalpages, setTotalpages] = useState(1);
|
||||
useEffect(() => {
|
||||
getSearchHistory();
|
||||
return () => {
|
||||
handleClear();
|
||||
};
|
||||
// return () => {
|
||||
// handleClear();
|
||||
// };
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -55,6 +56,7 @@ const QueryTransactions = () => {
|
||||
}, [ref.current]);
|
||||
|
||||
useReachBottom(() => {
|
||||
if (load_transactions_params.page >= totalpages) return;
|
||||
set_load_transactions_params((prev) => {
|
||||
return {
|
||||
...prev,
|
||||
@@ -93,9 +95,7 @@ const QueryTransactions = () => {
|
||||
* @param value
|
||||
*/
|
||||
const handleChange = (value: string) => {
|
||||
set_load_transactions_params((prev) => {
|
||||
return { ...prev, keyword: value };
|
||||
});
|
||||
setKeyword(value);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -104,7 +104,7 @@ const QueryTransactions = () => {
|
||||
const handleClear = () => {
|
||||
setTransactions([]);
|
||||
set_load_transactions_params((prev) => {
|
||||
return { ...prev, keyword: "" };
|
||||
return { ...prev, page: 1, keyword: "" };
|
||||
});
|
||||
};
|
||||
|
||||
@@ -114,7 +114,7 @@ const QueryTransactions = () => {
|
||||
*/
|
||||
const handleHistoryClick = (item: { id: number; keyword: string }) => {
|
||||
set_load_transactions_params((prev) => {
|
||||
return { ...prev, keyword: item?.keyword };
|
||||
return { ...prev, page: 1, keyword: item?.keyword };
|
||||
});
|
||||
};
|
||||
|
||||
@@ -129,16 +129,20 @@ const QueryTransactions = () => {
|
||||
/**
|
||||
* @description 点击搜索
|
||||
*/
|
||||
const handleSearch = async (val?: string) => {
|
||||
const handleSearch = async () => {
|
||||
// set_loading_transactions(true);
|
||||
try {
|
||||
const response = await httpService.post("/wallet/transactions", {
|
||||
...load_transactions_params,
|
||||
keyword: val,
|
||||
...load_transactions_params
|
||||
});
|
||||
|
||||
if (response && response.data && response.data.list) {
|
||||
if (load_transactions_params.keyword !== "") {
|
||||
getSearchHistory();
|
||||
}
|
||||
if (response && response.data && response.data.list.length) {
|
||||
setTransactions([...transactions, ...response.data.list]);
|
||||
setTotalpages(response.data.totalPages);
|
||||
} else if (load_transactions_params.page === 1) {
|
||||
setTransactions([]);
|
||||
}
|
||||
} catch (error) {
|
||||
setTransactions([]);
|
||||
@@ -237,8 +241,8 @@ const QueryTransactions = () => {
|
||||
<Image className="searchIcon" src={img.ICON_LIST_SEARCH_SEARCH} />
|
||||
<Input
|
||||
placeholder="查找"
|
||||
value={load_transactions_params.keyword}
|
||||
defaultValue={load_transactions_params.keyword}
|
||||
value={keyword}
|
||||
defaultValue={keyword}
|
||||
onChange={handleChange}
|
||||
onClear={handleClear}
|
||||
autoFocus
|
||||
@@ -256,7 +260,11 @@ const QueryTransactions = () => {
|
||||
<View className="searchLine" />
|
||||
<Text
|
||||
className="searchText"
|
||||
onClick={() => handleSearch(load_transactions_params.keyword)}
|
||||
onClick={() => {
|
||||
set_load_transactions_params((prev) => {
|
||||
return { ...prev, page: 1, keyword };
|
||||
});
|
||||
}}
|
||||
>
|
||||
搜索
|
||||
</Text>
|
||||
@@ -303,7 +311,7 @@ const QueryTransactions = () => {
|
||||
<View className="loading_state">
|
||||
<Text className="loading_text">加载中...</Text>
|
||||
</View>
|
||||
) : transactions.length > 0 ? (
|
||||
) : transactions.length > 0 && load_transactions_params.keyword !== "" ? (
|
||||
transactions.map((transaction) => {
|
||||
const timeInfo = format_time(transaction.create_time);
|
||||
return (
|
||||
|
||||
@@ -4,6 +4,7 @@ import { View, Text, Input, Button } from "@tarojs/components";
|
||||
|
||||
import "./index.scss";
|
||||
import httpService from "@/services/httpService";
|
||||
import { useKeyboardHeight } from '@/store/keyboardStore'
|
||||
|
||||
interface FormFields {
|
||||
old_password?: string;
|
||||
@@ -13,6 +14,22 @@ interface FormFields {
|
||||
}
|
||||
|
||||
const SetTransactionPassword: React.FC = () => {
|
||||
// 使用全局键盘状态
|
||||
const { keyboardHeight, isKeyboardVisible, addListener, initializeKeyboardListener } = useKeyboardHeight()
|
||||
// 使用全局键盘状态监听
|
||||
useEffect(() => {
|
||||
// 初始化全局键盘监听器
|
||||
initializeKeyboardListener()
|
||||
|
||||
// 添加本地监听器
|
||||
const removeListener = addListener((height, visible) => {
|
||||
console.log('AiImportPopup 收到键盘变化:', height, visible)
|
||||
})
|
||||
|
||||
return () => {
|
||||
removeListener()
|
||||
}
|
||||
}, [initializeKeyboardListener, addListener])
|
||||
const [handleType, setHandleType] = useState("set");
|
||||
const router = useRouter();
|
||||
const { type, phone, sms_code } = router.params;
|
||||
@@ -129,7 +146,7 @@ const SetTransactionPassword: React.FC = () => {
|
||||
</View>
|
||||
)}
|
||||
<Text className="tips">* 密码由6位数字组成</Text>
|
||||
<Button className="btn bottom-btn" onClick={handleConfirm}>
|
||||
<Button className="btn bottom-btn" onClick={handleConfirm} style={{ bottom: isKeyboardVisible ? `${keyboardHeight + 20}px` : undefined }}>
|
||||
完成
|
||||
</Button>
|
||||
</View>
|
||||
|
||||
@@ -5,6 +5,7 @@ import { View, Text, Input, Button } from "@tarojs/components";
|
||||
import "./index.scss";
|
||||
import httpService from "@/services/httpService";
|
||||
import { useUserInfo } from "@/store/userStore";
|
||||
import { useKeyboardHeight } from '@/store/keyboardStore'
|
||||
|
||||
interface FormFields {
|
||||
phone?: string;
|
||||
@@ -12,6 +13,22 @@ interface FormFields {
|
||||
}
|
||||
|
||||
const ValidPhone: React.FC = () => {
|
||||
// 使用全局键盘状态
|
||||
const { keyboardHeight, isKeyboardVisible, addListener, initializeKeyboardListener } = useKeyboardHeight()
|
||||
// 使用全局键盘状态监听
|
||||
useEffect(() => {
|
||||
// 初始化全局键盘监听器
|
||||
initializeKeyboardListener()
|
||||
|
||||
// 添加本地监听器
|
||||
const removeListener = addListener((height, visible) => {
|
||||
console.log('AiImportPopup 收到键盘变化:', height, visible)
|
||||
})
|
||||
|
||||
return () => {
|
||||
removeListener()
|
||||
}
|
||||
}, [initializeKeyboardListener, addListener])
|
||||
const userInfo = useUserInfo();
|
||||
const [formData, setFormData] = useState<FormFields>({
|
||||
phone: userInfo.phone || "",
|
||||
@@ -69,7 +86,7 @@ const ValidPhone: React.FC = () => {
|
||||
<Input placeholder="请输入验证码" type="number" onInput={(e) => { handleInput(e, "sms_code") }}></Input>
|
||||
<Button className="btn" onClick={getSMSCode}>获取验证码</Button>
|
||||
</View>
|
||||
<Button className="btn bottom-btn" disabled={!formData.sms_code} onClick={handleConfirm}>提交</Button>
|
||||
<Button className="btn bottom-btn" disabled={!formData.sms_code} onClick={handleConfirm} style={{ bottom: isKeyboardVisible ? `${keyboardHeight + 20}px` : undefined }}>提交</Button>
|
||||
</View>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -98,6 +98,7 @@ const transaction_type_options: Option<TransactionSubType>[] = [
|
||||
|
||||
const WalletPage: React.FC = () => {
|
||||
useReachBottom(() => {
|
||||
if (load_transactions_params.page >= totalPages) return;
|
||||
// 加载更多方法
|
||||
set_load_transactions_params((prev) => {
|
||||
return {
|
||||
@@ -144,6 +145,8 @@ const WalletPage: React.FC = () => {
|
||||
date: `${year}-${month}`,
|
||||
});
|
||||
|
||||
const [totalPages, setTotalPages] = useState(1);
|
||||
|
||||
useEffect(() => {
|
||||
load_transactions();
|
||||
}, [load_transactions_params]);
|
||||
@@ -229,6 +232,7 @@ const WalletPage: React.FC = () => {
|
||||
|
||||
if (response && response.data && response.data.list) {
|
||||
set_transactions([...transactions, ...response.data.list]);
|
||||
setTotalPages(response.data.totalPages);
|
||||
console.log("设置交易记录:", response.data.list);
|
||||
} else {
|
||||
console.log("响应数据格式异常:", response);
|
||||
|
||||
Reference in New Issue
Block a user