From 89a49cf19c8935a03fefccc3cf95d88b8565eb13 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Thu, 28 May 2026 23:38:46 +0800 Subject: [PATCH] =?UTF-8?q?refactor(frontend):=20=E7=BB=9F=E4=B8=80?= =?UTF-8?q?=E5=BD=93=E5=89=8D=E7=99=BB=E5=BD=95=E7=94=A8=E6=88=B7=20ID=20?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E5=85=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 getCurrentUserId 到 utils/auth - 替换 IM、CRM、BPM、MES、Mall 等模块中直接读取 userStore.getUser.id 的写法 - 移除 IM 内部 currentUser 工具依赖,统一从全局 auth 工具获取当前用户编号 - 保留 userStore 对昵称、头像、部门等非 ID 字段的读取 --- .../FormCreate/src/components/useApiSelect.tsx | 6 ++---- src/utils/auth.ts | 6 ++++++ src/views/bpm/model/CategoryDraggableModel.vue | 5 ++--- src/views/bpm/model/form/index.vue | 5 ++--- .../detail/ProcessInstanceOperationButton.vue | 4 ++-- src/views/crm/business/BusinessForm.vue | 4 ++-- src/views/crm/clue/ClueForm.vue | 4 ++-- src/views/crm/contact/ContactForm.vue | 4 ++-- src/views/crm/contract/ContractForm.vue | 4 ++-- src/views/crm/customer/CustomerForm.vue | 4 ++-- src/views/crm/customer/CustomerImportForm.vue | 4 ++-- .../crm/permission/components/PermissionList.vue | 15 ++++++++------- src/views/crm/product/ProductForm.vue | 4 ++-- src/views/crm/receivable/ReceivableForm.vue | 4 ++-- .../crm/receivable/plan/ReceivablePlanForm.vue | 4 ++-- .../im/home/components/friend/FriendAddDialog.vue | 2 +- src/views/im/home/components/group/GroupInfo.vue | 5 ++--- .../components/group/GroupMemberAddDialog.vue | 5 ++--- .../im/home/components/rtc/RtcCallContainer.vue | 2 +- .../components/rtc/RtcCallMemberPickerDialog.vue | 2 +- .../im/home/components/rtc/RtcGroupCallBanner.vue | 2 +- .../im/home/components/user/UserInfoCard.vue | 5 ++--- src/views/im/home/composables/useMediaUploader.ts | 5 ++--- src/views/im/home/composables/useMessagePuller.ts | 2 +- src/views/im/home/composables/useMessageSender.ts | 5 ++--- src/views/im/home/composables/useMuteOverlay.ts | 5 ++--- .../im/home/pages/contact/FriendRequestDetail.vue | 2 +- .../im/home/pages/contact/FriendRequestList.vue | 2 +- .../conversation/ConversationGroupSide.vue | 5 ++--- .../components/input/MentionPicker.vue | 5 ++--- .../components/input/MessageInput.vue | 5 ++--- .../components/message/GroupPinnedMessage.vue | 5 ++--- .../components/message/GroupRequestPending.vue | 5 ++--- .../components/message/MessageItem.vue | 9 +++++---- src/views/im/home/store/channelStore.ts | 12 +++++------- src/views/im/home/store/conversationStore.ts | 2 +- src/views/im/home/store/friendStore.ts | 2 +- src/views/im/home/store/groupStore.ts | 2 +- src/views/im/home/store/messageStore.ts | 2 +- src/views/im/home/store/rtcStore.ts | 2 +- src/views/im/home/store/websocketStore.ts | 12 ++++-------- src/views/im/utils/db.ts | 2 +- src/views/im/utils/message.ts | 2 +- src/views/im/utils/user.ts | 9 +-------- .../mall/trade/delivery/pickUpOrder/index.vue | 4 ++-- .../mes/dv/maintenrecord/MaintenRecordForm.vue | 5 ++--- .../mes/pro/andon/record/AndonRecordForm.vue | 7 +++---- src/views/mes/pro/feedback/FeedbackForm.vue | 4 ++-- src/views/mes/pro/feedback/index.vue | 4 ++-- .../mes/wm/stocktaking/task/StockTakingForm.vue | 4 ++-- 50 files changed, 104 insertions(+), 126 deletions(-) diff --git a/src/components/FormCreate/src/components/useApiSelect.tsx b/src/components/FormCreate/src/components/useApiSelect.tsx index 847eb077c..98466c32b 100644 --- a/src/components/FormCreate/src/components/useApiSelect.tsx +++ b/src/components/FormCreate/src/components/useApiSelect.tsx @@ -2,7 +2,7 @@ import request from '@/config/axios' import { isEmpty } from '@/utils/is' import { ApiSelectProps } from '@/components/FormCreate/src/type' import { jsonParse } from '@/utils' -import { useUserStoreWithOut } from '@/store/modules/user' +import { getCurrentUserId } from '@/utils/auth' export const useApiSelect = (option: ApiSelectProps) => { return defineComponent({ @@ -99,9 +99,7 @@ export const useApiSelect = (option: ApiSelectProps) => { } // 获取当前用户 ID - const userStore = useUserStoreWithOut() - const user = userStore.getUser - const currentUserId = user?.id + const currentUserId = getCurrentUserId() if (currentUserId) { // 根据多选/单选模式设置默认值 const defaultValue = props.multiple ? [currentUserId] : currentUserId diff --git a/src/utils/auth.ts b/src/utils/auth.ts index ad67440d4..3f76a10b0 100644 --- a/src/utils/auth.ts +++ b/src/utils/auth.ts @@ -37,6 +37,12 @@ export const formatToken = (token: string): string => { } // ========== 账号相关 ========== +/** 获取当前登录用户编号 */ +export const getCurrentUserId = (): number => { + const user = wsCache.get(CACHE_KEY.USER)?.user + return Number(user?.id) || 0 +} + export type LoginFormType = { tenantName: string username: string diff --git a/src/views/bpm/model/CategoryDraggableModel.vue b/src/views/bpm/model/CategoryDraggableModel.vue index 003e46f3c..c2c679310 100644 --- a/src/views/bpm/model/CategoryDraggableModel.vue +++ b/src/views/bpm/model/CategoryDraggableModel.vue @@ -284,7 +284,7 @@ import * as FormApi from '@/api/bpm/form' import { setConfAndFields2 } from '@/utils/formCreate' import { BpmModelFormType } from '@/utils/constants' import { checkPermi } from '@/utils/permission' -import { useUserStoreWithOut } from '@/store/modules/user' +import { getCurrentUserId } from '@/utils/auth' import { useAppStore } from '@/store/modules/app' import { cloneDeep, isEqual } from 'lodash-es' import { useDebounceFn } from '@vueuse/core' @@ -333,7 +333,6 @@ const emit = defineEmits(['success']) const message = useMessage() // 消息弹窗 const { t } = useI18n() // 国际化 const { push } = useRouter() // 路由 -const userStore = useUserStoreWithOut() // 用户信息缓存 const isDark = computed(() => useAppStore().getIsDark) // 是否黑暗模式 const router = useRouter() // 路由 @@ -501,7 +500,7 @@ const handleFormDetail = async (row: any) => { /** 判断是否可以操作 */ const isManagerUser = (row: any) => { - const userId = userStore.getUser.id + const userId = getCurrentUserId() return row.managerUserIds && row.managerUserIds.includes(userId) } diff --git a/src/views/bpm/model/form/index.vue b/src/views/bpm/model/form/index.vue index 9974f0829..2d7e84987 100644 --- a/src/views/bpm/model/form/index.vue +++ b/src/views/bpm/model/form/index.vue @@ -88,7 +88,7 @@ import { useRoute, useRouter } from 'vue-router' import { useMessage } from '@/hooks/web/useMessage' import { useTagsViewStore } from '@/store/modules/tagsView' -import { useUserStoreWithOut } from '@/store/modules/user' +import { getCurrentUserId } from '@/utils/auth' import * as ModelApi from '@/api/bpm/model' import * as FormApi from '@/api/bpm/form' import { CategoryApi, CategoryVO } from '@/api/bpm/category' @@ -107,7 +107,6 @@ const { delView } = useTagsViewStore() // 视图操作 const tagsView = useTagsView() const route = useRoute() const message = useMessage() -const userStore = useUserStoreWithOut() // 组件引用 const basicInfoRef = ref() @@ -237,7 +236,7 @@ const initData = async () => { } else { // 情况三:新增场景 formData.value.startUserType = 0 // 全体 - formData.value.managerUserIds.push(userStore.getUser.id) + formData.value.managerUserIds.push(getCurrentUserId()) } // 获取表单列表 diff --git a/src/views/bpm/processInstance/detail/ProcessInstanceOperationButton.vue b/src/views/bpm/processInstance/detail/ProcessInstanceOperationButton.vue index 53b10bdfc..85e0d3bad 100644 --- a/src/views/bpm/processInstance/detail/ProcessInstanceOperationButton.vue +++ b/src/views/bpm/processInstance/detail/ProcessInstanceOperationButton.vue @@ -513,7 +513,7 @@