|
@@ -1,37 +1,32 @@
|
|
|
import {
|
|
|
deleteMenuList,
|
|
|
getMenuList,
|
|
|
- getPermissionList,
|
|
|
postMenuList,
|
|
|
putMenuList
|
|
|
} from "@/api/system";
|
|
|
-import { ListDate } from "@/utils/formateDate";
|
|
|
-import {
|
|
|
- UseFormatDatePickerHook,
|
|
|
- UseValidTimeRangeHook
|
|
|
-} from "@/utils/hooks/format";
|
|
|
import { type PaginationProps } from "@pureadmin/table";
|
|
|
-import { number } from "echarts";
|
|
|
import { ElMessage, ElMessageBox } from "element-plus";
|
|
|
import { reactive, ref, computed, onMounted } from "vue";
|
|
|
|
|
|
export function useUser() {
|
|
|
- const UpdateForm = ref({
|
|
|
- name: "", // 菜单名
|
|
|
- path: "", // 组件路径
|
|
|
- title: "",
|
|
|
- descs: "", // 描述
|
|
|
- icon: "", // 图标
|
|
|
- parentId: "", //父id
|
|
|
- permissionId: "", //权限id
|
|
|
- menuStatus: "1", // 按钮标识
|
|
|
- version: "1", // 是否按钮
|
|
|
- id: ""
|
|
|
+ //是否可见,0隐藏,1显示
|
|
|
+ const visibleswitchvalue = ref("1");
|
|
|
+ // 是否缓存,0否,1是
|
|
|
+ const keepAliveswitchvalue = ref("1");
|
|
|
+ const UpdateForm: any = ref({
|
|
|
+ name: "", //菜单名称
|
|
|
+ enName: "", //英文名称
|
|
|
+ permission: "", //权限标识
|
|
|
+ path: "", //路由路径
|
|
|
+ parentId: "-1", //父菜单ID
|
|
|
+ icon: "", //菜单图标
|
|
|
+ sortOrder: "", //排序值,越小越靠前
|
|
|
+ embedded: "0", //是否内嵌,0否,1是
|
|
|
+ menuType: "0" //菜单类型,0菜单,1按钮
|
|
|
});
|
|
|
const dialogType = ref(1);
|
|
|
const dataList = ref([]);
|
|
|
const menuList = ref([]);
|
|
|
- const permissionList = ref([]);
|
|
|
const loading = ref(false);
|
|
|
const dialogUpdateVisible = ref(false);
|
|
|
const pagination = reactive<PaginationProps>({
|
|
@@ -70,19 +65,12 @@ export function useUser() {
|
|
|
},
|
|
|
{
|
|
|
label: "图标",
|
|
|
- prop: "icon",
|
|
|
- minWidth: 130
|
|
|
- },
|
|
|
- {
|
|
|
- label: "描述",
|
|
|
- prop: "descs",
|
|
|
- minWidth: 130
|
|
|
+ prop: "meta.icon",
|
|
|
+ minWidth: 130,
|
|
|
+ cellRenderer: ({ props, row }) => (
|
|
|
+ <el-text size={props.size}>{row.meta.icon}</el-text>
|
|
|
+ )
|
|
|
},
|
|
|
- // {
|
|
|
- // label: "状态",
|
|
|
- // prop: "status",
|
|
|
- // minWidth: 130
|
|
|
- // },
|
|
|
{
|
|
|
label: "操作",
|
|
|
fixed: "right",
|
|
@@ -100,33 +88,16 @@ export function useUser() {
|
|
|
];
|
|
|
});
|
|
|
|
|
|
- // 获取权限列表
|
|
|
- async function permission() {
|
|
|
- const { data } = await getPermissionList({});
|
|
|
- const permission = data.map(item => {
|
|
|
- return {
|
|
|
- label: item.name,
|
|
|
- Id: item.id
|
|
|
- };
|
|
|
- });
|
|
|
- permissionList.value = permission;
|
|
|
- permissionList.value.unshift({
|
|
|
- label: "作为菜单",
|
|
|
- Id: ""
|
|
|
- });
|
|
|
- }
|
|
|
- permission();
|
|
|
-
|
|
|
// 树形结构格式化
|
|
|
- function TreeFormatter(data, flag = false) {
|
|
|
+ function TreeFormatter(data) {
|
|
|
const result = data.map(item => {
|
|
|
- if (item.children.length != 0) {
|
|
|
+ if (item.children && item.children.length != 0) {
|
|
|
return {
|
|
|
label: item.name,
|
|
|
value: item.id,
|
|
|
- children: TreeFormatter(item.children, true)
|
|
|
+ children: TreeFormatter(item.children)
|
|
|
};
|
|
|
- } else if (item.version != 0) {
|
|
|
+ } else if (item.menuType == 1) {
|
|
|
return {
|
|
|
disabled: true,
|
|
|
label: item.name,
|
|
@@ -143,29 +114,33 @@ export function useUser() {
|
|
|
}
|
|
|
// 获取全部菜单列表
|
|
|
async function Menu() {
|
|
|
- const { data } = await getMenuList({ id: "" });
|
|
|
+ const { data } = await getMenuList({});
|
|
|
+ console.log(data);
|
|
|
menuList.value = TreeFormatter(data);
|
|
|
console.log(menuList.value);
|
|
|
menuList.value.unshift({
|
|
|
label: "作为顶级菜单",
|
|
|
- value: "null"
|
|
|
+ value: "-1"
|
|
|
});
|
|
|
}
|
|
|
Menu();
|
|
|
async function UpdateFormSubmit() {
|
|
|
if (dialogType.value == 1) {
|
|
|
- const { status, message } = await postMenuList({
|
|
|
- name: UpdateForm.value.name, // 菜单名
|
|
|
- path: UpdateForm.value.path, // 组件路径
|
|
|
- descs: UpdateForm.value.descs, // 描述
|
|
|
- title: UpdateForm.value.title, // 名称
|
|
|
- icon: UpdateForm.value.icon, // 图标
|
|
|
+ const { status, msg } = await postMenuList({
|
|
|
+ name: UpdateForm.value.name,
|
|
|
+ enName: UpdateForm.value.enName,
|
|
|
+ permission: UpdateForm.value.permission,
|
|
|
+ path: UpdateForm.value.path,
|
|
|
parentId:
|
|
|
UpdateForm.value.parentId === "null"
|
|
|
? null
|
|
|
- : UpdateForm.value.parentId, //父id
|
|
|
- permissionId: UpdateForm.value.permissionId, //权限id
|
|
|
- menuStatus: UpdateForm.value.permissionId === "" ? "0" : "1" // 按钮标识
|
|
|
+ : UpdateForm.value.parentId,
|
|
|
+ icon: UpdateForm.value.icon,
|
|
|
+ visible: visibleswitchvalue.value,
|
|
|
+ sortOrder: UpdateForm.value.sortOrder,
|
|
|
+ keepAlive: keepAliveswitchvalue.value,
|
|
|
+ embedded: UpdateForm.value.embedded,
|
|
|
+ menuType: UpdateForm.value.menuType
|
|
|
});
|
|
|
if (status == 1) {
|
|
|
ElMessage({
|
|
@@ -174,28 +149,30 @@ export function useUser() {
|
|
|
});
|
|
|
dialogUpdateVisible.value = false;
|
|
|
onSearch();
|
|
|
- permission();
|
|
|
Menu();
|
|
|
} else {
|
|
|
- ElMessageBox.alert(message, "提示", {
|
|
|
+ ElMessageBox.alert(msg, "提示", {
|
|
|
confirmButtonText: "关闭",
|
|
|
type: "warning"
|
|
|
});
|
|
|
}
|
|
|
} else {
|
|
|
- const { status, message } = await putMenuList({
|
|
|
- name: UpdateForm.value.name, // 菜单名
|
|
|
- path: UpdateForm.value.path, // 组件路径
|
|
|
- descs: UpdateForm.value.descs, // 描述
|
|
|
- title: UpdateForm.value.title, // 名称
|
|
|
- icon: UpdateForm.value.icon, // 图标
|
|
|
+ const { status, msg } = await putMenuList({
|
|
|
+ name: UpdateForm.value.name,
|
|
|
+ enName: UpdateForm.value.enName,
|
|
|
+ permission: UpdateForm.value.permission,
|
|
|
+ path: UpdateForm.value.path,
|
|
|
parentId:
|
|
|
UpdateForm.value.parentId === "null"
|
|
|
? null
|
|
|
- : UpdateForm.value.parentId, //父id
|
|
|
- permissionId: UpdateForm.value.permissionId, //权限id
|
|
|
- menuStatus: UpdateForm.value.permissionId === "" ? "0" : "1", // 按钮标识
|
|
|
- id: UpdateForm.value.id
|
|
|
+ : UpdateForm.value.parentId,
|
|
|
+ icon: UpdateForm.value.icon,
|
|
|
+ visible: visibleswitchvalue.value,
|
|
|
+ sortOrder: UpdateForm.value.sortOrder,
|
|
|
+ keepAlive: keepAliveswitchvalue.value,
|
|
|
+ embedded: UpdateForm.value.embedded,
|
|
|
+ menuType: UpdateForm.value.menuType,
|
|
|
+ menuId: UpdateForm.value.menuId
|
|
|
});
|
|
|
if (status == 1) {
|
|
|
ElMessage({
|
|
@@ -204,10 +181,9 @@ export function useUser() {
|
|
|
});
|
|
|
dialogUpdateVisible.value = false;
|
|
|
onSearch();
|
|
|
- permission();
|
|
|
Menu();
|
|
|
} else {
|
|
|
- ElMessageBox.alert(message, "提示", {
|
|
|
+ ElMessageBox.alert(msg, "提示", {
|
|
|
confirmButtonText: "关闭",
|
|
|
type: "warning"
|
|
|
});
|
|
@@ -220,54 +196,51 @@ export function useUser() {
|
|
|
cancelButtonText: "取消",
|
|
|
type: "warning"
|
|
|
}).then(async () => {
|
|
|
- const { status, message } = await deleteMenuList({ id: row.id });
|
|
|
+ const { status, msg } = await deleteMenuList(row.id);
|
|
|
if (status == 1) {
|
|
|
ElMessage({
|
|
|
message: "删除成功",
|
|
|
type: "success"
|
|
|
});
|
|
|
onSearch();
|
|
|
- permission();
|
|
|
Menu();
|
|
|
} else {
|
|
|
- ElMessageBox.alert(message, "提示", {
|
|
|
+ ElMessageBox.alert(msg, "提示", {
|
|
|
confirmButtonText: "关闭",
|
|
|
type: "warning"
|
|
|
});
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
- function AddUser(row) {
|
|
|
+ function AddUser() {
|
|
|
UpdateForm.value = {
|
|
|
- name: "", // 菜单名
|
|
|
- path: "", // 组件路径
|
|
|
- descs: "", // 描述
|
|
|
- title: "", // 名称
|
|
|
- icon: "", // 图标
|
|
|
- parentId: "", //父id
|
|
|
- permissionId: "", //权限id
|
|
|
- menuStatus: "1", // 按钮标识
|
|
|
- version: "" // 是否按钮
|
|
|
+ name: "", //菜单名称
|
|
|
+ enName: "", //英文名称
|
|
|
+ permission: "", //权限标识
|
|
|
+ path: "", //路由路径
|
|
|
+ parentId: "", //父菜单ID
|
|
|
+ icon: "", //菜单图标
|
|
|
+ sortOrder: "", //排序值,越小越靠前
|
|
|
+ embedded: "0", //是否内嵌,0否,1是
|
|
|
+ menuType: "0" //菜单类型,0菜单,1按钮
|
|
|
};
|
|
|
dialogType.value = 1;
|
|
|
dialogUpdateVisible.value = true;
|
|
|
}
|
|
|
function handleUpdate(row) {
|
|
|
- console.log(row);
|
|
|
-
|
|
|
dialogType.value = 2;
|
|
|
dialogUpdateVisible.value = true;
|
|
|
UpdateForm.value = {
|
|
|
- name: row.name, // 菜单名
|
|
|
- path: row.path, // 组件路径
|
|
|
- title: row.title, // 菜单名称
|
|
|
- descs: row.descs, // 描述
|
|
|
- icon: row.icon, // 图标
|
|
|
- parentId: row.parentId ? row.parentId : "null", //父id
|
|
|
- permissionId: row.permissionId === null ? "" : row.permissionId, //权限id
|
|
|
- menuStatus: row.version === 0 ? "0" : "1", // 按钮标识
|
|
|
- version: row.version, // 是否按钮
|
|
|
- id: row.id // 是否按钮
|
|
|
+ menuId: row.id ? row.id : "",
|
|
|
+ name: row.name ? row.name : "", //菜单名称
|
|
|
+ enName: row.meta.enName ? row.meta.enName : "", //英文名称
|
|
|
+ permission: row.permission ? row.permission : "", //权限标识
|
|
|
+ path: row.path ? row.path : "", //路由路径
|
|
|
+ parentId: row.parentId ? row.parentId : "", //父菜单ID
|
|
|
+ icon: row.meta.icon ? row.meta.icon : "", //菜单图标
|
|
|
+ sortOrder: row.sortOrder, //排序值,越小越靠前
|
|
|
+ embedded: row.embedded ? row.embedded : "0", //是否内嵌,0否,1是
|
|
|
+ menuType: row.menuType ? row.menuType : "" //菜单类型,0菜单,1按钮
|
|
|
};
|
|
|
}
|
|
|
|
|
@@ -297,17 +270,13 @@ export function useUser() {
|
|
|
}
|
|
|
async function onSearch() {
|
|
|
loading.value = true;
|
|
|
- const { data, other } = await getMenuList({
|
|
|
- pageSize: pagination.pageSize,
|
|
|
- pageNum: pagination.currentPage
|
|
|
- });
|
|
|
+ const { data } = await getMenuList({});
|
|
|
dataList.value = data;
|
|
|
- pagination.total = other;
|
|
|
+ pagination.total = data.length;
|
|
|
setTimeout(() => {
|
|
|
loading.value = false;
|
|
|
}, 500);
|
|
|
}
|
|
|
-
|
|
|
onMounted(() => {
|
|
|
onSearch();
|
|
|
});
|
|
@@ -319,11 +288,12 @@ export function useUser() {
|
|
|
pagination,
|
|
|
buttonClass,
|
|
|
dialogUpdateVisible,
|
|
|
+ visibleswitchvalue,
|
|
|
+ keepAliveswitchvalue,
|
|
|
UpdateFormSubmit,
|
|
|
submit,
|
|
|
UpdateForm,
|
|
|
menuList,
|
|
|
- permissionList,
|
|
|
dialogType,
|
|
|
AddUser,
|
|
|
onSearch,
|