()
| 44 | // Actions |
| 45 | // 管理员获取所有知识库,普通用户获取有权限访问的知识库 |
| 46 | async function loadDatabases() { |
| 47 | state.listLoading = true |
| 48 | try { |
| 49 | const data = userStore.isAdmin |
| 50 | ? await databaseApi.getDatabases() |
| 51 | : await databaseApi.getAccessibleDatabases() |
| 52 | const list = data?.databases || [] |
| 53 | databases.value = list.sort((a, b) => { |
| 54 | const timeA = parseToShanghai(a.created_at) |
| 55 | const timeB = parseToShanghai(b.created_at) |
| 56 | if (!timeA && !timeB) return 0 |
| 57 | if (!timeA) return 1 |
| 58 | if (!timeB) return -1 |
| 59 | return timeB.valueOf() - timeA.valueOf() // 降序排列,最新的在前面 |
| 60 | }) |
| 61 | } catch (error) { |
| 62 | console.error('加载数据库列表失败:', error) |
| 63 | if (error.message.includes('权限')) { |
| 64 | message.error('没有权限访问知识库') |
| 65 | } |
| 66 | throw error |
| 67 | } finally { |
| 68 | state.listLoading = false |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | async function createDatabase(formData) { |
| 73 | // 验证 |
no test coverage detected