mirror of
https://github.com/ccmjga/zhilu-admin
synced 2026-04-01 00:53:44 +08:00
新增岗位、角色和权限的删除功能,更新相关API接口和前端组件,优化操作逻辑和权限校验
This commit is contained in:
@@ -5,8 +5,7 @@ import com.zl.mjga.dto.PageResponseDto;
|
|||||||
import com.zl.mjga.dto.ai.LlmQueryDto;
|
import com.zl.mjga.dto.ai.LlmQueryDto;
|
||||||
import com.zl.mjga.dto.ai.LlmVm;
|
import com.zl.mjga.dto.ai.LlmVm;
|
||||||
import com.zl.mjga.exception.BusinessException;
|
import com.zl.mjga.exception.BusinessException;
|
||||||
import com.zl.mjga.repository.DepartmentRepository;
|
import com.zl.mjga.repository.*;
|
||||||
import com.zl.mjga.repository.UserRepository;
|
|
||||||
import com.zl.mjga.service.AiChatService;
|
import com.zl.mjga.service.AiChatService;
|
||||||
import com.zl.mjga.service.EmbeddingService;
|
import com.zl.mjga.service.EmbeddingService;
|
||||||
import com.zl.mjga.service.LlmService;
|
import com.zl.mjga.service.LlmService;
|
||||||
@@ -20,9 +19,7 @@ import lombok.RequiredArgsConstructor;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.jooq.generated.mjga.enums.LlmCodeEnum;
|
import org.jooq.generated.mjga.enums.LlmCodeEnum;
|
||||||
import org.jooq.generated.mjga.tables.pojos.AiLlmConfig;
|
import org.jooq.generated.mjga.tables.pojos.*;
|
||||||
import org.jooq.generated.mjga.tables.pojos.Department;
|
|
||||||
import org.jooq.generated.mjga.tables.pojos.User;
|
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
@@ -41,6 +38,10 @@ public class AiController {
|
|||||||
private final EmbeddingService embeddingService;
|
private final EmbeddingService embeddingService;
|
||||||
private final UserRepository userRepository;
|
private final UserRepository userRepository;
|
||||||
private final DepartmentRepository departmentRepository;
|
private final DepartmentRepository departmentRepository;
|
||||||
|
private final PositionRepository positionRepository;
|
||||||
|
private final RoleRepository repository;
|
||||||
|
private final PermissionRepository permissionRepository;
|
||||||
|
private final RoleRepository roleRepository;
|
||||||
|
|
||||||
@PostMapping(value = "/action/execute", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
|
@PostMapping(value = "/action/execute", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
|
||||||
public Flux<String> actionExecute(Principal principal, @RequestBody String userMessage) {
|
public Flux<String> actionExecute(Principal principal, @RequestBody String userMessage) {
|
||||||
@@ -124,7 +125,7 @@ public class AiController {
|
|||||||
userRepository.deleteByUsername(username);
|
userRepository.deleteByUsername(username);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PreAuthorize("hasAuthority(T(com.zl.mjga.model.urp.EPermission).WRITE_USER_ROLE_PERMISSION)")
|
@PreAuthorize("hasAuthority(T(com.zl.mjga.model.urp.EPermission).WRITE_DEPARTMENT_PERMISSION)")
|
||||||
@DeleteMapping("/action/department")
|
@DeleteMapping("/action/department")
|
||||||
void deleteDepartment(@RequestParam String name) {
|
void deleteDepartment(@RequestParam String name) {
|
||||||
Department department = departmentRepository.fetchOneByName(name);
|
Department department = departmentRepository.fetchOneByName(name);
|
||||||
@@ -134,6 +135,36 @@ public class AiController {
|
|||||||
departmentRepository.deleteByName(name);
|
departmentRepository.deleteByName(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PreAuthorize("hasAuthority(T(com.zl.mjga.model.urp.EPermission).WRITE_POSITION_PERMISSION)")
|
||||||
|
@DeleteMapping("/action/position")
|
||||||
|
void deletePosition(@RequestParam String name) {
|
||||||
|
Position position = positionRepository.fetchOneByName(name);
|
||||||
|
if (position == null) {
|
||||||
|
throw new BusinessException("该岗位不存在");
|
||||||
|
}
|
||||||
|
positionRepository.deleteById(position.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@PreAuthorize("hasAuthority(T(com.zl.mjga.model.urp.EPermission).WRITE_USER_ROLE_PERMISSION)")
|
||||||
|
@DeleteMapping("/action/role")
|
||||||
|
void deleteRole(@RequestParam String name) {
|
||||||
|
Role role = roleRepository.fetchOneByName(name);
|
||||||
|
if (role == null) {
|
||||||
|
throw new BusinessException("该角色不存在");
|
||||||
|
}
|
||||||
|
roleRepository.deleteById(role.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@PreAuthorize("hasAuthority(T(com.zl.mjga.model.urp.EPermission).WRITE_USER_ROLE_PERMISSION)")
|
||||||
|
@DeleteMapping("/action/permission")
|
||||||
|
void deletePermission(@RequestParam String name) {
|
||||||
|
Permission permission = permissionRepository.fetchOneByName(name);
|
||||||
|
if (permission == null) {
|
||||||
|
throw new BusinessException("该权限不存在");
|
||||||
|
}
|
||||||
|
permissionRepository.deleteById(permission.getId());
|
||||||
|
}
|
||||||
|
|
||||||
@PostMapping("/chat/refresh")
|
@PostMapping("/chat/refresh")
|
||||||
void createNewConversation(Principal principal) {
|
void createNewConversation(Principal principal) {
|
||||||
aiChatService.evictChatMemory(principal.getName());
|
aiChatService.evictChatMemory(principal.getName());
|
||||||
|
|||||||
@@ -7,9 +7,15 @@ import lombok.Getter;
|
|||||||
@Getter
|
@Getter
|
||||||
public enum Actions {
|
public enum Actions {
|
||||||
CREATE_USER("CREATE_USER", "创建用户"),
|
CREATE_USER("CREATE_USER", "创建用户"),
|
||||||
CREATE_DEPARTMENT("CREATE_DEPARTMENT", "创建部门"),
|
|
||||||
DELETE_USER("DELETE_USER", "删除用户"),
|
DELETE_USER("DELETE_USER", "删除用户"),
|
||||||
DELETE_DEPARTMENT("DELETE_DEPARTMENT", "删除部门");
|
CREATE_DEPARTMENT("CREATE_DEPARTMENT", "创建部门"),
|
||||||
|
DELETE_DEPARTMENT("DELETE_DEPARTMENT", "删除部门"),
|
||||||
|
CREATE_POSITION("CREATE_POSITION", "创建岗位"),
|
||||||
|
DELETE_POSITION("DELETE_POSITION", "删除岗位"),
|
||||||
|
CREATE_ROLE("CREATE_ROLE", "创建角色"),
|
||||||
|
DELETE_ROLE("CREATE_ROLE", "删除角色"),
|
||||||
|
CREATE_PERMISSION("CREATE_PERMISSION", "创建权限"),
|
||||||
|
DELETE_PERMISSION("DELETE_PERMISSION", "删除权限");
|
||||||
public static final String INDEX_KEY = "action";
|
public static final String INDEX_KEY = "action";
|
||||||
private final String code;
|
private final String code;
|
||||||
private final String content;
|
private final String content;
|
||||||
|
|||||||
@@ -1210,6 +1210,75 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"/ai/action/role": {
|
||||||
|
"delete": {
|
||||||
|
"tags": [
|
||||||
|
"ai-controller"
|
||||||
|
],
|
||||||
|
"operationId": "deleteRole_1",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"name": "name",
|
||||||
|
"in": "query",
|
||||||
|
"required": true,
|
||||||
|
"schema": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/ai/action/position": {
|
||||||
|
"delete": {
|
||||||
|
"tags": [
|
||||||
|
"ai-controller"
|
||||||
|
],
|
||||||
|
"operationId": "deletePosition_1",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"name": "name",
|
||||||
|
"in": "query",
|
||||||
|
"required": true,
|
||||||
|
"schema": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/ai/action/permission": {
|
||||||
|
"delete": {
|
||||||
|
"tags": [
|
||||||
|
"ai-controller"
|
||||||
|
],
|
||||||
|
"operationId": "deletePermission_1",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"name": "name",
|
||||||
|
"in": "query",
|
||||||
|
"required": true,
|
||||||
|
"schema": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"/ai/action/department": {
|
"/ai/action/department": {
|
||||||
"delete": {
|
"delete": {
|
||||||
"tags": [
|
"tags": [
|
||||||
|
|||||||
108
frontend/src/api/types/schema.d.ts
vendored
108
frontend/src/api/types/schema.d.ts
vendored
@@ -596,6 +596,54 @@ export interface paths {
|
|||||||
patch?: never;
|
patch?: never;
|
||||||
trace?: never;
|
trace?: never;
|
||||||
};
|
};
|
||||||
|
"/ai/action/role": {
|
||||||
|
parameters: {
|
||||||
|
query?: never;
|
||||||
|
header?: never;
|
||||||
|
path?: never;
|
||||||
|
cookie?: never;
|
||||||
|
};
|
||||||
|
get?: never;
|
||||||
|
put?: never;
|
||||||
|
post?: never;
|
||||||
|
delete: operations["deleteRole_1"];
|
||||||
|
options?: never;
|
||||||
|
head?: never;
|
||||||
|
patch?: never;
|
||||||
|
trace?: never;
|
||||||
|
};
|
||||||
|
"/ai/action/position": {
|
||||||
|
parameters: {
|
||||||
|
query?: never;
|
||||||
|
header?: never;
|
||||||
|
path?: never;
|
||||||
|
cookie?: never;
|
||||||
|
};
|
||||||
|
get?: never;
|
||||||
|
put?: never;
|
||||||
|
post?: never;
|
||||||
|
delete: operations["deletePosition_1"];
|
||||||
|
options?: never;
|
||||||
|
head?: never;
|
||||||
|
patch?: never;
|
||||||
|
trace?: never;
|
||||||
|
};
|
||||||
|
"/ai/action/permission": {
|
||||||
|
parameters: {
|
||||||
|
query?: never;
|
||||||
|
header?: never;
|
||||||
|
path?: never;
|
||||||
|
cookie?: never;
|
||||||
|
};
|
||||||
|
get?: never;
|
||||||
|
put?: never;
|
||||||
|
post?: never;
|
||||||
|
delete: operations["deletePermission_1"];
|
||||||
|
options?: never;
|
||||||
|
head?: never;
|
||||||
|
patch?: never;
|
||||||
|
trace?: never;
|
||||||
|
};
|
||||||
"/ai/action/department": {
|
"/ai/action/department": {
|
||||||
parameters: {
|
parameters: {
|
||||||
query?: never;
|
query?: never;
|
||||||
@@ -1866,6 +1914,66 @@ export interface operations {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
deleteRole_1: {
|
||||||
|
parameters: {
|
||||||
|
query: {
|
||||||
|
name: string;
|
||||||
|
};
|
||||||
|
header?: never;
|
||||||
|
path?: never;
|
||||||
|
cookie?: never;
|
||||||
|
};
|
||||||
|
requestBody?: never;
|
||||||
|
responses: {
|
||||||
|
/** @description OK */
|
||||||
|
200: {
|
||||||
|
headers: {
|
||||||
|
[name: string]: unknown;
|
||||||
|
};
|
||||||
|
content?: never;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
deletePosition_1: {
|
||||||
|
parameters: {
|
||||||
|
query: {
|
||||||
|
name: string;
|
||||||
|
};
|
||||||
|
header?: never;
|
||||||
|
path?: never;
|
||||||
|
cookie?: never;
|
||||||
|
};
|
||||||
|
requestBody?: never;
|
||||||
|
responses: {
|
||||||
|
/** @description OK */
|
||||||
|
200: {
|
||||||
|
headers: {
|
||||||
|
[name: string]: unknown;
|
||||||
|
};
|
||||||
|
content?: never;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
deletePermission_1: {
|
||||||
|
parameters: {
|
||||||
|
query: {
|
||||||
|
name: string;
|
||||||
|
};
|
||||||
|
header?: never;
|
||||||
|
path?: never;
|
||||||
|
cookie?: never;
|
||||||
|
};
|
||||||
|
requestBody?: never;
|
||||||
|
responses: {
|
||||||
|
/** @description OK */
|
||||||
|
200: {
|
||||||
|
headers: {
|
||||||
|
[name: string]: unknown;
|
||||||
|
};
|
||||||
|
content?: never;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
deleteDepartment_1: {
|
deleteDepartment_1: {
|
||||||
parameters: {
|
parameters: {
|
||||||
query: {
|
query: {
|
||||||
|
|||||||
@@ -18,21 +18,16 @@
|
|||||||
<div class="markdown-content markdown-body text-base font-normal py-2.5 text-gray-900 break-words"
|
<div class="markdown-content markdown-body text-base font-normal py-2.5 text-gray-900 break-words"
|
||||||
v-html="renderMarkdown(chatElement.content)">
|
v-html="renderMarkdown(chatElement.content)">
|
||||||
</div>
|
</div>
|
||||||
<button
|
<button v-if="chatElement.type === 'action' && chatElement.command?.startsWith('CREATE_')" type="button"
|
||||||
v-if="chatElement.type === 'action' && (chatElement.command === 'CREATE_USER' || chatElement.command === 'CREATE_DEPARTMENT')"
|
@click="commandActionMap[chatElement.command!]"
|
||||||
type="button" @click="commandActionMap[chatElement.command!]"
|
|
||||||
class="px-3 py-2 text-sm font-medium text-center text-white bg-blue-700 rounded-lg hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300">
|
class="px-3 py-2 text-sm font-medium text-center text-white bg-blue-700 rounded-lg hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300">
|
||||||
{{
|
{{
|
||||||
commandContentMap[chatElement.command!]
|
commandContentMap[chatElement.command!]
|
||||||
}}</button>
|
}}</button>
|
||||||
<InputButton size="md"
|
<InputButton size="md"
|
||||||
bgColor="bg-red-700 hover:bg-red-800 focus:ring-red-300 text-white focus:ring-4 focus:outline-none"
|
bgColor="bg-red-700 hover:bg-red-800 focus:ring-red-300 text-white focus:ring-4 focus:outline-none"
|
||||||
:content="commandContentMap[chatElement.command!]" :handleSubmit="handleDeleteUserClick"
|
:content="commandContentMap[chatElement.command!]" :handleSubmit="commandActionMap[chatElement.command!]"
|
||||||
v-if="chatElement.command === 'DELETE_USER'" />
|
v-if="chatElement.command?.startsWith('DELETE_')" />
|
||||||
<InputButton size="md"
|
|
||||||
bgColor="bg-red-700 hover:bg-red-800 focus:ring-red-300 text-white focus:ring-4 focus:outline-none"
|
|
||||||
:content="commandContentMap[chatElement.command!]" :handleSubmit="handleDeleteDepartmentClick"
|
|
||||||
v-if="chatElement.command === 'DELETE_DEPARTMENT'" />
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
@@ -88,6 +83,30 @@
|
|||||||
currentDeleteDepartmentName = undefined
|
currentDeleteDepartmentName = undefined
|
||||||
departmentDeleteModal!.hide();
|
departmentDeleteModal!.hide();
|
||||||
}" :onSubmit="handleDeleteDepartmentSubmit" title="确定删除该部门吗" content="删除部门"></DepartmentDeleteModal>
|
}" :onSubmit="handleDeleteDepartmentSubmit" title="确定删除该部门吗" content="删除部门"></DepartmentDeleteModal>
|
||||||
|
<PositionFormDialog :id="'position-upsert-modal'" :onSubmit="handleUpsertPositionSubmit" :closeModal="() => {
|
||||||
|
positionUpsertModal!.hide();
|
||||||
|
}">
|
||||||
|
</PositionFormDialog>
|
||||||
|
<PositionDeleteModal :id="'position-delete-modal'" :closeModal="() => {
|
||||||
|
currentDeletePositionName = undefined
|
||||||
|
positionDeleteModal!.hide();
|
||||||
|
}" :onSubmit="handleDeletePositionSubmit" title="确定删除该岗位吗" content="删除岗位"></PositionDeleteModal>
|
||||||
|
<RoleFormDialog :id="'role-upsert-modal'" :onSubmit="handleUpsertRoleSubmit" :closeModal="() => {
|
||||||
|
roleUpsertModal!.hide();
|
||||||
|
}">
|
||||||
|
</RoleFormDialog>
|
||||||
|
<RoleDeleteModal :id="'role-delete-modal'" :closeModal="() => {
|
||||||
|
currentDeleteRoleName = undefined
|
||||||
|
roleDeleteModal!.hide();
|
||||||
|
}" :onSubmit="handleDeleteRoleSubmit" title="确定删除该角色吗" content="删除角色"></RoleDeleteModal>
|
||||||
|
<PermissionFormDialog :id="'permission-upsert-modal'" :onSubmit="handleUpsertPermissionSubmit" :closeModal="() => {
|
||||||
|
permissionUpsertModal!.hide();
|
||||||
|
}">
|
||||||
|
</PermissionFormDialog>
|
||||||
|
<PermissionDeleteModal :id="'permission-delete-modal'" :closeModal="() => {
|
||||||
|
currentDeletePermissionName = undefined
|
||||||
|
permissionDeleteModal!.hide();
|
||||||
|
}" :onSubmit="handleDeletePermissionSubmit" title="确定删除该权限吗" content="删除权限"></PermissionDeleteModal>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
@@ -102,17 +121,29 @@ import { useAiAction } from "@/composables/ai/useAiAction";
|
|||||||
import { useAiChat } from "@/composables/ai/useAiChat";
|
import { useAiChat } from "@/composables/ai/useAiChat";
|
||||||
import { useDepartmentQuery } from "@/composables/department/useDepartmentQuery";
|
import { useDepartmentQuery } from "@/composables/department/useDepartmentQuery";
|
||||||
import { useDepartmentUpsert } from "@/composables/department/useDepartmentUpsert";
|
import { useDepartmentUpsert } from "@/composables/department/useDepartmentUpsert";
|
||||||
|
import usePermissionUpsert from "@/composables/permission/usePermissionUpsert";
|
||||||
|
import { usePositionUpsert } from "@/composables/position/usePositionUpsert";
|
||||||
|
import { useRoleUpsert } from "@/composables/role/useRoleUpsert";
|
||||||
import { useActionExcStore } from "@/composables/store/useActionExcStore";
|
import { useActionExcStore } from "@/composables/store/useActionExcStore";
|
||||||
import useAlertStore from "@/composables/store/useAlertStore";
|
import useAlertStore from "@/composables/store/useAlertStore";
|
||||||
import useUserStore from "@/composables/store/useUserStore";
|
import useUserStore from "@/composables/store/useUserStore";
|
||||||
import { useUserUpsert } from "@/composables/user/useUserUpsert";
|
import { useUserUpsert } from "@/composables/user/useUserUpsert";
|
||||||
import type { DepartmentUpsertModel } from "@/types/DepartmentTypes";
|
import type { DepartmentUpsertModel } from "@/types/DepartmentTypes";
|
||||||
|
import type { PositionUpsertModel } from "@/types/PositionTypes";
|
||||||
|
import type { PermissionUpsertModel } from "@/types/PermissionTypes";
|
||||||
|
import type { RoleUpsertModel } from "@/types/RoleTypes";
|
||||||
import type { UserUpsertSubmitModel } from "@/types/UserTypes";
|
import type { UserUpsertSubmitModel } from "@/types/UserTypes";
|
||||||
import DOMPurify from "dompurify";
|
import DOMPurify from "dompurify";
|
||||||
import { Modal, type ModalInterface, initFlowbite } from "flowbite";
|
import { Modal, type ModalInterface, initFlowbite } from "flowbite";
|
||||||
import { marked } from "marked";
|
import { marked } from "marked";
|
||||||
import { nextTick, onMounted, onUnmounted, ref, watch } from "vue";
|
import { nextTick, onMounted, onUnmounted, ref, watch } from "vue";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
import PermissionDeleteModal from "@/components/modals/ConfirmationDialog.vue";
|
||||||
|
import PermissionFormDialog from "@/components/modals/PermissionFormDialog.vue";
|
||||||
|
import PositionDeleteModal from "@/components/modals/ConfirmationDialog.vue";
|
||||||
|
import PositionFormDialog from "@/components/modals/PositionFormDialog.vue";
|
||||||
|
import RoleDeleteModal from "@/components/modals/ConfirmationDialog.vue";
|
||||||
|
import RoleFormDialog from "@/components/modals/RoleFormDialog.vue";
|
||||||
|
|
||||||
const {
|
const {
|
||||||
messages,
|
messages,
|
||||||
@@ -132,42 +163,50 @@ const alertStore = useAlertStore();
|
|||||||
const commandMode = ref<"chat" | "search" | "execute">("execute");
|
const commandMode = ref<"chat" | "search" | "execute">("execute");
|
||||||
const userUpsert = useUserUpsert();
|
const userUpsert = useUserUpsert();
|
||||||
const departmentUpsert = useDepartmentUpsert();
|
const departmentUpsert = useDepartmentUpsert();
|
||||||
|
const positionUpsert = usePositionUpsert();
|
||||||
|
const roleUpsert = useRoleUpsert();
|
||||||
const userDeleteModal = ref<ModalInterface>();
|
const userDeleteModal = ref<ModalInterface>();
|
||||||
const { deleteUserByUsername, deleteDepartmentByName } = useAiAction();
|
const positionUpsertModal = ref<ModalInterface>();
|
||||||
|
const positionDeleteModal = ref<ModalInterface>();
|
||||||
|
const roleUpsertModal = ref<ModalInterface>();
|
||||||
|
const roleDeleteModal = ref<ModalInterface>();
|
||||||
|
const permissionUpsertModal = ref<ModalInterface>();
|
||||||
|
const permissionDeleteModal = ref<ModalInterface>();
|
||||||
|
const {
|
||||||
|
deleteUserByUsername,
|
||||||
|
deleteDepartmentByName,
|
||||||
|
deletePositionByName,
|
||||||
|
deleteRoleByName,
|
||||||
|
deletePermissionByName,
|
||||||
|
} = useAiAction();
|
||||||
|
const { upsertPermission } = usePermissionUpsert();
|
||||||
const departmentDeleteModal = ref<ModalInterface>();
|
const departmentDeleteModal = ref<ModalInterface>();
|
||||||
const currentDeleteUsername = ref<string>();
|
const currentDeleteUsername = ref<string>();
|
||||||
const currentDeleteDepartmentName = ref<string>();
|
const currentDeleteDepartmentName = ref<string>();
|
||||||
|
const currentDeletePositionName = ref<string>();
|
||||||
|
const currentDeleteRoleName = ref<string>();
|
||||||
|
const currentDeletePermissionName = ref<string>();
|
||||||
const actionExcStore = useActionExcStore();
|
const actionExcStore = useActionExcStore();
|
||||||
const { availableDepartments, fetchAvailableDepartments } =
|
const { availableDepartments, fetchAvailableDepartments } =
|
||||||
useDepartmentQuery();
|
useDepartmentQuery();
|
||||||
|
|
||||||
const commandPlaceholderMap: Record<string, string> = {
|
const commandPlaceholderMap: Record<string, string> = {
|
||||||
chat: "随便聊聊",
|
chat: "随便聊聊",
|
||||||
search: "搜索创建用户、删除部门等功能",
|
search: "输入「创建用户、删除部门、创建岗位、创建角色、创建权限」试试看",
|
||||||
execute: "帮我创建一个名为 mjga 的用户",
|
execute: "帮我创建一个名为 mjga 的用户",
|
||||||
};
|
};
|
||||||
|
|
||||||
const commandActionMap: Record<string, () => void> = {
|
|
||||||
CREATE_USER: () => {
|
|
||||||
userUpsertModal.value?.show();
|
|
||||||
},
|
|
||||||
CREATE_DEPARTMENT: () => {
|
|
||||||
fetchAvailableDepartments();
|
|
||||||
departmentUpsertModal.value?.show();
|
|
||||||
},
|
|
||||||
DELETE_USER: () => {
|
|
||||||
userDeleteModal.value?.show();
|
|
||||||
},
|
|
||||||
DELETE_DEPARTMENT: () => {
|
|
||||||
departmentDeleteModal.value?.show();
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const commandContentMap: Record<string, string> = {
|
const commandContentMap: Record<string, string> = {
|
||||||
CREATE_USER: "创建用户",
|
CREATE_USER: "创建用户",
|
||||||
CREATE_DEPARTMENT: "创建部门",
|
CREATE_DEPARTMENT: "创建部门",
|
||||||
DELETE_USER: "删除用户",
|
DELETE_USER: "删除用户",
|
||||||
DELETE_DEPARTMENT: "删除部门",
|
DELETE_DEPARTMENT: "删除部门",
|
||||||
|
CREATE_POSITION: "创建岗位",
|
||||||
|
DELETE_POSITION: "删除岗位",
|
||||||
|
CREATE_ROLE: "创建角色",
|
||||||
|
DELETE_ROLE: "删除角色",
|
||||||
|
CREATE_PERMISSION: "创建权限",
|
||||||
|
DELETE_PERMISSION: "删除权限",
|
||||||
};
|
};
|
||||||
|
|
||||||
marked.setOptions({
|
marked.setOptions({
|
||||||
@@ -206,6 +245,21 @@ const handleDeleteDepartmentClick = (input: string) => {
|
|||||||
departmentDeleteModal.value?.show();
|
departmentDeleteModal.value?.show();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleDeletePositionClick = (input: string) => {
|
||||||
|
currentDeletePositionName.value = input;
|
||||||
|
positionDeleteModal.value?.show();
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleDeleteRoleClick = (input: string) => {
|
||||||
|
currentDeleteRoleName.value = input;
|
||||||
|
roleDeleteModal.value?.show();
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleDeletePermissionClick = (input: string) => {
|
||||||
|
currentDeletePermissionName.value = input;
|
||||||
|
permissionDeleteModal.value?.show();
|
||||||
|
};
|
||||||
|
|
||||||
const handleUpsertUserSubmit = async (data: UserUpsertSubmitModel) => {
|
const handleUpsertUserSubmit = async (data: UserUpsertSubmitModel) => {
|
||||||
await userUpsert.upsertUser(data);
|
await userUpsert.upsertUser(data);
|
||||||
userUpsertModal.value?.hide();
|
userUpsertModal.value?.hide();
|
||||||
@@ -248,6 +302,68 @@ const handleDeleteDepartmentSubmit = async () => {
|
|||||||
actionExcStore.notify(true);
|
actionExcStore.notify(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleUpsertPositionSubmit = async (position: PositionUpsertModel) => {
|
||||||
|
await positionUpsert.upsertPosition(position);
|
||||||
|
positionUpsertModal.value?.hide();
|
||||||
|
alertStore.showAlert({
|
||||||
|
content: "操作成功",
|
||||||
|
level: "success",
|
||||||
|
});
|
||||||
|
actionExcStore.notify(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleDeletePositionSubmit = async () => {
|
||||||
|
await deletePositionByName(currentDeletePositionName.value!);
|
||||||
|
positionDeleteModal.value?.hide();
|
||||||
|
alertStore.showAlert({
|
||||||
|
content: "操作成功",
|
||||||
|
level: "success",
|
||||||
|
});
|
||||||
|
actionExcStore.notify(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleUpsertRoleSubmit = async (role: RoleUpsertModel) => {
|
||||||
|
await roleUpsert.upsertRole(role);
|
||||||
|
roleUpsertModal.value?.hide();
|
||||||
|
alertStore.showAlert({
|
||||||
|
content: "操作成功",
|
||||||
|
level: "success",
|
||||||
|
});
|
||||||
|
actionExcStore.notify(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleDeleteRoleSubmit = async () => {
|
||||||
|
await deleteRoleByName(currentDeleteRoleName.value!);
|
||||||
|
roleDeleteModal.value?.hide();
|
||||||
|
alertStore.showAlert({
|
||||||
|
content: "操作成功",
|
||||||
|
level: "success",
|
||||||
|
});
|
||||||
|
actionExcStore.notify(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleUpsertPermissionSubmit = async (
|
||||||
|
permission: PermissionUpsertModel,
|
||||||
|
) => {
|
||||||
|
await upsertPermission(permission);
|
||||||
|
permissionUpsertModal.value?.hide();
|
||||||
|
alertStore.showAlert({
|
||||||
|
content: "操作成功",
|
||||||
|
level: "success",
|
||||||
|
});
|
||||||
|
actionExcStore.notify(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleDeletePermissionSubmit = async () => {
|
||||||
|
await deletePermissionByName(currentDeletePermissionName.value!);
|
||||||
|
permissionDeleteModal.value?.hide();
|
||||||
|
alertStore.showAlert({
|
||||||
|
content: "操作成功",
|
||||||
|
level: "success",
|
||||||
|
});
|
||||||
|
actionExcStore.notify(true);
|
||||||
|
};
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
messages,
|
messages,
|
||||||
() => {
|
() => {
|
||||||
@@ -337,7 +453,76 @@ onMounted(async () => {
|
|||||||
if ($departmentUpsertModalElement) {
|
if ($departmentUpsertModalElement) {
|
||||||
departmentUpsertModal.value = new Modal($departmentUpsertModalElement, {});
|
departmentUpsertModal.value = new Modal($departmentUpsertModalElement, {});
|
||||||
}
|
}
|
||||||
|
const $positionDeleteModalElement: HTMLElement | null =
|
||||||
|
document.querySelector("#position-delete-modal");
|
||||||
|
if ($positionDeleteModalElement) {
|
||||||
|
positionDeleteModal.value = new Modal($positionDeleteModalElement, {});
|
||||||
|
}
|
||||||
|
const $positionUpsertModalElement: HTMLElement | null =
|
||||||
|
document.querySelector("#position-upsert-modal");
|
||||||
|
if ($positionUpsertModalElement) {
|
||||||
|
positionUpsertModal.value = new Modal($positionUpsertModalElement, {});
|
||||||
|
}
|
||||||
|
const $roleDeleteModalElement: HTMLElement | null =
|
||||||
|
document.querySelector("#role-delete-modal");
|
||||||
|
if ($roleDeleteModalElement) {
|
||||||
|
roleDeleteModal.value = new Modal($roleDeleteModalElement, {});
|
||||||
|
}
|
||||||
|
const $roleUpsertModalElement: HTMLElement | null =
|
||||||
|
document.querySelector("#role-upsert-modal");
|
||||||
|
if ($roleUpsertModalElement) {
|
||||||
|
roleUpsertModal.value = new Modal($roleUpsertModalElement, {});
|
||||||
|
}
|
||||||
|
const $permissionDeleteModalElement: HTMLElement | null =
|
||||||
|
document.querySelector("#permission-delete-modal");
|
||||||
|
if ($permissionDeleteModalElement) {
|
||||||
|
permissionDeleteModal.value = new Modal($permissionDeleteModalElement, {});
|
||||||
|
}
|
||||||
|
const $permissionUpsertModalElement: HTMLElement | null =
|
||||||
|
document.querySelector("#permission-upsert-modal");
|
||||||
|
if ($permissionUpsertModalElement) {
|
||||||
|
permissionUpsertModal.value = new Modal($permissionUpsertModalElement, {});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const commandActionMap: Record<string, (input: string) => void> = {
|
||||||
|
CREATE_USER: () => {
|
||||||
|
userUpsertModal.value?.show();
|
||||||
|
},
|
||||||
|
CREATE_DEPARTMENT: () => {
|
||||||
|
fetchAvailableDepartments();
|
||||||
|
departmentUpsertModal.value?.show();
|
||||||
|
},
|
||||||
|
DELETE_USER: (input: string) => {
|
||||||
|
currentDeleteUsername.value = input;
|
||||||
|
userDeleteModal.value?.show();
|
||||||
|
},
|
||||||
|
DELETE_DEPARTMENT: (input: string) => {
|
||||||
|
currentDeleteDepartmentName.value = input;
|
||||||
|
departmentDeleteModal.value?.show();
|
||||||
|
},
|
||||||
|
CREATE_POSITION: () => {
|
||||||
|
positionUpsertModal.value?.show();
|
||||||
|
},
|
||||||
|
DELETE_POSITION: (input: string) => {
|
||||||
|
currentDeletePositionName.value = input;
|
||||||
|
positionDeleteModal.value?.show();
|
||||||
|
},
|
||||||
|
CREATE_ROLE: () => {
|
||||||
|
roleUpsertModal.value?.show();
|
||||||
|
},
|
||||||
|
DELETE_ROLE: (input: string) => {
|
||||||
|
currentDeleteRoleName.value = input;
|
||||||
|
roleDeleteModal.value?.show();
|
||||||
|
},
|
||||||
|
CREATE_PERMISSION: () => {
|
||||||
|
permissionUpsertModal.value?.show();
|
||||||
|
},
|
||||||
|
DELETE_PERMISSION: (input: string) => {
|
||||||
|
currentDeletePermissionName.value = input;
|
||||||
|
permissionDeleteModal.value?.show();
|
||||||
|
},
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="css">
|
<style lang="css">
|
||||||
|
|||||||
@@ -21,8 +21,41 @@ export const useAiAction = () => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const deletePositionByName = async (name: string) => {
|
||||||
|
await client.DELETE("/ai/action/position", {
|
||||||
|
params: {
|
||||||
|
query: {
|
||||||
|
name,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const deleteRoleByName = async (name: string) => {
|
||||||
|
await client.DELETE("/ai/action/role", {
|
||||||
|
params: {
|
||||||
|
query: {
|
||||||
|
name,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const deletePermissionByName = async (name: string) => {
|
||||||
|
await client.DELETE("/ai/action/permission", {
|
||||||
|
params: {
|
||||||
|
query: {
|
||||||
|
name,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
deleteUserByUsername,
|
deleteUserByUsername,
|
||||||
deleteDepartmentByName,
|
deleteDepartmentByName,
|
||||||
|
deletePositionByName,
|
||||||
|
deleteRoleByName,
|
||||||
|
deletePermissionByName,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user