Add EasyCode front web app

This commit is contained in:
王鹏
2026-05-22 16:26:33 +08:00
parent ca3242915b
commit d39eeca8a9
24 changed files with 2821 additions and 0 deletions

View File

@@ -0,0 +1,123 @@
<template>
<header class="app-header">
<router-link class="brand" to="/">
<span class="brand-mark">EC</span>
<span>EasyCode</span>
</router-link>
<nav class="nav">
<router-link to="/">工作台</router-link>
<router-link to="/generate">生成项目</router-link>
</nav>
<div class="actions">
<template v-if="token">
<span class="user-name">{{ displayName }}</span>
<el-button :icon="SwitchButton" @click="handleLogout">退出</el-button>
</template>
<template v-else>
<el-button @click="router.push('/login')">登录</el-button>
<el-button type="primary" @click="router.push('/register')">注册</el-button>
</template>
</div>
</header>
</template>
<script setup>
import { computed } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { SwitchButton } from '@element-plus/icons-vue'
import { getToken, getUser, removeToken } from '@/utils/auth'
const router = useRouter()
const route = useRoute()
const token = computed(() => {
route.fullPath
return getToken()
})
const user = computed(() => {
route.fullPath
return getUser()
})
const displayName = computed(() => user.value?.nickName || user.value?.userName || '已登录')
function handleLogout() {
removeToken()
router.push('/')
}
</script>
<style scoped lang="scss">
.app-header {
position: sticky;
top: 0;
z-index: 10;
display: grid;
grid-template-columns: auto 1fr auto;
align-items: center;
gap: 28px;
height: 64px;
padding: 0 28px;
border-bottom: 1px solid #dfe5ee;
background: rgba(255, 255, 255, 0.94);
backdrop-filter: blur(12px);
}
.brand {
display: inline-flex;
align-items: center;
gap: 10px;
color: #111827;
font-size: 18px;
font-weight: 700;
}
.brand-mark {
display: inline-grid;
width: 34px;
height: 34px;
place-items: center;
border-radius: 8px;
color: #ffffff;
background: #2563eb;
font-size: 13px;
}
.nav {
display: flex;
align-items: center;
gap: 20px;
color: #4b5563;
font-size: 14px;
.router-link-active {
color: #1d4ed8;
font-weight: 700;
}
}
.actions {
display: flex;
align-items: center;
gap: 10px;
}
.user-name {
color: #475467;
font-size: 14px;
}
@media (max-width: 720px) {
.app-header {
grid-template-columns: 1fr auto;
height: auto;
min-height: 64px;
padding: 12px;
}
.nav {
order: 3;
grid-column: 1 / -1;
}
}
</style>

View File

@@ -0,0 +1,56 @@
<template>
<section class="code-preview">
<div class="preview-head">
<span>{{ fileName || '代码预览' }}</span>
</div>
<el-empty v-if="!code" description="请选择左侧文件查看代码" />
<pre v-else><code>{{ code }}</code></pre>
</section>
</template>
<script setup>
defineProps({
fileName: {
type: String,
default: ''
},
code: {
type: String,
default: ''
}
})
</script>
<style scoped lang="scss">
.code-preview {
display: grid;
grid-template-rows: auto 1fr;
min-height: 560px;
border-left: 1px solid #e3e8f0;
background: #0f172a;
}
.preview-head {
display: flex;
align-items: center;
min-height: 48px;
padding: 0 16px;
border-bottom: 1px solid #243044;
color: #dbe4f0;
font-weight: 700;
}
pre {
min-width: 0;
margin: 0;
padding: 18px;
overflow: auto;
color: #d8dee9;
font-size: 13px;
line-height: 1.7;
}
:deep(.el-empty__description p) {
color: #cbd5e1;
}
</style>

View File

