u
This commit is contained in:
1 parent
46cbb2f50d
commit
e3d765a9d4
15 files changed
+903
-190
No files matched your search
@@ -111,46 +111,6 @@ export default function Login() {
|
||||
}, [onLoginFinished]);
|
||||
|
||||
const handlePostLogin = async (user: any) => {
|
||||
// let finalAvatar = user.avatar || "";
|
||||
|
||||
// // 统一头像迁移逻辑
|
||||
// const isExternalUrl = finalAvatar && !isS3Key(finalAvatar);
|
||||
|
||||
// if (isExternalUrl) {
|
||||
// userStore.updateToken(user.token);
|
||||
|
||||
// try {
|
||||
// const file = {
|
||||
// uri: finalAvatar,
|
||||
// name: `avatar_${Date.now()}.jpg`,
|
||||
// type: "image/jpeg",
|
||||
// };
|
||||
|
||||
// const uploadRes = await s3UploadFileApi([file]);
|
||||
|
||||
// if (uploadRes.isSuccess) {
|
||||
// finalAvatar = uploadRes.data?.[0] || finalAvatar;
|
||||
|
||||
// saveDataApi([
|
||||
// {
|
||||
// table_name: "b_user",
|
||||
// key_field: "id",
|
||||
// inserts: [],
|
||||
// deletes: [],
|
||||
// updates: [
|
||||
// {
|
||||
// id: user.userId,
|
||||
// avatar: finalAvatar,
|
||||
// },
|
||||
// ],
|
||||
// },
|
||||
// ]).catch(console.log);
|
||||
// }
|
||||
// } catch (e) {
|
||||
// console.log("头像迁移失败", e);
|
||||
// }
|
||||
// }
|
||||
|
||||
// 统一写入 store
|
||||
userStore.setUserInfo({
|
||||
token: user.token,
|
||||
@@ -254,14 +214,22 @@ export default function Login() {
|
||||
{loading ? (
|
||||
<Spinner entering={FadeIn.delay(50)} color="white" />
|
||||
) : (
|
||||
<IconWeixin color="white" />
|
||||
<>
|
||||
<IconWeixin color={"#fff"} />
|
||||
<Button.Label>WeChat</Button.Label>
|
||||
</>
|
||||
)}
|
||||
<Button.Label>WeChat</Button.Label>
|
||||
</Button>
|
||||
|
||||
<Button variant="outline" onPress={handleLoginQQ}>
|
||||
{loading ? <Spinner entering={FadeIn.delay(50)} /> : <IconQq />}
|
||||
<Button.Label>QQ</Button.Label>
|
||||
<Button variant="outline" onPress={handleLoginQQ} isDisabled={loading}>
|
||||
{loading ? (
|
||||
<Spinner entering={FadeIn.delay(50)} />
|
||||
) : (
|
||||
<>
|
||||
<IconQq />
|
||||
<Button.Label>QQ</Button.Label>
|
||||
</>
|
||||
)}
|
||||
</Button>
|
||||
</View>
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ import { CopyIcon } from "lucide-react-native";
|
||||
import * as Clipboard from "expo-clipboard";
|
||||
import { formatRelativeTime } from "@/utils/time";
|
||||
import { UserRoundIcon } from "lucide-react-native";
|
||||
import { buildFileUrl } from "@/utils/file";
|
||||
|
||||
const StyledIonicons = withUniwind(Ionicons);
|
||||
|
||||
@@ -168,6 +169,8 @@ export default function HomeSettings() {
|
||||
return;
|
||||
}
|
||||
|
||||
setRenameLoading(true);
|
||||
|
||||
try {
|
||||
const requestData = [];
|
||||
|
||||
@@ -223,6 +226,8 @@ export default function HomeSettings() {
|
||||
return;
|
||||
}
|
||||
|
||||
setNicknameLoading(true);
|
||||
|
||||
try {
|
||||
const requestData = [];
|
||||
|
||||
@@ -264,6 +269,8 @@ export default function HomeSettings() {
|
||||
async function handleExitFamily() {
|
||||
if (exitLoading) return;
|
||||
|
||||
setExitLoading(true);
|
||||
|
||||
try {
|
||||
let isExit = true;
|
||||
|
||||
@@ -357,20 +364,25 @@ export default function HomeSettings() {
|
||||
}
|
||||
|
||||
async function loadMembers() {
|
||||
let searchCondition = `family_id = ?`;
|
||||
let args = [familyStore.currentFamily.family_id];
|
||||
const familyId = familyStore.currentFamily?.family_id;
|
||||
if (!familyId) return;
|
||||
|
||||
const loadRes = await loadDataApi({
|
||||
view_name: `v_family_member`,
|
||||
search_condition: searchCondition,
|
||||
view_name: "v_family_member",
|
||||
search_condition: "family_id = ?",
|
||||
search_columns: [],
|
||||
order_by: "role ASC, create_time ASC",
|
||||
args,
|
||||
args: [familyId],
|
||||
});
|
||||
|
||||
if (loadRes.isSuccess) {
|
||||
setFamilyMembers(loadRes.data);
|
||||
}
|
||||
if (!loadRes?.isSuccess || !Array.isArray(loadRes.data)) return;
|
||||
|
||||
const list = loadRes.data.map((item) => ({
|
||||
...item,
|
||||
avatar: item.avatar ? buildFileUrl(item.avatar) : "",
|
||||
}));
|
||||
|
||||
setFamilyMembers(list);
|
||||
}
|
||||
|
||||
return (
|
||||
@@ -537,9 +549,12 @@ export default function HomeSettings() {
|
||||
/>
|
||||
</TextField>
|
||||
|
||||
<Button className="mt-3" onPress={handleRename}>
|
||||
{renameLoading && <Spinner entering={FadeIn.delay(50)} color="white" />}
|
||||
<Button.Label>保存</Button.Label>
|
||||
<Button className="mt-3" onPress={handleRename} isDisabled={renameLoading}>
|
||||
{renameLoading ? (
|
||||
<Spinner entering={FadeIn.delay(50)} color="white" />
|
||||
) : (
|
||||
<Button.Label>保存</Button.Label>
|
||||
)}
|
||||
</Button>
|
||||
</View>
|
||||
</BottomSheet.Content>
|
||||
@@ -574,9 +589,12 @@ export default function HomeSettings() {
|
||||
/>
|
||||
</TextField>
|
||||
|
||||
<Button className="mt-3" onPress={handleNickname}>
|
||||
{renameLoading && <Spinner entering={FadeIn.delay(50)} color="white" />}
|
||||
<Button.Label>保存</Button.Label>
|
||||
<Button className="mt-3" onPress={handleNickname} isDisabled={nicknameLoading}>
|
||||
{nicknameLoading ? (
|
||||
<Spinner entering={FadeIn.delay(50)} color="white" />
|
||||
) : (
|
||||
<Button.Label>保存</Button.Label>
|
||||
)}
|
||||
</Button>
|
||||
</View>
|
||||
</BottomSheet.Content>
|
||||
@@ -612,9 +630,12 @@ export default function HomeSettings() {
|
||||
取消
|
||||
</Button>
|
||||
|
||||
<Button size="sm" variant="danger" onPress={handleExitFamily}>
|
||||
{exitLoading && <Spinner entering={FadeIn.delay(50)} color="white" />}
|
||||
<Button.Label>确认退出</Button.Label>
|
||||
<Button size="sm" variant="danger" onPress={handleExitFamily} isDisabled={exitLoading}>
|
||||
{exitLoading ? (
|
||||
<Spinner entering={FadeIn.delay(50)} color="white" />
|
||||
) : (
|
||||
<Button.Label>保存</Button.Label>
|
||||
)}
|
||||
</Button>
|
||||
</View>
|
||||
</Dialog.Content>
|
||||
|
||||
@@ -1,18 +1,61 @@
|
||||
import LayoutView from "@/components/layout/view";
|
||||
import { View, Text, Pressable } from "react-native";
|
||||
import { View, Text, Pressable, Keyboard } from "react-native";
|
||||
import PageLayout from "@/layouts/PageLayout";
|
||||
import { Avatar, PressableFeedback, ListGroup, Separator, Button, Dialog } from "heroui-native";
|
||||
import {
|
||||
Avatar,
|
||||
PressableFeedback,
|
||||
BottomSheet,
|
||||
ListGroup,
|
||||
Separator,
|
||||
Button,
|
||||
Dialog,
|
||||
TextField,
|
||||
Label,
|
||||
Input,
|
||||
useBottomSheetAwareHandlers,
|
||||
Spinner,
|
||||
} from "heroui-native";
|
||||
import { loadDataApi, saveDataApi } from "@/request/api";
|
||||
import { useUserStore, useFamilyStore } from "@/store";
|
||||
import { useEffect, useState } from "react";
|
||||
import { CameraIcon } from "lucide-react-native";
|
||||
import ImagePicker from "react-native-image-crop-picker";
|
||||
import { s3UploadFileApi } from "@/request/api";
|
||||
import { s3UploadFileApi, bindQqApi, bindWxApi } from "@/request/api";
|
||||
import { buildFileUrl } from "@/utils/file";
|
||||
import { PhoneIcon, CakeIcon, ContactRoundIcon } from "lucide-react-native";
|
||||
import { IconQq, IconWeixin } from "@/components/iconfont";
|
||||
import { useRouter } from "expo-router";
|
||||
import Ionicons from "@expo/vector-icons/Ionicons";
|
||||
import { withUniwind } from "uniwind";
|
||||
import ExpoQQ from "expo-qq";
|
||||
import ExpoWeChat from "expo-wechat";
|
||||
import { useEvent } from "expo";
|
||||
import { toast } from "sonner-native";
|
||||
import { forwardRef, useRef } from "react";
|
||||
import { FadeIn } from "react-native-reanimated";
|
||||
import DateTime from "@/components/DateTime";
|
||||
import { toDateString } from "@/utils/time";
|
||||
|
||||
const StyledIonicons = withUniwind(Ionicons);
|
||||
|
||||
const BottomSheetTextInput = forwardRef<any, React.ComponentProps<typeof Input>>((props, ref) => {
|
||||
const { onFocus, onBlur } = useBottomSheetAwareHandlers();
|
||||
|
||||
return (
|
||||
<Input
|
||||
ref={ref}
|
||||
{...props}
|
||||
onFocus={(e) => {
|
||||
onFocus(e);
|
||||
props.onFocus?.(e);
|
||||
}}
|
||||
onBlur={(e) => {
|
||||
onBlur(e);
|
||||
props.onBlur?.(e);
|
||||
}}
|
||||
/>
|
||||
);
|
||||
});
|
||||
|
||||
export default function UserSetting() {
|
||||
const router = useRouter();
|
||||
@@ -25,10 +68,75 @@ export default function UserSetting() {
|
||||
|
||||
const [openLogout, setOpenLogout] = useState(false);
|
||||
|
||||
// 绑定
|
||||
const [bindLoading, setBindLoading] = useState(false);
|
||||
const onLoginFinished = useEvent(ExpoQQ, "onLoginFinished");
|
||||
const authResult = useEvent(ExpoWeChat, "onAuthResult");
|
||||
|
||||
// 名称
|
||||
const [showRename, setShowRename] = useState(false);
|
||||
const [renameLoading, setRenameLoading] = useState(false);
|
||||
|
||||
const [renameForm, setRenameForm] = useState({
|
||||
name: "",
|
||||
});
|
||||
|
||||
const renameInputRef = useRef<any>(null);
|
||||
|
||||
// 手机号
|
||||
const [showPhone, setShowPhone] = useState(false);
|
||||
const [phoneLoading, setPhoneLoading] = useState(false);
|
||||
|
||||
const [phoneForm, setPhoneForm] = useState({
|
||||
phone: "",
|
||||
});
|
||||
|
||||
const phoneInputRef = useRef<any>(null);
|
||||
|
||||
// 年龄
|
||||
const [showBirth, setShowBirth] = useState(false);
|
||||
|
||||
const [birthForm, setBirthForm] = useState({
|
||||
birth: "",
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
loadUserInfo();
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
ExpoQQ.init("102826474", "");
|
||||
ExpoWeChat.registerApp("wxdab3e21a1f7e392f", "");
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (showRename) {
|
||||
requestAnimationFrame(() => {
|
||||
renameInputRef.current?.focus();
|
||||
});
|
||||
} else {
|
||||
setRenameForm({
|
||||
name: "",
|
||||
});
|
||||
setRenameLoading(false);
|
||||
Keyboard.dismiss();
|
||||
}
|
||||
}, [showRename]);
|
||||
|
||||
useEffect(() => {
|
||||
if (showPhone) {
|
||||
requestAnimationFrame(() => {
|
||||
phoneInputRef.current?.focus();
|
||||
});
|
||||
} else {
|
||||
setPhoneForm({
|
||||
phone: "",
|
||||
});
|
||||
setPhoneLoading(false);
|
||||
Keyboard.dismiss();
|
||||
}
|
||||
}, [showPhone]);
|
||||
|
||||
async function loadUserInfo() {
|
||||
try {
|
||||
const userId = userStore.userInfo.id;
|
||||
@@ -71,6 +179,118 @@ export default function UserSetting() {
|
||||
}
|
||||
}
|
||||
|
||||
// 微信登录
|
||||
async function handleBindWechat() {
|
||||
if (bindWechat) {
|
||||
toast.success("微信已绑定");
|
||||
setBindLoading(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (bindLoading) {
|
||||
return;
|
||||
}
|
||||
setBindLoading(true);
|
||||
|
||||
// 检查微信是否安装
|
||||
const isInstalled = await ExpoWeChat.isWXAppInstalled();
|
||||
if (!isInstalled) {
|
||||
toast.warning(onLoginFinished?.errorMessage || "请先安装微信");
|
||||
setBindLoading(false);
|
||||
return;
|
||||
}
|
||||
|
||||
ExpoWeChat.sendAuthRequest("snsapi_userinfo", "state123");
|
||||
}
|
||||
|
||||
// QQ 登录
|
||||
async function handleBindQq() {
|
||||
if (bindQq) {
|
||||
toast.success("QQ已绑定");
|
||||
setBindLoading(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (bindLoading) {
|
||||
return;
|
||||
}
|
||||
|
||||
setBindLoading(true);
|
||||
|
||||
await ExpoQQ.login(["get_user_info"]);
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (!onLoginFinished) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!onLoginFinished.success) {
|
||||
toast.warning(onLoginFinished?.errorMessage || "授权失败,请检查手机是否安装 QQ 或确认授权");
|
||||
setBindLoading(false);
|
||||
return;
|
||||
}
|
||||
|
||||
const fetchUserInfo = async () => {
|
||||
try {
|
||||
const tokenInfo = await ExpoQQ.getLoginTokenInfo();
|
||||
if (!tokenInfo.openId) {
|
||||
toast.warning(tokenInfo?.errorMessage || "授权失败,请检查手机是否安装 QQ 或确认授权");
|
||||
setBindLoading(false);
|
||||
return;
|
||||
}
|
||||
|
||||
const bindRes = await bindQqApi({
|
||||
openid: String(tokenInfo.openId),
|
||||
avatar: "",
|
||||
nickname: "",
|
||||
});
|
||||
|
||||
if (bindRes.isSuccess) {
|
||||
toast.success("绑定 QQ 成功");
|
||||
setBindQq(true);
|
||||
}
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
} finally {
|
||||
setBindLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
fetchUserInfo();
|
||||
}, [onLoginFinished]);
|
||||
|
||||
// 微信登录
|
||||
useEffect(() => {
|
||||
if (!authResult) return;
|
||||
|
||||
const handleLogin = async () => {
|
||||
if (authResult.errorCode !== 0) {
|
||||
console.log("授权失败:", authResult.errorMessage);
|
||||
setBindLoading(false);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// 登录
|
||||
const bindRes = await bindWxApi({
|
||||
code: authResult.code,
|
||||
});
|
||||
|
||||
if (bindRes.isSuccess) {
|
||||
toast.success("绑定 微信 成功");
|
||||
setBindWechat(true);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error("微信登录失败", err);
|
||||
} finally {
|
||||
setBindLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
handleLogin();
|
||||
}, [authResult]);
|
||||
|
||||
// 选择头像
|
||||
const pickImage = async () => {
|
||||
try {
|
||||
@@ -128,6 +348,164 @@ export default function UserSetting() {
|
||||
});
|
||||
}
|
||||
|
||||
// 姓名
|
||||
async function handleRename() {
|
||||
if (renameLoading) return;
|
||||
|
||||
if (renameForm.name === "") {
|
||||
toast.warning("名称不能为空");
|
||||
return;
|
||||
}
|
||||
|
||||
if (renameForm.name === userInfo.name) {
|
||||
setShowRename(false);
|
||||
setRenameForm({
|
||||
name: "",
|
||||
});
|
||||
toast.success("名称修改成功");
|
||||
return;
|
||||
}
|
||||
|
||||
setRenameLoading(true);
|
||||
|
||||
try {
|
||||
const requestData = [];
|
||||
|
||||
requestData.push({
|
||||
table_name: "b_user",
|
||||
key_field: "id",
|
||||
inserts: [],
|
||||
updates: [
|
||||
{
|
||||
id: userInfo.id,
|
||||
name: renameForm.name,
|
||||
},
|
||||
],
|
||||
deletes: [],
|
||||
});
|
||||
|
||||
const saveRes = await saveDataApi(requestData);
|
||||
|
||||
if (saveRes.isSuccess) {
|
||||
setUserInfo((prev: any) => ({
|
||||
...prev,
|
||||
name: renameForm.name,
|
||||
}));
|
||||
|
||||
setShowRename(false);
|
||||
setRenameForm({
|
||||
name: "",
|
||||
});
|
||||
|
||||
toast.success("名称修改成功");
|
||||
}
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
} finally {
|
||||
setRenameLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
// 手机号
|
||||
async function handlePhone() {
|
||||
if (phoneLoading) return;
|
||||
|
||||
if (phoneForm.phone === "") {
|
||||
toast.warning("手机号不能为空");
|
||||
return;
|
||||
}
|
||||
|
||||
if (phoneForm.phone === userInfo.phone) {
|
||||
setShowPhone(false);
|
||||
setPhoneForm({
|
||||
phone: "",
|
||||
});
|
||||
toast.success("手机号修改成功");
|
||||
return;
|
||||
}
|
||||
|
||||
setPhoneLoading(true);
|
||||
|
||||
try {
|
||||
const requestData = [];
|
||||
|
||||
requestData.push({
|
||||
table_name: "b_user",
|
||||
key_field: "id",
|
||||
inserts: [],
|
||||
updates: [
|
||||
{
|
||||
id: userInfo.id,
|
||||
phone: phoneForm.phone,
|
||||
},
|
||||
],
|
||||
deletes: [],
|
||||
});
|
||||
|
||||
const saveRes = await saveDataApi(requestData);
|
||||
|
||||
if (saveRes.isSuccess) {
|
||||
setUserInfo((prev: any) => ({
|
||||
...prev,
|
||||
phone: phoneForm.phone,
|
||||
}));
|
||||
|
||||
setShowPhone(false);
|
||||
setPhoneForm({
|
||||
phone: "",
|
||||
});
|
||||
|
||||
toast.success("手机号修改成功");
|
||||
}
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
} finally {
|
||||
setPhoneLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
// 生日期
|
||||
async function handleBirth(value: string) {
|
||||
if (value === userInfo.birth_date) {
|
||||
setShowBirth(false);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const requestData = [
|
||||
{
|
||||
table_name: "b_user",
|
||||
key_field: "id",
|
||||
inserts: [],
|
||||
updates: [
|
||||
{
|
||||
id: userInfo.id,
|
||||
birth_date: value,
|
||||
},
|
||||
],
|
||||
deletes: [],
|
||||
},
|
||||
];
|
||||
|
||||
const saveRes = await saveDataApi(requestData);
|
||||
|
||||
if (saveRes.isSuccess) {
|
||||
setUserInfo((prev: any) => ({
|
||||
...prev,
|
||||
birth_date: value,
|
||||
}));
|
||||
|
||||
setShowBirth(false);
|
||||
|
||||
toast.success("生日修改成功");
|
||||
} else {
|
||||
toast.error(saveRes.message || "修改失败");
|
||||
}
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<PageLayout title="个人设置">
|
||||
<LayoutView>
|
||||
@@ -165,7 +543,14 @@ export default function UserSetting() {
|
||||
<View>
|
||||
<Text className="text-sm text-muted mb-2 ml-2">基础信息</Text>
|
||||
<ListGroup className="mb-6">
|
||||
<PressableFeedback>
|
||||
<PressableFeedback
|
||||
onPress={() => {
|
||||
setShowRename(true);
|
||||
setRenameForm({
|
||||
name: userInfo.name,
|
||||
});
|
||||
}}
|
||||
>
|
||||
<ListGroup.Item>
|
||||
<ListGroup.ItemPrefix>
|
||||
<ContactRoundIcon size="22" strokeWidth={1.5} />
|
||||
@@ -181,7 +566,14 @@ export default function UserSetting() {
|
||||
<PressableFeedback.Ripple />
|
||||
</PressableFeedback>
|
||||
<Separator className="mx-4" />
|
||||
<PressableFeedback>
|
||||
<PressableFeedback
|
||||
onPress={() => {
|
||||
setShowPhone(true);
|
||||
setPhoneForm({
|
||||
phone: userInfo.phone,
|
||||
});
|
||||
}}
|
||||
>
|
||||
<ListGroup.Item>
|
||||
<ListGroup.ItemPrefix>
|
||||
<PhoneIcon size="22" strokeWidth={1.5} />
|
||||
@@ -196,7 +588,14 @@ export default function UserSetting() {
|
||||
<PressableFeedback.Ripple />
|
||||
</PressableFeedback>
|
||||
<Separator className="mx-4" />
|
||||
<PressableFeedback>
|
||||
<PressableFeedback
|
||||
onPress={() => {
|
||||
setShowBirth(true);
|
||||
setBirthForm({
|
||||
birth: userInfo.birth_date,
|
||||
});
|
||||
}}
|
||||
>
|
||||
<ListGroup.Item>
|
||||
<ListGroup.ItemPrefix>
|
||||
<CakeIcon size="22" strokeWidth={1.5} />
|
||||
@@ -205,7 +604,9 @@ export default function UserSetting() {
|
||||
<ListGroup.ItemTitle>生日</ListGroup.ItemTitle>
|
||||
</ListGroup.ItemContent>
|
||||
<ListGroup.ItemSuffix>
|
||||
<Text className="text-sm text-muted">{userInfo.birth_date || "-"}</Text>
|
||||
<Text className="text-sm text-muted">
|
||||
{toDateString(userInfo.birth_date) || "-"}
|
||||
</Text>
|
||||
</ListGroup.ItemSuffix>
|
||||
</ListGroup.Item>
|
||||
<PressableFeedback.Ripple />
|
||||
@@ -214,7 +615,11 @@ export default function UserSetting() {
|
||||
|
||||
<Text className="text-sm text-muted mb-2 ml-2">账号信息</Text>
|
||||
<ListGroup className="mb-6">
|
||||
<PressableFeedback>
|
||||
<PressableFeedback
|
||||
onPress={() => {
|
||||
handleBindQq();
|
||||
}}
|
||||
>
|
||||
<ListGroup.Item>
|
||||
<ListGroup.ItemPrefix>
|
||||
<IconQq size={22} />
|
||||
@@ -223,15 +628,28 @@ export default function UserSetting() {
|
||||
<ListGroup.ItemTitle>QQ</ListGroup.ItemTitle>
|
||||
</ListGroup.ItemContent>
|
||||
<ListGroup.ItemSuffix>
|
||||
<Text className={`text-sm ${bindWechat ? "text-green-500" : "text-muted"}`}>
|
||||
{bindQq ? "已绑定" : "未绑定"}
|
||||
</Text>
|
||||
<ListGroup.ItemSuffix className="flex-row gap-2 items-center">
|
||||
<Text className={`text-sm ${bindQq ? "text-green-500" : "text-muted"}`}>
|
||||
{bindQq ? "已绑定" : "未绑定"}
|
||||
</Text>
|
||||
{bindQq && (
|
||||
<StyledIonicons
|
||||
name="checkmark-circle-sharp"
|
||||
size={24}
|
||||
className="text-accent"
|
||||
/>
|
||||
)}
|
||||
</ListGroup.ItemSuffix>
|
||||
</ListGroup.ItemSuffix>
|
||||
</ListGroup.Item>
|
||||
<PressableFeedback.Ripple />
|
||||
</PressableFeedback>
|
||||
<Separator className="mx-4" />
|
||||
<PressableFeedback>
|
||||
<PressableFeedback
|
||||
onPress={() => {
|
||||
handleBindWechat();
|
||||
}}
|
||||
>
|
||||
<ListGroup.Item>
|
||||
<ListGroup.ItemPrefix>
|
||||
<IconWeixin size={22} />
|
||||
@@ -239,28 +657,17 @@ export default function UserSetting() {
|
||||
<ListGroup.ItemContent>
|
||||
<ListGroup.ItemTitle>微信</ListGroup.ItemTitle>
|
||||
</ListGroup.ItemContent>
|
||||
<ListGroup.ItemSuffix>
|
||||
<ListGroup.ItemSuffix className="flex-row gap-2 items-center">
|
||||
<Text className={`text-sm ${bindWechat ? "text-green-500" : "text-muted"}`}>
|
||||
{bindWechat ? "已绑定" : "未绑定"}
|
||||
</Text>
|
||||
</ListGroup.ItemSuffix>
|
||||
</ListGroup.Item>
|
||||
<PressableFeedback.Ripple />
|
||||
</PressableFeedback>
|
||||
</ListGroup>
|
||||
|
||||
<Text className="text-sm text-muted mb-2 ml-2">其它</Text>
|
||||
<ListGroup className="mb-6">
|
||||
<PressableFeedback>
|
||||
<ListGroup.Item>
|
||||
<ListGroup.ItemPrefix>
|
||||
<IconQq size={22} />
|
||||
</ListGroup.ItemPrefix>
|
||||
<ListGroup.ItemContent>
|
||||
<ListGroup.ItemTitle>QQ</ListGroup.ItemTitle>
|
||||
</ListGroup.ItemContent>
|
||||
<ListGroup.ItemSuffix>
|
||||
<Text className={`text-sm text-muted`}>注销账号</Text>
|
||||
{bindWechat && (
|
||||
<StyledIonicons
|
||||
name="checkmark-circle-sharp"
|
||||
size={24}
|
||||
className="text-accent"
|
||||
/>
|
||||
)}
|
||||
</ListGroup.ItemSuffix>
|
||||
</ListGroup.Item>
|
||||
<PressableFeedback.Ripple />
|
||||
@@ -269,7 +676,7 @@ export default function UserSetting() {
|
||||
|
||||
<View className="mt-2">
|
||||
<Button
|
||||
variant="danger"
|
||||
variant="secondary"
|
||||
onPress={() => {
|
||||
setOpenLogout(true);
|
||||
}}
|
||||
@@ -308,6 +715,93 @@ export default function UserSetting() {
|
||||
</Dialog.Content>
|
||||
</Dialog.Portal>
|
||||
</Dialog>
|
||||
|
||||
<BottomSheet
|
||||
isOpen={showRename}
|
||||
onOpenChange={(val) => {
|
||||
setShowRename(val);
|
||||
}}
|
||||
>
|
||||
<BottomSheet.Portal>
|
||||
<BottomSheet.Overlay />
|
||||
<BottomSheet.Content
|
||||
animation="disabled"
|
||||
enableBlurKeyboardOnGesture
|
||||
keyboardBlurBehavior="restore"
|
||||
>
|
||||
<View>
|
||||
<TextField>
|
||||
<Label>我的名字</Label>
|
||||
<BottomSheetTextInput
|
||||
ref={renameInputRef}
|
||||
value={renameForm.name}
|
||||
onChangeText={(val) =>
|
||||
setRenameForm({
|
||||
name: val,
|
||||
})
|
||||
}
|
||||
/>
|
||||
</TextField>
|
||||
|
||||
<Button className="mt-3" onPress={handleRename} isDisabled={renameLoading}>
|
||||
{renameLoading ? (
|
||||
<Spinner entering={FadeIn.delay(50)} color="white" />
|
||||
) : (
|
||||
<Button.Label>保存</Button.Label>
|
||||
)}
|
||||
</Button>
|
||||
</View>
|
||||
</BottomSheet.Content>
|
||||
</BottomSheet.Portal>
|
||||
</BottomSheet>
|
||||
|
||||
<BottomSheet
|
||||
isOpen={showPhone}
|
||||
onOpenChange={(val) => {
|
||||
setShowPhone(val);
|
||||
}}
|
||||
>
|
||||
<BottomSheet.Portal>
|
||||
<BottomSheet.Overlay />
|
||||
<BottomSheet.Content
|
||||
animation="disabled"
|
||||
enableBlurKeyboardOnGesture
|
||||
keyboardBlurBehavior="restore"
|
||||
>
|
||||
<View>
|
||||
<TextField>
|
||||
<Label>手机号</Label>
|
||||
<BottomSheetTextInput
|
||||
ref={phoneInputRef}
|
||||
value={phoneForm.phone}
|
||||
onChangeText={(val) =>
|
||||
setPhoneForm({
|
||||
phone: val,
|
||||
})
|
||||
}
|
||||
/>
|
||||
</TextField>
|
||||
|
||||
<Button className="mt-3" onPress={handlePhone} isDisabled={phoneLoading}>
|
||||
{phoneLoading ? (
|
||||
<Spinner entering={FadeIn.delay(50)} color="white" />
|
||||
) : (
|
||||
<Button.Label>保存</Button.Label>
|
||||
)}
|
||||
</Button>
|
||||
</View>
|
||||
</BottomSheet.Content>
|
||||
</BottomSheet.Portal>
|
||||
</BottomSheet>
|
||||
|
||||
<DateTime
|
||||
show={showBirth}
|
||||
value={birthForm.birth}
|
||||
onClose={() => {
|
||||
setShowBirth(false);
|
||||
}}
|
||||
onConfirm={handleBirth}
|
||||
/>
|
||||
</PageLayout>
|
||||
);
|
||||
}
|
||||
@@ -1,10 +1,11 @@
|
||||
import { DatePicker as YzDatePicker } from "@yz1311/react-native-wheel-picker";
|
||||
import dayjs from "dayjs";
|
||||
import { BottomSheet, Button } from "heroui-native";
|
||||
import { BottomSheet, Button, Spinner } from "heroui-native";
|
||||
import { useState, useEffect } from "react";
|
||||
import { toDate } from "@/utils/time";
|
||||
import { View } from "react-native";
|
||||
import { CheckIcon } from "lucide-react-native";
|
||||
import { FadeIn } from "react-native-reanimated";
|
||||
|
||||
export type DatePickerMode = "year" | "month" | "date" | "time" | "datetime";
|
||||
|
||||
@@ -14,7 +15,7 @@ interface DatePickerProps {
|
||||
value: Date | string;
|
||||
show?: boolean;
|
||||
onClose?: () => void;
|
||||
onConfirm?: (value: string) => void;
|
||||
onConfirm?: (value: string) => void | Promise<void>;
|
||||
mode?: DatePickerMode;
|
||||
format?: DateFormatType;
|
||||
}
|
||||
@@ -35,9 +36,10 @@ export default function DateTime({
|
||||
mode = "date",
|
||||
format,
|
||||
}: DatePickerProps) {
|
||||
const finalFormat = format ?? defaultFormatMap[mode] ?? "YYYY-MM-DD";
|
||||
const finalFormat = format ?? defaultFormatMap[mode];
|
||||
|
||||
const [tempDate, setTempDate] = useState<Date>(toDate(value) ?? new Date());
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (show) {
|
||||
@@ -46,14 +48,26 @@ export default function DateTime({
|
||||
}, [show, value]);
|
||||
|
||||
const handleClose = () => {
|
||||
if (loading) return;
|
||||
onClose?.();
|
||||
};
|
||||
|
||||
const handleConfirm = () => {
|
||||
if (!tempDate) return;
|
||||
const handleConfirm = async () => {
|
||||
if (!tempDate || loading) return;
|
||||
|
||||
onConfirm?.(dayjs(tempDate).format(finalFormat));
|
||||
handleClose();
|
||||
try {
|
||||
setLoading(true);
|
||||
|
||||
const result = dayjs(tempDate).format(finalFormat);
|
||||
|
||||
await onConfirm?.(result);
|
||||
|
||||
handleClose();
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
@@ -71,9 +85,15 @@ export default function DateTime({
|
||||
onDateChange={(d: Date) => setTempDate(d)}
|
||||
/>
|
||||
|
||||
<Button className="w-full" onPress={handleConfirm}>
|
||||
<CheckIcon color="#fff" />
|
||||
<Button.Label>确认</Button.Label>
|
||||
<Button className="w-full" onPress={handleConfirm} isDisabled={loading}>
|
||||
{loading ? (
|
||||
<Spinner entering={FadeIn.delay(50)} color="white" />
|
||||
) : (
|
||||
<>
|
||||
<CheckIcon color="#fff" />
|
||||
<Button.Label>确认</Button.Label>
|
||||
</>
|
||||
)}
|
||||
</Button>
|
||||
</View>
|
||||
</BottomSheet.Content>
|
||||
|
||||
@@ -9,6 +9,14 @@ export function loginWxApi(params: LoginWxParams) {
|
||||
return alovaInstance.Post<ResponseData<LoginResult>>(`/auth/login/wechat`, params);
|
||||
}
|
||||
|
||||
export function bindQqApi(params: LoginQqParams) {
|
||||
return alovaInstance.Post<ResponseData<null>>(`/bind/qq`, params);
|
||||
}
|
||||
|
||||
export function bindWxApi(params: LoginWxParams) {
|
||||
return alovaInstance.Post<ResponseData<null>>(`/bind/wechat`, params);
|
||||
}
|
||||
|
||||
export function getUniqueIdApi(count = 1) {
|
||||
return alovaInstance.Post<ResponseData<number[]>>(`/data/getUniqueId`, {
|
||||
count: count,
|
||||
@@ -48,10 +56,6 @@ export function saveDataApi(params: SaveDataParams[]) {
|
||||
return alovaInstance.Post<ResponseData<null>>(`/data/saveData`, params);
|
||||
}
|
||||
|
||||
export function s3ListBucketsApi() {
|
||||
return alovaInstance.Post<ResponseData<string[]>>(`/s3/listBuckets`);
|
||||
}
|
||||
|
||||
export function s3UploadFileApi(files: any[]) {
|
||||
const form = new FormData();
|
||||
|
||||
|
||||
@@ -34,35 +34,44 @@ export function getCurrentYear(): string {
|
||||
|
||||
/** 字符串 / 数字 / Date → Date(无效返回 null) */
|
||||
export function toDate(input: string | number | Date | undefined | null): Date | undefined {
|
||||
if (!input) return undefined;
|
||||
if (input === null || input === undefined || input === "") return undefined;
|
||||
|
||||
if (input instanceof Date) return input;
|
||||
|
||||
const d = dayjs(input);
|
||||
return d.isValid() ? d.toDate() : undefined;
|
||||
}
|
||||
|
||||
/** Date → YYYY-MM-DD */
|
||||
export function toDateString(date: string | number | Date): string {
|
||||
const d = dayjs(toDate(date));
|
||||
return d.isValid() ? d.format("YYYY-MM-DD") : "";
|
||||
const parsed = toDate(date);
|
||||
if (!parsed) return "";
|
||||
|
||||
return dayjs(parsed).format("YYYY-MM-DD");
|
||||
}
|
||||
|
||||
/** Date → YYYY-MM */
|
||||
export function toYearMonthString(date: string | number | Date): string {
|
||||
const d = dayjs(toDate(date));
|
||||
return d.isValid() ? d.format("YYYY-MM") : "";
|
||||
const parsed = toDate(date);
|
||||
if (!parsed) return "";
|
||||
|
||||
return dayjs(parsed).format("YYYY-MM");
|
||||
}
|
||||
|
||||
/** Date → HH:mm:ss */
|
||||
export function toTimeString(date: string | number | Date): string {
|
||||
const d = dayjs(toDate(date));
|
||||
return d.isValid() ? d.format("HH:mm:ss") : "";
|
||||
const parsed = toDate(date);
|
||||
if (!parsed) return "";
|
||||
|
||||
return dayjs(parsed).format("HH:mm:ss");
|
||||
}
|
||||
|
||||
/** Date → YYYY-MM-DD HH:mm:ss */
|
||||
export function toDateTimeString(date: string | number | Date): string {
|
||||
const d = dayjs(toDate(date));
|
||||
return d.isValid() ? d.format("YYYY-MM-DD HH:mm:ss") : "";
|
||||
const parsed = toDate(date);
|
||||
if (!parsed) return "";
|
||||
|
||||
return dayjs(parsed).format("YYYY-MM-DD HH:mm:ss");
|
||||
}
|
||||
|
||||
export function isInMonth(date: string, month: string): boolean {
|
||||
|
||||
Reference in new issue
Block a user