This commit is contained in:
root 2025-07-12 21:33:39 +08:00
parent 013ff446e0
commit 50106f548d
2 changed files with 22 additions and 19 deletions

View File

@ -7,11 +7,9 @@ import {
Grid,
List,
Upload,
Filter,
Tag,
BarChart3,
RefreshCw,
Download,
Eye,
Trash2
} from 'lucide-react'

View File

@ -1,4 +1,5 @@
import { invoke } from '@tauri-apps/api/core'
import { useAuthStore } from '../stores/useAuthStore'
// 统一的响应格式
export interface TemplateResponse {
@ -137,13 +138,17 @@ export interface TemplateDetail {
}
export class TemplateServiceV2 {
private static currentUserId: string = 'default'
/**
* ID
* ID
*/
static setUserId(userId: string) {
this.currentUserId = userId
private static getCurrentUserId(): string {
const authState = useAuthStore.getState()
if (!authState.isAuthenticated || !authState.user?.id) {
throw new Error('用户未登录,请先登录后再进行操作')
}
return authState.user.id
}
/**
@ -153,7 +158,7 @@ export class TemplateServiceV2 {
try {
const request: BatchImportRequest = {
source_folder: sourceFolder,
user_id: userId || this.currentUserId,
user_id: userId || this.getCurrentUserId(),
verbose: false,
json_output: true
}
@ -177,7 +182,7 @@ export class TemplateServiceV2 {
static async getTemplates(includeCloud: boolean = true, limit: number = 100, userId?: string): Promise<TemplateInfo[]> {
try {
const request: TemplateListRequest = {
user_id: userId || this.currentUserId,
user_id: userId || this.getCurrentUserId(),
include_cloud: includeCloud,
limit: limit,
verbose: false,
@ -204,7 +209,7 @@ export class TemplateServiceV2 {
try {
const request: TemplateGetRequest = {
template_id: templateId,
user_id: userId || this.currentUserId,
user_id: userId || this.getCurrentUserId(),
verbose: false,
json_output: true
}
@ -250,7 +255,7 @@ export class TemplateServiceV2 {
try {
const request: TemplateDeleteRequest = {
template_id: templateId,
user_id: userId || this.currentUserId,
user_id: userId || this.getCurrentUserId(),
verbose: false,
json_output: true
}
@ -280,7 +285,7 @@ export class TemplateServiceV2 {
try {
const request: TemplateSearchRequest = {
query: query,
user_id: userId || this.currentUserId,
user_id: userId || this.getCurrentUserId(),
include_cloud: includeCloud,
limit: limit,
verbose: false,
@ -305,8 +310,8 @@ export class TemplateServiceV2 {
*/
static async getTemplateStats(userId?: string): Promise<TemplateStats> {
try {
const response = await invoke<TemplateResponse>('get_template_stats_cli', {
user_id: userId || this.currentUserId,
const response = await invoke<TemplateResponse>('get_template_stats_cli', {
user_id: userId || this.getCurrentUserId(),
verbose: false
})
@ -326,8 +331,8 @@ export class TemplateServiceV2 {
*/
static async getPopularTags(limit: number = 20, userId?: string): Promise<TagInfo[]> {
try {
const response = await invoke<TemplateResponse>('get_popular_tags_cli', {
user_id: userId || this.currentUserId,
const response = await invoke<TemplateResponse>('get_popular_tags_cli', {
user_id: userId || this.getCurrentUserId(),
limit: limit,
verbose: false
})
@ -353,9 +358,9 @@ export class TemplateServiceV2 {
userId?: string
): Promise<TemplateInfo[]> {
try {
const response = await invoke<TemplateResponse>('get_templates_by_tag_cli', {
const response = await invoke<TemplateResponse>('get_templates_by_tag_cli', {
tag: tag,
user_id: userId || this.currentUserId,
user_id: userId || this.getCurrentUserId(),
include_cloud: includeCloud,
limit: limit,
verbose: false
@ -430,6 +435,6 @@ export class TemplateServiceV2 {
*
*/
static isUserTemplate(template: TemplateInfo, userId?: string): boolean {
return template.user_id === (userId || this.currentUserId)
return template.user_id === (userId || this.getCurrentUserId())
}
}