🚨 Format code

This commit is contained in:
2025-09-24 21:44:42 +08:00
parent 1462d8a753
commit f5bfff80b7
76 changed files with 839 additions and 863 deletions

View File

@@ -288,11 +288,6 @@ const updateSystemTheme = async (event: Event) => {
// 控制颜色选择器显示状态
const showPickerMap = ref<Record<string, boolean>>({});
// 切换颜色选择器显示状态
const toggleColorPicker = (colorKey: string) => {
showPickerMap.value[colorKey] = !showPickerMap.value[colorKey];
};
// 颜色变更处理
const handleColorChange = (colorKey: string, value: string) => {
updateColor(colorKey, value);

View File

@@ -21,7 +21,7 @@ onMounted(async () => {
});
onUnmounted(() => {
backupStore.clearError();
})
});
// 认证方式选项
const authMethodOptions = computed(() => [

View File

@@ -1,33 +1,32 @@
<script setup lang="ts">
import {computed, ref} from 'vue'
import {useI18n} from 'vue-i18n'
import {useEditorStore} from '@/stores/editorStore'
import {useExtensionStore} from '@/stores/extensionStore'
import {ExtensionService} from '@/../bindings/voidraft/internal/services'
import {ExtensionID} from '@/../bindings/voidraft/internal/models/models'
import {getExtensionManager} from '@/views/editor/manager'
import {computed, ref} from 'vue';
import {useI18n} from 'vue-i18n';
import {useEditorStore} from '@/stores/editorStore';
import {useExtensionStore} from '@/stores/extensionStore';
import {ExtensionService} from '@/../bindings/voidraft/internal/services';
import {ExtensionID} from '@/../bindings/voidraft/internal/models/models';
import {
getAllExtensionIds,
getExtensionDefaultConfig,
getExtensionDescription,
getExtensionDisplayName,
hasExtensionConfig
} from '@/views/editor/manager/factories'
import SettingSection from '../components/SettingSection.vue'
import SettingItem from '../components/SettingItem.vue'
import ToggleSwitch from '../components/ToggleSwitch.vue'
} from '@/views/editor/manager/factories';
import SettingSection from '../components/SettingSection.vue';
import SettingItem from '../components/SettingItem.vue';
import ToggleSwitch from '../components/ToggleSwitch.vue';
const {t} = useI18n()
const editorStore = useEditorStore()
const extensionStore = useExtensionStore()
const {t} = useI18n();
const editorStore = useEditorStore();
const extensionStore = useExtensionStore();
// 展开状态管理
const expandedExtensions = ref<Set<ExtensionID>>(new Set())
const expandedExtensions = ref<Set<ExtensionID>>(new Set());
// 获取所有可用的扩展
const availableExtensions = computed(() => {
return getAllExtensionIds().map(id => {
const extension = extensionStore.extensions.find(ext => ext.id === id)
const extension = extensionStore.extensions.find(ext => ext.id === id);
return {
id,
displayName: getExtensionDisplayName(id),
@@ -37,68 +36,68 @@ const availableExtensions = computed(() => {
hasConfig: hasExtensionConfig(id),
config: extension?.config || {},
defaultConfig: getExtensionDefaultConfig(id)
}
})
})
};
});
});
// 切换展开状态
const toggleExpanded = (extensionId: ExtensionID) => {
if (expandedExtensions.value.has(extensionId)) {
expandedExtensions.value.delete(extensionId)
expandedExtensions.value.delete(extensionId);
} else {
expandedExtensions.value.add(extensionId)
expandedExtensions.value.add(extensionId);
}
}
};
// 更新扩展状态
const updateExtension = async (extensionId: ExtensionID, enabled: boolean) => {
try {
await editorStore.updateExtension(extensionId, enabled)
await editorStore.updateExtension(extensionId, enabled);
} catch (error) {
console.error('Failed to update extension:', error)
console.error('Failed to update extension:', error);
}
}
};
// 更新扩展配置
const updateExtensionConfig = async (extensionId: ExtensionID, configKey: string, value: any) => {
try {
// 获取当前扩展状态
const extension = extensionStore.extensions.find(ext => ext.id === extensionId)
if (!extension) return
const extension = extensionStore.extensions.find(ext => ext.id === extensionId);
if (!extension) return;
// 更新配置
const updatedConfig = {...extension.config, [configKey]: value}
const updatedConfig = {...extension.config, [configKey]: value};
console.log(`[ExtensionsPage] 更新扩展 ${extensionId} 配置, ${configKey}=${value}`)
console.log(`[ExtensionsPage] 更新扩展 ${extensionId} 配置, ${configKey}=${value}`);
// 使用editorStore的updateExtension方法更新确保应用到所有编辑器实例
await editorStore.updateExtension(extensionId, extension.enabled, updatedConfig)
await editorStore.updateExtension(extensionId, extension.enabled, updatedConfig);
} catch (error) {
console.error('Failed to update extension config:', error)
console.error('Failed to update extension config:', error);
}
}
};
// 重置扩展到默认配置
const resetExtension = async (extensionId: ExtensionID) => {
try {
// 重置到默认配置(后端)
await ExtensionService.ResetExtensionToDefault(extensionId)
await ExtensionService.ResetExtensionToDefault(extensionId);
// 重新加载扩展状态以获取最新配置
await extensionStore.loadExtensions()
await extensionStore.loadExtensions();
// 获取重置后的状态,立即应用到所有编辑器视图
const extension = extensionStore.extensions.find(ext => ext.id === extensionId)
const extension = extensionStore.extensions.find(ext => ext.id === extensionId);
if (extension) {
// 通过editorStore更新确保所有视图都能同步
await editorStore.updateExtension(extensionId, extension.enabled, extension.config)
console.log(`[ExtensionsPage] 重置扩展 ${extensionId} 配置,同步应用到所有编辑器实例`)
await editorStore.updateExtension(extensionId, extension.enabled, extension.config);
console.log(`[ExtensionsPage] 重置扩展 ${extensionId} 配置,同步应用到所有编辑器实例`);
}
} catch (error) {
console.error('Failed to reset extension:', error)
console.error('Failed to reset extension:', error);
}
}
};
// 配置项类型定义
type ConfigItemType = 'toggle' | 'number' | 'text' | 'select'
@@ -131,25 +130,25 @@ const extensionConfigMeta: Partial<Record<ExtensionID, Record<string, ConfigItem
]
}
}
}
};
// 获取配置项类型
const getConfigItemType = (extensionId: ExtensionID, configKey: string, defaultValue: any): string => {
const meta = extensionConfigMeta[extensionId]?.[configKey]
const meta = extensionConfigMeta[extensionId]?.[configKey];
if (meta?.type) {
return meta.type
return meta.type;
}
// 根据默认值类型自动推断
if (typeof defaultValue === 'boolean') return 'toggle'
if (typeof defaultValue === 'number') return 'number'
return 'text'
}
if (typeof defaultValue === 'boolean') return 'toggle';
if (typeof defaultValue === 'number') return 'number';
return 'text';
};
// 获取选择框的选项列表
const getSelectOptions = (extensionId: ExtensionID, configKey: string): SelectOption[] => {
return extensionConfigMeta[extensionId]?.[configKey]?.options || []
}
return extensionConfigMeta[extensionId]?.[configKey]?.options || [];
};
</script>
<template>

