feat: 新增扫码登录功能并优化 SSE、请求拦截与多页面适配

This commit is contained in:
Ray.Hao committed 2026-08-23 16:24:59 +08:00
1 parent 484e7047f5
commit 907b07f552
30 files changed
+259 -142

No files matched your search

+21 -19
View File
@@ -120,9 +120,7 @@
<!-- 登录按钮 -->
<view class="login__form-item">
<wd-button block :loading="isLoading" @click="handleLogin">
登 录
</wd-button>
<wd-button block :loading="isLoading" @click="handleLogin">登 录</wd-button>
</view>
<!-- 切换登录方式 -->
@@ -243,9 +241,7 @@
<text class="login__demo-hint-text">演示环境验证码:123456</text>
</view>
<wd-button block :loading="isBindLoading" @click="handleBindMobile">
确认绑定
</wd-button>
<wd-button block :loading="isBindLoading" @click="handleBindMobile">确认绑定</wd-button>
</view>
</view>
</wd-popup>
@@ -264,6 +260,7 @@ import type { FormSchema } from "@wot-ui/ui/components/wd-form/types";
import { useUserStore } from "@/store/modules/user";
import { useCountdown } from "@/composables/useCountdown";
import { getErrorMessage } from "@/utils";
import AuthAPI from "@/api/auth";
definePage({
@@ -432,8 +429,8 @@ async function doFormLogin() {
await userStore.getInfo();
toast.success("登录成功");
setTimeout(() => uni.reLaunch({ url: redirect.value }), 800);
} catch (error: any) {
toast.error(error?.message || "登录失败");
} catch (error) {
toast.error(getErrorMessage(error, "登录失败"));
if (loginMode.value === "PASSWORD") fetchCaptcha();
} finally {
isLoading.value = false;
@@ -475,13 +472,18 @@ const handleSendCode = async () => {
await AuthAPI.sendSmsLoginCode(mobile);
toast.success("验证码已发送");
startSmsCountdown();
} catch (error: any) {
toast.error(error?.message || "发送失败");
} catch (error) {
toast.error(getErrorMessage(error, "发送失败"));
}
};
// 微信登录
const handleWechatPhoneLogin = async (e: any) => {
/** 微信手机号快捷填充按钮回调事件 */
interface WxPhoneLoginEvent {
detail: { code?: string };
}
const handleWechatPhoneLogin = async (e: WxPhoneLoginEvent) => {
const phoneCode = e.detail.code;
if (!isAgreePolicy.value) {
openPolicyDialog("WECHAT_PHONE", phoneCode);
@@ -518,7 +520,7 @@ const handleWechatSilentLogin = async () => {
isLoading.value = true;
try {
const { code } = await uni.login();
const result: any = await userStore.loginByWxMa(code);
const result = await userStore.loginByWxMa(code);
if (result.needBindMobile && result.openid) {
wechatOpenid.value = result.openid;
showBindMobilePopup.value = true;
@@ -527,8 +529,8 @@ const handleWechatSilentLogin = async () => {
toast.success("登录成功");
setTimeout(() => uni.reLaunch({ url: redirect.value }), 800);
}
} catch (error: any) {
toast.error(error?.message || "微信登录失败");
} catch (error) {
toast.error(getErrorMessage(error, "微信登录失败"));
} finally {
isLoading.value = false;
}
@@ -546,8 +548,8 @@ const handleSendBindCode = async () => {
await AuthAPI.sendSmsLoginCode(mobile);
toast.success("验证码已发送");
startBindSmsCountdown();
} catch (error: any) {
toast.error(error?.message || "发送失败");
} catch (error) {
toast.error(getErrorMessage(error, "发送失败"));
}
};
@@ -575,8 +577,8 @@ const handleBindMobile = async () => {
resetBindForm();
toast.success("绑定成功");
setTimeout(() => uni.reLaunch({ url: redirect.value }), 800);
} catch (error: any) {
toast.error(error?.message || "绑定失败");
} catch (error) {
toast.error(getErrorMessage(error, "绑定失败"));
} finally {
isBindLoading.value = false;
}
@@ -597,7 +599,7 @@ const handleBack = () => {
};
// 生命周期
onLoad((options: any) => {
onLoad((options) => {
const fromQuery = options?.redirect ? decodeURIComponent(options.redirect) : "";
if (fromQuery && fromQuery !== "/pages/login/index") redirect.value = fromQuery;
uni.setNavigationBarTitle({ title: "" });
+23 -31
View File
@@ -11,6 +11,11 @@
:show-back="false"
:placeholder="false"
>
<template #left>
<view v-if="isLogin" class="mine-navbar__scan" aria-label="扫一扫" @click="scanLogin">
<wd-icon name="scan" size="40rpx" color="var(--color-text-inverse)" />
</view>
</template>
<template #center>
<text class="mine-navbar__title">个人中心</text>
</template>
@@ -65,9 +70,7 @@
</view>
<view v-if="!isLogin" class="profile-card__action" @click.stop="navigateToLogin()">
<wd-button custom-class="profile-card__button" size="small">
立即登录
</wd-button>
<wd-button custom-class="profile-card__button" size="small">立即登录</wd-button>
</view>
</view>
</view>
@@ -132,16 +135,6 @@
</view>
<wd-icon name="right" size="16" color="var(--color-text-placeholder)" />
</view>
<view v-if="isLogin" class="menu-row" @click="handleScan">
<view class="menu-row__icon menu-row__icon--info">
<wd-icon name="scan" size="18" color="var(--color-info)" />
</view>
<view class="menu-row__main">
<text class="menu-row__title">扫一扫</text>
<text class="menu-row__desc">扫描二维码登录 PC</text>
</view>
<wd-icon name="right" size="16" color="var(--color-text-placeholder)" />
</view>
<view class="menu-row" @click="handleClearCache">
<view class="menu-row__icon menu-row__icon--danger">
<wd-icon name="delete" size="18" color="var(--color-danger)" />
@@ -211,6 +204,7 @@ import { onShow } from "@dcloudio/uni-app";
import { useUserStore, useThemeStore } from "@/store";
import { useRouter } from "uni-mini-router";
import { useNavbar } from "@/composables/useNavbar";
import { useScanLogin } from "@/composables/useScanLogin";
import { getAccessToken } from "@/utils/auth";
import { formatBytes } from "@/utils/format";
@@ -388,24 +382,8 @@ const handleClearCache = async () => {
}
};
// 扫一扫:扫描 PC 端二维码后跳转确认页
const handleScan = async () => {
if (!isLogin.value) {
navigateToLogin();
return;
}
try {
const res = await uni.scanCode({ scanType: ["qrCode"] });
const ticket = (res.result || "").trim();
if (!ticket) {
uni.showToast({ title: "无效的二维码", icon: "none" });
return;
}
router.push({ path: "/pages/mine/scan-confirm/index", query: { ticket: encodeURIComponent(ticket) } });
} catch {
// 用户取消扫码,静默处理
}
};
// 扫一扫:扫描 PC 端二维码后跳转确认页(逻辑收敛在 useScanLogin)
const { scanLogin } = useScanLogin();
// 有来技术公众号
const openOfficialAccount = () => {
@@ -455,6 +433,20 @@ const openOfficialAccount = () => {
letter-spacing: 2rpx;
}
/* 扫码入口:渐变背景上的白色图标,64rpx 圆形热区 */
.mine-navbar__scan {
display: flex;
align-items: center;
justify-content: center;
width: 64rpx;
height: 64rpx;
border-radius: 50%;
&:active {
background-color: rgba(255, 255, 255, 0.2);
}
}
.profile-tag {
display: inline-flex;
gap: 8rpx;
+17 -6
View File
@@ -133,6 +133,7 @@ import { ref, reactive, computed } from "vue";
import { onLoad } from "@dcloudio/uni-app";
import { useDialog, useToast } from "@wot-ui/ui";
import { useUserStore } from "@/store";
import { getErrorMessage } from "@/utils";
import UserAPI, { type UserProfileForm } from "@/api/user";
import FileAPI, { type FileInfo } from "@/api/file";
@@ -165,7 +166,7 @@ const canComplete = computed(() => {
return profileForm.nickname && profileForm.mobile;
});
onLoad((options: any) => {
onLoad((options) => {
if (options?.redirect) {
redirect.value = decodeURIComponent(options.redirect);
}
@@ -173,11 +174,21 @@ onLoad((options: any) => {
if (userInfo) {
profileForm.nickname = userInfo.nickname || "";
profileForm.avatar = userInfo.avatar || "";
profileForm.gender = (userInfo as any).gender || 1;
profileForm.gender = userInfo.gender || 1;
}
});
const onChooseAvatar = async (e: any) => {
/** 微信头像选择按钮回调事件(open-type="chooseAvatar") */
interface WxChooseAvatarEvent {
detail: { avatarUrl: string };
}
/** wd-img-cropper 裁剪确认事件 */
interface ImgCropperConfirmEvent {
tempFilePath: string;
}
const onChooseAvatar = async (e: WxChooseAvatarEvent) => {
try {
const { avatarUrl } = e.detail;
toast.loading("上传中...");
@@ -220,7 +231,7 @@ const chooseAvatar = () => {
// #endif
};
const handleAvatarConfirm = async (event: any) => {
const handleAvatarConfirm = async (event: ImgCropperConfirmEvent) => {
try {
const { tempFilePath } = event;
toast.loading("上传中...");
@@ -260,8 +271,8 @@ const handleComplete = async () => {
setTimeout(() => {
uni.reLaunch({ url: redirect.value });
}, 1000);
} catch (error: any) {
toast.error(error?.message || "完善信息失败");
} catch (error) {
toast.error(getErrorMessage(error, "完善信息失败"));
} finally {
isLoading.value = false;
}
+6 -1
View File
@@ -99,7 +99,12 @@ function handleAvatarUpload() {
});
}
// 头像裁剪完成
function handleAvatarConfirm(event: any) {
/** wd-img-cropper 裁剪确认事件 */
interface ImgCropperConfirmEvent {
tempFilePath: string;
}
function handleAvatarConfirm(event: ImgCropperConfirmEvent) {
const { tempFilePath } = event;
FileAPI.upload(tempFilePath).then((fileInfo: FileInfo) => {
const avatarForm: UserProfileForm = {
+6 -5
View File
@@ -35,6 +35,7 @@
import { onLoad } from "@dcloudio/uni-app";
import { useToast } from "@wot-ui/ui";
import { useUserStore } from "@/store/modules/user";
import { getErrorMessage } from "@/utils";
import type { QrCodeScanResult } from "@/api/auth";
definePage({
@@ -61,8 +62,8 @@ const scanResult = ref<QrCodeScanResult | null>(null);
const markScanned = async (code: string) => {
try {
scanResult.value = await userStore.qrScan(code);
} catch (error: any) {
toast.error(error?.message || "二维码无效或已过期");
} catch (error) {
toast.error(getErrorMessage(error, "二维码无效或已过期"));
setTimeout(() => uni.navigateBack(), TOAST_DURATION);
}
};
@@ -75,8 +76,8 @@ const handleConfirm = async () => {
await userStore.qrConfirm(ticket.value);
toast.success("已确认登录");
setTimeout(() => uni.navigateBack(), TOAST_DURATION);
} catch (error: any) {
toast.error(error?.message || "确认失败");
} catch (error) {
toast.error(getErrorMessage(error, "确认失败"));
} finally {
isLoading.value = false;
}
@@ -96,7 +97,7 @@ const handleCancel = async () => {
}
};
onLoad((options: any) => {
onLoad((options) => {
const code = options?.ticket ? decodeURIComponent(options.ticket) : "";
if (!code) {
toast.error("二维码无效");
+1 -3
View File
@@ -67,9 +67,7 @@
<!-- 操作按钮 -->
<view class="mt-32rpx">
<wd-button plain size="large" block @click="handleResetTheme">
重置为默认主题
</wd-button>
<wd-button plain size="large" block @click="handleResetTheme">重置为默认主题</wd-button>
</view>
<!-- 自定义颜色输入弹窗 -->
+2 -2
View File
@@ -15,8 +15,8 @@ definePage({
const url = ref("");
onLoad((query: any) => {
if (query.url) {
onLoad((query) => {
if (query?.url) {
url.value = decodeURIComponent(query.url);
}
});
+3 -5
View File
@@ -72,9 +72,7 @@
</wd-form>
<view class="popup-actions">
<wd-button type="info" variant="plain" @click="closeConfigDialog">取消</wd-button>
<wd-button :loading="isSubmitting" @click="submitConfigForm">
保存
</wd-button>
<wd-button :loading="isSubmitting" @click="submitConfigForm">保存</wd-button>
</view>
</view>
</wd-popup>
@@ -154,7 +152,7 @@ function loadConfigList() {
function fetchConfigList() {
loadMoreState.value = "loading";
ConfigAPI.getPage(queryParams)
.then((data: any) => {
.then((data) => {
pageData.value = data.list;
total.value = data.total;
queryParams.pageNum++;
@@ -205,7 +203,7 @@ function closeConfigDialog() {
}
// 操作菜单分发
function handleActionSelect({ item }: { item: any }) {
function handleActionSelect({ item }: { item: { name: string } }) {
const value = item.name;
const configItem = currentActionItem.value;
if (value === "编辑") {
+17 -8
View File
@@ -104,9 +104,10 @@ import { onLoad } from "@dcloudio/uni-app";
import { toFormSchema } from "@/utils/form";
import { findOptionChain } from "@/utils/tree";
import { useToast, useDialog } from "@wot-ui/ui";
import type { CascaderOption } from "@wot-ui/ui/components/wd-cascader/types";
import DeptAPI, { type DeptQuery, DeptItem, DeptForm } from "@/api/dept";
import { hasPermission } from "@/utils/permission";
import CustomTree from "@/components/custom-tree/index.vue";
import CustomTree, { type TreeOption } from "@/components/custom-tree/index.vue";
definePage({
name: "dept",
@@ -140,10 +141,10 @@ const formData = reactive<DeptForm>({ ...initialFormData });
// 转换为树组件数据格式
const treeData = computed(() => deptList.value.map((dept) => transformDeptToTree(dept)));
function transformDeptToTree(dept: DeptItem): any {
function transformDeptToTree(dept: DeptItem): TreeOption {
return {
value: String(dept.id),
label: dept.name,
label: dept.name ?? "",
id: dept.id,
name: dept.name,
status: dept.status,
@@ -158,10 +159,16 @@ const parentOptions = ref<OptionType[]>([]);
const parentLabel = ref("");
// 上级部门确认选择
const handleParentConfirm = ({ value, selectedOptions }: any) => {
const handleParentConfirm = ({
value,
selectedOptions,
}: {
value: string | number;
selectedOptions: CascaderOption[];
}) => {
parentSelected.value = value;
formData.parentId = Number(value) || 0;
parentLabel.value = selectedOptions.map((item: any) => item.label).join("/");
parentLabel.value = selectedOptions.map((item) => String(item.label ?? "")).join("/");
};
const rules = toFormSchema({
@@ -185,7 +192,7 @@ function loadDeptList() {
}
// 操作菜单分发
function handleActionSelect({ item }: { item: any }) {
function handleActionSelect({ item }: { item: { name: string } }) {
const value = item.name;
const dept = currentActionItem.value;
if (value === "新增子部门") {
@@ -206,7 +213,7 @@ function handleActionSelect({ item }: { item: any }) {
}
// 处理节点操作按钮点击
function handleNodeAction(node: any) {
function handleNodeAction(node: TreeOption) {
const dept: DeptItem = {
id: node.id,
name: node.label,
@@ -272,7 +279,9 @@ function handleAddChild(dept: DeptItem) {
formData.parentId = dept.id!;
parentSelected.value = dept.id!;
parentLabel.value =
findOptionChain(treeData.value, dept.id!)?.map((option) => option.label).join("/") ||
findOptionChain(treeData.value, dept.id!)
?.map((option) => option.label)
.join("/") ||
dept.name ||
"";
}
+2 -2
View File
@@ -147,7 +147,7 @@ function loadDictTypeList() {
function fetchDictTypeList() {
loadMoreState.value = "loading";
DictAPI.getPage(queryParams)
.then((data: any) => {
.then((data) => {
pageData.value = data.list;
total.value = data.total;
queryParams.pageNum++;
@@ -249,7 +249,7 @@ function showDictActions(item: DictTypeItem) {
actionSheetVisible.value = true;
}
function handleActionSelect({ item }: { item: any }) {
function handleActionSelect({ item }: { item: { name: string } }) {
pendingAction.value[item.name]?.();
}
+5 -5
View File
@@ -163,7 +163,7 @@ function fetchItemList() {
loadMoreState.value = "loading";
DictAPI.getItemPage(dictCode.value, queryParams)
.then((data: any) => {
.then((data) => {
pageData.value = data.list;
total.value = data.total;
queryParams.pageNum++;
@@ -264,7 +264,7 @@ function showItemActions(item: DictDataItem) {
actionSheetVisible.value = true;
}
function handleActionSelect({ item }: { item: any }) {
function handleActionSelect({ item }: { item: { name: string } }) {
pendingAction.value[item.name]?.();
}
@@ -276,9 +276,9 @@ onReachBottom(() => {
}
});
onLoad((query: any) => {
dictCode.value = String((query as any)?.dictCode || "");
pageTitle.value = String((query as any)?.title || "字典数据");
onLoad((query) => {
dictCode.value = String(query?.dictCode || "");
pageTitle.value = String(query?.title || "字典数据");
if (pageTitle.value) {
uni.setNavigationBarTitle({ title: pageTitle.value });
}
+24 -11
View File
@@ -81,7 +81,11 @@
<wd-radio value="B">按钮</wd-radio>
</wd-radio-group>
</wd-form-item>
<wd-form-item v-if="formData.type === 'C' || formData.type === 'M'" prop="routePath" title="路由路径">
<wd-form-item
v-if="formData.type === 'C' || formData.type === 'M'"
prop="routePath"
title="路由路径"
>
<wd-input v-model="formData.routePath" placeholder="system 或 /system" />
</wd-form-item>
<wd-form-item v-if="formData.type === 'E'" prop="externalUrl" title="外链地址">
@@ -136,7 +140,8 @@ import { findOptionChain } from "@/utils/tree";
import { useToast, useDialog } from "@wot-ui/ui";
import MenuAPI, { type MenuQuery, MenuItem, MenuForm } from "@/api/menu";
import { hasPermission } from "@/utils/permission";
import CustomTree from "@/components/custom-tree/index.vue";
import CustomTree, { type TreeOption } from "@/components/custom-tree/index.vue";
import type { CascaderOption } from "@wot-ui/ui/components/wd-cascader/types";
definePage({
name: "menu",
@@ -175,10 +180,10 @@ const formData = reactive<MenuForm>({ ...initialFormData });
// 转换为树组件数据格式
const treeData = computed(() => menuList.value.map((menu: MenuItem) => transformMenuToTree(menu)));
function transformMenuToTree(menu: MenuItem): any {
function transformMenuToTree(menu: MenuItem): TreeOption {
return {
value: menu.id,
label: menu.name,
value: menu.id ?? "",
label: menu.name ?? "",
id: menu.id,
name: menu.name,
type: menu.type,
@@ -221,10 +226,16 @@ const parentOptions = ref<OptionType[]>([]);
const parentLabel = ref("");
// 上级菜单确认选择
const handleParentConfirm = ({ value, selectedOptions }: any) => {
const handleParentConfirm = ({
value,
selectedOptions,
}: {
value: string | number;
selectedOptions: CascaderOption[];
}) => {
parentSelected.value = value;
formData.parentId = String(value) || "0";
parentLabel.value = selectedOptions.map((item: any) => item.label).join("/");
parentLabel.value = selectedOptions.map((item) => String(item.label ?? "")).join("/");
};
const rules = toFormSchema({
@@ -236,13 +247,13 @@ const rules = toFormSchema({
const handleSearch = () => loadMenuList();
function loadMenuList() {
MenuAPI.getList(queryParams).then((data: any) => {
MenuAPI.getList(queryParams).then((data) => {
menuList.value = data;
});
}
// 操作菜单分发
function handleActionSelect({ item }: { item: any }) {
function handleActionSelect({ item }: { item: { name: string } }) {
const value = item.name;
const menu = currentActionItem.value;
if (value === "新增子菜单") {
@@ -263,7 +274,7 @@ function handleActionSelect({ item }: { item: any }) {
}
// 处理节点操作按钮点击
function handleNodeAction(node: any) {
function handleNodeAction(node: TreeOption) {
const menu: MenuItem = {
id: node.id,
name: node.label,
@@ -330,7 +341,9 @@ function handleAddChild(menu: MenuItem) {
formData.parentId = menu.id!;
parentSelected.value = menu.id!;
parentLabel.value =
findOptionChain(treeData.value, menu.id!)?.map((option) => option.label).join("/") ||
findOptionChain(treeData.value, menu.id!)
?.map((option) => option.label)
.join("/") ||
menu.name ||
"";
}
+2 -4
View File
@@ -134,9 +134,7 @@
</wd-form>
<view class="popup-actions">
<wd-button type="info" variant="plain" @click="closeNoticeForm">取消</wd-button>
<wd-button :loading="isSubmitting" @click="submitNoticeForm">
保存
</wd-button>
<wd-button :loading="isSubmitting" @click="submitNoticeForm">保存</wd-button>
</view>
</view>
</wd-popup>
@@ -390,7 +388,7 @@ function showNoticeActions(item: NoticeItem) {
actionSheetVisible.value = true;
}
function handleActionSelect({ item }: { item: any }) {
function handleActionSelect({ item }: { item: { name: string } }) {
pendingAction.value[item.name]?.();
}
+3 -1
View File
@@ -10,7 +10,9 @@
<view class="action-bar">
<view class="action-bar__left">
<wd-button type="" size="small" variant="plain" @click="handleSelectAll">全选</wd-button>
<wd-button type="" size="small" variant="plain" @click="handleClearAll">取消全选</wd-button>
<wd-button type="" size="small" variant="plain" @click="handleClearAll">
取消全选
</wd-button>
</view>
</view>
</view>
+2 -2
View File
@@ -254,7 +254,7 @@ function closeRoleDialog() {
}
// 操作菜单分发
function handleActionSelect({ item }: { item: any }) {
function handleActionSelect({ item }: { item: { name: string } }) {
const value = item.name;
const role = currentActionItem.value;
if (value === "编辑") {
@@ -267,7 +267,7 @@ function handleActionSelect({ item }: { item: any }) {
msg: `确定要删除角色「${role.name}」吗?`,
headerImage: "warning",
}).then(async () => {
await RoleAPI.deleteByIds(String(item.id));
await RoleAPI.deleteByIds(String(role.id));
toast.success("删除成功");
loadRoleList();
});
+25 -15
View File
@@ -202,10 +202,7 @@
<wd-button type="info" variant="plain" @click="resetPwdDialog.visible = false">
取消
</wd-button>
<wd-button
:loading="resetPwdDialog.isSubmitting"
@click="handleResetPassword"
>
<wd-button :loading="resetPwdDialog.isSubmitting" @click="handleResetPassword">
确认
</wd-button>
</view>
@@ -217,6 +214,7 @@
<script lang="ts" setup>
import { onLoad, onReachBottom } from "@dcloudio/uni-app";
import { LoadMoreState } from "@wot-ui/ui/components/wd-loadmore/types";
import type { CascaderOption } from "@wot-ui/ui/components/wd-cascader/types";
import { toFormSchema } from "@/utils/form";
import { findOptionChain } from "@/utils/tree";
import { useQueue, useToast, useDialog } from "@wot-ui/ui";
@@ -261,7 +259,7 @@ const initialFormData: UserForm = {
};
const formData = reactive<UserForm>({ ...initialFormData });
const roleOptions = ref<Record<string, any>[]>([]);
const roleOptions = ref<OptionType[]>([]);
const deptOptions = ref<OptionType[]>([]);
// 部门选择器状态
@@ -274,14 +272,25 @@ const showRolePicker = ref(false);
const roleLabel = ref("");
// 部门确认选择
const handleDeptConfirm = ({ value, selectedOptions }: any) => {
formData.deptId = value;
deptLabel.value = selectedOptions.map((item: any) => item.label).join("/");
const handleDeptConfirm = ({
value,
selectedOptions,
}: {
value: string | number;
selectedOptions: CascaderOption[];
}) => {
formData.deptId = Number(value);
deptLabel.value = selectedOptions.map((item) => String(item.label ?? "")).join("/");
};
// 角色确认选择
const handleRoleConfirm = ({ selectedItems }: any) => {
roleLabel.value = selectedItems.map((item: any) => item.label).join("、");
const handleRoleConfirm = ({
selectedItems,
}: {
value: (string | number)[];
selectedItems: OptionType[];
}) => {
roleLabel.value = selectedItems.map((item) => item.label).join("、");
};
const rules = toFormSchema({
@@ -336,7 +345,7 @@ function resetUserFilter() {
function fetchUserList() {
loadMoreState.value = "loading";
UserAPI.getPage(queryParams)
.then((data: any) => {
.then((data) => {
pageData.value = data.list;
total.value = data.total;
queryParams.pageNum++;
@@ -371,11 +380,12 @@ async function openUserDialog(user?: UserItem) {
const chain = findOptionChain(deptData, data.deptId);
deptLabel.value = chain ? chain.map((option) => option.label).join("/") : user.deptName || "";
}
// 回显角色
// 回显角色(roleIds 与选项 value 统一转字符串比较,兼容数字/字符串ID)
if (data.roleIds && data.roleIds.length > 0) {
const roleIds = data.roleIds.map(String);
const names = roleOptions.value
.filter((r: any) => data.roleIds.includes(r.value))
.map((r: any) => r.label);
.filter((r) => roleIds.includes(String(r.value)))
.map((r) => r.label);
roleLabel.value = names.join("、");
}
}
@@ -464,7 +474,7 @@ function showUserActions(item: UserItem) {
actionSheetVisible.value = true;
}
function handleActionSelect({ item }: { item: any }) {
function handleActionSelect({ item }: { item: { name: string } }) {
pendingAction.value[item.name]?.();
}