# 网盘账号管理与列表刷新 (2025-04-11 14:43:49)
_**User**_
1.管理页面-网盘账号管理-点击网盘列表内的编辑-编辑完内容保存后,自动局部刷新网盘账号列表
---
_**Assistant**_
---
我需要先了解项目的结构,然后再查找与网盘账号管理相关的代码。
---
Listed current directory • **22** results
| Name |
|-------|
| 📁 `.git` |
| 📄 `uv.lock` |
| 📄 `pyproject.toml` |
| 📄 `.python-version` |
| 📁 `.venv` |
| 📄 ` .python-version` |
| 📄 `.cursorindexingignore` |
| 📁 `.ide` |
| 📁 `utils` |
| 📁 `.cnb` |
| 📄 `.cnb copy.yml` |
| 📄 `.cnb.yml` |
| 📁 `.specstory` |
| 📄 `README.md` |
| 📄 `database.db` |
| 📄 `init_db.py` |
| 📄 `main.py` |
| 📁 `templates` |
| 📁 `__pycache__` |
| 📄 `config.py` |
| 📄 `requirements.txt` |
| 📁 `static` |
---
我需要查看项目的主要文件和网盘账号管理相关的代码。首先,让我看看main.py,因为这可能是主要的应用文件。
---
Read file: main.py
---
现在我需要查看templates目录中的admin.html文件,这可能包含网盘账号管理的前端代码。
---
Read file: templates/admin.html
---
让我继续查看admin.html文件的剩余部分,特别是关注网盘编辑的模态框:
---
Read file: templates/admin.html
---
让我继续查看JavaScript代码部分的后半部分,特别是关于编辑网盘账号的处理:
---
Read file: templates/admin.html
---
现在,我需要修改代码以实现当编辑网盘账号后保存时自动刷新网盘账号列表。我注意到在编辑模态框的保存事件处理中,已经有注释提到可以局部刷新表格内容,但没有实现。
让我编写一个函数来更新网盘账号列表,并在编辑成功后调用它:
---
```diff
editor.setValue(configJson, -1);
$('#editudriveModal').modal('hide');
- // 如果需要,可以在这里刷新页面或表格数据
- // 局部刷新表格内容
+ // 刷新网盘账号列表
+ refreshAccountsList();
} else {
showMessage('配置更新失败: ' + response.message, 'error');
}
});
+
+ // 刷新网盘账号列表函数
+ function refreshAccountsList() {
+ $.ajax({
+ url: '/admin/user_drive/get',
+ type: 'POST',
+ contentType: 'application/json',
+ data: JSON.stringify({}),
+ success: function(response) {
+ if (response.status && response.data) {
+ // 清空现有表格内容
+ const accountsTableBody = $('#accounts table tbody');
+ accountsTableBody.empty();
+
+ // 添加新的行
+ response.data.forEach(function(drive) {
+ const row = $('
');
+ row.append(`${drive.provider_name} | `);
+ row.append(`${drive.provider_name} | `);
+ row.append(`正常 | `);
+ row.append(`1.5TB / 2TB | `);
+ row.append(`
+
+
+
+ |
+ `);
+ accountsTableBody.append(row);
+ });
+
+ // 重新绑定编辑按钮事件
+ bindEditButtonEvents();
+ } else {
+ showMessage('获取网盘账号列表失败', 'error');
+ }
+ },
+ error: function(error) {
+ console.error('获取网盘账号列表出错:', error);
+ showMessage('获取网盘账号列表时发生错误', 'error');
+ }
+ });
+ }
+
+ // 绑定编辑按钮事件
+ function bindEditButtonEvents() {
+ document.querySelectorAll('.editudrivebtn').forEach(button => {
+ button.addEventListener('click', function() {
+ const editModalEditorArea = document.querySelector('#editudriveModal .json-editor-area');
+ const editorElement = editModalEditorArea.querySelector('.ace-editor');
+ const editor = ace.edit(editorElement); // Get the Ace editor instance
+ const selectedtid = this.getAttribute('tid');
+
+ if (selectedtid) {
+ // 获取最新的账号信息
+ $.ajax({
+ url: '/admin/user_drive/get',
+ type: 'POST',
+ contentType: 'application/json',
+ data: JSON.stringify({ id: selectedtid }),
+ success: function(response) {
+ if (response.status && response.data) {
+ let selectedUdrive = null;
+ // 查找匹配的用户驱动
+ if (Array.isArray(response.data)) {
+ selectedUdrive = response.data.find(drive => drive.id == selectedtid);
+ } else if (response.data.id == selectedtid) {
+ selectedUdrive = response.data;
+ }
+
+ if (selectedUdrive && selectedUdrive.login_config) {
+ let configData = selectedUdrive.login_config;
+ // 如果是字符串格式,解析为对象
+ if (typeof configData === 'string') {
+ try {
+ configData = JSON.parse(configData);
+ } catch (e) {
+ console.error('解析配置JSON失败:', e);
+ }
+ }
+ editor.setValue(JSON.stringify(configData, null, 2), -1);
+ } else {
+ const defaultJson = {
+ "provider_name": selectedtid,
+ "config": { "api_key": "", "secret_key": "", "redirect_uri": "" },
+ "auth": { "token": "", "expires_in": 0 }
+ };
+ editor.setValue(JSON.stringify(defaultJson, null, 2), -1);
+ }
+
+ // 存储选中的ID
+ document.querySelector('#editudriveModal #saveAccount').setAttribute('data-tid', selectedtid);
+ }
+ },
+ error: function(error) {
+ console.error('获取账号信息出错:', error);
+ showMessage('获取账号信息时发生错误', 'error');
+
+ // 使用默认值
+ const defaultJson = {
+ "provider_name": selectedtid,
+ "config": { "api_key": "", "secret_key": "", "redirect_uri": "" },
+ "auth": { "token": "", "expires_in": 0 }
+ };
+ editor.setValue(JSON.stringify(defaultJson, null, 2), -1);
+ document.querySelector('#editudriveModal #saveAccount').setAttribute('data-tid', selectedtid);
+ }
+ });
+ }
+ });
+ });
+ }