@@ -0,0 +1,293 @@
<template>
<div class="designer">
<aside class="table-list">
<div class="list-head">
<strong>数据表</strong>
<el-button :icon="Plus" circle @click="addTable" />
</div>
<el-empty v-if="!tables.length" description="暂无表结构" :image-size="88" />
<button
v-for="(table, index) in tables"
v-else
:key="table.tableId || table.id || index"
class="table-item"
:class="{ active: selectedIndex === index }"
type="button"
@click="selectedIndex = index"
>
<span>{{ table.tableName || '未命名表' }}</span>
<small>{{ table.tableComment || '未填写备注' }}</small>
</button>
</aside>
<section class="table-editor">
<el-empty v-if="!currentTable" description="添加或选择一张数据表" />
<template v-else>
<div class="table-form">
<el-form label-position="top">
<el-row :gutter="16">
<el-col :xs="24" :md="10">
<el-form-item label="表名">
<el-input v-model="currentTable.tableName" placeholder="例如 sys_customer" />
</el-form-item>
</el-col>
<el-col :xs="24" :md="10">
<el-form-item label="备注">
<el-input v-model="currentTable.tableComment" placeholder="例如 客户信息表" />
</el-form-item>
</el-col>
<el-col :xs="24" :md="4" class="delete-col">
<el-button :icon="Delete" type="danger" plain @click="removeTable(selectedIndex)">
删除表
</el-button>
</el-col>
</el-row>
</el-form>
</div>
<div class="field-head">
<h3>字段设计</h3>
<el-button type="primary" :icon="Plus" @click="addField">添加字段</el-button>
</div>
<el-table :data="currentColumns" border>
<el-table-column label="字段名" min-width="160">
<template #default="{ row }">
<el-input v-model="row.columnName" placeholder="字段名" />
</template>
</el-table-column>
<el-table-column label="类型" width="160">
<template #default="{ row }">
<el-select v-model="row.columnType" placeholder="字段类型">
<el-option label="varchar(255)" value="varchar(255)" />
<el-option label="bigint(20)" value="bigint(20)" />
<el-option label="int(11)" value="int(11)" />
<el-option label="decimal(10,2)" value="decimal(10,2)" />
<el-option label="datetime" value="datetime" />
<el-option label="text" value="text" />
</el-select>
</template>
</el-table-column>
<el-table-column label="备注" min-width="180">
<template #default="{ row }">
<el-input v-model="row.columnComment" placeholder="字段备注" />
</template>
</el-table-column>
<el-table-column label="主键" width="90" align="center">
<template #default="{ row }">
<el-checkbox :model-value="row.isPk === '1'" @change="(checked) => row.isPk = checked ? '1' : '0'" />
</template>
</el-table-column>
<el-table-column label="必填" width="90" align="center">
<template #default="{ row }">
<el-checkbox :model-value="row.isRequired === '1'" @change="(checked) => row.isRequired = checked ? '1' : '0'" />
</template>
</el-table-column>
<el-table-column label="操作" width="90" align="center">
<template #default="{ $index }">
<el-button :icon="Delete" circle text type="danger" @click="removeField($index)" />
</template>
</el-table-column>
</el-table>
</template>
</section>
</div>
</template>
<script setup>
import { computed, ref, watch } from 'vue'
import { Delete, Plus } from '@element-plus/icons-vue'
const props = defineProps({
modelValue: {
type: Object,
default: () => ({ tables: [], sql: '' })
}
})
const emit = defineEmits(['update:modelValue'])
const selectedIndex = ref(0)
const database = computed({
get: () => props.modelValue,
set: (value) => emit('update:modelValue', value)
})
const tables = computed(() => database.value.tables || [])
const currentTable = computed(() => tables.value[selectedIndex.value])
const currentColumns = computed(() => {
if (!currentTable.value) return []
if (!Array.isArray(currentTable.value.columns)) {
currentTable.value.columns = []
}
return currentTable.value.columns
})
watch(
() => tables.value.length,
(length) => {
if (selectedIndex.value >= length) {
selectedIndex.value = Math.max(length - 1, 0)
}
}
)
function uid(prefix) {
return `${prefix}_${Date.now()}_${Math.random().toString(16).slice(2)}`
}
function updateTables(nextTables) {
database.value = { ...database.value, tables: nextTables }
}
function addTable() {
const nextTables = [
...tables.value,
{
id: uid('table'),
tableName: 'new_table',
tableComment: '新建数据表',
className: 'NewTable',
moduleName: 'system',
businessName: 'newTable',
functionName: '新建数据',
tplCategory: 'crud',
tplWebType: 'element-plus',
columns: [
{
id: uid('field'),
columnName: 'id',
columnType: 'bigint(20)',
columnComment: '主键',
javaType: 'Long',
javaField: 'id',
isPk: '1',
isIncrement: '1',
isRequired: '1',
isInsert: '1',
isEdit: '1',
isList: '1',
isQuery: '0',
queryType: 'EQ',
htmlType: 'input'
}
]
}
]
updateTables(nextTables)
selectedIndex.value = nextTables.length - 1
}
function removeTable(index) {
updateTables(tables.value.filter((_, itemIndex) => itemIndex !== index))
}
function addField() {
if (!currentTable.value) return
currentColumns.value.push({
id: uid('field'),
columnName: '',
columnType: 'varchar(255)',
columnComment: '',
javaType: 'String',
javaField: '',
isPk: '0',
isIncrement: '0',
isRequired: '0',
isInsert: '1',
isEdit: '1',
isList: '1',
isQuery: '0',
queryType: 'EQ',
htmlType: 'input'
})
}
function removeField(index) {
if (!currentTable.value) return
currentColumns.value.splice(index, 1)
}
</script>
<style scoped lang="scss">
.designer {
display: grid;
grid-template-columns: 260px 1fr;
min-height: 430px;
}
.table-list {
border-right: 1px solid #e3e8f0;
background: #f8fafc;
}
.list-head {
display: flex;
align-items: center;
justify-content: space-between;
padding: 16px;
border-bottom: 1px solid #e3e8f0;
}
.table-item {
display: flex;
width: calc(100% - 20px);
flex-direction: column;
gap: 5px;
margin: 10px;
padding: 12px;
border: 1px solid transparent;
border-radius: 8px;
color: #344054;
background: transparent;
text-align: left;
cursor: pointer;
span {
font-weight: 700;
}
small {
color: #667085;
}
&.active {
border-color: #9bbcf5;
background: #eef5ff;
color: #1d4ed8;
}
}
.table-editor {
min-width: 0;
padding: 18px;
}
.delete-col {
display: flex;
align-items: end;
}
.field-head {
display: flex;
align-items: center;
justify-content: space-between;
margin: 4px 0 14px;
h3 {
margin: 0;
font-size: 16px;
}
}
@media (max-width: 860px) {
.designer {
grid-template-columns: 1fr;
}
.table-list {
border-right: 0;
border-bottom: 1px solid #e3e8f0;
}
}
</style>

View File

@@ -0,0 +1,59 @@
<template>
<el-tree
class="structure-tree"
:data="data"
:props="{ label: 'label', children: 'children' }"
node-key="id"
default-expand-all
highlight-current
@node-click="handleNodeClick"
>
<template #default="{ node, data: nodeData }">
<span class="tree-node">
<el-icon>
<Document v-if="isFile(nodeData)" />
<Folder v-else />
</el-icon>
<span>{{ node.label }}</span>
</span>
</template>
</el-tree>
</template>
<script setup>
import { Document, Folder } from '@element-plus/icons-vue'
defineProps({
data: {
type: Array,
default: () => []
}
})
const emit = defineEmits(['file-select'])
function isFile(node) {
if (node?.type === 'folder' || node?.type === 'directory') return false
if (node?.type === 'file' || node?.isFile) return true
return !node?.children?.length
}
function handleNodeClick(node) {
if (isFile(node)) {
emit('file-select', node)
}
}
</script>
<style scoped lang="scss">
.structure-tree {
min-width: 220px;
}
.tree-node {
display: inline-flex;
align-items: center;
gap: 8px;
min-width: 0;
}
</style>