diff --git a/frontend/src/api/Api.ts b/frontend/src/api/Api.ts index a69561c8..bf53dc8a 100644 --- a/frontend/src/api/Api.ts +++ b/frontend/src/api/Api.ts @@ -53,6 +53,7 @@ export enum ConstsNotifyChannelKind { NotifyChannelFeishu = "feishu", NotifyChannelWeCom = "wecom", NotifyChannelWebhook = "webhook", + NotifyChannelWechatMP = "wechat_mp", } export enum ConstsNotifyEventType { @@ -342,6 +343,12 @@ export interface DomainAvailableModelResp { output_price?: number; } +export interface DomainBindQRCodeResp { + expire_seconds?: number; + qrcode_url?: string; + ticket?: string; +} + export interface DomainBranch { name?: string; } @@ -397,6 +404,7 @@ export interface DomainCollaborator { status?: ConstsUserStatus; team?: DomainTeam; token?: string; + wechat_mp_bound?: boolean; } export interface DomainCreateCollaboratorItem { @@ -669,6 +677,13 @@ export interface DomainImage { remark?: string; } +export interface DomainImportLicenseResp { + /** license 唯一 ID */ + license_id?: string; + /** 导入后的授权状态 */ + state?: DomainLicenseState; +} + export interface DomainInstallCommand { command?: string; } @@ -687,6 +702,45 @@ export interface DomainInvitationListResp { page?: Dbv2PageInfo; } +export interface DomainLicenseMachineCodeResp { + /** 机器码生成时间,RFC3339 */ + generated_at?: string; + /** 客户部署实例 ID */ + installation_id?: string; + /** 产品标识,首版固定为 monkeycode-enterprise */ + product?: DomainLicenseProduct; + /** 当前私有化产品版本 */ + product_version?: string; + /** 协议版本,首版固定为 1 */ + version?: number; +} + +export enum DomainLicenseProduct { + LicenseProductMonkeyCodeEnterprise = "monkeycode-enterprise", +} + +export enum DomainLicenseState { + LicenseStateMissing = "missing", + LicenseStateActive = "active", + LicenseStateExpired = "expired", + LicenseStateInvalid = "invalid", +} + +export interface DomainLicenseStatusResp { + /** 客户名称 */ + customer_name?: string; + /** 授权过期时间,RFC3339 */ + expires_at?: string; + /** 当前生效 license ID */ + license_id?: string; + /** 授权席位数 */ + seats?: number; + /** 当前授权状态 */ + state?: DomainLicenseState; + /** 当前已使用席位数 */ + used_seats?: number; +} + export interface DomainListAuditsResponse { audits?: DomainAudit[]; page?: Dbv2Cursor; @@ -1727,6 +1781,7 @@ export interface DomainUser { status?: ConstsUserStatus; team?: DomainTeam; token?: string; + wechat_mp_bound?: boolean; } export interface DomainUserIdentity { @@ -1811,6 +1866,7 @@ export interface GitInChaitinNetAiMonkeycodeMonkeycodeAiEntTypesCondition { type?: GitInChaitinNetAiMonkeycodeMonkeycodeAiEntTypesConditionType; } +/** @format int32 */ export enum GitInChaitinNetAiMonkeycodeMonkeycodeAiEntTypesConditionStatus { ConditionStatusCONDITIONSTATUSUNKNOWN = 0, ConditionStatusCONDITIONSTATUSINPROGRESS = 1, @@ -2278,6 +2334,88 @@ export class Api extends HttpClient + this.request< + GitInChaitinNetGoDevWebResp & { + data?: DomainImportLicenseResp; + }, + GitInChaitinNetGoDevWebResp + >({ + path: `/api/v1/license/import`, + method: "POST", + body: data, + secure: true, + type: ContentType.FormData, + format: "json", + ...params, + }), + + /** + * @description 私有化部署导出 machine-code.json。SaaS 环境仅用于生成 Swagger 文档,实际业务由 MonkeyCodePro 实现。 + * + * @tags 【License】License + * @name V1LicenseMachineCodeList + * @summary 导出机器码 + * @request GET:/api/v1/license/machine-code + * @secure + */ + v1LicenseMachineCodeList: (params: RequestParams = {}) => + this.request< + GitInChaitinNetGoDevWebResp & { + data?: DomainLicenseMachineCodeResp; + }, + GitInChaitinNetGoDevWebResp + >({ + path: `/api/v1/license/machine-code`, + method: "GET", + secure: true, + type: ContentType.Json, + format: "json", + ...params, + }), + + /** + * @description 私有化部署查看当前 license 状态。SaaS 环境仅用于生成 Swagger 文档,实际业务由 MonkeyCodePro 实现。 + * + * @tags 【License】License + * @name V1LicenseStatusList + * @summary 查看 license 状态 + * @request GET:/api/v1/license/status + * @secure + */ + v1LicenseStatusList: (params: RequestParams = {}) => + this.request< + GitInChaitinNetGoDevWebResp & { + data?: DomainLicenseStatusResp; + }, + GitInChaitinNetGoDevWebResp + >({ + path: `/api/v1/license/status`, + method: "GET", + secure: true, + type: ContentType.Json, + format: "json", + ...params, + }), + /** * @description 绑定第三方平台 * @@ -6518,5 +6656,48 @@ export class Api extends HttpClient + this.request({ + path: `/api/v1/users/wechat-mp/bind`, + method: "DELETE", + secure: true, + type: ContentType.Json, + format: "json", + ...params, + }), + + /** + * @description 为当前登录用户创建微信公众号绑定临时二维码,用户扫码关注/扫码后完成绑定 + * + * @tags 【用户】微信公众号推送 + * @name V1UsersWechatMpBindQrcodeCreate + * @summary 创建公众号绑定二维码 + * @request POST:/api/v1/users/wechat-mp/bind-qrcode + * @secure + */ + v1UsersWechatMpBindQrcodeCreate: (params: RequestParams = {}) => + this.request< + GithubComGoYokoWebResp & { + data?: DomainBindQRCodeResp; + }, + GithubComGoYokoWebResp + >({ + path: `/api/v1/users/wechat-mp/bind-qrcode`, + method: "POST", + secure: true, + type: ContentType.Json, + format: "json", + ...params, + }), }; } diff --git a/frontend/src/components/console/data-provider.tsx b/frontend/src/components/console/data-provider.tsx index ed4224e3..a53965ec 100644 --- a/frontend/src/components/console/data-provider.tsx +++ b/frontend/src/components/console/data-provider.tsx @@ -1,8 +1,9 @@ import { ConstsGitPlatform, ConstsOwnerType, type DomainGitIdentity, type DomainHost, type DomainImage, type DomainModel, type DomainProject, type DomainProjectTask, type DomainSubscriptionResp, type DomainUser, type DomainVirtualMachine } from '@/api/Api'; +import { WechatMpBindDialog } from '@/components/console/wechat-mp-bind-dialog'; import { getImageShortName } from '@/utils/common'; import { IS_OFFLINE_EDITION } from '@/utils/edition'; import { apiRequest } from '@/utils/requestUtils'; -import React, { createContext, useCallback, useContext, useEffect, useMemo, useState } from 'react'; +import React, { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react'; import { toast } from 'sonner'; type CommonData = { @@ -62,6 +63,8 @@ const DataContext = createContext(null); export const DataProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => { const [userInfo, setUserInfo] = useState({}); + const [wechatMpBindDialogOpen, setWechatMpBindDialogOpen] = useState(false); + const checkedWechatMpBindRef = useRef(false); const [hosts, setHosts] = useState([]); const [hostsInited, setHostsInited] = useState(false); @@ -101,6 +104,10 @@ export const DataProvider: React.FC<{ children: React.ReactNode }> = ({ children await apiRequest('v1UsersStatusList', {}, [], (resp) => { nextUser = resp.data?.user || {} setUserInfo(nextUser); + if (resp.code === 0 && !IS_OFFLINE_EDITION && !checkedWechatMpBindRef.current) { + checkedWechatMpBindRef.current = true; + setWechatMpBindDialogOpen(nextUser.wechat_mp_bound !== true); + } }) return nextUser } @@ -404,7 +411,8 @@ export const DataProvider: React.FC<{ children: React.ReactNode }> = ({ children }, []); return ( - + = ({ children historicalTasks: historicalTasks, loadingHistoricalTasks: loadingHistoricalTasks, reloadHistoricalTasks: fetchHistoricalTasks, - }}> - {children} - + }}> + {children} + + + ); }; diff --git a/frontend/src/components/console/settings/notifications.tsx b/frontend/src/components/console/settings/notifications.tsx index 7edb04a5..37ad4794 100644 --- a/frontend/src/components/console/settings/notifications.tsx +++ b/frontend/src/components/console/settings/notifications.tsx @@ -58,6 +58,7 @@ import { Empty, EmptyContent, EmptyDescription, EmptyHeader, EmptyMedia } from " /** 接收端类型(UI 用,wechat_work 映射到 API 的 wecom) */ export type ReceiverType = "dingtalk" | "feishu" | "wechat_work" | "webhook" +type ApiReceiverKind = "dingtalk" | "feishu" | "wecom" | "webhook" const RECEIVER_TYPE_OPTIONS: { value: ReceiverType; label: string; icon: React.ReactNode }[] = [ { value: "dingtalk", label: "钉钉机器人", icon: }, @@ -66,19 +67,19 @@ const RECEIVER_TYPE_OPTIONS: { value: ReceiverType; label: string; icon: React.R { value: "webhook", label: "Webhook", icon: }, ] -const RECEIVER_TO_API_KIND: Record = { +const RECEIVER_TO_API_KIND: Record = { dingtalk: ConstsNotifyChannelKind.NotifyChannelDingTalk, feishu: ConstsNotifyChannelKind.NotifyChannelFeishu, wechat_work: ConstsNotifyChannelKind.NotifyChannelWeCom, webhook: ConstsNotifyChannelKind.NotifyChannelWebhook, } -/** UI ReceiverType -> API ConstsNotifyChannelKind */ -function toApiKind(type: ReceiverType): ConstsNotifyChannelKind { +/** UI ReceiverType -> API notify channel kind */ +function toApiKind(type: ReceiverType): ApiReceiverKind { return RECEIVER_TO_API_KIND[type] } -const API_KIND_TO_RECEIVER: Record = { +const API_KIND_TO_RECEIVER: Partial> = { [ConstsNotifyChannelKind.NotifyChannelDingTalk]: "dingtalk", [ConstsNotifyChannelKind.NotifyChannelFeishu]: "feishu", [ConstsNotifyChannelKind.NotifyChannelWeCom]: "wechat_work", diff --git a/frontend/src/components/console/wechat-mp-bind-dialog.tsx b/frontend/src/components/console/wechat-mp-bind-dialog.tsx new file mode 100644 index 00000000..2e5cc43f --- /dev/null +++ b/frontend/src/components/console/wechat-mp-bind-dialog.tsx @@ -0,0 +1,93 @@ +import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert" +import { + Dialog, + DialogContent, + DialogHeader, + DialogTitle, +} from "@/components/ui/dialog" +import { Spinner } from "@/components/ui/spinner" +import { apiRequest } from "@/utils/requestUtils" +import { useCallback, useEffect, useState } from "react" +import { toast } from "sonner" + +type WechatMpBindDialogProps = { + open: boolean + onOpenChange: (open: boolean) => void +} + +export function WechatMpBindDialog({ open, onOpenChange }: WechatMpBindDialogProps) { + const [qrcodeUrl, setQrcodeUrl] = useState("") + const [loading, setLoading] = useState(false) + const [error, setError] = useState("") + + const fetchQrcode = useCallback(async () => { + setLoading(true) + setError("") + try { + await apiRequest("v1UsersWechatMpBindQrcodeCreate", {}, [], (resp) => { + if (resp.code === 0 && resp.data?.qrcode_url) { + setQrcodeUrl(resp.data.qrcode_url) + return + } + + const message = resp.message || "获取绑定二维码失败" + setError(message) + toast.error(message) + }, () => { + setError("获取绑定二维码失败") + }) + } finally { + setLoading(false) + } + }, []) + + useEffect(() => { + if (!open || qrcodeUrl || loading) { + return + } + + fetchQrcode() + }, [fetchQrcode, loading, open, qrcodeUrl]) + + return ( + + + + 订阅重要通知 + + +
+
+ {loading ? ( + + ) : qrcodeUrl ? ( + 微信公众号绑定二维码 + ) : ( +
+ {error || "二维码暂不可用"} +
+ )} +
+ + + 微信扫码关注公众号 + + + 扫码订阅任务通知,避免任务自动终止后丢失工作文件。 + + + + + 专属二维码,请勿与他人分享 + + +
+ +
+
+ ) +} diff --git a/frontend/src/components/manager/team-notifications.tsx b/frontend/src/components/manager/team-notifications.tsx index e4954f1c..2ca3d897 100644 --- a/frontend/src/components/manager/team-notifications.tsx +++ b/frontend/src/components/manager/team-notifications.tsx @@ -66,6 +66,7 @@ import { Empty, EmptyContent, EmptyDescription, EmptyHeader, EmptyMedia } from " /** 接收端类型(UI 用,wechat_work 映射到 API 的 wecom) */ type ReceiverType = "dingtalk" | "feishu" | "wechat_work" | "webhook" +type ApiReceiverKind = "dingtalk" | "feishu" | "wecom" | "webhook" const RECEIVER_TYPE_OPTIONS: { value: ReceiverType; label: string; icon: React.ReactNode }[] = [ { value: "dingtalk", label: "钉钉机器人", icon: }, @@ -74,18 +75,18 @@ const RECEIVER_TYPE_OPTIONS: { value: ReceiverType; label: string; icon: React.R { value: "webhook", label: "Webhook", icon: }, ] -const RECEIVER_TO_API_KIND: Record = { +const RECEIVER_TO_API_KIND: Record = { dingtalk: ConstsNotifyChannelKind.NotifyChannelDingTalk, feishu: ConstsNotifyChannelKind.NotifyChannelFeishu, wechat_work: ConstsNotifyChannelKind.NotifyChannelWeCom, webhook: ConstsNotifyChannelKind.NotifyChannelWebhook, } -function toApiKind(type: ReceiverType): ConstsNotifyChannelKind { +function toApiKind(type: ReceiverType): ApiReceiverKind { return RECEIVER_TO_API_KIND[type] } -const API_KIND_TO_RECEIVER: Record = { +const API_KIND_TO_RECEIVER: Partial> = { [ConstsNotifyChannelKind.NotifyChannelDingTalk]: "dingtalk", [ConstsNotifyChannelKind.NotifyChannelFeishu]: "feishu", [ConstsNotifyChannelKind.NotifyChannelWeCom]: "wechat_work",