View File

@@ -62,7 +62,7 @@ const startPolling = () => {
const delay = status === MigrationStatus.MigrationStatusCompleted ? 3000 : 5000;
hideProgressTimer = setTimeout(hideProgress, delay);
}
} catch (error) {
} catch (_error) {
stopPolling();
// 使用常量简化错误处理

View File

@@ -87,52 +87,52 @@
</template>
<script setup lang="ts">
import { ref } from 'vue'
import * as TestService from '@/../bindings/voidraft/internal/services/testservice'
import SettingSection from '../components/SettingSection.vue'
import SettingItem from '../components/SettingItem.vue'
import { ref } from 'vue';
import * as TestService from '@/../bindings/voidraft/internal/services/testservice';
import SettingSection from '../components/SettingSection.vue';
import SettingItem from '../components/SettingItem.vue';
// Badge测试状态
const badgeText = ref('')
const badgeStatus = ref<{ type: string; message: string } | null>(null)
const badgeText = ref('');
const badgeStatus = ref<{ type: string; message: string } | null>(null);
// 通知测试状态
const notificationTitle = ref('')
const notificationSubtitle = ref('')
const notificationBody = ref('')
const notificationStatus = ref<{ type: string; message: string } | null>(null)
const notificationTitle = ref('');
const notificationSubtitle = ref('');
const notificationBody = ref('');
const notificationStatus = ref<{ type: string; message: string } | null>(null);
// 清除状态
const clearStatus = ref<{ type: string; message: string } | null>(null)
const clearStatus = ref<{ type: string; message: string } | null>(null);
// 显示状态消息的辅助函数
const showStatus = (statusRef: any, type: 'success' | 'error', message: string) => {
statusRef.value = { type, message }
statusRef.value = { type, message };
setTimeout(() => {
statusRef.value = null
}, 5000)
}
statusRef.value = null;
}, 5000);
};
// 测试Badge功能
const testBadge = async () => {
try {
await TestService.TestBadge(badgeText.value)
showStatus(badgeStatus, 'success', `Badge ${badgeText.value ? 'set to: ' + badgeText.value : 'cleared'} successfully`)
await TestService.TestBadge(badgeText.value);
showStatus(badgeStatus, 'success', `Badge ${badgeText.value ? 'set to: ' + badgeText.value : 'cleared'} successfully`);
} catch (error: any) {
showStatus(badgeStatus, 'error', `Failed to set badge: ${error.message || error}`)
showStatus(badgeStatus, 'error', `Failed to set badge: ${error.message || error}`);
}
}
};
// 清除Badge
const clearBadge = async () => {
try {
await TestService.TestBadge('')
badgeText.value = ''
showStatus(badgeStatus, 'success', 'Badge cleared successfully')
await TestService.TestBadge('');
badgeText.value = '';
showStatus(badgeStatus, 'success', 'Badge cleared successfully');
} catch (error: any) {
showStatus(badgeStatus, 'error', `Failed to clear badge: ${error.message || error}`)
showStatus(badgeStatus, 'error', `Failed to clear badge: ${error.message || error}`);
}
}
};
// 测试通知功能
const testNotification = async () => {
@@ -141,37 +141,37 @@ const testNotification = async () => {
notificationTitle.value,
notificationSubtitle.value,
notificationBody.value
)
showStatus(notificationStatus, 'success', 'Notification sent successfully')
);
showStatus(notificationStatus, 'success', 'Notification sent successfully');
} catch (error: any) {
showStatus(notificationStatus, 'error', `Failed to send notification: ${error.message || error}`)
showStatus(notificationStatus, 'error', `Failed to send notification: ${error.message || error}`);
}
}
};
// 测试更新通知
const testUpdateNotification = async () => {
try {
await TestService.TestUpdateNotification()
showStatus(notificationStatus, 'success', 'Update notification sent successfully (badge + notification)')
await TestService.TestUpdateNotification();
showStatus(notificationStatus, 'success', 'Update notification sent successfully (badge + notification)');
} catch (error: any) {
showStatus(notificationStatus, 'error', `Failed to send update notification: ${error.message || error}`)
showStatus(notificationStatus, 'error', `Failed to send update notification: ${error.message || error}`);
}
}
};
// 清除所有测试状态
const clearAll = async () => {
try {
await TestService.ClearAll()
await TestService.ClearAll();
// 清空表单
badgeText.value = ''
notificationTitle.value = ''
notificationSubtitle.value = ''
notificationBody.value = ''
showStatus(clearStatus, 'success', 'All test states cleared successfully')
badgeText.value = '';
notificationTitle.value = '';
notificationSubtitle.value = '';
notificationBody.value = '';
showStatus(clearStatus, 'success', 'All test states cleared successfully');
} catch (error: any) {
showStatus(clearStatus, 'error', `Failed to clear test states: ${error.message || error}`)
showStatus(clearStatus, 'error', `Failed to clear test states: ${error.message || error}`);
}
}
};
</script>
<style scoped lang="scss">

View File

@@ -1,6 +1,6 @@
<script setup lang="ts">
import {useI18n} from 'vue-i18n';
import {computed, onMounted, ref} from 'vue';
import {computed} from 'vue';
import {useConfigStore} from '@/stores/configStore';
import {useUpdateStore} from '@/stores/updateStore';
import SettingSection from '../components/SettingSection.vue';