refactor: 界面优化和使用sse替换websocket

This commit is contained in:
Ray.Hao committed 2026-04-26 14:11:05 +08:00
1 parent 0288b5a08d
commit c9fbc441bd
31 files changed
+546 -916

No files matched your search

+8 -56
View File
@@ -2,14 +2,7 @@
<view class="page page--tabbar">
<!-- 轮播图 -->
<view class="relative">
<wd-swiper
v-model:current="current"
custom-class="swiper-box"
:list="swiperList"
autoplay
@click="handleSwiperClick"
@change="handleSwiperChange"
/>
<wd-swiper v-model:current="current" custom-class="swiper-box" :list="swiperList" autoplay />
<view class="hero-fade"></view>
</view>
@@ -20,7 +13,7 @@
v-for="(item, index) in quickNavList"
:key="index"
use-slot
@itemclick="handleNavClick(item)"
@itemclick="handleNavClickWithGuard(item)"
>
<view class="nav-item">
<image class="nav-item__icon" :src="item.icon" mode="aspectFit" />
@@ -100,8 +93,9 @@ import { onReady, onShow } from "@dcloudio/uni-app";
import { dayjs } from "wot-design-uni";
import { useRouter } from "uni-mini-router";
import { useUserStore } from "@/store";
import { useNavigation } from "@/composables/useNavigation";
import { menuConfig } from "@/config/menu";
import { checkLogin, isLoggedIn } from "@/utils/auth";
import { isLoggedIn } from "@/utils/auth";
import { hasPermission } from "@/utils/permission";
import LogAPI, { type VisitOverview as ApiVisitOverview, type VisitTrend } from "@/api/log";
import NoticeAPI, { type NoticeItem } from "@/api/notice";
@@ -117,6 +111,7 @@ interface NavItem {
const router = useRouter();
const userStore = useUserStore();
const { handleNavClick } = useNavigation();
// custom-navbar 组件内部已处理导航栏高度与胶囊避让
const current = ref(0);
@@ -136,17 +131,12 @@ const visitOverviewData = ref<VisitOverviewVO>({
totalPvCount: 0,
});
const appVersion = ref<string>("");
const noticeList = ref<NoticeItem[]>([]);
const noticeText = computed(() => {
if (!noticeList.value.length) {
return "暂无通知";
}
const titles = noticeList.value
.map((n: NoticeItem) => n.title)
.filter(Boolean)
.slice(0, 2) as string[];
.slice(0, 2);
return titles.length ? titles.join(" ") : "暂无通知";
});
@@ -214,17 +204,6 @@ const chartOpts = ref({
},
});
function loadAppVersion() {
try {
const p: any = (globalThis as any).plus;
if (p?.runtime?.version) {
appVersion.value = `v${p.runtime.version}`;
}
} catch {
appVersion.value = "";
}
}
async function loadNoticeData() {
// 未登录时不调用通知接口
if (!isLogged.value) {
@@ -269,49 +248,24 @@ async function loadVisitTrendData() {
}
}
function handleNavClick(item: NavItem) {
// 未登录 / 无权限时:展示默认导航,但点击统一跳登录
function handleNavClickWithGuard(item: NavItem) {
if (!isLogged.value || !hasAnyPerm.value) {
uni.navigateTo({ url: "/pages/login/index" });
return;
}
// 已登录但访问受限时,仍做一次登录校验(防 token 过期)
if (!checkLogin()) return;
// 外部链接处理
if (item.url.startsWith("http://") || item.url.startsWith("https://")) {
const isH5 = typeof window !== "undefined";
if (isH5) {
uni.navigateTo({ url: `/pages/webview/index?url=${encodeURIComponent(item.url)}` });
} else {
try {
const p = (globalThis as any).plus;
p?.runtime?.openURL(item.url);
} catch {
uni.navigateTo({ url: `/pages/webview/index?url=${encodeURIComponent(item.url)}` });
}
}
return;
}
router.push({ path: item.url });
handleNavClick(item);
}
function handleNoticeClick() {
router.push({ path: "/pages/work/notice/index" });
}
function handleSwiperClick(_e: any) {}
function handleSwiperChange(_e: any) {}
function handleDataRangeChange({ value }: { value: number }) {
recentDaysRange.value = value;
loadVisitTrendData();
}
onReady(() => {
loadAppVersion();
loadNoticeData();
loadVisitOverviewData();
loadVisitTrendData();
@@ -436,7 +390,6 @@ onShow(() => {
&__header {
position: relative;
z-index: var(--z-sticky);
display: flex;
align-items: center;
justify-content: space-between;
@@ -478,7 +431,6 @@ onShow(() => {
&__num {
position: relative;
z-index: var(--z-sticky);
font-size: 48rpx;
font-weight: 700;
line-height: 1;
+31 -55
View File
@@ -105,7 +105,7 @@
<!-- 登录按钮 -->
<view class="login__form-item">
<wd-button type="primary" block :loading="loading" @click="handleLogin">
<wd-button type="primary" block :loading="isLoading" @click="handleLogin">
登 录
</wd-button>
</view>
@@ -228,7 +228,7 @@
<text class="login__demo-hint-text">演示环境验证码:123456</text>
</view>
<wd-button type="primary" block :loading="bindLoading" @click="handleBindMobile">
<wd-button type="primary" block :loading="isBindLoading" @click="handleBindMobile">
确认绑定
</wd-button>
</view>
@@ -260,9 +260,10 @@
</route>
<script lang="ts" setup>
import { onLoad, onShow, onUnload } from "@dcloudio/uni-app";
import { onLoad, onShow } from "@dcloudio/uni-app";
import { useToast, useMessage } from "wot-design-uni";
import { useUserStore } from "@/store/modules/user";
import { useCountdown } from "@/composables/useCountdown";
import AuthAPI from "@/api/auth";
const toast = useToast();
@@ -274,11 +275,10 @@ const statusBarHeight = ref(20);
const navBarHeight = ref(44);
// 表单状态
const loading = ref(false);
const isLoading = ref(false);
const isAgreePolicy = ref(false);
const loginMode = ref<"PASSWORD" | "SMS" | "WECHAT">("PASSWORD");
const smsCountdown = ref(0);
const smsTimer = ref<ReturnType<typeof setInterval> | null>(null);
const { countdown: smsCountdown, start: startSmsCountdown } = useCountdown(60);
const formData = ref({
username: "admin",
@@ -290,15 +290,14 @@ const formData = ref({
// 图形验证码
const captchaId = ref("");
const captchaBase64 = ref("");
const captchaLoading = ref(false);
const isCaptchaLoading = ref(false);
const redirect = ref("/pages/index/index");
// 绑定手机号
const showBindMobilePopup = ref(false);
const bindLoading = ref(false);
const bindSmsCountdown = ref(0);
const bindSmsTimer = ref<ReturnType<typeof setInterval> | null>(null);
const isBindLoading = ref(false);
const { countdown: bindSmsCountdown, start: startBindSmsCountdown } = useCountdown(60);
const wechatOpenid = ref("");
const bindMobileForm = ref({
@@ -333,9 +332,9 @@ const canSubmit = computed(() => {
// 图形验证码
const fetchCaptcha = async () => {
if (captchaLoading.value) return;
if (isCaptchaLoading.value) return;
try {
captchaLoading.value = true;
isCaptchaLoading.value = true;
captchaBase64.value = "";
const res = await AuthAPI.getCaptcha();
captchaId.value = res.captchaId;
@@ -343,29 +342,10 @@ const fetchCaptcha = async () => {
} catch {
// 获取验证码失败由 API 层处理
} finally {
captchaLoading.value = false;
isCaptchaLoading.value = false;
}
};
// 短信倒计时
const startSmsCountdown = (
countdown: Ref<number>,
timer: Ref<ReturnType<typeof setInterval> | null>
) => {
countdown.value = 60;
if (timer.value) clearInterval(timer.value);
timer.value = setInterval(() => {
countdown.value -= 1;
if (countdown.value <= 0) {
countdown.value = 0;
if (timer.value) {
clearInterval(timer.value);
timer.value = null;
}
}
}, 1000);
};
// 切换登录方式
const toggleLoginMode = () => {
if (loginMode.value === "PASSWORD") {
@@ -412,8 +392,8 @@ async function doFormLogin() {
);
return;
}
if (loading.value) return;
loading.value = true;
if (isLoading.value) return;
isLoading.value = true;
try {
if (loginMode.value === "PASSWORD") {
await userStore.login({
@@ -435,7 +415,7 @@ async function doFormLogin() {
toast.error(error?.message || "登录失败");
if (loginMode.value === "PASSWORD") fetchCaptcha();
} finally {
loading.value = false;
isLoading.value = false;
}
}
@@ -461,7 +441,7 @@ const handleSendCode = async () => {
try {
await AuthAPI.sendSmsLoginCode(mobile);
toast.success("验证码已发送");
startSmsCountdown(smsCountdown, smsTimer);
startSmsCountdown();
} catch (error: any) {
toast.error(error?.message || "发送失败");
}
@@ -486,7 +466,7 @@ async function doWechatPhoneLogin(phoneCode: string) {
await handleWechatSilentLogin();
return;
}
loading.value = true;
isLoading.value = true;
try {
const { code: loginCode } = await uni.login();
await userStore.loginByWxMaPhone({ loginCode, phoneCode });
@@ -497,12 +477,12 @@ async function doWechatPhoneLogin(phoneCode: string) {
toast.info("正在尝试其他登录方式...");
await handleWechatSilentLogin();
} finally {
loading.value = false;
isLoading.value = false;
}
}
const handleWechatSilentLogin = async () => {
loading.value = true;
isLoading.value = true;
try {
const { code } = await uni.login();
const result: any = await userStore.loginByWxMa(code);
@@ -517,7 +497,7 @@ const handleWechatSilentLogin = async () => {
} catch (error: any) {
toast.error(error?.message || "微信登录失败");
} finally {
loading.value = false;
isLoading.value = false;
}
};
@@ -532,7 +512,7 @@ const handleSendBindCode = async () => {
try {
await AuthAPI.sendSmsLoginCode(mobile);
toast.success("验证码已发送");
startSmsCountdown(bindSmsCountdown, bindSmsTimer);
startBindSmsCountdown();
} catch (error: any) {
toast.error(error?.message || "发送失败");
}
@@ -541,14 +521,10 @@ const handleSendBindCode = async () => {
const resetBindForm = () => {
bindMobileForm.value = { mobile: "", code: "" };
bindSmsCountdown.value = 0;
if (bindSmsTimer.value) {
clearInterval(bindSmsTimer.value);
bindSmsTimer.value = null;
}
};
const handleBindMobile = async () => {
if (bindLoading.value) return;
if (isBindLoading.value) return;
const { mobile, code } = bindMobileForm.value;
if (!isValidMobile(mobile)) {
toast.error("请输入正确的手机号");
@@ -558,7 +534,7 @@ const handleBindMobile = async () => {
toast.error("请输入验证码");
return;
}
bindLoading.value = true;
isBindLoading.value = true;
try {
await userStore.bindMobileForWxMa({ openid: wechatOpenid.value, mobile, smsCode: code });
await userStore.getInfo();
@@ -569,7 +545,7 @@ const handleBindMobile = async () => {
} catch (error: any) {
toast.error(error?.message || "绑定失败");
} finally {
bindLoading.value = false;
isBindLoading.value = false;
}
};
@@ -606,11 +582,6 @@ onLoad((options: any) => {
});
onShow(() => uni.setNavigationBarTitle({ title: "" }));
onUnload(() => {
if (smsTimer.value) clearInterval(smsTimer.value);
if (bindSmsTimer.value) clearInterval(bindSmsTimer.value);
});
</script>
<style lang="scss" scoped>
@@ -744,10 +715,15 @@ onUnload(() => {
.login__card {
width: 100%;
padding: 64rpx;
background-color: var(--color-bg-alpha-95);
backdrop-filter: blur(24px);
background-color: var(--color-bg);
border-radius: 48rpx;
box-shadow: 0 20rpx 50rpx -10rpx rgba(0, 0, 0, 0.1);
@supports (backdrop-filter: blur(24px)) or (-webkit-backdrop-filter: blur(24px)) {
background-color: var(--color-bg-alpha-95);
-webkit-backdrop-filter: blur(24px);
backdrop-filter: blur(24px);
}
}
// 卡片头部
+6 -33
View File
@@ -161,8 +161,9 @@
</view>
</template>
<script setup lang="ts">
import { onMounted, onUnmounted, reactive, ref } from "vue";
import { onMounted, reactive, ref } from "vue";
import { useToast, useMessage } from "wot-design-uni";
import { useCountdown } from "@/composables/useCountdown";
import UserAPI, {
PasswordChangeForm,
MobileBindingForm,
@@ -219,11 +220,8 @@ const passwordChangeFormRef = ref();
const mobileBindingFormRef = ref();
const emailBindingFormRef = ref();
const mobileCountdown = ref(0);
const mobileTimer = ref<ReturnType<typeof setInterval> | null>(null);
const emailCountdown = ref(0);
const emailTimer = ref<ReturnType<typeof setTimeout> | null>(null);
const { countdown: mobileCountdown, start: startMobileCountdown } = useCountdown(60);
const { countdown: emailCountdown, start: startEmailCountdown } = useCountdown(60);
const handleUnbindWechat = async () => {
try {
@@ -280,14 +278,7 @@ const handleSendVerificationCode = async (contactType: string) => {
if (valid) {
UserAPI.sendVerificationCode(mobileBindingForm.mobile!, "MOBILE").then(() => {
uni.showToast({ title: "验证码已发送", icon: "none" });
mobileCountdown.value = 60;
mobileTimer.value = setInterval(() => {
if (mobileCountdown.value > 0) {
mobileCountdown.value -= 1;
} else {
clearInterval(mobileTimer.value!);
}
}, 1000);
startMobileCountdown();
});
}
});
@@ -296,14 +287,7 @@ const handleSendVerificationCode = async (contactType: string) => {
if (valid) {
UserAPI.sendVerificationCode(emailBindingForm.email!, "EMAIL").then(() => {
uni.showToast({ title: "验证码已发送", icon: "none" });
emailCountdown.value = 60;
emailTimer.value = setInterval(() => {
if (emailCountdown.value > 0) {
emailCountdown.value -= 1;
} else {
clearInterval(emailTimer.value!);
}
}, 1000);
startEmailCountdown();
});
}
});
@@ -347,15 +331,4 @@ function handleSubmit() {
onMounted(() => {
loadUserProfile();
});
onUnmounted(() => {
if (mobileTimer.value) {
clearInterval(mobileTimer.value);
mobileTimer.value = null;
}
if (emailTimer.value) {
clearInterval(emailTimer.value as unknown as number);
emailTimer.value = null;
}
});
</script>
+48 -53
View File
@@ -24,6 +24,7 @@
class="profile-card__avatar"
:src="isLogin && userInfo?.avatar ? userInfo.avatar : defaultAvatar"
mode="aspectFill"
lazy-load
/>
<view v-if="isLogin" class="profile-card__online-dot" />
<view v-if="genderIconName" class="profile-card__gender" :class="genderIconClass">
@@ -57,13 +58,18 @@
</view>
<view v-if="isLogin" class="profile-card__actions">
<view class="profile-card__action-btn" @click.stop="openNotifications">
<view
class="profile-card__action-btn"
aria-label="通知"
@click.stop="openNotifications"
>
<wd-icon name="notification" size="16" color="var(--color-text-inverse)" />
<view v-if="notificationCount > 0" class="profile-card__notify-badge">
{{ notificationCount }}
</view>
</view>
<view class="profile-card__action-btn" @click.stop="openThemeSettings">
<view
class="profile-card__action-btn"
aria-label="主题设置"
@click.stop="openThemeSettings"
>
<wd-icon name="setting1" size="16" color="var(--color-text-inverse)" />
</view>
</view>
@@ -183,8 +189,8 @@
</view>
<wd-loading
v-if="clearing"
v-model="clearing"
v-if="isClearing"
v-model="isClearing"
text="正在清理..."
mask
custom-class="loading-center"
@@ -208,8 +214,8 @@ import { useToast, useMessage } from "wot-design-uni";
import { useUserStore, useThemeStore } from "@/store";
import { useRouter } from "uni-mini-router";
import { useNavbar } from "@/composables/useNavbar";
import type { UserInfo } from "@/api/user";
import { getAccessToken } from "@/utils/auth";
import { formatBytes } from "@/utils/format";
const toast = useToast();
const { messageBox } = useMessage();
@@ -220,7 +226,6 @@ const currentThemeColor = computed(() => themeStore.themeVars.colorTheme);
const userInfo = computed(() => userStore.userInfo);
const defaultAvatar = "/static/images/default-avatar.png";
const hasAccessToken = ref(!!getAccessToken());
const isLogin = computed(() => !!getAccessToken());
const headerBackground = computed(() => {
@@ -231,7 +236,6 @@ const headerBackground = computed(() => {
});
const router = useRouter();
const notificationCount = computed(() => 0);
const appVersion = ref("1.0.0");
const navbar = useNavbar({ hasTabbar: true });
@@ -265,12 +269,8 @@ const genderIconClass = computed(() => {
return "";
});
const syncAuthState = () => {
hasAccessToken.value = !!getAccessToken();
};
const fetchUserInfoIfNeeded = async () => {
if (!hasAccessToken.value || hasUserProfile.value) return;
if (!isLogin.value || hasUserProfile.value) return;
try {
await userStore.getInfo();
} catch {
@@ -285,7 +285,6 @@ const syncMiniProgramVersion = () => {
};
onShow(async () => {
syncAuthState();
await fetchUserInfoIfNeeded();
await fetchCacheSize();
syncMiniProgramVersion();
@@ -347,19 +346,9 @@ const openAbout = () => {
router.push({ path: "/pages/mine/about/index" });
};
const clearing = ref(false);
const isClearing = ref(false);
const cacheSize = ref<string>("计算中...");
const formatBytes = (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 fetchCacheSize = async () => {
try {
// #ifdef MP-WEIXIN
@@ -396,12 +385,12 @@ const handleClearCache = async () => {
});
return;
}
if (clearing.value) {
if (isClearing.value) {
return;
}
try {
clearing.value = true;
isClearing.value = true;
await new Promise((resolve) => setTimeout(resolve, 1500));
await uni.clearStorage();
await fetchCacheSize();
@@ -415,7 +404,7 @@ const handleClearCache = async () => {
icon: "error",
});
} finally {
clearing.value = false;
isClearing.value = false;
}
};
@@ -492,14 +481,16 @@ const openOfficialAccount = () => {
position: relative;
padding: 28rpx 28rpx;
overflow: hidden;
background: linear-gradient(135deg, var(--color-glass) 0%, var(--color-glass-light) 100%);
backdrop-filter: blur(20px);
background: var(--color-bg-alpha-95);
border: 1rpx solid var(--color-border-glass);
border-radius: 28rpx;
box-shadow:
0 8rpx 32rpx rgba(0, 0, 0, 0.08),
0 2rpx 8rpx rgba(0, 0, 0, 0.04),
inset 0 1rpx 0 var(--color-glass);
box-shadow: var(--shadow-md);
@supports (backdrop-filter: blur(20px)) or (-webkit-backdrop-filter: blur(20px)) {
background: linear-gradient(135deg, var(--color-glass) 0%, var(--color-glass-light) 100%);
-webkit-backdrop-filter: blur(20px);
backdrop-filter: blur(20px);
}
}
.profile-card__header {
@@ -520,7 +511,7 @@ const openOfficialAccount = () => {
height: 120rpx;
border: 3rpx solid var(--color-border-glass-strong);
border-radius: 50%;
box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.1);
box-shadow: var(--shadow-sm);
}
.profile-card__gender {
@@ -531,7 +522,7 @@ const openOfficialAccount = () => {
height: 36rpx;
border: 2rpx solid var(--color-text-inverse);
border-radius: 50%;
box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.15);
box-shadow: var(--shadow-sm);
}
.profile-card__online-dot {
@@ -543,7 +534,7 @@ const openOfficialAccount = () => {
background: var(--color-success);
border: 3rpx solid var(--color-border-glass-strong);
border-radius: 50%;
box-shadow: 0 4rpx 12rpx rgba(15, 23, 42, 0.12);
box-shadow: var(--shadow-sm);
}
.profile-card__actions {
@@ -562,10 +553,15 @@ const openOfficialAccount = () => {
justify-content: center;
width: 52rpx;
height: 52rpx;
background: var(--color-glass-light);
backdrop-filter: blur(10px);
background: var(--color-bg-alpha-95);
border: 1rpx solid var(--color-border-glass);
border-radius: 999rpx;
@supports (backdrop-filter: blur(10px)) or (-webkit-backdrop-filter: blur(10px)) {
background: var(--color-glass-light);
-webkit-backdrop-filter: blur(10px);
backdrop-filter: blur(10px);
}
}
.profile-card__notify-badge {
@@ -670,7 +666,7 @@ const openOfficialAccount = () => {
overflow: hidden;
background: transparent;
border-radius: 32rpx;
box-shadow: 0 10rpx 30rpx rgba(15, 23, 42, 0.06);
box-shadow: var(--shadow-md);
}
.community-card__bg {
@@ -703,7 +699,6 @@ const openOfficialAccount = () => {
.community-card__logo {
position: relative;
z-index: var(--z-sticky);
box-sizing: border-box;
width: 84rpx;
height: 84rpx;
@@ -711,19 +706,17 @@ const openOfficialAccount = () => {
background: var(--color-bg-alpha-95);
border: 1rpx solid var(--color-border-glass);
border-radius: 20rpx;
box-shadow: 0 6rpx 18rpx rgba(15, 23, 42, 0.06);
box-shadow: var(--shadow-sm);
}
.community-card__body {
position: relative;
z-index: var(--z-sticky);
flex: 1;
min-width: 0;
}
.community-card__arrow {
position: relative;
z-index: var(--z-sticky);
display: flex;
align-items: center;
justify-content: center;
@@ -768,7 +761,7 @@ const openOfficialAccount = () => {
padding: 28rpx;
background: var(--color-bg);
border-radius: 32rpx;
box-shadow: 0 10rpx 30rpx rgba(15, 23, 42, 0.05);
box-shadow: var(--shadow-md);
}
.section-card + .section-card {
@@ -790,11 +783,11 @@ const openOfficialAccount = () => {
padding: 28rpx 24rpx;
background: var(--color-bg);
border-radius: 24rpx;
box-shadow: 0 8rpx 24rpx rgba(15, 23, 42, 0.04);
box-shadow: var(--shadow-sm);
}
.quick-card:active {
box-shadow: 0 4rpx 12rpx rgba(15, 23, 42, 0.06);
box-shadow: var(--shadow-sm);
transform: scale(0.96);
}
@@ -884,7 +877,7 @@ const openOfficialAccount = () => {
overflow: hidden;
background: var(--color-bg);
border-radius: 32rpx;
box-shadow: 0 16rpx 40rpx rgba(15, 23, 42, 0.05);
box-shadow: var(--shadow-lg);
}
.menu-list--flat {
@@ -932,7 +925,8 @@ const openOfficialAccount = () => {
}
.logout-section {
padding: 36rpx 32rpx 0;
display: flex;
padding: 36rpx 28rpx 0;
}
.profile-card__button {
@@ -947,14 +941,15 @@ const openOfficialAccount = () => {
}
.logout-btn {
width: 100%;
flex: 1;
width: auto;
height: 88rpx;
font-size: 28rpx;
color: var(--color-danger);
background: var(--color-bg);
border: 1rpx solid rgba(239, 68, 68, 0.18);
border-radius: 24rpx;
box-shadow: 0 12rpx 30rpx var(--color-danger-shadow);
box-shadow: var(--shadow-md);
}
.loading-center {
+5 -5
View File
@@ -96,8 +96,8 @@
type="primary"
size="large"
block
:disabled="!canComplete || loading"
:loading="loading"
:disabled="!canComplete || isLoading"
:loading="isLoading"
@click="handleComplete"
>
完成
@@ -145,7 +145,7 @@ const rules = {
],
};
const loading = ref(false);
const isLoading = ref(false);
const cropperVisible = ref(false);
const originalImageSrc = ref("");
const profileFormRef = ref();
@@ -231,7 +231,7 @@ const handleComplete = async () => {
return;
}
loading.value = true;
isLoading.value = true;
await UserAPI.updateProfile({
nickname: profileForm.nickname,
@@ -252,7 +252,7 @@ const handleComplete = async () => {
} catch (error: any) {
toast.error(error?.message || "完善信息失败");
} finally {
loading.value = false;
isLoading.value = false;
}
};
-5
View File
@@ -161,11 +161,6 @@ onLoad(() => {
loadUserProfile();
});
onMounted(() => {
// 在onMounted中不再重复检查登录状态和加载用户信息
// 如果需要检查登录状态和加载用户信息,请使用onLoad中的逻辑
});
// 页面销毁前移除事件监听
onBeforeUnmount(() => {
// #ifdef H5
+6 -6
View File
@@ -23,8 +23,8 @@
<!-- 使用wot-design-uni的Loading组件 -->
<wd-loading
v-if="clearing"
v-model="clearing"
v-if="isClearing"
v-model="isClearing"
text="正在清理..."
mask
custom-class="loading-center"
@@ -69,7 +69,7 @@ const navigateToNetworkTest = () => {
};
// 是否正在清理
const clearing = ref(false);
const isClearing = ref(false);
// 缓存大小
const cacheSize = ref<string>("计算中...");
// 获取缓存大小
@@ -121,12 +121,12 @@ const handleClearCache = async () => {
});
return;
}
if (clearing.value) {
if (isClearing.value) {
return;
}
try {
clearing.value = true;
isClearing.value = true;
// 模拟清理过程
await new Promise((resolve) => setTimeout(resolve, 1500));
// 清除缓存
@@ -144,7 +144,7 @@ const handleClearCache = async () => {
icon: "error",
});
} finally {
clearing.value = false;
isClearing.value = false;
}
};
+1 -1
View File
@@ -25,7 +25,7 @@
v-if="currentThemeColor === color.primary"
name="check"
size="14"
color="#fff"
color="var(--color-text-inverse)"
/>
</view>
</view>
+6 -4
View File
@@ -67,7 +67,9 @@
</wd-form>
<view class="popup-actions">
<wd-button type="info" plain @click="closeConfigDialog">取消</wd-button>
<wd-button type="primary" :loading="submitting" @click="submitConfigForm">保存</wd-button>
<wd-button type="primary" :loading="isSubmitting" @click="submitConfigForm">
保存
</wd-button>
</view>
</view>
</wd-popup>
@@ -100,7 +102,7 @@ const toast = useToast();
const { messageBox } = useMessage();
const loadMoreState = ref<LoadMoreState>("loading");
const formRef = ref();
const submitting = ref(false);
const isSubmitting = ref(false);
const queryParams = reactive<ConfigPageQuery>({ pageNum: 1, pageSize: 10, keywords: "" });
const total = ref(0);
@@ -169,7 +171,7 @@ async function openConfigDialog(id?: number) {
function submitConfigForm() {
formRef.value.validate().then(({ valid }: { valid: boolean }) => {
if (!valid) return;
submitting.value = true;
isSubmitting.value = true;
const action = formData.id ? ConfigAPI.update(formData.id, formData) : ConfigAPI.add(formData);
action
.then(() => {
@@ -178,7 +180,7 @@ function submitConfigForm() {
loadConfigList();
})
.finally(() => {
submitting.value = false;
isSubmitting.value = false;
});
});
}
+4 -4
View File
@@ -66,7 +66,7 @@
</wd-form>
<view class="popup-actions">
<wd-button type="info" plain @click="closeDeptDialog">取消</wd-button>
<wd-button type="primary" :loading="submitting" @click="submitDeptForm">保存</wd-button>
<wd-button type="primary" :loading="isSubmitting" @click="submitDeptForm">保存</wd-button>
</view>
</view>
</wd-popup>
@@ -95,7 +95,7 @@ import CustomTree from "@/components/custom-tree/index.vue";
const toast = useToast();
const { messageBox } = useMessage();
const formRef = ref();
const submitting = ref(false);
const isSubmitting = ref(false);
const queryParams = reactive<DeptQuery>({ keywords: "" });
const deptList = ref<DeptItem[]>([]);
@@ -301,7 +301,7 @@ function handleAddChild(dept: DeptItem) {
function submitDeptForm() {
formRef.value.validate().then(({ valid }: { valid: boolean }) => {
if (!valid) return;
submitting.value = true;
isSubmitting.value = true;
const action = formData.id ? DeptAPI.update(formData.id, formData) : DeptAPI.add(formData);
action
.then(() => {
@@ -310,7 +310,7 @@ function submitDeptForm() {
loadDeptList();
})
.finally(() => {
submitting.value = false;
isSubmitting.value = false;
});
});
}
+4 -4
View File
@@ -72,7 +72,7 @@
</wd-form>
<view class="popup-actions">
<wd-button type="info" plain @click="closeDictDialog">取消</wd-button>
<wd-button type="primary" :loading="submitting" @click="submitDictForm">保存</wd-button>
<wd-button type="primary" :loading="isSubmitting" @click="submitDictForm">保存</wd-button>
</view>
</view>
</wd-popup>
@@ -102,7 +102,7 @@ const toast = useToast();
const { messageBox } = useMessage();
const loadMoreState = ref<LoadMoreState>("loading");
const formRef = ref();
const submitting = ref(false);
const isSubmitting = ref(false);
const queryParams = reactive<DictTypePageQuery>({ pageNum: 1, pageSize: 10, keywords: "" });
const total = ref(0);
@@ -169,7 +169,7 @@ async function openDictDialog(id?: string) {
function submitDictForm() {
formRef.value.validate().then(({ valid }: { valid: boolean }) => {
if (!valid) return;
submitting.value = true;
isSubmitting.value = true;
const id = formData.id;
const action = id ? DictAPI.update(id, formData) : DictAPI.create(formData);
action
@@ -179,7 +179,7 @@ function submitDictForm() {
loadDictTypeList();
})
.finally(() => {
submitting.value = false;
isSubmitting.value = false;
});
});
}
+4 -4
View File
@@ -77,7 +77,7 @@
</wd-form>
<view class="popup-actions">
<wd-button type="info" plain @click="closeItemDialog">取消</wd-button>
<wd-button type="primary" :loading="submitting" @click="submitItemForm">保存</wd-button>
<wd-button type="primary" :loading="isSubmitting" @click="submitItemForm">保存</wd-button>
</view>
</view>
</wd-popup>
@@ -112,7 +112,7 @@ const pageTitle = ref<string>("字典数据");
const loadMoreState = ref<LoadMoreState>("loading");
const formRef = ref();
const submitting = ref(false);
const isSubmitting = ref(false);
const queryParams = reactive<DictItemPageQuery>({ pageNum: 1, pageSize: 10, keywords: "" });
const total = ref(0);
@@ -187,7 +187,7 @@ function submitItemForm() {
return;
}
submitting.value = true;
isSubmitting.value = true;
const id = formData.id;
const action = id
? DictAPI.updateItem(dictCode.value, id, formData)
@@ -200,7 +200,7 @@ function submitItemForm() {
loadItemList();
})
.finally(() => {
submitting.value = false;
isSubmitting.value = false;
});
});
}
+3 -33
View File
@@ -23,18 +23,13 @@
<script lang="ts" setup>
import { computed } from "vue";
import { useRouter } from "uni-mini-router";
import { useNavbar } from "@/composables/useNavbar";
import { useNavigation } from "@/composables/useNavigation";
import { menuConfig } from "@/config/menu";
import { checkLogin, isLoggedIn } from "@/utils/auth";
import { hasPermission as checkPermission } from "@/utils/permission";
const router = useRouter();
const navbar = useNavbar({ hasTabbar: true });
// 是否已登录
const isLogged = computed(() => isLoggedIn());
const navbar = useNavbar();
const { handleNavClick } = useNavigation();
// 检查是否有权限
const hasPermission = (perm: string) => {
@@ -51,31 +46,6 @@ const visibleGridList = computed(() => {
}))
.filter((group) => group.children.length > 0);
});
// 处理导航点击
function handleNavClick(item: any) {
// 未登录时跳转登录页
if (!isLogged.value) {
uni.navigateTo({ url: "/pages/login/index" });
return;
}
// 已登录但访问受限时,仍做一次登录校验(防 token 过期)
if (!checkLogin()) return;
try {
if (
typeof item?.url === "string" &&
(item.url.startsWith("http://") || item.url.startsWith("https://"))
) {
uni.navigateTo({ url: `/pages/webview/index?url=${encodeURIComponent(item.url)}` });
return;
}
router.push({ path: item.url });
} catch {
// 路由跳转失败已由拦截器处理
}
}
</script>
<route lang="json">
+4 -4
View File
@@ -101,7 +101,7 @@
</scroll-view>
<view class="popup-actions">
<wd-button type="info" plain @click="closeMenuDialog">取消</wd-button>
<wd-button type="primary" :loading="submitting" @click="submitMenuForm">保存</wd-button>
<wd-button type="primary" :loading="isSubmitting" @click="submitMenuForm">保存</wd-button>
</view>
</view>
</wd-popup>
@@ -130,7 +130,7 @@ import CustomTree from "@/components/custom-tree/index.vue";
const toast = useToast();
const { messageBox } = useMessage();
const formRef = ref();
const submitting = ref(false);
const isSubmitting = ref(false);
const queryParams = reactive<MenuQuery>({ keywords: "" });
const menuList = ref<MenuItem[]>([]);
@@ -364,7 +364,7 @@ function handleAddChild(menu: MenuItem) {
function submitMenuForm() {
formRef.value.validate().then(({ valid }: { valid: boolean }) => {
if (!valid) return;
submitting.value = true;
isSubmitting.value = true;
const action = formData.id ? MenuAPI.update(formData.id, formData) : MenuAPI.add(formData);
action
.then(() => {
@@ -373,7 +373,7 @@ function submitMenuForm() {
loadMenuList();
})
.finally(() => {
submitting.value = false;
isSubmitting.value = false;
});
});
}
+6 -4
View File
@@ -133,7 +133,9 @@
</wd-form>
<view class="popup-actions">
<wd-button type="info" plain @click="closeNoticeForm">取消</wd-button>
<wd-button type="primary" :loading="submitting" @click="submitNoticeForm">保存</wd-button>
<wd-button type="primary" :loading="isSubmitting" @click="submitNoticeForm">
保存
</wd-button>
</view>
</view>
</wd-popup>
@@ -169,7 +171,7 @@ const toast = useToast();
const { messageBox } = useMessage();
const loadMoreState = ref<LoadMoreState>("loading");
const formRef = ref();
const submitting = ref(false);
const isSubmitting = ref(false);
const queryParams = reactive<NoticePageQuery>({ pageNum: 1, pageSize: 10 });
const total = ref(0);
@@ -290,7 +292,7 @@ function closeNoticeForm() {
function submitNoticeForm() {
formRef.value.validate().then(({ valid }: { valid: boolean }) => {
if (!valid) return;
submitting.value = true;
isSubmitting.value = true;
const id = formData.id;
const action = id ? NoticeAPI.update(id, formData) : NoticeAPI.add(formData);
action
@@ -300,7 +302,7 @@ function submitNoticeForm() {
loadNoticeList();
})
.finally(() => {
submitting.value = false;
isSubmitting.value = false;
});
});
}
+4 -4
View File
@@ -70,7 +70,7 @@
<!-- 固定底部操作栏 -->
<view class="bottom-bar">
<wd-button type="info" plain @click="handleCancel">取消</wd-button>
<wd-button type="primary" :loading="submitting" @click="handleSubmit">保存</wd-button>
<wd-button type="primary" :loading="isSubmitting" @click="handleSubmit">保存</wd-button>
</view>
</view>
</template>
@@ -84,7 +84,7 @@ import CustomTree from "@/components/custom-tree/index.vue";
import type { TreeOption } from "@/components/custom-tree/index.vue";
const toast = useToast();
const submitting = ref(false);
const isSubmitting = ref(false);
const roleId = ref<number>(0);
const roleName = ref("");
const menuList = ref<MenuItem[]>([]);
@@ -148,13 +148,13 @@ function handleCancel() {
// 提交
async function handleSubmit() {
submitting.value = true;
isSubmitting.value = true;
try {
await RoleAPI.updateRoleMenus(roleId.value, checkedKeys.value.map(Number));
toast.success("保存成功");
uni.navigateBack();
} finally {
submitting.value = false;
isSubmitting.value = false;
}
}
+4 -4
View File
@@ -90,7 +90,7 @@
</wd-form>
<view class="popup-actions">
<wd-button type="info" plain @click="closeRoleDialog">取消</wd-button>
<wd-button type="primary" :loading="submitting" @click="submitRoleForm">保存</wd-button>
<wd-button type="primary" :loading="isSubmitting" @click="submitRoleForm">保存</wd-button>
</view>
</view>
</wd-popup>
@@ -120,7 +120,7 @@ const toast = useToast();
const { messageBox } = useMessage();
const loadMoreState = ref<LoadMoreState>("loading");
const formRef = ref();
const submitting = ref(false);
const isSubmitting = ref(false);
const queryParams = reactive<RolePageQuery>({ pageNum: 1, pageSize: 10, keywords: "" });
const total = ref(0);
@@ -198,7 +198,7 @@ async function openRoleDialog(id?: number) {
function submitRoleForm() {
formRef.value.validate().then(({ valid }: { valid: boolean }) => {
if (!valid) return;
submitting.value = true;
isSubmitting.value = true;
const action = formData.id ? RoleAPI.update(formData.id, formData) : RoleAPI.add(formData);
action
.then(() => {
@@ -207,7 +207,7 @@ function submitRoleForm() {
loadRoleList();
})
.finally(() => {
submitting.value = false;
isSubmitting.value = false;
});
});
}
+9 -9
View File
@@ -52,7 +52,7 @@
>
<!-- 主信息行 -->
<view class="flex-start">
<image class="user-card__avatar" :src="item.avatar" mode="aspectFill" />
<image class="user-card__avatar" :src="item.avatar" mode="aspectFill" lazy-load />
<view class="user-card__main">
<view class="flex-start mt-12rpx">
<text class="user-card__name">{{ item.nickname }}</text>
@@ -149,7 +149,7 @@
</wd-form>
<view class="popup-actions">
<wd-button type="info" plain @click="closeUserDialog">取消</wd-button>
<wd-button type="primary" :loading="submitting" @click="submitUserForm">保存</wd-button>
<wd-button type="primary" :loading="isSubmitting" @click="submitUserForm">保存</wd-button>
</view>
</view>
</wd-popup>
@@ -187,7 +187,7 @@
<wd-button type="info" plain @click="resetPwdDialog.visible = false">取消</wd-button>
<wd-button
type="primary"
:loading="resetPwdDialog.submitting"
:loading="resetPwdDialog.isSubmitting"
@click="handleResetPassword"
>
确认
@@ -213,7 +213,7 @@ const { messageBox } = useMessage();
const { closeOutside } = useQueue();
const loadMoreState = ref<LoadMoreState>("loading");
const formRef = ref();
const submitting = ref(false);
const isSubmitting = ref(false);
const sortValue = ref(0);
const sortOptions = ref([
@@ -394,7 +394,7 @@ async function openUserDialog(id?: number) {
function submitUserForm() {
formRef.value.validate().then(({ valid }: { valid: boolean }) => {
if (!valid) return;
submitting.value = true;
isSubmitting.value = true;
const action = formData.id ? UserAPI.update(formData.id, formData) : UserAPI.add(formData);
action
.then(() => {
@@ -403,7 +403,7 @@ function submitUserForm() {
loadUserList();
})
.finally(() => {
submitting.value = false;
isSubmitting.value = false;
});
});
}
@@ -421,7 +421,7 @@ const pendingAction = ref<Record<string, () => void>>({});
const resetPwdDialog = reactive({
visible: false,
submitting: false,
isSubmitting: false,
userId: undefined as number | undefined,
});
const resetPwdForm = reactive({ password: "" });
@@ -493,7 +493,7 @@ async function handleResetPassword() {
if (!valid || valid.valid === false) return;
if (!resetPwdDialog.userId) return;
resetPwdDialog.submitting = true;
resetPwdDialog.isSubmitting = true;
try {
await UserAPI.resetPassword(resetPwdDialog.userId, resetPwdForm.password);
toast.success("密码重置成功");
@@ -501,7 +501,7 @@ async function handleResetPassword() {
} catch (error) {
// API 已处理错误提示
} finally {
resetPwdDialog.submitting = false;
resetPwdDialog.isSubmitting = false;
}
}