开始尝试进行业务化模板

This commit is contained in:
2025-03-27 23:42:53 +08:00
parent 7c6c387a07
commit dd9f966597
11 changed files with 166 additions and 34 deletions

1
.gitignore vendored
View File

@@ -82,3 +82,4 @@ Icon
Network Trash Folder Network Trash Folder
Temporary Items Temporary Items
.apdisk .apdisk
*.db

View File

@@ -27,6 +27,11 @@ createApp(App)
path: 'overview', path: 'overview',
component: () => import('@/views/management/Overview.vue'), component: () => import('@/views/management/Overview.vue'),
}, },
{
name: 'organization',
path: 'organization',
component: () => import('@/views/management/Organization.vue'),
},
{ {
name: 'setting', name: 'setting',
path: 'setting', path: 'setting',

View File

@@ -1,6 +1,6 @@
const information = { const information = {
debug: true, debug: true,
baseUrl: 'http://localhost' baseUrl: 'http://localhost:8080',
} }
export function amisRender(target, amisJson) { export function amisRender(target, amisJson) {
@@ -13,7 +13,9 @@ export function amisRender(target, amisJson) {
amisJsonObject, amisJsonObject,
information, information,
{ {
theme: 'antd' theme: 'antd',
} enableAMISDebug:
information.debug,
},
) )
} }

View File

@@ -1,5 +1,8 @@
<script setup> <script setup>
import {ref, watch} from 'vue' import {
ref,
watch,
} from 'vue'
import {useRoute} from 'vue-router' import {useRoute} from 'vue-router'
const route = useRoute(); const route = useRoute();
@@ -13,13 +16,18 @@ const menus = [
key: 'system', key: 'system',
name: '系统管理', name: '系统管理',
children: [ children: [
{
key: 'organization',
path: '/management/organization',
name: '组织架构',
},
{ {
key: 'setting', key: 'setting',
path: '/management/setting', path: '/management/setting',
name: '设置', name: '设置',
} },
] ],
} },
] ]
const sideNavSelected = ref(['overview']) const sideNavSelected = ref(['overview'])
const openKeys = ref([]) // 控制展开的子菜单 const openKeys = ref([]) // 控制展开的子菜单
@@ -65,19 +73,21 @@ watch(() => route.path, () => {
v-model:openKeys="openKeys" v-model:openKeys="openKeys"
mode="inline" mode="inline"
> >
<a-menu-item key="overview"> <div v-for="menu in menus" :key="menu.key">
<router-link to="/management/overview">概览</router-link> <a-sub-menu v-if="menu.children" :key="menu.key">
</a-menu-item>
<a-sub-menu key="system">
<template #title> <template #title>
<span> <span>
系统管理 {{ menu.name }}
</span> </span>
</template> </template>
<a-menu-item key="setting"> <a-menu-item v-for="submenu in menu.children" :key="submenu.key">
<router-link to="/management/setting">设置</router-link> <router-link :to="submenu.path">{{ submenu.name }}</router-link>
</a-menu-item> </a-menu-item>
</a-sub-menu> </a-sub-menu>
<a-menu-item v-else :key="menu.key">
<router-link :to="menu.path">{{ menu.name }}</router-link>
</a-menu-item>
</div>
</a-menu> </a-menu>
</a-layout-sider> </a-layout-sider>
<div class="p-3 h-full w-full"> <div class="p-3 h-full w-full">

View File

@@ -0,0 +1,78 @@
<script setup>
import {onMounted} from 'vue'
import {amisRender} from '@/utils.js'
onMounted(() => {
amisRender(
'#amis-organization',
information => {
return {
type: 'page',
body: [
{
type: 'tpl',
tpl: '${baseUrl}1',
},
{
type: 'crud',
syncLocation: false,
headerToolbar: [
{
type: 'action',
label: '新增组织',
level: 'primary',
actionType: 'dialog',
dialog: {
title: '新增组织',
body: {
type: 'form',
api: {
method: 'post',
url: `${information.baseUrl}/jsonapi/organization`,
dataType: 'application/vnd.api+json',
headers: {
'Content-Type': 'application/vnd.api+json',
},
data: {
type: 'user',
attributes: {
organizationName: '${organizationName}',
},
},
},
body: [
{
type: 'input-text',
name: 'organizationName',
label: '组织名称',
required: true,
},
],
},
},
},
],
columns: [
{
name: 'organizationId',
label: '组织编号',
},
{
name: 'organizationName',
label: '组织名称',
},
],
},
],
}
},
)
})
</script>
<template>
<div id="amis-organization"></div>
</template>
<style scoped>
</style>

View File

@@ -5,5 +5,5 @@ package com.lanyuanxiaoyao.server.configuration;
* @version 20250327 * @version 20250327
*/ */
public interface Constants { public interface Constants {
String DATABASE_TABLE_PREFIX = "system_"; String DATABASE_TABLE_PREFIX = "platform_";
} }

View File

@@ -22,7 +22,6 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME;
@Slf4j @Slf4j
public class SnowflakeId { public class SnowflakeId {
@IdGeneratorType(IdGenerator.class) @IdGeneratorType(IdGenerator.class)
@ValueGenerationType(generatedBy = IdGenerator.class)
@Retention(RUNTIME) @Retention(RUNTIME)
@Target({FIELD, METHOD}) @Target({FIELD, METHOD})
public @interface Generator { public @interface Generator {

View File

@@ -2,6 +2,7 @@ package com.lanyuanxiaoyao.server.entity;
import com.lanyuanxiaoyao.server.configuration.Constants; import com.lanyuanxiaoyao.server.configuration.Constants;
import com.lanyuanxiaoyao.server.configuration.database.SnowflakeId; import com.lanyuanxiaoyao.server.configuration.database.SnowflakeId;
import com.yahoo.elide.annotation.Include;
import jakarta.persistence.ConstraintMode; import jakarta.persistence.ConstraintMode;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
import jakarta.persistence.FetchType; import jakarta.persistence.FetchType;
@@ -27,19 +28,24 @@ import lombok.ToString;
@ToString @ToString
@Entity @Entity
@Table(name = Constants.DATABASE_TABLE_PREFIX + "department") @Table(name = Constants.DATABASE_TABLE_PREFIX + "department")
@Include
public class Department { public class Department {
@Id @Id
@SnowflakeId.Generator @SnowflakeId.Generator
private Long departmentId; private Long departmentId;
private String departmentName; private String departmentName;
@ManyToOne @ManyToOne(optional = false)
@JoinColumn(nullable = false, foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) @JoinColumn(foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
private Organization organization; private Organization organization;
@OneToMany(fetch = FetchType.LAZY, mappedBy = "department")
@ToString.Exclude
private Set<User> users;
@ManyToOne @ManyToOne
private Department parent; private Department parent;
@OneToMany(fetch = FetchType.LAZY, mappedBy = "departmentParent") @OneToMany(fetch = FetchType.LAZY, mappedBy = "parent")
@ToString.Exclude @ToString.Exclude
private Set<Department> children; private Set<Department> children;
} }

View File

@@ -2,6 +2,7 @@ package com.lanyuanxiaoyao.server.entity;
import com.lanyuanxiaoyao.server.configuration.Constants; import com.lanyuanxiaoyao.server.configuration.Constants;
import com.lanyuanxiaoyao.server.configuration.database.SnowflakeId; import com.lanyuanxiaoyao.server.configuration.database.SnowflakeId;
import com.yahoo.elide.annotation.Include;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
import jakarta.persistence.FetchType; import jakarta.persistence.FetchType;
import jakarta.persistence.Id; import jakarta.persistence.Id;
@@ -23,12 +24,17 @@ import lombok.ToString;
@ToString @ToString
@Entity @Entity
@Table(name = Constants.DATABASE_TABLE_PREFIX + "organization") @Table(name = Constants.DATABASE_TABLE_PREFIX + "organization")
@Include
public class Organization { public class Organization {
@Id @Id
@SnowflakeId.Generator @SnowflakeId.Generator
private Long organizationId; private Long organizationId;
private String organizationName; private String organizationName;
@OneToMany(fetch = FetchType.LAZY, mappedBy = "organization")
@ToString.Exclude
private Set<User> users;
@OneToMany(fetch = FetchType.LAZY, mappedBy = "organization") @OneToMany(fetch = FetchType.LAZY, mappedBy = "organization")
@ToString.Exclude @ToString.Exclude
private Set<Department> departments; private Set<Department> departments;

View File

@@ -2,9 +2,15 @@ package com.lanyuanxiaoyao.server.entity;
import com.lanyuanxiaoyao.server.configuration.Constants; import com.lanyuanxiaoyao.server.configuration.Constants;
import com.lanyuanxiaoyao.server.configuration.database.SnowflakeId; import com.lanyuanxiaoyao.server.configuration.database.SnowflakeId;
import com.yahoo.elide.annotation.Include;
import jakarta.persistence.ConstraintMode;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
import jakarta.persistence.ForeignKey;
import jakarta.persistence.Id; import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table; import jakarta.persistence.Table;
import jakarta.persistence.UniqueConstraint;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import lombok.ToString; import lombok.ToString;
@@ -20,11 +26,20 @@ import lombok.ToString;
@ToString @ToString
@Entity @Entity
@Table(name = Constants.DATABASE_TABLE_PREFIX + "user") @Table(name = Constants.DATABASE_TABLE_PREFIX + "user")
@Include
public class User { public class User {
@Id @Id
@SnowflakeId.Generator @SnowflakeId.Generator
private Long userId; private Long userId;
private String userCode; private String userCode;
private String userNickName; private String userNickname;
private String userSecret; private String userSecret;
@ManyToOne
@JoinColumn(foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
private Organization organization;
@ManyToOne
@JoinColumn(foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
private Department department;
} }

View File

@@ -0,0 +1,10 @@
### Create
POST http://localhost:8080/jsonapi/organization
Content-Type: application/json
{
"type": "organization",
"attributes": {
"organizationName": "苹果公司"
}
}