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, Grid,
List, List,
Upload, Upload,
Filter,
Tag, Tag,
BarChart3, BarChart3,
RefreshCw, RefreshCw,
Download,
Eye, Eye,
Trash2 Trash2
} from 'lucide-react' } from 'lucide-react'

View File

@ -1,4 +1,5 @@
import { invoke } from '@tauri-apps/api/core' import { invoke } from '@tauri-apps/api/core'
import { useAuthStore } from '../stores/useAuthStore'
// 统一的响应格式 // 统一的响应格式
export interface TemplateResponse { export interface TemplateResponse {
@ -137,13 +138,17 @@ export interface TemplateDetail {
} }
export class TemplateServiceV2 { export class TemplateServiceV2 {
private static currentUserId: string = 'default'
/** /**
* ID * ID
*/ */
static setUserId(userId: string) { private static getCurrentUserId(): string {
this.currentUserId = userId 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 { try {
const request: BatchImportRequest = { const request: BatchImportRequest = {
source_folder: sourceFolder, source_folder: sourceFolder,
user_id: userId || this.currentUserId, user_id: userId || this.getCurrentUserId(),
verbose: false, verbose: false,
json_output: true json_output: true
} }
@ -177,7 +182,7 @@ export class TemplateServiceV2 {
static async getTemplates(includeCloud: boolean = true, limit: number = 100, userId?: string): Promise<TemplateInfo[]> { static async getTemplates(includeCloud: boolean = true, limit: number = 100, userId?: string): Promise<TemplateInfo[]> {
try { try {
const request: TemplateListRequest = { const request: TemplateListRequest = {
user_id: userId || this.currentUserId, user_id: userId || this.getCurrentUserId(),
include_cloud: includeCloud, include_cloud: includeCloud,
limit: limit, limit: limit,
verbose: false, verbose: false,
@ -204,7 +209,7 @@ export class TemplateServiceV2 {
try { try {
const request: TemplateGetRequest = { const request: TemplateGetRequest = {
template_id: templateId, template_id: templateId,
user_id: userId || this.currentUserId, user_id: userId || this.getCurrentUserId(),
verbose: false, verbose: false,
json_output: true json_output: true
} }
@ -250,7 +255,7 @@ export class TemplateServiceV2 {
try { try {
const request: TemplateDeleteRequest = { const request: TemplateDeleteRequest = {
template_id: templateId, template_id: templateId,
user_id: userId || this.currentUserId, user_id: userId || this.getCurrentUserId(),
verbose: false, verbose: false,
json_output: true json_output: true
} }
@ -280,7 +285,7 @@ export class TemplateServiceV2 {
try { try {
const request: TemplateSearchRequest = { const request: TemplateSearchRequest = {
query: query, query: query,
user_id: userId || this.currentUserId, user_id: userId || this.getCurrentUserId(),
include_cloud: includeCloud, include_cloud: includeCloud,
limit: limit, limit: limit,
verbose: false, verbose: false,
@ -306,7 +311,7 @@ export class TemplateServiceV2 {
static async getTemplateStats(userId?: string): Promise<TemplateStats> { static async getTemplateStats(userId?: string): Promise<TemplateStats> {
try { try {
const response = await invoke<TemplateResponse>('get_template_stats_cli', { const response = await invoke<TemplateResponse>('get_template_stats_cli', {
user_id: userId || this.currentUserId, user_id: userId || this.getCurrentUserId(),
verbose: false verbose: false
}) })
@ -327,7 +332,7 @@ export class TemplateServiceV2 {
static async getPopularTags(limit: number = 20, userId?: string): Promise<TagInfo[]> { static async getPopularTags(limit: number = 20, userId?: string): Promise<TagInfo[]> {
try { try {
const response = await invoke<TemplateResponse>('get_popular_tags_cli', { const response = await invoke<TemplateResponse>('get_popular_tags_cli', {
user_id: userId || this.currentUserId, user_id: userId || this.getCurrentUserId(),
limit: limit, limit: limit,
verbose: false verbose: false
}) })
@ -355,7 +360,7 @@ export class TemplateServiceV2 {
try { try {
const response = await invoke<TemplateResponse>('get_templates_by_tag_cli', { const response = await invoke<TemplateResponse>('get_templates_by_tag_cli', {
tag: tag, tag: tag,
user_id: userId || this.currentUserId, user_id: userId || this.getCurrentUserId(),
include_cloud: includeCloud, include_cloud: includeCloud,
limit: limit, limit: limit,
verbose: false verbose: false
@ -430,6 +435,6 @@ export class TemplateServiceV2 {
* *
*/ */
static isUserTemplate(template: TemplateInfo, userId?: string): boolean { static isUserTemplate(template: TemplateInfo, userId?: string): boolean {
return template.user_id === (userId || this.currentUserId) return template.user_id === (userId || this.getCurrentUserId())
} }
} }