新增角色模板静态文件
This commit is contained in:
@@ -0,0 +1,105 @@
|
||||
<template>
|
||||
<el-dialog :title="form.id ? `编辑${typeObj[type]}` : `添加${typeObj[type]}`" width="400px" v-model="visible"
|
||||
@closed="resetForm">
|
||||
<el-form ref="formRef" :model="form" :rules="rules" label-width="100px" label-position="left">
|
||||
<el-form-item :label="`${typeObj[type]}名称`" prop="name">
|
||||
<el-input placeholder="请输入" :maxlength="30" v-model="form.name"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="排序值">
|
||||
<el-input placeholder="请输入" :maxlength="20" v-model="form.sort"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="启用状态">
|
||||
<el-switch v-model="form.status" :active-value="1" :inactive-value="0"></el-switch>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<div class="dialog_footer">
|
||||
<div class="btn">
|
||||
<el-button size="large" style="width: 100%;" @click="visible = false">取 消</el-button>
|
||||
</div>
|
||||
<div class="btn">
|
||||
<el-button size="large" type="primary" :loading="loading" style="width: 100%;" @click="submitHandle">确
|
||||
定</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref } from 'vue'
|
||||
|
||||
// 1添加模板 2添加类型
|
||||
const type = ref(1)
|
||||
const typeObj = ref({
|
||||
1: '模板',
|
||||
2: '角色'
|
||||
})
|
||||
|
||||
const visible = ref(false)
|
||||
const formRef = ref(null)
|
||||
const loading = ref(false)
|
||||
const form = ref({
|
||||
name: '',
|
||||
sort: '',
|
||||
status: 1
|
||||
})
|
||||
const rules = ref({
|
||||
name: [
|
||||
{
|
||||
required: true,
|
||||
message: '请输入模板名称',
|
||||
triiger: 'blur'
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
function resetForm() {
|
||||
form.value = {
|
||||
name: '',
|
||||
sort: '',
|
||||
status: 1
|
||||
}
|
||||
formRef.value.resetFields()
|
||||
}
|
||||
|
||||
// 提交
|
||||
function submitHandle() {
|
||||
formRef.value.validate(async vaild => {
|
||||
try {
|
||||
if (vaild) {
|
||||
loading.value = true
|
||||
// const res = await abc()
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
setTimeout(() => {
|
||||
loading.value = false
|
||||
}, 500);
|
||||
})
|
||||
}
|
||||
|
||||
function show(t, obj) {
|
||||
visible.value = true
|
||||
type.value = t
|
||||
if (obj && obj.id) {
|
||||
form.value = { ...obj }
|
||||
}
|
||||
}
|
||||
|
||||
defineExpose({
|
||||
show
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.dialog_footer {
|
||||
display: flex;
|
||||
gap: 14px;
|
||||
|
||||
.btn {
|
||||
flex: 1;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -2,13 +2,275 @@
|
||||
<div class="container">
|
||||
<div class="content">
|
||||
<div class="row">
|
||||
<el-button type="primary">添加</el-button>
|
||||
<el-button type="primary" @click="addTempateDialogRef.show(1)">添加</el-button>
|
||||
</div>
|
||||
<div class="row mt14">
|
||||
<el-table :data="tableData.list" v-loading="tableData.loading" stripe border>
|
||||
<el-table-column label="ID"></el-table-column>
|
||||
<el-table-column label="模版名称"></el-table-column>
|
||||
<el-table-column label="启用状态"></el-table-column>
|
||||
<el-table-column label="排序值"></el-table-column>
|
||||
<el-table-column label="创建时间"></el-table-column>
|
||||
<el-table-column label="操作人"></el-table-column>
|
||||
<el-table-column label="操作">
|
||||
<template v-slot="scope">
|
||||
<el-button link type="primary">添加角色</el-button>
|
||||
<el-button link type="primary">分配权限</el-button>
|
||||
<el-button link type="danger">删除</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</div>
|
||||
</div>
|
||||
<!-- 添加模板/角色 -->
|
||||
<addTempateDialog ref="addTempateDialogRef" />
|
||||
<!-- 分配菜单弹窗 -->
|
||||
<el-drawer v-model="assignPermDialogVisible" size="500">
|
||||
<template #header>
|
||||
<div>
|
||||
<div>
|
||||
<h3>
|
||||
{{ "【" + checkedRole.name + "】菜单分配" }}
|
||||
</h3>
|
||||
</div>
|
||||
<div>
|
||||
<el-form-item label="平台类型">
|
||||
<el-radio-group v-model="platformType" @change="handlePlatformTypeChange">
|
||||
<el-radio :value="0">管理端</el-radio>
|
||||
<el-radio :value="1">收银机</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
</div>
|
||||
<div class="flex-x-between">
|
||||
<el-input v-model="permKeywords" clearable class="w-[150px]" placeholder="菜单菜单名称">
|
||||
<template #prefix>
|
||||
<Search />
|
||||
</template>
|
||||
</el-input>
|
||||
|
||||
<div class="flex-center ml-5">
|
||||
<el-button type="primary" size="small" plain @click="togglePermTree">
|
||||
<template #icon>
|
||||
<Switch />
|
||||
</template>
|
||||
{{ isExpanded ? "收缩" : "展开" }}
|
||||
</el-button>
|
||||
<el-checkbox v-model="parentChildLinked" class="ml-5" @change="handleparentChildLinkedChange">
|
||||
父子联动
|
||||
</el-checkbox>
|
||||
|
||||
<el-tooltip placement="bottom">
|
||||
<template #content>
|
||||
如果只需勾选菜单菜单,不需要勾选子菜单或者按钮菜单,请关闭父子联动
|
||||
</template>
|
||||
<el-icon class="ml-1 color-[--el-color-primary] inline-block cursor-pointer">
|
||||
<QuestionFilled />
|
||||
</el-icon>
|
||||
</el-tooltip>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<div class="u-relative" style="overflow-x: hidden">
|
||||
<el-tree ref="permTreeRef" node-key="value" show-checkbox :data="menuPermOptions"
|
||||
:default-checked-keys="adminMenuIdList" :filter-node-method="handlePermFilter" :default-expand-all="true"
|
||||
:check-strictly="!parentChildLinked" class="mt-5">
|
||||
<template #default="{ data }">
|
||||
{{ data.label }}
|
||||
</template>
|
||||
</el-tree>
|
||||
<div class="cashMenuIdList" :style="{
|
||||
transform: `translateX(${(platformType == 1 ? 0 : 1) * 100}%)`,
|
||||
}">
|
||||
<el-checkbox-group v-model="cashMenuIdList">
|
||||
<el-checkbox v-for="(item, index) in casher_windows_menus" :key="index" :value="item.menuId">
|
||||
{{ item.name }}
|
||||
</el-checkbox>
|
||||
</el-checkbox-group>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<template #footer>
|
||||
<div class="dialog-footer">
|
||||
<el-button type="primary" @click="handleAssignPermSubmit">确 定</el-button>
|
||||
<el-button @click="assignPermDialogVisible = false">取 消</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</el-drawer>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup></script>
|
||||
<script setup>
|
||||
import { ref, reactive } from 'vue'
|
||||
import addTempateDialog from './components/addTempateDialog.vue';
|
||||
import MenuAPI from "@/api/account/menu";
|
||||
|
||||
const addTempateDialogRef = ref(null)
|
||||
|
||||
const tableData = reactive({
|
||||
loading: false,
|
||||
page: 1,
|
||||
size: 10,
|
||||
list: []
|
||||
})
|
||||
|
||||
const assignPermDialogVisible = ref(false)
|
||||
|
||||
const checkedRole = ref({})
|
||||
|
||||
const platformType = ref(0);
|
||||
function handlePlatformTypeChange(e) {
|
||||
const value = Number(e); // Ensure the value is cast to a number
|
||||
console.log("handlePlatformTypeChange");
|
||||
platformType.value = value;
|
||||
handleOpenAssignPermDialog(dialog.row);
|
||||
}
|
||||
|
||||
const permKeywords = ref("");
|
||||
const isExpanded = ref(true);
|
||||
const parentChildLinked = ref(false);
|
||||
|
||||
// 展开/收缩 菜单菜单树
|
||||
function togglePermTree() {
|
||||
isExpanded.value = !isExpanded.value;
|
||||
if (permTreeRef.value) {
|
||||
Object.values(permTreeRef.value.store.nodesMap).forEach((node) => {
|
||||
if (isExpanded.value) {
|
||||
node.expand();
|
||||
} else {
|
||||
node.collapse();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// 父子菜单节点是否联动
|
||||
function handleparentChildLinkedChange(val) {
|
||||
parentChildLinked.value = val;
|
||||
}
|
||||
|
||||
// 角色表格数据
|
||||
const roleList = ref();
|
||||
// 菜单菜单下拉
|
||||
const menuPermOptions = ref([]);
|
||||
|
||||
//获取收银机菜单
|
||||
async function getCashMenus() {
|
||||
const res = await MenuAPI.getCashMenus();
|
||||
console.log(res);
|
||||
casher_windows_menus.value = res;
|
||||
}
|
||||
// 获取所有的菜单
|
||||
async function getMenuPermOptions() {
|
||||
// let arr = shopUser.userInfo.account === "admin" ? await MenuAPI.getList() : await MenuAPI.getRoutes();
|
||||
let arr = await MenuAPI.getList();
|
||||
menuPermOptions.value = returnMenu(arr);
|
||||
}
|
||||
|
||||
const adminMenuIdList = ref([]);
|
||||
|
||||
function handlePermFilter(value, data) {
|
||||
if (!value) return true;
|
||||
return data.label.includes(value);
|
||||
}
|
||||
|
||||
// 角色表单
|
||||
const formData = reactive({
|
||||
// sort: 1,
|
||||
// status: 1,
|
||||
id: null,
|
||||
name: "",
|
||||
level: 0,
|
||||
menuIdList: [],
|
||||
description: "",
|
||||
});
|
||||
const cashMenuIdList = ref([]);
|
||||
const rules = reactive({
|
||||
name: [{ required: true, message: "请输入角色名称", trigger: "blur" }],
|
||||
level: [{ required: false, message: "请输入角色等级", trigger: "blur" }],
|
||||
});
|
||||
|
||||
// 回显角色已拥有的菜单
|
||||
function getMenuIds(roleId) {
|
||||
roleId = roleId ? roleId : dialog.row.id;
|
||||
if (!roleId) {
|
||||
return;
|
||||
}
|
||||
RoleApi.getMenu(roleId, platformType.value)
|
||||
.then((data) => {
|
||||
if (platformType.value == 0) {
|
||||
const checkedMenuIds = data;
|
||||
adminMenuIdList.value = data;
|
||||
// checkedMenuIds.forEach((menuId) => permTreeRef.value!.setChecked(menuId, true, false));
|
||||
}
|
||||
if (platformType.value == 1) {
|
||||
cashMenuIdList.value = data;
|
||||
}
|
||||
})
|
||||
.finally(() => {
|
||||
loading.value = false;
|
||||
});
|
||||
}
|
||||
|
||||
function returnMenu(menu) {
|
||||
return menu.map((v) => {
|
||||
return {
|
||||
...v,
|
||||
label: v.title,
|
||||
value: v.menuId,
|
||||
children: v.children ? returnMenu(v.children) : [],
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
const casher_windows_menus = ref([]);
|
||||
|
||||
watch(
|
||||
() => assignPermDialogVisible.value,
|
||||
(val) => {
|
||||
if (!val) {
|
||||
permTreeRef.value.setCheckedKeys([]);
|
||||
platformType.value = 0;
|
||||
cashMenuIdList.value = [];
|
||||
adminMenuIdList.value = [];
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
// 分配菜单菜单提交
|
||||
function handleAssignPermSubmit() {
|
||||
const roleId = checkedRole.value.id;
|
||||
const name = checkedRole.value.name;
|
||||
if (roleId) {
|
||||
const checkedMenuIds = permTreeRef
|
||||
.value.getCheckedNodes(false, true)
|
||||
.map((node) => node.value);
|
||||
|
||||
loading.value = true;
|
||||
RoleApi.update(roleId, {
|
||||
name,
|
||||
adminMenuIdList: checkedMenuIds,
|
||||
cashMenuIdList: cashMenuIdList.value.filter((id) =>
|
||||
casher_windows_menus.value.find((v) => v.menuId == id)
|
||||
),
|
||||
})
|
||||
.then(() => {
|
||||
ElMessage.success("分配菜单成功");
|
||||
assignPermDialogVisible.value = false;
|
||||
handleResetQuery();
|
||||
})
|
||||
.finally(() => {
|
||||
loading.value = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
getMenuPermOptions();
|
||||
getCashMenus();
|
||||
})
|
||||
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.container {
|
||||
@@ -20,4 +282,10 @@
|
||||
background-color: #fff;
|
||||
padding: 14px;
|
||||
}
|
||||
|
||||
.row {
|
||||
&.mt14 {
|
||||
margin-top: 14px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -81,7 +81,6 @@ const modalConfig: IModalConfig<addRequest> = {
|
||||
attrs: {
|
||||
placeholder: "请上传版本文件",
|
||||
},
|
||||
hidden: true,
|
||||
initialValue: [],
|
||||
},
|
||||
],
|
||||
|
||||
@@ -64,7 +64,7 @@ const contentConfig: IContentConfig = {
|
||||
width: 150,
|
||||
},
|
||||
{
|
||||
label: "订单原金额 不含折扣价格",
|
||||
label: "订单商品总价",
|
||||
align: "center",
|
||||
prop: "originAmount",
|
||||
templet: "custom",
|
||||
|
||||
Reference in New Issue
Block a user