feat: prompt users to subscribe task notifications

This commit is contained in:
monster committed 2026-05-26 18:05:17 +08:00
1 parent 9a6a91de4a
commit 3ef4e87f31
5 files changed
+301 -12

No files matched your search

+181
View File
@@ -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<SecurityDataType extends unknown> extends HttpClient<SecurityDa
...params,
}),
/**
* @description 私有化部署直接上传 license.lic 文件。SaaS 环境仅用于生成 Swagger 文档,实际业务由 MonkeyCodePro 实现。
*
* @tags 【License】License
* @name V1LicenseImportCreate
* @summary 导入 license
* @request POST:/api/v1/license/import
* @secure
*/
v1LicenseImportCreate: (
data: {
/**
* license.lic 文件
* @format binary
*/
file: File;
},
params: RequestParams = {},
) =>
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<SecurityDataType extends unknown> extends HttpClient<SecurityDa
format: "json",
...params,
}),
/**
* @description 解除当前用户与微信公众号 OpenID 的绑定关系
*
* @tags 【用户】微信公众号推送
* @name V1UsersWechatMpBindDelete
* @summary 解除公众号绑定
* @request DELETE:/api/v1/users/wechat-mp/bind
* @secure
*/
v1UsersWechatMpBindDelete: (params: RequestParams = {}) =>
this.request<GithubComGoYokoWebResp, GithubComGoYokoWebResp>({
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,
}),
};
}
@@ -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<CommonData | null>(null);
export const DataProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => {
const [userInfo, setUserInfo] = useState<DomainUser>({});
const [wechatMpBindDialogOpen, setWechatMpBindDialogOpen] = useState(false);
const checkedWechatMpBindRef = useRef(false);
const [hosts, setHosts] = useState<DomainHost[]>([]);
const [hostsInited, setHostsInited] = useState<boolean>(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 (
<DataContext.Provider value={{
<>
<DataContext.Provider value={{
user: userInfo,
reloadUser: fetchUserInfo,
@@ -453,9 +461,14 @@ export const DataProvider: React.FC<{ children: React.ReactNode }> = ({ children
historicalTasks: historicalTasks,
loadingHistoricalTasks: loadingHistoricalTasks,
reloadHistoricalTasks: fetchHistoricalTasks,
}}>
{children}
</DataContext.Provider>
}}>
{children}
</DataContext.Provider>
<WechatMpBindDialog
open={wechatMpBindDialogOpen}
onOpenChange={setWechatMpBindDialogOpen}
/>
</>
);
};
@@ -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: <Icon name="dingtalk" className="size-4" /> },
@@ -66,19 +67,19 @@ const RECEIVER_TYPE_OPTIONS: { value: ReceiverType; label: string; icon: React.R
{ value: "webhook", label: "Webhook", icon: <Link2 className="size-4" /> },
]
const RECEIVER_TO_API_KIND: Record<ReceiverType, ConstsNotifyChannelKind> = {
const RECEIVER_TO_API_KIND: Record<ReceiverType, ApiReceiverKind> = {
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<ConstsNotifyChannelKind, ReceiverType> = {
const API_KIND_TO_RECEIVER: Partial<Record<ConstsNotifyChannelKind, ReceiverType>> = {
[ConstsNotifyChannelKind.NotifyChannelDingTalk]: "dingtalk",
[ConstsNotifyChannelKind.NotifyChannelFeishu]: "feishu",
[ConstsNotifyChannelKind.NotifyChannelWeCom]: "wechat_work",
@@ -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 (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent className="sm:max-w-sm">
<DialogHeader>
<DialogTitle>订阅重要通知</DialogTitle>
</DialogHeader>
<div className="flex flex-col items-center gap-4">
<div className="flex size-52 items-center justify-center rounded-lg border bg-background p-1">
{loading ? (
<Spinner className="size-6 text-muted-foreground" />
) : qrcodeUrl ? (
<img
src={qrcodeUrl}
alt="微信公众号绑定二维码"
className="size-full rounded-sm object-contain"
/>
) : (
<div className="px-4 text-center text-sm text-muted-foreground">
{error || "二维码暂不可用"}
</div>
)}
</div>
<Alert className="py-2">
<AlertTitle className="text-xs">
微信扫码关注公众号
</AlertTitle>
<AlertDescription className="text-xs">
扫码订阅任务通知,避免任务自动终止后丢失工作文件。
</AlertDescription>
</Alert>
<Alert variant="destructive" className="py-2">
<AlertDescription className="text-xs">
专属二维码,请勿与他人分享
</AlertDescription>
</Alert>
</div>
</DialogContent>
</Dialog>
)
}
@@ -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: <Icon name="dingtalk" className="size-4" /> },
@@ -74,18 +75,18 @@ const RECEIVER_TYPE_OPTIONS: { value: ReceiverType; label: string; icon: React.R
{ value: "webhook", label: "Webhook", icon: <Link2 className="size-4" /> },
]
const RECEIVER_TO_API_KIND: Record<ReceiverType, ConstsNotifyChannelKind> = {
const RECEIVER_TO_API_KIND: Record<ReceiverType, ApiReceiverKind> = {
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<ConstsNotifyChannelKind, ReceiverType> = {
const API_KIND_TO_RECEIVER: Partial<Record<ConstsNotifyChannelKind, ReceiverType>> = {
[ConstsNotifyChannelKind.NotifyChannelDingTalk]: "dingtalk",
[ConstsNotifyChannelKind.NotifyChannelFeishu]: "feishu",
[ConstsNotifyChannelKind.NotifyChannelWeCom]: "wechat_work",