style: 代码格式优化
This commit is contained in:
1 parent
a422f9f962
commit
55086c6757
35 files changed
+4045
-3515
No files matched your search
+281
-185
@@ -2,10 +2,27 @@
|
||||
<view class="page py-16rpx">
|
||||
<wd-card>
|
||||
<wd-cell-group border>
|
||||
<wd-cell icon="secured" title="账户密码" value="修改" is-link @click="handleOpenDialog(DialogType.PASSWORD)" />
|
||||
<wd-cell icon="mobile" title="绑定手机" :value="userProfile?.mobile || '未绑定手机号'" is-link @click="handleOpenDialog(DialogType.MOBILE)" />
|
||||
<wd-cell icon="mail" title="绑定邮箱" :value="userProfile?.email ? userProfile.email : '未绑定邮箱'" is-link
|
||||
@click="handleOpenDialog(DialogType.EMAIL)" />
|
||||
<wd-cell
|
||||
icon="secured"
|
||||
title="账户密码"
|
||||
value="修改"
|
||||
is-link
|
||||
@click="handleOpenDialog(DialogType.PASSWORD)"
|
||||
/>
|
||||
<wd-cell
|
||||
icon="mobile"
|
||||
title="绑定手机"
|
||||
:value="userProfile?.mobile || '未绑定手机号'"
|
||||
is-link
|
||||
@click="handleOpenDialog(DialogType.MOBILE)"
|
||||
/>
|
||||
<wd-cell
|
||||
icon="mail"
|
||||
title="绑定邮箱"
|
||||
:value="userProfile?.email ? userProfile.email : '未绑定邮箱'"
|
||||
is-link
|
||||
@click="handleOpenDialog(DialogType.EMAIL)"
|
||||
/>
|
||||
<!-- #ifdef MP-WEIXIN -->
|
||||
<wd-cell icon="wechat" title="微信" value="解绑" is-link @click="handleUnbindWechat" />
|
||||
<!-- #endif -->
|
||||
@@ -13,28 +30,84 @@
|
||||
</wd-card>
|
||||
|
||||
<!--用户信息编辑弹出框-->
|
||||
<wd-popup v-model="dialog.visible" position="bottom" custom-style="border-top-left-radius: 24rpx; border-top-right-radius: 24rpx;">
|
||||
<wd-form v-if="dialog.type === DialogType.PASSWORD" ref="passwordChangeFormRef" :model="passwordChangeForm" custom-class="edit-form">
|
||||
<wd-popup
|
||||
v-model="dialog.visible"
|
||||
position="bottom"
|
||||
custom-style="border-top-left-radius: 24rpx; border-top-right-radius: 24rpx;"
|
||||
>
|
||||
<wd-form
|
||||
v-if="dialog.type === DialogType.PASSWORD"
|
||||
ref="passwordChangeFormRef"
|
||||
:model="passwordChangeForm"
|
||||
custom-class="edit-form"
|
||||
>
|
||||
<wd-cell-group border>
|
||||
<wd-input v-model="passwordChangeForm.oldPassword" label="原密码" label-width="160rpx" show-password clearable placeholder="请输入原密码"
|
||||
prop="oldPassword" :rules="rules.oldPassword" />
|
||||
<wd-input v-model="passwordChangeForm.newPassword" label="新密码" label-width="160rpx" show-password clearable placeholder="请输入新密码"
|
||||
prop="newPassword" :rules="rules.newPassword" />
|
||||
<wd-input v-model="passwordChangeForm.confirmPassword" label="确认密码" label-width="160rpx" show-password clearable placeholder="请确认新密码"
|
||||
prop="confirmPassword" :rules="rules.confirmPassword" />
|
||||
<wd-input
|
||||
v-model="passwordChangeForm.oldPassword"
|
||||
label="原密码"
|
||||
label-width="160rpx"
|
||||
show-password
|
||||
clearable
|
||||
placeholder="请输入原密码"
|
||||
prop="oldPassword"
|
||||
:rules="rules.oldPassword"
|
||||
/>
|
||||
<wd-input
|
||||
v-model="passwordChangeForm.newPassword"
|
||||
label="新密码"
|
||||
label-width="160rpx"
|
||||
show-password
|
||||
clearable
|
||||
placeholder="请输入新密码"
|
||||
prop="newPassword"
|
||||
:rules="rules.newPassword"
|
||||
/>
|
||||
<wd-input
|
||||
v-model="passwordChangeForm.confirmPassword"
|
||||
label="确认密码"
|
||||
label-width="160rpx"
|
||||
show-password
|
||||
clearable
|
||||
placeholder="请确认新密码"
|
||||
prop="confirmPassword"
|
||||
:rules="rules.confirmPassword"
|
||||
/>
|
||||
</wd-cell-group>
|
||||
<view class="p-24rpx">
|
||||
<wd-button type="primary" size="large" block @click="handleSubmit">提交</wd-button>
|
||||
</view>
|
||||
</wd-form>
|
||||
<wd-form v-if="dialog.type === DialogType.MOBILE" ref="mobileBindingFormRef" :model="mobileBindingForm" custom-class="edit-form">
|
||||
<wd-form
|
||||
v-if="dialog.type === DialogType.MOBILE"
|
||||
ref="mobileBindingFormRef"
|
||||
:model="mobileBindingForm"
|
||||
custom-class="edit-form"
|
||||
>
|
||||
<wd-cell-group border>
|
||||
<wd-input v-model="mobileBindingForm.mobile" label="手机号码" label-width="160rpx" clearable placeholder="请输入手机号码" prop="mobile"
|
||||
:rules="rules.mobile" />
|
||||
<wd-input v-model="mobileBindingForm.code" label="验证码" label-width="160rpx" clearable placeholder="请输入验证码" prop="code"
|
||||
:rules="rules.code">
|
||||
<wd-input
|
||||
v-model="mobileBindingForm.mobile"
|
||||
label="手机号码"
|
||||
label-width="160rpx"
|
||||
clearable
|
||||
placeholder="请输入手机号码"
|
||||
prop="mobile"
|
||||
:rules="rules.mobile"
|
||||
/>
|
||||
<wd-input
|
||||
v-model="mobileBindingForm.code"
|
||||
label="验证码"
|
||||
label-width="160rpx"
|
||||
clearable
|
||||
placeholder="请输入验证码"
|
||||
prop="code"
|
||||
:rules="rules.code"
|
||||
>
|
||||
<template #suffix>
|
||||
<wd-button plain :disabled="mobileCountdown > 0" @click="handleSendVerificationCode('MOBILE')">
|
||||
<wd-button
|
||||
plain
|
||||
:disabled="mobileCountdown > 0"
|
||||
@click="handleSendVerificationCode('MOBILE')"
|
||||
>
|
||||
{{ mobileCountdown > 0 ? `${mobileCountdown}s后重新发送` : "发送验证码" }}
|
||||
</wd-button>
|
||||
</template>
|
||||
@@ -44,14 +117,37 @@
|
||||
<wd-button type="primary" size="large" block @click="handleSubmit">提交</wd-button>
|
||||
</view>
|
||||
</wd-form>
|
||||
<wd-form v-if="dialog.type === DialogType.EMAIL" ref="emailBindingFormRef" :model="emailBindingForm" custom-class="edit-form">
|
||||
<wd-form
|
||||
v-if="dialog.type === DialogType.EMAIL"
|
||||
ref="emailBindingFormRef"
|
||||
:model="emailBindingForm"
|
||||
custom-class="edit-form"
|
||||
>
|
||||
<wd-cell-group border>
|
||||
<wd-input v-model="emailBindingForm.email" label="邮箱" label-width="160rpx" clearable placeholder="请输入邮箱" prop="email"
|
||||
:rules="rules.email" />
|
||||
<wd-input v-model="emailBindingForm.code" label="验证码" label-width="160rpx" clearable placeholder="请输入验证码" prop="code"
|
||||
:rules="rules.code">
|
||||
<wd-input
|
||||
v-model="emailBindingForm.email"
|
||||
label="邮箱"
|
||||
label-width="160rpx"
|
||||
clearable
|
||||
placeholder="请输入邮箱"
|
||||
prop="email"
|
||||
:rules="rules.email"
|
||||
/>
|
||||
<wd-input
|
||||
v-model="emailBindingForm.code"
|
||||
label="验证码"
|
||||
label-width="160rpx"
|
||||
clearable
|
||||
placeholder="请输入验证码"
|
||||
prop="code"
|
||||
:rules="rules.code"
|
||||
>
|
||||
<template #suffix>
|
||||
<wd-button plain :disabled="emailCountdown > 0" @click="handleSendVerificationCode('EMAIL')">
|
||||
<wd-button
|
||||
plain
|
||||
:disabled="emailCountdown > 0"
|
||||
@click="handleSendVerificationCode('EMAIL')"
|
||||
>
|
||||
{{ emailCountdown > 0 ? `${emailCountdown}s后重新发送` : "发送验证码" }}
|
||||
</wd-button>
|
||||
</template>
|
||||
@@ -65,172 +161,172 @@
|
||||
</view>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import { onMounted, reactive, ref } from "vue";
|
||||
import { useToast, useDialog } from "@wot-ui/ui";
|
||||
import { useCountdown } from "@/composables/useCountdown";
|
||||
import UserAPI, {
|
||||
PasswordChangeForm,
|
||||
MobileBindingForm,
|
||||
EmailBindingForm,
|
||||
UserProfile,
|
||||
} from "@/api/user";
|
||||
import { onMounted, reactive, ref } from "vue";
|
||||
import { useToast, useDialog } from "@wot-ui/ui";
|
||||
import { useCountdown } from "@/composables/useCountdown";
|
||||
import UserAPI, {
|
||||
PasswordChangeForm,
|
||||
MobileBindingForm,
|
||||
EmailBindingForm,
|
||||
UserProfile,
|
||||
} from "@/api/user";
|
||||
|
||||
const toast = useToast();
|
||||
const { confirm } = useDialog();
|
||||
const toast = useToast();
|
||||
const { confirm } = useDialog();
|
||||
|
||||
const validatorConfirmPassword = (value: string) => {
|
||||
if (!value) {
|
||||
return Promise.reject("请确认密码");
|
||||
const validatorConfirmPassword = (value: string) => {
|
||||
if (!value) {
|
||||
return Promise.reject("请确认密码");
|
||||
} else {
|
||||
if (value !== passwordChangeForm.newPassword) {
|
||||
return Promise.reject("两次输入的密码不一致");
|
||||
} else {
|
||||
if (value !== passwordChangeForm.newPassword) {
|
||||
return Promise.reject("两次输入的密码不一致");
|
||||
} else {
|
||||
return Promise.resolve();
|
||||
}
|
||||
}
|
||||
};
|
||||
// 本页面中所有的校验规则
|
||||
const rules = reactive({
|
||||
oldPassword: [{ required: true, message: "请填写原密码" }],
|
||||
newPassword: [{ required: true, message: "请填写新密码" }],
|
||||
confirmPassword: [{ required: true, message: "请确认密码", validator: validatorConfirmPassword }],
|
||||
mobile: [{ required: true, pattern: /^1[3-9]\d{9}$/, message: "请填写正确的手机号码" }],
|
||||
code: [{ required: true, message: "请填写验证码" }],
|
||||
email: [
|
||||
{
|
||||
required: true,
|
||||
pattern: /\w[-\w.+]*@([A-Za-z0-9][-A-Za-z0-9]+\.)+[A-Za-z]{2,14}/,
|
||||
message: "请填写正确的邮箱地址",
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
enum DialogType {
|
||||
PASSWORD = "password",
|
||||
MOBILE = "mobile",
|
||||
EMAIL = "email",
|
||||
}
|
||||
|
||||
const dialog = reactive({
|
||||
visible: false,
|
||||
type: "" as DialogType, // 修改账号资料,修改密码、绑定手机、绑定邮箱
|
||||
});
|
||||
|
||||
const userProfile = ref<UserProfile>(); //用户信息
|
||||
const passwordChangeForm = reactive<PasswordChangeForm>({});
|
||||
const mobileBindingForm = reactive<MobileBindingForm>({});
|
||||
const emailBindingForm = reactive<EmailBindingForm>({});
|
||||
const passwordChangeFormRef = ref();
|
||||
const mobileBindingFormRef = ref();
|
||||
const emailBindingFormRef = ref();
|
||||
|
||||
const { countdown: mobileCountdown, start: startMobileCountdown } = useCountdown(60);
|
||||
const { countdown: emailCountdown, start: startEmailCountdown } = useCountdown(60);
|
||||
|
||||
const handleUnbindWechat = async () => {
|
||||
try {
|
||||
await confirm({
|
||||
title: "提示",
|
||||
msg: "确定要解绑微信吗?解绑后将无法使用微信小程序登录",
|
||||
headerImage: "warning"
|
||||
});
|
||||
await UserAPI.unbindSocial("WECHAT_MINI");
|
||||
toast.success("解绑成功");
|
||||
loadUserProfile();
|
||||
} catch {
|
||||
// 用户取消或解绑失败
|
||||
}
|
||||
};
|
||||
|
||||
/** 加载用户信息 */
|
||||
const loadUserProfile = async () => {
|
||||
userProfile.value = await UserAPI.getProfile();
|
||||
};
|
||||
|
||||
/**
|
||||
* 打开弹窗
|
||||
* @param type 弹窗类型 ACCOUNT: 账号资料 PASSWORD: 修改密码 MOBILE: 绑定手机 EMAIL: 绑定邮箱
|
||||
*/
|
||||
const handleOpenDialog = (type: DialogType) => {
|
||||
dialog.type = type;
|
||||
dialog.visible = true;
|
||||
switch (type) {
|
||||
case DialogType.PASSWORD:
|
||||
passwordChangeForm.oldPassword = "";
|
||||
passwordChangeForm.newPassword = "";
|
||||
passwordChangeForm.confirmPassword = "";
|
||||
break;
|
||||
case DialogType.MOBILE:
|
||||
mobileBindingForm.mobile = "";
|
||||
mobileBindingForm.code = "";
|
||||
break;
|
||||
case DialogType.EMAIL:
|
||||
emailBindingForm.email = "";
|
||||
emailBindingForm.code = "";
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 发送验证码
|
||||
*
|
||||
* @param contactType 联系方式类型 MOBILE: 手机号码 EMAIL: 邮箱
|
||||
*/
|
||||
const handleSendVerificationCode = async (contactType: string) => {
|
||||
try {
|
||||
if (contactType === "MOBILE") {
|
||||
const { valid } = await mobileBindingFormRef.value.validate("mobile");
|
||||
if (valid) {
|
||||
await UserAPI.sendVerificationCode(mobileBindingForm.mobile!, "MOBILE");
|
||||
uni.showToast({ title: "验证码已发送", icon: "none" });
|
||||
startMobileCountdown();
|
||||
}
|
||||
} else if (contactType === "EMAIL") {
|
||||
const { valid } = await emailBindingFormRef.value.validate("email");
|
||||
if (valid) {
|
||||
await UserAPI.sendVerificationCode(emailBindingForm.email!, "EMAIL");
|
||||
uni.showToast({ title: "验证码已发送", icon: "none" });
|
||||
startEmailCountdown();
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("发送验证码失败:", error);
|
||||
}
|
||||
};
|
||||
|
||||
// 提交表单
|
||||
async function handleSubmit() {
|
||||
try {
|
||||
if (dialog.type === DialogType.PASSWORD) {
|
||||
const { valid } = await passwordChangeFormRef.value.validate();
|
||||
if (valid) {
|
||||
await UserAPI.changePassword(passwordChangeForm);
|
||||
uni.showToast({ title: "密码修改成功", icon: "none" });
|
||||
dialog.visible = false;
|
||||
}
|
||||
} else if (dialog.type === DialogType.MOBILE) {
|
||||
const { valid } = await mobileBindingFormRef.value.validate();
|
||||
if (valid) {
|
||||
await UserAPI.bindMobile(mobileBindingForm);
|
||||
uni.showToast({ title: "手机号绑定成功", icon: "none" });
|
||||
dialog.visible = false;
|
||||
loadUserProfile();
|
||||
}
|
||||
} else if (dialog.type === DialogType.EMAIL) {
|
||||
const { valid } = await emailBindingFormRef.value.validate();
|
||||
if (valid) {
|
||||
await UserAPI.bindEmail(emailBindingForm);
|
||||
uni.showToast({ title: "邮箱绑定成功", icon: "none" });
|
||||
dialog.visible = false;
|
||||
loadUserProfile();
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("提交表单失败:", error);
|
||||
return Promise.resolve();
|
||||
}
|
||||
}
|
||||
};
|
||||
// 本页面中所有的校验规则
|
||||
const rules = reactive({
|
||||
oldPassword: [{ required: true, message: "请填写原密码" }],
|
||||
newPassword: [{ required: true, message: "请填写新密码" }],
|
||||
confirmPassword: [{ required: true, message: "请确认密码", validator: validatorConfirmPassword }],
|
||||
mobile: [{ required: true, pattern: /^1[3-9]\d{9}$/, message: "请填写正确的手机号码" }],
|
||||
code: [{ required: true, message: "请填写验证码" }],
|
||||
email: [
|
||||
{
|
||||
required: true,
|
||||
pattern: /\w[-\w.+]*@([A-Za-z0-9][-A-Za-z0-9]+\.)+[A-Za-z]{2,14}/,
|
||||
message: "请填写正确的邮箱地址",
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
onMounted(() => {
|
||||
enum DialogType {
|
||||
PASSWORD = "password",
|
||||
MOBILE = "mobile",
|
||||
EMAIL = "email",
|
||||
}
|
||||
|
||||
const dialog = reactive({
|
||||
visible: false,
|
||||
type: "" as DialogType, // 修改账号资料,修改密码、绑定手机、绑定邮箱
|
||||
});
|
||||
|
||||
const userProfile = ref<UserProfile>(); //用户信息
|
||||
const passwordChangeForm = reactive<PasswordChangeForm>({});
|
||||
const mobileBindingForm = reactive<MobileBindingForm>({});
|
||||
const emailBindingForm = reactive<EmailBindingForm>({});
|
||||
const passwordChangeFormRef = ref();
|
||||
const mobileBindingFormRef = ref();
|
||||
const emailBindingFormRef = ref();
|
||||
|
||||
const { countdown: mobileCountdown, start: startMobileCountdown } = useCountdown(60);
|
||||
const { countdown: emailCountdown, start: startEmailCountdown } = useCountdown(60);
|
||||
|
||||
const handleUnbindWechat = async () => {
|
||||
try {
|
||||
await confirm({
|
||||
title: "提示",
|
||||
msg: "确定要解绑微信吗?解绑后将无法使用微信小程序登录",
|
||||
headerImage: "warning",
|
||||
});
|
||||
await UserAPI.unbindSocial("WECHAT_MINI");
|
||||
toast.success("解绑成功");
|
||||
loadUserProfile();
|
||||
});
|
||||
} catch {
|
||||
// 用户取消或解绑失败
|
||||
}
|
||||
};
|
||||
|
||||
/** 加载用户信息 */
|
||||
const loadUserProfile = async () => {
|
||||
userProfile.value = await UserAPI.getProfile();
|
||||
};
|
||||
|
||||
/**
|
||||
* 打开弹窗
|
||||
* @param type 弹窗类型 ACCOUNT: 账号资料 PASSWORD: 修改密码 MOBILE: 绑定手机 EMAIL: 绑定邮箱
|
||||
*/
|
||||
const handleOpenDialog = (type: DialogType) => {
|
||||
dialog.type = type;
|
||||
dialog.visible = true;
|
||||
switch (type) {
|
||||
case DialogType.PASSWORD:
|
||||
passwordChangeForm.oldPassword = "";
|
||||
passwordChangeForm.newPassword = "";
|
||||
passwordChangeForm.confirmPassword = "";
|
||||
break;
|
||||
case DialogType.MOBILE:
|
||||
mobileBindingForm.mobile = "";
|
||||
mobileBindingForm.code = "";
|
||||
break;
|
||||
case DialogType.EMAIL:
|
||||
emailBindingForm.email = "";
|
||||
emailBindingForm.code = "";
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 发送验证码
|
||||
*
|
||||
* @param contactType 联系方式类型 MOBILE: 手机号码 EMAIL: 邮箱
|
||||
*/
|
||||
const handleSendVerificationCode = async (contactType: string) => {
|
||||
try {
|
||||
if (contactType === "MOBILE") {
|
||||
const { valid } = await mobileBindingFormRef.value.validate("mobile");
|
||||
if (valid) {
|
||||
await UserAPI.sendVerificationCode(mobileBindingForm.mobile!, "MOBILE");
|
||||
uni.showToast({ title: "验证码已发送", icon: "none" });
|
||||
startMobileCountdown();
|
||||
}
|
||||
} else if (contactType === "EMAIL") {
|
||||
const { valid } = await emailBindingFormRef.value.validate("email");
|
||||
if (valid) {
|
||||
await UserAPI.sendVerificationCode(emailBindingForm.email!, "EMAIL");
|
||||
uni.showToast({ title: "验证码已发送", icon: "none" });
|
||||
startEmailCountdown();
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("发送验证码失败:", error);
|
||||
}
|
||||
};
|
||||
|
||||
// 提交表单
|
||||
async function handleSubmit() {
|
||||
try {
|
||||
if (dialog.type === DialogType.PASSWORD) {
|
||||
const { valid } = await passwordChangeFormRef.value.validate();
|
||||
if (valid) {
|
||||
await UserAPI.changePassword(passwordChangeForm);
|
||||
uni.showToast({ title: "密码修改成功", icon: "none" });
|
||||
dialog.visible = false;
|
||||
}
|
||||
} else if (dialog.type === DialogType.MOBILE) {
|
||||
const { valid } = await mobileBindingFormRef.value.validate();
|
||||
if (valid) {
|
||||
await UserAPI.bindMobile(mobileBindingForm);
|
||||
uni.showToast({ title: "手机号绑定成功", icon: "none" });
|
||||
dialog.visible = false;
|
||||
loadUserProfile();
|
||||
}
|
||||
} else if (dialog.type === DialogType.EMAIL) {
|
||||
const { valid } = await emailBindingFormRef.value.validate();
|
||||
if (valid) {
|
||||
await UserAPI.bindEmail(emailBindingForm);
|
||||
uni.showToast({ title: "邮箱绑定成功", icon: "none" });
|
||||
dialog.visible = false;
|
||||
loadUserProfile();
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("提交表单失败:", error);
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
loadUserProfile();
|
||||
});
|
||||
</script>
|
||||
+683
-686
File diff suppressed because it is too large.
Load diff
@@ -21,9 +21,7 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
|
||||
|
||||
import { onLoad } from "@dcloudio/uni-app";
|
||||
import { onLoad } from "@dcloudio/uni-app";
|
||||
|
||||
definePage({
|
||||
name: "official",
|
||||
@@ -38,8 +36,8 @@ onLoad(() => {
|
||||
<style lang="scss" scoped>
|
||||
.brand {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 20rpx;
|
||||
align-items: center;
|
||||
padding: 28rpx;
|
||||
background: var(--color-bg);
|
||||
border-radius: 20rpx;
|
||||
@@ -70,8 +68,8 @@ onLoad(() => {
|
||||
}
|
||||
|
||||
.tip {
|
||||
margin-top: 20rpx;
|
||||
padding: 20rpx;
|
||||
margin-top: 20rpx;
|
||||
font-size: 26rpx;
|
||||
line-height: 1.6;
|
||||
color: var(--color-text);
|
||||
@@ -80,8 +78,8 @@ onLoad(() => {
|
||||
}
|
||||
|
||||
.qrcode-card {
|
||||
margin-top: 24rpx;
|
||||
padding: 28rpx;
|
||||
margin-top: 24rpx;
|
||||
background: var(--color-bg);
|
||||
border-radius: 20rpx;
|
||||
box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.04);
|
||||
@@ -94,8 +92,8 @@ onLoad(() => {
|
||||
|
||||
.qrcode-hint {
|
||||
margin-top: 20rpx;
|
||||
text-align: center;
|
||||
font-size: 26rpx;
|
||||
color: var(--color-text-secondary);
|
||||
text-align: center;
|
||||
}
|
||||
</style>
|
||||
@@ -14,364 +14,411 @@
|
||||
<view class="profile-form__label">头像</view>
|
||||
<view class="avatar-picker">
|
||||
<!-- #ifdef MP-WEIXIN -->
|
||||
<button class="avatar-picker__trigger" open-type="chooseAvatar" @chooseavatar="onChooseAvatar">
|
||||
<!-- #endif -->
|
||||
<!-- #ifndef MP-WEIXIN -->
|
||||
<view class="avatar-picker__trigger" @click="chooseAvatar">
|
||||
<!-- #endif -->
|
||||
<image v-if="profileForm.avatar" :src="profileForm.avatar" class="avatar-picker__img" mode="aspectFill" />
|
||||
<view v-else class="avatar-picker__placeholder">
|
||||
<wd-icon name="camera" size="40" color="var(--color-text-placeholder)" />
|
||||
<text class="avatar-picker__hint">选择头像</text>
|
||||
</view>
|
||||
|
||||
<!-- #ifdef MP-WEIXIN -->
|
||||
<button
|
||||
class="avatar-picker__trigger"
|
||||
open-type="chooseAvatar"
|
||||
@chooseavatar="onChooseAvatar"
|
||||
>
|
||||
<image
|
||||
v-if="profileForm.avatar"
|
||||
:src="profileForm.avatar"
|
||||
class="avatar-picker__img"
|
||||
mode="aspectFill"
|
||||
/>
|
||||
<view v-else class="avatar-picker__placeholder">
|
||||
<wd-icon name="camera" size="40" color="var(--color-text-placeholder)" />
|
||||
<text class="avatar-picker__hint">选择头像</text>
|
||||
</view>
|
||||
</button>
|
||||
<!-- #endif -->
|
||||
|
||||
<!-- #ifndef MP-WEIXIN -->
|
||||
<view class="avatar-picker__trigger" @click="chooseAvatar">
|
||||
<image
|
||||
v-if="profileForm.avatar"
|
||||
:src="profileForm.avatar"
|
||||
class="avatar-picker__img"
|
||||
mode="aspectFill"
|
||||
/>
|
||||
<view v-else class="avatar-picker__placeholder">
|
||||
<wd-icon name="camera" size="40" color="var(--color-text-placeholder)" />
|
||||
<text class="avatar-picker__hint">选择头像</text>
|
||||
</view>
|
||||
</view>
|
||||
<!-- #endif -->
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 昵称 -->
|
||||
<view class="profile-form__section">
|
||||
<view class="profile-form__label">
|
||||
昵称
|
||||
<text class="profile-form__required">*</text>
|
||||
</view>
|
||||
<!-- #ifdef MP-WEIXIN -->
|
||||
<input
|
||||
v-model="profileForm.nickname"
|
||||
type="nickname"
|
||||
class="profile-form__nickname-input"
|
||||
placeholder="请输入昵称"
|
||||
:maxlength="20"
|
||||
/>
|
||||
<!-- #endif -->
|
||||
<!-- #ifndef MP-WEIXIN -->
|
||||
<wd-input
|
||||
v-model="profileForm.nickname"
|
||||
placeholder="请输入昵称"
|
||||
prop="nickname"
|
||||
:rules="rules.nickname"
|
||||
custom-class="profile-form__nickname-input"
|
||||
/>
|
||||
<!-- #endif -->
|
||||
</view>
|
||||
|
||||
<!-- 性别 -->
|
||||
<view class="profile-form__section">
|
||||
<view class="profile-form__label">性别</view>
|
||||
<wd-radio-group v-model="profileForm.gender" type="button" class="gender-group">
|
||||
<wd-radio :value="1" class="gender-radio">男</wd-radio>
|
||||
<wd-radio :value="2" class="gender-radio">女</wd-radio>
|
||||
</wd-radio-group>
|
||||
</view>
|
||||
|
||||
<!-- 手机号 -->
|
||||
<view class="profile-form__section">
|
||||
<view class="profile-form__label">
|
||||
手机号
|
||||
<text class="profile-form__required">*</text>
|
||||
</view>
|
||||
<wd-input
|
||||
v-model="profileForm.mobile"
|
||||
placeholder="请输入手机号"
|
||||
prop="mobile"
|
||||
custom-class="profile-form__nickname-input"
|
||||
/>
|
||||
</view>
|
||||
</wd-form>
|
||||
</view>
|
||||
|
||||
<!-- 昵称 -->
|
||||
<view class="profile-form__section">
|
||||
<view class="profile-form__label">
|
||||
昵称
|
||||
<text class="profile-form__required">*</text>
|
||||
<!-- 底部 -->
|
||||
<view class="profile-footer">
|
||||
<wd-button
|
||||
class="profile-footer__submit"
|
||||
type="primary"
|
||||
size="large"
|
||||
block
|
||||
:disabled="!canComplete || isLoading"
|
||||
:loading="isLoading"
|
||||
@click="handleComplete"
|
||||
>
|
||||
完成
|
||||
</wd-button>
|
||||
<view class="profile-footer__skip" @click="handleSkip">
|
||||
<text>暂时跳过</text>
|
||||
</view>
|
||||
<!-- #ifdef MP-WEIXIN -->
|
||||
<input v-model="profileForm.nickname" type="nickname" class="profile-form__nickname-input" placeholder="请输入昵称" :maxlength="20" />
|
||||
<!-- #endif -->
|
||||
<!-- #ifndef MP-WEIXIN -->
|
||||
<wd-input v-model="profileForm.nickname" placeholder="请输入昵称" prop="nickname" :rules="rules.nickname"
|
||||
custom-class="profile-form__nickname-input" />
|
||||
<!-- #endif -->
|
||||
</view>
|
||||
|
||||
<!-- 性别 -->
|
||||
<view class="profile-form__section">
|
||||
<view class="profile-form__label">性别</view>
|
||||
<wd-radio-group v-model="profileForm.gender" type="button" class="gender-group">
|
||||
<wd-radio :value="1" class="gender-radio">男</wd-radio>
|
||||
<wd-radio :value="2" class="gender-radio">女</wd-radio>
|
||||
</wd-radio-group>
|
||||
</view>
|
||||
<!-- 头像裁剪 -->
|
||||
<wd-img-cropper
|
||||
v-model="cropperVisible"
|
||||
:img-src="originalImageSrc"
|
||||
@confirm="handleAvatarConfirm"
|
||||
/>
|
||||
|
||||
<!-- 手机号 -->
|
||||
<view class="profile-form__section">
|
||||
<view class="profile-form__label">
|
||||
手机号
|
||||
<text class="profile-form__required">*</text>
|
||||
</view>
|
||||
<wd-input v-model="profileForm.mobile" placeholder="请输入手机号" prop="mobile" custom-class="profile-form__nickname-input" />
|
||||
</view>
|
||||
</wd-form>
|
||||
</view>
|
||||
|
||||
<!-- 底部 -->
|
||||
<view class="profile-footer">
|
||||
<wd-button class="profile-footer__submit" type="primary" size="large" block :disabled="!canComplete || isLoading" :loading="isLoading"
|
||||
@click="handleComplete">
|
||||
完成
|
||||
</wd-button>
|
||||
<view class="profile-footer__skip" @click="handleSkip">
|
||||
<text>暂时跳过</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 头像裁剪 -->
|
||||
<wd-img-cropper v-model="cropperVisible" :img-src="originalImageSrc" @confirm="handleAvatarConfirm" />
|
||||
|
||||
<wd-toast />
|
||||
<wd-toast />
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { ref, reactive, computed } from "vue";
|
||||
import { onLoad } from "@dcloudio/uni-app";
|
||||
import { useUserStore } from "@/store";
|
||||
import UserAPI, { type UserProfileForm } from "@/api/user";
|
||||
import FileAPI, { type FileInfo } from "@/api/file";
|
||||
import { ref, reactive, computed } from "vue";
|
||||
import { onLoad } from "@dcloudio/uni-app";
|
||||
import { useDialog, useToast } from "@wot-ui/ui";
|
||||
import { useUserStore } from "@/store";
|
||||
import UserAPI, { type UserProfileForm } from "@/api/user";
|
||||
import FileAPI, { type FileInfo } from "@/api/file";
|
||||
|
||||
const toast = useToast();
|
||||
const { confirm } = useDialog();
|
||||
const userStore = useUserStore();
|
||||
const toast = useToast();
|
||||
const { confirm } = useDialog();
|
||||
const userStore = useUserStore();
|
||||
|
||||
const redirect = ref("/pages/index/index");
|
||||
const redirect = ref("/pages/index/index");
|
||||
|
||||
const profileForm = reactive<UserProfileForm & { mobile?: string }>({
|
||||
nickname: "",
|
||||
avatar: "",
|
||||
gender: 1,
|
||||
mobile: "",
|
||||
const profileForm = reactive<UserProfileForm & { mobile?: string }>({
|
||||
nickname: "",
|
||||
avatar: "",
|
||||
gender: 1,
|
||||
mobile: "",
|
||||
});
|
||||
|
||||
const rules = {
|
||||
nickname: [
|
||||
{ required: true, message: "请输入昵称" },
|
||||
{ required: true, min: 2, max: 20, message: "昵称长度为2-20个字符" },
|
||||
],
|
||||
};
|
||||
|
||||
const isLoading = ref(false);
|
||||
const cropperVisible = ref(false);
|
||||
const originalImageSrc = ref("");
|
||||
const profileFormRef = ref();
|
||||
|
||||
const canComplete = computed(() => {
|
||||
return profileForm.nickname && profileForm.mobile;
|
||||
});
|
||||
|
||||
onLoad((options: any) => {
|
||||
if (options?.redirect) {
|
||||
redirect.value = decodeURIComponent(options.redirect);
|
||||
}
|
||||
const userInfo = userStore.userInfo;
|
||||
if (userInfo) {
|
||||
profileForm.nickname = userInfo.nickname || "";
|
||||
profileForm.avatar = userInfo.avatar || "";
|
||||
profileForm.gender = (userInfo as any).gender || 1;
|
||||
}
|
||||
});
|
||||
|
||||
const onChooseAvatar = async (e: any) => {
|
||||
try {
|
||||
const { avatarUrl } = e.detail;
|
||||
toast.loading("上传中...");
|
||||
const fileInfo: FileInfo = await FileAPI.upload(avatarUrl);
|
||||
profileForm.avatar = fileInfo.url;
|
||||
toast.success("头像上传成功");
|
||||
} catch {
|
||||
toast.error("头像上传失败");
|
||||
}
|
||||
};
|
||||
|
||||
const chooseAvatar = () => {
|
||||
// #ifdef MP-WEIXIN
|
||||
uni.chooseMedia({
|
||||
count: 1,
|
||||
mediaType: ["image"],
|
||||
sourceType: ["album", "camera"],
|
||||
success: (res) => {
|
||||
originalImageSrc.value = res.tempFiles[0].tempFilePath;
|
||||
cropperVisible.value = true;
|
||||
},
|
||||
fail: () => {
|
||||
toast.error("选择图片失败");
|
||||
},
|
||||
});
|
||||
// #endif
|
||||
|
||||
const rules = {
|
||||
nickname: [
|
||||
{ required: true, message: "请输入昵称" },
|
||||
{ required: true, min: 2, max: 20, message: "昵称长度为2-20个字符" },
|
||||
],
|
||||
};
|
||||
|
||||
const isLoading = ref(false);
|
||||
const cropperVisible = ref(false);
|
||||
const originalImageSrc = ref("");
|
||||
const profileFormRef = ref();
|
||||
|
||||
const canComplete = computed(() => {
|
||||
return profileForm.nickname && profileForm.mobile;
|
||||
// #ifndef MP-WEIXIN
|
||||
uni.chooseImage({
|
||||
count: 1,
|
||||
sourceType: ["album", "camera"],
|
||||
success: (res) => {
|
||||
originalImageSrc.value = res.tempFilePaths[0];
|
||||
cropperVisible.value = true;
|
||||
},
|
||||
fail: () => {
|
||||
toast.error("选择图片失败");
|
||||
},
|
||||
});
|
||||
// #endif
|
||||
};
|
||||
|
||||
onLoad((options: any) => {
|
||||
if (options?.redirect) {
|
||||
redirect.value = decodeURIComponent(options.redirect);
|
||||
}
|
||||
const userInfo = userStore.userInfo;
|
||||
if (userInfo) {
|
||||
profileForm.nickname = userInfo.nickname || "";
|
||||
profileForm.avatar = userInfo.avatar || "";
|
||||
profileForm.gender = (userInfo as any).gender || 1;
|
||||
}
|
||||
});
|
||||
const handleAvatarConfirm = async (event: any) => {
|
||||
try {
|
||||
const { tempFilePath } = event;
|
||||
toast.loading("上传中...");
|
||||
const fileInfo: FileInfo = await FileAPI.upload(tempFilePath);
|
||||
profileForm.avatar = fileInfo.url;
|
||||
toast.success("头像上传成功");
|
||||
} catch {
|
||||
toast.error("头像上传失败");
|
||||
}
|
||||
};
|
||||
|
||||
const onChooseAvatar = async (e: any) => {
|
||||
try {
|
||||
const { avatarUrl } = e.detail;
|
||||
toast.loading("上传中...");
|
||||
const fileInfo: FileInfo = await FileAPI.upload(avatarUrl);
|
||||
profileForm.avatar = fileInfo.url;
|
||||
toast.success("头像上传成功");
|
||||
} catch {
|
||||
toast.error("头像上传失败");
|
||||
}
|
||||
};
|
||||
const handleComplete = async () => {
|
||||
try {
|
||||
const { valid } = await profileFormRef.value.validate();
|
||||
if (!valid) return;
|
||||
|
||||
const chooseAvatar = () => {
|
||||
// #ifdef MP-WEIXIN
|
||||
uni.chooseMedia({
|
||||
count: 1,
|
||||
mediaType: ["image"],
|
||||
sourceType: ["album", "camera"],
|
||||
success: (res) => {
|
||||
originalImageSrc.value = res.tempFiles[0].tempFilePath;
|
||||
cropperVisible.value = true;
|
||||
},
|
||||
fail: () => {
|
||||
toast.error("选择图片失败");
|
||||
},
|
||||
if (!profileForm.mobile) {
|
||||
toast.error("请输入手机号");
|
||||
return;
|
||||
}
|
||||
|
||||
isLoading.value = true;
|
||||
|
||||
await UserAPI.updateProfile({
|
||||
nickname: profileForm.nickname,
|
||||
avatar: profileForm.avatar,
|
||||
gender: profileForm.gender,
|
||||
});
|
||||
// #endif
|
||||
|
||||
// #ifndef MP-WEIXIN
|
||||
uni.chooseImage({
|
||||
count: 1,
|
||||
sourceType: ["album", "camera"],
|
||||
success: (res) => {
|
||||
originalImageSrc.value = res.tempFilePaths[0];
|
||||
cropperVisible.value = true;
|
||||
},
|
||||
fail: () => {
|
||||
toast.error("选择图片失败");
|
||||
},
|
||||
});
|
||||
// #endif
|
||||
};
|
||||
|
||||
const handleAvatarConfirm = async (event: any) => {
|
||||
try {
|
||||
const { tempFilePath } = event;
|
||||
toast.loading("上传中...");
|
||||
const fileInfo: FileInfo = await FileAPI.upload(tempFilePath);
|
||||
profileForm.avatar = fileInfo.url;
|
||||
toast.success("头像上传成功");
|
||||
} catch {
|
||||
toast.error("头像上传失败");
|
||||
if (profileForm.mobile) {
|
||||
await UserAPI.bindMobile({ mobile: profileForm.mobile });
|
||||
}
|
||||
};
|
||||
|
||||
const handleComplete = async () => {
|
||||
try {
|
||||
const { valid } = await profileFormRef.value.validate();
|
||||
if (!valid) return;
|
||||
await userStore.getInfo();
|
||||
toast.success("信息完善成功");
|
||||
|
||||
if (!profileForm.mobile) {
|
||||
toast.error("请输入手机号");
|
||||
return;
|
||||
}
|
||||
|
||||
isLoading.value = true;
|
||||
|
||||
await UserAPI.updateProfile({
|
||||
nickname: profileForm.nickname,
|
||||
avatar: profileForm.avatar,
|
||||
gender: profileForm.gender,
|
||||
});
|
||||
|
||||
if (profileForm.mobile) {
|
||||
await UserAPI.bindMobile({ mobile: profileForm.mobile });
|
||||
}
|
||||
|
||||
await userStore.getInfo();
|
||||
toast.success("信息完善成功");
|
||||
|
||||
setTimeout(() => {
|
||||
uni.reLaunch({ url: redirect.value });
|
||||
}, 1000);
|
||||
} catch (error: any) {
|
||||
toast.error(error?.message || "完善信息失败");
|
||||
} finally {
|
||||
isLoading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
const handleSkip = async () => {
|
||||
try {
|
||||
await confirm({ title: "提示", msg: "跳过信息完善可能会影响部分功能使用,确定要跳过吗?", headerImage: "warning" });
|
||||
setTimeout(() => {
|
||||
uni.reLaunch({ url: redirect.value });
|
||||
} catch {
|
||||
// 用户取消
|
||||
}
|
||||
};
|
||||
}, 1000);
|
||||
} catch (error: any) {
|
||||
toast.error(error?.message || "完善信息失败");
|
||||
} finally {
|
||||
isLoading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
const handleSkip = async () => {
|
||||
try {
|
||||
await confirm({
|
||||
title: "提示",
|
||||
msg: "跳过信息完善可能会影响部分功能使用,确定要跳过吗?",
|
||||
headerImage: "warning",
|
||||
});
|
||||
uni.reLaunch({ url: redirect.value });
|
||||
} catch {
|
||||
// 用户取消
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.complete-profile__hero {
|
||||
margin-bottom: 60rpx;
|
||||
text-align: center;
|
||||
}
|
||||
.complete-profile__hero {
|
||||
margin-bottom: 60rpx;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.complete-profile__hero-title {
|
||||
margin-bottom: 20rpx;
|
||||
font-size: 48rpx;
|
||||
font-weight: bold;
|
||||
color: var(--color-text-inverse);
|
||||
}
|
||||
.complete-profile__hero-title {
|
||||
margin-bottom: 20rpx;
|
||||
font-size: 48rpx;
|
||||
font-weight: bold;
|
||||
color: var(--color-text-inverse);
|
||||
}
|
||||
|
||||
.complete-profile__hero-subtitle {
|
||||
font-size: 28rpx;
|
||||
line-height: 1.5;
|
||||
color: rgba(255, 255, 255, 0.8);
|
||||
}
|
||||
.complete-profile__hero-subtitle {
|
||||
font-size: 28rpx;
|
||||
line-height: 1.5;
|
||||
color: rgba(255, 255, 255, 0.8);
|
||||
}
|
||||
|
||||
.profile-form {
|
||||
padding: 40rpx;
|
||||
.profile-form {
|
||||
padding: 40rpx;
|
||||
margin-bottom: 40rpx;
|
||||
background: var(--color-bg);
|
||||
border-radius: 24rpx;
|
||||
box-shadow: 0 8rpx 40rpx rgba(0, 0, 0, 0.1);
|
||||
|
||||
&__section {
|
||||
margin-bottom: 40rpx;
|
||||
background: var(--color-bg);
|
||||
border-radius: 24rpx;
|
||||
box-shadow: 0 8rpx 40rpx rgba(0, 0, 0, 0.1);
|
||||
|
||||
&__section {
|
||||
margin-bottom: 40rpx;
|
||||
|
||||
&:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
&:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
}
|
||||
|
||||
&__label {
|
||||
margin-bottom: 20rpx;
|
||||
&__label {
|
||||
margin-bottom: 20rpx;
|
||||
font-size: 32rpx;
|
||||
font-weight: 600;
|
||||
color: var(--color-text);
|
||||
}
|
||||
|
||||
&__required {
|
||||
color: var(--color-danger);
|
||||
}
|
||||
|
||||
&__nickname-input {
|
||||
:deep(.wd-input__inner) {
|
||||
padding: 24rpx 20rpx;
|
||||
background: var(--color-bg-tertiary);
|
||||
border: 1rpx solid var(--color-border-light);
|
||||
border-radius: 12rpx;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.avatar-picker {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
|
||||
&__trigger {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 160rpx;
|
||||
height: 160rpx;
|
||||
padding: 0;
|
||||
margin: 0 auto;
|
||||
overflow: hidden;
|
||||
background: transparent;
|
||||
border: none;
|
||||
border-radius: 50%;
|
||||
|
||||
&::after {
|
||||
border: none;
|
||||
}
|
||||
}
|
||||
|
||||
&__img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
border: 4rpx solid var(--color-border-light);
|
||||
border-radius: 50%;
|
||||
}
|
||||
|
||||
&__placeholder {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 160rpx;
|
||||
height: 160rpx;
|
||||
background: var(--color-bg-tertiary);
|
||||
border: 2rpx dashed var(--color-border);
|
||||
border-radius: 50%;
|
||||
}
|
||||
|
||||
&__hint {
|
||||
margin-top: 10rpx;
|
||||
font-size: 24rpx;
|
||||
color: var(--color-text-placeholder);
|
||||
}
|
||||
}
|
||||
|
||||
.gender-group {
|
||||
display: flex;
|
||||
gap: 20rpx;
|
||||
|
||||
.gender-radio {
|
||||
flex: 1;
|
||||
|
||||
:deep(.wd-radio) {
|
||||
justify-content: center;
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.profile-footer {
|
||||
&__submit {
|
||||
margin-bottom: 30rpx;
|
||||
|
||||
:deep(.wd-button) {
|
||||
height: 88rpx;
|
||||
font-size: 32rpx;
|
||||
font-weight: 600;
|
||||
color: var(--color-text);
|
||||
}
|
||||
|
||||
&__required {
|
||||
color: var(--color-danger);
|
||||
}
|
||||
|
||||
&__nickname-input {
|
||||
:deep(.wd-input__inner) {
|
||||
padding: 24rpx 20rpx;
|
||||
background: var(--color-bg-tertiary);
|
||||
border: 1rpx solid var(--color-border-light);
|
||||
border-radius: 12rpx;
|
||||
}
|
||||
border-radius: 44rpx;
|
||||
}
|
||||
}
|
||||
|
||||
.avatar-picker {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
&__skip {
|
||||
text-align: center;
|
||||
|
||||
&__trigger {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 160rpx;
|
||||
height: 160rpx;
|
||||
padding: 0;
|
||||
margin: 0 auto;
|
||||
overflow: hidden;
|
||||
background: transparent;
|
||||
border: none;
|
||||
border-radius: 50%;
|
||||
|
||||
&::after {
|
||||
border: none;
|
||||
}
|
||||
}
|
||||
|
||||
&__img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
border: 4rpx solid var(--color-border-light);
|
||||
border-radius: 50%;
|
||||
}
|
||||
|
||||
&__placeholder {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 160rpx;
|
||||
height: 160rpx;
|
||||
background: var(--color-bg-tertiary);
|
||||
border: 2rpx dashed var(--color-border);
|
||||
border-radius: 50%;
|
||||
}
|
||||
|
||||
&__hint {
|
||||
margin-top: 10rpx;
|
||||
font-size: 24rpx;
|
||||
color: var(--color-text-placeholder);
|
||||
}
|
||||
}
|
||||
|
||||
.gender-group {
|
||||
display: flex;
|
||||
gap: 20rpx;
|
||||
|
||||
.gender-radio {
|
||||
flex: 1;
|
||||
|
||||
:deep(.wd-radio) {
|
||||
justify-content: center;
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.profile-footer {
|
||||
&__submit {
|
||||
margin-bottom: 30rpx;
|
||||
|
||||
:deep(.wd-button) {
|
||||
height: 88rpx;
|
||||
font-size: 32rpx;
|
||||
font-weight: 600;
|
||||
border-radius: 44rpx;
|
||||
}
|
||||
}
|
||||
|
||||
&__skip {
|
||||
text-align: center;
|
||||
|
||||
text {
|
||||
font-size: 28rpx;
|
||||
color: rgba(255, 255, 255, 0.8);
|
||||
text-decoration: underline;
|
||||
}
|
||||
text {
|
||||
font-size: 28rpx;
|
||||
color: rgba(255, 255, 255, 0.8);
|
||||
text-decoration: underline;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -20,8 +20,6 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
|
||||
|
||||
const activeNames = ref(["0"]); // 默认展开第一项
|
||||
|
||||
const agreementContent = [
|
||||
@@ -57,10 +55,10 @@ const agreementContent = [
|
||||
},
|
||||
];
|
||||
|
||||
definePage({
|
||||
name: "theme",
|
||||
style: { navigationBarTitleText: "用户协议" },
|
||||
});
|
||||
definePage({
|
||||
name: "theme",
|
||||
style: { navigationBarTitleText: "用户协议" },
|
||||
});
|
||||
|
||||
// 同意协议
|
||||
const handleAgree = () => {
|
||||
@@ -86,7 +84,7 @@ const handleAgree = () => {
|
||||
}
|
||||
|
||||
.agreement__action {
|
||||
margin-top: 48rpx;
|
||||
padding: 0 32rpx;
|
||||
margin-top: 48rpx;
|
||||
}
|
||||
</style>
|
||||
+180
-173
@@ -11,7 +11,13 @@
|
||||
<view class="settings-group-wrap">
|
||||
<wd-cell-group custom-style="margin-top:24rpx">
|
||||
<wd-cell title="网络测试" icon="wifi" is-link @click="navigateToNetworkTest" />
|
||||
<wd-cell title="清空缓存" icon="delete" :value="cacheSize" clickable @click="handleClearCache" />
|
||||
<wd-cell
|
||||
title="清空缓存"
|
||||
icon="delete"
|
||||
:value="cacheSize"
|
||||
clickable
|
||||
@click="handleClearCache"
|
||||
/>
|
||||
</wd-cell-group>
|
||||
</view>
|
||||
|
||||
@@ -21,202 +27,203 @@
|
||||
</wd-button>
|
||||
</view>
|
||||
|
||||
<wd-loading v-if="isClearing" v-model="isClearing" text="正在清理..." mask custom-class="loading-center" />
|
||||
<wd-loading
|
||||
v-if="isClearing"
|
||||
v-model="isClearing"
|
||||
text="正在清理..."
|
||||
mask
|
||||
custom-class="loading-center"
|
||||
/>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { useUserStore } from "@/store";
|
||||
import { onLoad } from "@dcloudio/uni-app";
|
||||
import { useToast } from "@wot-ui/ui";
|
||||
|
||||
import { useUserStore } from "@/store";
|
||||
import { onLoad } from "@dcloudio/uni-app";
|
||||
import { useToast } from "@wot-ui/ui";
|
||||
definePage({
|
||||
name: "settings",
|
||||
style: { navigationBarTitleText: "设置" },
|
||||
});
|
||||
|
||||
definePage({
|
||||
name: "settings",
|
||||
style: { navigationBarTitleText: "设置" },
|
||||
const userStore = useUserStore();
|
||||
const toast = useToast();
|
||||
const isLogin = computed(() => !!userStore.userInfo);
|
||||
|
||||
// 主题设置
|
||||
const navigateToTheme = () => {
|
||||
uni.navigateTo({
|
||||
url: "/pages/mine/settings/theme/index",
|
||||
});
|
||||
};
|
||||
|
||||
const userStore = useUserStore();
|
||||
const toast = useToast();
|
||||
const isLogin = computed(() => !!userStore.userInfo);
|
||||
// 用户协议
|
||||
const navigateToUserAgreement = () => {
|
||||
uni.navigateTo({
|
||||
url: "/pages/mine/settings/agreement/index",
|
||||
});
|
||||
};
|
||||
|
||||
// 主题设置
|
||||
const navigateToTheme = () => {
|
||||
uni.navigateTo({
|
||||
url: "/pages/mine/settings/theme/index",
|
||||
// 关于我们
|
||||
const navigateToAbout = () => {
|
||||
uni.navigateTo({
|
||||
url: "/pages/mine/about/index",
|
||||
});
|
||||
};
|
||||
|
||||
// 网络测试
|
||||
const navigateToNetworkTest = () => {
|
||||
uni.navigateTo({ url: "/pages/mine/settings/network/index" });
|
||||
};
|
||||
|
||||
// 是否正在清理
|
||||
const isClearing = ref(false);
|
||||
// 缓存大小
|
||||
const cacheSize = ref<string>("计算中...");
|
||||
// 获取缓存大小
|
||||
const getCacheSize = async () => {
|
||||
try {
|
||||
// #ifdef MP-WEIXIN
|
||||
const res = await uni.getStorageInfo();
|
||||
cacheSize.value = formatSize(res.currentSize);
|
||||
// #endif
|
||||
// #ifdef H5
|
||||
cacheSize.value = formatSize(
|
||||
Object.keys(localStorage).reduce((size, key) => size + localStorage[key].length, 0)
|
||||
);
|
||||
// #endif
|
||||
if (!cacheSize.value) {
|
||||
cacheSize.value = "0B";
|
||||
}
|
||||
} catch {
|
||||
cacheSize.value = "获取失败";
|
||||
}
|
||||
};
|
||||
|
||||
// 格式化存储大小
|
||||
const formatSize = (size: number) => {
|
||||
if (size < 1024) {
|
||||
return size + "B";
|
||||
} else if (size < 1024 * 1024) {
|
||||
return (size / 1024).toFixed(2) + "KB";
|
||||
} else {
|
||||
return (size / 1024 / 1024).toFixed(2) + "MB";
|
||||
}
|
||||
};
|
||||
|
||||
// 处理清除缓存
|
||||
const handleClearCache = async () => {
|
||||
if (cacheSize.value === "获取失败") {
|
||||
uni.showToast({
|
||||
title: "获取缓存信息失败,请稍后重试",
|
||||
icon: "none",
|
||||
duration: 2000,
|
||||
});
|
||||
};
|
||||
|
||||
// 用户协议
|
||||
const navigateToUserAgreement = () => {
|
||||
uni.navigateTo({
|
||||
url: "/pages/mine/settings/agreement/index",
|
||||
return;
|
||||
}
|
||||
if (cacheSize.value === "0B") {
|
||||
uni.showToast({
|
||||
title: "暂无缓存需要清理",
|
||||
icon: "none",
|
||||
duration: 2000,
|
||||
});
|
||||
};
|
||||
return;
|
||||
}
|
||||
if (isClearing.value) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 关于我们
|
||||
const navigateToAbout = () => {
|
||||
uni.navigateTo({
|
||||
url: "/pages/mine/about/index",
|
||||
try {
|
||||
isClearing.value = true;
|
||||
// 模拟清理过程
|
||||
await new Promise((resolve) => setTimeout(resolve, 1500));
|
||||
// 清除缓存
|
||||
await uni.clearStorage();
|
||||
// 更新缓存大小显示
|
||||
await getCacheSize();
|
||||
// 提示清理成功
|
||||
uni.showToast({
|
||||
title: "清理成功",
|
||||
icon: "success",
|
||||
});
|
||||
};
|
||||
} catch {
|
||||
uni.showToast({
|
||||
title: "清理失败",
|
||||
icon: "error",
|
||||
});
|
||||
} finally {
|
||||
isClearing.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
// 网络测试
|
||||
const navigateToNetworkTest = () => {
|
||||
uni.navigateTo({ url: "/pages/mine/settings/network/index" });
|
||||
};
|
||||
|
||||
// 是否正在清理
|
||||
const isClearing = ref(false);
|
||||
// 缓存大小
|
||||
const cacheSize = ref<string>("计算中...");
|
||||
// 获取缓存大小
|
||||
const getCacheSize = async () => {
|
||||
try {
|
||||
// #ifdef MP-WEIXIN
|
||||
const res = await uni.getStorageInfo();
|
||||
cacheSize.value = formatSize(res.currentSize);
|
||||
// #endif
|
||||
// #ifdef H5
|
||||
cacheSize.value = formatSize(
|
||||
Object.keys(localStorage).reduce((size, key) => size + localStorage[key].length, 0)
|
||||
);
|
||||
// #endif
|
||||
if (!cacheSize.value) {
|
||||
cacheSize.value = "0B";
|
||||
// 退出登录
|
||||
const handleLogout = () => {
|
||||
uni.showModal({
|
||||
title: "提示",
|
||||
content: "确定要退出登录吗?",
|
||||
confirmColor: "#ff4757",
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
userStore.logout();
|
||||
toast.success("已退出登录");
|
||||
setTimeout(() => {
|
||||
uni.reLaunch({ url: "/pages/mine/index" });
|
||||
}, 800);
|
||||
}
|
||||
} catch {
|
||||
cacheSize.value = "获取失败";
|
||||
}
|
||||
};
|
||||
|
||||
// 格式化存储大小
|
||||
const formatSize = (size: number) => {
|
||||
if (size < 1024) {
|
||||
return size + "B";
|
||||
} else if (size < 1024 * 1024) {
|
||||
return (size / 1024).toFixed(2) + "KB";
|
||||
} else {
|
||||
return (size / 1024 / 1024).toFixed(2) + "MB";
|
||||
}
|
||||
};
|
||||
|
||||
// 处理清除缓存
|
||||
const handleClearCache = async () => {
|
||||
if (cacheSize.value === "获取失败") {
|
||||
uni.showToast({
|
||||
title: "获取缓存信息失败,请稍后重试",
|
||||
icon: "none",
|
||||
duration: 2000,
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (cacheSize.value === "0B") {
|
||||
uni.showToast({
|
||||
title: "暂无缓存需要清理",
|
||||
icon: "none",
|
||||
duration: 2000,
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (isClearing.value) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
isClearing.value = true;
|
||||
// 模拟清理过程
|
||||
await new Promise((resolve) => setTimeout(resolve, 1500));
|
||||
// 清除缓存
|
||||
await uni.clearStorage();
|
||||
// 更新缓存大小显示
|
||||
await getCacheSize();
|
||||
// 提示清理成功
|
||||
uni.showToast({
|
||||
title: "清理成功",
|
||||
icon: "success",
|
||||
});
|
||||
} catch {
|
||||
uni.showToast({
|
||||
title: "清理失败",
|
||||
icon: "error",
|
||||
});
|
||||
} finally {
|
||||
isClearing.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
// 退出登录
|
||||
const handleLogout = () => {
|
||||
uni.showModal({
|
||||
title: "提示",
|
||||
content: "确定要退出登录吗?",
|
||||
confirmColor: "#ff4757",
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
userStore.logout();
|
||||
toast.success("已退出登录");
|
||||
setTimeout(() => {
|
||||
uni.reLaunch({ url: "/pages/mine/index" });
|
||||
}, 800);
|
||||
}
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
// 检查登录状态
|
||||
onLoad(() => {
|
||||
getCacheSize();
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
// 检查登录状态
|
||||
onLoad(() => {
|
||||
getCacheSize();
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.logout-section {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin-top: 60rpx;
|
||||
}
|
||||
.logout-section {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin-top: 48rpx;
|
||||
}
|
||||
|
||||
.settings-page {
|
||||
padding: 24rpx;
|
||||
}
|
||||
.settings-page {
|
||||
padding: 24rpx;
|
||||
}
|
||||
|
||||
.settings-group-wrap {
|
||||
margin-bottom: 24rpx;
|
||||
}
|
||||
.settings-group-wrap {
|
||||
margin-bottom: 24rpx;
|
||||
}
|
||||
|
||||
.logout-section {
|
||||
margin-top: 48rpx;
|
||||
}
|
||||
:deep(.wd-cell:active) {
|
||||
background-color: var(--color-bg-tertiary) !important;
|
||||
}
|
||||
|
||||
:deep(.wd-cell:active) {
|
||||
background-color: var(--color-bg-tertiary) !important;
|
||||
}
|
||||
:deep(.logout-btn) {
|
||||
height: 88rpx;
|
||||
font-size: 32rpx;
|
||||
font-weight: 500;
|
||||
border-radius: 24rpx;
|
||||
}
|
||||
|
||||
:deep(.logout-btn) {
|
||||
height: 88rpx;
|
||||
font-size: 32rpx;
|
||||
font-weight: 500;
|
||||
border-radius: 24rpx;
|
||||
}
|
||||
.loading-center {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background-color: rgba(0, 0, 0, 0.6);
|
||||
border-radius: 12rpx;
|
||||
}
|
||||
|
||||
.loading-center {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background-color: rgba(0, 0, 0, 0.6);
|
||||
border-radius: 12rpx;
|
||||
}
|
||||
.loading-center :deep(.wd-loading__spinner) {
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.loading-center :deep(.wd-loading__spinner) {
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.loading-center :deep(.wd-loading__text) {
|
||||
margin-top: 20rpx;
|
||||
color: var(--color-text-inverse);
|
||||
text-align: center;
|
||||
}
|
||||
.loading-center :deep(.wd-loading__text) {
|
||||
margin-top: 20rpx;
|
||||
color: var(--color-text-inverse);
|
||||
text-align: center;
|
||||
}
|
||||
</style>
|
||||
@@ -32,7 +32,6 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
|
||||
import { onLoad } from "@dcloudio/uni-app";
|
||||
|
||||
definePage({
|
||||
@@ -40,7 +39,6 @@ definePage({
|
||||
style: { navigationBarTitleText: "网络测试" },
|
||||
});
|
||||
|
||||
|
||||
const result = ref<number | null>(null);
|
||||
const isTesting = ref(false);
|
||||
|
||||
@@ -93,10 +91,10 @@ onLoad(() => {
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.result-card {
|
||||
background: var(--color-bg);
|
||||
border-radius: 16rpx;
|
||||
border: 1rpx solid var(--color-border);
|
||||
overflow: hidden;
|
||||
background: var(--color-bg);
|
||||
border: 1rpx solid var(--color-border);
|
||||
border-radius: 16rpx;
|
||||
|
||||
&__header {
|
||||
padding: 24rpx;
|
||||
@@ -107,8 +105,8 @@ onLoad(() => {
|
||||
|
||||
&__row {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 24rpx;
|
||||
|
||||
& + & {
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
|
||||
const activeNames = ref(["0"]); // 默认展开第一项
|
||||
|
||||
const privacyContent = [
|
||||
@@ -71,11 +70,10 @@ const privacyContent = [
|
||||
},
|
||||
];
|
||||
|
||||
definePage({
|
||||
name: "privacy",
|
||||
style: { navigationBarTitleText: "隐私政策" },
|
||||
});
|
||||
|
||||
definePage({
|
||||
name: "privacy",
|
||||
style: { navigationBarTitleText: "隐私政策" },
|
||||
});
|
||||
|
||||
// 同意隐私政策
|
||||
const handleAgree = () => {
|
||||
@@ -101,7 +99,7 @@ const handleAgree = () => {
|
||||
}
|
||||
|
||||
.privacy__action {
|
||||
margin-top: 48rpx;
|
||||
padding: 0 32rpx;
|
||||
margin-top: 48rpx;
|
||||
}
|
||||
</style>
|
||||
@@ -13,10 +13,20 @@
|
||||
<wd-cell title="预设主题色">
|
||||
<template #default>
|
||||
<view class="flex flex-wrap gap-12rpx">
|
||||
<view v-for="(color, index) in themeColorOptions" :key="index" class="color-option"
|
||||
:class="{ 'color-option--active': currentThemeColor === color.primary }" :style="{ backgroundColor: color.primary }"
|
||||
@click="handleSelectColor(color)">
|
||||
<wd-icon v-if="currentThemeColor === color.primary" name="check" size="14" color="var(--color-text-inverse)" />
|
||||
<view
|
||||
v-for="(color, index) in themeColorOptions"
|
||||
:key="index"
|
||||
class="color-option"
|
||||
:class="{ 'color-option--active': currentThemeColor === color.primary }"
|
||||
:style="{ backgroundColor: color.primary }"
|
||||
@click="handleSelectColor(color)"
|
||||
>
|
||||
<wd-icon
|
||||
v-if="currentThemeColor === color.primary"
|
||||
name="check"
|
||||
size="14"
|
||||
color="var(--color-text-inverse)"
|
||||
/>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
@@ -67,8 +77,11 @@
|
||||
<view class="popup-content">
|
||||
<view class="popup-header">
|
||||
<text class="popup-title">自定义主题色</text>
|
||||
<view class="w-64rpx h-64rpx flex-center rounded-full" hover-class="bg-[var(--color-text-placeholder)]/16"
|
||||
@click="showCustomColorInput = false">
|
||||
<view
|
||||
class="w-64rpx h-64rpx flex-center rounded-full"
|
||||
hover-class="bg-[var(--color-text-placeholder)]/16"
|
||||
@click="showCustomColorInput = false"
|
||||
>
|
||||
<wd-icon name="close" size="18" class="color-text-secondary" />
|
||||
</view>
|
||||
</view>
|
||||
@@ -77,7 +90,12 @@
|
||||
<text class="text-28rpx color-text-secondary">请输入十六进制颜色值</text>
|
||||
<view class="flex items-center gap-16rpx mt-16rpx">
|
||||
<view class="color-dot-lg" :style="{ backgroundColor: customColor || '#FF4757' }" />
|
||||
<wd-input v-model="customColor" placeholder="例如: #FF4757" :maxlength="7" custom-class="theme-input" />
|
||||
<wd-input
|
||||
v-model="customColor"
|
||||
placeholder="例如: #FF4757"
|
||||
:maxlength="7"
|
||||
custom-class="theme-input"
|
||||
/>
|
||||
</view>
|
||||
<text class="text-24rpx color-text-placeholder mt-12rpx">支持格式:#RGB 或 #RRGGBB</text>
|
||||
</view>
|
||||
@@ -92,184 +110,182 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { useTheme } from "@/composables/useTheme";
|
||||
import { useToast, useDialog } from "@wot-ui/ui";
|
||||
import { useTheme } from "@/composables/useTheme";
|
||||
import { useToast, useDialog } from "@wot-ui/ui";
|
||||
|
||||
definePage({
|
||||
name: "theme",
|
||||
style: { navigationBarTitleText: "主题设置" },
|
||||
definePage({
|
||||
name: "theme",
|
||||
style: { navigationBarTitleText: "主题设置" },
|
||||
});
|
||||
|
||||
// 使用主题组合函数
|
||||
const { isDark, themeColorOptions, toggleTheme, setThemeColor } = useTheme();
|
||||
|
||||
const toast = useToast();
|
||||
const { confirm } = useDialog();
|
||||
|
||||
// 创建响应式的计算属性
|
||||
const isDarkMode = computed(() => isDark.value);
|
||||
|
||||
// 自定义颜色输入
|
||||
const customColor = ref("");
|
||||
const showCustomColorInput = ref(false);
|
||||
|
||||
// 当前选中的主题色
|
||||
const currentThemeColor = computed(() => {
|
||||
return themeColorOptions[0].primary;
|
||||
});
|
||||
|
||||
// 选择预设颜色
|
||||
const handleSelectColor = (color: (typeof themeColorOptions)[0]) => {
|
||||
setThemeColor(color);
|
||||
customColor.value = color.primary;
|
||||
|
||||
// 提示
|
||||
uni.showToast({
|
||||
title: "主题色已更新",
|
||||
icon: "success",
|
||||
duration: 1500,
|
||||
});
|
||||
};
|
||||
|
||||
// 使用主题组合函数
|
||||
const { isDark, themeColorOptions, toggleTheme, setThemeColor } = useTheme();
|
||||
// 显示自定义颜色输入
|
||||
const showCustomInput = () => {
|
||||
showCustomColorInput.value = true;
|
||||
customColor.value = currentThemeColor.value;
|
||||
};
|
||||
|
||||
const toast = useToast();
|
||||
const { confirm } = useDialog();
|
||||
|
||||
// 创建响应式的计算属性
|
||||
const isDarkMode = computed(() => isDark.value);
|
||||
|
||||
// 自定义颜色输入
|
||||
const customColor = ref("");
|
||||
const showCustomColorInput = ref(false);
|
||||
|
||||
// 当前选中的主题色
|
||||
const currentThemeColor = computed(() => {
|
||||
return themeColorOptions[0].primary;
|
||||
});
|
||||
|
||||
// 选择预设颜色
|
||||
const handleSelectColor = (color: (typeof themeColorOptions)[0]) => {
|
||||
setThemeColor(color);
|
||||
customColor.value = color.primary;
|
||||
|
||||
// 提示
|
||||
// 应用自定义颜色
|
||||
const applyCustomColor = () => {
|
||||
// 验证颜色格式
|
||||
const colorRegex = /^#([0-9A-F]{6}|[0-9A-F]{3})$/i;
|
||||
if (!colorRegex.test(customColor.value)) {
|
||||
uni.showToast({
|
||||
title: "主题色已更新",
|
||||
title: "请输入有效的颜色值",
|
||||
icon: "none",
|
||||
duration: 2000,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// 转换3位颜色值为6位
|
||||
let color = customColor.value;
|
||||
if (color.length === 4) {
|
||||
color = "#" + color[1] + color[1] + color[2] + color[2] + color[3] + color[3];
|
||||
}
|
||||
|
||||
// 创建自定义主题色选项
|
||||
const customColorOption = {
|
||||
name: "自定义",
|
||||
value: "custom",
|
||||
primary: color,
|
||||
};
|
||||
|
||||
setThemeColor(customColorOption);
|
||||
showCustomColorInput.value = false;
|
||||
|
||||
// 提示
|
||||
uni.showToast({
|
||||
title: "自定义主题色已应用",
|
||||
icon: "success",
|
||||
duration: 1500,
|
||||
});
|
||||
};
|
||||
|
||||
// 重置为默认主题
|
||||
const handleResetTheme = async () => {
|
||||
try {
|
||||
await confirm({ title: "确认重置", msg: "确定要重置为默认主题吗?", headerImage: "warning" });
|
||||
setThemeColor(themeColorOptions[0]);
|
||||
customColor.value = themeColorOptions[0].primary;
|
||||
toast.success("已重置为默认主题");
|
||||
} catch {
|
||||
// 用户取消
|
||||
}
|
||||
};
|
||||
|
||||
// 切换暗黑模式
|
||||
const handleToggleDarkMode = () => {
|
||||
toggleTheme();
|
||||
nextTick(() => {
|
||||
uni.showToast({
|
||||
title: `已切换到${isDarkMode.value ? "暗黑" : "浅色"}模式`,
|
||||
icon: "success",
|
||||
duration: 1500,
|
||||
});
|
||||
};
|
||||
|
||||
// 显示自定义颜色输入
|
||||
const showCustomInput = () => {
|
||||
showCustomColorInput.value = true;
|
||||
customColor.value = currentThemeColor.value;
|
||||
};
|
||||
|
||||
// 应用自定义颜色
|
||||
const applyCustomColor = () => {
|
||||
// 验证颜色格式
|
||||
const colorRegex = /^#([0-9A-F]{6}|[0-9A-F]{3})$/i;
|
||||
if (!colorRegex.test(customColor.value)) {
|
||||
uni.showToast({
|
||||
title: "请输入有效的颜色值",
|
||||
icon: "none",
|
||||
duration: 2000,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// 转换3位颜色值为6位
|
||||
let color = customColor.value;
|
||||
if (color.length === 4) {
|
||||
color = "#" + color[1] + color[1] + color[2] + color[2] + color[3] + color[3];
|
||||
}
|
||||
|
||||
// 创建自定义主题色选项
|
||||
const customColorOption = {
|
||||
name: "自定义",
|
||||
value: "custom",
|
||||
primary: color,
|
||||
};
|
||||
|
||||
setThemeColor(customColorOption);
|
||||
showCustomColorInput.value = false;
|
||||
|
||||
// 提示
|
||||
uni.showToast({
|
||||
title: "自定义主题色已应用",
|
||||
icon: "success",
|
||||
duration: 1500,
|
||||
});
|
||||
};
|
||||
|
||||
// 重置为默认主题
|
||||
const handleResetTheme = async () => {
|
||||
try {
|
||||
await confirm({ title: "确认重置", msg: "确定要重置为默认主题吗?", headerImage: "warning" });
|
||||
setThemeColor(themeColorOptions[0]);
|
||||
customColor.value = themeColorOptions[0].primary;
|
||||
toast.success("已重置为默认主题");
|
||||
} catch {
|
||||
// 用户取消
|
||||
}
|
||||
};
|
||||
|
||||
// 切换暗黑模式
|
||||
const handleToggleDarkMode = () => {
|
||||
toggleTheme();
|
||||
nextTick(() => {
|
||||
uni.showToast({
|
||||
title: `已切换到${isDarkMode.value ? "暗黑" : "浅色"}模式`,
|
||||
icon: "success",
|
||||
duration: 1500,
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
onLoad(() => {
|
||||
customColor.value = currentThemeColor.value;
|
||||
});
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
customColor.value = currentThemeColor.value;
|
||||
});
|
||||
onLoad(() => {
|
||||
customColor.value = currentThemeColor.value;
|
||||
});
|
||||
|
||||
// 页面显示时确保主题色同步
|
||||
onShow(() => {
|
||||
customColor.value = currentThemeColor.value;
|
||||
});
|
||||
onMounted(() => {
|
||||
customColor.value = currentThemeColor.value;
|
||||
});
|
||||
|
||||
// 页面显示时确保主题色同步
|
||||
onShow(() => {
|
||||
customColor.value = currentThemeColor.value;
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.color-option {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 48rpx;
|
||||
height: 48rpx;
|
||||
cursor: pointer;
|
||||
border-radius: 50%;
|
||||
.color-option {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 48rpx;
|
||||
height: 48rpx;
|
||||
cursor: pointer;
|
||||
border-radius: 50%;
|
||||
|
||||
&--active {
|
||||
box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.2);
|
||||
transform: scale(1.1);
|
||||
}
|
||||
&--active {
|
||||
box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.2);
|
||||
transform: scale(1.1);
|
||||
}
|
||||
}
|
||||
|
||||
.color-dot {
|
||||
width: 32rpx;
|
||||
height: 32rpx;
|
||||
border-radius: 50%;
|
||||
}
|
||||
.color-dot {
|
||||
width: 32rpx;
|
||||
height: 32rpx;
|
||||
border-radius: 50%;
|
||||
}
|
||||
|
||||
.color-dot-lg {
|
||||
flex-shrink: 0;
|
||||
width: 48rpx;
|
||||
height: 48rpx;
|
||||
border-radius: 8rpx;
|
||||
}
|
||||
.color-dot-lg {
|
||||
flex-shrink: 0;
|
||||
width: 48rpx;
|
||||
height: 48rpx;
|
||||
border-radius: 8rpx;
|
||||
}
|
||||
|
||||
.popup-content {
|
||||
padding-bottom: env(safe-area-inset-bottom);
|
||||
}
|
||||
.popup-content {
|
||||
padding-bottom: env(safe-area-inset-bottom);
|
||||
}
|
||||
|
||||
.popup-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 24rpx 32rpx;
|
||||
border-bottom: 1rpx solid var(--color-border);
|
||||
}
|
||||
.popup-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 24rpx 32rpx;
|
||||
border-bottom: 1rpx solid var(--color-border);
|
||||
}
|
||||
|
||||
.popup-title {
|
||||
font-size: 32rpx;
|
||||
font-weight: 600;
|
||||
color: var(--color-text);
|
||||
}
|
||||
.popup-title {
|
||||
font-size: 32rpx;
|
||||
font-weight: 600;
|
||||
color: var(--color-text);
|
||||
}
|
||||
|
||||
.popup-actions {
|
||||
display: flex;
|
||||
gap: 24rpx;
|
||||
padding: 24rpx 32rpx;
|
||||
border-top: 1rpx solid var(--color-border);
|
||||
}
|
||||
.popup-actions {
|
||||
display: flex;
|
||||
gap: 24rpx;
|
||||
padding: 24rpx 32rpx;
|
||||
border-top: 1rpx solid var(--color-border);
|
||||
}
|
||||
|
||||
:deep(.theme-input) {
|
||||
background-color: var(--color-bg-secondary) !important;
|
||||
color: var(--color-text) !important;
|
||||
}
|
||||
:deep(.theme-input) {
|
||||
color: var(--color-text) !important;
|
||||
background-color: var(--color-bg-secondary) !important;
|
||||
}
|
||||
</style>
|
||||
Reference in new issue
Block a user