feat(system): 实现注册码功能并优化用户注册流程
- 新增注册码生成和验证功能- 实现系统设置管理,包括注册功能开关 - 更新前端界面,增加系统管理和注册码相关功能 - 修改数据库结构,添加系统设置和注册码表
This commit is contained in:
@@ -88,6 +88,7 @@
|
||||
<div v-if="userStore.isLoggedIn" class="user-actions">
|
||||
<span class="welcome-text">欢迎, {{ userStore.userInfo?.username }}</span>
|
||||
<el-button type="danger" @click="handleLogout">退出</el-button>
|
||||
<el-button type="warning" @click="showSystemSettingsDialog = true">系统管理</el-button>
|
||||
<el-button type="primary" @click="showCreateNoteDialog = true">新建笔记</el-button>
|
||||
<el-upload
|
||||
class="upload-btn"
|
||||
@@ -203,6 +204,28 @@
|
||||
<el-button type="primary" @click="handleMoveNote">确定</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
|
||||
<!-- 系统管理对话框 -->
|
||||
<el-dialog v-model="showSystemSettingsDialog" title="系统管理" width="500px">
|
||||
<el-form label-width="120px">
|
||||
<el-form-item label="开放注册">
|
||||
<el-switch v-model="isRegistrationEnabled" @change="handleToggleRegistration"></el-switch>
|
||||
</el-form-item>
|
||||
<el-form-item label="生成注册码">
|
||||
<el-button type="primary" @click="handleGenerateCode">生成</el-button>
|
||||
</el-form-item>
|
||||
<el-form-item v-if="generatedCode" label="新注册码">
|
||||
<el-input v-model="generatedCode" readonly>
|
||||
<template #append>
|
||||
<el-button @click="copyToClipboard(generatedCode)">复制</el-button>
|
||||
</template>
|
||||
</el-input>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="showSystemSettingsDialog = false">关闭</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</el-main>
|
||||
</el-container>
|
||||
</el-container>
|
||||
@@ -225,7 +248,10 @@ import {
|
||||
updateMarkdownTitle,
|
||||
deleteGrouping as apiDeleteGrouping,
|
||||
getRecentFiles,
|
||||
validateToken
|
||||
validateToken,
|
||||
getRegistrationStatus,
|
||||
toggleRegistration,
|
||||
generateRegistrationCode
|
||||
} from '@/api/CommonApi.js'
|
||||
import { Plus, Fold, Expand, Folder, Document, Search, Edit, Delete, ArrowDown, Clock } from "@element-plus/icons-vue";
|
||||
import { useUserStore } from '../stores/user';
|
||||
@@ -253,6 +279,9 @@ const fileToImport = ref(null);
|
||||
const showMoveNoteDialog = ref(false);
|
||||
const moveToGroupId = ref(null);
|
||||
const currentGroupName = ref('');
|
||||
const showSystemSettingsDialog = ref(false);
|
||||
const isRegistrationEnabled = ref(true);
|
||||
const generatedCode = ref('');
|
||||
|
||||
const groupFormRef = ref(null);
|
||||
const newGroupForm = ref({ name: '', parentId: null });
|
||||
@@ -921,6 +950,44 @@ watch(activeMenu, (newVal) => {
|
||||
resetToHomeView();
|
||||
}
|
||||
});
|
||||
|
||||
const handleToggleRegistration = async (value) => {
|
||||
try {
|
||||
await toggleRegistration(value);
|
||||
ElMessage.success(`注册功能已${value ? '开启' : '关闭'}`);
|
||||
} catch (error) {
|
||||
ElMessage.error('操作失败');
|
||||
isRegistrationEnabled.value = !value; // revert
|
||||
}
|
||||
};
|
||||
|
||||
const handleGenerateCode = async () => {
|
||||
try {
|
||||
const response = await generateRegistrationCode();
|
||||
generatedCode.value = response.data;
|
||||
ElMessage.success('注册码生成成功');
|
||||
} catch (error) {
|
||||
ElMessage.error('生成注册码失败');
|
||||
}
|
||||
};
|
||||
|
||||
const copyToClipboard = (text) => {
|
||||
navigator.clipboard.writeText(text).then(() => {
|
||||
ElMessage.success('已复制到剪贴板');
|
||||
}, () => {
|
||||
ElMessage.error('复制失败');
|
||||
});
|
||||
};
|
||||
|
||||
onMounted(async () => {
|
||||
// ... existing onMounted logic
|
||||
try {
|
||||
const response = await getRegistrationStatus();
|
||||
isRegistrationEnabled.value = response.data;
|
||||
} catch (error) {
|
||||
console.error("Failed to fetch registration status:", error);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<style>
|
||||
|
||||
Reference in New Issue
Block a user