|
@@ -18,15 +18,29 @@
|
|
|
|
|
|
<script setup lang="ts">
|
|
<script setup lang="ts">
|
|
import { getRoleList } from "@/api/roleManagementPage";
|
|
import { getRoleList } from "@/api/roleManagementPage";
|
|
|
|
+import { ROLE_MANAGE_SET } from "@/constants/constants";
|
|
|
|
+import { useMainStore } from "@/store";
|
|
import { onMounted, computed, watch } from "vue";
|
|
import { onMounted, computed, watch } from "vue";
|
|
|
|
+import { RoleOption } from "@/types";
|
|
|
|
|
|
-const props = defineProps<{
|
|
|
|
- value?: null | number;
|
|
|
|
- rootOrgId?: null | number;
|
|
|
|
|
|
+const props = withDefaults(
|
|
|
|
+ defineProps<{
|
|
|
|
+ value?: null | number;
|
|
|
|
+ rootOrgId?: null | number;
|
|
|
|
+ isManage: boolean;
|
|
|
|
+ }>(),
|
|
|
|
+ {
|
|
|
|
+ value: null,
|
|
|
|
+ rootOrgId: null,
|
|
|
|
+ isManage: false,
|
|
|
|
+ }
|
|
|
|
+);
|
|
|
|
+const emit = defineEmits<{
|
|
|
|
+ (e: "update:value", id: number): void;
|
|
|
|
+ (e: "change", role: RoleOption | null): void;
|
|
}>();
|
|
}>();
|
|
-const emit = defineEmits(["update:value"]);
|
|
|
|
|
|
|
|
-let optionList = $ref<{ id: number; name: string }[]>([]);
|
|
|
|
|
|
+let optionList = $ref<RoleOption[]>([]);
|
|
|
|
|
|
onMounted(async () => {
|
|
onMounted(async () => {
|
|
await fetchData();
|
|
await fetchData();
|
|
@@ -34,20 +48,32 @@ onMounted(async () => {
|
|
|
|
|
|
watch(() => [props.rootOrgId], fetchData);
|
|
watch(() => [props.rootOrgId], fetchData);
|
|
|
|
|
|
|
|
+const store = useMainStore();
|
|
async function fetchData() {
|
|
async function fetchData() {
|
|
- if (typeof props.rootOrgId === "number") {
|
|
|
|
- const res = await getRoleList(props.rootOrgId);
|
|
|
|
- optionList = res.data;
|
|
|
|
|
|
+ if (typeof props.rootOrgId !== "number") return;
|
|
|
|
+
|
|
|
|
+ const res = await getRoleList(props.rootOrgId);
|
|
|
|
+ optionList = res.data;
|
|
|
|
+
|
|
|
|
+ if (props.isManage) {
|
|
|
|
+ let userRoleSet: string[] = [];
|
|
|
|
+ store.userInfo.roleList.forEach((r) => {
|
|
|
|
+ const info = ROLE_MANAGE_SET[r.roleCode];
|
|
|
|
+ userRoleSet.push(...info);
|
|
|
|
+ });
|
|
|
|
+ optionList = optionList.filter((item) => userRoleSet.includes(item.code));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
const valueStr = computed(() => {
|
|
const valueStr = computed(() => {
|
|
let res: undefined | number = props.value ?? undefined;
|
|
let res: undefined | number = props.value ?? undefined;
|
|
// if (typeof res === "number") res = props.value;
|
|
// if (typeof res === "number") res = props.value;
|
|
- return res ;
|
|
|
|
|
|
+ return res;
|
|
});
|
|
});
|
|
|
|
|
|
-function handleChange(v: string) {
|
|
|
|
|
|
+function handleChange(v: number) {
|
|
// console.log(typeof v);
|
|
// console.log(typeof v);
|
|
emit("update:value", v);
|
|
emit("update:value", v);
|
|
|
|
+ const role = optionList.find((item) => item.id === v);
|
|
|
|
+ emit("change", role || null);
|
|
}
|
|
}
|
|
</script>
|
|
</script>
|