整合数据

This commit is contained in:
李志强 2026-06-16 01:30:39 +08:00
parent 761a5cb69c
commit c0f70823a9
31 changed files with 4385 additions and 893 deletions

View File

@ -463,7 +463,7 @@ h3 {
background-color: rgba(60, 60, 60, 0.8) !important;
}
color: #ffffff !important;
border-left: 3px solid #4f84ff;
/* border-left: 3px solid #4f84ff; */
margin-left: -3px;
.menu-icon {
@ -504,7 +504,7 @@ h3 {
.el-menu-item.is-active {
background: rgba(219, 148, 148, 0.8) !important;
color: var(--el-color-primary-light-3) !important;
border-left-color: var(--el-color-primary);
/* border-left-color: var(--el-color-primary); */
.menu-icon {
color: var(--el-color-primary);

View File

@ -0,0 +1,503 @@
package controllers
import (
"encoding/json"
"strings"
"time"
"server/models"
"github.com/beego/beego/v2/client/orm"
beego "github.com/beego/beego/v2/server/web"
)
// ApiCursorEquipmentController 开放接口:登录器上报 Cursor 设备信息(无需登录)
type ApiCursorEquipmentController struct {
beego.Controller
}
type cursorEquipmentReportPayload struct {
DeviceInfo string `json:"deviceInfo"`
DeviceInfoSnake string `json:"device_info"`
MachineCode string `json:"machineCode"`
MachineCodeSnake string `json:"machine_code"`
Status *int8 `json:"status"`
System string `json:"system"`
Version string `json:"version"`
BindAccount string `json:"bindAccount"`
BindAccountSnake string `json:"bind_account"`
OwnerUserID *uint64 `json:"ownerUserId"`
OwnerUserIDSnake *uint64 `json:"owner_user_id"`
OwnerUserName string `json:"ownerUserName"`
OwnerUserNameSnake string `json:"owner_user_name"`
ActivationTime string `json:"activationTime"`
ActivationTimeSnake string `json:"activation_time"`
ExpireTime string `json:"expireTime"`
ExpireTimeSnake string `json:"expire_time"`
Remark string `json:"remark"`
}
type cursorEquipmentActivatePayload struct {
Code string `json:"code"`
ActivationCode string `json:"activationCode"`
ActivationCodeSnake string `json:"activation_code"`
DeviceInfo string `json:"deviceInfo"`
DeviceInfoSnake string `json:"device_info"`
MachineCode string `json:"machineCode"`
MachineCodeSnake string `json:"machine_code"`
System string `json:"system"`
Version string `json:"version"`
BindAccount string `json:"bindAccount"`
BindAccountSnake string `json:"bind_account"`
OwnerUserID *uint64 `json:"ownerUserId"`
OwnerUserIDSnake *uint64 `json:"owner_user_id"`
OwnerUserName string `json:"ownerUserName"`
OwnerUserNameSnake string `json:"owner_user_name"`
Remark string `json:"remark"`
}
func cursorFirstNonEmpty(values ...string) string {
for _, v := range values {
if s := strings.TrimSpace(v); s != "" {
return s
}
}
return ""
}
func cursorStringPtr(value string) *string {
value = strings.TrimSpace(value)
if value == "" {
return nil
}
return &value
}
func cursorParseTimePtr(value string) *time.Time {
value = strings.TrimSpace(value)
if value == "" {
return nil
}
layouts := []string{
time.RFC3339,
"2006-01-02 15:04:05",
"2006-01-02 15:04",
"2006-01-02",
}
for _, layout := range layouts {
if t, err := time.ParseInLocation(layout, value, time.Local); err == nil {
return &t
}
}
return nil
}
func cursorValidStatus(status int8) bool {
return status == 0 || status == 1 || status == 2 || status == 3
}
func (c *ApiCursorEquipmentController) jsonResult(code int, msg string, data interface{}) {
resp := map[string]interface{}{"code": code, "msg": msg}
if data != nil {
resp["data"] = data
}
c.Data["json"] = resp
_ = c.ServeJSON()
}
// Report POST /api/cursor/equipment/report
//
// JSON 示例:
//
// {
// "machineCode": "ABC-123",
// "deviceInfo": "CPU/RAM/磁盘等设备信息",
// "system": "Windows",
// "version": "1.0.0",
// "bindAccount": "user@example.com",
// "ownerUserId": 1,
// "ownerUserName": "张三",
// "activationTime": "2026-06-15 22:00:00",
// "expireTime": "2026-07-15 22:00:00",
// "remark": "登录器上报"
// }
//
// 兼容 snake_case 字段,例如 machine_code、device_info、bind_account。
func (c *ApiCursorEquipmentController) Report() {
var p cursorEquipmentReportPayload
if err := json.Unmarshal(c.Ctx.Input.RequestBody, &p); err != nil {
c.jsonResult(400, "参数错误", nil)
return
}
machineCode := cursorFirstNonEmpty(p.MachineCode, p.MachineCodeSnake)
if machineCode == "" {
c.jsonResult(400, "缺少参数 machineCode/machine_code机器码", nil)
return
}
if len(machineCode) > 128 {
c.jsonResult(400, "机器码长度不能超过 128 个字符", nil)
return
}
status := int8(0)
statusProvided := p.Status != nil
if statusProvided {
status = *p.Status
if !cursorValidStatus(status) {
c.jsonResult(400, "状态不合法支持0 未激活、1 激活中、2 已过期、3 已禁用", nil)
return
}
}
deviceInfo := cursorFirstNonEmpty(p.DeviceInfo, p.DeviceInfoSnake)
system := cursorFirstNonEmpty(p.System)
version := cursorFirstNonEmpty(p.Version)
bindAccount := cursorFirstNonEmpty(p.BindAccount, p.BindAccountSnake)
ownerUserID := p.OwnerUserID
if ownerUserID == nil {
ownerUserID = p.OwnerUserIDSnake
}
ownerUserName := cursorFirstNonEmpty(p.OwnerUserName, p.OwnerUserNameSnake)
activationTime := cursorParseTimePtr(cursorFirstNonEmpty(p.ActivationTime, p.ActivationTimeSnake))
expireTime := cursorParseTimePtr(cursorFirstNonEmpty(p.ExpireTime, p.ExpireTimeSnake))
remark := cursorFirstNonEmpty(p.Remark)
now := time.Now()
var row models.PlatformCursorEquipment
err := models.Orm.QueryTable(new(models.PlatformCursorEquipment)).
Filter("machine_code", machineCode).
Filter("delete_time__isnull", true).
One(&row)
created := false
if err == orm.ErrNoRows {
row = models.PlatformCursorEquipment{
MachineCode: machineCode,
Status: status,
DeviceInfo: cursorStringPtr(deviceInfo),
System: cursorStringPtr(system),
Version: cursorStringPtr(version),
BindAccount: cursorStringPtr(bindAccount),
OwnerUserID: ownerUserID,
OwnerUserName: cursorStringPtr(ownerUserName),
ActivationTime: activationTime,
ExpireTime: expireTime,
Remark: cursorStringPtr(remark),
CreateTime: now,
}
id, insertErr := models.Orm.Insert(&row)
if insertErr != nil {
c.jsonResult(500, "设备信息保存失败", nil)
return
}
row.ID = uint64(id)
created = true
} else if err != nil {
c.jsonResult(500, "设备信息查询失败", nil)
return
} else {
update := map[string]interface{}{
"device_info": cursorStringPtr(deviceInfo),
"system": cursorStringPtr(system),
"version": cursorStringPtr(version),
"bind_account": cursorStringPtr(bindAccount),
"owner_user_id": ownerUserID,
"owner_user_name": cursorStringPtr(ownerUserName),
"activation_time": activationTime,
"expire_time": expireTime,
"remark": cursorStringPtr(remark),
"update_time": now,
}
if statusProvided {
update["status"] = status
row.Status = status
}
if _, updateErr := models.Orm.QueryTable(new(models.PlatformCursorEquipment)).
Filter("id", row.ID).
Update(update); updateErr != nil {
c.jsonResult(500, "设备信息更新失败", nil)
return
}
row.DeviceInfo = cursorStringPtr(deviceInfo)
row.System = cursorStringPtr(system)
row.Version = cursorStringPtr(version)
row.BindAccount = cursorStringPtr(bindAccount)
row.OwnerUserID = ownerUserID
row.OwnerUserName = cursorStringPtr(ownerUserName)
row.ActivationTime = activationTime
row.ExpireTime = expireTime
row.Remark = cursorStringPtr(remark)
row.UpdateTime = &now
}
c.jsonResult(200, "success", map[string]interface{}{
"id": row.ID,
"machineCode": row.MachineCode,
"status": row.Status,
"created": created,
})
}
// ActivateByCode POST /api/cursor/equipment/activateByCode
//
// 设备端使用激活码激活/续期 Cursor 设备(无需登录)。
//
// JSON 示例:
//
// {
// "activationCode": "CUR-XXXXXXXX",
// "machineCode": "ABC-123",
// "deviceInfo": "CPU/RAM/磁盘等设备信息",
// "system": "Windows",
// "version": "1.0.0",
// "bindAccount": "user@example.com",
// "ownerUserId": 1,
// "ownerUserName": "张三",
// "remark": "登录器激活"
// }
//
// 兼容字段:
// - 激活码activationCode / activation_code / code
// - 机器码machineCode / machine_code
// - 设备信息deviceInfo / device_info
// - 绑定账号bindAccount / bind_account
func (c *ApiCursorEquipmentController) ActivateByCode() {
var p cursorEquipmentActivatePayload
if err := json.Unmarshal(c.Ctx.Input.RequestBody, &p); err != nil {
c.jsonResult(400, "参数错误", nil)
return
}
code := cursorFirstNonEmpty(p.ActivationCode, p.ActivationCodeSnake, p.Code)
if code == "" {
c.jsonResult(400, "缺少参数 activationCode/activation_code/code激活码", nil)
return
}
if len(code) > 128 {
c.jsonResult(400, "激活码长度不能超过 128 个字符", nil)
return
}
machineCode := cursorFirstNonEmpty(p.MachineCode, p.MachineCodeSnake)
if machineCode == "" {
c.jsonResult(400, "缺少参数 machineCode/machine_code机器码", nil)
return
}
if len(machineCode) > 128 {
c.jsonResult(400, "机器码长度不能超过 128 个字符", nil)
return
}
deviceInfo := cursorFirstNonEmpty(p.DeviceInfo, p.DeviceInfoSnake)
system := cursorFirstNonEmpty(p.System)
version := cursorFirstNonEmpty(p.Version)
bindAccount := cursorFirstNonEmpty(p.BindAccount, p.BindAccountSnake)
ownerUserID := p.OwnerUserID
if ownerUserID == nil {
ownerUserID = p.OwnerUserIDSnake
}
ownerUserName := cursorFirstNonEmpty(p.OwnerUserName, p.OwnerUserNameSnake)
remark := cursorFirstNonEmpty(p.Remark)
now := time.Now()
var activationCode models.PlatformCursorActivationCode
err := models.Orm.QueryTable(new(models.PlatformCursorActivationCode)).
Filter("code", code).
Filter("delete_time__isnull", true).
One(&activationCode)
if err == orm.ErrNoRows {
c.jsonResult(404, "激活码不存在", nil)
return
}
if err != nil {
c.jsonResult(500, "激活码查询失败", nil)
return
}
if activationCode.Status == 3 {
c.jsonResult(403, "激活码已禁用", nil)
return
}
if activationCode.Status == 2 || (activationCode.ExpiredAt != nil && activationCode.ExpiredAt.Before(now)) {
_, _ = models.Orm.QueryTable(new(models.PlatformCursorActivationCode)).
Filter("id", activationCode.ID).
Update(map[string]interface{}{"status": int8(2), "update_time": now})
c.jsonResult(410, "激活码已过期", nil)
return
}
if activationCode.Status == 1 {
if activationCode.MachineCode == nil || strings.TrimSpace(*activationCode.MachineCode) != machineCode {
c.jsonResult(409, "激活码已被其他设备使用", nil)
return
}
if activationCode.ExpiredAt != nil && activationCode.ExpiredAt.Before(now) {
_, _ = models.Orm.QueryTable(new(models.PlatformCursorActivationCode)).
Filter("id", activationCode.ID).
Update(map[string]interface{}{"status": int8(2), "update_time": now})
c.jsonResult(410, "激活码已过期", nil)
return
}
c.jsonResult(200, "success", map[string]interface{}{
"activated": true,
"reused": true,
"activationId": activationCode.ID,
"deviceId": activationCode.BindDeviceID,
"machineCode": machineCode,
"status": 1,
"durationDays": activationCode.DurationDays,
"activatedAt": activationCode.ActivatedAt,
"expireTime": activationCode.ExpiredAt,
"expiredAt": activationCode.ExpiredAt,
})
return
}
var device models.PlatformCursorEquipment
deviceErr := models.Orm.QueryTable(new(models.PlatformCursorEquipment)).
Filter("machine_code", machineCode).
Filter("delete_time__isnull", true).
One(&device)
created := false
if deviceErr != nil && deviceErr != orm.ErrNoRows {
c.jsonResult(500, "设备信息查询失败", nil)
return
}
if deviceErr == nil && device.Status == 3 {
c.jsonResult(403, "设备已禁用,无法激活", nil)
return
}
baseTime := now
if deviceErr == nil && device.ExpireTime != nil && device.ExpireTime.After(now) {
baseTime = *device.ExpireTime
}
var expireTime *time.Time
if activationCode.DurationDays > 0 {
t := baseTime.AddDate(0, 0, activationCode.DurationDays)
expireTime = &t
}
txOrm, err := models.Orm.Begin()
if err != nil {
c.jsonResult(500, "开启事务失败", nil)
return
}
rollback := true
defer func() {
if rollback {
_ = txOrm.Rollback()
}
}()
if deviceErr == orm.ErrNoRows {
device = models.PlatformCursorEquipment{
MachineCode: machineCode,
Status: 1,
DeviceInfo: cursorStringPtr(deviceInfo),
System: cursorStringPtr(system),
Version: cursorStringPtr(version),
BindAccount: cursorStringPtr(bindAccount),
OwnerUserID: ownerUserID,
OwnerUserName: cursorStringPtr(ownerUserName),
ActivationTime: &now,
ExpireTime: expireTime,
Remark: cursorStringPtr(remark),
CreateTime: now,
}
id, insertErr := txOrm.Insert(&device)
if insertErr != nil {
c.jsonResult(500, "设备信息保存失败", nil)
return
}
device.ID = uint64(id)
created = true
} else {
if bindAccount == "" && device.BindAccount != nil {
bindAccount = *device.BindAccount
}
if ownerUserID == nil {
ownerUserID = device.OwnerUserID
}
if ownerUserName == "" && device.OwnerUserName != nil {
ownerUserName = *device.OwnerUserName
}
_, updateErr := txOrm.QueryTable(new(models.PlatformCursorEquipment)).
Filter("id", device.ID).
Update(map[string]interface{}{
"device_info": cursorStringPtr(deviceInfo),
"system": cursorStringPtr(system),
"version": cursorStringPtr(version),
"bind_account": cursorStringPtr(bindAccount),
"owner_user_id": ownerUserID,
"owner_user_name": cursorStringPtr(ownerUserName),
"activation_time": now,
"expire_time": expireTime,
"status": int8(1),
"remark": cursorStringPtr(remark),
"update_time": now,
})
if updateErr != nil {
c.jsonResult(500, "设备信息更新失败", nil)
return
}
}
codeUpdateCount, updateCodeErr := txOrm.QueryTable(new(models.PlatformCursorActivationCode)).
Filter("id", activationCode.ID).
Filter("status", int8(0)).
Filter("delete_time__isnull", true).
Update(map[string]interface{}{
"status": int8(1),
"bind_account": cursorStringPtr(bindAccount),
"bind_device_id": device.ID,
"machine_code": machineCode,
"device_info": cursorStringPtr(deviceInfo),
"owner_user_id": ownerUserID,
"owner_user_name": cursorStringPtr(ownerUserName),
"activated_at": now,
"expired_at": expireTime,
"remark": cursorStringPtr(remark),
"update_time": now,
})
if updateCodeErr != nil {
c.jsonResult(500, "激活码绑定失败", nil)
return
}
if codeUpdateCount == 0 {
c.jsonResult(409, "激活码状态已变化,请重新查询后再试", nil)
return
}
if err := txOrm.Commit(); err != nil {
c.jsonResult(500, "提交事务失败", nil)
return
}
rollback = false
c.jsonResult(200, "success", map[string]interface{}{
"activated": true,
"reused": false,
"created": created,
"activationId": activationCode.ID,
"deviceId": device.ID,
"machineCode": machineCode,
"status": 1,
"durationDays": activationCode.DurationDays,
"activationAt": now,
"activatedAt": now,
"expireTime": expireTime,
"expiredAt": expireTime,
})
}

View File

@ -287,16 +287,16 @@ func (c *BackendArticleController) Detail() {
}
type cmsArticlePayload struct {
Title string `json:"title"`
Author string `json:"author"`
Cate interface{} `json:"cate"`
Content string `json:"content"`
Desc string `json:"desc"`
Image string `json:"image"`
IsTrans int8 `json:"is_trans"`
TransURL *string `json:"transurl"`
Status int8 `json:"status"`
IgnoreSimilarity int `json:"ignore_similarity"`
Title string `json:"title"`
Author string `json:"author"`
Cate interface{} `json:"cate"`
Content string `json:"content"`
Desc string `json:"desc"`
Image string `json:"image"`
IsTrans int8 `json:"is_trans"`
TransURL *string `json:"transurl"`
Status int8 `json:"status"`
IgnoreSimilarity int `json:"ignore_similarity"`
}
// Create POST /backend/createarticle
@ -593,8 +593,8 @@ func (c *BackendArticleController) Unpublish() {
func (c *BackendArticleController) Recommend() { c.setArticleFlag("recommend", 1) }
func (c *BackendArticleController) Unrecommend() { c.setArticleFlag("recommend", 0) }
func (c *BackendArticleController) Top() { c.setArticleFlag("top", 1) }
func (c *BackendArticleController) Untop() { c.setArticleFlag("top", 0) }
func (c *BackendArticleController) Top() { c.setArticleFlag("top", 1) }
func (c *BackendArticleController) Untop() { c.setArticleFlag("top", 0) }
// List GET /backend/categories
func (c *BackendArticleCategoryController) List() {

View File

@ -619,115 +619,150 @@ func replenishPoolRow(c *beego.Controller, module string) {
platform := payload.Platform
remark := strings.TrimSpace(payload.Remark)
replenishWithProbe(c, module, payload.Type, platform, remark, now)
}
type poolReplenishCandidate struct {
id uint64
dataType string
token string
isUsed *int8
row interface{}
}
type poolReplenishFetcher func() (*poolReplenishCandidate, error)
// replenishWithProbe 按 id 顺序补号并探测;不可用则标记 is_extracted=2 后继续下一条。
func replenishWithProbe(c *beego.Controller, module, dataType, platform, remark string, now time.Time) {
var fetch poolReplenishFetcher
switch module {
case "cursor":
checkedCount := 0
unavailableCount := 0
for {
fetch = func() (*poolReplenishCandidate, error) {
var row models.PlatformAccountPoolCursor
if err := models.Orm.QueryTable(new(models.PlatformAccountPoolCursor)).
Filter("is_extracted", 0).Filter("data_type", payload.Type).
OrderBy("id").One(&row); err != nil {
msg := "暂无可用账号"
if checkedCount > 0 {
msg = fmt.Sprintf("已检测%d个账号其中%d个不可用暂无可用账号", checkedCount, unavailableCount)
}
poolJSONErr(c, 404, 404, msg)
return
err := models.Orm.QueryTable(new(models.PlatformAccountPoolCursor)).
Filter("is_extracted", 0).
Filter("data_type", dataType).
Filter("delete_time__isnull", true).
OrderBy("id").
One(&row)
if err != nil {
return nil, err
}
checkedCount++
isAvailable := poolProbeToken("cursor", row.DataType, row.Token, row.ID)
if !isAvailable {
unavailableCount++
if _, err := models.Orm.QueryTable(new(models.PlatformAccountPoolCursor)).Filter("id", row.ID).Update(map[string]interface{}{
// 补号流程检测出来不可用/已用完的号,仍然归类为“补号”记录。
// 不要写成已提取/已用完状态;只有接口提取后再标记不可用的号才归到已提取侧。
"is_extracted": int8(2),
"is_used": int8(0),
"extracted_time": now,
"extracted_platform": platform,
"remark": remark,
"update_time": now,
}); err != nil {
poolJSONErr(c, 500, 500, "补号检测失败: "+err.Error())
return
}
continue
}
if _, err := models.Orm.QueryTable(new(models.PlatformAccountPoolCursor)).Filter("id", row.ID).Update(map[string]interface{}{
"is_extracted": int8(2),
"is_used": int8(1),
"extracted_time": now,
"extracted_platform": platform,
"remark": remark,
"update_time": now,
}); err != nil {
poolJSONErr(c, 500, 500, "补号失败: "+err.Error())
return
}
row.IsExtracted = 2
isUsed := int8(1)
row.IsUsed = &isUsed
row.ExtractedTime = &now
row.ExtractedPlatform = &platform
row.Remark = remark
c.Data["json"] = map[string]interface{}{
"code": 200,
"msg": "补号成功",
"data": row,
"probe": map[string]interface{}{
"checkedCount": checkedCount,
"unavailableCount": unavailableCount,
},
}
break
return &poolReplenishCandidate{
id: row.ID, dataType: row.DataType, token: row.Token, isUsed: row.IsUsed, row: row,
}, nil
}
case "windsurf":
var row models.PlatformAccountPoolWindsurf
if err := models.Orm.QueryTable(new(models.PlatformAccountPoolWindsurf)).
Filter("is_extracted", 0).Filter("data_type", payload.Type).
OrderBy("id").One(&row); err != nil {
poolJSONErr(c, 404, 404, "暂无可用账号")
return
fetch = func() (*poolReplenishCandidate, error) {
var row models.PlatformAccountPoolWindsurf
err := models.Orm.QueryTable(new(models.PlatformAccountPoolWindsurf)).
Filter("is_extracted", 0).
Filter("data_type", dataType).
Filter("delete_time__isnull", true).
OrderBy("id").
One(&row)
if err != nil {
return nil, err
}
return &poolReplenishCandidate{
id: row.ID, dataType: row.DataType, token: row.Token, row: row,
}, nil
}
if _, err = models.Orm.QueryTable(new(models.PlatformAccountPoolWindsurf)).Filter("id", row.ID).Update(map[string]interface{}{
"is_extracted": int8(2), "extracted_time": now, "extracted_platform": platform, "remark": remark,
}); err != nil {
poolJSONErr(c, 500, 500, "补号失败: "+err.Error())
return
}
row.IsExtracted = 2
row.ExtractedTime = &now
row.ExtractedPlatform = &platform
row.Remark = remark
c.Data["json"] = map[string]interface{}{"code": 200, "msg": "补号成功", "data": row}
case "krio":
var row models.PlatformAccountPoolKiro
if err := models.Orm.QueryTable(new(models.PlatformAccountPoolKiro)).
Filter("is_extracted", 0).Filter("data_type", payload.Type).
OrderBy("id").One(&row); err != nil {
poolJSONErr(c, 404, 404, "暂无可用账号")
return
fetch = func() (*poolReplenishCandidate, error) {
var row models.PlatformAccountPoolKiro
err := models.Orm.QueryTable(new(models.PlatformAccountPoolKiro)).
Filter("is_extracted", 0).
Filter("data_type", dataType).
Filter("delete_time__isnull", true).
OrderBy("id").
One(&row)
if err != nil {
return nil, err
}
return &poolReplenishCandidate{
id: row.ID, dataType: row.DataType, token: row.Token, row: row,
}, nil
}
if _, err = models.Orm.QueryTable(new(models.PlatformAccountPoolKiro)).Filter("id", row.ID).Update(map[string]interface{}{
"is_extracted": int8(2), "extracted_time": now, "extracted_platform": platform, "remark": remark,
}); err != nil {
poolJSONErr(c, 500, 500, "补号失败: "+err.Error())
return
}
row.IsExtracted = 2
row.ExtractedTime = &now
row.ExtractedPlatform = &platform
row.Remark = remark
c.Data["json"] = map[string]interface{}{"code": 200, "msg": "补号成功", "data": row}
default:
poolJSONErr(c, 400, 400, "无效模块")
return
}
_ = c.ServeJSON()
tableName := poolTableName(module)
if tableName == "" {
poolJSONErr(c, 400, 400, "无效模块")
return
}
for {
candidate, err := fetch()
if err != nil {
if err == orm.ErrNoRows {
poolJSONErr(c, 404, 404, "暂无可用账号")
} else {
poolJSONErr(c, 500, 500, "查询失败")
}
return
}
updateFields := map[string]interface{}{
"is_extracted": int8(2),
"extracted_time": now,
"extracted_platform": platform,
"remark": remark,
"update_time": now,
}
if _, err = models.Orm.QueryTable(tableName).
Filter("id", candidate.id).
Update(updateFields); err != nil {
poolJSONErr(c, 500, 500, "补号失败: "+err.Error())
return
}
if known, available := poolIsUsedAvailable(candidate.isUsed); known {
if !available {
continue
}
} else if !poolProbeToken(module, candidate.dataType, candidate.token, candidate.id) {
continue
}
data := replenishApplyResponse(candidate.row, platform, remark, now)
c.Data["json"] = map[string]interface{}{"code": 200, "msg": "补号成功", "data": data}
_ = c.ServeJSON()
return
}
}
func replenishApplyResponse(row interface{}, platform, remark string, now time.Time) interface{} {
pf := platform
switch r := row.(type) {
case models.PlatformAccountPoolCursor:
r.IsExtracted = 2
r.ExtractedTime = &now
r.ExtractedPlatform = &pf
r.Remark = remark
if r.IsUsed == nil || *r.IsUsed != 1 {
used := int8(1)
r.IsUsed = &used
}
return r
case models.PlatformAccountPoolWindsurf:
r.IsExtracted = 2
r.ExtractedTime = &now
r.ExtractedPlatform = &pf
r.Remark = remark
return r
case models.PlatformAccountPoolKiro:
r.IsExtracted = 2
r.ExtractedTime = &now
r.ExtractedPlatform = &pf
r.Remark = remark
return r
default:
return row
}
}
func updatePoolRemark(c *beego.Controller, module string) {
@ -843,6 +878,54 @@ func setPoolUnavailable(c *beego.Controller, module string) {
_ = c.ServeJSON()
}
func updatePoolUsable(c *beego.Controller, module string) {
if _, err := requirePlatformAuth(c); err != nil {
poolJSONErr(c, 401, 401, err.Error())
return
}
if module != "cursor" {
poolJSONErr(c, 400, 400, "该模块不支持可用状态修改")
return
}
raw, err := io.ReadAll(c.Ctx.Request.Body)
if err != nil {
poolJSONErr(c, 400, 400, "参数错误")
return
}
var payload struct {
ID uint64 `json:"id"`
Usable int `json:"usable"`
}
if err := json.Unmarshal(raw, &payload); err != nil || payload.ID == 0 {
poolJSONErr(c, 400, 400, "参数错误")
return
}
if payload.Usable != 0 && payload.Usable != 1 {
poolJSONErr(c, 400, 400, "可用状态参数错误")
return
}
now := time.Now()
updated, err := models.Orm.QueryTable(new(models.PlatformAccountPoolCursor)).Filter("id", payload.ID).Update(orm.Params{
"is_used": int8(payload.Usable),
"update_time": now,
})
if err != nil {
poolJSONErr(c, 500, 500, "可用状态更新失败: "+err.Error())
return
}
if updated == 0 {
poolJSONErr(c, 404, 404, "记录不存在")
return
}
msg := "已标记不可用"
if payload.Usable == 1 {
msg = "已标记可用"
}
c.Data["json"] = map[string]interface{}{"code": 200, "msg": msg}
_ = c.ServeJSON()
}
func updatePoolPlatform(c *beego.Controller, module string) {
if _, err := requirePlatformAuth(c); err != nil {
poolJSONErr(c, 401, 401, err.Error())
@ -1019,12 +1102,12 @@ func probePoolToken(c *beego.Controller, module string) {
if r.StreamNote != "" {
data["streamNote"] = r.StreamNote
}
// Cursor 探测状态只按底层探针结论 r.OK 保存。
// 注意:客户端版本过旧只是 warningToken 仍可用时 r.OK=true不能因此写成已用完。
if module == "cursor" && payload.ID > 0 && r.HTTPStatus == http.StatusOK {
isUsed := int8(0)
var isUsed int8
if r.OK {
isUsed = 1
} else {
isUsed = 0
}
if _, uerr := models.Orm.QueryTable(new(models.PlatformAccountPoolCursor)).Filter("id", payload.ID).Update(orm.Params{
"is_used": isUsed,
@ -1041,62 +1124,6 @@ func probePoolToken(c *beego.Controller, module string) {
_ = c.ServeJSON()
}
func poolTableName(module string) string {
switch module {
case "cursor":
return (&models.PlatformAccountPoolCursor{}).TableName()
case "windsurf":
return (&models.PlatformAccountPoolWindsurf{}).TableName()
case "krio":
return (&models.PlatformAccountPoolKiro{}).TableName()
default:
return ""
}
}
func poolIsUsedAvailable(isUsed *int8) (known bool, available bool) {
if isUsed == nil {
return false, false
}
switch *isUsed {
case 1:
return true, true
case 0:
return true, false
default:
return false, false
}
}
func poolProbeToken(module, rowDataType, token string, id uint64) bool {
token = strings.TrimSpace(token)
if rowDataType == "account" || token == "" {
return true
}
r := tokenprobe.ProbeOfficial(module, token)
// Cursor 自动探测只按底层探针结论 r.OK 判定。
// 客户端版本过旧是 warning不代表 Token 已用完;只有 tokenprobe 明确判定额度用尽/不可用时 r.OK 才为 false。
available := r.OK
// 更新数据库中的 is_used 字段
if module == "cursor" && id > 0 {
isUsed := int8(0)
if available {
isUsed = 1
}
_, _ = models.Orm.QueryTable(new(models.PlatformAccountPoolCursor)).
Filter("id", id).
Update(orm.Params{
"is_used": isUsed,
"update_time": time.Now(),
})
}
return available
}
func (c *PlatformAccountPoolCursorController) List() { listPoolRows(&c.Controller, "cursor") }
func (c *PlatformAccountPoolCursorController) Add() { addPoolRow(&c.Controller, "cursor") }
func (c *PlatformAccountPoolCursorController) BatchAdd() { batchAddPoolRows(&c.Controller, "cursor") }
@ -1109,6 +1136,9 @@ func (c *PlatformAccountPoolCursorController) UpdateRemark() {
func (c *PlatformAccountPoolCursorController) SetUnavailable() {
setPoolUnavailable(&c.Controller, "cursor")
}
func (c *PlatformAccountPoolCursorController) UpdateUsable() {
updatePoolUsable(&c.Controller, "cursor")
}
func (c *PlatformAccountPoolCursorController) UpdatePlatform() {
updatePoolPlatform(&c.Controller, "cursor")
}

View File

@ -0,0 +1,750 @@
package controllers
import (
"crypto/rand"
"encoding/csv"
"encoding/hex"
"encoding/json"
"fmt"
"io"
"strconv"
"strings"
"time"
"server/models"
"server/pkg/jwtutil"
"github.com/beego/beego/v2/client/orm"
beego "github.com/beego/beego/v2/server/web"
)
// PlatformCursorActivationCodeController 平台端 Cursor 激活码管理
type PlatformCursorActivationCodeController struct {
beego.Controller
}
func (c *PlatformCursorActivationCodeController) platformClaims() (*jwtutil.Claims, error) {
auth := c.Ctx.Request.Header.Get("Authorization")
if auth == "" {
return nil, fmt.Errorf("未登录")
}
parts := strings.SplitN(auth, " ", 2)
if len(parts) != 2 || parts[0] != "Bearer" {
return nil, fmt.Errorf("认证信息格式错误")
}
claims, err := jwtutil.ParseToken(parts[1])
if err != nil {
return nil, fmt.Errorf("无效的token")
}
if claims.UserType != "platform" {
return nil, fmt.Errorf("无权访问")
}
return claims, nil
}
func (c *PlatformCursorActivationCodeController) jsonErr(httpStatus, bizCode int, msg string) {
c.Ctx.Output.SetStatus(httpStatus)
c.Data["json"] = map[string]interface{}{"code": bizCode, "msg": msg}
_ = c.ServeJSON()
}
func (c *PlatformCursorActivationCodeController) ok(data interface{}) {
c.Data["json"] = map[string]interface{}{"code": 200, "msg": "success", "data": data}
_ = c.ServeJSON()
}
func cursorActivationCodeTrimPtr(value *string) *string {
if value == nil {
return nil
}
v := strings.TrimSpace(*value)
if v == "" {
return nil
}
return &v
}
func cursorActivationCodeTimePtr(value *string) *time.Time {
if value == nil {
return nil
}
v := strings.TrimSpace(*value)
if v == "" {
return nil
}
layouts := []string{
time.RFC3339,
"2006-01-02 15:04:05",
"2006-01-02 15:04",
"2006-01-02",
}
for _, layout := range layouts {
if t, err := time.ParseInLocation(layout, v, time.Local); err == nil {
return &t
}
}
return nil
}
func cursorActivationCodeStatusValid(status int8) bool {
return status == 0 || status == 1 || status == 2 || status == 3
}
func cursorActivationCodeTypeName(cardType int) string {
switch cardType {
case 1:
return "天卡"
case 7:
return "周卡"
case 30:
return "月卡"
case 90:
return "季卡"
case 365:
return "年卡"
case 0:
return "自定义"
default:
return fmt.Sprintf("%d天", cardType)
}
}
func (c *PlatformCursorActivationCodeController) rowToMap(row *models.PlatformCursorActivationCode) map[string]interface{} {
bindStatus := 0
if row.BindAccount != nil || row.BindDeviceID != nil || row.MachineCode != nil {
bindStatus = 1
}
return map[string]interface{}{
"id": row.ID,
"code": row.Code,
"type": row.Type,
"typeName": cursorActivationCodeTypeName(row.Type),
"status": row.Status,
"durationDays": row.DurationDays,
"bindAccount": row.BindAccount,
"bindDeviceId": row.BindDeviceID,
"bindStatus": bindStatus,
"machineCode": row.MachineCode,
"deviceInfo": row.DeviceInfo,
"ownerUserId": row.OwnerUserID,
"ownerUserName": row.OwnerUserName,
"activatedAt": row.ActivatedAt,
"expiredAt": row.ExpiredAt,
"createdAt": row.CreateTime,
"updatedAt": row.UpdateTime,
"createTime": row.CreateTime,
"updateTime": row.UpdateTime,
"remark": row.Remark,
}
}
func (c *PlatformCursorActivationCodeController) filteredQuery() orm.QuerySeter {
keyword := strings.TrimSpace(c.GetString("keyword"))
statusText := strings.TrimSpace(c.GetString("status"))
typeText := strings.TrimSpace(c.GetString("type"))
bindStatusText := strings.TrimSpace(c.GetString("bindStatus"))
qs := models.Orm.QueryTable(new(models.PlatformCursorActivationCode)).Filter("delete_time__isnull", true)
if keyword != "" {
cond := orm.NewCondition().
Or("code__icontains", keyword).
Or("bind_account__icontains", keyword).
Or("machine_code__icontains", keyword).
Or("device_info__icontains", keyword).
Or("owner_user_name__icontains", keyword).
Or("remark__icontains", keyword)
qs = qs.SetCond(cond)
qs = qs.Filter("delete_time__isnull", true)
}
if statusText != "" {
status, err := strconv.ParseInt(statusText, 10, 8)
if err == nil && cursorActivationCodeStatusValid(int8(status)) {
qs = qs.Filter("status", int8(status))
}
}
if typeText != "" {
cardType, err := strconv.Atoi(typeText)
if err == nil {
qs = qs.Filter("type", cardType)
}
}
if bindStatusText != "" {
bindStatus, err := strconv.Atoi(bindStatusText)
if err == nil {
if bindStatus == 0 {
qs = qs.Filter("bind_account__isnull", true).Filter("bind_device_id__isnull", true).Filter("machine_code__isnull", true)
} else if bindStatus == 1 {
cond := orm.NewCondition().
Or("bind_account__isnull", false).
Or("bind_device_id__isnull", false).
Or("machine_code__isnull", false)
qs = qs.SetCond(cond)
qs = qs.Filter("delete_time__isnull", true)
if statusText != "" {
status, err := strconv.ParseInt(statusText, 10, 8)
if err == nil && cursorActivationCodeStatusValid(int8(status)) {
qs = qs.Filter("status", int8(status))
}
}
if typeText != "" {
cardType, err := strconv.Atoi(typeText)
if err == nil {
qs = qs.Filter("type", cardType)
}
}
}
}
}
return qs
}
// List GET /platform/cursor/activationcode/list
func (c *PlatformCursorActivationCodeController) List() {
if _, err := c.platformClaims(); err != nil {
c.jsonErr(401, 401, err.Error())
return
}
page, _ := c.GetInt("page", 1)
pageSize, _ := c.GetInt("pageSize", 20)
if page < 1 {
page = 1
}
if pageSize < 1 {
pageSize = 20
}
if pageSize > 200 {
pageSize = 200
}
qs := c.filteredQuery()
total, _ := qs.Count()
var rows []models.PlatformCursorActivationCode
_, err := qs.OrderBy("-id").Limit(pageSize, (page-1)*pageSize).All(&rows)
if err != nil {
c.jsonErr(500, 500, "获取激活码列表失败: "+err.Error())
return
}
list := make([]map[string]interface{}, 0, len(rows))
for i := range rows {
list = append(list, c.rowToMap(&rows[i]))
}
c.ok(map[string]interface{}{
"list": list,
"total": total,
"page": page,
"pageSize": pageSize,
})
}
// Detail GET /platform/cursor/activationcode/detail/:id
func (c *PlatformCursorActivationCodeController) Detail() {
if _, err := c.platformClaims(); err != nil {
c.jsonErr(401, 401, err.Error())
return
}
id, err := strconv.ParseUint(c.Ctx.Input.Param(":id"), 10, 64)
if err != nil || id == 0 {
c.jsonErr(400, 400, "无效ID")
return
}
var row models.PlatformCursorActivationCode
err = models.Orm.QueryTable(new(models.PlatformCursorActivationCode)).
Filter("id", id).
Filter("delete_time__isnull", true).
One(&row)
if err != nil {
c.jsonErr(404, 404, "激活码不存在")
return
}
c.ok(c.rowToMap(&row))
}
type platformCursorActivationCodePayload struct {
ID *uint64 `json:"id"`
Code *string `json:"code"`
Type *int `json:"type"`
Status *int8 `json:"status"`
DurationDays *int `json:"durationDays"`
BindAccount *string `json:"bindAccount"`
BindDeviceID *uint64 `json:"bindDeviceId"`
OwnerUserID *uint64 `json:"ownerUserId"`
OwnerUserName *string `json:"ownerUserName"`
ActivatedAt *string `json:"activatedAt"`
ExpiredAt *string `json:"expiredAt"`
Remark *string `json:"remark"`
}
func (c *PlatformCursorActivationCodeController) readPayload() (*platformCursorActivationCodePayload, error) {
body, _ := io.ReadAll(c.Ctx.Request.Body)
var p platformCursorActivationCodePayload
if err := json.Unmarshal(body, &p); err != nil {
return nil, err
}
return &p, nil
}
func (c *PlatformCursorActivationCodeController) fillDeviceSnapshot(up map[string]interface{}, bindDeviceID *uint64) {
if bindDeviceID == nil || *bindDeviceID == 0 {
up["bind_device_id"] = nil
up["machine_code"] = nil
up["device_info"] = nil
return
}
var device models.PlatformCursorEquipment
err := models.Orm.QueryTable(new(models.PlatformCursorEquipment)).
Filter("id", *bindDeviceID).
Filter("delete_time__isnull", true).
One(&device)
if err == nil {
up["bind_device_id"] = *bindDeviceID
up["machine_code"] = device.MachineCode
up["device_info"] = device.DeviceInfo
return
}
up["bind_device_id"] = *bindDeviceID
}
func (c *PlatformCursorActivationCodeController) payloadToUpdateMap(p *platformCursorActivationCodePayload, includeCode bool) (map[string]interface{}, error) {
up := map[string]interface{}{}
if includeCode {
if p.Code == nil || strings.TrimSpace(*p.Code) == "" {
return nil, fmt.Errorf("激活码不能为空")
}
up["code"] = strings.TrimSpace(*p.Code)
} else if p.Code != nil {
if strings.TrimSpace(*p.Code) == "" {
return nil, fmt.Errorf("激活码不能为空")
}
up["code"] = strings.TrimSpace(*p.Code)
}
if p.Type != nil {
if *p.Type < 0 {
return nil, fmt.Errorf("卡密类型不合法")
}
up["type"] = *p.Type
}
if p.Status != nil {
if !cursorActivationCodeStatusValid(*p.Status) {
return nil, fmt.Errorf("状态不合法支持0 未使用、1 已使用、2 已过期、3 已禁用")
}
up["status"] = *p.Status
}
if p.DurationDays != nil {
if *p.DurationDays < 0 || *p.DurationDays > 9999 {
return nil, fmt.Errorf("有效天数范围为 0-9999")
}
up["duration_days"] = *p.DurationDays
}
if p.BindAccount != nil {
up["bind_account"] = cursorActivationCodeTrimPtr(p.BindAccount)
}
if p.BindDeviceID != nil {
c.fillDeviceSnapshot(up, p.BindDeviceID)
}
if p.OwnerUserID != nil {
if *p.OwnerUserID == 0 {
up["owner_user_id"] = nil
} else {
up["owner_user_id"] = *p.OwnerUserID
}
}
if p.OwnerUserName != nil {
up["owner_user_name"] = cursorActivationCodeTrimPtr(p.OwnerUserName)
}
if p.ActivatedAt != nil {
up["activated_at"] = cursorActivationCodeTimePtr(p.ActivatedAt)
}
if p.ExpiredAt != nil {
up["expired_at"] = cursorActivationCodeTimePtr(p.ExpiredAt)
}
if p.Remark != nil {
up["remark"] = cursorActivationCodeTrimPtr(p.Remark)
}
return up, nil
}
// Add POST /platform/cursor/activationcode/add
func (c *PlatformCursorActivationCodeController) Add() {
if _, err := c.platformClaims(); err != nil {
c.jsonErr(401, 401, err.Error())
return
}
p, err := c.readPayload()
if err != nil {
c.jsonErr(400, 400, "参数错误")
return
}
up, err := c.payloadToUpdateMap(p, true)
if err != nil {
c.jsonErr(400, 400, err.Error())
return
}
row := models.PlatformCursorActivationCode{
Code: up["code"].(string),
Type: 30,
Status: 0,
DurationDays: 30,
BindAccount: cursorActivationCodeTrimPtr(p.BindAccount),
BindDeviceID: p.BindDeviceID,
OwnerUserID: p.OwnerUserID,
OwnerUserName: cursorActivationCodeTrimPtr(p.OwnerUserName),
ActivatedAt: cursorActivationCodeTimePtr(p.ActivatedAt),
ExpiredAt: cursorActivationCodeTimePtr(p.ExpiredAt),
Remark: cursorActivationCodeTrimPtr(p.Remark),
CreateTime: time.Now(),
}
if p.Type != nil {
row.Type = *p.Type
}
if p.Status != nil {
row.Status = *p.Status
}
if p.DurationDays != nil {
row.DurationDays = *p.DurationDays
}
if row.BindDeviceID != nil && *row.BindDeviceID == 0 {
row.BindDeviceID = nil
}
if row.OwnerUserID != nil && *row.OwnerUserID == 0 {
row.OwnerUserID = nil
}
if row.BindDeviceID != nil {
var device models.PlatformCursorEquipment
if err := models.Orm.QueryTable(new(models.PlatformCursorEquipment)).
Filter("id", *row.BindDeviceID).
Filter("delete_time__isnull", true).
One(&device); err == nil {
row.MachineCode = &device.MachineCode
row.DeviceInfo = device.DeviceInfo
}
}
id, err := models.Orm.Insert(&row)
if err != nil {
if strings.Contains(strings.ToLower(err.Error()), "duplicate") {
c.jsonErr(400, 400, "激活码已存在")
return
}
c.jsonErr(500, 500, "新增激活码失败: "+err.Error())
return
}
c.ok(map[string]interface{}{"id": id})
}
// Update POST /platform/cursor/activationcode/update
func (c *PlatformCursorActivationCodeController) Update() {
if _, err := c.platformClaims(); err != nil {
c.jsonErr(401, 401, err.Error())
return
}
p, err := c.readPayload()
if err != nil {
c.jsonErr(400, 400, "参数错误")
return
}
if p.ID == nil || *p.ID == 0 {
c.jsonErr(400, 400, "无效ID")
return
}
up, err := c.payloadToUpdateMap(p, false)
if err != nil {
c.jsonErr(400, 400, err.Error())
return
}
if len(up) == 0 {
c.jsonErr(400, 400, "无更新字段")
return
}
now := time.Now()
up["update_time"] = now
n, err := models.Orm.QueryTable(new(models.PlatformCursorActivationCode)).
Filter("id", *p.ID).
Filter("delete_time__isnull", true).
Update(up)
if err != nil {
if strings.Contains(strings.ToLower(err.Error()), "duplicate") {
c.jsonErr(400, 400, "激活码已存在")
return
}
c.jsonErr(500, 500, "更新激活码失败: "+err.Error())
return
}
if n == 0 {
c.jsonErr(404, 404, "激活码不存在")
return
}
c.ok(nil)
}
// Delete POST /platform/cursor/activationcode/delete/:id
func (c *PlatformCursorActivationCodeController) Delete() {
if _, err := c.platformClaims(); err != nil {
c.jsonErr(401, 401, err.Error())
return
}
id, err := strconv.ParseUint(c.Ctx.Input.Param(":id"), 10, 64)
if err != nil || id == 0 {
c.jsonErr(400, 400, "无效ID")
return
}
now := time.Now()
n, err := models.Orm.QueryTable(new(models.PlatformCursorActivationCode)).
Filter("id", id).
Filter("delete_time__isnull", true).
Update(map[string]interface{}{"delete_time": now, "update_time": now})
if err != nil {
c.jsonErr(500, 500, "删除激活码失败: "+err.Error())
return
}
if n == 0 {
c.jsonErr(404, 404, "激活码不存在")
return
}
c.ok(nil)
}
type platformCursorActivationCodeGeneratePayload struct {
Count int `json:"count"`
Type int `json:"type"`
DurationDays int `json:"durationDays"`
OwnerUserID *uint64 `json:"ownerUserId"`
OwnerUserName *string `json:"ownerUserName"`
Remark *string `json:"remark"`
}
func randomCursorActivationCode() (string, error) {
b := make([]byte, 12)
if _, err := rand.Read(b); err != nil {
return "", err
}
return "CUR-" + strings.ToUpper(hex.EncodeToString(b)), nil
}
// Generate POST /platform/cursor/activationcode/generate
func (c *PlatformCursorActivationCodeController) Generate() {
if _, err := c.platformClaims(); err != nil {
c.jsonErr(401, 401, err.Error())
return
}
body, _ := io.ReadAll(c.Ctx.Request.Body)
var p platformCursorActivationCodeGeneratePayload
if err := json.Unmarshal(body, &p); err != nil {
c.jsonErr(400, 400, "参数错误")
return
}
if p.Count < 1 {
p.Count = 1
}
if p.Count > 10000 {
c.jsonErr(400, 400, "单次最多生成 10000 个激活码")
return
}
if p.Type < 0 {
c.jsonErr(400, 400, "卡密类型不合法")
return
}
if p.DurationDays < 0 || p.DurationDays > 9999 {
c.jsonErr(400, 400, "有效天数范围为 0-9999")
return
}
if p.Type == 0 && p.DurationDays == 0 {
p.DurationDays = 30
}
if p.Type > 0 && p.DurationDays == 0 {
p.DurationDays = p.Type
}
createdIDs := make([]int64, 0, p.Count)
codes := make([]string, 0, p.Count)
now := time.Now()
for len(createdIDs) < p.Count {
code, err := randomCursorActivationCode()
if err != nil {
c.jsonErr(500, 500, "生成激活码失败: "+err.Error())
return
}
row := models.PlatformCursorActivationCode{
Code: code,
Type: p.Type,
Status: 0,
DurationDays: p.DurationDays,
OwnerUserID: p.OwnerUserID,
OwnerUserName: cursorActivationCodeTrimPtr(p.OwnerUserName),
Remark: cursorActivationCodeTrimPtr(p.Remark),
CreateTime: now,
}
if row.OwnerUserID != nil && *row.OwnerUserID == 0 {
row.OwnerUserID = nil
}
id, err := models.Orm.Insert(&row)
if err != nil {
if strings.Contains(strings.ToLower(err.Error()), "duplicate") {
continue
}
c.jsonErr(500, 500, "生成激活码失败: "+err.Error())
return
}
createdIDs = append(createdIDs, id)
codes = append(codes, code)
}
c.ok(map[string]interface{}{
"count": len(createdIDs),
"ids": createdIDs,
"codes": codes,
})
}
// Enable POST /platform/cursor/activationcode/enable/:id
func (c *PlatformCursorActivationCodeController) Enable() {
c.changeStatus(0, "启用激活码失败")
}
// Disable POST /platform/cursor/activationcode/disable/:id
func (c *PlatformCursorActivationCodeController) Disable() {
c.changeStatus(3, "禁用激活码失败")
}
func (c *PlatformCursorActivationCodeController) changeStatus(status int8, failMsg string) {
if _, err := c.platformClaims(); err != nil {
c.jsonErr(401, 401, err.Error())
return
}
id, err := strconv.ParseUint(c.Ctx.Input.Param(":id"), 10, 64)
if err != nil || id == 0 {
c.jsonErr(400, 400, "无效ID")
return
}
now := time.Now()
n, err := models.Orm.QueryTable(new(models.PlatformCursorActivationCode)).
Filter("id", id).
Filter("delete_time__isnull", true).
Update(map[string]interface{}{
"status": status,
"update_time": now,
})
if err != nil {
c.jsonErr(500, 500, failMsg+": "+err.Error())
return
}
if n == 0 {
c.jsonErr(404, 404, "激活码不存在")
return
}
c.ok(nil)
}
// Export GET /platform/cursor/activationcode/export
func (c *PlatformCursorActivationCodeController) Export() {
if _, err := c.platformClaims(); err != nil {
c.jsonErr(401, 401, err.Error())
return
}
var rows []models.PlatformCursorActivationCode
_, err := c.filteredQuery().OrderBy("-id").Limit(50000).All(&rows)
if err != nil {
c.jsonErr(500, 500, "导出激活码失败: "+err.Error())
return
}
filename := fmt.Sprintf("cursor-activation-code-%s.csv", time.Now().Format("20060102150405"))
c.Ctx.Output.Header("Content-Type", "text/csv; charset=utf-8")
c.Ctx.Output.Header("Content-Disposition", fmt.Sprintf(`attachment; filename="%s"`, filename))
_, _ = c.Ctx.ResponseWriter.Write([]byte{0xEF, 0xBB, 0xBF})
writer := csv.NewWriter(c.Ctx.ResponseWriter)
_ = writer.Write([]string{
"ID", "激活码", "类型", "有效天数", "状态", "绑定账号", "绑定设备ID", "机器码", "归属用户ID", "归属用户", "激活时间", "过期时间", "创建时间", "备注",
})
statusText := map[int8]string{
0: "未使用",
1: "已使用",
2: "已过期",
3: "已禁用",
}
for i := range rows {
row := rows[i]
_ = writer.Write([]string{
strconv.FormatUint(row.ID, 10),
row.Code,
cursorActivationCodeTypeName(row.Type),
strconv.Itoa(row.DurationDays),
statusText[row.Status],
stringPtrValue(row.BindAccount),
uint64PtrValue(row.BindDeviceID),
stringPtrValue(row.MachineCode),
uint64PtrValue(row.OwnerUserID),
stringPtrValue(row.OwnerUserName),
timePtrValue(row.ActivatedAt),
timePtrValue(row.ExpiredAt),
row.CreateTime.Format("2006-01-02 15:04:05"),
stringPtrValue(row.Remark),
})
}
writer.Flush()
}
func stringPtrValue(value *string) string {
if value == nil {
return ""
}
return *value
}
func uint64PtrValue(value *uint64) string {
if value == nil {
return ""
}
return strconv.FormatUint(*value, 10)
}
func timePtrValue(value *time.Time) string {
if value == nil {
return ""
}
return value.Format("2006-01-02 15:04:05")
}

View File

@ -0,0 +1,681 @@
package controllers
import (
"encoding/json"
"fmt"
"io"
"strconv"
"strings"
"time"
"server/models"
"server/pkg/jwtutil"
"github.com/beego/beego/v2/client/orm"
beego "github.com/beego/beego/v2/server/web"
)
// PlatformCursorEquipmentController 平台端 Cursor 设备管理
type PlatformCursorEquipmentController struct {
beego.Controller
}
func (c *PlatformCursorEquipmentController) platformClaims() (*jwtutil.Claims, error) {
auth := c.Ctx.Request.Header.Get("Authorization")
if auth == "" {
return nil, fmt.Errorf("未登录")
}
parts := strings.SplitN(auth, " ", 2)
if len(parts) != 2 || parts[0] != "Bearer" {
return nil, fmt.Errorf("认证信息格式错误")
}
claims, err := jwtutil.ParseToken(parts[1])
if err != nil {
return nil, fmt.Errorf("无效的token")
}
if claims.UserType != "platform" {
return nil, fmt.Errorf("无权访问")
}
return claims, nil
}
func (c *PlatformCursorEquipmentController) jsonErr(httpStatus, bizCode int, msg string) {
c.Ctx.Output.SetStatus(httpStatus)
c.Data["json"] = map[string]interface{}{"code": bizCode, "msg": msg}
_ = c.ServeJSON()
}
func (c *PlatformCursorEquipmentController) ok(data interface{}) {
c.Data["json"] = map[string]interface{}{"code": 200, "msg": "success", "data": data}
_ = c.ServeJSON()
}
func cursorEquipmentTrimPtr(value *string) *string {
if value == nil {
return nil
}
v := strings.TrimSpace(*value)
if v == "" {
return nil
}
return &v
}
func cursorEquipmentTimePtr(value *string) *time.Time {
if value == nil {
return nil
}
v := strings.TrimSpace(*value)
if v == "" {
return nil
}
layouts := []string{
time.RFC3339,
"2006-01-02 15:04:05",
"2006-01-02 15:04",
"2006-01-02",
}
for _, layout := range layouts {
if t, err := time.ParseInLocation(layout, v, time.Local); err == nil {
return &t
}
}
return nil
}
func cursorEquipmentStatusValid(status int8) bool {
return status == 0 || status == 1 || status == 2 || status == 3
}
func (c *PlatformCursorEquipmentController) cursorActivationSummary(row *models.PlatformCursorEquipment) (int64, *models.PlatformCursorActivationCode) {
cond := orm.NewCondition().
And("delete_time__isnull", true).
AndCond(orm.NewCondition().
Or("bind_device_id", row.ID).
Or("machine_code", row.MachineCode))
qs := models.Orm.QueryTable(new(models.PlatformCursorActivationCode)).SetCond(cond)
count, _ := qs.Count()
var latest models.PlatformCursorActivationCode
if err := qs.OrderBy("-activated_at", "-id").One(&latest); err != nil {
return count, nil
}
return count, &latest
}
func (c *PlatformCursorEquipmentController) cursorExtractSummary() (int64, *models.PlatformAccountPoolCursor) {
qs := models.Orm.QueryTable(new(models.PlatformAccountPoolCursor)).
Filter("delete_time__isnull", true).
Filter("is_extracted__gt", 0)
count, _ := qs.Count()
var latest models.PlatformAccountPoolCursor
if err := qs.OrderBy("-extracted_time", "-id").One(&latest); err != nil {
return count, nil
}
return count, &latest
}
func (c *PlatformCursorEquipmentController) rowToMap(row *models.PlatformCursorEquipment) map[string]interface{} {
activationCount, latestActivation := c.cursorActivationSummary(row)
extractCount, latestExtract := c.cursorExtractSummary()
var bindActivationCode interface{}
var activationCodeId interface{}
var lastActivatedAt interface{} = row.ActivationTime
var expireTime interface{} = row.ExpireTime
var lastExtractedAt interface{}
if latestActivation != nil {
bindActivationCode = latestActivation.Code
activationCodeId = latestActivation.ID
if latestActivation.ActivatedAt != nil {
lastActivatedAt = latestActivation.ActivatedAt
}
if latestActivation.ExpiredAt != nil {
expireTime = latestActivation.ExpiredAt
}
}
if latestExtract != nil {
lastExtractedAt = latestExtract.ExtractedTime
}
return map[string]interface{}{
"id": row.ID,
"deviceInfo": row.DeviceInfo,
"machineCode": row.MachineCode,
"status": row.Status,
"system": row.System,
"os": row.System,
"version": row.Version,
"bindAccount": row.BindAccount,
"bindActivationCode": bindActivationCode,
"activationCode": bindActivationCode,
"activationCodeId": activationCodeId,
"ownerUserId": row.OwnerUserID,
"ownerUserName": row.OwnerUserName,
"activationTime": lastActivatedAt,
"lastActivatedAt": lastActivatedAt,
"expireTime": expireTime,
"expiredAt": expireTime,
"activationCount": activationCount,
"extractCount": extractCount,
"lastExtractedAt": lastExtractedAt,
"remark": row.Remark,
"createTime": row.CreateTime,
"updateTime": row.UpdateTime,
}
}
// List GET /platform/cursor/equipment/list
func (c *PlatformCursorEquipmentController) List() {
if _, err := c.platformClaims(); err != nil {
c.jsonErr(401, 401, err.Error())
return
}
page, _ := c.GetInt("page", 1)
pageSize, _ := c.GetInt("pageSize", 20)
if page < 1 {
page = 1
}
if pageSize < 1 {
pageSize = 20
}
if pageSize > 200 {
pageSize = 200
}
keyword := strings.TrimSpace(c.GetString("keyword"))
statusText := strings.TrimSpace(c.GetString("status"))
system := strings.TrimSpace(c.GetString("system"))
if system == "" {
system = strings.TrimSpace(c.GetString("os"))
}
qs := models.Orm.QueryTable(new(models.PlatformCursorEquipment)).Filter("delete_time__isnull", true)
if keyword != "" {
cond := orm.NewCondition().
Or("machine_code__icontains", keyword).
Or("device_info__icontains", keyword).
Or("bind_account__icontains", keyword).
Or("owner_user_name__icontains", keyword).
Or("remark__icontains", keyword)
qs = qs.SetCond(cond)
}
if statusText != "" {
status, err := strconv.ParseInt(statusText, 10, 8)
if err == nil && cursorEquipmentStatusValid(int8(status)) {
qs = qs.Filter("status", int8(status))
}
}
if system != "" {
qs = qs.Filter("system__icontains", system)
}
total, _ := qs.Count()
var rows []models.PlatformCursorEquipment
_, err := qs.OrderBy("-id").Limit(pageSize, (page-1)*pageSize).All(&rows)
if err != nil {
c.jsonErr(500, 500, "获取设备列表失败: "+err.Error())
return
}
list := make([]map[string]interface{}, 0, len(rows))
for i := range rows {
list = append(list, c.rowToMap(&rows[i]))
}
c.ok(map[string]interface{}{
"list": list,
"total": total,
"page": page,
"pageSize": pageSize,
})
}
// Detail GET /platform/cursor/equipment/detail/:id
func (c *PlatformCursorEquipmentController) Detail() {
if _, err := c.platformClaims(); err != nil {
c.jsonErr(401, 401, err.Error())
return
}
id, err := strconv.ParseUint(c.Ctx.Input.Param(":id"), 10, 64)
if err != nil || id == 0 {
c.jsonErr(400, 400, "无效ID")
return
}
var row models.PlatformCursorEquipment
err = models.Orm.QueryTable(new(models.PlatformCursorEquipment)).
Filter("id", id).
Filter("delete_time__isnull", true).
One(&row)
if err != nil {
c.jsonErr(404, 404, "设备不存在")
return
}
c.ok(c.rowToMap(&row))
}
type platformCursorEquipmentPayload struct {
ID *uint64 `json:"id"`
DeviceInfo *string `json:"deviceInfo"`
MachineCode *string `json:"machineCode"`
Status *int8 `json:"status"`
System *string `json:"system"`
Version *string `json:"version"`
BindAccount *string `json:"bindAccount"`
OwnerUserID *uint64 `json:"ownerUserId"`
OwnerUserName *string `json:"ownerUserName"`
ActivationTime *string `json:"activationTime"`
ExpireTime *string `json:"expireTime"`
Remark *string `json:"remark"`
}
func (c *PlatformCursorEquipmentController) readPayload() (*platformCursorEquipmentPayload, error) {
body, _ := io.ReadAll(c.Ctx.Request.Body)
var p platformCursorEquipmentPayload
if err := json.Unmarshal(body, &p); err != nil {
return nil, err
}
return &p, nil
}
func (c *PlatformCursorEquipmentController) payloadToUpdateMap(p *platformCursorEquipmentPayload, includeMachineCode bool) (map[string]interface{}, error) {
up := map[string]interface{}{}
if includeMachineCode {
if p.MachineCode == nil || strings.TrimSpace(*p.MachineCode) == "" {
return nil, fmt.Errorf("机器码不能为空")
}
up["machine_code"] = strings.TrimSpace(*p.MachineCode)
} else if p.MachineCode != nil {
if strings.TrimSpace(*p.MachineCode) == "" {
return nil, fmt.Errorf("机器码不能为空")
}
up["machine_code"] = strings.TrimSpace(*p.MachineCode)
}
if p.DeviceInfo != nil {
up["device_info"] = cursorEquipmentTrimPtr(p.DeviceInfo)
}
if p.Status != nil {
if !cursorEquipmentStatusValid(*p.Status) {
return nil, fmt.Errorf("状态不合法支持0 未激活、1 激活中、2 已过期、3 已禁用")
}
up["status"] = *p.Status
}
if p.System != nil {
up["system"] = cursorEquipmentTrimPtr(p.System)
}
if p.Version != nil {
up["version"] = cursorEquipmentTrimPtr(p.Version)
}
if p.BindAccount != nil {
up["bind_account"] = cursorEquipmentTrimPtr(p.BindAccount)
}
if p.OwnerUserID != nil {
if *p.OwnerUserID == 0 {
up["owner_user_id"] = nil
} else {
up["owner_user_id"] = *p.OwnerUserID
}
}
if p.OwnerUserName != nil {
up["owner_user_name"] = cursorEquipmentTrimPtr(p.OwnerUserName)
}
if p.ActivationTime != nil {
up["activation_time"] = cursorEquipmentTimePtr(p.ActivationTime)
}
if p.ExpireTime != nil {
up["expire_time"] = cursorEquipmentTimePtr(p.ExpireTime)
}
if p.Remark != nil {
up["remark"] = cursorEquipmentTrimPtr(p.Remark)
}
return up, nil
}
// Add POST /platform/cursor/equipment/add
func (c *PlatformCursorEquipmentController) Add() {
if _, err := c.platformClaims(); err != nil {
c.jsonErr(401, 401, err.Error())
return
}
p, err := c.readPayload()
if err != nil {
c.jsonErr(400, 400, "参数错误")
return
}
up, err := c.payloadToUpdateMap(p, true)
if err != nil {
c.jsonErr(400, 400, err.Error())
return
}
status := int8(0)
if value, ok := up["status"]; ok {
status = value.(int8)
}
row := models.PlatformCursorEquipment{
MachineCode: up["machine_code"].(string),
Status: status,
DeviceInfo: cursorEquipmentTrimPtr(p.DeviceInfo),
System: cursorEquipmentTrimPtr(p.System),
Version: cursorEquipmentTrimPtr(p.Version),
BindAccount: cursorEquipmentTrimPtr(p.BindAccount),
OwnerUserID: p.OwnerUserID,
OwnerUserName: cursorEquipmentTrimPtr(p.OwnerUserName),
ActivationTime: cursorEquipmentTimePtr(p.ActivationTime),
ExpireTime: cursorEquipmentTimePtr(p.ExpireTime),
Remark: cursorEquipmentTrimPtr(p.Remark),
CreateTime: time.Now(),
}
if row.OwnerUserID != nil && *row.OwnerUserID == 0 {
row.OwnerUserID = nil
}
id, err := models.Orm.Insert(&row)
if err != nil {
if strings.Contains(strings.ToLower(err.Error()), "duplicate") {
c.jsonErr(400, 400, "机器码已存在")
return
}
c.jsonErr(500, 500, "新增设备失败: "+err.Error())
return
}
c.ok(map[string]interface{}{"id": id})
}
// Update POST /platform/cursor/equipment/update
func (c *PlatformCursorEquipmentController) Update() {
if _, err := c.platformClaims(); err != nil {
c.jsonErr(401, 401, err.Error())
return
}
p, err := c.readPayload()
if err != nil {
c.jsonErr(400, 400, "参数错误")
return
}
if p.ID == nil || *p.ID == 0 {
c.jsonErr(400, 400, "无效ID")
return
}
up, err := c.payloadToUpdateMap(p, false)
if err != nil {
c.jsonErr(400, 400, err.Error())
return
}
if len(up) == 0 {
c.jsonErr(400, 400, "无更新字段")
return
}
now := time.Now()
up["update_time"] = now
n, err := models.Orm.QueryTable(new(models.PlatformCursorEquipment)).
Filter("id", *p.ID).
Filter("delete_time__isnull", true).
Update(up)
if err != nil {
if strings.Contains(strings.ToLower(err.Error()), "duplicate") {
c.jsonErr(400, 400, "机器码已存在")
return
}
c.jsonErr(500, 500, "更新设备失败: "+err.Error())
return
}
if n == 0 {
c.jsonErr(404, 404, "设备不存在")
return
}
c.ok(nil)
}
// Delete POST /platform/cursor/equipment/delete/:id
func (c *PlatformCursorEquipmentController) Delete() {
if _, err := c.platformClaims(); err != nil {
c.jsonErr(401, 401, err.Error())
return
}
id, err := strconv.ParseUint(c.Ctx.Input.Param(":id"), 10, 64)
if err != nil || id == 0 {
c.jsonErr(400, 400, "无效ID")
return
}
now := time.Now()
n, err := models.Orm.QueryTable(new(models.PlatformCursorEquipment)).
Filter("id", id).
Filter("delete_time__isnull", true).
Update(map[string]interface{}{"delete_time": now})
if err != nil {
c.jsonErr(500, 500, "删除设备失败: "+err.Error())
return
}
if n == 0 {
c.jsonErr(404, 404, "设备不存在")
return
}
c.ok(nil)
}
type platformCursorEquipmentActivatePayload struct {
ID uint64 `json:"id"`
}
// Activate POST /platform/cursor/equipment/activate
func (c *PlatformCursorEquipmentController) Activate() {
if _, err := c.platformClaims(); err != nil {
c.jsonErr(401, 401, err.Error())
return
}
body, _ := io.ReadAll(c.Ctx.Request.Body)
var p platformCursorEquipmentActivatePayload
if err := json.Unmarshal(body, &p); err != nil || p.ID == 0 {
c.jsonErr(400, 400, "无效ID")
return
}
now := time.Now()
n, err := models.Orm.QueryTable(new(models.PlatformCursorEquipment)).
Filter("id", p.ID).
Filter("delete_time__isnull", true).
Update(map[string]interface{}{
"status": int8(1),
"activation_time": now,
"update_time": now,
})
if err != nil {
c.jsonErr(500, 500, "激活设备失败: "+err.Error())
return
}
if n == 0 {
c.jsonErr(404, 404, "设备不存在")
return
}
c.ok(nil)
}
// ActivationRecords GET /platform/cursor/equipment/activationRecords
func (c *PlatformCursorEquipmentController) ActivationRecords() {
if _, err := c.platformClaims(); err != nil {
c.jsonErr(401, 401, err.Error())
return
}
equipmentID, _ := c.GetUint64("equipmentId")
if equipmentID == 0 {
equipmentID, _ = c.GetUint64("id")
}
if equipmentID == 0 {
c.jsonErr(400, 400, "缺少设备ID")
return
}
var equipment models.PlatformCursorEquipment
if err := models.Orm.QueryTable(new(models.PlatformCursorEquipment)).
Filter("id", equipmentID).
Filter("delete_time__isnull", true).
One(&equipment); err != nil {
c.jsonErr(404, 404, "设备不存在")
return
}
page, _ := c.GetInt("page", 1)
pageSize, _ := c.GetInt("pageSize", 20)
if page < 1 {
page = 1
}
if pageSize < 1 {
pageSize = 20
}
if pageSize > 200 {
pageSize = 200
}
cond := orm.NewCondition().
And("delete_time__isnull", true).
AndCond(orm.NewCondition().
Or("bind_device_id", equipment.ID).
Or("machine_code", equipment.MachineCode))
qs := models.Orm.QueryTable(new(models.PlatformCursorActivationCode)).SetCond(cond)
total, _ := qs.Count()
var rows []models.PlatformCursorActivationCode
if _, err := qs.OrderBy("-activated_at", "-id").Limit(pageSize, (page-1)*pageSize).All(&rows); err != nil {
c.jsonErr(500, 500, "获取激活记录失败: "+err.Error())
return
}
list := make([]map[string]interface{}, 0, len(rows))
for i := range rows {
row := rows[i]
list = append(list, map[string]interface{}{
"id": row.ID,
"code": row.Code,
"activationCode": row.Code,
"status": row.Status,
"durationDays": row.DurationDays,
"machineCode": row.MachineCode,
"deviceInfo": row.DeviceInfo,
"ownerUserId": row.OwnerUserID,
"ownerUserName": row.OwnerUserName,
"activatedAt": row.ActivatedAt,
"expiredAt": row.ExpiredAt,
"createdAt": row.CreateTime,
"remark": row.Remark,
})
}
c.ok(map[string]interface{}{
"list": list,
"total": total,
"page": page,
"pageSize": pageSize,
})
}
// ExtractRecords GET /platform/cursor/equipment/extractRecords
func (c *PlatformCursorEquipmentController) ExtractRecords() {
if _, err := c.platformClaims(); err != nil {
c.jsonErr(401, 401, err.Error())
return
}
equipmentID, _ := c.GetUint64("equipmentId")
if equipmentID == 0 {
equipmentID, _ = c.GetUint64("id")
}
if equipmentID == 0 {
c.jsonErr(400, 400, "缺少设备ID")
return
}
var equipment models.PlatformCursorEquipment
if err := models.Orm.QueryTable(new(models.PlatformCursorEquipment)).
Filter("id", equipmentID).
Filter("delete_time__isnull", true).
One(&equipment); err != nil {
c.jsonErr(404, 404, "设备不存在")
return
}
page, _ := c.GetInt("page", 1)
pageSize, _ := c.GetInt("pageSize", 20)
if page < 1 {
page = 1
}
if pageSize < 1 {
pageSize = 20
}
if pageSize > 200 {
pageSize = 200
}
qs := models.Orm.QueryTable(new(models.PlatformAccountPoolCursor)).
Filter("delete_time__isnull", true).
Filter("is_extracted__gt", 0)
total, _ := qs.Count()
var rows []models.PlatformAccountPoolCursor
if _, err := qs.OrderBy("-extracted_time", "-id").Limit(pageSize, (page-1)*pageSize).All(&rows); err != nil {
c.jsonErr(500, 500, "获取提取记录失败: "+err.Error())
return
}
list := make([]map[string]interface{}, 0, len(rows))
for i := range rows {
row := rows[i]
content := buildCardResult(&row.Account, &row.Password, row.Token, row.DataType)
list = append(list, map[string]interface{}{
"id": row.ID,
"status": row.IsExtracted,
"isExtracted": row.IsExtracted,
"platform": row.ExtractedPlatform,
"extractedPlatform": row.ExtractedPlatform,
"dataType": row.DataType,
"type": row.DataType,
"account": row.Account,
"password": row.Password,
"token": row.Token,
"content": content,
"extractedAt": row.ExtractedTime,
"createdAt": row.ExtractedTime,
"remark": row.Remark,
})
}
c.ok(map[string]interface{}{
"list": list,
"total": total,
"page": page,
"pageSize": pageSize,
})
}

View File

@ -0,0 +1,63 @@
package controllers
import (
"strings"
"time"
"server/models"
"server/pkg/tokenprobe"
)
func poolTableName(module string) string {
switch module {
case "cursor":
return new(models.PlatformAccountPoolCursor).TableName()
case "windsurf":
return new(models.PlatformAccountPoolWindsurf).TableName()
case "krio":
return new(models.PlatformAccountPoolKiro).TableName()
default:
return ""
}
}
// poolNeedsTokenProbe account 类型无 Token无需探测tk / account_tk 需探测。
func poolNeedsTokenProbe(dataType, token string) bool {
if strings.TrimSpace(token) == "" {
return false
}
return dataType != "account"
}
func poolSaveCursorIsUsed(id uint64, isUsed int8) {
_, _ = models.Orm.QueryTable(new(models.PlatformAccountPoolCursor)).
Filter("id", id).
Update(map[string]interface{}{
"is_used": isUsed,
"update_time": time.Now(),
})
}
// poolProbeToken 探测 Tokencursor 模块会回写 is_used。
func poolProbeToken(module, dataType, token string, rowID uint64) bool {
if !poolNeedsTokenProbe(dataType, token) {
return true
}
r := tokenprobe.ProbeOfficial(module, token)
if module == "cursor" && rowID > 0 {
var isUsed int8
if r.OK {
isUsed = 1
}
poolSaveCursorIsUsed(rowID, isUsed)
}
return r.OK
}
// poolIsUsedAvailable 已有探测结论时1=可用0=不可用nil=未探测。
func poolIsUsedAvailable(isUsed *int8) (known bool, available bool) {
if isUsed == nil {
return false, false
}
return true, *isUsed == 1
}

View File

@ -0,0 +1,31 @@
-- Cursor 激活码管理
-- status: 0 未使用 1 已使用 2 已过期 3 已禁用
-- type: 0 自定义 1 天卡 7 周卡 30 月卡 90 季卡 365 年卡
CREATE TABLE IF NOT EXISTS `yz_platform_cursor_activation_code` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
`code` varchar(128) NOT NULL COMMENT '激活码',
`type` int NOT NULL DEFAULT 30 COMMENT '卡密类型0自定义 1天卡 7周卡 30月卡 90季卡 365年卡',
`status` tinyint NOT NULL DEFAULT 0 COMMENT '状态0未使用 1已使用 2已过期 3已禁用',
`duration_days` int NOT NULL DEFAULT 30 COMMENT '有效天数',
`bind_account` varchar(128) DEFAULT NULL COMMENT '绑定账号',
`bind_device_id` bigint unsigned DEFAULT NULL COMMENT '绑定设备ID关联 yz_platform_cursor_equipment.id',
`machine_code` varchar(128) DEFAULT NULL COMMENT '绑定设备机器码',
`device_info` varchar(1000) DEFAULT NULL COMMENT '绑定设备信息',
`owner_user_id` bigint unsigned DEFAULT NULL COMMENT '归属用户ID',
`owner_user_name` varchar(128) DEFAULT NULL COMMENT '归属用户名称',
`activated_at` datetime DEFAULT NULL COMMENT '激活时间',
`expired_at` datetime DEFAULT NULL COMMENT '过期时间',
`remark` varchar(1000) DEFAULT NULL COMMENT '备注',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
`delete_time` datetime DEFAULT NULL COMMENT '删除时间',
PRIMARY KEY (`id`),
UNIQUE KEY `uk_code` (`code`),
KEY `idx_status_delete` (`status`,`delete_time`),
KEY `idx_type_status` (`type`,`status`),
KEY `idx_bind_account` (`bind_account`),
KEY `idx_bind_device_id` (`bind_device_id`),
KEY `idx_owner_user_id` (`owner_user_id`),
KEY `idx_expired_at` (`expired_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Cursor续杯激活码';

View File

@ -1,53 +1,24 @@
package models
import (
"fmt"
"strings"
"sync"
"time"
"github.com/beego/beego/v2/client/orm"
)
// CmsArticle CMS文章表: yz_cms_article
type CmsArticle struct {
ID uint64 `orm:"column(id);pk;auto" json:"id"`
Tid uint64 `orm:"column(tid)" json:"tid"`
Title string `orm:"column(title);size(255)" json:"title"`
Author string `orm:"column(author);size(100);default()" json:"author"`
CateID uint64 `orm:"column(cate_id);default(0)" json:"cate_id"`
Content string `orm:"column(content);type(text);null" json:"content"`
Desc string `orm:"column(desc);size(500);default()" json:"desc"`
Image string `orm:"column(image);size(500);default()" json:"image"`
IsTrans int8 `orm:"column(is_trans);default(0)" json:"is_trans"`
TransURL *string `orm:"column(transurl);size(500);null" json:"transurl"`
Status int8 `orm:"column(status);default(1)" json:"status"` // 1草稿 2已发布 3已下架
Views int64 `orm:"column(views);default(0)" json:"views"`
Likes int64 `orm:"column(likes);default(0)" json:"likes"`
Top int8 `orm:"column(top);default(0)" json:"top"`
Recommend int8 `orm:"column(recommend);default(0)" json:"recommend"`
PublishTime *time.Time `orm:"column(publish_time);type(datetime);null" json:"publish_time"`
PublisherID uint64 `orm:"column(publisher_id);default(0)" json:"publisher_id"`
CreateTime time.Time `orm:"column(create_time);type(datetime);auto_now_add" json:"create_time"`
UpdateTime *time.Time `orm:"column(update_time);type(datetime);auto_now;null" json:"update_time"`
DeleteTime *time.Time `orm:"column(delete_time);type(datetime);null" json:"delete_time"`
}
func (m *CmsArticle) TableName() string {
return "yz_cms_article"
}
// CmsArticleCategory CMS文章分类表: yz_cms_article_category
// CmsArticleCategory CMS 文章分类 yz_cms_article_category
type CmsArticleCategory struct {
ID uint64 `orm:"column(id);pk;auto" json:"id"`
Tid uint64 `orm:"column(tid)" json:"tid"`
Cid uint64 `orm:"column(cid);default(0)" json:"cid"` // 父级分类ID
Tid uint64 `orm:"column(tid);default(0)" json:"tid"`
Cid uint64 `orm:"column(cid);default(0)" json:"cid"`
Name string `orm:"column(name);size(100)" json:"name"`
Image string `orm:"column(image);size(500);default()" json:"image"`
Desc string `orm:"column(desc);size(500);default()" json:"desc"`
Sort int `orm:"column(sort);default(0)" json:"sort"`
Status int8 `orm:"column(status);default(1)" json:"status"`
CreateTime time.Time `orm:"column(create_time);type(datetime);auto_now_add" json:"create_time"`
UpdateTime *time.Time `orm:"column(update_time);type(datetime);auto_now;null" json:"update_time"`
CreateTime time.Time `orm:"column(create_time);auto_now_add;type(datetime)" json:"create_time"`
UpdateTime *time.Time `orm:"column(update_time);type(datetime);null" json:"update_time"`
DeleteTime *time.Time `orm:"column(delete_time);type(datetime);null" json:"delete_time"`
}
@ -55,137 +26,133 @@ func (m *CmsArticleCategory) TableName() string {
return "yz_cms_article_category"
}
// EnsureCmsArticleTables 确保 CMS 文章相关表存在。
func EnsureCmsArticleTables() error {
sqls := []string{
`CREATE TABLE IF NOT EXISTS ` + "`yz_cms_article_category`" + ` (
` + "`id`" + ` bigint unsigned NOT NULL AUTO_INCREMENT,
` + "`tid`" + ` bigint unsigned NOT NULL DEFAULT 0,
` + "`cid`" + ` bigint unsigned NOT NULL DEFAULT 0,
` + "`name`" + ` varchar(100) NOT NULL DEFAULT '',
` + "`image`" + ` varchar(500) NOT NULL DEFAULT '',
` + "`desc`" + ` varchar(500) NOT NULL DEFAULT '',
` + "`sort`" + ` int NOT NULL DEFAULT 0,
` + "`status`" + ` tinyint NOT NULL DEFAULT 1,
` + "`create_time`" + ` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
` + "`update_time`" + ` datetime NULL DEFAULT NULL,
` + "`delete_time`" + ` datetime NULL DEFAULT NULL,
PRIMARY KEY (` + "`id`" + `),
KEY ` + "`idx_tid`" + ` (` + "`tid`" + `),
KEY ` + "`idx_tid_cid`" + ` (` + "`tid`" + `,` + "`cid`" + `),
KEY ` + "`idx_delete_time`" + ` (` + "`delete_time`" + `)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci`,
`CREATE TABLE IF NOT EXISTS ` + "`yz_cms_article`" + ` (
` + "`id`" + ` bigint unsigned NOT NULL AUTO_INCREMENT,
` + "`tid`" + ` bigint unsigned NOT NULL DEFAULT 0,
` + "`title`" + ` varchar(255) NOT NULL DEFAULT '',
` + "`author`" + ` varchar(100) NOT NULL DEFAULT '',
` + "`cate_id`" + ` bigint unsigned NOT NULL DEFAULT 0,
` + "`content`" + ` longtext NULL,
` + "`desc`" + ` varchar(500) NOT NULL DEFAULT '',
` + "`image`" + ` varchar(500) NOT NULL DEFAULT '',
` + "`is_trans`" + ` tinyint NOT NULL DEFAULT 0,
` + "`transurl`" + ` varchar(500) NULL DEFAULT NULL,
` + "`status`" + ` tinyint NOT NULL DEFAULT 1,
` + "`views`" + ` bigint NOT NULL DEFAULT 0,
` + "`likes`" + ` bigint NOT NULL DEFAULT 0,
` + "`top`" + ` tinyint NOT NULL DEFAULT 0,
` + "`recommend`" + ` tinyint NOT NULL DEFAULT 0,
` + "`publish_time`" + ` datetime NULL DEFAULT NULL,
` + "`publisher_id`" + ` bigint unsigned NOT NULL DEFAULT 0,
` + "`create_time`" + ` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
` + "`update_time`" + ` datetime NULL DEFAULT NULL,
` + "`delete_time`" + ` datetime NULL DEFAULT NULL,
PRIMARY KEY (` + "`id`" + `),
KEY ` + "`idx_tid`" + ` (` + "`tid`" + `),
KEY ` + "`idx_tid_cate`" + ` (` + "`tid`" + `,` + "`cate_id`" + `),
KEY ` + "`idx_tid_status`" + ` (` + "`tid`" + `,` + "`status`" + `),
KEY ` + "`idx_delete_time`" + ` (` + "`delete_time`" + `)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci`,
}
for _, sqlStr := range sqls {
if _, err := Orm.Raw(sqlStr).Exec(); err != nil {
return err
}
}
return nil
// CmsArticle CMS 文章 yz_cms_article
type CmsArticle struct {
ID uint64 `orm:"column(id);pk;auto" json:"id"`
Tid uint64 `orm:"column(tid);default(0)" json:"tid"`
Title string `orm:"column(title);size(255)" json:"title"`
Author string `orm:"column(author);size(100);default()" json:"author"`
CateID uint64 `orm:"column(cate_id);default(0)" json:"cate_id"`
Content string `orm:"column(content);type(mediumtext);null" json:"content"`
Desc string `orm:"column(desc);size(500);default()" json:"desc"`
Image string `orm:"column(image);size(500);default()" json:"image"`
IsTrans int8 `orm:"column(is_trans);default(0)" json:"is_trans"`
TransURL *string `orm:"column(transurl);size(500);null" json:"transurl"`
Status int8 `orm:"column(status);default(0)" json:"status"`
Top int8 `orm:"column(top);default(0)" json:"top"`
Recommend int8 `orm:"column(recommend);default(0)" json:"recommend"`
Views int `orm:"column(views);default(0)" json:"views"`
Likes int `orm:"column(likes);default(0)" json:"likes"`
PublisherID *uint64 `orm:"column(publisher_id);null" json:"publisher_id"`
PublishTime *time.Time `orm:"column(publish_time);type(datetime);null" json:"publish_time"`
CreateTime time.Time `orm:"column(create_time);auto_now_add;type(datetime)" json:"create_time"`
UpdateTime *time.Time `orm:"column(update_time);type(datetime);null" json:"update_time"`
DeleteTime *time.Time `orm:"column(delete_time);type(datetime);null" json:"delete_time"`
}
func (m *CmsArticle) TableName() string {
return "yz_cms_article"
}
var cmsArticleTablesOnce sync.Once
// EnsureCmsArticleTables 首次使用时自动建表(若不存在)。
func EnsureCmsArticleTables() error {
var err error
cmsArticleTablesOnce.Do(func() {
_, err = Orm.Raw(`
CREATE TABLE IF NOT EXISTS yz_cms_article_category (
id bigint unsigned NOT NULL AUTO_INCREMENT,
tid bigint unsigned NOT NULL DEFAULT 0,
cid bigint unsigned NOT NULL DEFAULT 0,
name varchar(100) NOT NULL DEFAULT '',
image varchar(500) NOT NULL DEFAULT '',
` + "`desc`" + ` varchar(500) NOT NULL DEFAULT '',
sort int NOT NULL DEFAULT 0,
status tinyint NOT NULL DEFAULT 1,
create_time datetime NOT NULL,
update_time datetime DEFAULT NULL,
delete_time datetime DEFAULT NULL,
PRIMARY KEY (id),
KEY idx_tid_cid (tid, cid)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4`).Exec()
if err != nil {
return
}
_, err = Orm.Raw(`
CREATE TABLE IF NOT EXISTS yz_cms_article (
id bigint unsigned NOT NULL AUTO_INCREMENT,
tid bigint unsigned NOT NULL DEFAULT 0,
title varchar(255) NOT NULL DEFAULT '',
author varchar(100) NOT NULL DEFAULT '',
cate_id bigint unsigned NOT NULL DEFAULT 0,
content mediumtext,
` + "`desc`" + ` varchar(500) NOT NULL DEFAULT '',
image varchar(500) NOT NULL DEFAULT '',
is_trans tinyint NOT NULL DEFAULT 0,
transurl varchar(500) DEFAULT NULL,
status tinyint NOT NULL DEFAULT 0,
top tinyint NOT NULL DEFAULT 0,
recommend tinyint NOT NULL DEFAULT 0,
views int NOT NULL DEFAULT 0,
likes int NOT NULL DEFAULT 0,
publisher_id bigint unsigned DEFAULT NULL,
publish_time datetime DEFAULT NULL,
create_time datetime NOT NULL,
update_time datetime DEFAULT NULL,
delete_time datetime DEFAULT NULL,
PRIMARY KEY (id),
KEY idx_tid_status (tid, status),
KEY idx_cate_id (cate_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4`).Exec()
})
return err
}
func CmsCategoryNameMap(tid uint64, ids []uint64) map[uint64]string {
out := make(map[uint64]string)
if len(ids) == 0 {
return out
}
var rows []CmsArticleCategory
_, _ = Orm.QueryTable(new(CmsArticleCategory)).
Filter("tid", tid).
Filter("id__in", ids).
Filter("delete_time__isnull", true).
All(&rows, "ID", "Name")
for _, r := range rows {
out[r.ID] = r.Name
}
return out
}
// CmsFormatTime 格式化 CMS 可空时间。
func CmsFormatTime(t *time.Time) string {
if t == nil || t.IsZero() {
if t == nil {
return ""
}
return t.Format("2006-01-02 15:04:05")
}
// CmsCategoryNameMap 批量获取分类ID到分类名称的映射。
func CmsCategoryNameMap(tid uint64, cateIDs []uint64) map[uint64]string {
result := make(map[uint64]string)
if tid == 0 || len(cateIDs) == 0 {
return result
}
seen := make(map[uint64]bool)
ids := make([]uint64, 0, len(cateIDs))
for _, id := range cateIDs {
if id == 0 || seen[id] {
continue
}
seen[id] = true
ids = append(ids, id)
}
if len(ids) == 0 {
return result
}
var rows []CmsArticleCategory
_, err := Orm.QueryTable(new(CmsArticleCategory)).
Filter("tid", tid).
Filter("id__in", ids).
Filter("delete_time__isnull", true).
All(&rows, "id", "name")
if err != nil && err != orm.ErrNoRows {
return result
}
for _, row := range rows {
result[row.ID] = row.Name
}
return result
}
// CmsSimilarArticles 根据标题查找相似文章,用于创建文章时提示重复内容。
func CmsSimilarArticles(tid uint64, title string, limit int) ([]map[string]interface{}, error) {
title = strings.TrimSpace(title)
if tid == 0 || title == "" {
return []map[string]interface{}{}, nil
}
func CmsSimilarArticles(tid uint64, title string, limit int) ([]orm.Params, error) {
if limit <= 0 {
limit = 5
}
var rows []CmsArticle
_, err := Orm.QueryTable(new(CmsArticle)).
Filter("tid", tid).
Filter("title__icontains", title).
Filter("delete_time__isnull", true).
OrderBy("-id").
Filter("title__icontains", title).
Limit(limit).
All(&rows, "id", "title", "cate_id", "status", "create_time")
if err != nil && err != orm.ErrNoRows {
All(&rows, "ID", "Title")
if err != nil {
return nil, err
}
out := make([]map[string]interface{}, 0, len(rows))
for _, row := range rows {
out = append(out, map[string]interface{}{
"id": row.ID,
"title": row.Title,
"cate_id": row.CateID,
"status": row.Status,
"create_time": row.CreateTime.Format("2006-01-02 15:04:05"),
"similarity": fmt.Sprintf("标题包含“%s”", title),
out := make([]orm.Params, 0, len(rows))
for _, r := range rows {
out = append(out, orm.Params{
"id": r.ID,
"title": r.Title,
"similarity": 80,
})
}
return out, nil

View File

@ -56,11 +56,13 @@ func Init(_ string) {
new(ComplaintCategory),
new(PlatformComplaint),
new(SystemSoftwareUpgrade),
new(CmsArticle),
new(CmsArticleCategory),
new(PlatformCursorEquipment),
new(PlatformCursorActivationCode),
new(PlatformAccountPoolKiro),
new(PlatformAccountPoolWindsurf),
new(PlatformAccountPoolCursor),
new(CmsArticleCategory),
new(CmsArticle),
)
// 创建全局 Ormer

View File

@ -0,0 +1,28 @@
package models
import "time"
// PlatformCursorActivationCode Cursor 续杯激活码 yz_platform_cursor_activation_code
type PlatformCursorActivationCode struct {
ID uint64 `orm:"column(id);pk;auto" json:"id"`
Code string `orm:"column(code);size(128);unique" json:"code"`
Type int `orm:"column(type);default(30)" json:"type"`
Status int8 `orm:"column(status);default(0)" json:"status"`
DurationDays int `orm:"column(duration_days);default(30)" json:"durationDays"`
BindAccount *string `orm:"column(bind_account);size(128);null" json:"bindAccount"`
BindDeviceID *uint64 `orm:"column(bind_device_id);null" json:"bindDeviceId"`
MachineCode *string `orm:"column(machine_code);size(128);null" json:"machineCode"`
DeviceInfo *string `orm:"column(device_info);size(1000);null" json:"deviceInfo"`
OwnerUserID *uint64 `orm:"column(owner_user_id);null" json:"ownerUserId"`
OwnerUserName *string `orm:"column(owner_user_name);size(128);null" json:"ownerUserName"`
ActivatedAt *time.Time `orm:"column(activated_at);type(datetime);null" json:"activatedAt"`
ExpiredAt *time.Time `orm:"column(expired_at);type(datetime);null" json:"expiredAt"`
Remark *string `orm:"column(remark);size(1000);null" json:"remark"`
CreateTime time.Time `orm:"column(create_time);auto_now_add;type(datetime)" json:"createTime"`
UpdateTime *time.Time `orm:"column(update_time);auto_now;type(datetime);null" json:"updateTime"`
DeleteTime *time.Time `orm:"column(delete_time);type(datetime);null" json:"deleteTime"`
}
func (m *PlatformCursorActivationCode) TableName() string {
return "yz_platform_cursor_activation_code"
}

View File

@ -0,0 +1,26 @@
package models
import "time"
// PlatformCursorEquipment Cursor 设备管理 yz_platform_cursor_equipment
type PlatformCursorEquipment struct {
ID uint64 `orm:"column(id);pk;auto" json:"id"`
DeviceInfo *string `orm:"column(device_info);size(1000);null" json:"deviceInfo"`
MachineCode string `orm:"column(machine_code);size(128);unique" json:"machineCode"`
Status int8 `orm:"column(status);default(0)" json:"status"`
System *string `orm:"column(system);size(64);null" json:"system"`
Version *string `orm:"column(version);size(64);null" json:"version"`
BindAccount *string `orm:"column(bind_account);size(128);null" json:"bindAccount"`
OwnerUserID *uint64 `orm:"column(owner_user_id);null" json:"ownerUserId"`
OwnerUserName *string `orm:"column(owner_user_name);size(128);null" json:"ownerUserName"`
ActivationTime *time.Time `orm:"column(activation_time);type(datetime);null" json:"activationTime"`
ExpireTime *time.Time `orm:"column(expire_time);type(datetime);null" json:"expireTime"`
Remark *string `orm:"column(remark);size(1000);null" json:"remark"`
CreateTime time.Time `orm:"column(create_time);auto_now_add;type(datetime)" json:"createTime"`
UpdateTime *time.Time `orm:"column(update_time);auto_now;type(datetime);null" json:"updateTime"`
DeleteTime *time.Time `orm:"column(delete_time);type(datetime);null" json:"deleteTime"`
}
func (m *PlatformCursorEquipment) TableName() string {
return "yz_platform_cursor_equipment"
}

View File

@ -16,5 +16,5 @@ type SystemTenantDomain struct {
}
func (m *SystemTenantDomain) TableName() string {
return "yz_tenant_domain"
return "yz_system_tenant_domain"
}

View File

@ -10,7 +10,6 @@ import (
"io"
"net/http"
"os"
"regexp"
"runtime"
"strings"
"time"
@ -23,7 +22,7 @@ import (
const (
cursorBackendURL = "https://api2.cursor.sh"
cursorAgentPath = "/aiserver.v1.ChatService/StreamUnifiedChatWithTools"
cursorClientVersion = "3.6.31"
cursorClientVersion = "2.6.22"
cursorHiMaxRead = 512 * 1024
// probeHiText 发往官方 Agent 的探测内容(与前端展示 probeMessage 一致)
probeHiText = "hi"
@ -277,43 +276,55 @@ var cursorQuotaTipSig = []byte("Get Cursor Pro for more Agent usage, unlimited T
const cursorLimitTipPrefix = "Get Cursor Pro for more Agent usage, unlimited Tab"
// classifyCursorRawStream 在官方流式二进制/文本中匹配用量与升级提示
// 返回 (isQuotaExhausted, message)
// isQuotaExhausted: true 表示额度用完/Token不可用false 表示 Token 可用(可能有警告信息)
func classifyCursorRawStream(raw []byte) (isQuotaExhausted bool, message string) {
// classifyCursorRawStream 在官方流式二进制/文本中匹配用量与升级提示ASCII 区不区分大小写 + UTF-8 短语)
func classifyCursorRawStream(raw []byte) (blocked bool, reason string) {
if len(raw) == 0 {
return false, ""
}
// 额度用尽只按明确完整提示判定,避免“可用但带推广/提示文案”的 Token 被误标为已用完。
// 用户自定义的二进制特征仍保留给部署方精确配置。
for _, sig := range cursorQuotaExhaustedSigsFromEnv() {
if bytes.Contains(raw, sig) {
return true, "该TOKEN已用完额度已耗尽"
return true, fmt.Sprintf("流中匹配CURSOR_QUOTA_EXHAUSTED_SIG_HEX 配置的二进制特征(%d 字节)", len(sig))
}
}
if bytes.Contains(raw, cursorQuotaTipSig) {
return true, "该TOKEN已用完Get Cursor Pro for more Agent usage, unlimited Tab, and more."
return true, "流中匹配:" + string(cursorQuotaTipSig)
}
// 社区脚本仅到「…Agent usage」的 ASCII 前缀(流里可能只有前半段)
if bytes.Contains(raw, cursorQuotaExhaustedSigCommunity) {
return true, "流中匹配Get Cursor Pro for more Agent usage…社区 QuotaExhaustedSignature 前缀)"
}
if bytes.Contains(raw, []byte(cursorLimitTipPrefix)) {
return true, "流中匹配:" + cursorLimitTipPrefix + "…"
}
low := append([]byte(nil), raw...)
asciiLowerInPlace(low)
if bytes.Contains(low, []byte("you've hit your usage limit")) ||
bytes.Contains(low, []byte("youve hit your usage limit")) ||
bytes.Contains(low, []byte("hit your usage limit")) {
return true, "流中匹配hit your usage limit / you've hit your usage limit"
}
if bytes.Contains(low, []byte("get cursor pro for more agent usage")) {
return true, "流中匹配get cursor pro for more agent usage"
}
if bytes.Contains(low, []byte("upgrade to pro")) {
return true, "流中匹配upgrade to pro"
}
if bytes.Contains(low, []byte("get cursor pro")) && bytes.Contains(low, []byte("agent")) {
return true, "流中匹配get cursor pro + agent"
}
if bytes.Contains(low, []byte("usage limit")) {
return true, "流中匹配usage limit"
}
if bytes.Contains(low, []byte("unlimited tab")) && bytes.Contains(low, []byte("cursor pro")) {
return true, "流中匹配unlimited tab + cursor pro"
}
flat := strings.ToLower(strings.ToValidUTF8(string(raw), "\uFFFD"))
flat = strings.ReplaceAll(flat, "\u2019", "'")
flat = strings.ReplaceAll(flat, "\u2019", "'") // 右单引号
flat = strings.ReplaceAll(flat, "`", "'")
if strings.Contains(flat, "suspicious activity") ||
strings.Contains(flat, "unauthenticated") ||
strings.Contains(flat, "unauthorized request") ||
strings.Contains(flat, "unauthorizedrequest") ||
strings.Contains(flat, "error_unauthorized") {
return true, "该TOKEN不可用账号触发可疑活动风控/未认证,需要重新登录)"
if strings.Contains(flat, "you've hit your usage limit") {
return true, "流中匹配you've hit your usage limitUTF-8"
}
// 版本过旧警告 - 这不是额度问题Token 仍然可用
// 返回 false表示 Token 可用
if strings.Contains(flat, "very old version") || strings.Contains(flat, "update to the latest version") {
return false, "Token可用但客户端版本过旧建议更新到最新版本"
}
return false, ""
}
@ -389,29 +400,41 @@ func decodeConnectFramedBody(raw []byte) ([]byte, string, bool) {
return nil, "", false
}
return out.Bytes(), "", true
note := fmt.Sprintf("响应体已按 Connect 分帧解析(%d 帧", frameCount)
if compressedFrames > 0 {
note += fmt.Sprintf(",其中 %d 帧已做 gzip 解压", compressedFrames)
}
note += ")后分析"
return out.Bytes(), note, true
}
func decodeCursorResponseBody(raw []byte, contentEncoding string) ([]byte, string) {
if decoded, _, ok := decodeConnectFramedBody(raw); ok {
return decoded, ""
if decoded, note, ok := decodeConnectFramedBody(raw); ok {
return decoded, note
}
enc := strings.ToLower(strings.TrimSpace(contentEncoding))
if strings.Contains(enc, "gzip") || looksLikeGzip(raw) {
decoded, err := gunzipBytes(raw)
if err != nil {
return raw, ""
if strings.Contains(enc, "gzip") {
return raw, "响应头声明 gzip但解压失败已回退为原始字节预览"
}
return raw, "检测到 gzip 魔数,但解压失败,已回退为原始字节预览"
}
return decoded, ""
if strings.Contains(enc, "gzip") {
return decoded, "响应体已按 gzip 解压后分析"
}
return decoded, "响应体虽未显式声明 Content-Encoding但按 gzip 魔数解压后分析"
}
return raw, ""
if enc != "" {
return raw, "响应头 Content-Encoding=" + enc + ",当前未额外解码,按原始字节分析"
}
return raw, "响应体未压缩或未声明压缩,且未识别为 Connect 分帧,按原始字节分析"
}
// cursorStreamProtocol 与官方客户端一致Connect-RPC + protobuf 体HTTP/2 流式。
// 当前探测接口使用新版 Agent/aiserver.v1.ChatService/StreamUnifiedChatWithTools。
// 若 Cursor 后续强制更高客户端版本,可通过环境变量 CURSOR_CLIENT_VERSION 覆盖默认 X-Cursor-Client-Version。
const cursorStreamProtocol = "Connect-Protocol-Version:1 + application/connect+protoHTTP/2 二进制流gRPC/ConnectRPC 兼容形态,非 JSON REST"
// cursorStreamProtocol 与官方客户端一致Connect-RPC + protobuf 体HTTP/2 流式
const cursorStreamProtocol = "Connect-Protocol-Version:1 + application/connect+protoHTTP/2 二进制流gRPC 兼容形态,非 JSON REST"
// cursorStreamNote 说明 rawPreview / ok 的含义边界(与「仅通 200」结论一致
const cursorStreamNote = `【协议】本 URL 为 Cursor 官方 Agent 流式接口,请求体为 protobufrequestBodyPrefixHex 可见非表单/JSON` +
@ -461,189 +484,6 @@ func cursorProbeResult(ok bool, detail string, httpStatus int, reqBody, raw, pre
}
}
// cursorReadableServerOutput 从 Cursor 的 protobuf 二进制流里提取适合展示的可读文本。
// 注意:这里不完整解析 proto只做展示层清洗避免把字段号、长度前缀、UUID、think 过程等内容直接展示给用户。
func cursorReadableServerOutput(decoded []byte, maxBytes int) string {
if len(decoded) == 0 {
return ""
}
s := strings.ToValidUTF8(string(decoded), "")
s = strings.ReplaceAll(s, "\uFFFD", "")
finalMarkerRe := regexp.MustCompile(`(?is)<\s*[|]\s*final\s*[|]\s*>`)
s = finalMarkerRe.ReplaceAllString(s, "<final>")
var b strings.Builder
lastSpace := false
for _, r := range s {
switch {
case r == '\r' || r == '\n' || r == '\t' || r == ' ':
if !lastSpace {
b.WriteByte('\n')
}
lastSpace = true
case r >= 32:
b.WriteRune(r)
lastSpace = false
default:
// protobuf 字段号、长度前缀等控制字符经常刚好位于单词/JSON 字段之间。
// 这里用分隔符替代直接丢弃,避免 Your + request 被粘成 Yourrequest。
if !lastSpace {
b.WriteByte('\n')
}
lastSpace = true
}
}
cleaned := strings.TrimSpace(b.String())
if cleaned == "" {
return ""
}
uuidRe := regexp.MustCompile(`(?i)\b[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\b`)
cleaned = uuidRe.ReplaceAllString(cleaned, "")
var parts []string
const oldVersionText = "This is a very old version of Cursor. Please update to the latest version at [cursor.com/downloads](https://cursor.com/downloads)"
if strings.Contains(cleaned, oldVersionText) {
parts = append(parts, oldVersionText)
}
// 优先展示最终回复:先按 <final> 切分;没有 final 标记时,按被二进制流切碎的 </think> 标记切分。
finalText := ""
if idx := strings.LastIndex(cleaned, "<final>"); idx >= 0 {
finalText = cleaned[idx+len("<final>"):]
} else {
thinkCloseRe := regexp.MustCompile(`(?is)</\s*t\s*h\s*i\s*n\s*k\s*>`)
matches := thinkCloseRe.FindAllStringIndex(cleaned, -1)
if len(matches) > 0 {
finalText = cleaned[matches[len(matches)-1][1]:]
}
}
if strings.TrimSpace(finalText) == "" {
finalText = cleaned
}
finalText = cursorJoinFragmentedText(finalText)
if errorMessage := cursorExtractReadableCursorError(finalText); errorMessage != "" {
finalText = errorMessage
}
finalText = strings.TrimSuffix(finalText, "{}")
finalText = strings.TrimSpace(finalText)
finalText = strings.Trim(finalText, `'"#%{} `)
// 清理流尾残留的二进制标记例如a%߯B{}
tailJunkRe := regexp.MustCompile(`(?is)\s+[a-z]?%[^\s]{0,12}B\{\}\s*$`)
finalText = tailJunkRe.ReplaceAllString(finalText, "")
finalText = strings.TrimSpace(finalText)
if finalText != "" && !strings.Contains(strings.Join(parts, "\n"), finalText) {
parts = append(parts, finalText)
}
if len(parts) > 0 {
cleaned = strings.Join(parts, "\n\n")
} else {
cleaned = finalText
}
if maxBytes > 0 && len(cleaned) > maxBytes {
cleaned = cleaned[:maxBytes]
for len(cleaned) > 0 && !utf8.ValidString(cleaned) {
cleaned = cleaned[:len(cleaned)-1]
}
cleaned += "…(已截断)"
}
return strings.TrimSpace(cleaned)
}
func cursorExtractReadableCursorError(text string) string {
if text == "" {
return ""
}
unescaped := strings.ReplaceAll(text, `\n`, "\n")
unescaped = strings.ReplaceAll(unescaped, `\"`, `"`)
unescaped = strings.ReplaceAll(unescaped, `\/`, `/`)
if !(strings.Contains(strings.ToLower(unescaped), "error") ||
strings.Contains(strings.ToLower(unescaped), "unauthenticated") ||
strings.Contains(strings.ToLower(unescaped), "unauthorized") ||
strings.Contains(strings.ToLower(unescaped), "suspicious activity")) {
return ""
}
messageRe := regexp.MustCompile(`(?is)"(?:message|detail)"\s*:\s*"([^"]+)"`)
matches := messageRe.FindAllStringSubmatch(unescaped, -1)
for _, match := range matches {
if len(match) < 2 {
continue
}
msg := strings.TrimSpace(match[1])
if msg == "" {
continue
}
msg = strings.ReplaceAll(msg, `\n`, "\n")
msg = strings.ReplaceAll(msg, `\"`, `"`)
msg = cursorJoinFragmentedText(msg)
lowerMsg := strings.ToLower(msg)
if strings.Contains(lowerMsg, "suspicious activity") ||
strings.Contains(lowerMsg, "blocked") ||
strings.Contains(lowerMsg, "unauthorized") ||
strings.Contains(lowerMsg, "unauthenticated") {
return msg
}
}
if strings.Contains(strings.ToLower(unescaped), "suspicious activity") {
return "Your request has been blocked as our system has detected suspicious activity from your account. For troubleshooting, please visit the Cursor Docs at https://cursor.com/docs/troubleshooting/common-issues#suspicious-activity-message."
}
return ""
}
func cursorJoinFragmentedText(text string) string {
lines := strings.Split(text, "\n")
parts := make([]string, 0, len(lines))
for _, line := range lines {
part := strings.TrimSpace(line)
if part == "" {
continue
}
parts = append(parts, part)
}
out := strings.Join(parts, " ")
// 标点前不保留空格。
punctRe := regexp.MustCompile(`\s+([.,!?;:)\]}"',。!?;:)】》])`)
out = punctRe.ReplaceAllString(out, "$1")
// 只修复很明确的“单词内部被切开”场景,避免把 How can / I help / with your 误拼成 Howcan / Ihelp / withyour。
singlePrefixRe := regexp.MustCompile(`\b([b-hj-zB-HJ-Z])\s+([a-z]{2,})\b`)
out = singlePrefixRe.ReplaceAllString(out, "$1$2")
commonSuffixRe := regexp.MustCompile(`\b([A-Za-z]{3,})\s+(ing|ed|er|ers|ly|s)\b`)
out = commonSuffixRe.ReplaceAllString(out, "$1$2")
spaceRe := regexp.MustCompile(`\s+`)
out = spaceRe.ReplaceAllString(out, " ")
return strings.TrimSpace(out)
}
// cursorServerOutputDetail 将服务器响应内容放入 detail便于前端只展示 detail 时也能看到服务端输出。
func cursorServerOutputDetail(prefix string, decoded []byte) string {
serverOutput := cursorReadableServerOutput(decoded, 8000)
if serverOutput == "" {
return prefix
}
return prefix + ",服务器可读输出:\n" + serverOutput
}
// probeCursorHiAgent 探测 Cursor Token 可用性
func probeCursorHiAgent(authToken string) Result {
if strings.Contains(authToken, "::") {
if i := strings.LastIndex(authToken, "::"); i >= 0 {
@ -664,7 +504,7 @@ func probeCursorHiAgent(authToken string) Result {
fullURL := cursorBackendURL + cursorAgentPath
req, err := http.NewRequest(http.MethodPost, fullURL, bytes.NewReader(body))
if err != nil {
r := cursorProbeResult(false, "请求失败: "+err.Error(), 0, body, nil, nil)
r := cursorProbeResult(false, err.Error(), 0, body, nil, nil)
return r
}
req.Header.Set("Authorization", "Bearer "+authToken)
@ -692,36 +532,29 @@ func probeCursorHiAgent(authToken string) Result {
resp, err := cursorProbeHTTPClient.Do(req)
if err != nil {
return cursorProbeResult(false, "请求失败: "+err.Error(), 0, body, nil, nil)
return cursorProbeResult(false, "请求 Cursor Agent 失败: "+err.Error(), 0, body, nil, nil)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
raw, _ := io.ReadAll(io.LimitReader(resp.Body, cursorHiMaxRead))
decoded, _ := decodeCursorResponseBody(raw, resp.Header.Get("Content-Encoding"))
isQuotaExhausted, msg := classifyCursorRawStream(decoded)
if isQuotaExhausted {
return cursorProbeResult(false, msg, resp.StatusCode, body, raw, decoded)
decoded, decodeNote := decodeCursorResponseBody(raw, resp.Header.Get("Content-Encoding"))
blocked, reason := classifyCursorRawStream(decoded)
if blocked {
return cursorProbeResult(false, reason+""+decodeNote, resp.StatusCode, body, raw, decoded)
}
// 非 200 状态码且不是额度问题
return cursorProbeResult(false, fmt.Sprintf("HTTP %d - Token不可用", resp.StatusCode), resp.StatusCode, body, raw, decoded)
detail := fmt.Sprintf("HTTP %d非 200%s说明与协议边界见 streamNote", resp.StatusCode, decodeNote)
return cursorProbeResult(false, detail, resp.StatusCode, body, raw, decoded)
}
var buf bytes.Buffer
_, _ = io.Copy(&buf, io.LimitReader(resp.Body, cursorHiMaxRead))
raw := buf.Bytes()
decoded, _ := decodeCursorResponseBody(raw, resp.Header.Get("Content-Encoding"))
isQuotaExhausted, msg := classifyCursorRawStream(decoded)
if isQuotaExhausted {
// Token 不可用(额度用完等)
return cursorProbeResult(false, msg, resp.StatusCode, body, raw, decoded)
decoded, decodeNote := decodeCursorResponseBody(raw, resp.Header.Get("Content-Encoding"))
blocked, reason := classifyCursorRawStream(decoded)
if blocked {
return cursorProbeResult(false, reason+""+decodeNote, resp.StatusCode, body, raw, decoded)
}
// Token 可用时也把服务器实际输出放到 Detail避免前端只展示 Detail 时看不到 RawPreview。
if msg != "" {
return cursorProbeResult(true, cursorServerOutputDetail(msg, decoded), resp.StatusCode, body, raw, decoded)
}
return cursorProbeResult(true, cursorServerOutputDetail("Token可用", decoded), resp.StatusCode, body, raw, decoded)
detail := "HTTP 200未命中内置英文关键词" + decodeNote + ";二进制流含义与 ok 边界见 streamNote"
return cursorProbeResult(true, detail, resp.StatusCode, body, raw, decoded)
}

View File

@ -1,9 +1,8 @@
// Package tokenprobe 使用号池内 Token 调用各厂商接口做可用性探测。
// Cursor 走 api2.cursor.sh 的 Connect + protobuf 二进制流(非 JSON 文本接口)。
package tokenprobe
import (
"bytes"
"crypto/tls"
"encoding/base64"
"encoding/json"
"fmt"
@ -14,9 +13,13 @@ import (
"time"
)
var httpClient = &http.Client{Timeout: 25 * time.Second}
var httpClient = &http.Client{
Timeout: 12 * time.Second,
Transport: &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
},
}
// Result 探测结果Cursor 会填充 ProbeMessage / Endpoint / BytesRead / RawPreview 等)
type Result struct {
OK bool `json:"ok"`
Detail string `json:"detail"`
@ -30,7 +33,6 @@ type Result struct {
StreamNote string `json:"streamNote,omitempty"`
}
// ProbeOfficial 按号池模块探测 Tokencursor / windsurf / krio
func ProbeOfficial(module, rawToken string) Result {
tok := normalizeBearerToken(strings.TrimSpace(rawToken))
if tok == "" {
@ -38,8 +40,7 @@ func ProbeOfficial(module, rawToken string) Result {
}
switch module {
case "cursor":
// 直接使用 cursor_hi.go 中已有的完整探测函数
return probeCursorHiAgent(tok)
return probeCursor(tok)
case "windsurf":
return probeWindsurf(tok)
case "krio":
@ -57,12 +58,10 @@ func normalizeBearerToken(s string) string {
return s
}
// probeCursor Cursor Token 探测(直接使用 cursor_hi.go 的实现)
func probeCursor(token string) Result {
return probeCursorHiAgent(token)
}
// probeWindsurf WindSurf 探测
func probeWindsurf(apiKey string) Result {
payload := map[string]interface{}{
"metadata": map[string]string{
@ -119,13 +118,12 @@ func probeWindsurf(apiKey string) Result {
}
}
// probeKiro Kiro 探测
func probeKiro(accessToken string) Result {
arn := findProfileArnInJWT(accessToken)
if arn == "" {
return Result{
OK: false,
Detail: "无法从 Token 中解析 profileArnKiro 暂无法自动探测(需完整登录 JWT",
Detail: "无法从 Token 中解析 profileArnKiro 暂无法自动探测",
}
}
@ -163,7 +161,6 @@ func probeKiro(accessToken string) Result {
}
}
// decodeJWTPayloadMap 解析 JWT payload
func decodeJWTPayloadMap(raw string) (map[string]interface{}, error) {
tok := normalizeBearerToken(strings.TrimSpace(raw))
parts := strings.Split(tok, ".")
@ -181,7 +178,6 @@ func decodeJWTPayloadMap(raw string) (map[string]interface{}, error) {
return m, nil
}
// findProfileArnInJWT 从 JWT 中查找 profileArn
func findProfileArnInJWT(raw string) string {
m, err := decodeJWTPayloadMap(raw)
if err != nil {
@ -190,7 +186,6 @@ func findProfileArnInJWT(raw string) string {
return findProfileArnValue(m)
}
// findProfileArnValue 递归查找 profileArn
func findProfileArnValue(v interface{}) string {
switch x := v.(type) {
case map[string]interface{}:

View File

@ -11,6 +11,12 @@ func Register() {
// 客户端检查更新(无需登录)
beego.Router("/api/softwareupgrade/check", &controllers.ApiSoftwareUpgradeController{}, "get:Check")
// 登录器上报 Cursor 设备信息(无需登录)
beego.Router("/api/cursor/equipment/report", &controllers.ApiCursorEquipmentController{}, "post:Report")
// 登录器使用激活码激活/续期 Cursor 设备(无需登录)
beego.Router("/api/cursor/equipment/activateByCode", &controllers.ApiCursorEquipmentController{}, "post:ActivateByCode")
// 对外提卡接口(无需登录)
// GET /api/getcard?type=xianyu&module=cursor&data_type=tk
beego.Router("/api/getcard", &controllers.ApiGetCardController{}, "get:GetCard")

View File

@ -14,31 +14,20 @@ func Register() {
// RegisterAuthRoutes 注册 backend 认证相关路由。
func RegisterAuthRoutes() {
// backend 登录相关(统一走 /backend/*
// 登录、注册与找回密码相关
beego.Router("/backend/login", &controllers.BackendAuthController{}, "post:LoginBackend")
beego.Router("/backend/sendLoginCode", &controllers.BackendAuthController{}, "post:SendLoginCode")
beego.Router("/backend/loginBySms", &controllers.BackendAuthController{}, "post:LoginBySms")
beego.Router("/backend/logout", &controllers.BackendAuthController{}, "post:Logout")
// 极验与登录验证配置
beego.Router("/backend/login/getGeetest3Infos", &controllers.BackendAuthController{}, "get:GetGeetest3Infos")
beego.Router("/backend/login/getGeetest4Infos", &controllers.BackendAuthController{}, "get:GetGeetest4Infos")
beego.Router("/backend/login/getOpenVerify", &controllers.BackendAuthController{}, "get:GetOpenVerify")
// 登录相关接口
beego.Router("/backend/login/getGeetest3Infos", &controllers.BackendAuthController{}, "get:GetGeetest3Infos")
beego.Router("/backend/login/getGeetest4Infos", &controllers.BackendAuthController{}, "get:GetGeetest4Infos")
beego.Router("/backend/login/getOpenVerify", &controllers.BackendAuthController{}, "get:GetOpenVerify")
// 注册与找回密码
beego.Router("/backend/register", &controllers.BackendAuthController{}, "post:Register")
beego.Router("/backend/sendRegisterCode", &controllers.BackendAuthController{}, "post:SendRegisterCode")
beego.Router("/backend/resetPassword", &controllers.BackendAuthController{}, "post:ResetPassword")
beego.Router("/backend/sendResetCode", &controllers.BackendAuthController{}, "post:SendResetCode")
// 租户站点设置
beego.Router("/backend/normalInfos", &controllers.BackendSiteSettingsController{}, "get:GetNormalInfos")
beego.Router("/backend/saveNormalInfos", &controllers.BackendSiteSettingsController{}, "post:SaveNormalInfos")
// 极验与登录验证配置
beego.Router("/backend/login/getGeetest3Infos", &controllers.BackendAuthController{}, "get:GetGeetest3Infos")
beego.Router("/backend/login/getGeetest4Infos", &controllers.BackendAuthController{}, "get:GetGeetest4Infos")
beego.Router("/backend/login/getOpenVerify", &controllers.BackendAuthController{}, "get:GetOpenVerify")
// 菜单接口
beego.Router("/backend/menu/:id", &controllers.BackendMenuController{}, "get:GetBackendMenu")
@ -50,6 +39,18 @@ func RegisterAuthRoutes() {
beego.Router("/backend/operationLogs/:id", &controllers.BackendOperationLogController{}, "get:Detail;delete:Delete")
beego.Router("/backend/operationLogs/batchDelete", &controllers.BackendOperationLogController{}, "post:BatchDelete")
// 租户站点设置
beego.Router("/backend/normalInfos", &controllers.BackendSiteSettingsController{}, "get:GetNormalInfos")
beego.Router("/backend/saveNormalInfos", &controllers.BackendSiteSettingsController{}, "post:SaveNormalInfos")
beego.Router("/backend/legalInfos", &controllers.BackendSiteSettingsController{}, "get:GetLegalInfos")
beego.Router("/backend/saveLegalInfos", &controllers.BackendSiteSettingsController{}, "post:SaveLegalInfos")
beego.Router("/backend/companyInfos", &controllers.BackendSiteSettingsController{}, "get:GetCompanyInfos")
beego.Router("/backend/saveCompanyInfos", &controllers.BackendSiteSettingsController{}, "post:SaveCompanyInfos")
beego.Router("/backend/companySeo", &controllers.BackendSiteSettingsController{}, "get:GetCompanySeo")
beego.Router("/backend/saveCompanySeo", &controllers.BackendSiteSettingsController{}, "post:SaveCompanySeo")
beego.Router("/backend/loginVerifyInfos", &controllers.BackendLoginVerifyController{}, "get:GetLoginVerifyInfos")
beego.Router("/backend/saveloginVerifyInfos", &controllers.BackendLoginVerifyController{}, "post:SaveLoginVerifyInfos")
// 文件管理yz_system_files / yz_system_files_category
beego.Router("/backend/usercate", &controllers.BackendFileController{}, "get:GetUserCate")
beego.Router("/backend/allfiles", &controllers.BackendFileController{}, "get:GetAllFiles")
@ -101,6 +102,40 @@ func RegisterAuthRoutes() {
beego.Router("/backend/erp/editPosition/:id", &controllers.BackendErpController{}, "post:EditPosition")
beego.Router("/backend/erp/deletePosition/:id", &controllers.BackendErpController{}, "delete:DeletePosition")
// 文章管理相关接口
// 文章管理
beego.Router("/backend/articlesList", &controllers.BackendArticleController{}, "get:List")
beego.Router("/backend/allarticles", &controllers.BackendArticleController{}, "get:ListAll")
beego.Router("/backend/articles/:id", &controllers.BackendArticleController{}, "get:Detail")
beego.Router("/backend/createarticle", &controllers.BackendArticleController{}, "post:Create")
beego.Router("/backend/editarticle/:id", &controllers.BackendArticleController{}, "post:Update")
beego.Router("/backend/deletearticle/:id", &controllers.BackendArticleController{}, "delete:Delete")
beego.Router("/backend/publisharticle/:id", &controllers.BackendArticleController{}, "post:Publish")
beego.Router("/backend/unPublisharticle/:id", &controllers.BackendArticleController{}, "post:Unpublish")
beego.Router("/backend/articleRecommend/:id", &controllers.BackendArticleController{}, "post:Recommend")
beego.Router("/backend/unArticleRecommend/:id", &controllers.BackendArticleController{}, "post:Unrecommend")
beego.Router("/backend/articleTop/:id", &controllers.BackendArticleController{}, "post:Top")
beego.Router("/backend/unArticleTop/:id", &controllers.BackendArticleController{}, "post:Untop")
beego.Router("/backend/categories", &controllers.BackendArticleCategoryController{}, "get:List")
beego.Router("/backend/allcategories", &controllers.BackendArticleCategoryController{}, "get:ListAll")
beego.Router("/backend/categories/:id", &controllers.BackendArticleCategoryController{}, "get:Detail;delete:Delete")
beego.Router("/backend/createCategory", &controllers.BackendArticleCategoryController{}, "post:Create")
beego.Router("/backend/editCategory/:id", &controllers.BackendArticleCategoryController{}, "post:Update")
beego.Router("/backend/categories/:id/status", &controllers.BackendArticleCategoryController{}, "patch:UpdateStatus")
// 域名管理(主域名池 / 租户域名)
beego.Router("/backend/domain/pool/index", &controllers.BackendDomainPoolController{}, "get:Index")
beego.Router("/backend/domain/pool/getEnabledDomains", &controllers.BackendDomainPoolController{}, "get:GetEnabledDomains")
beego.Router("/backend/domain/pool/create", &controllers.BackendDomainPoolController{}, "post:Create")
beego.Router("/backend/domain/pool/update", &controllers.BackendDomainPoolController{}, "post:Update")
beego.Router("/backend/domain/pool/delete/:id", &controllers.BackendDomainPoolController{}, "delete:Delete")
beego.Router("/backend/domain/pool/toggleStatus", &controllers.BackendDomainPoolController{}, "post:ToggleStatus")
beego.Router("/backend/domain/tenant/index", &controllers.BackendTenantDomainController{}, "get:Index")
beego.Router("/backend/domain/tenant/myDomains", &controllers.BackendTenantDomainController{}, "get:MyDomains")
beego.Router("/backend/domain/tenant/apply", &controllers.BackendTenantDomainController{}, "post:Apply")
beego.Router("/backend/domain/tenant/audit", &controllers.BackendTenantDomainController{}, "post:Audit")
beego.Router("/backend/domain/tenant/toggleStatus", &controllers.BackendTenantDomainController{}, "post:ToggleStatus")
beego.Router("/backend/domain/tenant/delete/:id", &controllers.BackendTenantDomainController{}, "delete:Delete")
}

View File

@ -162,6 +162,27 @@ func Register() {
beego.Router("/platform/home/accountPoolDailyExtract", &controllers.PlatformHomeController{}, "get:AccountPoolDailyExtract")
beego.Router("/platform/home/accountPoolInventoryTotals", &controllers.PlatformHomeController{}, "get:AccountPoolInventoryTotals")
// Cursor 设备管理yz_platform_cursor_equipment
beego.Router("/platform/cursor/equipment/list", &controllers.PlatformCursorEquipmentController{}, "get:List")
beego.Router("/platform/cursor/equipment/detail/:id", &controllers.PlatformCursorEquipmentController{}, "get:Detail")
beego.Router("/platform/cursor/equipment/add", &controllers.PlatformCursorEquipmentController{}, "post:Add")
beego.Router("/platform/cursor/equipment/update", &controllers.PlatformCursorEquipmentController{}, "post:Update")
beego.Router("/platform/cursor/equipment/delete/:id", &controllers.PlatformCursorEquipmentController{}, "post:Delete")
beego.Router("/platform/cursor/equipment/activate", &controllers.PlatformCursorEquipmentController{}, "post:Activate")
beego.Router("/platform/cursor/equipment/activationRecords", &controllers.PlatformCursorEquipmentController{}, "get:ActivationRecords")
beego.Router("/platform/cursor/equipment/extractRecords", &controllers.PlatformCursorEquipmentController{}, "get:ExtractRecords")
// Cursor 激活码管理yz_platform_cursor_activation_code
beego.Router("/platform/cursor/activationcode/list", &controllers.PlatformCursorActivationCodeController{}, "get:List")
beego.Router("/platform/cursor/activationcode/detail/:id", &controllers.PlatformCursorActivationCodeController{}, "get:Detail")
beego.Router("/platform/cursor/activationcode/add", &controllers.PlatformCursorActivationCodeController{}, "post:Add")
beego.Router("/platform/cursor/activationcode/update", &controllers.PlatformCursorActivationCodeController{}, "post:Update")
beego.Router("/platform/cursor/activationcode/delete/:id", &controllers.PlatformCursorActivationCodeController{}, "post:Delete")
beego.Router("/platform/cursor/activationcode/generate", &controllers.PlatformCursorActivationCodeController{}, "post:Generate")
beego.Router("/platform/cursor/activationcode/enable/:id", &controllers.PlatformCursorActivationCodeController{}, "post:Enable")
beego.Router("/platform/cursor/activationcode/disable/:id", &controllers.PlatformCursorActivationCodeController{}, "post:Disable")
beego.Router("/platform/cursor/activationcode/export", &controllers.PlatformCursorActivationCodeController{}, "get:Export")
// 账号池管理cursor/windsurf/krio
beego.Router("/platform/accountPool/cursor/list", &controllers.PlatformAccountPoolCursorController{}, "get:List")
beego.Router("/platform/accountPool/cursor/add", &controllers.PlatformAccountPoolCursorController{}, "post:Add")
@ -170,6 +191,7 @@ func Register() {
beego.Router("/platform/accountPool/cursor/extract", &controllers.PlatformAccountPoolCursorController{}, "post:Extract")
beego.Router("/platform/accountPool/cursor/updateRemark", &controllers.PlatformAccountPoolCursorController{}, "post:UpdateRemark")
beego.Router("/platform/accountPool/cursor/setUnavailable", &controllers.PlatformAccountPoolCursorController{}, "post:SetUnavailable")
beego.Router("/platform/accountPool/cursor/updateUsable", &controllers.PlatformAccountPoolCursorController{}, "post:UpdateUsable")
beego.Router("/platform/accountPool/cursor/updatePlatform", &controllers.PlatformAccountPoolCursorController{}, "post:UpdatePlatform")
beego.Router("/platform/accountPool/cursor/unextract", &controllers.PlatformAccountPoolCursorController{}, "post:Unextract")
beego.Router("/platform/accountPool/cursor/replenish", &controllers.PlatformAccountPoolCursorController{}, "post:Replenish")

View File

@ -59,6 +59,14 @@ export function setAccountPoolUnavailable(module, data) {
});
}
export function updateAccountPoolUsable(module, data) {
return request({
url: `${base(module)}/updateUsable`,
method: 'post',
data,
});
}
export function updateAccountPoolPlatform(module, data) {
return request({
url: `${base(module)}/updatePlatform`,

View File

@ -0,0 +1,106 @@
// @ts-ignore request 封装是 JS 文件,项目未提供 TS 声明
import request from '@/utils/request';
const baseUrl = '/platform/cursor/activationcode';
export interface CursorActivationCodeQuery {
page?: number;
pageSize?: number;
keyword?: string;
status?: number | string;
type?: number | string;
bindStatus?: number | string;
}
export interface CursorActivationCodePayload {
id?: number | string;
code?: string;
type?: number;
status?: number;
durationDays?: number;
bindAccount?: string;
bindDeviceId?: number | string;
ownerUserId?: number | string;
ownerUserName?: string;
activatedAt?: string;
expiredAt?: string;
remark?: string;
}
export interface GenerateActivationCodePayload {
count: number;
type?: number;
durationDays?: number;
ownerUserId?: number | string;
ownerUserName?: string;
remark?: string;
}
export function getCursorActivationCodeList(params: CursorActivationCodeQuery) {
return request({
url: `${baseUrl}/list`,
method: 'get',
params,
});
}
export function getCursorActivationCodeDetail(id: number | string) {
return request({
url: `${baseUrl}/detail/${id}`,
method: 'get',
});
}
export function addCursorActivationCode(data: CursorActivationCodePayload) {
return request({
url: `${baseUrl}/add`,
method: 'post',
data,
});
}
export function updateCursorActivationCode(data: CursorActivationCodePayload) {
return request({
url: `${baseUrl}/update`,
method: 'post',
data,
});
}
export function deleteCursorActivationCode(id: number | string) {
return request({
url: `${baseUrl}/delete/${id}`,
method: 'post',
});
}
export function generateCursorActivationCode(data: GenerateActivationCodePayload) {
return request({
url: `${baseUrl}/generate`,
method: 'post',
data,
});
}
export function enableCursorActivationCode(id: number | string) {
return request({
url: `${baseUrl}/enable/${id}`,
method: 'post',
});
}
export function disableCursorActivationCode(id: number | string) {
return request({
url: `${baseUrl}/disable/${id}`,
method: 'post',
});
}
export function exportCursorActivationCode(params: CursorActivationCodeQuery) {
return request({
url: `${baseUrl}/export`,
method: 'get',
params,
responseType: 'blob',
});
}

View File

@ -0,0 +1,90 @@
// @ts-ignore request 封装是 JS 文件,项目未提供 TS 声明
import request from '@/utils/request';
const baseUrl = '/platform/cursor/equipment';
export interface CursorEquipmentQuery {
page?: number;
pageSize?: number;
keyword?: string;
status?: number | string;
system?: string;
os?: string;
}
export interface CursorEquipmentPayload {
id?: number;
deviceInfo?: string;
machineCode?: string;
status?: number;
system?: string;
version?: string;
bindAccount?: string;
ownerUserId?: number;
ownerUserName?: string;
activationTime?: string;
expireTime?: string;
remark?: string;
}
export function getCursorEquipmentList(params: CursorEquipmentQuery) {
return request({
url: `${baseUrl}/list`,
method: 'get',
params,
});
}
export function getCursorEquipmentDetail(id: number | string) {
return request({
url: `${baseUrl}/detail/${id}`,
method: 'get',
});
}
export function addCursorEquipment(data: CursorEquipmentPayload) {
return request({
url: `${baseUrl}/add`,
method: 'post',
data,
});
}
export function updateCursorEquipment(data: CursorEquipmentPayload) {
return request({
url: `${baseUrl}/update`,
method: 'post',
data,
});
}
export function deleteCursorEquipment(id: number | string) {
return request({
url: `${baseUrl}/delete/${id}`,
method: 'post',
});
}
export function activateCursorEquipment(data: { id: number | string }) {
return request({
url: `${baseUrl}/activate`,
method: 'post',
data,
});
}
export function getCursorEquipmentActivationRecords(params: Record<string, any>) {
return request({
url: `${baseUrl}/activationRecords`,
method: 'get',
params,
});
}
export function getCursorEquipmentExtractRecords(params: Record<string, any>) {
return request({
url: `${baseUrl}/extractRecords`,
method: 'get',
params,
});
}

View File

@ -14,7 +14,6 @@
<!-- 菜单主体 -->
<el-menu
v-else
:collapse="isCollapse"
:collapse-transition="false"
:background-color="asideBgColor"
@ -23,6 +22,7 @@
:active-background-color="activeBgColor"
class="el-menu-vertical-demo"
:unique-opened="true"
:default-openeds="defaultOpeneds"
@select="handleMenuSelect"
:default-active="route.path"
>
@ -284,10 +284,29 @@ const currentModule = computed(() => {
});
const displayMenus = computed(() => {
//
// ""
return list.value;
});
const findOpenMenuPaths = (menus, targetPath, ancestors = []) => {
for (const menu of menus) {
const currentPath = menu.path || menu.id.toString();
if (menu.path && (targetPath === menu.path || targetPath.startsWith(menu.path + "/"))) {
return [...ancestors, currentPath];
}
if (menu.children && menu.children.length > 0) {
const found = findOpenMenuPaths(menu.children, targetPath, [...ancestors, currentPath]);
if (found) return found;
}
}
return null;
};
const defaultOpeneds = computed(() => {
const result = findOpenMenuPaths(displayMenus.value, route.path);
return result || [];
});
const asideTitle = computed(() => {
if (isCollapse.value) return "管理";
return "菜单";
@ -311,7 +330,7 @@ const processMenus = (menus) => {
.map((menu) => ({
id: menu.id,
path: menu.path,
icon: menu.icon || "Document",
icon: menu.icon || null,
title: menu.title,
route: menu.path,
component_path: menu.component_path,
@ -541,13 +560,13 @@ h3 {
//
.el-menu-item.is-active {
html:not(.dark) & {
background-color: rgba(57, 115, 255, 0.3) !important;
background-color: rgba(255, 255, 255, 0.2) !important;
border-left: 3px solid #ffffff;
}
html.dark & {
background-color: rgba(60, 60, 60, 0.8) !important;
}
color: #ffffff !important;
border-left: 3px solid #4f84ff;
margin-left: -3px;
.menu-icon {
@ -574,12 +593,17 @@ h3 {
}
&.is-opened .el-sub-menu__title {
background: rgba(255, 255, 255, 0.08) !important;
background: rgba(255, 255, 255, 0.12) !important;
margin-left: -3px;
}
.el-menu-item {
padding-left: 48px !important;
font-size: 13px;
&.is-active {
background: rgba(255, 255, 255, 0.18) !important;
}
}
}
@ -604,6 +628,10 @@ h3 {
.el-sub-menu.is-opened .el-sub-menu__title {
background: rgba(64, 158, 255, 0.08) !important;
}
.el-sub-menu .el-menu-item.is-active {
background: rgba(64, 158, 255, 0.15) !important;
}
}
}

View File

@ -1,4 +1,3 @@
<script setup>
import { reactive, ref, watch } from 'vue';
import { ElMessage } from 'element-plus';

View File

@ -22,8 +22,10 @@ const remarkText = ref("");
const remarkDialogVisible = ref(false);
const platformDialogVisible = ref(false);
const unavailableDialogVisible = ref(false);
const usableDialogVisible = ref(false);
const unextractDialogVisible = ref(false);
const platformForm = reactive({ platform: "local" });
const usableForm = reactive({ usable: 1 });
const TYPE_MAP = {
account: { label: "账号密码", type: "success" },
@ -82,6 +84,12 @@ watch(
(row) => {
remarkText.value = row?.remark || "";
platformForm.platform = row?.extractedPlatform || "local";
const raw = row?.isUsed;
if (raw === null || raw === undefined || raw === "") {
usableForm.usable = 1;
} else {
usableForm.usable = Number(raw) === 0 ? 0 : 1;
}
},
{ immediate: true },
);
@ -107,6 +115,26 @@ function onSetUnavailable() {
unavailableDialogVisible.value = false;
}
function openUsableDialog() {
const raw = props.row?.isUsed;
if (raw === null || raw === undefined || raw === "") {
usableForm.usable = 1;
} else {
usableForm.usable = Number(raw) === 0 ? 0 : 1;
}
usableDialogVisible.value = true;
}
function onUpdateUsable() {
if (!props.row?.id) return;
emit("detail-action", {
action: "usable",
id: props.row.id,
usable: usableForm.usable,
});
usableDialogVisible.value = false;
}
function onUpdatePlatform() {
if (!props.row?.id) return;
emit("detail-action", {
@ -299,6 +327,9 @@ function copyAll() {
</div>
</div>
<div class="copy-actions">
<el-button type="success" plain @click="openUsableDialog">
改可用状态
</el-button>
<el-button
type="danger"
plain
@ -334,6 +365,28 @@ function copyAll() {
</div>
</el-dialog>
<el-dialog
v-model="usableDialogVisible"
title="改可用状态"
width="420px"
append-to-body
>
<el-form label-width="84px">
<el-form-item label="可用状态">
<el-radio-group v-model="usableForm.usable">
<el-radio :value="1">可用</el-radio>
<el-radio :value="0">不可用</el-radio>
</el-radio-group>
</el-form-item>
</el-form>
<template #footer>
<el-button @click="usableDialogVisible = false">取消</el-button>
<el-button type="primary" :loading="saveLoading" @click="onUpdateUsable">
确认修改
</el-button>
</template>
</el-dialog>
<el-dialog
v-model="unavailableDialogVisible"
title="改不可用"

View File

@ -1,15 +1,7 @@
<script setup>
import {
computed,
h,
nextTick,
onMounted,
onUnmounted,
reactive,
ref,
watch,
} from "vue";
import { computed, h, nextTick, onMounted, onUnmounted, reactive, ref, watch } from "vue";
import { ElMessage, ElMessageBox } from "element-plus";
import { Loading } from "@element-plus/icons-vue";
import Edit from "./components/edit.vue";
import DetailDialog from "./components/detail.vue";
import ExtractDialog from "./components/extract.vue";
@ -22,6 +14,7 @@ import {
getAccountPoolList,
updateAccountPoolRemark,
setAccountPoolUnavailable,
updateAccountPoolUsable,
updateAccountPoolPlatform,
unextractAccountPool,
replenishAccountPool,
@ -29,6 +22,35 @@ import {
} from "@/api/accountPool";
const moduleKey = "cursor";
const PAGINATION_STORAGE_KEY = `accountPool:${moduleKey}:pagination`;
function loadStoredPagination() {
try {
const raw = sessionStorage.getItem(PAGINATION_STORAGE_KEY);
if (!raw) return { page: 1, pageSize: 20 };
const saved = JSON.parse(raw);
const pageSize = Number(saved.pageSize);
const page = Number(saved.page);
return {
page: Number.isFinite(page) && page >= 1 ? page : 1,
pageSize: [20, 50, 100].includes(pageSize) ? pageSize : 20,
};
} catch {
return { page: 1, pageSize: 20 };
}
}
function savePagination() {
sessionStorage.setItem(
PAGINATION_STORAGE_KEY,
JSON.stringify({
page: pagination.page,
pageSize: pagination.pageSize,
}),
);
}
const storedPagination = loadStoredPagination();
const loading = ref(false);
const editVisible = ref(false);
@ -67,10 +89,24 @@ const selectedRows = ref([]);
const detailRow = ref(null);
const detailRemarkSaving = ref(false);
const probeLoadingId = ref(null);
const batchProbeDialogVisible = ref(false);
const batchProbePhase = ref("running");
const batchProbeProgress = reactive({
total: 0,
current: 0,
currentId: null,
percent: 0,
});
const batchProbeSummary = reactive({
total: 0,
available: 0,
unavailable: 0,
skipped: 0,
});
const isMobile = ref(false);
const pagination = reactive({
page: 1,
pageSize: 20,
page: storedPagination.page,
pageSize: storedPagination.pageSize,
});
/** 跳转未提取末页时跳过 watcher避免先被重置到第 1 页 */
@ -97,15 +133,7 @@ const typeTabs = computed(() => {
});
watch(
() => [
query.account,
query.token,
query.remark,
query.status,
query.platform,
query.usable,
activeTypeTab.value,
],
() => [query.account, query.token, query.remark, query.status, query.platform, query.usable, activeTypeTab.value],
() => {
if (skipWatchFetchDuringUnusedJump.value) return;
pagination.page = 1;
@ -116,6 +144,7 @@ watch(
watch(
() => [pagination.page, pagination.pageSize],
() => {
savePagination();
if (skipWatchFetchDuringUnusedJump.value) return;
fetchList();
},
@ -200,7 +229,7 @@ function buildCopyTextByRow(row) {
if (row?.account) parts.push(row.account);
if (row?.password) parts.push(row.password);
if (row?.token) parts.push(row.token);
return parts.join("\n");
return parts.join('\n');
}
function rowToText(row) {
@ -208,20 +237,20 @@ function rowToText(row) {
if (row?.account) parts.push(row.account);
if (row?.password) parts.push(row.password);
if (row?.token) parts.push(row.token);
return parts.join(" / ");
return parts.join(' / ');
}
async function copyToClipboard(text) {
if (!text) {
ElMessage.warning("无可复制内容");
ElMessage.warning('无可复制内容');
return false;
}
try {
await navigator.clipboard.writeText(text);
ElMessage.success("已复制");
ElMessage.success('已复制');
return true;
} catch (e) {
ElMessage.error("复制失败,请检查浏览器权限");
ElMessage.error('复制失败,请检查浏览器权限');
return false;
}
}
@ -289,6 +318,11 @@ async function handleDetailAction(payload) {
let res;
if (payload.action === "unavailable") {
res = await setAccountPoolUnavailable(moduleKey, { id: payload.id });
} else if (payload.action === "usable") {
res = await updateAccountPoolUsable(moduleKey, {
id: payload.id,
usable: payload.usable,
});
} else if (payload.action === "platform") {
res = await updateAccountPoolPlatform(moduleKey, {
id: payload.id,
@ -395,20 +429,16 @@ function extractStatusTagType(row) {
}
const tooltipOpts = {
popperClass: "pool-tooltip",
popperStyle: {
maxWidth: "600px",
wordBreak: "break-all",
whiteSpace: "pre-wrap",
},
popperClass: 'pool-tooltip',
popperStyle: { maxWidth: '600px', wordBreak: 'break-all', whiteSpace: 'pre-wrap' },
};
const PLATFORM_MAP = {
local: { label: "本地", type: "info" },
xianyu: { label: "闲鱼", type: "warning" },
pinduoduo: { label: "拼多多", type: "danger" },
jingdong: { label: "京东", type: "primary" },
douyin: { label: "抖音", type: "success" },
local: { label: '本地', type: 'info' },
xianyu: { label: '闲鱼', type: 'warning' },
pinduoduo: { label: '拼多多', type: 'danger' },
jingdong: { label: '京东', type: 'primary' },
douyin: { label: '抖音', type: 'success' },
};
function platformText(platform) {
@ -437,17 +467,12 @@ function isUsedTagType(isUsed) {
function decodeJwtPayload(rawToken) {
const token = String(rawToken || "").trim();
if (!token) return null;
const pureToken = token.includes("::")
? token.split("::").pop().trim()
: token;
const pureToken = token.includes("::") ? token.split("::").pop().trim() : token;
const parts = pureToken.split(".");
if (parts.length < 2) return null;
try {
const base64 = parts[1].replace(/-/g, "+").replace(/_/g, "/");
const padded = base64.padEnd(
base64.length + ((4 - (base64.length % 4)) % 4),
"=",
);
const padded = base64.padEnd(base64.length + ((4 - (base64.length % 4)) % 4), "=");
const json = decodeURIComponent(
atob(padded)
.split("")
@ -554,8 +579,7 @@ async function fetchList() {
remark: query.remark || undefined,
status: query.status || undefined,
platform: query.platform || undefined,
usable:
query.usable === "1" || query.usable === "0" ? query.usable : undefined,
usable: query.usable === "1" || query.usable === "0" ? query.usable : undefined,
type: activeTypeTab.value === "all" ? undefined : activeTypeTab.value,
});
if (res?.code !== 200) {
@ -565,6 +589,10 @@ async function fetchList() {
const list = Array.isArray(res?.data?.list) ? res.data.list : [];
tableData.value = list.map(normalizeRow);
total.value = Number(res?.data?.total || 0);
const maxPage = Math.max(1, Math.ceil(total.value / pagination.pageSize));
if (pagination.page > maxPage) {
pagination.page = maxPage;
}
} finally {
loading.value = false;
}
@ -580,8 +608,7 @@ async function jumpToLastUnusedPage() {
token: query.token || undefined,
remark: query.remark || undefined,
status: "unused",
usable:
query.usable === "1" || query.usable === "0" ? query.usable : undefined,
usable: query.usable === "1" || query.usable === "0" ? query.usable : undefined,
type,
});
if (res?.code !== 200) {
@ -609,44 +636,29 @@ function updateDeviceType() {
onMounted(() => {
updateDeviceType();
window.addEventListener("resize", updateDeviceType);
window.addEventListener('resize', updateDeviceType);
fetchList();
});
onUnmounted(() => {
window.removeEventListener("resize", updateDeviceType);
window.removeEventListener('resize', updateDeviceType);
});
// ---- ----
const BASE_URL = "https://api.yunzer.cn";
const paramDocs = [
{
name: "type",
required: true,
desc: "来源平台,用于标记本次提取来自哪个渠道",
values: "xianyu / taobao / pinduoduo / jingdong / local",
},
{
name: "module",
required: true,
desc: "号池模块,指定从哪个产品的号池提取",
values: "cursor / windsurf / krio",
},
{
name: "data_type",
required: false,
desc: "账号类型,不传则提取任意类型",
values: "account / tk / account_tk",
},
{ name: 'type', required: true, desc: '来源平台,用于标记本次提取来自哪个渠道', values: 'xianyu / taobao / pinduoduo / jingdong / local' },
{ name: 'module', required: true, desc: '号池模块,指定从哪个产品的号池提取', values: 'cursor / windsurf / krio' },
{ name: 'data_type', required: false, desc: '账号类型,不传则提取任意类型', values: 'account / tk / account_tk' },
];
const platformDocs = [
{ value: "xianyu", label: "闲鱼", desc: "闲鱼平台发货调用" },
{ value: "pinduoduo", label: "拼多多", desc: "拼多多平台发货调用" },
{ value: "jingdong", label: "京东", desc: "京东平台发货调用" },
{ value: "douyin", label: "抖音", desc: "抖音平台发货调用" },
{ value: "local", label: "本地", desc: "本地手动调用" },
{ value: 'xianyu', label: '闲鱼', desc: '闲鱼平台发货调用' },
{ value: 'pinduoduo', label: '拼多多', desc: '拼多多平台发货调用' },
{ value: 'jingdong', label: '京东', desc: '京东平台发货调用' },
{ value: 'douyin', label: '抖音', desc: '抖音平台发货调用' },
{ value: 'local', label: '本地', desc: '本地手动调用' },
];
const moduleDocs = [
@ -700,48 +712,64 @@ function copyCardInfo(row) {
if (row.account) parts.push(row.account);
if (row.password) parts.push(row.password);
if (row.token) parts.push(row.token);
if (!parts.length) {
ElMessage.warning("无可复制内容");
return;
}
navigator.clipboard.writeText(parts.join("\n")).then(() => {
ElMessage.success("已复制");
if (!parts.length) { ElMessage.warning('无可复制内容'); return; }
navigator.clipboard.writeText(parts.join('\n')).then(() => {
ElMessage.success('已复制');
});
}
const CURSOR_PRO_LIMIT_TEXT =
"Get Cursor Pro for more Agent usage, unlimited Tab, and more.";
const CURSOR_PRO_LIMIT_TEXT = 'Get Cursor Pro for more Agent usage, unlimited Tab, and more.';
function formatCursorProbeDialogText(d) {
const detail = String(d?.detail || "").trim();
const rawPreview = String(d?.rawPreview || "").trim();
const serverOutput = detail || rawPreview;
// 1. ok
if (d && typeof d.ok === "boolean") {
if (d.ok) {
return serverOutput || "该TOKEN可用";
}
return `该TOKEN已用完 (${detail || rawPreview || "额度枯竭"})`;
if (d && typeof d.ok === 'boolean') {
return d.ok ? '该TOKEN可用' : `该TOKEN已用完 (${d.detail || '额度枯竭'})`;
}
// 2.
const CURSOR_PRO_LIMIT_TEXT =
"Get Cursor Pro for more Agent usage, unlimited Tab, and more.";
if (
detail.includes(CURSOR_PRO_LIMIT_TEXT) ||
rawPreview.includes(CURSOR_PRO_LIMIT_TEXT)
) {
return `该TOKEN已用完 (${detail || rawPreview})`;
const CURSOR_PRO_LIMIT_TEXT = 'Get Cursor Pro for more Agent usage, unlimited Tab, and more.';
const detail = String(d?.detail || '');
const rawPreview = String(d?.rawPreview || '');
if (detail.includes(CURSOR_PRO_LIMIT_TEXT) || rawPreview.includes(CURSOR_PRO_LIMIT_TEXT)) {
return '该TOKEN已用完';
}
return '该TOKEN可用';
}
return serverOutput || "该TOKEN可用";
function formatCursorProbeDetail(d) {
if (!d) return '';
const parts = [];
//
if (d.httpStatus) parts.push(`HTTP状态: ${d.httpStatus}`);
if (d.endpoint) parts.push(`接口: ${d.endpoint}`);
if (d.probeMessage) parts.push(`探测方式: ${d.probeMessage}`);
if (d.bytesRead) parts.push(`响应大小: ${d.bytesRead} 字节`);
if (d.streamProtocol) parts.push(`协议: ${d.streamProtocol}`);
//
if (d.detail) {
//
const matchPrefix = '流中匹配:';
if (d.detail.includes(matchPrefix)) {
const matchStart = d.detail.indexOf(matchPrefix);
const matchEnd = d.detail.indexOf('', matchStart);
const matchText = matchEnd > 0 ? d.detail.substring(matchStart, matchEnd) : d.detail.substring(matchStart);
parts.push(`检测结论: ${matchText}`);
} else {
parts.push(`检测结论: ${d.detail}`);
}
}
return parts.join('\n');
}
async function handleProbeToken(row) {
if (!row?.token) {
ElMessage.warning("该行无 Token");
ElMessage.warning('该行无 Token');
return;
}
probeLoadingId.value = row.id;
@ -751,17 +779,50 @@ async function handleProbeToken(row) {
accessToken: row.token,
});
if (res?.code !== 200) {
ElMessage.error(res?.msg || "探测失败");
ElMessage.error(res?.msg || '探测失败');
return;
}
const d = res?.data || {};
const text = formatCursorProbeDialogText(d);
const isOk = d.ok === true;
//
const detailItems = [];
if (d.httpStatus) detailItems.push(`HTTP状态: ${d.httpStatus}`);
if (d.endpoint) detailItems.push(`接口: ${d.endpoint}`);
if (d.probeMessage) detailItems.push(`探测方式: ${d.probeMessage}`);
if (d.bytesRead) detailItems.push(`响应大小: ${d.bytesRead} 字节`);
if (d.streamProtocol) detailItems.push(`协议: ${d.streamProtocol}`);
// detail
if (d.detail) {
const matchPrefix = '流中匹配:';
if (d.detail.includes(matchPrefix)) {
const matchStart = d.detail.indexOf(matchPrefix);
const matchEnd = d.detail.indexOf('', matchStart);
const matchText = matchEnd > 0 ? d.detail.substring(matchStart, matchEnd) : d.detail.substring(matchStart);
detailItems.push(`检测结论: ${matchText}`);
} else {
detailItems.push(`检测结论: ${d.detail}`);
}
}
try {
await ElMessageBox({
title: "检测结果",
message: h("div", { class: "cursor-probe-result" }, text),
confirmButtonText: "关闭",
customClass: "cursor-probe-dialog",
title: isOk ? '检测结果 - 可用' : '检测结果 - 不可用',
message: h('div', { class: 'cursor-probe-result cursor-expire-result' }, [
h('div', {
style: `text-align:center;font-size:18px;font-weight:700;margin-bottom:12px;color:${isOk ? '#67c23a' : '#f56c6c'}`
}, text),
detailItems.length > 0 ? h('div', {
style: 'text-align:left;font-size:13px;color:#606266;margin-bottom:8px;line-height:1.8'
}, detailItems.map(item => h('div', null, `${item}`))) : null,
d.streamNote ? h('div', {
style: 'text-align:left;font-size:12px;color:#909399;margin-top:8px;padding:8px;background:#f5f7fa;border-radius:4px;white-space:pre-wrap;line-height:1.6;'
}, d.streamNote) : null,
]),
confirmButtonText: '关闭',
customClass: 'cursor-probe-dialog',
closeOnClickModal: true,
});
} catch {
@ -769,7 +830,7 @@ async function handleProbeToken(row) {
}
await fetchList();
} catch {
ElMessage.error("探测请求失败");
ElMessage.error('探测请求失败');
} finally {
probeLoadingId.value = null;
}
@ -786,7 +847,8 @@ async function handleBatchProbe() {
return;
}
const skipped = selectedRows.value.length - rows.length;
const skipHint = skipped > 0 ? `(已跳过 ${skipped} 条无 Token` : "";
const skipHint =
skipped > 0 ? `(已跳过 ${skipped} 条无 Token` : "";
try {
await ElMessageBox.confirm(
`将对 ${rows.length} 条 Token进行检测是否继续${skipHint}`,
@ -796,36 +858,61 @@ async function handleBatchProbe() {
} catch {
return;
}
loading.value = true;
let ok = 0;
let fail = 0;
let available = 0;
let unavailable = 0;
batchProbePhase.value = "running";
batchProbeProgress.total = rows.length;
batchProbeProgress.current = 0;
batchProbeProgress.currentId = null;
batchProbeProgress.percent = 0;
batchProbeDialogVisible.value = true;
await nextTick();
try {
for (const row of rows) {
for (let i = 0; i < rows.length; i += 1) {
const row = rows[i];
batchProbeProgress.current = i + 1;
batchProbeProgress.currentId = row.id;
batchProbeProgress.percent = Math.round((i / rows.length) * 100);
await nextTick();
try {
const res = await probeAccountPoolToken(moduleKey, {
id: row.id,
accessToken: row.token,
});
if (res?.code === 200) {
ok += 1;
if (res?.code === 200 && res?.data?.ok === true) {
available += 1;
} else {
fail += 1;
unavailable += 1;
}
} catch {
fail += 1;
unavailable += 1;
}
batchProbeProgress.percent = Math.round(((i + 1) / rows.length) * 100);
await nextTick();
}
if (fail > 0) {
ElMessage.warning(`批量检测完成:成功 ${ok} 条,失败 ${fail}`);
} else {
ElMessage.success(`批量检测完成:共 ${ok}`);
}
batchProbeSummary.total = rows.length;
batchProbeSummary.available = available;
batchProbeSummary.unavailable = unavailable;
batchProbeSummary.skipped = skipped;
batchProbePhase.value = "done";
await fetchList();
} finally {
loading.value = false;
} catch {
batchProbeDialogVisible.value = false;
ElMessage.error("批量检测异常");
}
}
function closeBatchProbeDialog() {
batchProbeDialogVisible.value = false;
batchProbePhase.value = "running";
}
// async function handleBatchProbeExpireTime() {
// if (!selectedRows.value.length) {
// ElMessage.warning("");
@ -876,6 +963,7 @@ async function handleBatchProbe() {
// closeOnClickModal: true,
// });
// }
</script>
<template>
@ -951,12 +1039,8 @@ async function handleBatchProbe() {
<el-button @click="resetQuery">重置</el-button>
</div>
<div class="toolbar-right">
<el-button type="primary" @click="openAddDialog('single')"
>添加账号</el-button
>
<el-button type="success" @click="openAddDialog('batch')"
>批量添加</el-button
>
<el-button type="primary" @click="openAddDialog('single')">添加账号</el-button>
<el-button type="success" @click="openAddDialog('batch')">批量添加</el-button>
<el-button @click="replenishVisible = true">补号</el-button>
<el-button @click="markExtractForSelected">批量提取</el-button>
<el-button plain @click="handleBatchProbe">批量检测</el-button>
@ -984,108 +1068,84 @@ async function handleBatchProbe() {
:loading="loading"
@selection-change="handleSelectionChange"
>
<el-table-column type="selection" width="52" />
<el-table-column prop="id" label="ID" width="80" />
<el-table-column label="账号类型" width="160" align="center">
<template #default="{ row }">
<el-tag>{{ typeText(row.type) }}</el-tag>
</template>
</el-table-column>
<el-table-column
prop="account"
label="账号"
min-width="180"
show-overflow-tooltip
:tooltip-options="tooltipOpts"
/>
<!-- <el-table-column prop="password" label="密码" min-width="160" show-overflow-tooltip :tooltip-options="tooltipOpts">
<el-table-column type="selection" width="52" />
<el-table-column prop="id" label="ID" width="80" />
<el-table-column label="账号类型" width="160" align="center">
<template #default="{ row }">
<el-tag>{{ typeText(row.type) }}</el-tag>
</template>
</el-table-column>
<el-table-column prop="account" label="账号" min-width="180" show-overflow-tooltip :tooltip-options="tooltipOpts" />
<!-- <el-table-column prop="password" label="密码" min-width="160" show-overflow-tooltip :tooltip-options="tooltipOpts">
<template #default="{ row }">{{ row.password || '-' }}</template>
</el-table-column>
<el-table-column label="Token" min-width="200" show-overflow-tooltip :tooltip-options="tooltipOpts">
<template #default="{ row }">{{ row.token || '-' }}</template>
</el-table-column> -->
<el-table-column label="提取状态" width="100">
<template #default="{ row }">
<el-tag :type="extractStatusTagType(row)">
{{ extractStatusLabel(row) }}
</el-tag>
</template>
</el-table-column>
<el-table-column label="探测可用" width="100" align="center">
<template #default="{ row }">
<el-tag :type="isUsedTagType(row.isUsed)" size="small">
{{ isUsedLabel(row.isUsed) }}
</el-tag>
</template>
</el-table-column>
<!-- <el-table-column
label="accessToken失效时间"
width="190"
align="center"
>
<template #default="{ row }">
<el-tag
:type="accessTokenExpireTagType(row.accessTokenExpireStatus)"
size="small"
>
{{ row.accessTokenExpireText || "-" }}
</el-tag>
</template>
</el-table-column> -->
<el-table-column label="提取平台" width="120">
<template #default="{ row }">
<el-tag
v-if="row.extractedPlatform"
:type="platformTagType(row.extractedPlatform)"
size="small"
>
{{ platformText(row.extractedPlatform) }}
</el-tag>
<span v-else>-</span>
</template>
</el-table-column>
<el-table-column prop="extractedAt" label="提取时间" width="180" />
<el-table-column
prop="remark"
label="备注"
min-width="140"
show-overflow-tooltip
:tooltip-options="tooltipOpts"
/>
<el-table-column
label="操作"
width="300"
fixed="right"
align="center"
>
<template #default="{ row }">
<el-button
v-if="row.token"
link
type="info"
:loading="probeLoadingId === row.id"
@click="handleProbeToken(row)"
>检测</el-button
>
<el-button link type="primary" @click="openDetail(row)"
>详情</el-button
>
<el-button
v-if="!row.extractedAt && !row.extracted"
link
type="warning"
@click="openExtractByRow(row)"
>提取</el-button
>
<el-button
v-if="row.extracted"
link
type="success"
@click="copyCardInfo(row)"
>复制</el-button
>
</template>
</el-table-column>
<el-table-column label="提取状态" width="100">
<template #default="{ row }">
<el-tag :type="extractStatusTagType(row)">
{{ extractStatusLabel(row) }}
</el-tag>
</template>
</el-table-column>
<el-table-column label="探测可用" width="100" align="center">
<template #default="{ row }">
<el-tag :type="isUsedTagType(row.isUsed)" size="small">
{{ isUsedLabel(row.isUsed) }}
</el-tag>
</template>
</el-table-column>
<!-- <el-table-column label="accessToken失效时间" width="190" align="center">
<template #default="{ row }">
<el-tag :type="accessTokenExpireTagType(row.accessTokenExpireStatus)" size="small">
{{ row.accessTokenExpireText || "-" }}
</el-tag>
</template>
</el-table-column> -->
<el-table-column label="提取平台" width="120">
<template #default="{ row }">
<el-tag
v-if="row.extractedPlatform"
:type="platformTagType(row.extractedPlatform)"
size="small"
>
{{ platformText(row.extractedPlatform) }}
</el-tag>
<span v-else>-</span>
</template>
</el-table-column>
<el-table-column prop="extractedAt" label="提取时间" width="180" />
<el-table-column prop="remark" label="备注" min-width="140" show-overflow-tooltip :tooltip-options="tooltipOpts" />
<el-table-column label="操作" width="300" fixed="right" align="center">
<template #default="{ row }">
<el-button
v-if="row.token"
link
type="info"
:loading="probeLoadingId === row.id"
@click="handleProbeToken(row)"
>检测</el-button
>
<el-button link type="primary" @click="openDetail(row)"
>详情</el-button
>
<el-button
v-if="!row.extractedAt && !row.extracted"
link
type="warning"
@click="openExtractByRow(row)"
>提取</el-button
>
<el-button
v-if="row.extracted"
link
type="success"
@click="copyCardInfo(row)"
>复制</el-button
>
</template>
</el-table-column>
</el-table>
</div>
@ -1094,9 +1154,7 @@ async function handleBatchProbe() {
v-model:current-page="pagination.page"
v-model:page-size="pagination.pageSize"
background
:layout="
isMobile ? 'prev, pager, next' : 'total, prev, pager, next, jumper'
"
layout="total, sizes, prev, pager, next, jumper"
:page-sizes="[20, 50, 100]"
:total="total"
/>
@ -1148,9 +1206,7 @@ async function handleBatchProbe() {
destroy-on-close
>
<el-alert type="info" :closable="false" style="margin-bottom: 12px">
将对已选的
<strong>{{ selectedRows.length }}</strong>
条记录执行提取并标记为已提取
将对已选的 <strong>{{ selectedRows.length }}</strong> 条记录执行提取并标记为已提取
</el-alert>
<el-form label-width="84px">
<el-form-item label="提取平台">
@ -1174,16 +1230,67 @@ async function handleBatchProbe() {
</el-form>
<template #footer>
<el-button @click="batchExtractVisible = false">取消</el-button>
<el-button
type="primary"
:loading="loading"
@click="handleBatchExtract"
>
<el-button type="primary" :loading="loading" @click="handleBatchExtract">
确认提取
</el-button>
</template>
</el-dialog>
<el-dialog
v-model="batchProbeDialogVisible"
:title="batchProbePhase === 'running' ? '批量检测中' : '批量检测结果'"
width="440px"
align-center
:close-on-click-modal="false"
:close-on-press-escape="false"
:show-close="batchProbePhase === 'done'"
@close="closeBatchProbeDialog"
>
<div v-if="batchProbePhase === 'running'" class="batch-probe-progress">
<div class="batch-probe-icon">
<el-icon class="is-loading" :size="36" color="#409eff">
<Loading />
</el-icon>
</div>
<el-progress
:percentage="batchProbeProgress.percent"
:stroke-width="14"
striped
striped-flow
:duration="8"
/>
<div class="batch-probe-status">
正在检测第 {{ batchProbeProgress.current }} / {{ batchProbeProgress.total }}
</div>
<div v-if="batchProbeProgress.currentId" class="batch-probe-id">
当前 ID{{ batchProbeProgress.currentId }}
</div>
</div>
<div v-else class="batch-probe-summary">
<div class="batch-probe-summary-title">检测完成</div>
<div class="batch-probe-summary-grid">
<div class="summary-item">
<span class="summary-label">共检测</span>
<span class="summary-value">{{ batchProbeSummary.total }} </span>
</div>
<div class="summary-item available">
<span class="summary-label">可用</span>
<span class="summary-value">{{ batchProbeSummary.available }} </span>
</div>
<div class="summary-item unavailable">
<span class="summary-label">失效</span>
<span class="summary-value">{{ batchProbeSummary.unavailable }} </span>
</div>
</div>
<div v-if="batchProbeSummary.skipped > 0" class="batch-probe-skipped">
已跳过无 Token {{ batchProbeSummary.skipped }}
</div>
</div>
<template v-if="batchProbePhase === 'done'" #footer>
<el-button type="primary" @click="closeBatchProbeDialog">关闭</el-button>
</template>
</el-dialog>
<!-- 接口说明抽屉 -->
<el-drawer
v-model="apiDocVisible"
@ -1337,7 +1444,7 @@ async function handleBatchProbe() {
}
:deep(.pool-batch-extract-dialog) {
max-width: 420px;
max-width: 600px;
}
@media (max-width: 768px) {
@ -1375,6 +1482,12 @@ async function handleBatchProbe() {
justify-content: center;
}
.pager :deep(.el-pagination) {
flex-wrap: wrap;
justify-content: center;
row-gap: 8px;
}
:deep(.pool-batch-extract-dialog) {
width: calc(100vw - 24px) !important;
margin: 0 auto;
@ -1398,6 +1511,7 @@ async function handleBatchProbe() {
gap: 12px;
padding: 8px 12px 12px;
}
}
/* 接口说明抽屉 */
@ -1501,6 +1615,88 @@ async function handleBatchProbe() {
font-size: 12px;
color: #409eff;
}
.batch-probe-progress {
padding: 8px 4px 4px;
text-align: center;
}
.batch-probe-icon {
margin-bottom: 18px;
}
.batch-probe-status {
margin-top: 16px;
font-size: 15px;
font-weight: 600;
color: #303133;
}
.batch-probe-id {
margin-top: 8px;
font-size: 13px;
color: #909399;
}
.batch-probe-summary {
padding: 8px 4px 4px;
text-align: center;
}
.batch-probe-summary-title {
font-size: 18px;
font-weight: 700;
color: #303133;
margin-bottom: 18px;
}
.batch-probe-summary-grid {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 12px;
}
.summary-item {
padding: 14px 10px;
border-radius: 12px;
background: #f5f7fa;
}
.summary-item.available {
background: #f0f9eb;
}
.summary-item.unavailable {
background: #fef0f0;
}
.summary-label {
display: block;
font-size: 12px;
color: #909399;
margin-bottom: 6px;
}
.summary-value {
display: block;
font-size: 20px;
font-weight: 700;
color: #303133;
}
.summary-item.available .summary-value {
color: #67c23a;
}
.summary-item.unavailable .summary-value {
color: #f56c6c;
}
.batch-probe-skipped {
margin-top: 14px;
font-size: 12px;
color: #909399;
}
</style>
<style>
@ -1516,16 +1712,14 @@ async function handleBatchProbe() {
/* Cursor 探测结果弹窗teleport 到 body需非 scoped */
.cursor-probe-dialog .el-message-box__message {
padding: 12px 8px 4px;
width: 100%;
}
.cursor-probe-dialog .cursor-probe-result {
margin: 0;
max-height: 420px;
overflow: auto;
text-align: left;
font-size: 14px;
text-align: center;
font-size: 16px;
line-height: 1.6;
font-weight: 500;
white-space: pre-wrap;
font-weight: 600;
word-break: break-all;
}
.cursor-probe-dialog .cursor-expire-result {

View File

@ -0,0 +1,957 @@
<script lang="ts" setup>
import { computed, onMounted, onUnmounted, reactive, ref, watch } from 'vue';
import { ElMessage, ElMessageBox, type FormInstance, type FormRules } from 'element-plus';
import {
addCursorActivationCode,
deleteCursorActivationCode,
disableCursorActivationCode,
enableCursorActivationCode,
exportCursorActivationCode,
generateCursorActivationCode,
getCursorActivationCodeDetail,
getCursorActivationCodeList,
updateCursorActivationCode,
} from '../../../api/cursorActivationCode';
type ActivationCodeRow = Record<string, any>;
const loading = ref(false);
const actionLoading = ref(false);
const editVisible = ref(false);
const generateVisible = ref(false);
const detailVisible = ref(false);
const isMobile = ref(false);
const currentRow = ref<ActivationCodeRow | null>(null);
const selectedRows = ref<ActivationCodeRow[]>([]);
const tableData = ref<ActivationCodeRow[]>([]);
const total = ref(0);
const formRef = ref<FormInstance>();
const generateFormRef = ref<FormInstance>();
const query = reactive({
keyword: '',
status: '',
type: '',
bindStatus: '',
});
const pagination = reactive({
page: 1,
pageSize: 20,
});
const form = reactive({
id: '',
code: '',
type: 30,
status: 0,
durationDays: 30,
bindAccount: '',
bindDeviceId: '',
ownerUserId: '',
ownerUserName: '',
activatedAt: '',
expiredAt: '',
remark: '',
});
const generateForm = reactive({
count: 10,
type: 30,
durationDays: 30,
ownerUserId: '',
ownerUserName: '',
remark: '',
});
const statusOptions = [
{ label: '未使用', value: 0 },
{ label: '已使用', value: 1 },
{ label: '已过期', value: 2 },
{ label: '已禁用', value: 3 },
];
const typeOptions = [
{ label: '天卡', value: 1, days: 1 },
{ label: '周卡', value: 7, days: 7 },
{ label: '月卡', value: 30, days: 30 },
{ label: '季卡', value: 90, days: 90 },
{ label: '年卡', value: 365, days: 365 },
{ label: '自定义', value: 0, days: 0 },
];
const bindStatusOptions = [
{ label: '未绑定', value: 0 },
{ label: '已绑定', value: 1 },
];
const statusMap: Record<string, { label: string; type: string }> = {
'0': { label: '未使用', type: 'info' },
'1': { label: '已使用', type: 'success' },
'2': { label: '已过期', type: 'warning' },
'3': { label: '已禁用', type: 'danger' },
};
const rules: FormRules = {
code: [{ required: true, message: '请输入激活码', trigger: 'blur' }],
type: [{ required: true, message: '请选择卡密类型', trigger: 'change' }],
durationDays: [{ required: true, message: '请输入有效天数', trigger: 'blur' }],
status: [{ required: true, message: '请选择状态', trigger: 'change' }],
};
const generateRules: FormRules = {
count: [{ required: true, message: '请输入生成数量', trigger: 'blur' }],
type: [{ required: true, message: '请选择卡密类型', trigger: 'change' }],
durationDays: [{ required: true, message: '请输入有效天数', trigger: 'blur' }],
};
const summary = computed(() => {
const unused = tableData.value.filter((item) => Number(item.status) === 0).length;
const used = tableData.value.filter((item) => Number(item.status) === 1).length;
const expired = tableData.value.filter((item) => Number(item.status) === 2).length;
const disabled = tableData.value.filter((item) => Number(item.status) === 3).length;
return [
{ label: '当前页激活码', value: tableData.value.length, type: 'primary' },
{ label: '未使用', value: unused, type: 'info' },
{ label: '已使用', value: used, type: 'success' },
{ label: '过期/禁用', value: expired + disabled, type: 'danger' },
];
});
watch(
() => [query.keyword, query.status, query.type, query.bindStatus],
() => {
pagination.page = 1;
fetchList();
},
);
watch(
() => [pagination.page, pagination.pageSize],
() => {
fetchList();
},
);
function pick(raw: any, ...keys: string[]) {
for (const key of keys) {
if (raw?.[key] !== undefined && raw?.[key] !== null) return raw[key];
}
return '';
}
function formatTime(value: any) {
if (!value) return '';
const d = new Date(value);
if (Number.isNaN(d.getTime())) return String(value);
const p = (v: number) => String(v).padStart(2, '0');
return `${d.getFullYear()}-${p(d.getMonth() + 1)}-${p(d.getDate())} ${p(d.getHours())}:${p(d.getMinutes())}:${p(d.getSeconds())}`;
}
function normalizeRow(raw: any): ActivationCodeRow {
const status = Number(pick(raw, 'status', 'Status') || 0);
const type = Number(pick(raw, 'type', 'Type', 'card_type', 'cardType') || 0);
const bindAccount = pick(raw, 'bind_account', 'bindAccount', 'BindAccount', 'account', 'Account', 'email', 'Email');
const bindDeviceId = pick(raw, 'bind_device_id', 'bindDeviceId', 'BindDeviceID', 'device_id', 'deviceId');
return {
id: pick(raw, 'id', 'ID', 'Id'),
code: pick(raw, 'code', 'Code', 'activation_code', 'activationCode', 'card_no', 'cardNo'),
type,
typeName: typeLabel(type),
status,
durationDays: Number(pick(raw, 'duration_days', 'durationDays', 'DurationDays', 'days', 'Days') || 0),
bindAccount,
bindDeviceId,
bindStatus: bindAccount || bindDeviceId ? 1 : 0,
deviceInfo: pick(raw, 'device_info', 'deviceInfo', 'DeviceInfo'),
machineCode: pick(raw, 'machine_code', 'machineCode', 'MachineCode'),
ownerUserId: pick(raw, 'owner_user_id', 'ownerUserId', 'OwnerUserID'),
ownerUserName: pick(raw, 'owner_user_name', 'ownerUserName', 'OwnerUserName', 'owner', 'Owner', 'user_name', 'userName'),
activatedAt: formatTime(pick(raw, 'activated_at', 'activatedAt', 'activation_time', 'activationTime')),
expiredAt: formatTime(pick(raw, 'expired_at', 'expiredAt', 'expire_time', 'expireTime')),
createdAt: formatTime(pick(raw, 'created_at', 'createdAt', 'create_time', 'createTime', 'CreatedAt')),
updatedAt: formatTime(pick(raw, 'updated_at', 'updatedAt', 'update_time', 'updateTime', 'UpdatedAt')),
remark: pick(raw, 'remark', 'Remark'),
raw,
};
}
function statusLabel(status: string | number) {
const key = String(status ?? '');
return statusMap[key]?.label || key || '-';
}
function statusTagType(status: string | number) {
return statusMap[String(status ?? '')]?.type || 'info';
}
function typeLabel(type: string | number) {
const item = typeOptions.find((option) => Number(option.value) === Number(type));
return item?.label || (type ? `${type}` : '自定义');
}
function resetQuery() {
query.keyword = '';
query.status = '';
query.type = '';
query.bindStatus = '';
}
function resetForm() {
form.id = '';
form.code = '';
form.type = 30;
form.status = 0;
form.durationDays = 30;
form.bindAccount = '';
form.bindDeviceId = '';
form.ownerUserId = '';
form.ownerUserName = '';
form.activatedAt = '';
form.expiredAt = '';
form.remark = '';
formRef.value?.clearValidate();
}
function resetGenerateForm() {
generateForm.count = 10;
generateForm.type = 30;
generateForm.durationDays = 30;
generateForm.ownerUserId = '';
generateForm.ownerUserName = '';
generateForm.remark = '';
generateFormRef.value?.clearValidate();
}
function handleSelectionChange(rows: ActivationCodeRow[]) {
selectedRows.value = rows;
}
function handleTypeChange(type: number) {
const item = typeOptions.find((option) => Number(option.value) === Number(type));
if (item && item.days > 0) form.durationDays = item.days;
}
function handleGenerateTypeChange(type: number) {
const item = typeOptions.find((option) => Number(option.value) === Number(type));
if (item && item.days > 0) generateForm.durationDays = item.days;
}
async function fetchList() {
loading.value = true;
try {
const res = await getCursorActivationCodeList({
page: pagination.page,
pageSize: pagination.pageSize,
keyword: query.keyword || undefined,
status: query.status === '' ? undefined : query.status,
type: query.type === '' ? undefined : query.type,
bindStatus: query.bindStatus === '' ? undefined : query.bindStatus,
});
if (res?.code !== 200) {
ElMessage.error(res?.msg || '获取激活码列表失败');
return;
}
const list = Array.isArray(res?.data?.list) ? res.data.list : Array.isArray(res?.data) ? res.data : [];
tableData.value = list.map(normalizeRow);
total.value = Number(res?.data?.total || list.length || 0);
} finally {
loading.value = false;
}
}
function openAdd() {
currentRow.value = null;
resetForm();
editVisible.value = true;
}
function openEdit(row: ActivationCodeRow) {
currentRow.value = row;
resetForm();
form.id = String(row.id || '');
form.code = row.code || '';
form.type = Number(row.type || 0);
form.status = Number(row.status || 0);
form.durationDays = Number(row.durationDays || 0);
form.bindAccount = row.bindAccount || '';
form.bindDeviceId = row.bindDeviceId ? String(row.bindDeviceId) : '';
form.ownerUserId = row.ownerUserId ? String(row.ownerUserId) : '';
form.ownerUserName = row.ownerUserName || '';
form.activatedAt = row.activatedAt || '';
form.expiredAt = row.expiredAt || '';
form.remark = row.remark || '';
editVisible.value = true;
}
function openGenerate() {
resetGenerateForm();
generateVisible.value = true;
}
async function openDetail(row: ActivationCodeRow) {
loading.value = true;
try {
const res = await getCursorActivationCodeDetail(row.id);
if (res?.code === 200) {
currentRow.value = normalizeRow(res.data || row.raw || row);
} else {
currentRow.value = row;
ElMessage.warning(res?.msg || '详情接口异常,已展示列表数据');
}
detailVisible.value = true;
} finally {
loading.value = false;
}
}
async function handleSave() {
await formRef.value?.validate();
actionLoading.value = true;
try {
const data = {
id: form.id || undefined,
code: form.code,
type: Number(form.type),
status: Number(form.status),
durationDays: Number(form.durationDays || 0),
bindAccount: form.bindAccount || undefined,
bindDeviceId: form.bindDeviceId || undefined,
ownerUserId: form.ownerUserId || undefined,
ownerUserName: form.ownerUserName || undefined,
activatedAt: form.activatedAt || undefined,
expiredAt: form.expiredAt || undefined,
remark: form.remark || undefined,
};
const api = form.id ? updateCursorActivationCode : addCursorActivationCode;
const res = await api(data);
if (res?.code !== 200) {
ElMessage.error(res?.msg || '保存失败');
return;
}
ElMessage.success(form.id ? '激活码已更新' : '激活码已新增');
editVisible.value = false;
await fetchList();
} finally {
actionLoading.value = false;
}
}
async function handleGenerate() {
await generateFormRef.value?.validate();
actionLoading.value = true;
try {
const res = await generateCursorActivationCode({
count: Number(generateForm.count || 1),
type: Number(generateForm.type),
durationDays: Number(generateForm.durationDays || 0),
ownerUserId: generateForm.ownerUserId || undefined,
ownerUserName: generateForm.ownerUserName || undefined,
remark: generateForm.remark || undefined,
});
if (res?.code !== 200) {
ElMessage.error(res?.msg || '生成失败');
return;
}
ElMessage.success('激活码已生成');
generateVisible.value = false;
await fetchList();
} finally {
actionLoading.value = false;
}
}
async function handleDelete(row: ActivationCodeRow) {
try {
await ElMessageBox.confirm(`确认删除激活码「${row.code || row.id}」?`, '删除激活码', {
type: 'warning',
confirmButtonText: '确认删除',
cancelButtonText: '取消',
});
} catch {
return;
}
loading.value = true;
try {
const res = await deleteCursorActivationCode(row.id);
if (res?.code !== 200) {
ElMessage.error(res?.msg || '删除失败');
return;
}
ElMessage.success('激活码已删除');
await fetchList();
} finally {
loading.value = false;
}
}
async function handleBatchDelete() {
if (!selectedRows.value.length) {
ElMessage.warning('请选择需要删除的激活码');
return;
}
try {
await ElMessageBox.confirm(`确认删除选中的 ${selectedRows.value.length} 个激活码?`, '批量删除', {
type: 'warning',
confirmButtonText: '确认删除',
cancelButtonText: '取消',
});
} catch {
return;
}
loading.value = true;
try {
for (const row of selectedRows.value) {
const res = await deleteCursorActivationCode(row.id);
if (res?.code !== 200) {
ElMessage.error(res?.msg || `删除「${row.code || row.id}」失败`);
return;
}
}
ElMessage.success('选中激活码已删除');
selectedRows.value = [];
await fetchList();
} finally {
loading.value = false;
}
}
async function handleToggleStatus(row: ActivationCodeRow) {
const isDisabled = Number(row.status) === 3;
const title = isDisabled ? '启用激活码' : '禁用激活码';
const text = isDisabled ? '确认启用该激活码?' : '确认禁用该激活码?';
try {
await ElMessageBox.confirm(text, title, {
type: 'info',
confirmButtonText: isDisabled ? '确认启用' : '确认禁用',
cancelButtonText: '取消',
});
} catch {
return;
}
loading.value = true;
try {
const api = isDisabled ? enableCursorActivationCode : disableCursorActivationCode;
const res = await api(row.id);
if (res?.code !== 200) {
ElMessage.error(res?.msg || '操作失败');
return;
}
ElMessage.success(isDisabled ? '激活码已启用' : '激活码已禁用');
await fetchList();
} finally {
loading.value = false;
}
}
function copyCode(code: unknown) {
const text = String(code || '').trim();
if (!text) {
ElMessage.warning('暂无激活码可复制');
return;
}
navigator.clipboard.writeText(text).then(() => {
ElMessage.success('激活码已复制');
});
}
async function handleExport() {
loading.value = true;
try {
const res = await exportCursorActivationCode({
keyword: query.keyword || undefined,
status: query.status === '' ? undefined : query.status,
type: query.type === '' ? undefined : query.type,
bindStatus: query.bindStatus === '' ? undefined : query.bindStatus,
});
const blob = res instanceof Blob ? res : res?.data instanceof Blob ? res.data : null;
if (!blob) {
ElMessage.success('导出请求已提交');
return;
}
const url = window.URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = url;
link.download = `cursor-activation-code-${Date.now()}.xlsx`;
link.click();
window.URL.revokeObjectURL(url);
} finally {
loading.value = false;
}
}
function updateDeviceType() {
isMobile.value = window.innerWidth <= 768;
}
onMounted(() => {
updateDeviceType();
window.addEventListener('resize', updateDeviceType);
fetchList();
});
onUnmounted(() => {
window.removeEventListener('resize', updateDeviceType);
});
</script>
<template>
<div class="cursor-activation-code-page">
<el-card shadow="never">
<template #header>
<div class="card-header">
<span>激活码管理Cursor</span>
<div class="header-actions">
<el-button type="success" @click="openGenerate">批量生成</el-button>
<el-button type="primary" @click="openAdd">新增激活码</el-button>
</div>
</div>
</template>
<div class="summary-grid">
<div v-for="item in summary" :key="item.label" class="summary-card">
<div class="summary-label">{{ item.label }}</div>
<div class="summary-value" :class="`is-${item.type}`">{{ item.value }}</div>
</div>
</div>
<div class="toolbar">
<div class="toolbar-left">
<el-input v-model="query.keyword" placeholder="搜索激活码 / 账号 / 设备 / 归属用户" clearable class="w-320" />
<el-select v-model="query.status" placeholder="使用状态" clearable class="w-140">
<el-option v-for="item in statusOptions" :key="item.value" :label="item.label" :value="item.value" />
</el-select>
<el-select v-model="query.type" placeholder="卡密类型" clearable class="w-140">
<el-option v-for="item in typeOptions" :key="item.value" :label="item.label" :value="item.value" />
</el-select>
<el-select v-model="query.bindStatus" placeholder="绑定状态" clearable class="w-140">
<el-option v-for="item in bindStatusOptions" :key="item.value" :label="item.label" :value="item.value" />
</el-select>
<el-button @click="resetQuery">重置</el-button>
</div>
<div class="toolbar-right">
<el-button :disabled="!selectedRows.length" type="danger" plain @click="handleBatchDelete">批量删除</el-button>
<el-button @click="handleExport">导出</el-button>
<el-button :loading="loading" @click="fetchList">刷新</el-button>
</div>
</div>
<div class="table-scroll">
<el-table
v-loading="loading"
class="activation-code-table"
:data="tableData"
border
stripe
style="width: 100%"
@selection-change="handleSelectionChange"
>
<el-table-column type="selection" width="52" />
<el-table-column prop="id" label="ID" width="80" />
<el-table-column label="激活码" min-width="260" show-overflow-tooltip>
<template #default="{ row }">
<span class="code-text">{{ row.code || '-' }}</span>
</template>
</el-table-column>
<el-table-column label="类型" width="100" align="center">
<template #default="{ row }">{{ row.typeName || typeLabel(row.type) }}</template>
</el-table-column>
<el-table-column label="有效天数" width="100" align="center">
<template #default="{ row }">{{ row.durationDays || '-' }}</template>
</el-table-column>
<el-table-column label="状态" width="100" align="center">
<template #default="{ row }">
<el-tag :type="statusTagType(row.status)">
{{ statusLabel(row.status) }}
</el-tag>
</template>
</el-table-column>
<el-table-column label="绑定信息" min-width="220" show-overflow-tooltip>
<template #default="{ row }">
<div>{{ row.bindAccount || '-' }}</div>
<div class="muted">设备{{ row.machineCode || row.bindDeviceId || '-' }}</div>
</template>
</el-table-column>
<!-- <el-table-column prop="ownerUserName" label="归属用户" min-width="130" show-overflow-tooltip /> -->
<el-table-column prop="activatedAt" label="激活时间" width="180">
<template #default="{ row }">{{ row.activatedAt || '-' }}</template>
</el-table-column>
<el-table-column prop="expiredAt" label="过期时间" width="180">
<template #default="{ row }">{{ row.expiredAt || '-' }}</template>
</el-table-column>
<el-table-column prop="createdAt" label="创建时间" width="180">
<template #default="{ row }">{{ row.createdAt || '-' }}</template>
</el-table-column>
<el-table-column prop="remark" label="备注" min-width="160" show-overflow-tooltip />
<el-table-column label="操作" width="290" fixed="right" align="center">
<template #default="{ row }">
<el-button link type="primary" @click="openDetail(row)">详情</el-button>
<el-button v-if="row.code" link type="primary" @click="copyCode(row.code)">复制</el-button>
<el-button link type="warning" @click="openEdit(row)">编辑</el-button>
<el-button link :type="Number(row.status) === 3 ? 'success' : 'info'" @click="handleToggleStatus(row)">
{{ Number(row.status) === 3 ? '启用' : '禁用' }}
</el-button>
<el-button link type="danger" @click="handleDelete(row)">删除</el-button>
</template>
</el-table-column>
</el-table>
</div>
<div class="pager">
<el-pagination
v-model:current-page="pagination.page"
v-model:page-size="pagination.pageSize"
background
:layout="isMobile ? 'prev, pager, next' : 'total, sizes, prev, pager, next, jumper'"
:page-sizes="[20, 50, 100]"
:total="total"
/>
</div>
</el-card>
<el-dialog
v-model="editVisible"
:title="form.id ? '编辑激活码' : '新增激活码'"
width="720px"
class="activation-code-edit-dialog"
>
<el-form ref="formRef" :model="form" :rules="rules" label-width="110px">
<el-form-item label="激活码" prop="code">
<el-input v-model="form.code" placeholder="请输入激活码" clearable />
</el-form-item>
<el-row :gutter="12">
<el-col :xs="24" :sm="12">
<el-form-item label="卡密类型" prop="type">
<el-select v-model="form.type" placeholder="请选择卡密类型" class="full" @change="handleTypeChange">
<el-option v-for="item in typeOptions" :key="item.value" :label="item.label" :value="item.value" />
</el-select>
</el-form-item>
</el-col>
<el-col :xs="24" :sm="12">
<el-form-item label="有效天数" prop="durationDays">
<el-input-number v-model="form.durationDays" :min="0" :max="9999" class="full" />
</el-form-item>
</el-col>
</el-row>
<el-row :gutter="12">
<el-col :xs="24" :sm="12">
<el-form-item label="状态" prop="status">
<el-select v-model="form.status" placeholder="请选择状态" class="full">
<el-option v-for="item in statusOptions" :key="item.value" :label="item.label" :value="item.value" />
</el-select>
</el-form-item>
</el-col>
<el-col :xs="24" :sm="12">
<el-form-item label="归属用户ID">
<el-input v-model="form.ownerUserId" placeholder="请输入归属用户ID" clearable />
</el-form-item>
</el-col>
</el-row>
<el-form-item label="归属用户">
<el-input v-model="form.ownerUserName" placeholder="请输入归属用户名称" clearable />
</el-form-item>
<el-row :gutter="12">
<el-col :xs="24" :sm="12">
<el-form-item label="绑定账号">
<el-input v-model="form.bindAccount" placeholder="请输入绑定账号" clearable />
</el-form-item>
</el-col>
<el-col :xs="24" :sm="12">
<el-form-item label="绑定设备ID">
<el-input v-model="form.bindDeviceId" placeholder="请输入绑定设备ID" clearable />
</el-form-item>
</el-col>
</el-row>
<el-row :gutter="12">
<el-col :xs="24" :sm="12">
<el-form-item label="激活时间">
<el-date-picker
v-model="form.activatedAt"
type="datetime"
value-format="YYYY-MM-DD HH:mm:ss"
placeholder="请选择激活时间"
class="full"
/>
</el-form-item>
</el-col>
<el-col :xs="24" :sm="12">
<el-form-item label="过期时间">
<el-date-picker
v-model="form.expiredAt"
type="datetime"
value-format="YYYY-MM-DD HH:mm:ss"
placeholder="请选择过期时间"
class="full"
/>
</el-form-item>
</el-col>
</el-row>
<el-form-item label="备注">
<el-input v-model="form.remark" type="textarea" :rows="3" placeholder="请输入备注" />
</el-form-item>
</el-form>
<template #footer>
<el-button @click="editVisible = false">取消</el-button>
<el-button type="primary" :loading="actionLoading" @click="handleSave">保存</el-button>
</template>
</el-dialog>
<el-dialog v-model="generateVisible" title="批量生成激活码" width="620px" class="activation-code-generate-dialog">
<el-form ref="generateFormRef" :model="generateForm" :rules="generateRules" label-width="110px">
<el-row :gutter="12">
<el-col :xs="24" :sm="12">
<el-form-item label="生成数量" prop="count">
<el-input-number v-model="generateForm.count" :min="1" :max="10000" class="full" />
</el-form-item>
</el-col>
<el-col :xs="24" :sm="12">
<el-form-item label="卡密类型" prop="type">
<el-select
v-model="generateForm.type"
placeholder="请选择卡密类型"
class="full"
@change="handleGenerateTypeChange"
>
<el-option v-for="item in typeOptions" :key="item.value" :label="item.label" :value="item.value" />
</el-select>
</el-form-item>
</el-col>
</el-row>
<el-form-item label="有效天数" prop="durationDays">
<el-input-number v-model="generateForm.durationDays" :min="0" :max="9999" class="full" />
</el-form-item>
<el-row :gutter="12">
<el-col :xs="24" :sm="12">
<el-form-item label="归属用户ID">
<el-input v-model="generateForm.ownerUserId" placeholder="请输入归属用户ID" clearable />
</el-form-item>
</el-col>
<el-col :xs="24" :sm="12">
<el-form-item label="归属用户">
<el-input v-model="generateForm.ownerUserName" placeholder="请输入归属用户名称" clearable />
</el-form-item>
</el-col>
</el-row>
<el-form-item label="备注">
<el-input v-model="generateForm.remark" type="textarea" :rows="3" placeholder="请输入备注" />
</el-form-item>
</el-form>
<template #footer>
<el-button @click="generateVisible = false">取消</el-button>
<el-button type="primary" :loading="actionLoading" @click="handleGenerate">确认生成</el-button>
</template>
</el-dialog>
<el-drawer v-model="detailVisible" title="激活码详情" size="640px" direction="rtl" class="activation-code-detail-drawer">
<el-descriptions v-if="currentRow" :column="1" border>
<el-descriptions-item label="ID">{{ currentRow.id || '-' }}</el-descriptions-item>
<el-descriptions-item label="激活码">
<span class="code-text">{{ currentRow.code || '-' }}</span>
<el-button v-if="currentRow.code" link type="primary" @click="copyCode(currentRow.code)">复制</el-button>
</el-descriptions-item>
<el-descriptions-item label="卡密类型">{{ currentRow.typeName || typeLabel(currentRow.type) }}</el-descriptions-item>
<el-descriptions-item label="有效天数">{{ currentRow.durationDays || '-' }}</el-descriptions-item>
<el-descriptions-item label="状态">
<el-tag :type="statusTagType(currentRow.status)">
{{ statusLabel(currentRow.status) }}
</el-tag>
</el-descriptions-item>
<el-descriptions-item label="绑定账号">{{ currentRow.bindAccount || '-' }}</el-descriptions-item>
<el-descriptions-item label="绑定设备">{{ currentRow.machineCode || currentRow.bindDeviceId || '-' }}</el-descriptions-item>
<el-descriptions-item label="设备信息">{{ currentRow.deviceInfo || '-' }}</el-descriptions-item>
<el-descriptions-item label="归属用户">{{ currentRow.ownerUserName || '-' }}</el-descriptions-item>
<el-descriptions-item label="归属用户ID">{{ currentRow.ownerUserId || '-' }}</el-descriptions-item>
<el-descriptions-item label="激活时间">{{ currentRow.activatedAt || '-' }}</el-descriptions-item>
<el-descriptions-item label="过期时间">{{ currentRow.expiredAt || '-' }}</el-descriptions-item>
<el-descriptions-item label="创建时间">{{ currentRow.createdAt || '-' }}</el-descriptions-item>
<el-descriptions-item label="更新时间">{{ currentRow.updatedAt || '-' }}</el-descriptions-item>
<el-descriptions-item label="备注">{{ currentRow.remark || '-' }}</el-descriptions-item>
</el-descriptions>
</el-drawer>
</div>
</template>
<style lang="less" scoped>
.cursor-activation-code-page {
padding: 12px;
}
.card-header,
.header-actions,
.toolbar,
.toolbar-left,
.toolbar-right,
.code-cell {
display: flex;
align-items: center;
}
.card-header {
justify-content: space-between;
gap: 12px;
}
.header-actions,
.toolbar-left,
.toolbar-right,
.code-cell {
gap: 8px;
}
.summary-grid {
display: grid;
grid-template-columns: repeat(4, minmax(120px, 1fr));
gap: 12px;
margin-bottom: 14px;
}
.summary-card {
padding: 14px 16px;
border: 1px solid #ebeef5;
border-radius: 8px;
background: #fbfcff;
}
.summary-label {
color: #909399;
font-size: 13px;
margin-bottom: 8px;
}
.summary-value {
font-size: 24px;
font-weight: 700;
color: #409eff;
&.is-success {
color: #67c23a;
}
&.is-info {
color: #909399;
}
&.is-danger {
color: #f56c6c;
}
}
.toolbar {
justify-content: space-between;
gap: 12px;
flex-wrap: wrap;
margin-bottom: 12px;
}
.toolbar-left,
.toolbar-right {
flex-wrap: wrap;
}
.w-320 {
width: 320px;
}
.w-140 {
width: 140px;
}
.table-scroll {
width: 100%;
overflow-x: auto;
-webkit-overflow-scrolling: touch;
}
.activation-code-table {
min-width: 1360px;
}
.code-text {
font-family: Consolas, Monaco, 'Courier New', monospace;
font-weight: 600;
word-break: break-all;
}
.muted {
color: #909399;
font-size: 12px;
line-height: 1.6;
}
.full {
width: 100%;
}
.pager {
display: flex;
justify-content: flex-end;
margin-top: 14px;
}
:deep(.activation-code-edit-dialog),
:deep(.activation-code-generate-dialog) {
max-width: calc(100vw - 24px);
}
@media (max-width: 768px) {
.cursor-activation-code-page {
padding: 8px;
}
.card-header,
.header-actions {
align-items: stretch;
flex-direction: column;
}
.summary-grid {
grid-template-columns: repeat(2, minmax(120px, 1fr));
}
.toolbar-left,
.toolbar-right,
.w-320,
.w-140 {
width: 100%;
}
.toolbar-right .el-button,
.header-actions .el-button {
width: 100%;
margin-left: 0;
}
.pager {
justify-content: center;
}
:deep(.activation-code-detail-drawer) {
width: 100vw !important;
}
}
</style>

View File

@ -1,4 +1,6 @@
<script lang="ts" setup>
import { ElMessage } from 'element-plus';
defineProps({
modelValue: {
type: Boolean,
@ -45,6 +47,18 @@ function statusType(status: unknown) {
if (value === 'failed' || value === '0') return 'danger';
return 'info';
}
function copyCode(code: unknown) {
const text = String(code || '').trim();
if (!text) {
ElMessage.warning('暂无激活码可复制');
return;
}
navigator.clipboard.writeText(text).then(() => {
ElMessage.success('激活码已复制');
});
}
</script>
<template>
@ -54,7 +68,7 @@ function statusType(status: unknown) {
title="激活记录"
size="760px"
direction="rtl"
@update:model-value="(v) => emit('update:modelValue', v)"
@update:model-value="(v: boolean) => emit('update:modelValue', v)"
@opened="emit('refresh')"
>
<div class="record-header">
@ -74,10 +88,23 @@ function statusType(status: unknown) {
</el-tag>
</template>
</el-table-column>
<el-table-column prop="account" label="激活账号" min-width="150" show-overflow-tooltip />
<el-table-column prop="ip" label="IP" min-width="130" show-overflow-tooltip />
<el-table-column prop="clientVersion" label="客户端版本" width="120" />
<el-table-column prop="createdAt" label="激活时间" width="180" />
<el-table-column label="激活码" min-width="260" show-overflow-tooltip>
<template #default="{ row: item }">
<span class="code-text">{{ item.activationCode || item.code || '-' }}</span>
<el-button v-if="item.activationCode || item.code" link type="primary" @click="copyCode(item.activationCode || item.code)">
复制
</el-button>
</template>
</el-table-column>
<el-table-column prop="machineCode" label="机器码" min-width="180" show-overflow-tooltip />
<el-table-column prop="deviceInfo" label="设备信息" min-width="160" show-overflow-tooltip />
<el-table-column prop="durationDays" label="有效天数" width="100" align="center" />
<el-table-column prop="activatedAt" label="激活时间" width="180">
<template #default="{ row: item }">{{ item.activatedAt || item.createdAt || '-' }}</template>
</el-table-column>
<el-table-column prop="expiredAt" label="到期时间" width="180">
<template #default="{ row: item }">{{ item.expiredAt || '-' }}</template>
</el-table-column>
<el-table-column prop="remark" label="备注" min-width="180" show-overflow-tooltip />
</el-table>
@ -88,8 +115,8 @@ function statusType(status: unknown) {
background
layout="total, prev, pager, next, jumper"
:total="total"
@update:current-page="(v) => emit('update:page', v)"
@update:page-size="(v) => emit('update:pageSize', v)"
@update:current-page="(v: number) => emit('update:page', v)"
@update:page-size="(v: number) => emit('update:pageSize', v)"
/>
</div>
</el-drawer>
@ -121,6 +148,12 @@ function statusType(status: unknown) {
margin-top: 14px;
}
.code-text {
font-family: Consolas, Monaco, 'Courier New', monospace;
font-weight: 600;
word-break: break-all;
}
@media (max-width: 768px) {
:deep(.equipment-record-drawer) {
width: 100vw !important;

View File

@ -16,7 +16,7 @@ const props = defineProps({
const emit = defineEmits(['update:modelValue']);
const statusMap: Record<string, { label: string; type: string }> = {
active: { label: '正常', type: 'success' },
active: { label: '已激活', type: 'success' },
inactive: { label: '未激活', type: 'info' },
disabled: { label: '禁用', type: 'danger' },
expired: { label: '已过期', type: 'warning' },
@ -50,7 +50,7 @@ function copyText(text: unknown, label = '内容') {
:model-value="modelValue"
title="设备详情"
width="760px"
@update:model-value="(v) => emit('update:modelValue', v)"
@update:model-value="(v: boolean) => emit('update:modelValue', v)"
>
<el-descriptions v-if="row" :column="2" border>
<el-descriptions-item label="设备ID">
@ -73,7 +73,7 @@ function copyText(text: unknown, label = '内容') {
<el-descriptions-item label="机器码">
<span class="code-text">{{ display(row.machineCode) }}</span>
</el-descriptions-item>
<el-descriptions-item label="授权码">
<el-descriptions-item label="绑定激活码">
<span class="code-text">{{ display(row.licenseCode) }}</span>
</el-descriptions-item>
<el-descriptions-item label="系统平台">
@ -83,7 +83,7 @@ function copyText(text: unknown, label = '内容') {
{{ display(row.version) }}
</el-descriptions-item>
<el-descriptions-item label="绑定账号">
{{ display(row.account) }}
{{ display(row.raw?.bindAccount || row.raw?.bind_account) }}
</el-descriptions-item>
<el-descriptions-item label="归属用户">
{{ display(row.owner) }}

View File

@ -34,28 +34,31 @@ defineProps({
const emit = defineEmits(['update:modelValue', 'update:page', 'update:pageSize', 'refresh']);
function copyContent(content: unknown) {
function copyContent(content: unknown, label = '提取内容') {
const text = String(content || '').trim();
if (!text) {
ElMessage.warning('暂无提取内容可复制');
ElMessage.warning(`暂无${label}可复制`);
return;
}
navigator.clipboard.writeText(text).then(() => {
ElMessage.success('提取内容已复制');
ElMessage.success(`${label}已复制`);
});
}
function statusText(status: unknown) {
const value = String(status || '');
if (value === 'success' || value === '1') return '成功';
if (value === 'failed' || value === '0') return '失败';
if (value === 'success' || value === '1') return '已提取';
if (value === '2') return '补号';
if (value === '3') return '异常';
if (value === 'failed' || value === '0') return '未提取';
return value || '-';
}
function statusType(status: unknown) {
const value = String(status || '');
if (value === 'success' || value === '1') return 'success';
if (value === 'failed' || value === '0') return 'danger';
if (value === '2') return 'warning';
if (value === '3' || value === 'failed') return 'danger';
return 'info';
}
</script>
@ -67,7 +70,7 @@ function statusType(status: unknown) {
title="提取记录"
size="860px"
direction="rtl"
@update:model-value="(v) => emit('update:modelValue', v)"
@update:model-value="(v: boolean) => emit('update:modelValue', v)"
@opened="emit('refresh')"
>
<div class="record-header">
@ -87,19 +90,47 @@ function statusType(status: unknown) {
</el-tag>
</template>
</el-table-column>
<el-table-column prop="platform" label="提取平台" width="110" />
<el-table-column prop="type" label="提取类型" width="110" />
<el-table-column prop="account" label="提取账号" min-width="150" show-overflow-tooltip />
<el-table-column label="提取内容" min-width="220" show-overflow-tooltip>
<el-table-column prop="platform" label="提取平台" width="110">
<template #default="{ row: item }">{{ item.platform || '-' }}</template>
</el-table-column>
<el-table-column prop="type" label="数据类型" width="110">
<template #default="{ row: item }">{{ item.type || '-' }}</template>
</el-table-column>
<el-table-column label="Cursor账号" min-width="170" show-overflow-tooltip>
<template #default="{ row: item }">
<span>{{ item.content || '-' }}</span>
<el-button v-if="item.content" link type="primary" @click="copyContent(item.content)">
<span>{{ item.account || '-' }}</span>
<el-button v-if="item.account" link type="primary" @click="copyContent(item.account, 'Cursor账号')">
复制
</el-button>
</template>
</el-table-column>
<el-table-column prop="ip" label="IP" min-width="130" show-overflow-tooltip />
<el-table-column prop="createdAt" label="提取时间" width="180" />
<el-table-column label="密码" min-width="150" show-overflow-tooltip>
<template #default="{ row: item }">
<span>{{ item.password || '-' }}</span>
<el-button v-if="item.password" link type="primary" @click="copyContent(item.password, '密码')">
复制
</el-button>
</template>
</el-table-column>
<el-table-column label="Token" min-width="240" show-overflow-tooltip>
<template #default="{ row: item }">
<span>{{ item.token || '-' }}</span>
<el-button v-if="item.token" link type="primary" @click="copyContent(item.token, 'Token')">
复制
</el-button>
</template>
</el-table-column>
<el-table-column label="提取内容" min-width="260" show-overflow-tooltip>
<template #default="{ row: item }">
<span>{{ item.content || '-' }}</span>
<el-button v-if="item.content" link type="primary" @click="copyContent(item.content, '提取内容')">
复制
</el-button>
</template>
</el-table-column>
<el-table-column prop="extractedAt" label="提取时间" width="180">
<template #default="{ row: item }">{{ item.extractedAt || item.createdAt || '-' }}</template>
</el-table-column>
<el-table-column prop="remark" label="备注" min-width="180" show-overflow-tooltip />
</el-table>
@ -110,8 +141,8 @@ function statusType(status: unknown) {
background
layout="total, prev, pager, next, jumper"
:total="total"
@update:current-page="(v) => emit('update:page', v)"
@update:page-size="(v) => emit('update:pageSize', v)"
@update:current-page="(v: number) => emit('update:page', v)"
@update:page-size="(v: number) => emit('update:pageSize', v)"
/>
</div>
</el-drawer>

View File

@ -15,7 +15,7 @@ import {
getCursorEquipmentExtractRecords,
getCursorEquipmentList,
updateCursorEquipment,
} from '@/api/cursorEquipment';
} from '../../../api/cursorEquipment';
type EquipmentRow = Record<string, any>;
@ -60,10 +60,10 @@ const extractState = reactive({
});
const statusOptions = [
{ label: '未激活', value: 'inactive' },
{ label: '正常', value: 'active' },
{ label: '禁用', value: 'disabled' },
{ label: '已过期', value: 'expired' },
{ label: '未激活', value: 0 },
{ label: '已激活', value: 1 },
{ label: '禁用', value: 3 },
{ label: '已过期', value: 2 },
];
const osOptions = [
@ -74,7 +74,7 @@ const osOptions = [
];
const statusMap: Record<string, { label: string; type: string }> = {
active: { label: '正常', type: 'success' },
active: { label: '已激活', type: 'success' },
inactive: { label: '未激活', type: 'info' },
disabled: { label: '禁用', type: 'danger' },
expired: { label: '已过期', type: 'warning' },
@ -87,7 +87,7 @@ const summary = computed(() => {
const expired = tableData.value.filter((item) => item.status === 'expired').length;
return [
{ label: '当前页设备', value: tableData.value.length, type: 'primary' },
{ label: '正常设备', value: active, type: 'success' },
{ label: '已激活设备', value: active, type: 'success' },
{ label: '未激活', value: inactive, type: 'info' },
{ label: '禁用/过期', value: disabled + expired, type: 'danger' },
];
@ -137,24 +137,35 @@ function formatTime(value: any) {
return `${d.getFullYear()}-${p(d.getMonth() + 1)}-${p(d.getDate())} ${p(d.getHours())}:${p(d.getMinutes())}:${p(d.getSeconds())}`;
}
function normalizeEquipmentStatus(status: any) {
const value = String(status ?? '').trim();
if (value === '0' || value === 'inactive') return 'inactive';
if (value === '1' || value === 'active' || value === 'normal') return 'active';
if (value === '2' || value === 'expired') return 'expired';
if (value === '3' || value === 'disabled' || value === 'disable') return 'disabled';
return value || 'inactive';
}
function normalizeRow(raw: any): EquipmentRow {
const status = String(pick(raw, 'status', 'Status') || 'inactive');
const status = normalizeEquipmentStatus(pick(raw, 'status', 'Status'));
return {
id: pick(raw, 'id', 'ID', 'Id'),
name: pick(raw, 'name', 'device_name', 'deviceName', 'Name', 'DeviceName'),
deviceNo: pick(raw, 'device_no', 'deviceNo', 'DeviceNo', 'serial_no', 'serialNo'),
machineCode: pick(raw, 'machine_code', 'machineCode', 'MachineCode', 'fingerprint'),
licenseCode: pick(raw, 'license_code', 'licenseCode', 'LicenseCode'),
os: pick(raw, 'os', 'OS', 'platform', 'Platform'),
licenseCode: pick(raw, 'bindActivationCode', 'activationCode', 'activation_code', 'code', 'Code', 'license_code', 'licenseCode', 'LicenseCode'),
os: pick(raw, 'system', 'System', 'os', 'OS', 'platform', 'Platform'),
version: pick(raw, 'version', 'Version', 'client_version', 'clientVersion'),
account: pick(raw, 'account', 'Account', 'email', 'Email'),
account: pick(raw, 'bindActivationCode', 'activationCode', 'activation_code', 'code', 'Code', 'license_code', 'licenseCode', 'LicenseCode'),
owner: pick(raw, 'owner', 'Owner', 'user_name', 'userName', 'tenant_name', 'tenantName'),
status,
activationCount: Number(pick(raw, 'activation_count', 'activationCount', 'ActivationCount') || 0),
extractCount: Number(pick(raw, 'extract_count', 'extractCount', 'ExtractCount') || 0),
lastActivatedAt: formatTime(pick(raw, 'last_activated_at', 'lastActivatedAt', 'activated_at')),
lastActivatedAt: formatTime(pick(raw, 'lastActivatedAt', 'last_activated_at', 'activationTime', 'activation_time', 'activated_at', 'activatedAt')),
lastExtractedAt: formatTime(pick(raw, 'last_extracted_at', 'lastExtractedAt', 'extracted_at')),
expiredAt: formatTime(pick(raw, 'expired_at', 'expiredAt', 'expire_time', 'expireTime')),
expiredAt: formatTime(pick(raw, 'expiredAt', 'expired_at', 'expireTime', 'expire_time')),
createdAt: formatTime(pick(raw, 'create_time', 'created_at', 'createdAt', 'CreatedAt')),
remark: pick(raw, 'remark', 'Remark'),
raw,
@ -164,14 +175,23 @@ function normalizeRow(raw: any): EquipmentRow {
function normalizeRecord(raw: any): EquipmentRow {
return {
id: pick(raw, 'id', 'ID', 'Id'),
status: pick(raw, 'status', 'Status', 'result', 'Result'),
status: pick(raw, 'status', 'Status', 'result', 'Result', 'isExtracted', 'is_extracted'),
activationCode: pick(raw, 'activationCode', 'activation_code', 'code', 'Code'),
durationDays: pick(raw, 'durationDays', 'duration_days'),
machineCode: pick(raw, 'machineCode', 'machine_code', 'MachineCode'),
deviceInfo: pick(raw, 'deviceInfo', 'device_info', 'DeviceInfo'),
expiredAt: formatTime(pick(raw, 'expiredAt', 'expired_at', 'expireTime', 'expire_time')),
activatedAt: formatTime(pick(raw, 'activatedAt', 'activated_at', 'activationTime', 'activation_time')),
account: pick(raw, 'account', 'Account', 'email', 'Email'),
platform: pick(raw, 'platform', 'Platform', 'source', 'Source'),
password: pick(raw, 'password', 'Password'),
token: pick(raw, 'token', 'Token'),
platform: pick(raw, 'platform', 'Platform', 'source', 'Source', 'extractedPlatform', 'extracted_platform'),
type: pick(raw, 'type', 'Type', 'data_type', 'dataType'),
content: pick(raw, 'content', 'Content', 'extract_content', 'extractContent', 'token', 'Token'),
content: pick(raw, 'content', 'Content', 'extract_content', 'extractContent'),
ip: pick(raw, 'ip', 'IP', 'client_ip', 'clientIp'),
clientVersion: pick(raw, 'client_version', 'clientVersion', 'version', 'Version'),
createdAt: formatTime(pick(raw, 'create_time', 'created_at', 'createdAt', 'CreatedAt')),
extractedAt: formatTime(pick(raw, 'extractedAt', 'extracted_at', 'extracted_time')),
remark: pick(raw, 'remark', 'Remark', 'message', 'Message'),
raw,
};
@ -202,7 +222,7 @@ async function fetchList() {
page: pagination.page,
pageSize: pagination.pageSize,
keyword: query.keyword || undefined,
status: query.status || undefined,
status: query.status === '' ? undefined : query.status,
os: query.os || undefined,
});
if (res?.code !== 200) {
@ -401,7 +421,7 @@ onUnmounted(() => {
<div class="toolbar-left">
<el-input
v-model="query.keyword"
placeholder="搜索设备名称 / 编号 / 机器码 / 账号"
placeholder="搜索设备名称 / 编号 / 机器码 / 激活码"
clearable
class="w-300"
/>
@ -450,7 +470,7 @@ onUnmounted(() => {
<el-table-column prop="version" label="版本" width="110" align="center">
<template #default="{ row }">{{ row.version || '-' }}</template>
</el-table-column>
<el-table-column prop="account" label="绑定账号" min-width="160" show-overflow-tooltip />
<el-table-column prop="account" label="绑定激活码" min-width="160" show-overflow-tooltip />
<el-table-column prop="owner" label="归属用户" min-width="130" show-overflow-tooltip />
<el-table-column label="激活/提取" width="120" align="center">
<template #default="{ row }">
@ -492,18 +512,18 @@ onUnmounted(() => {
</div>
</el-card>
<DetailDialog v-model="detailVisible" :row="currentRow" />
<DetailDialog v-model="detailVisible" :row="currentRow || undefined" />
<EditDialog
v-model="editVisible"
:row="currentRow"
:row="currentRow || undefined"
:loading="actionLoading"
@submit="handleSave"
/>
<DeleteDialog
v-model="deleteVisible"
:row="currentRow"
:row="currentRow || undefined"
:loading="actionLoading"
@confirm="handleDelete"
/>
@ -512,7 +532,7 @@ onUnmounted(() => {
v-model="activationVisible"
v-model:page="activationState.page"
v-model:page-size="activationState.pageSize"
:row="currentRow"
:row="currentRow || undefined"
:loading="activationState.loading"
:records="activationState.records"
:total="activationState.total"
@ -523,7 +543,7 @@ onUnmounted(() => {
v-model="extractVisible"
v-model:page="extractState.page"
v-model:page-size="extractState.pageSize"
:row="currentRow"
:row="currentRow || undefined"
:loading="extractState.loading"
:records="extractState.records"
:total="extractState.total"

View File

@ -27,6 +27,7 @@ export default defineConfig({
},
},
server: {
host: "127.0.0.1",
port: 5000,
// 开发时前端在 5000接口走相对路径 /platform/*、/backend/*,转发到本地 Go当前 httpport=8081
proxy: {