缺陷优化
This commit is contained in:
@@ -26,7 +26,7 @@
|
||||
justify-content: center;
|
||||
width: 76px;
|
||||
background: #00000008;
|
||||
border: 0.5px solid #0000001F;
|
||||
border: 1.5px solid #e5e5e5;
|
||||
border-radius: 12px;
|
||||
padding: 12px 0;
|
||||
font-weight: 500;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import React, { useState, useEffect, useCallback } from "react";
|
||||
import React, { useState, useEffect } from "react";
|
||||
import CommonPopup from "@/components/CommonPopup";
|
||||
import { View, Text, Image } from "@tarojs/components";
|
||||
import { View } from "@tarojs/components";
|
||||
import Picker from "./Picker";
|
||||
import {
|
||||
renderYearMonth,
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
} from "./PickerData";
|
||||
import NTRPTestEntryCard from "../NTRPTestEntryCard";
|
||||
import { EvaluateScene } from "@/store/evaluateStore";
|
||||
import imgs from "@/config/images";
|
||||
// import imgs from "@/config/images";
|
||||
import styles from "./index.module.scss";
|
||||
interface PickerOption {
|
||||
text: string | number;
|
||||
@@ -27,7 +27,7 @@ interface PickerProps {
|
||||
options?: PickerOption[][] | PickerOption[];
|
||||
value?: (string | number)[];
|
||||
type?: "month" | "day" | "hour" | "ntrp" | null;
|
||||
img?: string;
|
||||
// img?: string;
|
||||
onConfirm?: (options: PickerOption[], values: (string | number)[]) => void;
|
||||
onChange?: (value: (string | number)[]) => void;
|
||||
style?: React.CSSProperties;
|
||||
@@ -42,7 +42,7 @@ const PopupPicker = ({
|
||||
visible,
|
||||
setvisible,
|
||||
value = [],
|
||||
img,
|
||||
// img,
|
||||
onConfirm,
|
||||
onChange,
|
||||
options = [],
|
||||
@@ -54,7 +54,6 @@ const PopupPicker = ({
|
||||
const changePicker = (options: any[], values: any, columnIndex: number) => {
|
||||
if (onChange) {
|
||||
console.log("picker onChange", columnIndex, values, options);
|
||||
|
||||
if (
|
||||
type === "day" &&
|
||||
JSON.stringify(defaultValue) !== JSON.stringify(values)
|
||||
@@ -79,7 +78,6 @@ const PopupPicker = ({
|
||||
};
|
||||
|
||||
const handleConfirm = () => {
|
||||
console.log(defaultValue, "defaultValue");
|
||||
onChange(defaultValue);
|
||||
setvisible(false);
|
||||
};
|
||||
|
||||
@@ -78,7 +78,7 @@ export const UserInfoCard: React.FC<UserInfoCardProps> = ({
|
||||
useState(false);
|
||||
|
||||
// 表单状态
|
||||
const [form_data, setFormData] = useState<Partial<UserInfoType>>({
|
||||
const [form_data] = useState<Partial<UserInfoType>>({
|
||||
...user_info,
|
||||
});
|
||||
|
||||
@@ -143,12 +143,14 @@ export const UserInfoCard: React.FC<UserInfoCardProps> = ({
|
||||
const update_data = { [editing_field]: value };
|
||||
await UserService.update_user_info(update_data);
|
||||
|
||||
await updateUserInfo({ [editing_field]: value });
|
||||
|
||||
// 更新本地状态
|
||||
setFormData((prev) => {
|
||||
const updated = { ...prev, [editing_field]: value };
|
||||
typeof set_user_info === "function" && set_user_info(updated);
|
||||
return updated;
|
||||
});
|
||||
// setFormData((prev) => {
|
||||
// const updated = { ...prev, [editing_field]: value };
|
||||
// typeof set_user_info === "function" && set_user_info(updated);
|
||||
// return updated;
|
||||
// });
|
||||
|
||||
// 关闭弹窗
|
||||
setEditModalVisible(false);
|
||||
@@ -180,14 +182,14 @@ export const UserInfoCard: React.FC<UserInfoCardProps> = ({
|
||||
) {
|
||||
await updateUserInfo({ ...field });
|
||||
// 更新本地状态
|
||||
setFormData((prev) => ({ ...prev, ...field }));
|
||||
// setFormData((prev) => ({ ...prev, ...field }));
|
||||
// setUserInfo((prev) => ({ ...prev, ...field }));
|
||||
} else {
|
||||
// 调用更新用户信息接口,只传递修改的字段
|
||||
const update_data = { [field as string]: value };
|
||||
await updateUserInfo(update_data);
|
||||
// 更新本地状态
|
||||
setFormData((prev) => ({ ...prev, [field as string]: value }));
|
||||
// setFormData((prev) => ({ ...prev, [field as string]: value }));
|
||||
// setUserInfo((prev) => ({ ...prev, [field as string]: value }));
|
||||
}
|
||||
|
||||
@@ -259,6 +261,22 @@ export const UserInfoCard: React.FC<UserInfoCardProps> = ({
|
||||
// 主办和参加暂时不处理,可以后续扩展
|
||||
};
|
||||
|
||||
const getDefaultOption = (options) => {
|
||||
if (!Array.isArray(options) || options.length === 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const defaultOptions: string[] = [];
|
||||
let current = options[0];
|
||||
|
||||
while (current) {
|
||||
defaultOptions.push(current.text);
|
||||
current = current.children?.[0];
|
||||
}
|
||||
|
||||
return defaultOptions;
|
||||
}
|
||||
|
||||
return (
|
||||
<View className="user_info_card">
|
||||
{/* 头像和基本信息 */}
|
||||
@@ -385,7 +403,7 @@ export const UserInfoCard: React.FC<UserInfoCardProps> = ({
|
||||
<Text>选择性别</Text>
|
||||
</View>
|
||||
) : null}
|
||||
{user_info.ntrp_level ? (
|
||||
{user_info.ntrp_level !== "0" ? (
|
||||
<View className="tag_item">
|
||||
<Text className="tag_text">{`NTRP ${user_info.ntrp_level}`}</Text>
|
||||
</View>
|
||||
@@ -472,7 +490,7 @@ export const UserInfoCard: React.FC<UserInfoCardProps> = ({
|
||||
]}
|
||||
visible={gender_picker_visible}
|
||||
setvisible={setGenderPickerVisible}
|
||||
value={[form_data.gender || ""]}
|
||||
value={form_data.gender === "" ? ["0"] : [form_data.gender]}
|
||||
onChange={handle_gender_change}
|
||||
/>
|
||||
)}
|
||||
@@ -484,11 +502,7 @@ export const UserInfoCard: React.FC<UserInfoCardProps> = ({
|
||||
options={cities}
|
||||
visible={location_picker_visible}
|
||||
setvisible={setLocationPickerVisible}
|
||||
value={[
|
||||
form_data.country || "",
|
||||
form_data.province || "",
|
||||
form_data.city || "",
|
||||
]}
|
||||
value={form_data.country ? [form_data.country, form_data.province, form_data.city] : getDefaultOption(cities)}
|
||||
onChange={handle_location_change}
|
||||
/>
|
||||
)}
|
||||
@@ -512,7 +526,7 @@ export const UserInfoCard: React.FC<UserInfoCardProps> = ({
|
||||
img={user_info.avatar_url || ""}
|
||||
visible={ntrp_picker_visible}
|
||||
setvisible={setNtrpPickerVisible}
|
||||
value={[form_data.ntrp_level || ""]}
|
||||
value={form_data.ntrp_level === "0" ? ["3.0"] : [form_data.ntrp_level]}
|
||||
onChange={handle_ntrp_level_change}
|
||||
/>
|
||||
)}
|
||||
@@ -524,7 +538,7 @@ export const UserInfoCard: React.FC<UserInfoCardProps> = ({
|
||||
options={professions}
|
||||
visible={occupation_picker_visible}
|
||||
setvisible={setOccupationPickerVisible}
|
||||
value={[...(form_data.occupation || "").split(" ")]}
|
||||
value={form_data.occupation ? [...form_data.occupation.split(" ")] : getDefaultOption(professions)}
|
||||
onChange={handle_occupation_change}
|
||||
/>
|
||||
)}
|
||||
@@ -665,9 +679,8 @@ export const GameTabs: React.FC<GameTabsProps> = ({
|
||||
<Text className="tab_text">{hosted_text}</Text>
|
||||
</View>
|
||||
<View
|
||||
className={`tab_item ${
|
||||
active_tab === "participated" ? "active" : ""
|
||||
}`}
|
||||
className={`tab_item ${active_tab === "participated" ? "active" : ""
|
||||
}`}
|
||||
onClick={() => on_tab_change("participated")}
|
||||
>
|
||||
<Text className="tab_text">{participated_text}</Text>
|
||||
|
||||
@@ -133,7 +133,7 @@ const EditProfilePage: React.FC = () => {
|
||||
const tempFilePath = res.tempFilePaths[0];
|
||||
try {
|
||||
const avatar_url = await UserService.upload_avatar(tempFilePath);
|
||||
setUserInfo((prev) => ({ ...prev, avatar: avatar_url }));
|
||||
await updateUserInfo({ avatar: avatar_url });
|
||||
Taro.showToast({
|
||||
title: "头像上传成功",
|
||||
icon: "success",
|
||||
@@ -331,6 +331,22 @@ const EditProfilePage: React.FC = () => {
|
||||
}
|
||||
};
|
||||
|
||||
const getDefaultOption = (options) => {
|
||||
if (!Array.isArray(options) || options.length === 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const defaultOptions: string[] = [];
|
||||
let current = options[0];
|
||||
|
||||
while (current) {
|
||||
defaultOptions.push(current.text);
|
||||
current = current.children?.[0];
|
||||
}
|
||||
|
||||
return defaultOptions;
|
||||
}
|
||||
|
||||
return (
|
||||
<View className="edit_profile_page">
|
||||
{/* 导航栏 */}
|
||||
@@ -639,7 +655,7 @@ const EditProfilePage: React.FC = () => {
|
||||
]}
|
||||
visible={gender_picker_visible}
|
||||
setvisible={setGenderPickerVisible}
|
||||
value={[form_data.gender]}
|
||||
value={form_data.gender === "" ? ["0"] : [form_data.gender]}
|
||||
onChange={handle_gender_change}
|
||||
/>
|
||||
)}
|
||||
@@ -671,7 +687,7 @@ const EditProfilePage: React.FC = () => {
|
||||
options={cities}
|
||||
visible={location_picker_visible}
|
||||
setvisible={setLocationPickerVisible}
|
||||
value={[form_data.country, form_data.province, form_data.city]}
|
||||
value={form_data.country ? [form_data.country, form_data.province, form_data.city] : getDefaultOption(cities)}
|
||||
onChange={handle_location_change}
|
||||
/>
|
||||
)}
|
||||
@@ -693,10 +709,10 @@ const EditProfilePage: React.FC = () => {
|
||||
],
|
||||
]}
|
||||
type="ntrp"
|
||||
img={(user_info as UserInfoType)?.avatar_url}
|
||||
// img={(user_info as UserInfoType)?.avatar_url}
|
||||
visible={ntrp_picker_visible}
|
||||
setvisible={setNtrpPickerVisible}
|
||||
value={[form_data.ntrp_level]}
|
||||
value={form_data.ntrp_level === "0" ? ["3.0"] : [form_data.ntrp_level]}
|
||||
onChange={handle_ntrp_level_change}
|
||||
/>
|
||||
)}
|
||||
@@ -709,7 +725,7 @@ const EditProfilePage: React.FC = () => {
|
||||
options={professions}
|
||||
visible={occupation_picker_visible}
|
||||
setvisible={setOccupationPickerVisible}
|
||||
value={[...form_data.occupation.split(" ")]}
|
||||
value={form_data.occupation ? [...form_data.occupation.split(" ")] : getDefaultOption(professions)}
|
||||
onChange={handle_occupation_change}
|
||||
/>
|
||||
)}
|
||||
|
||||
@@ -62,10 +62,10 @@ const SetTransactionPassword: React.FC = () => {
|
||||
const { new_password, confirm_password, sms_code } = formData;
|
||||
if (handleType === "set") {
|
||||
setValid(
|
||||
!!sms_code && new_password.length === 6 && confirm_password.length === 6
|
||||
(sms_code !== "") && (new_password.length === 6) && (confirm_password.length === 6)
|
||||
);
|
||||
} else {
|
||||
setValid(new_password.length === 6 && confirm_password.length === 6);
|
||||
setValid((new_password.length === 6) && (confirm_password.length === 6));
|
||||
}
|
||||
}, [formData]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user