fix
This commit is contained in:
parent
013ff446e0
commit
50106f548d
|
|
@ -7,11 +7,9 @@ import {
|
|||
Grid,
|
||||
List,
|
||||
Upload,
|
||||
Filter,
|
||||
Tag,
|
||||
BarChart3,
|
||||
RefreshCw,
|
||||
Download,
|
||||
Eye,
|
||||
Trash2
|
||||
} from 'lucide-react'
|
||||
|
|
|
|||
|
|
@ -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())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue