feat: 初始化考培练系统项目

- 从服务器拉取完整代码
- 按框架规范整理项目结构
- 配置 Drone CI 测试环境部署
- 包含后端(FastAPI)、前端(Vue3)、管理端

技术栈: Vue3 + TypeScript + FastAPI + MySQL
This commit is contained in:
111
2026-01-24 19:33:28 +08:00
commit 998211c483
1197 changed files with 228429 additions and 0 deletions

View File

@@ -0,0 +1,142 @@
<template>
<div class="tenant-configs" v-loading="loading">
<el-card shadow="hover">
<template #header>
<div class="card-header">
<span>租户配置 - {{ tenantName }}</span>
<div>
<el-button @click="$router.back()">返回</el-button>
<el-button type="primary" @click="handleSaveAll" :loading="saving">保存全部</el-button>
</div>
</div>
</template>
<el-tabs v-model="activeTab" type="border-card">
<el-tab-pane
v-for="group in configGroups"
:key="group.group_name"
:label="group.group_display_name"
:name="group.group_name"
>
<el-form label-width="180px">
<el-form-item
v-for="config in group.configs"
:key="config.config_key"
:label="config.display_name || config.config_key"
>
<template v-if="config.is_secret">
<el-input
v-model="configValues[`${config.config_group}.${config.config_key}`]"
type="password"
show-password
:placeholder="config.description"
style="width: 400px;"
/>
</template>
<template v-else>
<el-input
v-model="configValues[`${config.config_group}.${config.config_key}`]"
:placeholder="config.description"
style="width: 400px;"
/>
</template>
<span class="config-desc" v-if="config.description">{{ config.description }}</span>
</el-form-item>
</el-form>
</el-tab-pane>
</el-tabs>
</el-card>
</div>
</template>
<script setup>
import { ref, reactive, onMounted } from 'vue'
import { useRoute } from 'vue-router'
import { ElMessage } from 'element-plus'
import api from '@/api'
const route = useRoute()
const tenantId = route.params.id
const loading = ref(false)
const saving = ref(false)
const tenantName = ref('')
const activeTab = ref('database')
const configGroups = ref([])
const configValues = reactive({})
async function fetchConfigs() {
loading.value = true
try {
// 获取租户信息
const tenant = await api.tenants.get(tenantId)
tenantName.value = tenant.name
// 获取配置
const groups = await api.configs.getTenantConfigs(tenantId)
configGroups.value = groups
// 填充配置值
for (const group of groups) {
for (const config of group.configs) {
const key = `${config.config_group}.${config.config_key}`
configValues[key] = config.config_value || ''
}
}
} finally {
loading.value = false
}
}
async function handleSaveAll() {
saving.value = true
try {
const configs = []
for (const group of configGroups.value) {
for (const config of group.configs) {
const key = `${config.config_group}.${config.config_key}`
const value = configValues[key]
// 只保存有值的配置
if (value) {
configs.push({
config_group: config.config_group,
config_key: config.config_key,
config_value: value
})
}
}
}
await api.configs.batchUpdate(tenantId, { configs })
ElMessage.success('配置保存成功')
// 刷新缓存
await api.configs.refreshCache(tenantId)
} finally {
saving.value = false
}
}
onMounted(() => {
fetchConfigs()
})
</script>
<style lang="scss" scoped>
.tenant-configs {
.card-header {
display: flex;
justify-content: space-between;
align-items: center;
}
.config-desc {
font-size: 12px;
color: #999;
margin-left: 12px;
}
}
</style>

View File

@@ -0,0 +1,217 @@
<template>
<div class="tenant-detail" v-loading="loading">
<el-card shadow="hover">
<template #header>
<div class="card-header">
<span>租户详情</span>
<div>
<el-button @click="$router.back()">返回</el-button>
<el-button type="primary" @click="isEditing = !isEditing">
{{ isEditing ? '取消编辑' : '编辑' }}
</el-button>
</div>
</div>
</template>
<el-form
ref="formRef"
:model="form"
:rules="rules"
label-width="120px"
:disabled="!isEditing"
>
<el-row :gutter="20">
<el-col :span="12">
<el-form-item label="租户编码">
<el-input v-model="form.code" disabled />
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="状态">
<el-tag :type="form.status === 'active' ? 'success' : 'danger'">
{{ form.status === 'active' ? '启用' : '禁用' }}
</el-tag>
</el-form-item>
</el-col>
</el-row>
<el-row :gutter="20">
<el-col :span="12">
<el-form-item label="租户名称" prop="name">
<el-input v-model="form.name" />
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="显示名称" prop="display_name">
<el-input v-model="form.display_name" />
</el-form-item>
</el-col>
</el-row>
<el-row :gutter="20">
<el-col :span="12">
<el-form-item label="域名" prop="domain">
<el-input v-model="form.domain" />
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="行业" prop="industry">
<el-select v-model="form.industry" style="width: 100%;">
<el-option label="轻医美" value="medical_beauty" />
<el-option label="宠物" value="pet" />
<el-option label="教育" value="education" />
<el-option label="其他" value="other" />
</el-select>
</el-form-item>
</el-col>
</el-row>
<el-row :gutter="20">
<el-col :span="12">
<el-form-item label="联系人" prop="contact_name">
<el-input v-model="form.contact_name" />
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="联系电话" prop="contact_phone">
<el-input v-model="form.contact_phone" />
</el-form-item>
</el-col>
</el-row>
<el-row :gutter="20">
<el-col :span="12">
<el-form-item label="联系邮箱" prop="contact_email">
<el-input v-model="form.contact_email" />
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="服务到期">
<el-date-picker v-model="form.expire_at" type="date" style="width: 100%;" />
</el-form-item>
</el-col>
</el-row>
<el-form-item label="备注" prop="remarks">
<el-input v-model="form.remarks" type="textarea" :rows="3" />
</el-form-item>
<el-form-item v-if="isEditing">
<el-button type="primary" :loading="submitting" @click="handleSave">保存</el-button>
</el-form-item>
</el-form>
</el-card>
<!-- 快捷操作 -->
<el-card shadow="hover" style="margin-top: 20px;">
<template #header>
<span>快捷操作</span>
</template>
<div class="quick-actions">
<el-button @click="$router.push(`/tenants/${tenantId}/configs`)">
<el-icon><Setting /></el-icon>
配置管理
</el-button>
<el-button @click="$router.push(`/tenants/${tenantId}/features`)">
<el-icon><Switch /></el-icon>
功能开关
</el-button>
</div>
</el-card>
</div>
</template>
<script setup>
import { ref, reactive, onMounted } from 'vue'
import { useRoute } from 'vue-router'
import { ElMessage } from 'element-plus'
import { Setting, Switch } from '@element-plus/icons-vue'
import api from '@/api'
const route = useRoute()
const tenantId = route.params.id
const loading = ref(false)
const isEditing = ref(false)
const submitting = ref(false)
const formRef = ref()
const form = reactive({
code: '',
name: '',
display_name: '',
domain: '',
industry: '',
contact_name: '',
contact_phone: '',
contact_email: '',
expire_at: null,
remarks: '',
status: ''
})
const rules = {
name: [{ required: true, message: '请输入租户名称', trigger: 'blur' }],
domain: [{ required: true, message: '请输入域名', trigger: 'blur' }]
}
async function fetchTenant() {
loading.value = true
try {
const res = await api.tenants.get(tenantId)
Object.assign(form, res)
} finally {
loading.value = false
}
}
async function handleSave() {
await formRef.value.validate()
submitting.value = true
try {
await api.tenants.update(tenantId, {
name: form.name,
display_name: form.display_name,
domain: form.domain,
industry: form.industry,
contact_name: form.contact_name,
contact_phone: form.contact_phone,
contact_email: form.contact_email,
expire_at: form.expire_at,
remarks: form.remarks
})
ElMessage.success('保存成功')
isEditing.value = false
} finally {
submitting.value = false
}
}
onMounted(() => {
fetchTenant()
})
</script>
<style lang="scss" scoped>
.tenant-detail {
.card-header {
display: flex;
justify-content: space-between;
align-items: center;
}
.quick-actions {
display: flex;
gap: 12px;
.el-button {
display: flex;
align-items: center;
gap: 8px;
}
}
}
</style>

View File

@@ -0,0 +1,129 @@
<template>
<div class="tenant-features" v-loading="loading">
<el-card shadow="hover">
<template #header>
<div class="card-header">
<span>功能开关 - {{ tenantName }}</span>
<el-button @click="$router.back()">返回</el-button>
</div>
</template>
<div v-for="group in featureGroups" :key="group.group_name" class="feature-group">
<h3>{{ group.group_display_name }}</h3>
<el-table :data="group.features" style="width: 100%;">
<el-table-column prop="feature_name" label="功能名称" width="200" />
<el-table-column prop="description" label="说明" />
<el-table-column label="状态" width="120">
<template #default="{ row }">
<el-switch
v-model="row.is_enabled"
@change="handleToggle(row)"
/>
</template>
</el-table-column>
<el-table-column label="操作" width="100">
<template #default="{ row }">
<el-button
type="primary"
link
@click="handleReset(row)"
v-if="row.tenant_id"
>
重置
</el-button>
<span v-else class="default-label">默认</span>
</template>
</el-table-column>
</el-table>
</div>
</el-card>
</div>
</template>
<script setup>
import { ref, onMounted } from 'vue'
import { useRoute } from 'vue-router'
import { ElMessage, ElMessageBox } from 'element-plus'
import api from '@/api'
const route = useRoute()
const tenantId = route.params.id
const loading = ref(false)
const tenantName = ref('')
const featureGroups = ref([])
async function fetchFeatures() {
loading.value = true
try {
// 获取租户信息
const tenant = await api.tenants.get(tenantId)
tenantName.value = tenant.name
// 获取功能开关
const groups = await api.features.getTenantFeatures(tenantId)
featureGroups.value = groups
} finally {
loading.value = false
}
}
async function handleToggle(feature) {
try {
await api.features.updateFeature(tenantId, feature.feature_code, {
is_enabled: feature.is_enabled
})
ElMessage.success(feature.is_enabled ? '功能已启用' : '功能已禁用')
} catch (e) {
// 回滚状态
feature.is_enabled = !feature.is_enabled
}
}
async function handleReset(feature) {
await ElMessageBox.confirm('确定要重置为默认配置吗?', '提示', {
type: 'warning'
})
try {
await api.features.resetFeature(tenantId, feature.feature_code)
ElMessage.success('已重置为默认配置')
fetchFeatures()
} catch (e) {
// 错误已在拦截器处理
}
}
onMounted(() => {
fetchFeatures()
})
</script>
<style lang="scss" scoped>
.tenant-features {
.card-header {
display: flex;
justify-content: space-between;
align-items: center;
}
.feature-group {
margin-bottom: 30px;
h3 {
font-size: 16px;
color: #333;
margin-bottom: 16px;
padding-bottom: 8px;
border-bottom: 1px solid #eee;
}
}
.default-label {
color: #999;
font-size: 12px;
}
}
</style>

View File

@@ -0,0 +1,250 @@
<template>
<div class="tenant-list">
<el-card shadow="hover">
<template #header>
<div class="card-header">
<span>租户管理</span>
<el-button type="primary" @click="showCreateDialog">
<el-icon><Plus /></el-icon> 新建租户
</el-button>
</div>
</template>
<div class="filter-bar">
<el-input
v-model="keyword"
placeholder="搜索租户名称/编码/域名"
style="width: 300px;"
clearable
@keyup.enter="fetchTenants"
>
<template #prefix>
<el-icon><Search /></el-icon>
</template>
</el-input>
<el-select v-model="statusFilter" placeholder="状态" clearable style="width: 120px;">
<el-option label="启用" value="active" />
<el-option label="禁用" value="inactive" />
</el-select>
<el-button type="primary" @click="fetchTenants">查询</el-button>
</div>
<el-table :data="tenants" v-loading="loading" style="width: 100%;">
<el-table-column prop="code" label="编码" width="100" />
<el-table-column prop="name" label="名称" width="150" />
<el-table-column prop="domain" label="域名" />
<el-table-column prop="industry" label="行业" width="120">
<template #default="{ row }">
{{ getIndustryLabel(row.industry) }}
</template>
</el-table-column>
<el-table-column prop="status" label="状态" width="100">
<template #default="{ row }">
<el-tag :type="row.status === 'active' ? 'success' : 'danger'" size="small">
{{ row.status === 'active' ? '启用' : '禁用' }}
</el-tag>
</template>
</el-table-column>
<el-table-column prop="config_count" label="配置项" width="80" />
<el-table-column label="操作" width="280" fixed="right">
<template #default="{ row }">
<el-button type="primary" link @click="$router.push(`/tenants/${row.id}`)">详情</el-button>
<el-button type="primary" link @click="$router.push(`/tenants/${row.id}/configs`)">配置</el-button>
<el-button type="primary" link @click="$router.push(`/tenants/${row.id}/features`)">功能</el-button>
<el-button
:type="row.status === 'active' ? 'warning' : 'success'"
link
@click="toggleStatus(row)"
>
{{ row.status === 'active' ? '禁用' : '启用' }}
</el-button>
</template>
</el-table-column>
</el-table>
<div class="pagination">
<el-pagination
v-model:current-page="page"
v-model:page-size="pageSize"
:total="total"
:page-sizes="[10, 20, 50]"
layout="total, sizes, prev, pager, next"
@size-change="fetchTenants"
@current-change="fetchTenants"
/>
</div>
</el-card>
<!-- 新建租户对话框 -->
<el-dialog v-model="createDialogVisible" title="新建租户" width="500px">
<el-form ref="formRef" :model="form" :rules="rules" label-width="100px">
<el-form-item label="租户编码" prop="code">
<el-input v-model="form.code" placeholder="英文小写hua" />
</el-form-item>
<el-form-item label="租户名称" prop="name">
<el-input v-model="form.name" placeholder="如:华尔倍丽" />
</el-form-item>
<el-form-item label="域名" prop="domain">
<el-input v-model="form.domain" placeholder="如hua.ireborn.com.cn" />
</el-form-item>
<el-form-item label="行业" prop="industry">
<el-select v-model="form.industry" style="width: 100%;">
<el-option label="轻医美" value="medical_beauty" />
<el-option label="宠物" value="pet" />
<el-option label="教育" value="education" />
<el-option label="其他" value="other" />
</el-select>
</el-form-item>
<el-form-item label="联系人" prop="contact_name">
<el-input v-model="form.contact_name" />
</el-form-item>
<el-form-item label="联系电话" prop="contact_phone">
<el-input v-model="form.contact_phone" />
</el-form-item>
</el-form>
<template #footer>
<el-button @click="createDialogVisible = false">取消</el-button>
<el-button type="primary" :loading="submitting" @click="handleCreate">创建</el-button>
</template>
</el-dialog>
</div>
</template>
<script setup>
import { ref, reactive, onMounted } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import { Plus, Search } from '@element-plus/icons-vue'
import api from '@/api'
const loading = ref(false)
const tenants = ref([])
const page = ref(1)
const pageSize = ref(20)
const total = ref(0)
const keyword = ref('')
const statusFilter = ref('')
const createDialogVisible = ref(false)
const submitting = ref(false)
const formRef = ref()
const form = reactive({
code: '',
name: '',
domain: '',
industry: 'medical_beauty',
contact_name: '',
contact_phone: ''
})
const rules = {
code: [
{ required: true, message: '请输入租户编码', trigger: 'blur' },
{ pattern: /^[a-z0-9_]+$/, message: '只能包含小写字母、数字和下划线', trigger: 'blur' }
],
name: [{ required: true, message: '请输入租户名称', trigger: 'blur' }],
domain: [{ required: true, message: '请输入域名', trigger: 'blur' }],
industry: [{ required: true, message: '请选择行业', trigger: 'change' }]
}
function getIndustryLabel(industry) {
const map = {
medical_beauty: '轻医美',
pet: '宠物',
education: '教育',
other: '其他'
}
return map[industry] || industry
}
async function fetchTenants() {
loading.value = true
try {
const res = await api.tenants.list({
page: page.value,
page_size: pageSize.value,
keyword: keyword.value || undefined,
status: statusFilter.value || undefined
})
tenants.value = res.items
total.value = res.total
} finally {
loading.value = false
}
}
function showCreateDialog() {
Object.assign(form, {
code: '',
name: '',
domain: '',
industry: 'medical_beauty',
contact_name: '',
contact_phone: ''
})
createDialogVisible.value = true
}
async function handleCreate() {
await formRef.value.validate()
submitting.value = true
try {
await api.tenants.create(form)
ElMessage.success('租户创建成功')
createDialogVisible.value = false
fetchTenants()
} finally {
submitting.value = false
}
}
async function toggleStatus(tenant) {
const action = tenant.status === 'active' ? '禁用' : '启用'
await ElMessageBox.confirm(`确定要${action}租户 ${tenant.name} 吗?`, '提示', {
type: 'warning'
})
try {
if (tenant.status === 'active') {
await api.tenants.disable(tenant.id)
} else {
await api.tenants.enable(tenant.id)
}
ElMessage.success(`${action}成功`)
fetchTenants()
} catch (e) {
// 错误已在拦截器处理
}
}
onMounted(() => {
fetchTenants()
})
</script>
<style lang="scss" scoped>
.tenant-list {
.card-header {
display: flex;
justify-content: space-between;
align-items: center;
}
.filter-bar {
display: flex;
gap: 12px;
margin-bottom: 20px;
}
.pagination {
margin-top: 20px;
display: flex;
justify-content: flex-end;
}
}
</style>