diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 0e7d2f5..d1c8944 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,9 +4,8 @@
-
+
-
@@ -38,15 +37,17 @@
"junie.onboarding.icon.badge.shown": "true",
"last_opened_file_path": "/Users/gxwebsoft/VUE/websopy-taro/src/passport",
"node.js.detected.package.eslint": "true",
+ "node.js.detected.package.stylelint": "true",
"node.js.detected.package.tslint": "true",
"node.js.selected.package.eslint": "(autodetect)",
+ "node.js.selected.package.stylelint": "/Users/gxwebsoft/VUE/websopy-taro/node_modules/stylelint",
"node.js.selected.package.tslint": "(autodetect)",
"nodejs_package_manager_path": "pnpm",
"npm.build:weapp.executor": "Run",
"npm.dev:weapp.executor": "Run",
"settings.editor.selected.configurable": "preferences.pluginManager",
"to.speed.mode.migration.done": "true",
- "ts.external.directory.path": "/Applications/WebStorm.app/Contents/plugins/javascript-plugin/jsLanguageServicesImpl/external",
+ "ts.external.directory.path": "/Users/gxwebsoft/VUE/websopy-taro/node_modules/typescript/lib",
"vue.rearranger.settings.migration": "true"
}
}
@@ -115,15 +116,7 @@
-
-
-
-
- 1775902053962
-
-
-
- 1775902053962
+
@@ -509,7 +502,15 @@
1784136882898
-
+
+
+ 1784586922535
+
+
+
+ 1784586922535
+
+
@@ -529,7 +530,6 @@
-
@@ -554,7 +554,8 @@
-
+
+
\ No newline at end of file
diff --git a/.workbuddy/memory/2026-07-21.md b/.workbuddy/memory/2026-07-21.md
new file mode 100644
index 0000000..750d912
--- /dev/null
+++ b/.workbuddy/memory/2026-07-21.md
@@ -0,0 +1,9 @@
+# 2026-07-21
+
+## VIP 角色绑定改为动态查询(去硬编码)
+- 问题:`src/pages/user/vip-review/index.tsx` 中 `VIP_ROLE_ID = 2032` 写死,跨租户不适用。
+- 改动:
+ - `src/api/system/role/model/index.ts`:给 `RoleParam` 增加 `tenantId?: number | string` 字段,支持按租户过滤角色。
+ - `vip-review/index.tsx`:新增 `getCurrentTenantId()`(取自 `Taro.getStorageSync('TenantId') || TenantId`)与 `getVipRoleId()`(调用 `listRoles({ roleCode:'vip', tenantId })` 动态获取 roleId);`assignVipRole` 改用动态 roleId,并在 `addUserRole` 时带上 `tenantId`。
+ - 导入补充:`listRoles` (from `@/api/system/role`)、`TenantId` (from `@/config/app`)。
+- 约定:VIP 角色以 `roleCode='vip'` 标识,不再依赖固定 roleId。
diff --git a/src/api/system/role/model/index.ts b/src/api/system/role/model/index.ts
index d4c9a50..40896a4 100644
--- a/src/api/system/role/model/index.ts
+++ b/src/api/system/role/model/index.ts
@@ -24,4 +24,6 @@ export interface RoleParam extends PageParam {
roleName?: string;
roleCode?: string;
comments?: string;
+ // 租户ID(多租户隔离:按租户查询角色)
+ tenantId?: number | string;
}
diff --git a/src/pages/user/vip-review/index.tsx b/src/pages/user/vip-review/index.tsx
index 0e03a0e..ba2c2ff 100644
--- a/src/pages/user/vip-review/index.tsx
+++ b/src/pages/user/vip-review/index.tsx
@@ -4,6 +4,8 @@ import Taro, { useDidShow } from '@tarojs/taro'
import { listShopDealerApply, updateShopDealerApply } from '@/api/shop/shopDealerApply'
import type { ShopDealerApply } from '@/api/shop/shopDealerApply/model'
import { addUserRole, listUserRole } from '@/api/system/userRole'
+import { listRoles } from '@/api/system/role'
+import { TenantId } from '@/config/app'
import { getMyClerk } from '@/api/shop/shopStoreUser'
definePageConfig({
@@ -20,10 +22,25 @@ const TABS: { key: TabKey; label: string; status: number }[] = [
]
// VIP 角色信息(对应 system/role 表)
-const VIP_ROLE_ID = 2032
+// 角色 ID 不写死,按 roleCode + 当前租户ID 动态查询
const VIP_ROLE_CODE = 'vip'
const VIP_ROLE_NAME = 'VIP会员'
+// 获取当前租户 ID(登录时写入 storage,未登录时回退到默认租户)
+function getCurrentTenantId(): number | string | undefined {
+ return Taro.getStorageSync('TenantId') || TenantId
+}
+
+/**
+ * 按 roleCode=vip + 当前租户ID 动态查询 VIP 角色,返回 roleId
+ */
+async function getVipRoleId(): Promise {
+ const tenantId = getCurrentTenantId()
+ const roles = await listRoles({ roleCode: VIP_ROLE_CODE, tenantId })
+ const vip = (roles || []).find(r => r.roleCode === VIP_ROLE_CODE)
+ return vip?.roleId
+}
+
// 格式化时间戳
function formatTime(time?: number | string): string {
if (!time) return '-'
@@ -56,15 +73,23 @@ function formatDateTime(date: Date): string {
/**
* 给用户添加 VIP 角色
+ * 角色 ID 按 roleCode=vip + 当前租户ID 动态查询,避免写死;
* 先查询是否已有 VIP 角色,没有则新增,避免重复绑定
*/
async function assignVipRole(userId?: number): Promise {
if (!userId) return
+ // 动态查询当前租户下的 VIP 角色
+ const vipRoleId = await getVipRoleId()
+ if (!vipRoleId) {
+ Taro.showToast({ title: '未找到 VIP 角色配置', icon: 'none' })
+ return
+ }
+
// 查询用户已有角色
const userRoles = await listUserRole({ userId })
const hasVip = (userRoles || []).some(
- r => r.roleId === VIP_ROLE_ID || r.roleCode === VIP_ROLE_CODE
+ r => r.roleId === vipRoleId || r.roleCode === VIP_ROLE_CODE
)
if (hasVip) {
@@ -75,9 +100,10 @@ async function assignVipRole(userId?: number): Promise {
// 新增 VIP 角色绑定
await addUserRole({
userId,
- roleId: VIP_ROLE_ID,
+ roleId: vipRoleId,
roleCode: VIP_ROLE_CODE,
roleName: VIP_ROLE_NAME,
+ tenantId: getCurrentTenantId(),
})
}