From 9678f262a97bce237c1b1c219b25ce407a7e2395 Mon Sep 17 00:00:00 2001 From: zhx Date: Thu, 25 Jun 2026 19:29:26 +0800 Subject: [PATCH] 1 --- .../components/team-manager-form-modal.vue | 94 +++++++++++++++++-- apps/src/views/team/manager-list.vue | 38 +++++++- 2 files changed, 121 insertions(+), 11 deletions(-) diff --git a/apps/src/views/team/components/team-manager-form-modal.vue b/apps/src/views/team/components/team-manager-form-modal.vue index 0658561..4cc8e6b 100644 --- a/apps/src/views/team/components/team-manager-form-modal.vue +++ b/apps/src/views/team/components/team-manager-form-modal.vue @@ -53,6 +53,46 @@ const form = reactive({ const isUpdate = computed(() => Boolean(props.row?.id)); const title = computed(() => (isUpdate.value ? '修改经理' : '添加经理')); +function normalizeFeatureEnabled(value: unknown) { + if (value === undefined || value === null || value === '') { + return true; + } + if (typeof value === 'boolean') { + return value; + } + if (typeof value === 'number') { + return value !== 0; + } + const normalized = String(value).trim().toLowerCase(); + return !['0', 'false', 'n', 'no', 'off', '关', '关闭'].includes(normalized); +} + +function camelToSnake(key: string) { + return key.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`); +} + +function featurePayloadKey(key: FeatureSwitchKey) { + const bodyKey = key.replace(/^can/, ''); + return bodyKey ? `${bodyKey[0]?.toLowerCase()}${bodyKey.slice(1)}` : key; +} + +function rowFeatureValue(row: null | Record, key: FeatureSwitchKey) { + const snakeKey = camelToSnake(key); + const value = Object.prototype.hasOwnProperty.call(row || {}, key) + ? row?.[key] + : undefined; + if (value !== undefined) { + return value; + } + if (Object.prototype.hasOwnProperty.call(row || {}, snakeKey)) { + return row?.[snakeKey]; + } + const payloadKey = featurePayloadKey(key); + return Object.prototype.hasOwnProperty.call(row?.features || {}, payloadKey) + ? row?.features?.[payloadKey] + : row?.features?.[key]; +} + watch( () => props.open, (open) => { @@ -64,15 +104,19 @@ watch( form.sysOrigin = props.row?.sysOrigin || props.sysOrigin || 'LIKEI'; form.contact = props.row?.contact || ''; form.regionId = String(props.row?.regionId || ''); - form.canAddBdLeader = props.row?.canAddBdLeader !== false; - form.canGiftProps = props.row?.canGiftProps !== false; - form.canBanUser = props.row?.canBanUser !== false; - form.canUnbanUser = props.row?.canUnbanUser !== false; - form.canChangeCountry = props.row?.canChangeCountry !== false; + form.canAddBdLeader = normalizeFeatureEnabled(rowFeatureValue(props.row, 'canAddBdLeader')); + form.canGiftProps = normalizeFeatureEnabled(rowFeatureValue(props.row, 'canGiftProps')); + form.canBanUser = normalizeFeatureEnabled(rowFeatureValue(props.row, 'canBanUser')); + form.canUnbanUser = normalizeFeatureEnabled(rowFeatureValue(props.row, 'canUnbanUser')); + form.canChangeCountry = normalizeFeatureEnabled(rowFeatureValue(props.row, 'canChangeCountry')); }, { immediate: true }, ); +function setFeature(key: FeatureSwitchKey, checked: unknown) { + form[key] = normalizeFeatureEnabled(checked); +} + function toggleFeature(key: FeatureSwitchKey) { form[key] = !form[key]; } @@ -153,7 +197,12 @@ async function handleSubmit() { @keydown.space.prevent="toggleFeature('canAddBdLeader')" > 加BD Leader - + + +
赠送道具 - + + +
封禁用户 - + + +
解封用户 - + + +
改国家 - + + +
@@ -230,4 +299,9 @@ async function handleSubmit() { outline: 2px solid rgb(22 119 255 / 20%); outline-offset: 2px; } + +.feature-switch-control { + align-items: center; + display: inline-flex; +} diff --git a/apps/src/views/team/manager-list.vue b/apps/src/views/team/manager-list.vue index 185908b..5e428b6 100644 --- a/apps/src/views/team/manager-list.vue +++ b/apps/src/views/team/manager-list.vue @@ -85,8 +85,44 @@ function getUserShortId(profile?: Record | null) { return profile?.actualAccount || profile?.account || profile?.id || '-'; } +function normalizeFeatureEnabled(value: unknown) { + if (value === undefined || value === null || value === '') { + return true; + } + if (typeof value === 'boolean') { + return value; + } + if (typeof value === 'number') { + return value !== 0; + } + const normalized = String(value).trim().toLowerCase(); + return !['0', 'false', 'n', 'no', 'off', '关', '关闭'].includes(normalized); +} + +function camelToSnake(key: string) { + return key.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`); +} + +function featurePayloadKey(key: string) { + const bodyKey = key.replace(/^can/, ''); + return bodyKey ? `${bodyKey[0]?.toLowerCase()}${bodyKey.slice(1)}` : key; +} + function isFeatureEnabled(record: Record, key: string) { - return record?.[key] !== false; + const snakeKey = camelToSnake(key); + let value = Object.prototype.hasOwnProperty.call(record || {}, key) + ? record?.[key] + : undefined; + if (value === undefined && Object.prototype.hasOwnProperty.call(record || {}, snakeKey)) { + value = record?.[snakeKey]; + } + if (value === undefined && record?.features) { + const payloadKey = featurePayloadKey(key); + value = Object.prototype.hasOwnProperty.call(record.features, payloadKey) + ? record.features[payloadKey] + : record.features[key]; + } + return normalizeFeatureEnabled(value); } async function loadData(reset = false) {