|
|
@@ -19,23 +19,26 @@
|
|
|
<h4 class="mb30">权限设置</h4>
|
|
|
<el-tree
|
|
|
ref="treeRef"
|
|
|
- :data="currentPermissionData"
|
|
|
+ :data="basePermissionData"
|
|
|
show-checkbox
|
|
|
default-expand-all
|
|
|
node-key="code"
|
|
|
highlight-current
|
|
|
:props="defaultProps"
|
|
|
+ :default-checked-keys="checkedNodes"
|
|
|
style="display: flex; justify-content: space-between"
|
|
|
@check="getTree"
|
|
|
- /></el-card>
|
|
|
+ />
|
|
|
+ <div class="df aic jcfe mt50">
|
|
|
+ <el-button type="primary" @click="addRole">{{
|
|
|
+ roleId ? "修改角色" : "添加角色"
|
|
|
+ }}</el-button>
|
|
|
+ </div>
|
|
|
+ </el-card>
|
|
|
|
|
|
- <el-card class="mt30" style="display: none">
|
|
|
+ <!-- <el-card class="mt30">
|
|
|
<h4>权限设置</h4>
|
|
|
- <div
|
|
|
- v-for="(item, index) in currentPermissionData"
|
|
|
- :key="item"
|
|
|
- class="mt30"
|
|
|
- >
|
|
|
+ <div v-for="(item, index) in basePermissionData" :key="item" class="mt30">
|
|
|
<div class="df aic mb20">
|
|
|
<div class="mr20">{{ item.label }}</div>
|
|
|
<el-switch
|
|
|
@@ -75,15 +78,19 @@
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>
|
|
|
- </el-card>
|
|
|
+ </el-card> -->
|
|
|
</template>
|
|
|
|
|
|
<script setup>
|
|
|
import api from "../../apis/fetch";
|
|
|
import store from "../../store";
|
|
|
+import router from "../../router";
|
|
|
import { ref, onMounted, reactive, computed } from "vue";
|
|
|
import { ElNotification, ElMessageBox } from "element-plus";
|
|
|
import { mapGetters } from "vuex";
|
|
|
+import { useRoute } from "vue-router";
|
|
|
+
|
|
|
+const route = useRoute();
|
|
|
|
|
|
let loginAccountId = ref(0);
|
|
|
let form = ref(null);
|
|
|
@@ -107,23 +114,75 @@ const rules = reactive({
|
|
|
},
|
|
|
],
|
|
|
});
|
|
|
+let roleId = ref("");
|
|
|
let treeRef = ref(null);
|
|
|
-function getTree(checkedNodes, checkedKeys) {
|
|
|
- let postData = [...checkedKeys.checkedKeys, ...checkedKeys.halfCheckedKeys];
|
|
|
- console.log(postData);
|
|
|
-}
|
|
|
const defaultProps = {
|
|
|
children: "children",
|
|
|
label: "label",
|
|
|
};
|
|
|
|
|
|
-function change(status, code) {
|
|
|
- store.commit("updateCurrentPermissionData", { status, code });
|
|
|
+let basePermissionData = computed(() => store.state.basePermissionData);
|
|
|
+let permissionCodes = ref([]);
|
|
|
+let checkedNodes = ref([]);
|
|
|
+function getTree(checked, checkedKeys) {
|
|
|
+ permissionCodes.value = [
|
|
|
+ ...checkedKeys.checkedKeys,
|
|
|
+ ...checkedKeys.halfCheckedKeys,
|
|
|
+ ];
|
|
|
+}
|
|
|
+
|
|
|
+async function getRoleDetail(roleId) {
|
|
|
+ let res = await api.getRoleDetail({
|
|
|
+ loginAccountId: loginAccountId.value,
|
|
|
+ roleId,
|
|
|
+ });
|
|
|
+ if (res.data.status == 0) {
|
|
|
+ let { code, roleName, permission } = res.data.result;
|
|
|
+ ruleForm.value = {
|
|
|
+ roleCode: code,
|
|
|
+ roleName,
|
|
|
+ };
|
|
|
+ checkedNodes.value = permission.split(",");
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+async function addRole() {
|
|
|
+ let postData = {
|
|
|
+ loginAccountId: loginAccountId.value,
|
|
|
+ ...ruleForm.value,
|
|
|
+ permissionCodes: permissionCodes.value.join(","),
|
|
|
+ };
|
|
|
+ if (roleId.value) {
|
|
|
+ postData.roleId = roleId.value;
|
|
|
+ }
|
|
|
+ let res = await api[roleId.value ? "updateRole" : "addRole"](postData);
|
|
|
+ if (res.data.status == 0) {
|
|
|
+ ElNotification({
|
|
|
+ title: "成功",
|
|
|
+ duration: 1500,
|
|
|
+ message: res.data.msg,
|
|
|
+ type: "success",
|
|
|
+ });
|
|
|
+ router.replace("/authManage/roleList");
|
|
|
+ } else {
|
|
|
+ console.log(res);
|
|
|
+ ElNotification({
|
|
|
+ title: "失败",
|
|
|
+ duration: 1500,
|
|
|
+ message: res.data.msg,
|
|
|
+ type: "error",
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
-let currentPermissionData = computed(() => store.state.currentPermissionData);
|
|
|
onMounted(() => {
|
|
|
loginAccountId.value = localStorage.loginAccountId;
|
|
|
+ let id = route.query.roleId;
|
|
|
+ if (id) {
|
|
|
+ getRoleDetail(id);
|
|
|
+ roleId.value = id;
|
|
|
+ store.commit("changefirstTitle", "修改角色");
|
|
|
+ }
|
|
|
});
|
|
|
</script>
|
|
|
|