fix(admin): 企业微信管理界面增加从OA一键同步企业微信ID功能
This commit is contained in:
1 parent
6baeffba64
commit
638fdcb7fd
15 files changed
+570
-135
No files matched your search
@@ -1,7 +1,9 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* features/admin/modules/wecom/components/WecomSyncPanel.vue
|
||||
* 企微通讯录 userid 一键同步面板(预览 + 确认写入)。
|
||||
* OA userInfo_view 工号→wecom_userid 同步面板(预览 + 确认写入)。
|
||||
* 依赖:useWecomSync、WECOM_ADMIN_KEY.refreshWecomData。
|
||||
* 逻辑:绑定管理页调用;先扫本地工号,再按 IN 查 OA userInfo_view 匹配写入。
|
||||
*/
|
||||
import { inject } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
@@ -15,13 +17,14 @@ const emit = defineEmits<{
|
||||
}>();
|
||||
|
||||
const { t } = useI18n();
|
||||
const { wecomSystemSettings, refreshWecomData } = inject(WECOM_ADMIN_KEY)!;
|
||||
const { refreshWecomData } = inject(WECOM_ADMIN_KEY)!;
|
||||
|
||||
const {
|
||||
departmentId,
|
||||
isSyncing,
|
||||
previewSummary,
|
||||
showApplyConfirm,
|
||||
canApplySync,
|
||||
applyBlockHint,
|
||||
previewSync,
|
||||
requestApplySync,
|
||||
confirmApplySync,
|
||||
@@ -38,53 +41,57 @@ const {
|
||||
<div>
|
||||
<h3 class="font-semibold text-primary">{{ t('admin.wecom.sync.title') }}</h3>
|
||||
<p class="mt-1 text-sm text-muted">{{ t('admin.wecom.sync.desc') }}</p>
|
||||
<p class="mt-2 text-xs text-amber-800 bg-amber-50 border border-amber-100 rounded-lg px-3 py-2">
|
||||
{{ t('admin.wecom.sync.permissionNote') }}
|
||||
<p class="mt-2 text-xs text-sky-900 bg-sky-50 border border-sky-100 rounded-lg px-3 py-2">
|
||||
{{ t('admin.wecom.sync.oaSourceNote') }}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-3">
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-3 text-sm">
|
||||
<div>
|
||||
<label class="mb-1.5 block text-xs text-muted">{{ t('admin.wecom.sync.employeeIdSource') }}</label>
|
||||
<input
|
||||
:value="wecomSystemSettings.employee_id_source"
|
||||
readonly
|
||||
class="input-field bg-surface-soft"
|
||||
/>
|
||||
<div class="text-xs text-muted">{{ t('admin.wecom.sync.oaWorkcodeField') }}</div>
|
||||
<div class="mt-1 font-mono text-primary">userInfo_view.workcode</div>
|
||||
</div>
|
||||
<div>
|
||||
<label class="mb-1.5 block text-xs text-muted">{{ t('admin.wecom.sync.departmentId') }}</label>
|
||||
<input
|
||||
v-model="departmentId"
|
||||
:placeholder="t('admin.wecom.sync.departmentIdPlaceholder')"
|
||||
class="input-field"
|
||||
/>
|
||||
<div class="text-xs text-muted">{{ t('admin.wecom.sync.oaWecomIdField') }}</div>
|
||||
<div class="mt-1 font-mono text-primary">userInfo_view.id</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-wrap gap-2">
|
||||
<button type="button" class="btn-secondary inline-flex items-center gap-2" :disabled="isSyncing" @click="previewSync">
|
||||
<RefreshCw class="w-4 h-4" :class="{ 'animate-spin': isSyncing }" />
|
||||
{{ t('admin.wecom.sync.preview') }}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="btn-primary"
|
||||
:disabled="isSyncing || !previewSummary || (previewSummary.conflicts?.length || 0) > 0 || (previewSummary.would_update || 0) <= 0"
|
||||
@click="requestApplySync"
|
||||
>
|
||||
{{ t('admin.wecom.sync.apply') }}
|
||||
</button>
|
||||
<div class="space-y-2">
|
||||
<div class="flex flex-wrap gap-2">
|
||||
<button
|
||||
type="button"
|
||||
class="inline-flex items-center gap-2"
|
||||
:class="isSyncing ? 'btn-secondary opacity-60' : 'btn-primary'"
|
||||
:disabled="isSyncing"
|
||||
@click="previewSync"
|
||||
>
|
||||
<RefreshCw class="w-4 h-4" :class="{ 'animate-spin': isSyncing }" />
|
||||
{{ t('admin.wecom.sync.preview') }}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
:class="canApplySync && !isSyncing ? 'btn-primary' : 'btn-secondary opacity-60'"
|
||||
:disabled="isSyncing"
|
||||
:title="applyBlockHint || undefined"
|
||||
@click="requestApplySync"
|
||||
>
|
||||
{{ t('admin.wecom.sync.apply') }}
|
||||
</button>
|
||||
</div>
|
||||
<p v-if="applyBlockHint && !isSyncing" class="text-xs text-muted">
|
||||
{{ applyBlockHint }}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div v-if="previewSummary" class="rounded-xl border border-subtle bg-surface-soft p-4 space-y-3 text-sm">
|
||||
<div class="grid grid-cols-2 md:grid-cols-4 gap-3">
|
||||
<div>
|
||||
<div class="text-xs text-muted">{{ t('admin.wecom.sync.stats.wecomUsers') }}</div>
|
||||
<div class="font-semibold text-primary">{{ previewSummary.wecom_users }}</div>
|
||||
<div class="text-xs text-muted">{{ t('admin.wecom.sync.stats.localCandidates') }}</div>
|
||||
<div class="font-semibold text-primary">{{ previewSummary.local_candidates }}</div>
|
||||
</div>
|
||||
<div>
|
||||
<div class="text-xs text-muted">{{ t('admin.wecom.sync.stats.localMatched') }}</div>
|
||||
<div class="text-xs text-muted">{{ t('admin.wecom.sync.stats.oaMatched') }}</div>
|
||||
<div class="font-semibold text-primary">{{ previewSummary.local_matched }}</div>
|
||||
</div>
|
||||
<div>
|
||||
@@ -99,6 +106,10 @@ const {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="previewSummary.local_missing > 0" class="text-xs text-muted">
|
||||
{{ t('admin.wecom.sync.localMissingHint', { count: previewSummary.local_missing }) }}
|
||||
</div>
|
||||
|
||||
<div v-if="previewSummary.pending_updates?.length" class="overflow-x-auto">
|
||||
<table class="admin-table min-w-full">
|
||||
<thead>
|
||||
@@ -111,7 +122,10 @@ const {
|
||||
<tbody>
|
||||
<tr v-for="row in previewSummary.pending_updates" :key="`${row.employee_id}-${row.wecom_userid}`">
|
||||
<td class="px-3 py-2 text-xs">{{ row.employee_id }}</td>
|
||||
<td class="px-3 py-2 text-xs">{{ row.username }}</td>
|
||||
<td class="px-3 py-2 text-xs">
|
||||
{{ row.username }}
|
||||
<span v-if="row.name" class="text-muted"> · {{ row.name }}</span>
|
||||
</td>
|
||||
<td class="px-3 py-2 text-xs font-mono">{{ row.wecom_userid }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
@@ -137,7 +151,10 @@ const {
|
||||
|
||||
<DeleteConfirmDialog
|
||||
v-model="showApplyConfirm"
|
||||
:title="t('admin.wecom.sync.applyConfirmTitle')"
|
||||
:message="t('admin.wecom.sync.applyConfirm', { count: previewSummary?.would_update || 0 })"
|
||||
:confirm-text="t('admin.wecom.sync.applyConfirmButton')"
|
||||
confirm-tone="primary"
|
||||
@confirm="confirmApplySync"
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -1,50 +1,76 @@
|
||||
/**
|
||||
* features/admin/modules/wecom/composables/useWecomSync.ts
|
||||
* 企微通讯录 userid 同步:预览 dry-run 与确认写入。
|
||||
* OA userInfo_view → 本地 wecom_userid 同步:预览 dry-run 与确认写入。
|
||||
*/
|
||||
import { ref } from 'vue';
|
||||
import { computed, ref } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { syncAdminWecomUserids } from '@/features/admin/api/admin.api';
|
||||
import { useMessage } from '@/shared/composables/useMessage';
|
||||
import type { WecomSyncSummary } from '@/features/admin/types/wecom.types';
|
||||
|
||||
/** 确认写入被拦截的原因(用于按钮样式与提示文案) */
|
||||
export type WecomSyncApplyBlockReason = 'preview_first' | 'preview_failed' | 'conflicts' | 'nothing';
|
||||
|
||||
export function useWecomSync(options?: { onApplied?: () => void | Promise<void> }) {
|
||||
const { t } = useI18n();
|
||||
const msg = useMessage();
|
||||
|
||||
const departmentId = ref('');
|
||||
const isSyncing = ref(false);
|
||||
const previewSummary = ref<WecomSyncSummary | null>(null);
|
||||
const showApplyConfirm = ref(false);
|
||||
const previewAttempted = ref(false);
|
||||
const previewFailed = ref(false);
|
||||
|
||||
/**
|
||||
* 解析可选部门 ID;空字符串表示同步全部部门。
|
||||
* @returns number | null 合法值;false 表示格式非法
|
||||
* 判断当前是否允许打开确认写入弹窗。
|
||||
*/
|
||||
const parseDepartmentId = (): number | null | false => {
|
||||
const raw = departmentId.value.trim();
|
||||
if (!raw) return null;
|
||||
const parsed = Number(raw);
|
||||
if (!Number.isInteger(parsed) || parsed <= 0) {
|
||||
return false;
|
||||
}
|
||||
return parsed;
|
||||
};
|
||||
const canApplySync = computed(() => {
|
||||
if (!previewSummary.value) return false;
|
||||
if ((previewSummary.value.conflicts || []).length > 0) return false;
|
||||
return (previewSummary.value.would_update || 0) > 0;
|
||||
});
|
||||
|
||||
/**
|
||||
* 预览同步结果(dry-run,不写库)。
|
||||
* 确认写入不可用时的原因,用于按钮旁提示。
|
||||
*/
|
||||
const applyBlockReason = computed((): WecomSyncApplyBlockReason | null => {
|
||||
if (canApplySync.value) return null;
|
||||
if (previewFailed.value || (previewAttempted.value && !previewSummary.value)) {
|
||||
return 'preview_failed';
|
||||
}
|
||||
if (!previewSummary.value) return 'preview_first';
|
||||
if ((previewSummary.value.conflicts || []).length > 0) return 'conflicts';
|
||||
return 'nothing';
|
||||
});
|
||||
|
||||
/**
|
||||
* 与 applyBlockReason 对应的界面提示文案。
|
||||
*/
|
||||
const applyBlockHint = computed(() => {
|
||||
const reason = applyBlockReason.value;
|
||||
if (!reason) return '';
|
||||
const keyMap: Record<WecomSyncApplyBlockReason, string> = {
|
||||
preview_first: 'admin.wecom.sync.applyHintPreviewFirst',
|
||||
preview_failed: 'admin.wecom.sync.applyHintPreviewFailed',
|
||||
conflicts: 'admin.wecom.sync.applyHintConflicts',
|
||||
nothing: 'admin.wecom.sync.applyHintNothing',
|
||||
};
|
||||
return t(keyMap[reason]);
|
||||
});
|
||||
|
||||
/**
|
||||
* 预览 OA 同步结果(dry-run,不写库)。
|
||||
*/
|
||||
const previewSync = async (): Promise<void> => {
|
||||
const deptId = parseDepartmentId();
|
||||
if (deptId === false) {
|
||||
msg.warning(t('admin.wecom.sync.invalidDepartmentId'));
|
||||
return;
|
||||
}
|
||||
isSyncing.value = true;
|
||||
previewAttempted.value = true;
|
||||
previewFailed.value = false;
|
||||
try {
|
||||
previewSummary.value = await syncAdminWecomUserids({ apply: false, department_id: deptId });
|
||||
previewSummary.value = await syncAdminWecomUserids({ apply: false });
|
||||
msg.success(t('admin.wecom.sync.previewDone'));
|
||||
} catch (e) {
|
||||
previewSummary.value = null;
|
||||
previewFailed.value = true;
|
||||
console.error(e);
|
||||
msg.error((e as Error).message || t('admin.wecom.sync.previewFailed'));
|
||||
} finally {
|
||||
@@ -53,9 +79,14 @@ export function useWecomSync(options?: { onApplied?: () => void | Promise<void>
|
||||
};
|
||||
|
||||
/**
|
||||
* 打开确认写入对话框;需先预览且无冲突。
|
||||
* 打开确认写入对话框;不可写入时弹出对应提示。
|
||||
*/
|
||||
const requestApplySync = (): void => {
|
||||
if (isSyncing.value) return;
|
||||
if (previewFailed.value || (previewAttempted.value && !previewSummary.value)) {
|
||||
msg.warning(t('admin.wecom.sync.previewFirstAfterFail'));
|
||||
return;
|
||||
}
|
||||
if (!previewSummary.value) {
|
||||
msg.warning(t('admin.wecom.sync.previewFirst'));
|
||||
return;
|
||||
@@ -75,14 +106,9 @@ export function useWecomSync(options?: { onApplied?: () => void | Promise<void>
|
||||
* 确认后将预览结果写入数据库。
|
||||
*/
|
||||
const confirmApplySync = async (): Promise<void> => {
|
||||
const deptId = parseDepartmentId();
|
||||
if (deptId === false) {
|
||||
msg.warning(t('admin.wecom.sync.invalidDepartmentId'));
|
||||
return;
|
||||
}
|
||||
isSyncing.value = true;
|
||||
try {
|
||||
const summary = await syncAdminWecomUserids({ apply: true, department_id: deptId });
|
||||
const summary = await syncAdminWecomUserids({ apply: true });
|
||||
previewSummary.value = summary;
|
||||
showApplyConfirm.value = false;
|
||||
msg.success(t('admin.wecom.sync.applyDone', { count: summary.updated || 0 }));
|
||||
@@ -96,10 +122,11 @@ export function useWecomSync(options?: { onApplied?: () => void | Promise<void>
|
||||
};
|
||||
|
||||
return {
|
||||
departmentId,
|
||||
isSyncing,
|
||||
previewSummary,
|
||||
showApplyConfirm,
|
||||
canApplySync,
|
||||
applyBlockHint,
|
||||
previewSync,
|
||||
requestApplySync,
|
||||
confirmApplySync,
|
||||
|
||||
@@ -1,31 +1,18 @@
|
||||
<script setup lang="ts">
|
||||
|
||||
/**
|
||||
|
||||
* features/admin/modules/wecom/pages/WecomBindingsPage.vue
|
||||
|
||||
* 企微快速绑定与绑定列表(搜索 + 服务端分页)。
|
||||
|
||||
* 依赖:WECOM_ADMIN_KEY、PaginationBar、lucide-vue-next。
|
||||
|
||||
* 逻辑:inject 父级 useWecomAdmin 状态;列表区复用 PaginationBar。
|
||||
|
||||
* 企微 OA 同步、快速绑定与绑定列表(搜索 + 服务端分页)。
|
||||
* 依赖:WECOM_ADMIN_KEY、WecomSyncPanel、PaginationBar。
|
||||
*/
|
||||
|
||||
import { inject } from 'vue';
|
||||
|
||||
import { useI18n } from 'vue-i18n';
|
||||
|
||||
import { Link2, Search, Unlink2 } from 'lucide-vue-next';
|
||||
|
||||
import PaginationBar from '@/shared/components/PaginationBar.vue';
|
||||
|
||||
import WecomOverviewCards from '../components/WecomOverviewCards.vue';
|
||||
import WecomSyncPanel from '../components/WecomSyncPanel.vue';
|
||||
import { WECOM_ADMIN_KEY } from '../wecom.context';
|
||||
|
||||
|
||||
|
||||
const { t } = useI18n();
|
||||
|
||||
const {
|
||||
|
||||
wecomBindUserQuery,
|
||||
@@ -62,15 +49,19 @@ const {
|
||||
|
||||
unbindWecomUserByAdmin,
|
||||
|
||||
refreshWecomData,
|
||||
|
||||
} = inject(WECOM_ADMIN_KEY)!;
|
||||
|
||||
const onSyncApplied = async (): Promise<void> => {
|
||||
await refreshWecomData();
|
||||
};
|
||||
</script>
|
||||
|
||||
|
||||
|
||||
<template>
|
||||
|
||||
<div class="space-y-6">
|
||||
<WecomOverviewCards />
|
||||
<WecomSyncPanel @applied="onSyncApplied" />
|
||||
|
||||
<p class="text-sm text-muted">{{ t('admin.wecom.bindingsHint') }}</p>
|
||||
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* features/admin/modules/wecom/pages/WecomSettingsPage.vue
|
||||
* 企微系统配置、通讯录同步、通知与集成复制。
|
||||
* 企微系统配置、通知与集成复制。
|
||||
*/
|
||||
import { inject, ref } from 'vue';
|
||||
import { inject } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { CircleHelp } from 'lucide-vue-next';
|
||||
import WecomOverviewCards from '../components/WecomOverviewCards.vue';
|
||||
import WecomSyncPanel from '../components/WecomSyncPanel.vue';
|
||||
import { WECOM_ADMIN_KEY } from '../wecom.context';
|
||||
|
||||
const { t } = useI18n();
|
||||
@@ -25,17 +24,11 @@ const {
|
||||
saveWecomNotifySettings,
|
||||
copyText,
|
||||
} = inject(WECOM_ADMIN_KEY)!;
|
||||
const overviewRefreshKey = ref(0);
|
||||
|
||||
const onSyncApplied = (): void => {
|
||||
overviewRefreshKey.value += 1;
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="space-y-6">
|
||||
<WecomOverviewCards :refresh-key="overviewRefreshKey" />
|
||||
<WecomSyncPanel @applied="onSyncApplied" />
|
||||
<WecomOverviewCards />
|
||||
|
||||
<div class="card shadow-sm p-5 space-y-4">
|
||||
<h3 class="font-semibold text-primary">{{ t('admin.wecom.systemSettings') }}</h3>
|
||||
|
||||
Reference in new issue
Block a user