Compare commits
1
Commits
test
...
sophie-wecom
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f7890be317 |
No files matched your search
+5
-5
@@ -47,10 +47,10 @@ AUTH_LOCAL_JWT_AUDIENCE=hxops-frontend
|
||||
AUTH_LOCAL_JWT_EXPIRES_HOURS=12
|
||||
|
||||
# WeCom
|
||||
WECOM_ENABLED=false
|
||||
WECOM_CORP_ID=
|
||||
WECOM_AGENT_ID=
|
||||
WECOM_SECRET=
|
||||
WECOM_ENABLED=true
|
||||
WECOM_CORP_ID=ww1ada6c11b684783e
|
||||
WECOM_AGENT_ID=1000065
|
||||
WECOM_SECRET=N9a1EE6pDj_6wTpRrXmg9Vn4BdK54jb7yFmSQ0-FSwU
|
||||
WECOM_REDIRECT_URI=
|
||||
WECOM_AUTO_CREATE_USER=true
|
||||
WECOM_MATCH_RULES=employee_id,mobile
|
||||
@@ -68,7 +68,7 @@ WECOM_TRUSTED_DOMAIN=
|
||||
WECOM_PUBLIC_BASE_URL=
|
||||
WECOM_NOTIFY_ENABLED=true
|
||||
WECOM_NOTIFY_BASE_URL=
|
||||
WECOM_NOTIFY_EVENTS=permission_request_approved,permission_request_rejected,permission_batch_updated,task_completed,schedule_completed
|
||||
WECOM_NOTIFY_EVENTS=permission_request_approved,permission_request_rejected,permission_batch_updated,task_completed,schedule_completed,password_reset
|
||||
|
||||
|
||||
# Common integration defaults
|
||||
|
||||
+3
-1
@@ -46,7 +46,9 @@ frontend/public/WW_verify_46MjWA55y3PBRLid.txt
|
||||
frontend/package-lock.json
|
||||
|
||||
# IDEs
|
||||
.vscode/
|
||||
.vscode/*
|
||||
!.vscode/settings.json
|
||||
!.vscode/extensions.json
|
||||
.idea/
|
||||
*.swp
|
||||
*.swo
|
||||
|
||||
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"recommendations": ["ms-python.python", "ms-python.vscode-pylance"]
|
||||
}
|
||||
Vendored
+20
@@ -0,0 +1,20 @@
|
||||
{
|
||||
// 后端 Python 虚拟环境:新终端自动激活,无需手动 .venv\Scripts\activate
|
||||
"python.defaultInterpreterPath": "${workspaceFolder}/backend/.venv/Scripts/python.exe",
|
||||
"python.terminal.activateEnvironment": true,
|
||||
"python.venvPath": "${workspaceFolder}/backend",
|
||||
"python.venvFolders": [".venv"],
|
||||
|
||||
// 可选:在终端下拉中选择「HXOPS Backend」时,直接进入 backend 并激活 venv
|
||||
"terminal.integrated.profiles.windows": {
|
||||
"HXOPS Backend": {
|
||||
"source": "PowerShell",
|
||||
"icon": "server-environment",
|
||||
"args": [
|
||||
"-NoExit",
|
||||
"-Command",
|
||||
"Set-Location '${workspaceFolder}/backend'; if (Test-Path '.venv/Scripts/Activate.ps1') { . '.venv/Scripts/Activate.ps1' }"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
+128
-4
@@ -11,7 +11,7 @@ from app.decorators import require_admin
|
||||
from app.config import Config
|
||||
from app import db
|
||||
from app.env_persistence import persist_env_settings
|
||||
from sqlalchemy import func, desc, inspect
|
||||
from sqlalchemy import func, desc, inspect, or_
|
||||
from sqlalchemy.exc import IntegrityError
|
||||
from datetime import datetime, timedelta
|
||||
import csv
|
||||
@@ -20,6 +20,7 @@ import re
|
||||
import requests
|
||||
import uuid
|
||||
from app.services.wecom_notify import send_wecom_event_message
|
||||
from app.services.wecom_directory_sync import sync_wecom_userids_from_directory
|
||||
from app.services.dify import DifyService
|
||||
from app.auth_jwt import get_current_user as _get_auth_user
|
||||
from app.errors import AppError, ValidationError, UnauthorizedError, ForbiddenError, NotFoundError, ConflictError, ServiceUnavailableError, raise_for_status
|
||||
@@ -839,14 +840,63 @@ def get_table_count(table):
|
||||
@require_admin
|
||||
def list_wecom_bindings():
|
||||
"""
|
||||
List users with optional filter for WeCom bindings.
|
||||
分页列出用户企微绑定,支持 keyword 模糊搜索与 bound_only 筛选。
|
||||
|
||||
Query: bound_only, keyword, page, page_size
|
||||
Returns: { items, total, page, page_size, pages }
|
||||
"""
|
||||
bound_only = request.args.get('bound_only', 'false').lower() == 'true'
|
||||
keyword = (request.args.get('keyword') or '').strip()
|
||||
page = request.args.get('page', type=int) or 1
|
||||
page_size = request.args.get('page_size', type=int) or 20
|
||||
page = max(1, page)
|
||||
page_size = max(1, min(100, page_size))
|
||||
|
||||
query = db.session.query(User)
|
||||
if bound_only:
|
||||
query = query.filter(User.wecom_userid.isnot(None))
|
||||
users = query.order_by(User.id.asc()).all()
|
||||
return jsonify([{'id': u.id, 'username': u.username, 'real_name': u.real_name, 'email': u.email, 'role': u.role, 'status': u.status, 'wecom_userid': u.wecom_userid, 'wecom_unionid': u.wecom_unionid, 'bound': bool(u.wecom_userid)} for u in users])
|
||||
if keyword:
|
||||
pattern = f'%{keyword}%'
|
||||
query = query.filter(or_(
|
||||
User.username.ilike(pattern),
|
||||
User.real_name.ilike(pattern),
|
||||
User.employee_id.ilike(pattern),
|
||||
User.wecom_userid.ilike(pattern),
|
||||
))
|
||||
|
||||
total = query.count()
|
||||
pages = max(1, (total + page_size - 1) // page_size) if total else 1
|
||||
if page > pages:
|
||||
page = pages
|
||||
|
||||
users = (
|
||||
query.order_by(User.id.asc())
|
||||
.offset((page - 1) * page_size)
|
||||
.limit(page_size)
|
||||
.all()
|
||||
)
|
||||
items = [
|
||||
{
|
||||
'id': u.id,
|
||||
'username': u.username,
|
||||
'real_name': u.real_name,
|
||||
'employee_id': u.employee_id,
|
||||
'email': u.email,
|
||||
'role': u.role,
|
||||
'status': u.status,
|
||||
'wecom_userid': u.wecom_userid,
|
||||
'wecom_unionid': u.wecom_unionid,
|
||||
'bound': bool(u.wecom_userid),
|
||||
}
|
||||
for u in users
|
||||
]
|
||||
return jsonify({
|
||||
'items': items,
|
||||
'total': int(total),
|
||||
'page': page,
|
||||
'page_size': page_size,
|
||||
'pages': pages,
|
||||
})
|
||||
|
||||
@admin_bp.route('/guides/upload', methods=['POST'])
|
||||
@require_admin
|
||||
@@ -1177,3 +1227,77 @@ def wecom_notify_metrics():
|
||||
by_event[event_type] = {'sent': 0, 'failed': 0}
|
||||
by_event[event_type][status] = int(cnt)
|
||||
return jsonify({'window_days': 30, 'total': int(total), 'sent': int(sent), 'failed': int(total - sent), 'send_success_rate': round(sent / total * 100, 2) if total else 0, 'opened_24h': int(opened_24h), 'opened_24h_rate': round(opened_24h / sent * 100, 2) if sent else 0, 'by_event': by_event})
|
||||
|
||||
|
||||
@admin_bp.route('/wecom/binding-stats', methods=['GET'])
|
||||
@require_admin
|
||||
def wecom_binding_stats():
|
||||
"""
|
||||
返回活跃用户的企微 userid 绑定统计,供管理端概览卡片使用。
|
||||
"""
|
||||
total_active = db.session.query(func.count(User.id)).filter(User.status == 'active').scalar() or 0
|
||||
bound = (
|
||||
db.session.query(func.count(User.id))
|
||||
.filter(User.status == 'active', User.wecom_userid.isnot(None), User.wecom_userid != '')
|
||||
.scalar()
|
||||
or 0
|
||||
)
|
||||
total_active = int(total_active)
|
||||
bound = int(bound)
|
||||
return jsonify(
|
||||
{
|
||||
'total_active': total_active,
|
||||
'bound': bound,
|
||||
'unbound': max(total_active - bound, 0),
|
||||
'bound_rate': round(bound / total_active * 100, 2) if total_active else 0,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@admin_bp.route('/wecom/sync-userids', methods=['POST'])
|
||||
@require_admin
|
||||
def sync_wecom_userids_admin():
|
||||
"""
|
||||
从企微通讯录按工号同步 users.wecom_userid。
|
||||
Request JSON: { "apply": false, "department_id": 1 }
|
||||
"""
|
||||
data = request.get_json() or {}
|
||||
apply = bool(data.get('apply'))
|
||||
department_id = data.get('department_id')
|
||||
if department_id is not None and department_id != '':
|
||||
try:
|
||||
department_id = int(department_id)
|
||||
except (TypeError, ValueError):
|
||||
raise ValidationError('department_id must be an integer')
|
||||
else:
|
||||
department_id = None
|
||||
try:
|
||||
summary = sync_wecom_userids_from_directory(apply=apply, department_id=department_id)
|
||||
current_app.logger.info(
|
||||
'[wecom_sync] admin apply=%s updated=%s would_update=%s conflicts=%s',
|
||||
apply,
|
||||
summary.get('updated'),
|
||||
summary.get('would_update'),
|
||||
len(summary.get('conflicts') or []),
|
||||
)
|
||||
return jsonify(summary)
|
||||
except RuntimeError as exc:
|
||||
message = str(exc)
|
||||
if 'not configured' in message.lower():
|
||||
raise AppError(
|
||||
code='SYSTEM.HTTP_ERROR',
|
||||
message=message,
|
||||
http_status=503,
|
||||
details={'error_code': 'WECOM_NOT_CONFIGURED'},
|
||||
)
|
||||
if 'conflicts detected' in message.lower():
|
||||
raise ConflictError(message, details={'error_code': 'WECOM_SYNC_CONFLICTS'})
|
||||
if 'department/list failed' in message.lower() or 'user/list failed' in message.lower():
|
||||
raise AppError(
|
||||
code='SYSTEM.HTTP_ERROR',
|
||||
message='WeCom directory API failed. Check app contact read permissions.',
|
||||
http_status=502,
|
||||
details={'error_code': 'WECOM_DIRECTORY_API_FAILED', 'technical': message[:300]},
|
||||
)
|
||||
raise AppError(code='SYSTEM.INTERNAL_ERROR', message=message, http_status=500)
|
||||
|
||||
+225
-2
@@ -22,6 +22,8 @@ user_bp = Blueprint('user', __name__)
|
||||
_WECOM_ACCESS_TOKEN_CACHE = {'token': None, 'expires_at': None}
|
||||
_WECOM_STATE_CACHE = {}
|
||||
_WECOM_BIND_SESSION_CACHE = {}
|
||||
_PASSWORD_RESET_RATE_CACHE = {}
|
||||
_PASSWORD_RESET_GENERIC_MESSAGE = 'If the account exists and WeCom is bound, a reset link has been sent to your WeCom.'
|
||||
_ALLOWED_WECOM_MATCH_FIELDS = {'employee_id', 'mobile', 'email'}
|
||||
_LOGIN_AUDIT_COLUMNS_CACHE = None
|
||||
_CASDOOR_OIDC_CACHE = {'value': None, 'expires_at': None}
|
||||
@@ -108,8 +110,27 @@ def _run_db_with_retry(operation, *, label: str):
|
||||
current_app.logger.warning('%s dispose engine failed: %s', label, dispose_exc)
|
||||
return operation()
|
||||
|
||||
def _is_wecom_configured():
|
||||
return all([current_app.config.get('WECOM_ENABLED'), current_app.config.get('WECOM_CORP_ID'), current_app.config.get('WECOM_AGENT_ID'), current_app.config.get('WECOM_SECRET')])
|
||||
def _get_wecom_config_missing_fields() -> list[str]:
|
||||
"""
|
||||
列出企微集成尚未配置的环境项。
|
||||
Returns:
|
||||
缺失的配置键名列表,如 WECOM_ENABLED、WECOM_CORP_ID 等。
|
||||
"""
|
||||
missing: list[str] = []
|
||||
if not current_app.config.get('WECOM_ENABLED'):
|
||||
missing.append('WECOM_ENABLED')
|
||||
if not _clean_str(current_app.config.get('WECOM_CORP_ID')):
|
||||
missing.append('WECOM_CORP_ID')
|
||||
if not _clean_str(current_app.config.get('WECOM_AGENT_ID')):
|
||||
missing.append('WECOM_AGENT_ID')
|
||||
if not _clean_str(current_app.config.get('WECOM_SECRET')):
|
||||
missing.append('WECOM_SECRET')
|
||||
return missing
|
||||
|
||||
|
||||
def _is_wecom_configured() -> bool:
|
||||
"""企微 Corp/Agent/Secret 与总开关均已配置时返回 True。"""
|
||||
return len(_get_wecom_config_missing_fields()) == 0
|
||||
|
||||
def _issue_casdoor_state(redirect_uri: str):
|
||||
exp_ts = int((datetime.utcnow() + timedelta(minutes=10)).timestamp())
|
||||
@@ -1560,6 +1581,204 @@ def change_password():
|
||||
db.session.rollback()
|
||||
raise AppError(code='SYSTEM.INTERNAL_ERROR', message=str(e), http_status=500)
|
||||
|
||||
def _get_password_reset_public_base_url() -> str:
|
||||
"""
|
||||
解析密码重置外链基地址,优先公网入口配置。
|
||||
核心逻辑:依次读取 WECOM_PUBLIC_BASE_URL / PUBLIC_BASE_URL / WECOM_NOTIFY_BASE_URL。
|
||||
Returns:
|
||||
去掉尾斜杠的基地址;均未配置时返回空字符串。
|
||||
"""
|
||||
for key in ('WECOM_PUBLIC_BASE_URL', 'PUBLIC_BASE_URL', 'WECOM_NOTIFY_BASE_URL'):
|
||||
base = _clean_str(current_app.config.get(key))
|
||||
if base:
|
||||
return base.rstrip('/')
|
||||
return ''
|
||||
|
||||
|
||||
def _build_password_reset_url(token: str) -> str:
|
||||
"""
|
||||
构造带 token 的密码重置页 URL。
|
||||
@param token: reset_token 明文
|
||||
Returns:
|
||||
完整重置链接
|
||||
Raises:
|
||||
RuntimeError: 公网基地址未配置
|
||||
"""
|
||||
base = _get_password_reset_public_base_url()
|
||||
if not base:
|
||||
raise RuntimeError('Password reset public base URL is not configured')
|
||||
return f'{base}/reset-password?token={token}'
|
||||
|
||||
|
||||
def _check_password_reset_rate_limit(key: str, *, window_seconds: int = 300) -> bool:
|
||||
"""
|
||||
简易内存限流,防止同工号/IP 频繁触发找回密码。
|
||||
@param key: 限流键,通常为 employee_id + IP
|
||||
@param window_seconds: 窗口秒数,默认 5 分钟
|
||||
Returns:
|
||||
True 表示允许继续;False 表示应静默拒绝
|
||||
"""
|
||||
now = datetime.utcnow()
|
||||
last = _PASSWORD_RESET_RATE_CACHE.get(key)
|
||||
if last and (now - last).total_seconds() < window_seconds:
|
||||
return False
|
||||
_PASSWORD_RESET_RATE_CACHE[key] = now
|
||||
return True
|
||||
|
||||
|
||||
def _sync_casdoor_password_for_reset(user: User, new_password: str):
|
||||
"""
|
||||
Token 重置场景下将新密码同步至 Casdoor(无旧密码校验)。
|
||||
核心逻辑:Casdoor 已配置时调用 set-password,oldPassword 传空串(与 change-password fallback 一致)。
|
||||
@param user: 本地用户
|
||||
@param new_password: 新密码明文
|
||||
Raises:
|
||||
AppError: Casdoor 策略或 IdP 同步失败
|
||||
"""
|
||||
if not _is_casdoor_configured():
|
||||
return
|
||||
user_owner = _casdoor_user_owner()
|
||||
try:
|
||||
_casdoor_set_password(user_owner, user.username, '', new_password)
|
||||
except RuntimeError as exc:
|
||||
if _is_casdoor_user_missing_error(str(exc)):
|
||||
_raise_casdoor_user_not_in_idp(exc)
|
||||
_raise_casdoor_set_password_error(exc)
|
||||
|
||||
|
||||
def _password_reset_rate_key(employee_id: str) -> str:
|
||||
"""
|
||||
生成找回密码限流键。
|
||||
@param employee_id: 工号
|
||||
Returns:
|
||||
employee_id 与客户端 IP 组合键
|
||||
"""
|
||||
client_ip = request.headers.get('X-Forwarded-For', request.remote_addr) or 'unknown'
|
||||
return f'{employee_id}:{client_ip}'
|
||||
|
||||
|
||||
@user_bp.route('/reset-password-by-wecom', methods=['POST'])
|
||||
def reset_password_by_wecom():
|
||||
"""
|
||||
通过工号 + 用户名发起找回密码,并向已绑定 wecom_userid 发送 textcard 重置链接。
|
||||
Request JSON: { "employee_id": "...", "username": "..." }
|
||||
"""
|
||||
if not _is_wecom_configured():
|
||||
raise AppError(
|
||||
code='WECOM.RESET_NOT_CONFIGURED',
|
||||
message='WeCom password reset is not configured',
|
||||
http_status=503,
|
||||
details={
|
||||
'error_code': 'WECOM_RESET_NOT_CONFIGURED',
|
||||
'missing': _get_wecom_config_missing_fields(),
|
||||
},
|
||||
)
|
||||
if not bool(current_app.config.get('WECOM_NOTIFY_ENABLED', True)):
|
||||
raise AppError(
|
||||
code='WECOM.NOTIFY_DISABLED',
|
||||
message='WeCom notification is disabled',
|
||||
http_status=503,
|
||||
details={'error_code': 'WECOM_NOTIFY_DISABLED'},
|
||||
)
|
||||
if not _get_password_reset_public_base_url():
|
||||
raise AppError(
|
||||
code='WECOM.RESET_URL_NOT_CONFIGURED',
|
||||
message='Password reset public base URL is not configured',
|
||||
http_status=503,
|
||||
details={'error_code': 'PASSWORD_RESET_URL_NOT_CONFIGURED'},
|
||||
)
|
||||
|
||||
data = request.get_json() or {}
|
||||
employee_id = _clean_str(data.get('employee_id'))
|
||||
username = _clean_str(data.get('username'))
|
||||
if not employee_id:
|
||||
raise ValidationError('Employee ID is required')
|
||||
if not username:
|
||||
raise ValidationError('Username is required')
|
||||
|
||||
rate_key = _password_reset_rate_key(employee_id)
|
||||
if not _check_password_reset_rate_limit(rate_key):
|
||||
current_app.logger.info(
|
||||
'[password_reset] noop reason=rate_limited employee_id=%s',
|
||||
employee_id,
|
||||
)
|
||||
return jsonify({'message': _PASSWORD_RESET_GENERIC_MESSAGE})
|
||||
|
||||
user = db.session.query(User).filter(User.employee_id == employee_id).first()
|
||||
if not user:
|
||||
current_app.logger.info(
|
||||
'[password_reset] noop reason=user_not_found employee_id=%s',
|
||||
employee_id,
|
||||
)
|
||||
return jsonify({'message': _PASSWORD_RESET_GENERIC_MESSAGE})
|
||||
if user.username != username:
|
||||
current_app.logger.info(
|
||||
'[password_reset] noop reason=username_mismatch employee_id=%s user_id=%s',
|
||||
employee_id,
|
||||
user.id,
|
||||
)
|
||||
return jsonify({'message': _PASSWORD_RESET_GENERIC_MESSAGE})
|
||||
if user.status != 'active':
|
||||
current_app.logger.info(
|
||||
'[password_reset] noop reason=account_inactive employee_id=%s user_id=%s',
|
||||
employee_id,
|
||||
user.id,
|
||||
)
|
||||
return jsonify({'message': _PASSWORD_RESET_GENERIC_MESSAGE})
|
||||
if not user.wecom_userid:
|
||||
current_app.logger.info(
|
||||
'[password_reset] noop reason=wecom_unbound employee_id=%s user_id=%s',
|
||||
employee_id,
|
||||
user.id,
|
||||
)
|
||||
return jsonify({'message': _PASSWORD_RESET_GENERIC_MESSAGE})
|
||||
|
||||
token = str(uuid.uuid4())
|
||||
user.reset_token = token
|
||||
user.reset_token_expiry = datetime.utcnow() + timedelta(hours=1)
|
||||
db.session.flush()
|
||||
|
||||
title = 'HXOPS 密码重置'
|
||||
content = (
|
||||
'您发起了 HXOPS 密码重置请求。\n'
|
||||
'请在 1 小时内点击下方按钮设置新密码。\n'
|
||||
'如非本人操作,请忽略本消息。'
|
||||
)
|
||||
try:
|
||||
result = send_wecom_event_message(
|
||||
event_type='password_reset',
|
||||
user=user,
|
||||
title=title,
|
||||
content=content,
|
||||
jump_path='/reset-password',
|
||||
jump_params={'token': token},
|
||||
)
|
||||
if not result.get('ok'):
|
||||
db.session.rollback()
|
||||
current_app.logger.warning(
|
||||
'[password_reset] wecom send failed user_id=%s employee_id=%s reason=%s trace_id=%s raw=%s',
|
||||
user.id,
|
||||
employee_id,
|
||||
result.get('reason'),
|
||||
result.get('trace_id'),
|
||||
result.get('raw'),
|
||||
)
|
||||
return jsonify({'message': _PASSWORD_RESET_GENERIC_MESSAGE})
|
||||
|
||||
db.session.commit()
|
||||
current_app.logger.info(
|
||||
'[password_reset] reset link sent user_id=%s employee_id=%s trace_id=%s',
|
||||
user.id,
|
||||
employee_id,
|
||||
result.get('trace_id'),
|
||||
)
|
||||
return jsonify({'message': _PASSWORD_RESET_GENERIC_MESSAGE})
|
||||
except Exception as exc:
|
||||
db.session.rollback()
|
||||
current_app.logger.exception('[password_reset] unexpected failure user_id=%s: %s', user.id, exc)
|
||||
raise AppError(code='SYSTEM.INTERNAL_ERROR', message='Failed to request password reset', http_status=500)
|
||||
|
||||
|
||||
@user_bp.route('/reset-password-by-email', methods=['POST'])
|
||||
def reset_password_request():
|
||||
"""
|
||||
@@ -1598,11 +1817,15 @@ def reset_password_confirm():
|
||||
if not user or not user.reset_token_expiry or user.reset_token_expiry < datetime.utcnow():
|
||||
raise ValidationError('Invalid or expired token')
|
||||
try:
|
||||
_sync_casdoor_password_for_reset(user, new_password)
|
||||
user.set_password(new_password)
|
||||
user.reset_token = None
|
||||
user.reset_token_expiry = None
|
||||
db.session.commit()
|
||||
return jsonify({'message': 'Password has been reset successfully'})
|
||||
except AppError:
|
||||
db.session.rollback()
|
||||
raise
|
||||
except Exception as e:
|
||||
db.session.rollback()
|
||||
raise AppError(code='SYSTEM.INTERNAL_ERROR', message=str(e), http_status=500)
|
||||
|
||||
@@ -188,7 +188,7 @@ class Config:
|
||||
WECOM_PUBLIC_BASE_URL = os.getenv('WECOM_PUBLIC_BASE_URL')
|
||||
WECOM_NOTIFY_ENABLED = os.getenv('WECOM_NOTIFY_ENABLED', 'true').lower() == 'true'
|
||||
WECOM_NOTIFY_BASE_URL = os.getenv('WECOM_NOTIFY_BASE_URL')
|
||||
WECOM_NOTIFY_EVENTS = os.getenv('WECOM_NOTIFY_EVENTS', 'task_completed,schedule_completed')
|
||||
WECOM_NOTIFY_EVENTS = os.getenv('WECOM_NOTIFY_EVENTS', 'task_completed,schedule_completed,password_reset')
|
||||
|
||||
# JWT/Casdoor auth configuration (phase-1 compatible rollout)
|
||||
AUTH_LEGACY_HEADER_ENABLED = os.getenv('AUTH_LEGACY_HEADER_ENABLED', 'true').lower() == 'true'
|
||||
|
||||
@@ -0,0 +1,244 @@
|
||||
"""
|
||||
backend/app/services/wecom_directory_sync.py
|
||||
|
||||
用途:从企业微信通讯录拉取成员,按工号回填本地 users.wecom_userid。
|
||||
依赖:Flask current_app、SQLAlchemy db、wecom_notify._get_access_token、User 模型。
|
||||
逻辑:供 admin API 与 scripts/sync_wecom_userid_by_employee_id.py 共用;支持 dry-run 与 apply。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
import requests
|
||||
from flask import current_app
|
||||
|
||||
from app import db
|
||||
from app.models import User
|
||||
from app.services.wecom_notify import _get_access_token
|
||||
|
||||
_PREVIEW_LIMIT = 20
|
||||
|
||||
|
||||
def _clean_str(value) -> str | None:
|
||||
"""Trim string-like values; empty strings become None."""
|
||||
if value is None:
|
||||
return None
|
||||
text = str(value).strip()
|
||||
return text or None
|
||||
|
||||
|
||||
def _extract_wecom_extattr_value(wecom_user: dict, key: str) -> str | None:
|
||||
"""
|
||||
从企微成员 extattr.attrs 中读取指定扩展字段。
|
||||
@param wecom_user: user/list 返回的成员 dict
|
||||
@param key: 扩展属性名
|
||||
Returns:
|
||||
字段文本或 None
|
||||
"""
|
||||
extattr = wecom_user.get('extattr') or {}
|
||||
attrs = extattr.get('attrs') if isinstance(extattr, dict) else None
|
||||
if not isinstance(attrs, list):
|
||||
return None
|
||||
for attr in attrs:
|
||||
if not isinstance(attr, dict):
|
||||
continue
|
||||
if _clean_str(attr.get('name')) != key:
|
||||
continue
|
||||
raw = attr.get('value')
|
||||
if isinstance(raw, dict):
|
||||
raw = raw.get('text') or raw.get('web') or raw.get('value')
|
||||
return _clean_str(raw)
|
||||
return None
|
||||
|
||||
|
||||
def extract_employee_id_from_wecom_user(wecom_user: dict, employee_id_source: str) -> str | None:
|
||||
"""
|
||||
按 WECOM_EMPLOYEE_ID_SOURCE 从企微成员解析工号。
|
||||
核心逻辑:userid / extattr:xxx / 其它字段名,与 user.py _extract_wecom_identity 对齐。
|
||||
"""
|
||||
userid = _clean_str(wecom_user.get('userid'))
|
||||
source = _clean_str(employee_id_source) or 'userid'
|
||||
if source == 'userid':
|
||||
return userid
|
||||
if source.startswith('extattr:'):
|
||||
return _extract_wecom_extattr_value(wecom_user, source.split(':', 1)[1])
|
||||
return _clean_str(wecom_user.get(source))
|
||||
|
||||
|
||||
def fetch_wecom_departments(access_token: str) -> list[dict[str, Any]]:
|
||||
"""
|
||||
拉取企业微信部门列表。
|
||||
Raises:
|
||||
RuntimeError: API 失败
|
||||
"""
|
||||
resp = requests.get(
|
||||
'https://qyapi.weixin.qq.com/cgi-bin/department/list',
|
||||
params={'access_token': access_token},
|
||||
timeout=15,
|
||||
)
|
||||
data = resp.json() or {}
|
||||
if data.get('errcode') != 0:
|
||||
raise RuntimeError(f'department/list failed: {data}')
|
||||
departments = data.get('department') or []
|
||||
if not isinstance(departments, list):
|
||||
return []
|
||||
return [item for item in departments if isinstance(item, dict)]
|
||||
|
||||
|
||||
def fetch_wecom_users_in_department(access_token: str, department_id: int) -> list[dict[str, Any]]:
|
||||
"""
|
||||
拉取指定部门(含子部门)成员简要列表。
|
||||
@param department_id: 企微部门 ID
|
||||
Returns:
|
||||
user/list 返回的 userlist
|
||||
"""
|
||||
resp = requests.get(
|
||||
'https://qyapi.weixin.qq.com/cgi-bin/user/list',
|
||||
params={
|
||||
'access_token': access_token,
|
||||
'department_id': department_id,
|
||||
'fetch_child': 1,
|
||||
},
|
||||
timeout=30,
|
||||
)
|
||||
data = resp.json() or {}
|
||||
if data.get('errcode') != 0:
|
||||
raise RuntimeError(f'user/list failed department_id={department_id}: {data}')
|
||||
userlist = data.get('userlist') or []
|
||||
if not isinstance(userlist, list):
|
||||
return []
|
||||
return [item for item in userlist if isinstance(item, dict)]
|
||||
|
||||
|
||||
def collect_wecom_users(access_token: str, department_ids: list[int]) -> dict[str, dict[str, Any]]:
|
||||
"""
|
||||
汇总多个部门成员,按 wecom_userid 去重。
|
||||
Returns:
|
||||
key=userid, value=成员 dict
|
||||
"""
|
||||
merged: dict[str, dict[str, Any]] = {}
|
||||
for dept_id in department_ids:
|
||||
for user in fetch_wecom_users_in_department(access_token, dept_id):
|
||||
userid = _clean_str(user.get('userid'))
|
||||
if userid:
|
||||
merged[userid] = user
|
||||
return merged
|
||||
|
||||
|
||||
def sync_wecom_userids_from_directory(*, apply: bool, department_id: int | None = None) -> dict[str, Any]:
|
||||
"""
|
||||
执行工号 → wecom_userid 同步。
|
||||
核心逻辑:拉企微成员 → 解析 employee_id → 匹配本地 User → dry-run 或写 wecom_userid/wecom_unionid。
|
||||
@param apply: True 时提交数据库;存在 conflicts 时不写入
|
||||
@param department_id: 指定根部门 ID;None 时使用全部部门
|
||||
Returns:
|
||||
统计摘要 dict(含 conflicts、pending_updates 预览)
|
||||
"""
|
||||
if not current_app.config.get('WECOM_CORP_ID') or not current_app.config.get('WECOM_SECRET'):
|
||||
raise RuntimeError('WECOM_CORP_ID / WECOM_SECRET is not configured')
|
||||
|
||||
employee_id_source = _clean_str(current_app.config.get('WECOM_EMPLOYEE_ID_SOURCE')) or 'userid'
|
||||
token = _get_access_token()
|
||||
|
||||
if department_id is not None:
|
||||
department_ids = [department_id]
|
||||
else:
|
||||
departments = fetch_wecom_departments(token)
|
||||
department_ids = [int(item.get('id')) for item in departments if item.get('id') is not None]
|
||||
if not department_ids:
|
||||
department_ids = [1]
|
||||
|
||||
wecom_users = collect_wecom_users(token, department_ids)
|
||||
summary: dict[str, Any] = {
|
||||
'apply': apply,
|
||||
'employee_id_source': employee_id_source,
|
||||
'department_ids': department_ids,
|
||||
'wecom_users': len(wecom_users),
|
||||
'wecom_without_employee_id': 0,
|
||||
'local_matched': 0,
|
||||
'would_update': 0,
|
||||
'updated': 0,
|
||||
'already_bound': 0,
|
||||
'local_missing': 0,
|
||||
'conflicts': [],
|
||||
'missing_samples': [],
|
||||
'pending_updates': [],
|
||||
}
|
||||
|
||||
for wecom_user in wecom_users.values():
|
||||
wecom_userid = _clean_str(wecom_user.get('userid'))
|
||||
wecom_unionid = _clean_str(wecom_user.get('unionid'))
|
||||
employee_id = extract_employee_id_from_wecom_user(wecom_user, employee_id_source)
|
||||
if not employee_id:
|
||||
summary['wecom_without_employee_id'] += 1
|
||||
if len(summary['missing_samples']) < _PREVIEW_LIMIT:
|
||||
summary['missing_samples'].append(
|
||||
{'wecom_userid': wecom_userid, 'name': _clean_str(wecom_user.get('name'))}
|
||||
)
|
||||
continue
|
||||
|
||||
local_user = db.session.query(User).filter(User.employee_id == employee_id).first()
|
||||
if not local_user:
|
||||
summary['local_missing'] += 1
|
||||
continue
|
||||
|
||||
summary['local_matched'] += 1
|
||||
|
||||
if local_user.wecom_userid == wecom_userid:
|
||||
summary['already_bound'] += 1
|
||||
continue
|
||||
|
||||
conflict = None
|
||||
if local_user.wecom_userid and local_user.wecom_userid != wecom_userid:
|
||||
conflict = {
|
||||
'employee_id': employee_id,
|
||||
'username': local_user.username,
|
||||
'old_wecom_userid': local_user.wecom_userid,
|
||||
'new_wecom_userid': wecom_userid,
|
||||
}
|
||||
else:
|
||||
occupied = (
|
||||
db.session.query(User)
|
||||
.filter(User.wecom_userid == wecom_userid, User.id != local_user.id)
|
||||
.first()
|
||||
)
|
||||
if occupied:
|
||||
conflict = {
|
||||
'employee_id': employee_id,
|
||||
'username': local_user.username,
|
||||
'new_wecom_userid': wecom_userid,
|
||||
'occupied_by_user_id': occupied.id,
|
||||
'occupied_by_username': occupied.username,
|
||||
}
|
||||
|
||||
if conflict:
|
||||
summary['conflicts'].append(conflict)
|
||||
continue
|
||||
|
||||
summary['would_update'] += 1
|
||||
if len(summary['pending_updates']) < _PREVIEW_LIMIT:
|
||||
summary['pending_updates'].append(
|
||||
{
|
||||
'employee_id': employee_id,
|
||||
'username': local_user.username,
|
||||
'wecom_userid': wecom_userid,
|
||||
'name': _clean_str(wecom_user.get('name')),
|
||||
}
|
||||
)
|
||||
if apply:
|
||||
local_user.wecom_userid = wecom_userid
|
||||
if wecom_unionid:
|
||||
local_user.wecom_unionid = wecom_unionid
|
||||
summary['updated'] += 1
|
||||
|
||||
if summary['conflicts'] and apply:
|
||||
db.session.rollback()
|
||||
raise RuntimeError('Conflicts detected; resolve manually before apply')
|
||||
|
||||
if apply and summary['updated'] > 0:
|
||||
db.session.commit()
|
||||
elif apply:
|
||||
db.session.rollback()
|
||||
|
||||
return summary
|
||||
@@ -27,8 +27,22 @@ def _get_enabled_events() -> set[str]:
|
||||
return set()
|
||||
|
||||
|
||||
def _get_notify_base_url() -> str:
|
||||
"""
|
||||
解析企微 textcard 跳转基地址。
|
||||
核心逻辑:优先 WECOM_NOTIFY_BASE_URL,其次 WECOM_PUBLIC_BASE_URL。
|
||||
Returns:
|
||||
去掉尾斜杠的基地址;均未配置时返回空字符串。
|
||||
"""
|
||||
for key in ('WECOM_NOTIFY_BASE_URL', 'WECOM_PUBLIC_BASE_URL'):
|
||||
raw = current_app.config.get(key)
|
||||
if isinstance(raw, str) and raw.strip():
|
||||
return raw.strip().rstrip('/')
|
||||
return ''
|
||||
|
||||
|
||||
def _build_jump_url(path: str, trace_id: str, params: dict | None = None) -> str:
|
||||
base = current_app.config.get('WECOM_NOTIFY_BASE_URL') or ''
|
||||
base = _get_notify_base_url()
|
||||
if not base:
|
||||
return ''
|
||||
base = base.rstrip('/')
|
||||
@@ -133,7 +147,7 @@ def send_wecom_textcard_message(
|
||||
'textcard': {
|
||||
'title': title[:120],
|
||||
'description': (description or '')[:1024],
|
||||
'url': jump_url or (current_app.config.get('WECOM_NOTIFY_BASE_URL') or 'https://work.weixin.qq.com'),
|
||||
'url': jump_url or _get_notify_base_url() or 'https://work.weixin.qq.com',
|
||||
'btntxt': '查看详情',
|
||||
},
|
||||
'safe': 0,
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
backend/scripts/sync_wecom_userid_by_employee_id.py
|
||||
|
||||
用途:从企业微信通讯录拉取成员,按工号(employee_id)回填本地 users.wecom_userid。
|
||||
依赖:app.create_app、wecom_directory_sync.sync_wecom_userids_from_directory。
|
||||
逻辑:运维 CLI;默认 dry-run,--apply 才写库。
|
||||
|
||||
Usage:
|
||||
cd backend
|
||||
python scripts/sync_wecom_userid_by_employee_id.py
|
||||
python scripts/sync_wecom_userid_by_employee_id.py --apply
|
||||
python scripts/sync_wecom_userid_by_employee_id.py --apply --department-id 1
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
BACKEND_ROOT = Path(__file__).resolve().parents[1]
|
||||
if str(BACKEND_ROOT) not in sys.path:
|
||||
sys.path.insert(0, str(BACKEND_ROOT))
|
||||
|
||||
from app import create_app # noqa: E402
|
||||
from app.services.wecom_directory_sync import sync_wecom_userids_from_directory # noqa: E402
|
||||
|
||||
|
||||
def main() -> int:
|
||||
"""CLI 入口:解析参数并打印同步摘要 JSON。"""
|
||||
parser = argparse.ArgumentParser(description='Sync User.wecom_userid from WeCom directory by employee_id.')
|
||||
parser.add_argument('--apply', action='store_true', help='Persist changes (default: dry-run).')
|
||||
parser.add_argument('--department-id', type=int, default=None, help='Root department id (default: all departments).')
|
||||
args = parser.parse_args()
|
||||
|
||||
env = os.getenv('FLASK_ENV', 'production')
|
||||
app = create_app(env)
|
||||
with app.app_context():
|
||||
summary = sync_wecom_userids_from_directory(apply=args.apply, department_id=args.department_id)
|
||||
|
||||
print(json.dumps(summary, ensure_ascii=False, indent=2))
|
||||
if summary.get('conflicts'):
|
||||
print('\nConflicts detected; resolve manually before --apply.', file=sys.stderr)
|
||||
return 1
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
raise SystemExit(main())
|
||||
@@ -40,7 +40,10 @@ const SchedulesPage = () =>
|
||||
const KnowledgeBasePage = () =>
|
||||
import("@/features/admin/modules/knowledge-base/KnowledgeBasePage.vue");
|
||||
|
||||
const WecomPage = () => import("@/features/admin/modules/wecom/WecomPage.vue");
|
||||
const WecomLayout = () => import("@/features/admin/modules/wecom/WecomLayout.vue");
|
||||
const WecomSettingsPage = () => import("@/features/admin/modules/wecom/pages/WecomSettingsPage.vue");
|
||||
const WecomBindingsPage = () => import("@/features/admin/modules/wecom/pages/WecomBindingsPage.vue");
|
||||
const WecomAuditsPage = () => import("@/features/admin/modules/wecom/pages/WecomAuditsPage.vue");
|
||||
|
||||
const ReportsPage = () =>
|
||||
import("@/features/admin/modules/reports/ReportsPage.vue");
|
||||
@@ -83,8 +86,29 @@ export const adminRoutes: RouteRecordRaw[] = [
|
||||
{
|
||||
path: "wecom",
|
||||
name: "AdminWecom",
|
||||
component: WecomPage,
|
||||
component: WecomLayout,
|
||||
redirect: { name: "AdminWecomSettings" },
|
||||
meta: { requiresAdmin: true, adminModule: "wecom", title: "企业微信" },
|
||||
children: [
|
||||
{
|
||||
path: "settings",
|
||||
name: "AdminWecomSettings",
|
||||
component: WecomSettingsPage,
|
||||
meta: { requiresAdmin: true, adminModule: "wecom", title: "企业微信配置" },
|
||||
},
|
||||
{
|
||||
path: "bindings",
|
||||
name: "AdminWecomBindings",
|
||||
component: WecomBindingsPage,
|
||||
meta: { requiresAdmin: true, adminModule: "wecom", title: "企业微信绑定" },
|
||||
},
|
||||
{
|
||||
path: "audits",
|
||||
name: "AdminWecomAudits",
|
||||
component: WecomAuditsPage,
|
||||
meta: { requiresAdmin: true, adminModule: "wecom", title: "企业微信审计" },
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
path: "approvals",
|
||||
|
||||
@@ -130,8 +130,26 @@ export const batchDeleteAdminChatLogs = (ids: number[]) =>
|
||||
});
|
||||
|
||||
// WeCom admin
|
||||
export const listAdminWecomBindings = (boundOnly: boolean) =>
|
||||
requestJson<any[]>(`/api/admin/wecom/bindings?bound_only=${boundOnly ? 'true' : 'false'}`, auth());
|
||||
export interface ListAdminWecomBindingsParams {
|
||||
boundOnly?: boolean;
|
||||
keyword?: string;
|
||||
page?: number;
|
||||
pageSize?: number;
|
||||
}
|
||||
|
||||
export const listAdminWecomBindings = (params: ListAdminWecomBindingsParams = {}) => {
|
||||
const qs = new URLSearchParams();
|
||||
if (params.boundOnly) qs.set('bound_only', 'true');
|
||||
const keyword = params.keyword?.trim();
|
||||
if (keyword) qs.set('keyword', keyword);
|
||||
if (params.page) qs.set('page', String(params.page));
|
||||
if (params.pageSize) qs.set('page_size', String(params.pageSize));
|
||||
const query = qs.toString();
|
||||
const suffix = query ? `?${query}` : '';
|
||||
return requestJson<import('@/shared/types/pagination.types').PaginatedResult<
|
||||
import('@/features/admin/types/wecom.types').WecomBindingRow
|
||||
>>(`/api/admin/wecom/bindings${suffix}`, auth());
|
||||
};
|
||||
export const listAdminWecomLoginAudits = (query: string) =>
|
||||
requestJson<any[]>(`/api/admin/wecom/login-audits?${query}`, auth());
|
||||
export const getAdminWecomSystemSettings = () =>
|
||||
@@ -154,6 +172,14 @@ export const saveAdminWecomNotifySettings = (payload: Record<string, unknown>) =
|
||||
});
|
||||
export const getAdminWecomNotifyMetrics = () =>
|
||||
requestJson<any>('/api/admin/wecom/notify-metrics', auth());
|
||||
export const getAdminWecomBindingStats = () =>
|
||||
requestJson<import('@/features/admin/types/wecom.types').WecomBindingStats>('/api/admin/wecom/binding-stats', auth());
|
||||
export const syncAdminWecomUserids = (payload: { apply: boolean; department_id?: number | null }) =>
|
||||
requestJson<import('@/features/admin/types/wecom.types').WecomSyncSummary>('/api/admin/wecom/sync-userids', {
|
||||
method: 'POST',
|
||||
...jsonAuth(),
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
export const bindAdminWecomUser = (payload: Record<string, unknown>) =>
|
||||
requestJson('/api/admin/wecom/bind', { method: 'POST', ...jsonAuth(), body: JSON.stringify(payload) });
|
||||
export const unbindAdminWecomUser = (userId: number) =>
|
||||
|
||||
@@ -42,10 +42,25 @@ const visibleModules = computed(() =>
|
||||
ADMIN_MODULE_METAS.filter((item) => config.admin.modules[item.configKey] !== false),
|
||||
);
|
||||
|
||||
const standardModules = computed(() =>
|
||||
visibleModules.value.filter((item) => item.id !== 'wecom'),
|
||||
);
|
||||
|
||||
const isModuleActive = (moduleId: AdminModuleId): boolean =>
|
||||
route.meta.adminModule === moduleId;
|
||||
|
||||
const isReportsActive = computed(() => route.meta.adminModule === 'reports');
|
||||
const isWecomActive = computed(() => route.meta.adminModule === 'wecom');
|
||||
|
||||
const wecomSubRoutes = [
|
||||
{ name: 'AdminWecomSettings', labelKey: 'admin.wecom.nav.settings' },
|
||||
{ name: 'AdminWecomBindings', labelKey: 'admin.wecom.nav.bindings' },
|
||||
{ name: 'AdminWecomAudits', labelKey: 'admin.wecom.nav.audits' },
|
||||
] as const;
|
||||
|
||||
const navigateWecom = (routeName: string): void => {
|
||||
router.push({ name: routeName });
|
||||
};
|
||||
|
||||
const getReportTableLabel = (table: string): string => {
|
||||
const i18nKey = `admin.report.tables.${table}`;
|
||||
@@ -70,7 +85,7 @@ const navigateReport = (table: string): void => {
|
||||
>
|
||||
<nav class="flex md:flex-col p-3 gap-1 overflow-x-auto md:overflow-visible no-scrollbar">
|
||||
<button
|
||||
v-for="item in visibleModules"
|
||||
v-for="item in standardModules"
|
||||
:key="item.id"
|
||||
type="button"
|
||||
class="admin-nav-btn group"
|
||||
@@ -96,6 +111,35 @@ const navigateReport = (table: string): void => {
|
||||
/>
|
||||
</button>
|
||||
|
||||
<div v-if="config.admin.modules.wecom !== false" class="flex flex-col flex-shrink-0">
|
||||
<button
|
||||
type="button"
|
||||
class="admin-nav-btn group justify-between"
|
||||
:class="{ 'admin-nav-btn--active': isWecomActive }"
|
||||
@click="navStore.wecomExpanded = !navStore.wecomExpanded"
|
||||
>
|
||||
<div class="flex items-center gap-3">
|
||||
<Link2 class="w-5 h-5 flex-shrink-0" :class="isWecomActive ? 'text-brand-600' : 'text-muted'" />
|
||||
<span :class="navStore.sidebarCollapsed ? 'md:hidden' : ''">{{ t('admin.nav.wecom') }}</span>
|
||||
</div>
|
||||
</button>
|
||||
<div
|
||||
v-if="navStore.wecomExpanded && !navStore.sidebarCollapsed"
|
||||
class="pl-4 space-y-1 mt-1 border-l-2 border-subtle ml-6"
|
||||
>
|
||||
<button
|
||||
v-for="sub in wecomSubRoutes"
|
||||
:key="sub.name"
|
||||
type="button"
|
||||
class="admin-nav-subitem"
|
||||
:class="{ 'admin-nav-subitem--active': route.name === sub.name }"
|
||||
@click="navigateWecom(sub.name)"
|
||||
>
|
||||
{{ t(sub.labelKey) }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="config.admin.modules.reports !== false" class="flex flex-col flex-shrink-0">
|
||||
<button
|
||||
type="button"
|
||||
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
getAdminUsageReport,
|
||||
} from '@/features/admin/api/admin.api';
|
||||
import { loadReportLayoutPref, saveReportLayoutPref } from '@/shared/composables/useReportLayoutStorage';
|
||||
import { buildOffsetPageButtons } from '@/shared/composables/useOffsetPagination';
|
||||
import { useMessage } from '@/shared/composables/useMessage';
|
||||
import { ADMIN_REPORT_TABLES } from '@/features/admin/constants/modules';
|
||||
import type {
|
||||
@@ -635,10 +636,7 @@ const nextReportPage = () => goToReportPage(reportCurrentPage.value + 1);
|
||||
const reportPageButtons = computed(() => {
|
||||
const total = reportTotalPages.value;
|
||||
const current = Math.min(Math.max(1, reportCurrentPage.value), total);
|
||||
if (total <= 7) return Array.from({ length: total }, (_, i) => i + 1);
|
||||
if (current <= 4) return [1, 2, 3, 4, 5, -1, total];
|
||||
if (current >= total - 3) return [1, -1, total - 4, total - 3, total - 2, total - 1, total];
|
||||
return [1, -1, current - 1, current, current + 1, -1, total];
|
||||
return buildOffsetPageButtons(current, total);
|
||||
});
|
||||
|
||||
const onReportHeaderClick = (key: string) => {
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* features/admin/modules/wecom/WecomLayout.vue
|
||||
* 企微管理壳层:二级 Tab、共享 composable、子路由出口。
|
||||
*/
|
||||
import { onMounted, provide } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { RefreshCw } from 'lucide-vue-next';
|
||||
import DeleteConfirmDialog from '@/shared/components/DeleteConfirmDialog.vue';
|
||||
import WecomSubNav from './components/WecomSubNav.vue';
|
||||
import { useWecomAdmin } from './composables/useWecomAdmin';
|
||||
import { WECOM_ADMIN_KEY } from './wecom.context';
|
||||
|
||||
const { t } = useI18n();
|
||||
const wecomAdmin = useWecomAdmin();
|
||||
provide(WECOM_ADMIN_KEY, wecomAdmin);
|
||||
const {
|
||||
isLoading,
|
||||
showDeleteConfirmDialog,
|
||||
deleteConfirmMessage,
|
||||
confirmDelete,
|
||||
refreshWecomData,
|
||||
} = wecomAdmin;
|
||||
|
||||
onMounted(() => {
|
||||
void wecomAdmin.loadAll();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div v-if="isLoading" class="flex items-center justify-center py-20">
|
||||
<div class="animate-spin rounded-full h-10 w-10 border-b-2 border-brand-600" />
|
||||
</div>
|
||||
|
||||
<section v-else class="section-gap animate-fade-in-up space-y-6">
|
||||
<div class="flex flex-col md:flex-row items-start md:items-center justify-between gap-4">
|
||||
<div>
|
||||
<h2 class="section-title">{{ t('admin.wecom.title') }}</h2>
|
||||
<p class="section-desc mt-1">{{ t('admin.wecom.subtitle') }}</p>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
class="btn-secondary inline-flex items-center gap-2 px-4 py-2 text-secondary rounded-xl hover-surface-soft transition-all shadow-sm"
|
||||
@click="refreshWecomData()"
|
||||
>
|
||||
<RefreshCw class="w-4 h-4" />
|
||||
{{ t('admin.wecom.refresh') }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<WecomSubNav />
|
||||
<router-view />
|
||||
|
||||
<DeleteConfirmDialog
|
||||
v-model="showDeleteConfirmDialog"
|
||||
:message="deleteConfirmMessage"
|
||||
@confirm="confirmDelete"
|
||||
/>
|
||||
</section>
|
||||
</template>
|
||||
@@ -1,456 +0,0 @@
|
||||
/**
|
||||
* features/admin/modules/wecom/WecomPage.vue
|
||||
* 企业微信管理独立页面。路由:/admin/wecom
|
||||
*/
|
||||
<script setup lang="ts">
|
||||
import { onMounted } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { CircleHelp, Download, Link2, RefreshCw, Unlink2 } from 'lucide-vue-next';
|
||||
import DeleteConfirmDialog from '@/shared/components/DeleteConfirmDialog.vue';
|
||||
import { useWecomAdmin } from './composables/useWecomAdmin';
|
||||
|
||||
const { t } = useI18n();
|
||||
|
||||
const {
|
||||
isLoading,
|
||||
isSaving,
|
||||
wecomBindings,
|
||||
wecomBindForm,
|
||||
wecomBindUserQuery,
|
||||
wecomBindUserDropdownOpen,
|
||||
wecomBindUserOptions,
|
||||
wecomBoundOnly,
|
||||
wecomAuditSourceFilter,
|
||||
wecomAuditStatusFilter,
|
||||
filteredWecomLoginAudits,
|
||||
wecomNotifySettings,
|
||||
wecomNotifyEventsText,
|
||||
wecomNotifyMetrics,
|
||||
wecomSystemSettings,
|
||||
wecomIntegrationManifest,
|
||||
showDeleteConfirmDialog,
|
||||
deleteConfirmMessage,
|
||||
loadAll,
|
||||
refreshWecomData,
|
||||
selectWecomBindUser,
|
||||
scheduleCloseWecomBindUserDropdown,
|
||||
copyText,
|
||||
getWecomAuditReasonText,
|
||||
getWecomAuditMetaText,
|
||||
generateWecomAddressesFromPublicBase,
|
||||
generateWecomCallbackToken,
|
||||
generateWecomEncodingAesKey,
|
||||
saveWecomSystemSettings,
|
||||
saveWecomNotifySettings,
|
||||
bindWecomUser,
|
||||
unbindWecomUserByAdmin,
|
||||
exportWecomAudits,
|
||||
confirmDelete,
|
||||
} = useWecomAdmin();
|
||||
|
||||
onMounted(() => {
|
||||
void loadAll();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div v-if="isLoading" class="flex items-center justify-center py-20">
|
||||
<div class="animate-spin rounded-full h-10 w-10 border-b-2 border-brand-600" />
|
||||
</div>
|
||||
|
||||
<section v-else class="section-gap animate-fade-in-up">
|
||||
<div class="flex flex-col md:flex-row items-start md:items-center justify-between gap-4">
|
||||
<div>
|
||||
<h2 class="section-title">{{ t('admin.wecom.title') }}</h2>
|
||||
<p class="section-desc mt-1">{{ t('admin.wecom.subtitle') }}</p>
|
||||
</div>
|
||||
<button
|
||||
@click="refreshWecomData"
|
||||
class="btn-secondary inline-flex items-center gap-2 px-4 py-2 text-secondary rounded-xl hover-surface-soft transition-all shadow-sm"
|
||||
>
|
||||
<RefreshCw class="w-4 h-4" />
|
||||
{{ t('admin.wecom.refresh') }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="card shadow-sm p-5 space-y-4">
|
||||
<h3 class="font-semibold text-primary">{{ t('admin.wecom.quickBind') }}</h3>
|
||||
<div class="grid grid-cols-1 md:grid-cols-4 gap-3">
|
||||
<div class="relative md:col-span-1">
|
||||
<input
|
||||
v-model="wecomBindUserQuery"
|
||||
type="text"
|
||||
class="input-field"
|
||||
:placeholder="t('admin.wecom.fields.userSelect')"
|
||||
@focus="wecomBindUserDropdownOpen = true"
|
||||
@input="wecomBindUserDropdownOpen = true"
|
||||
@blur="scheduleCloseWecomBindUserDropdown"
|
||||
/>
|
||||
<div
|
||||
v-if="wecomBindUserDropdownOpen"
|
||||
class="admin-dropdown w-72"
|
||||
>
|
||||
<button
|
||||
v-for="u in wecomBindUserOptions"
|
||||
:key="u.id"
|
||||
type="button"
|
||||
class="flex w-full items-center justify-between gap-3 px-3 py-2 text-left hover:bg-blue-50"
|
||||
@mousedown.prevent="selectWecomBindUser(u.id, u.label)"
|
||||
>
|
||||
<span class="text-sm text-primary">{{ u.label }}</span>
|
||||
<span class="text-xs text-muted">{{ u.employeeId || '' }}</span>
|
||||
</button>
|
||||
<div v-if="wecomBindUserOptions.length === 0" class="px-3 py-2 text-sm text-muted">
|
||||
{{ t('admin.wecom.noData') }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<input v-model="wecomBindForm.wecom_userid" :placeholder="t('admin.wecom.fields.wecomUserId')" class="input-field md:col-span-2" />
|
||||
<input v-model="wecomBindForm.wecom_unionid" :placeholder="t('admin.wecom.fields.wecomUnionId')" class="input-field" />
|
||||
</div>
|
||||
<div class="flex justify-end">
|
||||
<button @click="bindWecomUser" :disabled="isSaving" class="btn-primary px-5 py-2 disabled:opacity-60">
|
||||
<Link2 class="w-4 h-4" /> {{ t('admin.wecom.bind') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card shadow-sm p-5 space-y-4">
|
||||
<h3 class="font-semibold text-primary">{{ t('admin.wecom.systemSettings') }}</h3>
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-3">
|
||||
<label class="inline-flex items-center gap-2 text-sm text-secondary">
|
||||
<input v-model="wecomSystemSettings.enabled" type="checkbox" class="admin-checkbox" />
|
||||
{{ t('admin.wecom.fields.enabled') }}
|
||||
<CircleHelp class="w-3.5 h-3.5 text-muted" :title="t('admin.wecom.tips.enabled')" />
|
||||
</label>
|
||||
<label class="inline-flex items-center gap-2 text-sm text-secondary">
|
||||
<input v-model="wecomSystemSettings.auto_create_user" type="checkbox" class="admin-checkbox" />
|
||||
{{ t('admin.wecom.fields.autoCreateUser') }}
|
||||
<CircleHelp class="w-3.5 h-3.5 text-muted" :title="t('admin.wecom.tips.autoCreateUser')" />
|
||||
</label>
|
||||
</div>
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-3">
|
||||
<div>
|
||||
<label class="mb-1.5 inline-flex items-center gap-1 text-xs text-muted">
|
||||
{{ t('admin.wecom.fields.corpId') }}
|
||||
<CircleHelp class="w-3.5 h-3.5 text-muted" :title="t('admin.wecom.tips.corpId')" />
|
||||
</label>
|
||||
<input v-model="wecomSystemSettings.corp_id" class="input-field" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="mb-1.5 inline-flex items-center gap-1 text-xs text-muted">
|
||||
{{ t('admin.wecom.fields.agentId') }}
|
||||
<CircleHelp class="w-3.5 h-3.5 text-muted" :title="t('admin.wecom.tips.agentId')" />
|
||||
</label>
|
||||
<input v-model="wecomSystemSettings.agent_id" class="input-field" />
|
||||
</div>
|
||||
<div class="md:col-span-2">
|
||||
<label class="mb-1.5 inline-flex items-center gap-1 text-xs text-muted">
|
||||
{{ t('admin.wecom.fields.secret') }}
|
||||
<CircleHelp class="w-3.5 h-3.5 text-muted" :title="t('admin.wecom.tips.secret')" />
|
||||
</label>
|
||||
<input v-model="wecomSystemSettings.secret" type="password" class="input-field" />
|
||||
</div>
|
||||
<div class="md:col-span-2">
|
||||
<label class="mb-1.5 inline-flex items-center gap-1 text-xs text-muted">
|
||||
{{ t('admin.wecom.fields.redirectUri') }}
|
||||
<CircleHelp class="w-3.5 h-3.5 text-muted" :title="t('admin.wecom.tips.redirectUri')" />
|
||||
</label>
|
||||
<input v-model="wecomSystemSettings.redirect_uri" class="input-field" />
|
||||
</div>
|
||||
<div class="md:col-span-2">
|
||||
<label class="mb-1.5 inline-flex items-center gap-1 text-xs text-muted">
|
||||
{{ t('admin.wecom.fields.publicBaseUrl') }}
|
||||
<CircleHelp class="w-3.5 h-3.5 text-muted" :title="t('admin.wecom.tips.publicBaseUrl')" />
|
||||
</label>
|
||||
<div class="flex flex-wrap gap-2">
|
||||
<input
|
||||
v-model="wecomSystemSettings.public_base_url"
|
||||
:placeholder="t('admin.wecom.publicBasePlaceholder')"
|
||||
class="input-field flex-1 min-w-[200px]"
|
||||
/>
|
||||
<button type="button" class="btn-secondary px-4 shrink-0" @click="generateWecomAddressesFromPublicBase">
|
||||
{{ t('admin.wecom.generateAddresses') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<label class="mb-1.5 inline-flex items-center gap-1 text-xs text-muted">
|
||||
{{ t('admin.wecom.fields.callbackToken') }}
|
||||
<CircleHelp class="w-3.5 h-3.5 text-muted" :title="t('admin.wecom.tips.callbackToken')" />
|
||||
</label>
|
||||
<div class="flex gap-2">
|
||||
<input v-model="wecomSystemSettings.callback_token" class="input-field flex-1 min-w-0" />
|
||||
<button type="button" class="btn-secondary px-3 shrink-0 text-xs" @click="generateWecomCallbackToken">
|
||||
{{ t('admin.wecom.generateToken') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<label class="mb-1.5 inline-flex items-center gap-1 text-xs text-muted">
|
||||
{{ t('admin.wecom.fields.encodingAesKey') }}
|
||||
<CircleHelp class="w-3.5 h-3.5 text-muted" :title="t('admin.wecom.tips.encodingAesKey')" />
|
||||
</label>
|
||||
<div class="flex gap-2">
|
||||
<input v-model="wecomSystemSettings.encoding_aes_key" class="input-field flex-1 min-w-0 font-mono text-xs" />
|
||||
<button type="button" class="btn-secondary px-3 shrink-0 text-xs" @click="generateWecomEncodingAesKey">
|
||||
{{ t('admin.wecom.generateEncodingKey') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<label class="mb-1.5 inline-flex items-center gap-1 text-xs text-muted">
|
||||
{{ t('admin.wecom.fields.callbackUrl') }}
|
||||
<CircleHelp class="w-3.5 h-3.5 text-muted" :title="t('admin.wecom.tips.callbackUrl')" />
|
||||
</label>
|
||||
<input v-model="wecomSystemSettings.callback_url" class="input-field" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="mb-1.5 inline-flex items-center gap-1 text-xs text-muted">
|
||||
{{ t('admin.wecom.fields.homepageUrl') }}
|
||||
<CircleHelp class="w-3.5 h-3.5 text-muted" :title="t('admin.wecom.tips.homepageUrl')" />
|
||||
</label>
|
||||
<input v-model="wecomSystemSettings.homepage_url" class="input-field" />
|
||||
</div>
|
||||
<div class="md:col-span-2">
|
||||
<label class="mb-1.5 inline-flex items-center gap-1 text-xs text-muted">
|
||||
{{ t('admin.wecom.fields.trustedDomain') }}
|
||||
<CircleHelp class="w-3.5 h-3.5 text-muted" :title="t('admin.wecom.tips.trustedDomain')" />
|
||||
</label>
|
||||
<input v-model="wecomSystemSettings.trusted_domain" class="input-field" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="mb-1.5 inline-flex items-center gap-1 text-xs text-muted">
|
||||
{{ t('admin.wecom.fields.matchRules') }}
|
||||
<CircleHelp class="w-3.5 h-3.5 text-muted" :title="t('admin.wecom.tips.matchRules')" />
|
||||
</label>
|
||||
<input v-model="wecomSystemSettings.match_rules" class="input-field" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="mb-1.5 inline-flex items-center gap-1 text-xs text-muted">
|
||||
{{ t('admin.wecom.fields.matchOperator') }}
|
||||
<CircleHelp class="w-3.5 h-3.5 text-muted" :title="t('admin.wecom.tips.matchOperator')" />
|
||||
</label>
|
||||
<select v-model="wecomSystemSettings.match_operator" class="input-field">
|
||||
<option value="AND">AND</option>
|
||||
<option value="OR">OR</option>
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label class="mb-1.5 inline-flex items-center gap-1 text-xs text-muted">
|
||||
{{ t('admin.wecom.fields.firstLoginBindMode') }}
|
||||
<CircleHelp class="w-3.5 h-3.5 text-muted" :title="t('admin.wecom.tips.firstLoginBindMode')" />
|
||||
</label>
|
||||
<select v-model="wecomSystemSettings.first_login_bind_mode" class="input-field">
|
||||
<option value="match_rules">{{ t('admin.wecom.bindModes.match_rules') }}</option>
|
||||
<option value="input_verify">{{ t('admin.wecom.bindModes.input_verify') }}</option>
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label class="mb-1.5 inline-flex items-center gap-1 text-xs text-muted">
|
||||
{{ t('admin.wecom.fields.firstLoginInputFields') }}
|
||||
<CircleHelp class="w-3.5 h-3.5 text-muted" :title="t('admin.wecom.tips.firstLoginInputFields')" />
|
||||
</label>
|
||||
<input v-model="wecomSystemSettings.first_login_input_fields" class="input-field" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="mb-1.5 inline-flex items-center gap-1 text-xs text-muted">
|
||||
{{ t('admin.wecom.fields.employeeIdSource') }}
|
||||
<CircleHelp class="w-3.5 h-3.5 text-muted" :title="t('admin.wecom.tips.employeeIdSource')" />
|
||||
</label>
|
||||
<input v-model="wecomSystemSettings.employee_id_source" class="input-field" />
|
||||
</div>
|
||||
<label class="inline-flex items-center gap-2 text-sm text-secondary pt-7">
|
||||
<input v-model="wecomSystemSettings.mobile_normalize" type="checkbox" class="admin-checkbox" />
|
||||
{{ t('admin.wecom.fields.mobileNormalize') }}
|
||||
<CircleHelp class="w-3.5 h-3.5 text-muted" :title="t('admin.wecom.tips.mobileNormalize')" />
|
||||
</label>
|
||||
</div>
|
||||
<div class="flex justify-end">
|
||||
<button @click="saveWecomSystemSettings" :disabled="isSaving" class="btn-primary px-5 py-2 disabled:opacity-60">
|
||||
{{ t('admin.save') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-1 xl:grid-cols-2 gap-6">
|
||||
<div class="card shadow-sm p-5 space-y-4">
|
||||
<h3 class="font-semibold text-primary">{{ t('admin.wecom.notifySettings') }}</h3>
|
||||
<label class="inline-flex items-center gap-2 text-sm text-secondary">
|
||||
<input v-model="wecomNotifySettings.enabled" type="checkbox" class="admin-checkbox" />
|
||||
{{ t('admin.wecom.notifyEnabled') }}
|
||||
</label>
|
||||
<input v-model="wecomNotifySettings.base_url" :placeholder="t('admin.wecom.notifyBaseUrl')" class="input-field" />
|
||||
<input v-model="wecomNotifyEventsText" :placeholder="t('admin.wecom.notifyEvents')" class="input-field" />
|
||||
<div class="flex justify-end">
|
||||
<button @click="saveWecomNotifySettings" :disabled="isSaving" class="btn-primary px-5 py-2 disabled:opacity-60">
|
||||
{{ t('admin.save') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card shadow-sm p-5 space-y-4">
|
||||
<h3 class="font-semibold text-primary">{{ t('admin.wecom.notifyMetrics') }}</h3>
|
||||
<div v-if="wecomNotifyMetrics" class="grid grid-cols-2 gap-3 text-sm">
|
||||
<div class="rounded-lg bg-surface-soft px-3 py-2">
|
||||
<div class="text-muted">{{ t('admin.wecom.metricTotal') }}</div>
|
||||
<div class="text-lg font-semibold text-primary">{{ wecomNotifyMetrics.total }}</div>
|
||||
</div>
|
||||
<div class="rounded-lg bg-surface-soft px-3 py-2">
|
||||
<div class="text-muted">{{ t('admin.wecom.metricSuccessRate') }}</div>
|
||||
<div class="text-lg font-semibold text-emerald-700">{{ wecomNotifyMetrics.send_success_rate }}%</div>
|
||||
</div>
|
||||
<div class="rounded-lg bg-surface-soft px-3 py-2">
|
||||
<div class="text-muted">{{ t('admin.wecom.metricOpenedRate') }}</div>
|
||||
<div class="text-lg font-semibold text-blue-700">{{ wecomNotifyMetrics.opened_24h_rate }}%</div>
|
||||
</div>
|
||||
<div class="rounded-lg bg-surface-soft px-3 py-2">
|
||||
<div class="text-muted">{{ t('admin.wecom.metricWindowDays') }}</div>
|
||||
<div class="text-lg font-semibold text-primary">{{ wecomNotifyMetrics.window_days }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card shadow-sm p-5 space-y-4">
|
||||
<h3 class="font-semibold text-primary">{{ t('admin.wecom.integrationCopyTitle') }}</h3>
|
||||
<p class="text-xs text-muted">{{ t('admin.wecom.integrationCopyDesc') }}</p>
|
||||
<p class="text-xs text-amber-800 bg-amber-50 border border-amber-100 rounded-lg px-3 py-2">{{ t('admin.wecom.integrationCopySecretsNote') }}</p>
|
||||
<div v-if="wecomIntegrationManifest" class="grid grid-cols-1 gap-3">
|
||||
<div v-for="item in [
|
||||
{ key: 'public_base_url', label: t('admin.wecom.copyFields.publicBaseUrl') },
|
||||
{ key: 'callback_url', label: t('admin.wecom.copyFields.callbackUrl') },
|
||||
{ key: 'callback_token', label: t('admin.wecom.copyFields.callbackToken') },
|
||||
{ key: 'encoding_aes_key', label: t('admin.wecom.copyFields.encodingAesKey') },
|
||||
{ key: 'oauth_redirect_uri', label: t('admin.wecom.copyFields.oauthRedirectUri') },
|
||||
{ key: 'homepage_url', label: t('admin.wecom.copyFields.homepageUrl') },
|
||||
{ key: 'trusted_domain', label: t('admin.wecom.copyFields.trustedDomain') },
|
||||
{ key: 'authorize_api', label: t('admin.wecom.copyFields.authorizeApi') },
|
||||
{ key: 'login_api', label: t('admin.wecom.copyFields.loginApi') },
|
||||
]" :key="item.key">
|
||||
<label class="mb-1.5 block text-xs text-muted">{{ item.label }}</label>
|
||||
<div class="flex gap-2">
|
||||
<input :value="(wecomIntegrationManifest as any)[item.key] || ''" readonly class="input-field flex-1 bg-surface-soft font-mono text-xs" />
|
||||
<button class="btn-secondary px-3" @click="copyText(String((wecomIntegrationManifest as any)[item.key] || ''))">{{ t('admin.wecom.copy') }}</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="admin-table-section">
|
||||
<div class="admin-table-header px-5 py-4">
|
||||
<h3 class="font-semibold text-primary">{{ t('admin.wecom.bindingList') }}</h3>
|
||||
<label class="inline-flex items-center gap-2 text-sm text-secondary">
|
||||
<input type="checkbox" v-model="wecomBoundOnly" class="w-4 h-4 rounded text-brand-600 border-default" />
|
||||
{{ t('admin.wecom.boundOnly') }}
|
||||
</label>
|
||||
</div>
|
||||
<div class="admin-table-wrap">
|
||||
<table class="admin-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="px-4 py-3 text-xs">{{ t('admin.wecom.headers.user') }}</th>
|
||||
<th class="px-4 py-3 text-xs">{{ t('admin.wecom.headers.roleStatus') }}</th>
|
||||
<th class="px-4 py-3 text-xs">{{ t('admin.wecom.headers.wecomUserId') }}</th>
|
||||
<th class="px-4 py-3 text-xs">{{ t('admin.wecom.headers.unionId') }}</th>
|
||||
<th class="px-4 py-3 text-xs text-right">{{ t('admin.wecom.headers.actions') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-if="wecomBindings.length === 0">
|
||||
<td colspan="5" class="px-4 admin-table-empty">{{ t('admin.wecom.noData') }}</td>
|
||||
</tr>
|
||||
<tr v-for="u in wecomBindings" :key="u.id">
|
||||
<td class="px-4 py-3">
|
||||
<div class="text-sm font-medium text-primary">{{ u.username }} <span class="text-muted">(#{{ u.id }})</span></div>
|
||||
<div class="text-xs text-muted">{{ u.real_name || '-' }} · {{ u.email }}</div>
|
||||
</td>
|
||||
<td class="px-4 py-3 text-sm text-secondary">{{ t('admin.role.' + u.role) }} / {{ t('admin.status.' + u.status) }}</td>
|
||||
<td class="px-4 py-3 text-sm text-secondary font-mono">{{ u.wecom_userid || '-' }}</td>
|
||||
<td class="px-4 py-3 text-sm text-secondary font-mono">{{ u.wecom_unionid || '-' }}</td>
|
||||
<td class="px-4 py-3 text-right">
|
||||
<button
|
||||
v-if="u.wecom_userid"
|
||||
@click="unbindWecomUserByAdmin(u.id)"
|
||||
class="inline-flex items-center gap-1 px-3 py-1.5 text-xs text-red-600 bg-red-50 rounded-lg hover:bg-red-100"
|
||||
>
|
||||
<Unlink2 class="w-3.5 h-3.5" />
|
||||
{{ t('admin.wecom.unbind') }}
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="admin-table-section">
|
||||
<div class="admin-table-header admin-table-header--stacked px-5 py-4">
|
||||
<h3 class="font-semibold text-primary">{{ t('admin.wecom.auditTitle') }}</h3>
|
||||
<div class="flex w-full md:w-auto flex-wrap md:flex-nowrap items-center justify-start md:justify-end gap-2">
|
||||
<select v-model="wecomAuditSourceFilter" class="admin-table-filter-input h-11 min-w-[112px] shrink-0">
|
||||
<option value="all">{{ t('admin.wecom.filters.allSources') }}</option>
|
||||
<option value="wecom">{{ t('admin.wecom.sources.wecom') }}</option>
|
||||
<option value="password">{{ t('admin.wecom.sources.password') }}</option>
|
||||
</select>
|
||||
<select v-model="wecomAuditStatusFilter" class="admin-table-filter-input h-11 min-w-[112px] shrink-0">
|
||||
<option value="all">{{ t('admin.wecom.filters.allStatus') }}</option>
|
||||
<option value="success">{{ t('admin.wecom.auditStatus.success') }}</option>
|
||||
<option value="failed">{{ t('admin.wecom.auditStatus.failed') }}</option>
|
||||
</select>
|
||||
<button
|
||||
@click="exportWecomAudits"
|
||||
class="btn-secondary h-11 shrink-0 text-sm"
|
||||
>
|
||||
<Download class="w-4 h-4" />
|
||||
{{ t('admin.wecom.exportAudit') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="admin-table-wrap max-h-[420px]">
|
||||
<table class="admin-table">
|
||||
<thead class="sticky top-0 z-10 admin-table-sticky-head">
|
||||
<tr>
|
||||
<th class="px-4 py-3 text-xs">{{ t('admin.wecom.auditHeaders.time') }}</th>
|
||||
<th class="px-4 py-3 text-xs">{{ t('admin.wecom.auditHeaders.source') }}</th>
|
||||
<th class="px-4 py-3 text-xs">{{ t('admin.wecom.auditHeaders.user') }}</th>
|
||||
<th class="px-4 py-3 text-xs">{{ t('admin.wecom.auditHeaders.status') }}</th>
|
||||
<th class="px-4 py-3 text-xs">{{ t('admin.wecom.auditHeaders.reason') }}</th>
|
||||
<th class="px-4 py-3 text-xs">{{ t('admin.wecom.auditHeaders.ip') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-if="filteredWecomLoginAudits.length === 0">
|
||||
<td colspan="6" class="px-4 admin-table-empty">{{ t('admin.wecom.noAuditData') }}</td>
|
||||
</tr>
|
||||
<tr v-for="row in filteredWecomLoginAudits" :key="row.id">
|
||||
<td class="px-4 py-3 text-xs text-muted whitespace-nowrap">{{ row.created_at || '-' }}</td>
|
||||
<td class="px-4 py-3 text-xs text-secondary">{{ t('admin.wecom.sources.' + row.source) }}</td>
|
||||
<td class="px-4 py-3 text-xs text-secondary">{{ row.username || '-' }}</td>
|
||||
<td class="px-4 py-3">
|
||||
<span class="inline-flex px-2 py-0.5 rounded-full text-[11px] font-medium" :class="row.status === 'success' ? 'bg-green-50 text-green-700' : 'bg-red-50 text-red-700'">
|
||||
{{ t('admin.wecom.auditStatus.' + row.status) }}
|
||||
</span>
|
||||
</td>
|
||||
<td class="px-4 py-3 text-xs text-muted max-w-[360px] align-top">
|
||||
<div class="max-w-[360px] whitespace-normal break-words">
|
||||
<div class="text-xs text-secondary leading-5">{{ getWecomAuditReasonText(row) }}</div>
|
||||
<div v-if="getWecomAuditMetaText(row)" class="mt-1 text-[11px] text-muted leading-5" :title="getWecomAuditMetaText(row)">
|
||||
{{ getWecomAuditMetaText(row) }}
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td class="px-4 py-3 text-xs text-muted font-mono">{{ row.ip || '-' }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
|
||||
<DeleteConfirmDialog
|
||||
v-model="showDeleteConfirmDialog"
|
||||
:message="deleteConfirmMessage"
|
||||
@confirm="confirmDelete"
|
||||
/>
|
||||
</template>
|
||||
@@ -0,0 +1,63 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* features/admin/modules/wecom/components/WecomOverviewCards.vue
|
||||
* 企微 userid 绑定概览统计卡片。
|
||||
*/
|
||||
import { onMounted, ref, watch } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { getAdminWecomBindingStats } from '@/features/admin/api/admin.api';
|
||||
import type { WecomBindingStats } from '@/features/admin/types/wecom.types';
|
||||
|
||||
const props = defineProps<{
|
||||
refreshKey?: number;
|
||||
}>();
|
||||
|
||||
const { t } = useI18n();
|
||||
const stats = ref<WecomBindingStats | null>(null);
|
||||
|
||||
/**
|
||||
* 拉取绑定统计,供设置页概览卡片展示。
|
||||
*/
|
||||
const loadStats = async (): Promise<void> => {
|
||||
try {
|
||||
stats.value = await getAdminWecomBindingStats();
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
stats.value = null;
|
||||
}
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
void loadStats();
|
||||
});
|
||||
|
||||
watch(
|
||||
() => props.refreshKey,
|
||||
() => {
|
||||
void loadStats();
|
||||
},
|
||||
);
|
||||
|
||||
defineExpose({ reload: loadStats });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div v-if="stats" class="grid grid-cols-2 xl:grid-cols-4 gap-3">
|
||||
<div class="rounded-xl bg-surface-soft px-4 py-3">
|
||||
<div class="text-xs text-muted">{{ t('admin.wecom.overview.bound') }}</div>
|
||||
<div class="mt-1 text-xl font-semibold text-primary">{{ stats.bound }} / {{ stats.total_active }}</div>
|
||||
</div>
|
||||
<div class="rounded-xl bg-surface-soft px-4 py-3">
|
||||
<div class="text-xs text-muted">{{ t('admin.wecom.overview.unbound') }}</div>
|
||||
<div class="mt-1 text-xl font-semibold text-amber-700">{{ stats.unbound }}</div>
|
||||
</div>
|
||||
<div class="rounded-xl bg-surface-soft px-4 py-3">
|
||||
<div class="text-xs text-muted">{{ t('admin.wecom.overview.boundRate') }}</div>
|
||||
<div class="mt-1 text-xl font-semibold text-emerald-700">{{ stats.bound_rate }}%</div>
|
||||
</div>
|
||||
<div class="rounded-xl bg-surface-soft px-4 py-3">
|
||||
<div class="text-xs text-muted">{{ t('admin.wecom.overview.hint') }}</div>
|
||||
<div class="mt-1 text-sm text-secondary leading-5">{{ t('admin.wecom.overview.hintDesc') }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,33 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* features/admin/modules/wecom/components/WecomSubNav.vue
|
||||
* 企微管理二级 Tab 导航。
|
||||
*/
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { useRoute } from 'vue-router';
|
||||
|
||||
const { t } = useI18n();
|
||||
const route = useRoute();
|
||||
|
||||
const tabs = [
|
||||
{ name: 'AdminWecomSettings', labelKey: 'admin.wecom.nav.settings' },
|
||||
{ name: 'AdminWecomBindings', labelKey: 'admin.wecom.nav.bindings' },
|
||||
{ name: 'AdminWecomAudits', labelKey: 'admin.wecom.nav.audits' },
|
||||
] as const;
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex flex-wrap gap-2 border-b border-subtle pb-3">
|
||||
<router-link
|
||||
v-for="tab in tabs"
|
||||
:key="tab.name"
|
||||
:to="{ name: tab.name }"
|
||||
class="rounded-xl px-4 py-2 text-sm font-medium transition-colors"
|
||||
:class="route.name === tab.name
|
||||
? 'bg-brand-50 text-brand-700 ring-1 ring-brand-200'
|
||||
: 'text-secondary hover:bg-surface-soft hover:text-primary'"
|
||||
>
|
||||
{{ t(tab.labelKey) }}
|
||||
</router-link>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,144 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* features/admin/modules/wecom/components/WecomSyncPanel.vue
|
||||
* 企微通讯录 userid 一键同步面板(预览 + 确认写入)。
|
||||
*/
|
||||
import { inject } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { RefreshCw } from 'lucide-vue-next';
|
||||
import DeleteConfirmDialog from '@/shared/components/DeleteConfirmDialog.vue';
|
||||
import { WECOM_ADMIN_KEY } from '../wecom.context';
|
||||
import { useWecomSync } from '../composables/useWecomSync';
|
||||
|
||||
const emit = defineEmits<{
|
||||
applied: [];
|
||||
}>();
|
||||
|
||||
const { t } = useI18n();
|
||||
const { wecomSystemSettings, refreshWecomData } = inject(WECOM_ADMIN_KEY)!;
|
||||
|
||||
const {
|
||||
departmentId,
|
||||
isSyncing,
|
||||
previewSummary,
|
||||
showApplyConfirm,
|
||||
previewSync,
|
||||
requestApplySync,
|
||||
confirmApplySync,
|
||||
} = useWecomSync({
|
||||
onApplied: async () => {
|
||||
await refreshWecomData();
|
||||
emit('applied');
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="card shadow-sm p-5 space-y-4">
|
||||
<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>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-3">
|
||||
<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>
|
||||
<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>
|
||||
</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>
|
||||
|
||||
<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>
|
||||
<div>
|
||||
<div class="text-xs text-muted">{{ t('admin.wecom.sync.stats.localMatched') }}</div>
|
||||
<div class="font-semibold text-primary">{{ previewSummary.local_matched }}</div>
|
||||
</div>
|
||||
<div>
|
||||
<div class="text-xs text-muted">{{ t('admin.wecom.sync.stats.wouldUpdate') }}</div>
|
||||
<div class="font-semibold text-brand-700">{{ previewSummary.would_update }}</div>
|
||||
</div>
|
||||
<div>
|
||||
<div class="text-xs text-muted">{{ t('admin.wecom.sync.stats.conflicts') }}</div>
|
||||
<div class="font-semibold" :class="previewSummary.conflicts?.length ? 'text-red-600' : 'text-emerald-700'">
|
||||
{{ previewSummary.conflicts?.length || 0 }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="previewSummary.pending_updates?.length" class="overflow-x-auto">
|
||||
<table class="admin-table min-w-full">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="px-3 py-2 text-xs">{{ t('admin.wecom.headers.employeeId') }}</th>
|
||||
<th class="px-3 py-2 text-xs">{{ t('admin.wecom.headers.user') }}</th>
|
||||
<th class="px-3 py-2 text-xs">{{ t('admin.wecom.headers.wecomUserId') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<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 font-mono">{{ row.wecom_userid }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<p v-if="previewSummary.would_update > previewSummary.pending_updates.length" class="mt-2 text-xs text-muted">
|
||||
{{ t('admin.wecom.sync.previewTruncated', { total: previewSummary.would_update }) }}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div v-if="previewSummary.conflicts?.length" class="space-y-2">
|
||||
<div class="text-xs font-medium text-red-700">{{ t('admin.wecom.sync.conflictsTitle') }}</div>
|
||||
<div
|
||||
v-for="(conflict, idx) in previewSummary.conflicts"
|
||||
:key="idx"
|
||||
class="rounded-lg border border-red-100 bg-red-50 px-3 py-2 text-xs text-red-800"
|
||||
>
|
||||
{{ conflict.employee_id }} / {{ conflict.username }}
|
||||
<span v-if="conflict.old_wecom_userid"> · {{ conflict.old_wecom_userid }} → {{ conflict.new_wecom_userid }}</span>
|
||||
<span v-else-if="conflict.occupied_by_username"> · {{ t('admin.wecom.sync.occupiedBy', { user: conflict.occupied_by_username }) }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<DeleteConfirmDialog
|
||||
v-model="showApplyConfirm"
|
||||
:message="t('admin.wecom.sync.applyConfirm', { count: previewSummary?.would_update || 0 })"
|
||||
@confirm="confirmApplySync"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
@@ -40,6 +40,13 @@ export function useWecomAdmin() {
|
||||
const isSaving = ref(false);
|
||||
|
||||
const wecomBindings = ref<WecomBindingRow[]>([]);
|
||||
const wecomBindingsKeyword = ref('');
|
||||
const wecomBindingsPage = ref(1);
|
||||
const wecomBindingsPageSize = ref(20);
|
||||
const wecomBindingsTotal = ref(0);
|
||||
const wecomBindingsPages = ref(1);
|
||||
const wecomBindingsPageSizeOptions = [10, 20, 50, 100] as const;
|
||||
let wecomBindingsSearchTimer: ReturnType<typeof setTimeout> | null = null;
|
||||
const wecomLoginAudits = ref<WecomLoginAuditRow[]>([]);
|
||||
const wecomBindForm = ref({
|
||||
user_id: '' as string | number,
|
||||
@@ -112,14 +119,44 @@ export function useWecomAdmin() {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 拉取绑定列表(服务端分页 + keyword 搜索)。
|
||||
* 核心逻辑:调用 listAdminWecomBindings,写回 items 与分页元数据。
|
||||
*/
|
||||
const loadWecomBindings = async (): Promise<void> => {
|
||||
try {
|
||||
wecomBindings.value = await listAdminWecomBindings(wecomBoundOnly.value);
|
||||
const data = await listAdminWecomBindings({
|
||||
boundOnly: wecomBoundOnly.value,
|
||||
keyword: wecomBindingsKeyword.value,
|
||||
page: wecomBindingsPage.value,
|
||||
pageSize: wecomBindingsPageSize.value,
|
||||
});
|
||||
wecomBindings.value = data.items;
|
||||
wecomBindingsTotal.value = data.total;
|
||||
wecomBindingsPage.value = data.page;
|
||||
wecomBindingsPages.value = data.pages;
|
||||
} catch (e) {
|
||||
console.error('Error loading WeCom bindings:', e);
|
||||
wecomBindings.value = [];
|
||||
wecomBindingsTotal.value = 0;
|
||||
wecomBindingsPages.value = 1;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 重置页码并刷新绑定列表;若页码已是 1 则直接请求。
|
||||
* @param resetPage - 为 true 时将 page 置 1
|
||||
*/
|
||||
const scheduleLoadWecomBindings = (resetPage = false): void => {
|
||||
if (resetPage) {
|
||||
if (wecomBindingsPage.value !== 1) {
|
||||
wecomBindingsPage.value = 1;
|
||||
return;
|
||||
}
|
||||
}
|
||||
void loadWecomBindings();
|
||||
};
|
||||
|
||||
const loadWecomAudits = async (): Promise<void> => {
|
||||
try {
|
||||
const params = new URLSearchParams({ limit: '200' });
|
||||
@@ -409,9 +446,24 @@ export function useWecomAdmin() {
|
||||
};
|
||||
|
||||
watch(wecomBoundOnly, () => {
|
||||
scheduleLoadWecomBindings(true);
|
||||
});
|
||||
|
||||
watch(wecomBindingsPage, () => {
|
||||
void loadWecomBindings();
|
||||
});
|
||||
|
||||
watch(wecomBindingsPageSize, () => {
|
||||
scheduleLoadWecomBindings(true);
|
||||
});
|
||||
|
||||
watch(wecomBindingsKeyword, () => {
|
||||
if (wecomBindingsSearchTimer) clearTimeout(wecomBindingsSearchTimer);
|
||||
wecomBindingsSearchTimer = setTimeout(() => {
|
||||
scheduleLoadWecomBindings(true);
|
||||
}, 300);
|
||||
});
|
||||
|
||||
watch([wecomAuditSourceFilter, wecomAuditStatusFilter], () => {
|
||||
void loadWecomAudits();
|
||||
});
|
||||
@@ -420,6 +472,12 @@ export function useWecomAdmin() {
|
||||
isLoading,
|
||||
isSaving,
|
||||
wecomBindings,
|
||||
wecomBindingsKeyword,
|
||||
wecomBindingsPage,
|
||||
wecomBindingsPageSize,
|
||||
wecomBindingsTotal,
|
||||
wecomBindingsPages,
|
||||
wecomBindingsPageSizeOptions,
|
||||
wecomLoginAudits,
|
||||
wecomBindForm,
|
||||
wecomBindUserQuery,
|
||||
|
||||
@@ -0,0 +1,107 @@
|
||||
/**
|
||||
* features/admin/modules/wecom/composables/useWecomSync.ts
|
||||
* 企微通讯录 userid 同步:预览 dry-run 与确认写入。
|
||||
*/
|
||||
import { 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 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);
|
||||
|
||||
/**
|
||||
* 解析可选部门 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;
|
||||
};
|
||||
|
||||
/**
|
||||
* 预览同步结果(dry-run,不写库)。
|
||||
*/
|
||||
const previewSync = async (): Promise<void> => {
|
||||
const deptId = parseDepartmentId();
|
||||
if (deptId === false) {
|
||||
msg.warning(t('admin.wecom.sync.invalidDepartmentId'));
|
||||
return;
|
||||
}
|
||||
isSyncing.value = true;
|
||||
try {
|
||||
previewSummary.value = await syncAdminWecomUserids({ apply: false, department_id: deptId });
|
||||
msg.success(t('admin.wecom.sync.previewDone'));
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
msg.error((e as Error).message || t('admin.wecom.sync.previewFailed'));
|
||||
} finally {
|
||||
isSyncing.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 打开确认写入对话框;需先预览且无冲突。
|
||||
*/
|
||||
const requestApplySync = (): void => {
|
||||
if (!previewSummary.value) {
|
||||
msg.warning(t('admin.wecom.sync.previewFirst'));
|
||||
return;
|
||||
}
|
||||
if ((previewSummary.value.conflicts || []).length > 0) {
|
||||
msg.warning(t('admin.wecom.sync.conflictsBlockApply'));
|
||||
return;
|
||||
}
|
||||
if ((previewSummary.value.would_update || 0) <= 0) {
|
||||
msg.info(t('admin.wecom.sync.nothingToUpdate'));
|
||||
return;
|
||||
}
|
||||
showApplyConfirm.value = true;
|
||||
};
|
||||
|
||||
/**
|
||||
* 确认后将预览结果写入数据库。
|
||||
*/
|
||||
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 });
|
||||
previewSummary.value = summary;
|
||||
showApplyConfirm.value = false;
|
||||
msg.success(t('admin.wecom.sync.applyDone', { count: summary.updated || 0 }));
|
||||
await options?.onApplied?.();
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
msg.error((e as Error).message || t('admin.wecom.sync.applyFailed'));
|
||||
} finally {
|
||||
isSyncing.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
departmentId,
|
||||
isSyncing,
|
||||
previewSummary,
|
||||
showApplyConfirm,
|
||||
previewSync,
|
||||
requestApplySync,
|
||||
confirmApplySync,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* features/admin/modules/wecom/pages/WecomAuditsPage.vue
|
||||
* 企微与密码登录审计列表。
|
||||
*/
|
||||
import { inject } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { Download } from 'lucide-vue-next';
|
||||
import { WECOM_ADMIN_KEY } from '../wecom.context';
|
||||
|
||||
const { t } = useI18n();
|
||||
const {
|
||||
wecomAuditSourceFilter,
|
||||
wecomAuditStatusFilter,
|
||||
filteredWecomLoginAudits,
|
||||
exportWecomAudits,
|
||||
getWecomAuditReasonText,
|
||||
getWecomAuditMetaText,
|
||||
} = inject(WECOM_ADMIN_KEY)!;
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="admin-table-section">
|
||||
<div class="admin-table-header admin-table-header--stacked px-5 py-4">
|
||||
<h3 class="font-semibold text-primary">{{ t('admin.wecom.auditTitle') }}</h3>
|
||||
<div class="flex w-full md:w-auto flex-wrap md:flex-nowrap items-center justify-start md:justify-end gap-2">
|
||||
<select v-model="wecomAuditSourceFilter" class="admin-table-filter-input h-11 min-w-[112px] shrink-0">
|
||||
<option value="all">{{ t('admin.wecom.filters.allSources') }}</option>
|
||||
<option value="wecom">{{ t('admin.wecom.sources.wecom') }}</option>
|
||||
<option value="password">{{ t('admin.wecom.sources.password') }}</option>
|
||||
</select>
|
||||
<select v-model="wecomAuditStatusFilter" class="admin-table-filter-input h-11 min-w-[112px] shrink-0">
|
||||
<option value="all">{{ t('admin.wecom.filters.allStatus') }}</option>
|
||||
<option value="success">{{ t('admin.wecom.auditStatus.success') }}</option>
|
||||
<option value="failed">{{ t('admin.wecom.auditStatus.failed') }}</option>
|
||||
</select>
|
||||
<button type="button" class="btn-secondary h-11 shrink-0 text-sm" @click="exportWecomAudits()">
|
||||
<Download class="w-4 h-4" />
|
||||
{{ t('admin.wecom.exportAudit') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="admin-table-wrap max-h-[560px]">
|
||||
<table class="admin-table">
|
||||
<thead class="sticky top-0 z-10 admin-table-sticky-head">
|
||||
<tr>
|
||||
<th class="px-4 py-3 text-xs">{{ t('admin.wecom.auditHeaders.time') }}</th>
|
||||
<th class="px-4 py-3 text-xs">{{ t('admin.wecom.auditHeaders.source') }}</th>
|
||||
<th class="px-4 py-3 text-xs">{{ t('admin.wecom.auditHeaders.user') }}</th>
|
||||
<th class="px-4 py-3 text-xs">{{ t('admin.wecom.auditHeaders.status') }}</th>
|
||||
<th class="px-4 py-3 text-xs">{{ t('admin.wecom.auditHeaders.reason') }}</th>
|
||||
<th class="px-4 py-3 text-xs">{{ t('admin.wecom.auditHeaders.ip') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-if="filteredWecomLoginAudits.length === 0">
|
||||
<td colspan="6" class="px-4 admin-table-empty">{{ t('admin.wecom.noAuditData') }}</td>
|
||||
</tr>
|
||||
<tr v-for="row in filteredWecomLoginAudits" :key="row.id">
|
||||
<td class="px-4 py-3 text-xs text-muted whitespace-nowrap">{{ row.created_at || '-' }}</td>
|
||||
<td class="px-4 py-3 text-xs text-secondary">{{ t('admin.wecom.sources.' + row.source) }}</td>
|
||||
<td class="px-4 py-3 text-xs text-secondary">{{ row.username || '-' }}</td>
|
||||
<td class="px-4 py-3">
|
||||
<span
|
||||
class="inline-flex px-2 py-0.5 rounded-full text-[11px] font-medium"
|
||||
:class="row.status === 'success' ? 'bg-green-50 text-green-700' : 'bg-red-50 text-red-700'"
|
||||
>
|
||||
{{ t('admin.wecom.auditStatus.' + row.status) }}
|
||||
</span>
|
||||
</td>
|
||||
<td class="px-4 py-3 text-xs text-muted max-w-[360px] align-top">
|
||||
<div class="max-w-[360px] whitespace-normal break-words">
|
||||
<div class="text-xs text-secondary leading-5">{{ getWecomAuditReasonText(row) }}</div>
|
||||
<div v-if="getWecomAuditMetaText(row)" class="mt-1 text-[11px] text-muted leading-5" :title="getWecomAuditMetaText(row)">
|
||||
{{ getWecomAuditMetaText(row) }}
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td class="px-4 py-3 text-xs text-muted font-mono">{{ row.ip || '-' }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,300 @@
|
||||
<script setup lang="ts">
|
||||
|
||||
/**
|
||||
|
||||
* features/admin/modules/wecom/pages/WecomBindingsPage.vue
|
||||
|
||||
* 企微快速绑定与绑定列表(搜索 + 服务端分页)。
|
||||
|
||||
* 依赖:WECOM_ADMIN_KEY、PaginationBar、lucide-vue-next。
|
||||
|
||||
* 逻辑:inject 父级 useWecomAdmin 状态;列表区复用 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 { WECOM_ADMIN_KEY } from '../wecom.context';
|
||||
|
||||
|
||||
|
||||
const { t } = useI18n();
|
||||
|
||||
const {
|
||||
|
||||
wecomBindUserQuery,
|
||||
|
||||
wecomBindUserDropdownOpen,
|
||||
|
||||
wecomBindUserOptions,
|
||||
|
||||
wecomBindForm,
|
||||
|
||||
isSaving,
|
||||
|
||||
wecomBoundOnly,
|
||||
|
||||
wecomBindings,
|
||||
|
||||
wecomBindingsKeyword,
|
||||
|
||||
wecomBindingsPage,
|
||||
|
||||
wecomBindingsPageSize,
|
||||
|
||||
wecomBindingsTotal,
|
||||
|
||||
wecomBindingsPages,
|
||||
|
||||
wecomBindingsPageSizeOptions,
|
||||
|
||||
selectWecomBindUser,
|
||||
|
||||
scheduleCloseWecomBindUserDropdown,
|
||||
|
||||
bindWecomUser,
|
||||
|
||||
unbindWecomUserByAdmin,
|
||||
|
||||
} = inject(WECOM_ADMIN_KEY)!;
|
||||
|
||||
</script>
|
||||
|
||||
|
||||
|
||||
<template>
|
||||
|
||||
<div class="space-y-6">
|
||||
|
||||
<p class="text-sm text-muted">{{ t('admin.wecom.bindingsHint') }}</p>
|
||||
|
||||
|
||||
|
||||
<div class="card shadow-sm p-5 space-y-4">
|
||||
|
||||
<h3 class="font-semibold text-primary">{{ t('admin.wecom.quickBind') }}</h3>
|
||||
|
||||
<div class="grid grid-cols-1 md:grid-cols-4 gap-3">
|
||||
|
||||
<div class="relative md:col-span-1">
|
||||
|
||||
<input
|
||||
|
||||
v-model="wecomBindUserQuery"
|
||||
|
||||
type="text"
|
||||
|
||||
class="input-field"
|
||||
|
||||
:placeholder="t('admin.wecom.fields.userSelect')"
|
||||
|
||||
@focus="wecomBindUserDropdownOpen = true"
|
||||
|
||||
@input="wecomBindUserDropdownOpen = true"
|
||||
|
||||
@blur="scheduleCloseWecomBindUserDropdown()"
|
||||
|
||||
/>
|
||||
|
||||
<div v-if="wecomBindUserDropdownOpen" class="admin-dropdown w-72">
|
||||
|
||||
<button
|
||||
|
||||
v-for="u in wecomBindUserOptions"
|
||||
|
||||
:key="u.id"
|
||||
|
||||
type="button"
|
||||
|
||||
class="flex w-full items-center justify-between gap-3 px-3 py-2 text-left hover:bg-blue-50"
|
||||
|
||||
@mousedown.prevent="selectWecomBindUser(u.id, u.label)"
|
||||
|
||||
>
|
||||
|
||||
<span class="text-sm text-primary">{{ u.label }}</span>
|
||||
|
||||
<span class="text-xs text-muted">{{ u.employeeId || '' }}</span>
|
||||
|
||||
</button>
|
||||
|
||||
<div v-if="wecomBindUserOptions.length === 0" class="px-3 py-2 text-sm text-muted">
|
||||
|
||||
{{ t('admin.wecom.noData') }}
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<input v-model="wecomBindForm.wecom_userid" :placeholder="t('admin.wecom.fields.wecomUserId')" class="input-field md:col-span-2" />
|
||||
|
||||
<input v-model="wecomBindForm.wecom_unionid" :placeholder="t('admin.wecom.fields.wecomUnionId')" class="input-field" />
|
||||
|
||||
</div>
|
||||
|
||||
<div class="flex justify-end">
|
||||
|
||||
<button type="button" :disabled="isSaving" class="btn-primary px-5 py-2 disabled:opacity-60" @click="bindWecomUser()">
|
||||
|
||||
<Link2 class="w-4 h-4" /> {{ t('admin.wecom.bind') }}
|
||||
|
||||
</button>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<div class="admin-table-section space-y-0">
|
||||
|
||||
<div class="admin-table-header px-5 py-4 flex flex-col gap-3 lg:flex-row lg:items-center lg:justify-between">
|
||||
|
||||
<h3 class="font-semibold text-primary">{{ t('admin.wecom.bindingList') }}</h3>
|
||||
|
||||
<div class="flex flex-col gap-3 sm:flex-row sm:items-center">
|
||||
|
||||
<div class="relative min-w-[240px]">
|
||||
|
||||
<Search class="pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted" />
|
||||
|
||||
<input
|
||||
|
||||
v-model="wecomBindingsKeyword"
|
||||
|
||||
type="search"
|
||||
|
||||
class="input-field pl-9"
|
||||
|
||||
:placeholder="t('admin.wecom.searchBindings')"
|
||||
|
||||
/>
|
||||
|
||||
</div>
|
||||
|
||||
<label class="inline-flex items-center gap-2 text-sm text-secondary whitespace-nowrap">
|
||||
|
||||
<input v-model="wecomBoundOnly" type="checkbox" class="w-4 h-4 rounded text-brand-600 border-default" />
|
||||
|
||||
{{ t('admin.wecom.boundOnly') }}
|
||||
|
||||
</label>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="admin-table-wrap">
|
||||
|
||||
<table class="admin-table">
|
||||
|
||||
<thead>
|
||||
|
||||
<tr>
|
||||
|
||||
<th class="px-4 py-3 text-xs">{{ t('admin.wecom.headers.user') }}</th>
|
||||
|
||||
<th class="px-4 py-3 text-xs">{{ t('admin.wecom.headers.employeeId') }}</th>
|
||||
|
||||
<th class="px-4 py-3 text-xs">{{ t('admin.wecom.headers.roleStatus') }}</th>
|
||||
|
||||
<th class="px-4 py-3 text-xs">{{ t('admin.wecom.headers.wecomUserId') }}</th>
|
||||
|
||||
<th class="px-4 py-3 text-xs">{{ t('admin.wecom.headers.unionId') }}</th>
|
||||
|
||||
<th class="px-4 py-3 text-xs text-right">{{ t('admin.wecom.headers.actions') }}</th>
|
||||
|
||||
</tr>
|
||||
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
|
||||
<tr v-if="wecomBindings.length === 0">
|
||||
|
||||
<td colspan="6" class="px-4 admin-table-empty">{{ t('admin.wecom.noData') }}</td>
|
||||
|
||||
</tr>
|
||||
|
||||
<tr v-for="u in wecomBindings" :key="u.id">
|
||||
|
||||
<td class="px-4 py-3">
|
||||
|
||||
<div class="text-sm font-medium text-primary">{{ u.username }} <span class="text-muted">(#{{ u.id }})</span></div>
|
||||
|
||||
<div class="text-xs text-muted">{{ u.real_name || '-' }} · {{ u.email }}</div>
|
||||
|
||||
</td>
|
||||
|
||||
<td class="px-4 py-3 text-sm text-secondary font-mono">{{ u.employee_id || '-' }}</td>
|
||||
|
||||
<td class="px-4 py-3 text-sm text-secondary">{{ t('admin.role.' + u.role) }} / {{ t('admin.status.' + u.status) }}</td>
|
||||
|
||||
<td class="px-4 py-3 text-sm text-secondary font-mono">{{ u.wecom_userid || '-' }}</td>
|
||||
|
||||
<td class="px-4 py-3 text-sm text-secondary font-mono">{{ u.wecom_unionid || '-' }}</td>
|
||||
|
||||
<td class="px-4 py-3 text-right">
|
||||
|
||||
<button
|
||||
|
||||
v-if="u.wecom_userid"
|
||||
|
||||
type="button"
|
||||
|
||||
class="inline-flex items-center gap-1 px-3 py-1.5 text-xs text-red-600 bg-red-50 rounded-lg hover:bg-red-100"
|
||||
|
||||
@click="unbindWecomUserByAdmin(u.id)"
|
||||
|
||||
>
|
||||
|
||||
<Unlink2 class="w-3.5 h-3.5" />
|
||||
|
||||
{{ t('admin.wecom.unbind') }}
|
||||
|
||||
</button>
|
||||
|
||||
</td>
|
||||
|
||||
</tr>
|
||||
|
||||
</tbody>
|
||||
|
||||
</table>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="px-4 pb-4 pt-2">
|
||||
|
||||
<PaginationBar
|
||||
|
||||
v-model:page="wecomBindingsPage"
|
||||
|
||||
v-model:page-size="wecomBindingsPageSize"
|
||||
|
||||
:total="wecomBindingsTotal"
|
||||
|
||||
:pages="wecomBindingsPages"
|
||||
|
||||
:page-size-options="[...wecomBindingsPageSizeOptions]"
|
||||
|
||||
:visible="wecomBindingsTotal > 0 || !!wecomBindingsKeyword.trim()"
|
||||
|
||||
/>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</template>
|
||||
|
||||
@@ -0,0 +1,268 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* features/admin/modules/wecom/pages/WecomSettingsPage.vue
|
||||
* 企微系统配置、通讯录同步、通知与集成复制。
|
||||
*/
|
||||
import { inject, ref } 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();
|
||||
const {
|
||||
wecomSystemSettings,
|
||||
isSaving,
|
||||
wecomNotifySettings,
|
||||
wecomNotifyEventsText,
|
||||
wecomNotifyMetrics,
|
||||
wecomIntegrationManifest,
|
||||
generateWecomAddressesFromPublicBase,
|
||||
generateWecomCallbackToken,
|
||||
generateWecomEncodingAesKey,
|
||||
saveWecomSystemSettings,
|
||||
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" />
|
||||
|
||||
<div class="card shadow-sm p-5 space-y-4">
|
||||
<h3 class="font-semibold text-primary">{{ t('admin.wecom.systemSettings') }}</h3>
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-3">
|
||||
<label class="inline-flex items-center gap-2 text-sm text-secondary">
|
||||
<input v-model="wecomSystemSettings.enabled" type="checkbox" class="admin-checkbox" />
|
||||
{{ t('admin.wecom.fields.enabled') }}
|
||||
<CircleHelp class="w-3.5 h-3.5 text-muted" :title="t('admin.wecom.tips.enabled')" />
|
||||
</label>
|
||||
<label class="inline-flex items-center gap-2 text-sm text-secondary">
|
||||
<input v-model="wecomSystemSettings.auto_create_user" type="checkbox" class="admin-checkbox" />
|
||||
{{ t('admin.wecom.fields.autoCreateUser') }}
|
||||
<CircleHelp class="w-3.5 h-3.5 text-muted" :title="t('admin.wecom.tips.autoCreateUser')" />
|
||||
</label>
|
||||
</div>
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-3">
|
||||
<div>
|
||||
<label class="mb-1.5 inline-flex items-center gap-1 text-xs text-muted">
|
||||
{{ t('admin.wecom.fields.corpId') }}
|
||||
<CircleHelp class="w-3.5 h-3.5 text-muted" :title="t('admin.wecom.tips.corpId')" />
|
||||
</label>
|
||||
<input v-model="wecomSystemSettings.corp_id" class="input-field" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="mb-1.5 inline-flex items-center gap-1 text-xs text-muted">
|
||||
{{ t('admin.wecom.fields.agentId') }}
|
||||
<CircleHelp class="w-3.5 h-3.5 text-muted" :title="t('admin.wecom.tips.agentId')" />
|
||||
</label>
|
||||
<input v-model="wecomSystemSettings.agent_id" class="input-field" />
|
||||
</div>
|
||||
<div class="md:col-span-2">
|
||||
<label class="mb-1.5 inline-flex items-center gap-1 text-xs text-muted">
|
||||
{{ t('admin.wecom.fields.secret') }}
|
||||
<CircleHelp class="w-3.5 h-3.5 text-muted" :title="t('admin.wecom.tips.secret')" />
|
||||
</label>
|
||||
<input v-model="wecomSystemSettings.secret" type="password" class="input-field" />
|
||||
</div>
|
||||
<div class="md:col-span-2">
|
||||
<label class="mb-1.5 inline-flex items-center gap-1 text-xs text-muted">
|
||||
{{ t('admin.wecom.fields.redirectUri') }}
|
||||
<CircleHelp class="w-3.5 h-3.5 text-muted" :title="t('admin.wecom.tips.redirectUri')" />
|
||||
</label>
|
||||
<input v-model="wecomSystemSettings.redirect_uri" class="input-field" />
|
||||
</div>
|
||||
<div class="md:col-span-2">
|
||||
<label class="mb-1.5 inline-flex items-center gap-1 text-xs text-muted">
|
||||
{{ t('admin.wecom.fields.publicBaseUrl') }}
|
||||
<CircleHelp class="w-3.5 h-3.5 text-muted" :title="t('admin.wecom.tips.publicBaseUrl')" />
|
||||
</label>
|
||||
<div class="flex flex-wrap gap-2">
|
||||
<input
|
||||
v-model="wecomSystemSettings.public_base_url"
|
||||
:placeholder="t('admin.wecom.publicBasePlaceholder')"
|
||||
class="input-field flex-1 min-w-[200px]"
|
||||
/>
|
||||
<button type="button" class="btn-secondary px-4 shrink-0" @click="generateWecomAddressesFromPublicBase()">
|
||||
{{ t('admin.wecom.generateAddresses') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<label class="mb-1.5 inline-flex items-center gap-1 text-xs text-muted">
|
||||
{{ t('admin.wecom.fields.callbackToken') }}
|
||||
<CircleHelp class="w-3.5 h-3.5 text-muted" :title="t('admin.wecom.tips.callbackToken')" />
|
||||
</label>
|
||||
<div class="flex gap-2">
|
||||
<input v-model="wecomSystemSettings.callback_token" class="input-field flex-1 min-w-0" />
|
||||
<button type="button" class="btn-secondary px-3 shrink-0 text-xs" @click="generateWecomCallbackToken()">
|
||||
{{ t('admin.wecom.generateToken') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<label class="mb-1.5 inline-flex items-center gap-1 text-xs text-muted">
|
||||
{{ t('admin.wecom.fields.encodingAesKey') }}
|
||||
<CircleHelp class="w-3.5 h-3.5 text-muted" :title="t('admin.wecom.tips.encodingAesKey')" />
|
||||
</label>
|
||||
<div class="flex gap-2">
|
||||
<input v-model="wecomSystemSettings.encoding_aes_key" class="input-field flex-1 min-w-0 font-mono text-xs" />
|
||||
<button type="button" class="btn-secondary px-3 shrink-0 text-xs" @click="generateWecomEncodingAesKey()">
|
||||
{{ t('admin.wecom.generateEncodingKey') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<label class="mb-1.5 inline-flex items-center gap-1 text-xs text-muted">
|
||||
{{ t('admin.wecom.fields.callbackUrl') }}
|
||||
<CircleHelp class="w-3.5 h-3.5 text-muted" :title="t('admin.wecom.tips.callbackUrl')" />
|
||||
</label>
|
||||
<input v-model="wecomSystemSettings.callback_url" class="input-field" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="mb-1.5 inline-flex items-center gap-1 text-xs text-muted">
|
||||
{{ t('admin.wecom.fields.homepageUrl') }}
|
||||
<CircleHelp class="w-3.5 h-3.5 text-muted" :title="t('admin.wecom.tips.homepageUrl')" />
|
||||
</label>
|
||||
<input v-model="wecomSystemSettings.homepage_url" class="input-field" />
|
||||
</div>
|
||||
<div class="md:col-span-2">
|
||||
<label class="mb-1.5 inline-flex items-center gap-1 text-xs text-muted">
|
||||
{{ t('admin.wecom.fields.trustedDomain') }}
|
||||
<CircleHelp class="w-3.5 h-3.5 text-muted" :title="t('admin.wecom.tips.trustedDomain')" />
|
||||
</label>
|
||||
<input v-model="wecomSystemSettings.trusted_domain" class="input-field" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="mb-1.5 inline-flex items-center gap-1 text-xs text-muted">
|
||||
{{ t('admin.wecom.fields.matchRules') }}
|
||||
<CircleHelp class="w-3.5 h-3.5 text-muted" :title="t('admin.wecom.tips.matchRules')" />
|
||||
</label>
|
||||
<input v-model="wecomSystemSettings.match_rules" class="input-field" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="mb-1.5 inline-flex items-center gap-1 text-xs text-muted">
|
||||
{{ t('admin.wecom.fields.matchOperator') }}
|
||||
<CircleHelp class="w-3.5 h-3.5 text-muted" :title="t('admin.wecom.tips.matchOperator')" />
|
||||
</label>
|
||||
<select v-model="wecomSystemSettings.match_operator" class="input-field">
|
||||
<option value="AND">AND</option>
|
||||
<option value="OR">OR</option>
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label class="mb-1.5 inline-flex items-center gap-1 text-xs text-muted">
|
||||
{{ t('admin.wecom.fields.firstLoginBindMode') }}
|
||||
<CircleHelp class="w-3.5 h-3.5 text-muted" :title="t('admin.wecom.tips.firstLoginBindMode')" />
|
||||
</label>
|
||||
<select v-model="wecomSystemSettings.first_login_bind_mode" class="input-field">
|
||||
<option value="match_rules">{{ t('admin.wecom.bindModes.match_rules') }}</option>
|
||||
<option value="input_verify">{{ t('admin.wecom.bindModes.input_verify') }}</option>
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label class="mb-1.5 inline-flex items-center gap-1 text-xs text-muted">
|
||||
{{ t('admin.wecom.fields.firstLoginInputFields') }}
|
||||
<CircleHelp class="w-3.5 h-3.5 text-muted" :title="t('admin.wecom.tips.firstLoginInputFields')" />
|
||||
</label>
|
||||
<input v-model="wecomSystemSettings.first_login_input_fields" class="input-field" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="mb-1.5 inline-flex items-center gap-1 text-xs text-muted">
|
||||
{{ t('admin.wecom.fields.employeeIdSource') }}
|
||||
<CircleHelp class="w-3.5 h-3.5 text-muted" :title="t('admin.wecom.tips.employeeIdSource')" />
|
||||
</label>
|
||||
<input v-model="wecomSystemSettings.employee_id_source" class="input-field" />
|
||||
</div>
|
||||
<label class="inline-flex items-center gap-2 text-sm text-secondary pt-7">
|
||||
<input v-model="wecomSystemSettings.mobile_normalize" type="checkbox" class="admin-checkbox" />
|
||||
{{ t('admin.wecom.fields.mobileNormalize') }}
|
||||
<CircleHelp class="w-3.5 h-3.5 text-muted" :title="t('admin.wecom.tips.mobileNormalize')" />
|
||||
</label>
|
||||
</div>
|
||||
<div class="flex justify-end">
|
||||
<button type="button" :disabled="isSaving" class="btn-primary px-5 py-2 disabled:opacity-60" @click="saveWecomSystemSettings()">
|
||||
{{ t('admin.save') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-1 xl:grid-cols-2 gap-6">
|
||||
<div class="card shadow-sm p-5 space-y-4">
|
||||
<h3 class="font-semibold text-primary">{{ t('admin.wecom.notifySettings') }}</h3>
|
||||
<label class="inline-flex items-center gap-2 text-sm text-secondary">
|
||||
<input v-model="wecomNotifySettings.enabled" type="checkbox" class="admin-checkbox" />
|
||||
{{ t('admin.wecom.notifyEnabled') }}
|
||||
</label>
|
||||
<input v-model="wecomNotifySettings.base_url" :placeholder="t('admin.wecom.notifyBaseUrl')" class="input-field" />
|
||||
<input v-model="wecomNotifyEventsText" :placeholder="t('admin.wecom.notifyEvents')" class="input-field" />
|
||||
<div class="flex justify-end">
|
||||
<button type="button" :disabled="isSaving" class="btn-primary px-5 py-2 disabled:opacity-60" @click="saveWecomNotifySettings()">
|
||||
{{ t('admin.save') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card shadow-sm p-5 space-y-4">
|
||||
<h3 class="font-semibold text-primary">{{ t('admin.wecom.notifyMetrics') }}</h3>
|
||||
<div v-if="wecomNotifyMetrics" class="grid grid-cols-2 gap-3 text-sm">
|
||||
<div class="rounded-lg bg-surface-soft px-3 py-2">
|
||||
<div class="text-muted">{{ t('admin.wecom.metricTotal') }}</div>
|
||||
<div class="text-lg font-semibold text-primary">{{ wecomNotifyMetrics.total }}</div>
|
||||
</div>
|
||||
<div class="rounded-lg bg-surface-soft px-3 py-2">
|
||||
<div class="text-muted">{{ t('admin.wecom.metricSuccessRate') }}</div>
|
||||
<div class="text-lg font-semibold text-emerald-700">{{ wecomNotifyMetrics.send_success_rate }}%</div>
|
||||
</div>
|
||||
<div class="rounded-lg bg-surface-soft px-3 py-2">
|
||||
<div class="text-muted">{{ t('admin.wecom.metricOpenedRate') }}</div>
|
||||
<div class="text-lg font-semibold text-blue-700">{{ wecomNotifyMetrics.opened_24h_rate }}%</div>
|
||||
</div>
|
||||
<div class="rounded-lg bg-surface-soft px-3 py-2">
|
||||
<div class="text-muted">{{ t('admin.wecom.metricWindowDays') }}</div>
|
||||
<div class="text-lg font-semibold text-primary">{{ wecomNotifyMetrics.window_days }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<details class="card shadow-sm p-5">
|
||||
<summary class="cursor-pointer font-semibold text-primary">{{ t('admin.wecom.integrationCopyTitle') }}</summary>
|
||||
<div class="mt-4 space-y-4">
|
||||
<p class="text-xs text-muted">{{ t('admin.wecom.integrationCopyDesc') }}</p>
|
||||
<p class="text-xs text-amber-800 bg-amber-50 border border-amber-100 rounded-lg px-3 py-2">{{ t('admin.wecom.integrationCopySecretsNote') }}</p>
|
||||
<div v-if="wecomIntegrationManifest" class="grid grid-cols-1 gap-3">
|
||||
<div
|
||||
v-for="item in [
|
||||
{ key: 'public_base_url', label: t('admin.wecom.copyFields.publicBaseUrl') },
|
||||
{ key: 'callback_url', label: t('admin.wecom.copyFields.callbackUrl') },
|
||||
{ key: 'callback_token', label: t('admin.wecom.copyFields.callbackToken') },
|
||||
{ key: 'encoding_aes_key', label: t('admin.wecom.copyFields.encodingAesKey') },
|
||||
{ key: 'oauth_redirect_uri', label: t('admin.wecom.copyFields.oauthRedirectUri') },
|
||||
{ key: 'homepage_url', label: t('admin.wecom.copyFields.homepageUrl') },
|
||||
{ key: 'trusted_domain', label: t('admin.wecom.copyFields.trustedDomain') },
|
||||
{ key: 'authorize_api', label: t('admin.wecom.copyFields.authorizeApi') },
|
||||
{ key: 'login_api', label: t('admin.wecom.copyFields.loginApi') },
|
||||
]"
|
||||
:key="item.key"
|
||||
>
|
||||
<label class="mb-1.5 block text-xs text-muted">{{ item.label }}</label>
|
||||
<div class="flex gap-2">
|
||||
<input :value="(wecomIntegrationManifest as any)[item.key] || ''" readonly class="input-field flex-1 bg-surface-soft font-mono text-xs" />
|
||||
<button type="button" class="btn-secondary px-3" @click="copyText(String((wecomIntegrationManifest as any)[item.key] || ''))">
|
||||
{{ t('admin.wecom.copy') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</details>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,10 @@
|
||||
/**
|
||||
* features/admin/modules/wecom/wecom.context.ts
|
||||
* 企微管理子页面共享 context key。
|
||||
*/
|
||||
import type { InjectionKey } from 'vue';
|
||||
import type { useWecomAdmin } from './composables/useWecomAdmin';
|
||||
|
||||
export type WecomAdminContext = ReturnType<typeof useWecomAdmin>;
|
||||
|
||||
export const WECOM_ADMIN_KEY: InjectionKey<WecomAdminContext> = Symbol('wecomAdmin');
|
||||
@@ -16,6 +16,7 @@ const BADGE_CACHE_TTL_MS = 60_000;
|
||||
export const useAdminNavStore = defineStore('adminNav', () => {
|
||||
const sidebarCollapsed = ref(false);
|
||||
const reportsExpanded = ref(true);
|
||||
const wecomExpanded = ref(true);
|
||||
/** 「用户审批」导航角标:pending 注册用户数 */
|
||||
const pendingApprovalsCount = ref(0);
|
||||
/** 「权限申请」导航角标:pending 权限申请数 */
|
||||
@@ -83,6 +84,7 @@ export const useAdminNavStore = defineStore('adminNav', () => {
|
||||
return {
|
||||
sidebarCollapsed,
|
||||
reportsExpanded,
|
||||
wecomExpanded,
|
||||
pendingApprovalsCount,
|
||||
pendingRequestsCount,
|
||||
toggleSidebar,
|
||||
|
||||
@@ -7,6 +7,7 @@ export interface WecomBindingRow {
|
||||
id: number;
|
||||
username: string;
|
||||
real_name?: string;
|
||||
employee_id?: string | null;
|
||||
email: string;
|
||||
role: string;
|
||||
status: string;
|
||||
@@ -82,6 +83,45 @@ export interface WecomIntegrationManifest {
|
||||
login_api: string;
|
||||
}
|
||||
|
||||
export interface WecomBindingStats {
|
||||
total_active: number;
|
||||
bound: number;
|
||||
unbound: number;
|
||||
bound_rate: number;
|
||||
}
|
||||
|
||||
export interface WecomSyncConflict {
|
||||
employee_id?: string;
|
||||
username?: string;
|
||||
old_wecom_userid?: string;
|
||||
new_wecom_userid?: string;
|
||||
occupied_by_user_id?: number;
|
||||
occupied_by_username?: string;
|
||||
}
|
||||
|
||||
export interface WecomSyncPendingUpdate {
|
||||
employee_id: string;
|
||||
username: string;
|
||||
wecom_userid: string;
|
||||
name?: string | null;
|
||||
}
|
||||
|
||||
export interface WecomSyncSummary {
|
||||
apply: boolean;
|
||||
employee_id_source: string;
|
||||
department_ids: number[];
|
||||
wecom_users: number;
|
||||
wecom_without_employee_id: number;
|
||||
local_matched: number;
|
||||
would_update: number;
|
||||
updated: number;
|
||||
already_bound: number;
|
||||
local_missing: number;
|
||||
conflicts: WecomSyncConflict[];
|
||||
missing_samples: Array<{ wecom_userid?: string | null; name?: string | null }>;
|
||||
pending_updates: WecomSyncPendingUpdate[];
|
||||
}
|
||||
|
||||
export const createDefaultWecomSystemSettings = (): WecomSystemSettings => ({
|
||||
enabled: true,
|
||||
corp_id: '',
|
||||
|
||||
@@ -35,6 +35,13 @@ export const submitLeaveWorkflow = (form: Record<string, any>) =>
|
||||
body: JSON.stringify(form),
|
||||
});
|
||||
|
||||
export const resetPasswordByWecom = (employeeId: string, username: string) =>
|
||||
requestJson('/api/user/reset-password-by-wecom', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ employee_id: employeeId, username }),
|
||||
});
|
||||
|
||||
export const resetPasswordConfirm = (token: string, newPassword: string) =>
|
||||
requestJson('/api/user/reset-password-confirm', {
|
||||
method: 'POST',
|
||||
|
||||
@@ -1,24 +1,45 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* features/auth/components/LoginModals.vue
|
||||
* 登录相关弹窗:找回密码、公告详情、企微登录/绑定提示、注册。
|
||||
* 用途:登录相关弹窗(找回密码、公告、企微提示、注册)。
|
||||
* 依赖:login.context、useDialogBackdropClose、wecom 工具函数。
|
||||
* 逻辑:LoginPage 注入 LOGIN_KEY;遮罩关闭用 pointer 判定避免拖选误关。
|
||||
*/
|
||||
import { inject } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { Lock, User, X } from 'lucide-vue-next';
|
||||
import { formatWecomFieldLabel } from '@/shared/utils/wecom';
|
||||
import { createDialogBackdropCloseHandler } from '@/shared/composables/useDialogBackdropClose';
|
||||
import { LOGIN_KEY } from '../composables/login.context';
|
||||
|
||||
const { t } = useI18n();
|
||||
const lk = inject(LOGIN_KEY)! as any;
|
||||
|
||||
const forgotPasswordBackdrop = createDialogBackdropCloseHandler(() => {
|
||||
lk.showForgotPasswordModal = false;
|
||||
});
|
||||
const announcementBackdrop = createDialogBackdropCloseHandler(() => {
|
||||
lk.showAnnouncementModal = false;
|
||||
});
|
||||
const wecomLoginBackdrop = createDialogBackdropCloseHandler(() => {
|
||||
lk.wecomLoginDialog = null;
|
||||
});
|
||||
const wecomBindBackdrop = createDialogBackdropCloseHandler(() => {
|
||||
lk.wecomBindPrompt = null;
|
||||
});
|
||||
const registerBackdrop = createDialogBackdropCloseHandler(() => {
|
||||
lk.showRegisterModal = false;
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<div
|
||||
v-if="lk.showForgotPasswordModal"
|
||||
class="dialog-overlay z-50 items-center animate-fade-in"
|
||||
@click.self="lk.showForgotPasswordModal = false"
|
||||
@pointerdown.self="forgotPasswordBackdrop.onBackdropPointerDown"
|
||||
@pointerup.self="forgotPasswordBackdrop.onBackdropPointerUp"
|
||||
>
|
||||
<div class="dialog-panel max-w-md animate-slide-up">
|
||||
<div class="dialog-header dialog-header--compact relative border-0 pb-0">
|
||||
@@ -33,9 +54,15 @@ const lk = inject(LOGIN_KEY)! as any;
|
||||
</div>
|
||||
<h3 class="text-xl font-bold text-primary">{{ $t('login.forgotPassword') }}</h3>
|
||||
<p class="mt-2 text-sm text-muted">{{ $t('login.forgotPasswordDesc') }}</p>
|
||||
<div class="mt-6 space-y-2 text-left">
|
||||
<label class="label-field ml-1">{{ $t('register.email') }}</label>
|
||||
<input v-model="lk.forgotPasswordForm.email" :placeholder="$t('register.email')" class="input-field" @keyup.enter="lk.handleForgotPassword" />
|
||||
<div class="mt-6 space-y-4 text-left">
|
||||
<div class="space-y-2">
|
||||
<label class="label-field ml-1">{{ $t('register.fields.employeeId') }}</label>
|
||||
<input v-model="lk.forgotPasswordForm.employee_id" :placeholder="$t('register.fields.employeeId')" class="input-field" @keyup.enter="lk.handleForgotPassword" />
|
||||
</div>
|
||||
<div class="space-y-2">
|
||||
<label class="label-field ml-1">{{ $t('login.username') }}</label>
|
||||
<input v-model="lk.forgotPasswordForm.username" :placeholder="$t('login.placeholder.username')" class="input-field" @keyup.enter="lk.handleForgotPassword" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="dialog-footer">
|
||||
@@ -48,7 +75,8 @@ const lk = inject(LOGIN_KEY)! as any;
|
||||
<div
|
||||
v-if="lk.showAnnouncementModal && lk.selectedAnnouncement"
|
||||
class="dialog-overlay z-50 items-center animate-fade-in"
|
||||
@click.self="lk.showAnnouncementModal = false"
|
||||
@pointerdown.self="announcementBackdrop.onBackdropPointerDown"
|
||||
@pointerup.self="announcementBackdrop.onBackdropPointerUp"
|
||||
>
|
||||
<div class="dialog-panel max-w-2xl max-h-[85vh] animate-slide-up">
|
||||
<div class="dialog-header">
|
||||
@@ -74,7 +102,8 @@ const lk = inject(LOGIN_KEY)! as any;
|
||||
<div
|
||||
v-if="lk.wecomLoginDialog"
|
||||
class="dialog-overlay z-50 items-center animate-fade-in"
|
||||
@click.self="lk.wecomLoginDialog = null"
|
||||
@pointerdown.self="wecomLoginBackdrop.onBackdropPointerDown"
|
||||
@pointerup.self="wecomLoginBackdrop.onBackdropPointerUp"
|
||||
>
|
||||
<div class="dialog-panel max-w-lg animate-slide-up">
|
||||
<div class="dialog-header dialog-header--compact">
|
||||
@@ -116,7 +145,8 @@ const lk = inject(LOGIN_KEY)! as any;
|
||||
<div
|
||||
v-if="lk.wecomBindPrompt"
|
||||
class="dialog-overlay z-50 items-center animate-fade-in"
|
||||
@click.self="lk.wecomBindPrompt = null"
|
||||
@pointerdown.self="wecomBindBackdrop.onBackdropPointerDown"
|
||||
@pointerup.self="wecomBindBackdrop.onBackdropPointerUp"
|
||||
>
|
||||
<div class="dialog-panel max-w-lg animate-slide-up">
|
||||
<div class="dialog-header dialog-header--compact">
|
||||
@@ -168,7 +198,8 @@ const lk = inject(LOGIN_KEY)! as any;
|
||||
<div
|
||||
v-if="lk.showRegisterModal"
|
||||
class="dialog-overlay z-50 items-center animate-fade-in"
|
||||
@click.self="lk.showRegisterModal = false"
|
||||
@pointerdown.self="registerBackdrop.onBackdropPointerDown"
|
||||
@pointerup.self="registerBackdrop.onBackdropPointerUp"
|
||||
>
|
||||
<div class="dialog-panel max-w-md animate-slide-up">
|
||||
<div class="dialog-header">
|
||||
|
||||
@@ -90,7 +90,7 @@ const lk = inject(LOGIN_KEY)! as any;
|
||||
</button>
|
||||
|
||||
<div class="flex justify-between items-center pt-4 mt-2 border-t border-subtle/50">
|
||||
<button type="button" @click="lk.showForgotPasswordModal = true" class="text-sm text-secondary hover:text-brand-700 transition-colors">
|
||||
<button type="button" @click="lk.openForgotPasswordModal" class="text-sm text-secondary hover:text-brand-700 transition-colors">
|
||||
{{ $t('login.forgotPassword') }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
@@ -45,7 +45,7 @@ export function useLoginAuth(deps: LoginDeps, options: LoginAuthOptions) {
|
||||
employee_id: '',
|
||||
phone_number: '',
|
||||
});
|
||||
const forgotPasswordForm = ref({ email: '' });
|
||||
const forgotPasswordForm = ref({ employee_id: '', username: '' });
|
||||
const isWecomLoggingIn = ref(false);
|
||||
const wecomLoginDialog = ref<WecomLoginDialogContent | null>(null);
|
||||
const wecomBindPrompt = ref<WecomBindPromptState | null>(null);
|
||||
@@ -59,20 +59,34 @@ export function useLoginAuth(deps: LoginDeps, options: LoginAuthOptions) {
|
||||
saveAuthUser({ ...(user || {}) }, rememberMe.value);
|
||||
};
|
||||
|
||||
const openForgotPasswordModal = () => {
|
||||
forgotPasswordForm.value = {
|
||||
employee_id: '',
|
||||
username: loginUsername.value.trim(),
|
||||
};
|
||||
showForgotPasswordModal.value = true;
|
||||
};
|
||||
|
||||
const handleForgotPassword = async () => {
|
||||
if (!forgotPasswordForm.value.email) {
|
||||
msg.warning(t('register.emailRequired'));
|
||||
const employeeId = forgotPasswordForm.value.employee_id.trim();
|
||||
const username = forgotPasswordForm.value.username.trim();
|
||||
if (!employeeId) {
|
||||
msg.warning(t('login.employeeIdRequired'));
|
||||
return;
|
||||
}
|
||||
if (!username) {
|
||||
msg.warning(t('login.usernameRequired'));
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await requestJson('/api/user/reset-password-by-email', {
|
||||
await requestJson('/api/user/reset-password-by-wecom', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(forgotPasswordForm.value),
|
||||
body: JSON.stringify({ employee_id: employeeId, username }),
|
||||
});
|
||||
msg.success(t('login.passwordResetEmailSent'));
|
||||
msg.success(t('login.passwordResetWecomSent'));
|
||||
showForgotPasswordModal.value = false;
|
||||
forgotPasswordForm.value = { email: '' };
|
||||
forgotPasswordForm.value = { employee_id: '', username: '' };
|
||||
} catch (e) {
|
||||
console.error('Password reset error', e);
|
||||
msg.error((e as Error)?.message || t('login.passwordResetRequestFailed'));
|
||||
@@ -375,6 +389,7 @@ export function useLoginAuth(deps: LoginDeps, options: LoginAuthOptions) {
|
||||
rememberMe,
|
||||
showRegisterModal,
|
||||
showForgotPasswordModal,
|
||||
openForgotPasswordModal,
|
||||
registerForm,
|
||||
forgotPasswordForm,
|
||||
isWecomLoggingIn,
|
||||
|
||||
@@ -8,6 +8,7 @@ export {
|
||||
getUserProfile,
|
||||
getLeaveBalance,
|
||||
submitLeaveWorkflow,
|
||||
resetPasswordByWecom,
|
||||
resetPasswordConfirm,
|
||||
getUserAgent,
|
||||
listUserAgents,
|
||||
|
||||
@@ -1,33 +1,43 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* features/auth/views/ResetPasswordView.vue
|
||||
* 邮件链接重置密码页(/reset-password?token=...)。
|
||||
* 企微 textcard / 邮件链接重置密码页(/reset-password?token=...)。
|
||||
* 依赖:user.api resetPasswordConfirm、vue-i18n、MinimalShell。
|
||||
* 逻辑:校验两次密码一致后调 confirm 接口,成功后跳转 /login。
|
||||
*/
|
||||
import { ref } from 'vue';
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { Lock, AlertCircle, CheckCircle } from 'lucide-vue-next';
|
||||
import MinimalShell from '@/shared/layouts/MinimalShell.vue';
|
||||
import { resetPasswordConfirm } from '@/features/auth/api/user.api';
|
||||
import { resolveCasdoorErrorMessage } from '@/shared/utils/casdoor';
|
||||
import type { BusinessError } from '@/shared/api/client';
|
||||
|
||||
const { t } = useI18n();
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
|
||||
const token = ref(route.query.token as string || '');
|
||||
const token = ref((route.query.token as string) || '');
|
||||
const password = ref('');
|
||||
const confirmPassword = ref('');
|
||||
const isLoading = ref(false);
|
||||
const status = ref<'idle' | 'success' | 'error'>('idle');
|
||||
const message = ref('');
|
||||
|
||||
/**
|
||||
* 提交新密码并重置 token。
|
||||
* 核心逻辑:前端校验 → resetPasswordConfirm → 成功 3 秒后跳转登录页。
|
||||
*/
|
||||
const handleReset = async () => {
|
||||
if (!password.value || !confirmPassword.value) {
|
||||
message.value = 'Please fill in all fields';
|
||||
message.value = t('resetPassword.fillAllFields');
|
||||
status.value = 'error';
|
||||
return;
|
||||
}
|
||||
|
||||
if (password.value !== confirmPassword.value) {
|
||||
message.value = 'Passwords do not match';
|
||||
message.value = t('resetPassword.passwordMismatch');
|
||||
status.value = 'error';
|
||||
return;
|
||||
}
|
||||
@@ -39,13 +49,14 @@ const handleReset = async () => {
|
||||
try {
|
||||
await resetPasswordConfirm(token.value, password.value);
|
||||
status.value = 'success';
|
||||
message.value = 'Password reset successfully! Redirecting to login...';
|
||||
message.value = t('resetPassword.successRedirect');
|
||||
setTimeout(() => {
|
||||
router.push('/');
|
||||
router.push('/login');
|
||||
}, 3000);
|
||||
} catch (e) {
|
||||
status.value = 'error';
|
||||
message.value = (e as Error).message || 'Failed to reset password';
|
||||
const err = e as BusinessError;
|
||||
message.value = resolveCasdoorErrorMessage(err, t) || (e as Error).message || t('resetPassword.failed');
|
||||
} finally {
|
||||
isLoading.value = false;
|
||||
}
|
||||
@@ -58,8 +69,8 @@ const handleReset = async () => {
|
||||
<div class="w-12 h-12 bg-brand-100 rounded-xl mx-auto flex items-center justify-center text-brand-600 mb-4">
|
||||
<Lock class="w-6 h-6" />
|
||||
</div>
|
||||
<h2 class="page-title">Reset Password</h2>
|
||||
<p class="section-desc mt-2">Enter your new password below</p>
|
||||
<h2 class="page-title">{{ $t('resetPassword.title') }}</h2>
|
||||
<p class="section-desc mt-2">{{ $t('resetPassword.desc') }}</p>
|
||||
</div>
|
||||
|
||||
<div v-if="status === 'success'" class="alert-ds alert-success mb-6">
|
||||
@@ -74,23 +85,35 @@ const handleReset = async () => {
|
||||
|
||||
<form v-if="status !== 'success'" @submit.prevent="handleReset" class="space-y-5">
|
||||
<div>
|
||||
<label class="label-field mb-1.5 block">New Password</label>
|
||||
<input v-model="password" type="password" class="input-field" placeholder="Enter new password" required />
|
||||
<label class="label-field mb-1.5 block">{{ $t('resetPassword.newPassword') }}</label>
|
||||
<input
|
||||
v-model="password"
|
||||
type="password"
|
||||
class="input-field"
|
||||
:placeholder="$t('resetPassword.newPasswordPlaceholder')"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label class="label-field mb-1.5 block">Confirm Password</label>
|
||||
<input v-model="confirmPassword" type="password" class="input-field" placeholder="Confirm new password" required />
|
||||
<label class="label-field mb-1.5 block">{{ $t('resetPassword.confirmPassword') }}</label>
|
||||
<input
|
||||
v-model="confirmPassword"
|
||||
type="password"
|
||||
class="input-field"
|
||||
:placeholder="$t('resetPassword.confirmPasswordPlaceholder')"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
|
||||
<button type="submit" :disabled="isLoading" class="btn-primary w-full py-3 flex justify-center items-center gap-2">
|
||||
<div v-if="isLoading" class="animate-spin rounded-full h-4 w-4 border-2 border-white/30 border-t-white"></div>
|
||||
<span>{{ isLoading ? 'Resetting...' : 'Reset Password' }}</span>
|
||||
<span>{{ isLoading ? $t('resetPassword.submitting') : $t('resetPassword.submit') }}</span>
|
||||
</button>
|
||||
</form>
|
||||
|
||||
<div class="mt-6 text-center">
|
||||
<router-link to="/" class="text-sm font-medium text-muted hover:text-secondary">Back to Login</router-link>
|
||||
<router-link to="/login" class="text-sm font-medium text-muted hover:text-secondary">{{ $t('resetPassword.backToLogin') }}</router-link>
|
||||
</div>
|
||||
</MinimalShell>
|
||||
</template>
|
||||
@@ -237,8 +237,50 @@
|
||||
}
|
||||
},
|
||||
"wecom": {
|
||||
"title": "WeCom Binding Management",
|
||||
"subtitle": "Manually bind/unbind WeCom accounts and review login audit records",
|
||||
"title": "WeCom",
|
||||
"subtitle": "Configure WeCom integration, sync userids, manage bindings and login audits",
|
||||
"nav": {
|
||||
"settings": "Settings",
|
||||
"bindings": "Bindings",
|
||||
"audits": "Login Audits"
|
||||
},
|
||||
"overview": {
|
||||
"bound": "Bound userids",
|
||||
"unbound": "Unbound",
|
||||
"boundRate": "Bound rate",
|
||||
"hint": "Password reset",
|
||||
"hintDesc": "Users without wecom_userid cannot receive WeCom reset links"
|
||||
},
|
||||
"sync": {
|
||||
"title": "Directory Sync",
|
||||
"desc": "Pull WeCom members and backfill users.wecom_userid by employee ID for reset and notifications.",
|
||||
"permissionNote": "Requires contact read and message send permissions on the WeCom app.",
|
||||
"employeeIdSource": "Employee ID source",
|
||||
"departmentId": "Root department ID (optional)",
|
||||
"departmentIdPlaceholder": "Leave empty for all departments",
|
||||
"preview": "Preview sync",
|
||||
"apply": "Apply changes",
|
||||
"previewDone": "Preview completed. Review results before applying.",
|
||||
"previewFailed": "Preview sync failed",
|
||||
"previewFirst": "Please preview sync results first",
|
||||
"conflictsBlockApply": "Conflicts detected. Resolve them before applying.",
|
||||
"nothingToUpdate": "Nothing to update",
|
||||
"applyConfirm": "Write {count} userid bindings to the database?",
|
||||
"applyDone": "Successfully updated {count} bindings",
|
||||
"applyFailed": "Failed to apply sync results",
|
||||
"invalidDepartmentId": "Department ID must be a positive integer",
|
||||
"previewTruncated": "Showing first 20 of {total} pending updates",
|
||||
"conflictsTitle": "Conflicts",
|
||||
"occupiedBy": "userid already used by {user}",
|
||||
"stats": {
|
||||
"wecomUsers": "WeCom members",
|
||||
"localMatched": "Local matched",
|
||||
"wouldUpdate": "Would update",
|
||||
"conflicts": "Conflicts"
|
||||
}
|
||||
},
|
||||
"bindingsHint": "Users without wecom_userid cannot use WeCom password reset. Run directory sync or bind manually.",
|
||||
"searchBindings": "Search username, name, employee ID or wecom_userid",
|
||||
"systemSettings": "WeCom System Settings",
|
||||
"integrationCopyTitle": "WeCom Console Copy Helper",
|
||||
"integrationCopyDesc": "Copy these values directly into WeCom console fields.",
|
||||
@@ -323,6 +365,7 @@
|
||||
},
|
||||
"headers": {
|
||||
"user": "User",
|
||||
"employeeId": "Employee ID",
|
||||
"roleStatus": "Role / Status",
|
||||
"wecomUserId": "WeCom UserId",
|
||||
"unionId": "UnionId",
|
||||
|
||||
@@ -30,11 +30,13 @@
|
||||
"dbConnectionFailed": "Database connection failed. Please check if the database service is running.",
|
||||
"internalError": "Internal server error. Please try again later.",
|
||||
"rememberMe": "Remember me for 30 days",
|
||||
"forgotPasswordDesc": "Enter your email to reset your password",
|
||||
"forgotPasswordDesc": "Enter your employee ID and username; a reset link will be sent to your WeCom",
|
||||
"findPassword": "Find Password",
|
||||
"employeeIdRequired": "Please enter employee ID",
|
||||
"passwordResetWecomSent": "If the account exists and WeCom is bound, a reset link has been sent to your WeCom.",
|
||||
"passwordResetEmailSent": "If the account exists, a reset link has been sent to your email.",
|
||||
"passwordResetRequestFailed": "Failed to request password reset",
|
||||
"announcements": "Announcements",
|
||||
"passwordResetEmailSent": "如果账号存在,重置链接已发送到您的邮箱。",
|
||||
"passwordResetRequestFailed": "请求密码重置失败",
|
||||
"casdoorLogin": "Login with Casdoor",
|
||||
"casdoorErrors": {
|
||||
"invalidCredentials": "Incorrect username or password",
|
||||
@@ -161,5 +163,20 @@
|
||||
"employeeId": "Employee ID",
|
||||
"phone": "Phone Number"
|
||||
}
|
||||
},
|
||||
"resetPassword": {
|
||||
"title": "Reset Password",
|
||||
"desc": "Enter your new password below",
|
||||
"newPassword": "New Password",
|
||||
"confirmPassword": "Confirm Password",
|
||||
"newPasswordPlaceholder": "Enter new password",
|
||||
"confirmPasswordPlaceholder": "Confirm new password",
|
||||
"submit": "Reset Password",
|
||||
"submitting": "Resetting...",
|
||||
"backToLogin": "Back to Login",
|
||||
"fillAllFields": "Please fill in all fields",
|
||||
"passwordMismatch": "Passwords do not match",
|
||||
"successRedirect": "Password reset successfully. Redirecting to login...",
|
||||
"failed": "Failed to reset password"
|
||||
}
|
||||
}
|
||||
@@ -17,5 +17,12 @@
|
||||
"info": "Notice",
|
||||
"warning": "Warning",
|
||||
"error": "Error"
|
||||
},
|
||||
"pagination": {
|
||||
"summary": "Total {total} rows, page {page} / {pages}",
|
||||
"perPage": "Per page",
|
||||
"itemsUnit": "rows",
|
||||
"prevPage": "Previous",
|
||||
"nextPage": "Next"
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,9 @@
|
||||
"USER_PHONE_EXISTS": "Phone number already exists.",
|
||||
"USER_UNIQUENESS_CONFLICT": "Data uniqueness conflict.",
|
||||
"SYSTEM_INTERNAL_ERROR": "Internal server error. Please try again later.",
|
||||
"SYSTEM_HTTP_ERROR": "Request failed."
|
||||
"SYSTEM_HTTP_ERROR": "Request failed.",
|
||||
"WECOM_RESET_NOT_CONFIGURED": "WeCom password reset is not configured. Enable WeCom under Admin → WeCom → System Settings and fill Corp ID, Agent ID, and Secret.",
|
||||
"WECOM_NOTIFY_DISABLED": "WeCom notifications are disabled. Enable them under Admin → WeCom → Notify Settings.",
|
||||
"WECOM_RESET_URL_NOT_CONFIGURED": "Public base URL is not configured. Set WECOM_PUBLIC_BASE_URL in system settings."
|
||||
}
|
||||
}
|
||||
@@ -237,8 +237,50 @@
|
||||
}
|
||||
},
|
||||
"wecom": {
|
||||
"title": "การจัดการการผูกบัญชี WeCom",
|
||||
"subtitle": "ผูก/ยกเลิกการผูกบัญชี WeCom แบบแมนนวล และตรวจสอบบันทึกการเข้าสู่ระบบ",
|
||||
"title": "WeCom",
|
||||
"subtitle": "ตั้งค่า WeCom ซิงค์ userid จัดการการผูกบัญชีและตรวจสอบการเข้าสู่ระบบ",
|
||||
"nav": {
|
||||
"settings": "การตั้งค่า",
|
||||
"bindings": "การผูกบัญชี",
|
||||
"audits": "ตรวจสอบการเข้าสู่ระบบ"
|
||||
},
|
||||
"overview": {
|
||||
"bound": "ผูก userid แล้ว",
|
||||
"unbound": "ยังไม่ผูก",
|
||||
"boundRate": "อัตราการผูก",
|
||||
"hint": "รีเซ็ตรหัสผ่าน",
|
||||
"hintDesc": "ผู้ใช้ที่ไม่มี wecom_userid จะไม่ได้รับลิงก์รีเซ็ตผ่าน WeCom"
|
||||
},
|
||||
"sync": {
|
||||
"title": "ซิงค์สมุดรายชื่อ",
|
||||
"desc": "ดึงสมาชิก WeCom และเติม users.wecom_userid ตามรหัสพนักงาน",
|
||||
"permissionNote": "แอป WeCom ต้องมีสิทธิ์อ่านสมุดรายชื่อและส่งข้อความ",
|
||||
"employeeIdSource": "แหล่งรหัสพนักงาน",
|
||||
"departmentId": "รหัสแผนกราก (ไม่บังคับ)",
|
||||
"departmentIdPlaceholder": "เว้นว่างเพื่อซิงค์ทุกแผนก",
|
||||
"preview": "ดูตัวอย่าง",
|
||||
"apply": "ยืนยันเขียน",
|
||||
"previewDone": "ดูตัวอย่างเสร็จแล้ว โปรดตรวจสอบก่อนยืนยัน",
|
||||
"previewFailed": "ดูตัวอย่างล้มเหลว",
|
||||
"previewFirst": "โปรดดูตัวอย่างก่อน",
|
||||
"conflictsBlockApply": "พบความขัดแย้ง โปรดแก้ไขก่อนยืนยัน",
|
||||
"nothingToUpdate": "ไม่มีรายการที่ต้องอัปเดต",
|
||||
"applyConfirm": "ยืนยันเขียน {count} รายการลงฐานข้อมูล?",
|
||||
"applyDone": "อัปเดต {count} รายการสำเร็จ",
|
||||
"applyFailed": "ยืนยันการซิงค์ล้มเหลว",
|
||||
"invalidDepartmentId": "รหัสแผนกต้องเป็นจำนวนเต็มบวก",
|
||||
"previewTruncated": "แสดง 20 รายการแรกจากทั้งหมด {total} รายการ",
|
||||
"conflictsTitle": "รายการขัดแย้ง",
|
||||
"occupiedBy": "userid ถูกใช้โดย {user} แล้ว",
|
||||
"stats": {
|
||||
"wecomUsers": "สมาชิก WeCom",
|
||||
"localMatched": "จับคู่ในระบบ",
|
||||
"wouldUpdate": "จะอัปเดต",
|
||||
"conflicts": "ขัดแย้ง"
|
||||
}
|
||||
},
|
||||
"bindingsHint": "ผู้ใช้ที่ไม่มี wecom_userid ใช้การรีเซ็ตรหัสผ่านผ่าน WeCom ไม่ได้ โปรดซิงค์หรือผูกด้วยตนเอง",
|
||||
"searchBindings": "ค้นหาชื่อผู้ใช้ ชื่อ รหัสพนักงาน หรือ wecom_userid",
|
||||
"systemSettings": "การตั้งค่าระบบ WeCom",
|
||||
"integrationCopyTitle": "ตัวช่วยคัดลอกค่าไปยังคอนโซล WeCom",
|
||||
"integrationCopyDesc": "คัดลอกค่าด้านล่างไปใส่ในช่องที่ตรงกันในคอนโซลผู้ดูแล WeCom ได้โดยตรง",
|
||||
@@ -328,6 +370,7 @@
|
||||
},
|
||||
"headers": {
|
||||
"user": "ผู้ใช้",
|
||||
"employeeId": "รหัสพนักงาน",
|
||||
"roleStatus": "บทบาท / สถานะ",
|
||||
"wecomUserId": "WeCom UserId",
|
||||
"unionId": "UnionId",
|
||||
|
||||
@@ -22,8 +22,11 @@
|
||||
"forgotPassword": "ลืมรหัสผ่าน?",
|
||||
"rememberMe": "จดจำการเข้าสู่ระบบ 30 วัน",
|
||||
"announcements": "ประกาศ",
|
||||
"forgotPasswordDesc": "กรอกอีเมลเพื่อรีเซ็ตรหัสผ่าน",
|
||||
"forgotPasswordDesc": "กรอกรหัสพนักงานและชื่อผู้ใช้ ลิงก์รีเซ็ตจะถูกส่งไปยัง WeCom ของคุณ",
|
||||
"findPassword": "ค้นหารหัสผ่าน",
|
||||
"employeeIdRequired": "กรุณากรอกรหัสพนักงาน",
|
||||
"passwordResetWecomSent": "หากบัญชีมีอยู่และผูก WeCom แล้ว ลิงก์รีเซ็ตถูกส่งไปยัง WeCom ของคุณแล้ว",
|
||||
"passwordResetRequestFailed": "คำขอรีเซ็ตรหัสผ่านล้มเหลว",
|
||||
"casdoorLogin": "เข้าสู่ระบบด้วย Casdoor",
|
||||
"casdoorErrors": {
|
||||
"invalidCredentials": "ชื่อผู้ใช้หรือรหัสผ่านไม่ถูกต้อง",
|
||||
@@ -143,6 +146,26 @@
|
||||
"success": "ส่งคำขอลงทะเบียนแล้ว โปรดรอการอนุมัติ",
|
||||
"failed": "การลงทะเบียนล้มเหลว",
|
||||
"inputError": "กรุณากรอกชื่อผู้ใช้และรหัสผ่าน",
|
||||
"requestFailed": "คำขอล้มเหลว"
|
||||
"requestFailed": "คำขอล้มเหลว",
|
||||
"fields": {
|
||||
"realName": "ชื่อจริง",
|
||||
"employeeId": "รหัสพนักงาน",
|
||||
"phone": "หมายเลขโทรศัพท์"
|
||||
}
|
||||
},
|
||||
"resetPassword": {
|
||||
"title": "รีเซ็ตรหัสผ่าน",
|
||||
"desc": "กรอกรหัสผ่านใหม่ด้านล่าง",
|
||||
"newPassword": "รหัสผ่านใหม่",
|
||||
"confirmPassword": "ยืนยันรหัสผ่าน",
|
||||
"newPasswordPlaceholder": "กรอกรหัสผ่านใหม่",
|
||||
"confirmPasswordPlaceholder": "กรอกรหัสผ่านใหม่อีกครั้ง",
|
||||
"submit": "รีเซ็ตรหัสผ่าน",
|
||||
"submitting": "กำลังรีเซ็ต...",
|
||||
"backToLogin": "กลับไปหน้าเข้าสู่ระบบ",
|
||||
"fillAllFields": "กรุณากรอกข้อมูลให้ครบ",
|
||||
"passwordMismatch": "รหัสผ่านไม่ตรงกัน",
|
||||
"successRedirect": "รีเซ็ตรหัสผ่านสำเร็จ กำลังไปหน้าเข้าสู่ระบบ...",
|
||||
"failed": "รีเซ็ตรหัสผ่านล้มเหลว"
|
||||
}
|
||||
}
|
||||
@@ -17,5 +17,12 @@
|
||||
"info": "แจ้งเตือน",
|
||||
"warning": "คำเตือน",
|
||||
"error": "ข้อผิดพลาด"
|
||||
},
|
||||
"pagination": {
|
||||
"summary": "ทั้งหมด {total} รายการ, หน้า {page} / {pages}",
|
||||
"perPage": "ต่อหน้า",
|
||||
"itemsUnit": "รายการ",
|
||||
"prevPage": "ก่อนหน้า",
|
||||
"nextPage": "ถัดไป"
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,9 @@
|
||||
"USER_PHONE_EXISTS": "หมายเลขโทรศัพท์นี้มีอยู่แล้ว",
|
||||
"USER_UNIQUENESS_CONFLICT": "ข้อมูลซ้ำกัน",
|
||||
"SYSTEM_INTERNAL_ERROR": "เซิร์ฟเวอร์ขัดข้อง กรุณาลองใหม่ภายหลัง",
|
||||
"SYSTEM_HTTP_ERROR": "คำขอล้มเหลว"
|
||||
"SYSTEM_HTTP_ERROR": "คำขอล้มเหลว",
|
||||
"WECOM_RESET_NOT_CONFIGURED": "ยังไม่ได้ตั้งค่าการรีเซ็ตรหัสผ่านผ่าน WeCom โปรดเปิดใช้งานและกรอก Corp ID, Agent ID, Secret ใน Admin → WeCom → System Settings",
|
||||
"WECOM_NOTIFY_DISABLED": "การแจ้งเตือน WeCom ถูกปิด โปรดเปิดใน Admin → WeCom → Notify Settings",
|
||||
"WECOM_RESET_URL_NOT_CONFIGURED": "ยังไม่ได้ตั้งค่า Public Base URL โปรดกรอก WECOM_PUBLIC_BASE_URL ในการตั้งค่าระบบ"
|
||||
}
|
||||
}
|
||||
@@ -238,8 +238,50 @@
|
||||
}
|
||||
},
|
||||
"wecom": {
|
||||
"title": "企业微信绑定管理",
|
||||
"subtitle": "手动绑定/解绑企业微信账号,并查看登录审计记录",
|
||||
"title": "企业微信",
|
||||
"subtitle": "配置企微集成、同步 userid、管理绑定与登录审计",
|
||||
"nav": {
|
||||
"settings": "系统配置",
|
||||
"bindings": "绑定管理",
|
||||
"audits": "登录审计"
|
||||
},
|
||||
"overview": {
|
||||
"bound": "已绑定 userid",
|
||||
"unbound": "未绑定",
|
||||
"boundRate": "绑定率",
|
||||
"hint": "找回密码",
|
||||
"hintDesc": "未绑定 wecom_userid 的用户无法接收企微重置链接"
|
||||
},
|
||||
"sync": {
|
||||
"title": "通讯录同步",
|
||||
"desc": "从企业微信通讯录按工号回填 users.wecom_userid,用于找回密码与通知触达。",
|
||||
"permissionNote": "需在企微后台为自建应用开通「通讯录读」与「发送应用消息」权限。",
|
||||
"employeeIdSource": "当前工号来源",
|
||||
"departmentId": "根部门 ID(可选)",
|
||||
"departmentIdPlaceholder": "留空表示全部部门",
|
||||
"preview": "预览同步",
|
||||
"apply": "确认写入",
|
||||
"previewDone": "预览完成,请确认结果后再写入",
|
||||
"previewFailed": "预览同步失败",
|
||||
"previewFirst": "请先预览同步结果",
|
||||
"conflictsBlockApply": "存在冲突,请先人工处理后再写入",
|
||||
"nothingToUpdate": "没有需要更新的绑定",
|
||||
"applyConfirm": "确认将 {count} 条 userid 绑定写入数据库?",
|
||||
"applyDone": "已成功更新 {count} 条绑定",
|
||||
"applyFailed": "写入同步结果失败",
|
||||
"invalidDepartmentId": "部门 ID 必须为正整数",
|
||||
"previewTruncated": "仅展示前 20 条,共 {total} 条待更新",
|
||||
"conflictsTitle": "冲突明细",
|
||||
"occupiedBy": "userid 已被用户 {user} 占用",
|
||||
"stats": {
|
||||
"wecomUsers": "企微成员",
|
||||
"localMatched": "本地匹配",
|
||||
"wouldUpdate": "待更新",
|
||||
"conflicts": "冲突"
|
||||
}
|
||||
},
|
||||
"bindingsHint": "未绑定 wecom_userid 的用户无法使用企微找回密码;可先运行通讯录同步或手动绑定。",
|
||||
"searchBindings": "搜索用户名、姓名、工号或 wecom_userid",
|
||||
"systemSettings": "企业微信系统配置",
|
||||
"integrationCopyTitle": "企微后台复制助手",
|
||||
"integrationCopyDesc": "以下字段可直接复制到企业微信管理后台对应配置项。",
|
||||
@@ -324,6 +366,7 @@
|
||||
},
|
||||
"headers": {
|
||||
"user": "用户",
|
||||
"employeeId": "工号",
|
||||
"roleStatus": "角色/状态",
|
||||
"wecomUserId": "WeCom UserId",
|
||||
"unionId": "UnionId",
|
||||
|
||||
@@ -30,11 +30,13 @@
|
||||
"dbConnectionFailed": "数据库连接失败,请检查数据库服务是否运行。",
|
||||
"internalError": "服务器内部错误,请稍后重试。",
|
||||
"rememberMe": "30天内免登录",
|
||||
"forgotPasswordDesc": "输入您的邮箱以重置密码",
|
||||
"forgotPasswordDesc": "输入工号和用户名,重置链接将发送到您的企业微信",
|
||||
"findPassword": "找回密码",
|
||||
"announcements": "公告",
|
||||
"passwordResetEmailSent": "如果账号存在,重置链接已发送到您的邮箱。",
|
||||
"employeeIdRequired": "请输入工号",
|
||||
"passwordResetWecomSent": "若账号存在且已绑定企业微信,重置链接已发送到您的企业微信。",
|
||||
"passwordResetEmailSent": "若账号存在,重置链接已发送到您的邮箱。",
|
||||
"passwordResetRequestFailed": "请求密码重置失败",
|
||||
"announcements": "公告",
|
||||
"casdoorLogin": "Casdoor 登录",
|
||||
"casdoorErrors": {
|
||||
"invalidCredentials": "用户名或密码错误",
|
||||
@@ -160,5 +162,20 @@
|
||||
"employeeId": "工号",
|
||||
"phone": "手机号"
|
||||
}
|
||||
},
|
||||
"resetPassword": {
|
||||
"title": "重置密码",
|
||||
"desc": "请在下方输入新密码",
|
||||
"newPassword": "新密码",
|
||||
"confirmPassword": "确认密码",
|
||||
"newPasswordPlaceholder": "请输入新密码",
|
||||
"confirmPasswordPlaceholder": "请再次输入新密码",
|
||||
"submit": "重置密码",
|
||||
"submitting": "正在重置...",
|
||||
"backToLogin": "返回登录",
|
||||
"fillAllFields": "请填写所有字段",
|
||||
"passwordMismatch": "两次输入的密码不一致",
|
||||
"successRedirect": "密码重置成功,即将跳转到登录页...",
|
||||
"failed": "密码重置失败"
|
||||
}
|
||||
}
|
||||
@@ -17,5 +17,12 @@
|
||||
"info": "提示",
|
||||
"warning": "警告",
|
||||
"error": "错误"
|
||||
},
|
||||
"pagination": {
|
||||
"summary": "共 {total} 条,当前第 {page} / {pages} 页",
|
||||
"perPage": "每页",
|
||||
"itemsUnit": "条",
|
||||
"prevPage": "上一页",
|
||||
"nextPage": "下一页"
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,9 @@
|
||||
"USER_PHONE_EXISTS": "手机号已存在。",
|
||||
"USER_UNIQUENESS_CONFLICT": "数据唯一性冲突。",
|
||||
"SYSTEM_INTERNAL_ERROR": "服务器内部错误,请稍后重试。",
|
||||
"SYSTEM_HTTP_ERROR": "请求失败。"
|
||||
"SYSTEM_HTTP_ERROR": "请求失败。",
|
||||
"WECOM_RESET_NOT_CONFIGURED": "企微找回密码未配置,请在管理端「企业微信 → 系统配置」开启企微并填写 Corp ID、Agent ID、Secret。",
|
||||
"WECOM_NOTIFY_DISABLED": "企微通知已关闭,请在管理端「企业微信 → 通知设置」开启。",
|
||||
"WECOM_RESET_URL_NOT_CONFIGURED": "未配置公网访问地址,请在系统配置中填写公网基地址(WECOM_PUBLIC_BASE_URL)。"
|
||||
}
|
||||
}
|
||||
@@ -237,8 +237,50 @@
|
||||
}
|
||||
},
|
||||
"wecom": {
|
||||
"title": "企業微信綁定管理",
|
||||
"subtitle": "手動綁定/解綁企業微信帳號,並查看登入審計記錄",
|
||||
"title": "企業微信",
|
||||
"subtitle": "配置企微整合、同步 userid、管理綁定與登入審計",
|
||||
"nav": {
|
||||
"settings": "系統配置",
|
||||
"bindings": "綁定管理",
|
||||
"audits": "登入審計"
|
||||
},
|
||||
"overview": {
|
||||
"bound": "已綁定 userid",
|
||||
"unbound": "未綁定",
|
||||
"boundRate": "綁定率",
|
||||
"hint": "找回密碼",
|
||||
"hintDesc": "未綁定 wecom_userid 的用戶無法接收企微重設連結"
|
||||
},
|
||||
"sync": {
|
||||
"title": "通訊錄同步",
|
||||
"desc": "從企業微信通訊錄按工號回填 users.wecom_userid。",
|
||||
"permissionNote": "需在企微後台開通「通訊錄讀」與「發送應用消息」權限。",
|
||||
"employeeIdSource": "當前工號來源",
|
||||
"departmentId": "根部門 ID(可選)",
|
||||
"departmentIdPlaceholder": "留空表示全部部門",
|
||||
"preview": "預覽同步",
|
||||
"apply": "確認寫入",
|
||||
"previewDone": "預覽完成,請確認結果後再寫入",
|
||||
"previewFailed": "預覽同步失敗",
|
||||
"previewFirst": "請先預覽同步結果",
|
||||
"conflictsBlockApply": "存在衝突,請先人工處理後再寫入",
|
||||
"nothingToUpdate": "沒有需要更新的綁定",
|
||||
"applyConfirm": "確認將 {count} 條 userid 綁定寫入資料庫?",
|
||||
"applyDone": "已成功更新 {count} 條綁定",
|
||||
"applyFailed": "寫入同步結果失敗",
|
||||
"invalidDepartmentId": "部門 ID 必須為正整數",
|
||||
"previewTruncated": "僅展示前 20 條,共 {total} 條待更新",
|
||||
"conflictsTitle": "衝突明細",
|
||||
"occupiedBy": "userid 已被用戶 {user} 占用",
|
||||
"stats": {
|
||||
"wecomUsers": "企微成員",
|
||||
"localMatched": "本地匹配",
|
||||
"wouldUpdate": "待更新",
|
||||
"conflicts": "衝突"
|
||||
}
|
||||
},
|
||||
"bindingsHint": "未綁定 wecom_userid 的用戶無法使用企微找回密碼;可先執行通訊錄同步或手動綁定。",
|
||||
"searchBindings": "搜尋用戶名、姓名、工號或 wecom_userid",
|
||||
"systemSettings": "企業微信系統配置",
|
||||
"integrationCopyTitle": "企微後台複製助手",
|
||||
"integrationCopyDesc": "以下字段可直接複製到企業微信管理後台對應配置項。",
|
||||
@@ -328,6 +370,7 @@
|
||||
},
|
||||
"headers": {
|
||||
"user": "用戶",
|
||||
"employeeId": "工號",
|
||||
"roleStatus": "角色/狀態",
|
||||
"wecomUserId": "WeCom UserId",
|
||||
"unionId": "UnionId",
|
||||
|
||||
@@ -22,8 +22,11 @@
|
||||
"forgotPassword": "忘記密碼?",
|
||||
"rememberMe": "30天內免登入",
|
||||
"announcements": "公告",
|
||||
"forgotPasswordDesc": "輸入您的郵箱以重設密碼",
|
||||
"forgotPasswordDesc": "輸入工號與用戶名,重設連結將發送到您的企業微信",
|
||||
"findPassword": "找回密碼",
|
||||
"employeeIdRequired": "請輸入工號",
|
||||
"passwordResetWecomSent": "若帳號存在且已綁定企業微信,重設連結已發送到您的企業微信。",
|
||||
"passwordResetRequestFailed": "請求密碼重設失敗",
|
||||
"casdoorLogin": "Casdoor 登入",
|
||||
"casdoorErrors": {
|
||||
"invalidCredentials": "用戶名或密碼錯誤",
|
||||
@@ -143,6 +146,26 @@
|
||||
"success": "註冊申請已提交,請等待管理員審批",
|
||||
"failed": "註冊失敗",
|
||||
"inputError": "請輸入用戶名和密碼",
|
||||
"requestFailed": "請求失敗"
|
||||
"requestFailed": "請求失敗",
|
||||
"fields": {
|
||||
"realName": "真實姓名",
|
||||
"employeeId": "工號",
|
||||
"phone": "手機號"
|
||||
}
|
||||
},
|
||||
"resetPassword": {
|
||||
"title": "重設密碼",
|
||||
"desc": "請在下方輸入新密碼",
|
||||
"newPassword": "新密碼",
|
||||
"confirmPassword": "確認密碼",
|
||||
"newPasswordPlaceholder": "請輸入新密碼",
|
||||
"confirmPasswordPlaceholder": "請再次輸入新密碼",
|
||||
"submit": "重設密碼",
|
||||
"submitting": "正在重設...",
|
||||
"backToLogin": "返回登入",
|
||||
"fillAllFields": "請填寫所有欄位",
|
||||
"passwordMismatch": "兩次輸入的密碼不一致",
|
||||
"successRedirect": "密碼重設成功,即將跳轉到登入頁...",
|
||||
"failed": "密碼重設失敗"
|
||||
}
|
||||
}
|
||||
@@ -17,5 +17,12 @@
|
||||
"info": "提示",
|
||||
"warning": "警告",
|
||||
"error": "錯誤"
|
||||
},
|
||||
"pagination": {
|
||||
"summary": "共 {total} 條,當前第 {page} / {pages} 頁",
|
||||
"perPage": "每頁",
|
||||
"itemsUnit": "條",
|
||||
"prevPage": "上一頁",
|
||||
"nextPage": "下一頁"
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,9 @@
|
||||
"USER_PHONE_EXISTS": "手機號已存在。",
|
||||
"USER_UNIQUENESS_CONFLICT": "數據唯一性衝突。",
|
||||
"SYSTEM_INTERNAL_ERROR": "伺服器內部錯誤,請稍後重試。",
|
||||
"SYSTEM_HTTP_ERROR": "請求失敗。"
|
||||
"SYSTEM_HTTP_ERROR": "請求失敗。",
|
||||
"WECOM_RESET_NOT_CONFIGURED": "企微找回密碼未配置,請在管理端「企業微信 → 系統配置」開啟企微並填寫 Corp ID、Agent ID、Secret。",
|
||||
"WECOM_NOTIFY_DISABLED": "企微通知已關閉,請在管理端「企業微信 → 通知設定」開啟。",
|
||||
"WECOM_RESET_URL_NOT_CONFIGURED": "未配置公網訪問地址,請在系統配置中填寫公網基地址(WECOM_PUBLIC_BASE_URL)。"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* shared/components/PaginationBar.vue
|
||||
* 用途:通用偏移分页条(摘要、每页条数、页码按钮)。
|
||||
* 依赖:buildOffsetPageButtons、common.pagination i18n、components-ds 样式类。
|
||||
* 逻辑:父组件 v-model:page / v-model:page-size,服务端或客户端分页均可复用。
|
||||
*/
|
||||
import { computed } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { buildOffsetPageButtons } from '@/shared/composables/useOffsetPagination';
|
||||
|
||||
interface Props {
|
||||
total: number;
|
||||
page: number;
|
||||
pageSize: number;
|
||||
/** 服务端已算好的总页数;不传则按 total/pageSize 推算 */
|
||||
pages?: number;
|
||||
pageSizeOptions?: number[];
|
||||
/** 为 false 时强制隐藏;默认 total > 0 时显示 */
|
||||
visible?: boolean;
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
pages: 0,
|
||||
pageSizeOptions: () => [10, 20, 50, 100],
|
||||
visible: undefined,
|
||||
});
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'update:page', value: number): void;
|
||||
(e: 'update:pageSize', value: number): void;
|
||||
}>();
|
||||
|
||||
const { t } = useI18n();
|
||||
|
||||
const totalPages = computed(() => {
|
||||
if (props.pages > 0) return props.pages;
|
||||
const size = Math.max(1, Number(props.pageSize) || 20);
|
||||
const total = Math.max(0, Number(props.total) || 0);
|
||||
return Math.max(1, Math.ceil(total / size));
|
||||
});
|
||||
|
||||
const safePage = computed(() =>
|
||||
Math.min(Math.max(1, Number(props.page) || 1), totalPages.value),
|
||||
);
|
||||
|
||||
const pageButtons = computed(() => buildOffsetPageButtons(safePage.value, totalPages.value));
|
||||
|
||||
const showBar = computed(() => {
|
||||
if (props.visible !== undefined) return props.visible;
|
||||
return props.total > 0;
|
||||
});
|
||||
|
||||
/**
|
||||
* 跳转到指定页并通知父组件。
|
||||
* @param target - 目标页码(1-based)
|
||||
*/
|
||||
const onGoToPage = (target: number): void => {
|
||||
const next = Math.min(Math.max(1, target), totalPages.value);
|
||||
emit('update:page', next);
|
||||
};
|
||||
|
||||
/**
|
||||
* 上一页并通知父组件。
|
||||
*/
|
||||
const onPrevPage = (): void => {
|
||||
onGoToPage(safePage.value - 1);
|
||||
};
|
||||
|
||||
/**
|
||||
* 下一页并通知父组件。
|
||||
*/
|
||||
const onNextPage = (): void => {
|
||||
onGoToPage(safePage.value + 1);
|
||||
};
|
||||
|
||||
/**
|
||||
* 每页条数变更时重置到第 1 页。
|
||||
* @param size - 新的 pageSize
|
||||
*/
|
||||
const onPageSizeChange = (size: number): void => {
|
||||
emit('update:pageSize', size);
|
||||
emit('update:page', 1);
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div
|
||||
v-if="showBar"
|
||||
class="flex flex-col gap-3 rounded-2xl border border-default bg-surface px-4 py-3 md:flex-row md:items-center md:justify-between"
|
||||
>
|
||||
<div class="text-sm text-secondary">
|
||||
{{ t('common.pagination.summary', { total, page: safePage, pages: totalPages }) }}
|
||||
</div>
|
||||
<div class="flex flex-wrap items-center gap-2">
|
||||
<label class="flex items-center gap-2 text-xs text-secondary">
|
||||
<span>{{ t('common.pagination.perPage') }}</span>
|
||||
<span class="relative inline-flex items-center">
|
||||
<select
|
||||
:value="pageSize"
|
||||
class="admin-table-filter-input appearance-none pl-2 pr-7 py-1 text-xs leading-5"
|
||||
@change="onPageSizeChange(Number(($event.target as HTMLSelectElement).value))"
|
||||
>
|
||||
<option v-for="size in pageSizeOptions" :key="`page-size-${size}`" :value="size">
|
||||
{{ size }}
|
||||
</option>
|
||||
</select>
|
||||
<svg
|
||||
class="pointer-events-none absolute right-2 h-3.5 w-3.5 text-muted"
|
||||
viewBox="0 0 20 20"
|
||||
fill="currentColor"
|
||||
aria-hidden="true"
|
||||
>
|
||||
<path
|
||||
fill-rule="evenodd"
|
||||
d="M5.23 7.21a.75.75 0 0 1 1.06.02L10 11.168l3.71-3.938a.75.75 0 1 1 1.08 1.04l-4.25 4.5a.75.75 0 0 1-1.08 0l-4.25-4.5a.75.75 0 0 1 .02-1.06Z"
|
||||
clip-rule="evenodd"
|
||||
/>
|
||||
</svg>
|
||||
</span>
|
||||
<span>{{ t('common.pagination.itemsUnit') }}</span>
|
||||
</label>
|
||||
<button
|
||||
type="button"
|
||||
:disabled="safePage <= 1"
|
||||
class="admin-report-page-btn"
|
||||
@click="onPrevPage"
|
||||
>
|
||||
{{ t('common.pagination.prevPage') }}
|
||||
</button>
|
||||
<button
|
||||
v-for="btn in pageButtons"
|
||||
:key="`page-btn-${btn}`"
|
||||
type="button"
|
||||
:disabled="btn === -1"
|
||||
class="admin-report-page-btn"
|
||||
:class="btn === -1
|
||||
? 'border-transparent text-muted cursor-default opacity-100'
|
||||
: btn === safePage
|
||||
? 'admin-report-page-btn--active'
|
||||
: ''"
|
||||
@click="btn !== -1 && onGoToPage(btn)"
|
||||
>
|
||||
{{ btn === -1 ? '...' : btn }}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
:disabled="safePage >= totalPages"
|
||||
class="admin-report-page-btn"
|
||||
@click="onNextPage"
|
||||
>
|
||||
{{ t('common.pagination.nextPage') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* shared/composables/useDialogBackdropClose.ts
|
||||
* 用途:弹窗遮罩点击关闭,避免输入框拖选文字时误触关闭。
|
||||
* 依赖:无。
|
||||
* 逻辑:仅当 pointerdown 与 pointerup 均发生在遮罩自身时才触发 onClose。
|
||||
*/
|
||||
|
||||
export interface DialogBackdropCloseHandlers {
|
||||
onBackdropPointerDown: (event: PointerEvent) => void;
|
||||
onBackdropPointerUp: (event: PointerEvent) => void;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建遮罩关闭处理器,防止从输入框拖选到遮罩外时误关弹窗。
|
||||
* @param onClose - 遮罩有效点击时的关闭回调
|
||||
* @returns pointerdown / pointerup 处理器
|
||||
*/
|
||||
export function createDialogBackdropCloseHandler(onClose: () => void): DialogBackdropCloseHandlers {
|
||||
let pointerDownOnBackdrop = false;
|
||||
|
||||
/**
|
||||
* 记录是否在遮罩上按下指针。
|
||||
* @param event - pointerdown 事件
|
||||
*/
|
||||
const onBackdropPointerDown = (event: PointerEvent): void => {
|
||||
pointerDownOnBackdrop = event.target === event.currentTarget;
|
||||
};
|
||||
|
||||
/**
|
||||
* 仅在遮罩上完成按下+抬起时关闭弹窗。
|
||||
* @param event - pointerup 事件
|
||||
*/
|
||||
const onBackdropPointerUp = (event: PointerEvent): void => {
|
||||
if (pointerDownOnBackdrop && event.target === event.currentTarget) {
|
||||
onClose();
|
||||
}
|
||||
pointerDownOnBackdrop = false;
|
||||
};
|
||||
|
||||
return { onBackdropPointerDown, onBackdropPointerUp };
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
/**
|
||||
* shared/composables/useOffsetPagination.ts
|
||||
* 用途:管理端偏移分页的页码计算与导航辅助。
|
||||
* 依赖:vue computed/ref/unref。
|
||||
* 逻辑:PaginationBar、报表页等复用 pageButtons 与翻页方法。
|
||||
*/
|
||||
import { computed, unref, type ComputedRef, type Ref } from 'vue';
|
||||
|
||||
export interface UseOffsetPaginationOptions {
|
||||
page: Ref<number>;
|
||||
pageSize: Ref<number>;
|
||||
total: Ref<number> | ComputedRef<number>;
|
||||
/** 服务端已计算总页数时传入,优先于 total/pageSize 推算 */
|
||||
pages?: Ref<number> | ComputedRef<number>;
|
||||
}
|
||||
|
||||
const DEFAULT_PAGE_SIZE_OPTIONS = [10, 20, 50, 100] as const;
|
||||
|
||||
/**
|
||||
* 根据当前页与总页数生成带省略号的页码按钮序列(-1 表示 ...)。
|
||||
* 核心逻辑:页数较多时开头仅展示 1–3 页,末尾仅展示最后 3 页,中间展示当前页邻域。
|
||||
* @param current - 当前页(1-based)
|
||||
* @param totalPages - 总页数
|
||||
*/
|
||||
export function buildOffsetPageButtons(current: number, totalPages: number): number[] {
|
||||
const total = Math.max(1, totalPages);
|
||||
const page = Math.min(Math.max(1, current), total);
|
||||
if (total <= 5) return Array.from({ length: total }, (_, i) => i + 1);
|
||||
if (page <= 3) return [1, 2, 3, -1, total];
|
||||
if (page >= total - 2) return [1, -1, total - 2, total - 1, total];
|
||||
return [1, -1, page - 1, page, page + 1, -1, total];
|
||||
}
|
||||
|
||||
/**
|
||||
* 提供偏移分页的 totalPages、range 与翻页辅助。
|
||||
* @param options.page - 当前页码 ref
|
||||
* @param options.pageSize - 每页条数 ref
|
||||
* @param options.total - 总条数 ref/computed
|
||||
* @param options.pages - 可选,服务端返回的总页数
|
||||
*/
|
||||
export function useOffsetPagination(options: UseOffsetPaginationOptions) {
|
||||
const totalPages = computed(() => {
|
||||
const explicit = options.pages ? Math.max(1, Number(unref(options.pages)) || 1) : 0;
|
||||
if (explicit > 0) return explicit;
|
||||
const size = Math.max(1, Number(unref(options.pageSize)) || 20);
|
||||
const total = Math.max(0, Number(unref(options.total)) || 0);
|
||||
return Math.max(1, Math.ceil(total / size));
|
||||
});
|
||||
|
||||
const safePage = computed(() =>
|
||||
Math.min(Math.max(1, Number(unref(options.page)) || 1), totalPages.value),
|
||||
);
|
||||
|
||||
const rangeStart = computed(() => {
|
||||
const total = Math.max(0, Number(unref(options.total)) || 0);
|
||||
if (total === 0) return 0;
|
||||
const size = Math.max(1, Number(unref(options.pageSize)) || 20);
|
||||
return (safePage.value - 1) * size + 1;
|
||||
});
|
||||
|
||||
const rangeEnd = computed(() => {
|
||||
const total = Math.max(0, Number(unref(options.total)) || 0);
|
||||
if (total === 0) return 0;
|
||||
const size = Math.max(1, Number(unref(options.pageSize)) || 20);
|
||||
return Math.min(rangeStart.value + size - 1, total);
|
||||
});
|
||||
|
||||
const pageButtons = computed(() => buildOffsetPageButtons(safePage.value, totalPages.value));
|
||||
|
||||
/**
|
||||
* 跳转到指定页,自动 clamp 到合法范围。
|
||||
* @param page - 目标页码
|
||||
*/
|
||||
const goToPage = (page: number): void => {
|
||||
options.page.value = Math.min(Math.max(1, page), totalPages.value);
|
||||
};
|
||||
|
||||
/** 上一页 */
|
||||
const prevPage = (): void => {
|
||||
goToPage(safePage.value - 1);
|
||||
};
|
||||
|
||||
/** 下一页 */
|
||||
const nextPage = (): void => {
|
||||
goToPage(safePage.value + 1);
|
||||
};
|
||||
|
||||
return {
|
||||
totalPages,
|
||||
safePage,
|
||||
rangeStart,
|
||||
rangeEnd,
|
||||
pageButtons,
|
||||
goToPage,
|
||||
prevPage,
|
||||
nextPage,
|
||||
pageSizeOptions: DEFAULT_PAGE_SIZE_OPTIONS,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
/**
|
||||
* shared/types/pagination.types.ts
|
||||
* 用途:前后端通用的偏移分页响应结构。
|
||||
* 依赖:无。
|
||||
* 逻辑:分页 API 与 PaginationBar 等组件共享本类型。
|
||||
*/
|
||||
|
||||
export interface PaginatedResult<T> {
|
||||
items: T[];
|
||||
total: number;
|
||||
page: number;
|
||||
page_size: number;
|
||||
pages: number;
|
||||
}
|
||||
Reference in new issue
Block a user