|
|
@@ -0,0 +1,141 @@
|
|
|
+<script lang="ts" setup>
|
|
|
+import type { DataNode } from 'ant-design-vue/es/tree';
|
|
|
+
|
|
|
+import type { Recordable } from '@vben/types';
|
|
|
+
|
|
|
+import type { RelationRequest } from '#/api/model';
|
|
|
+
|
|
|
+import { onMounted, reactive, ref, unref } from 'vue';
|
|
|
+
|
|
|
+import { alert, useVbenModal, VbenTree } from '@vben/common-ui';
|
|
|
+
|
|
|
+import { Spin } from 'ant-design-vue';
|
|
|
+
|
|
|
+import { useFormOptions, useVbenForm } from '#/adapter';
|
|
|
+import { DepartmentApi, EnumApi, RoleApi } from '#/api';
|
|
|
+
|
|
|
+defineOptions({
|
|
|
+ name: 'DataGrant',
|
|
|
+});
|
|
|
+const emit = defineEmits(['success']);
|
|
|
+
|
|
|
+const modelRef = ref<Recordable<any>>({});
|
|
|
+
|
|
|
+const state = reactive<{
|
|
|
+ loadingTree: boolean;
|
|
|
+ treeData: DataNode[];
|
|
|
+}>({
|
|
|
+ treeData: [],
|
|
|
+ loadingTree: false,
|
|
|
+});
|
|
|
+
|
|
|
+const [Form, { setValues, validate, getValues }] = useVbenForm(
|
|
|
+ useFormOptions({
|
|
|
+ schema: [
|
|
|
+ {
|
|
|
+ component: 'ApiSelect',
|
|
|
+ fieldName: 'dataScope',
|
|
|
+ componentProps: {
|
|
|
+ api: EnumApi.getList,
|
|
|
+ params: { name: EnumApi.EnumType.DataScope },
|
|
|
+ showSearch: true,
|
|
|
+ },
|
|
|
+ label: '数据范围',
|
|
|
+ rules: 'required',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ component: 'Input',
|
|
|
+ fieldName: 'relationIds',
|
|
|
+ formItemClass: 'items-start',
|
|
|
+ label: '机构',
|
|
|
+ modelPropName: 'modelValue',
|
|
|
+ dependencies: {
|
|
|
+ triggerFields: ['dataScope'],
|
|
|
+ show(values: any) {
|
|
|
+ return [5].includes(values.dataScope);
|
|
|
+ },
|
|
|
+ },
|
|
|
+ rules: 'required',
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ }),
|
|
|
+);
|
|
|
+
|
|
|
+const getRoleDetailData = async () => {
|
|
|
+ const data = await RoleApi.getDataScope(unref(modelRef).id);
|
|
|
+ setValues({ ...data });
|
|
|
+};
|
|
|
+
|
|
|
+const [Modal, { close, setState, getData, lock, unlock }] = useVbenModal({
|
|
|
+ fullscreenButton: false,
|
|
|
+ draggable: true,
|
|
|
+ closeOnClickModal: false,
|
|
|
+ onConfirm: async () => {
|
|
|
+ const { valid } = await validate();
|
|
|
+ if (!valid) return;
|
|
|
+
|
|
|
+ const values = await getValues();
|
|
|
+ try {
|
|
|
+ lock();
|
|
|
+ const postParams = unref(modelRef);
|
|
|
+ Object.assign(postParams, values);
|
|
|
+ if (postParams.dataScope !== 5) {
|
|
|
+ postParams.relationIds = [];
|
|
|
+ }
|
|
|
+ await RoleApi.updateDataScope(postParams as RelationRequest);
|
|
|
+ alert('操作成功');
|
|
|
+ close();
|
|
|
+ emit('success');
|
|
|
+ } finally {
|
|
|
+ unlock();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ onOpenChange: async (isOpen: boolean) => {
|
|
|
+ if (isOpen) {
|
|
|
+ setState({ loading: true });
|
|
|
+ const data = getData<Recordable<any>>();
|
|
|
+ modelRef.value = { ...data.baseData };
|
|
|
+
|
|
|
+ if (state.treeData.length === 0) {
|
|
|
+ await loadTreeData();
|
|
|
+ }
|
|
|
+
|
|
|
+ await getRoleDetailData();
|
|
|
+
|
|
|
+ setState({ loading: false });
|
|
|
+ }
|
|
|
+ },
|
|
|
+});
|
|
|
+
|
|
|
+onMounted(async () => {});
|
|
|
+
|
|
|
+const loadTreeData = async () => {
|
|
|
+ state.loadingTree = true;
|
|
|
+ try {
|
|
|
+ const res = await DepartmentApi.getTreeOptions();
|
|
|
+ state.treeData = res as unknown as DataNode[];
|
|
|
+ } finally {
|
|
|
+ state.loadingTree = false;
|
|
|
+ }
|
|
|
+};
|
|
|
+</script>
|
|
|
+<template>
|
|
|
+ <Modal class="w-[1000px]" title="数据范围">
|
|
|
+ <Form>
|
|
|
+ <template #relationIds="slotProps">
|
|
|
+ <Spin :spinning="state.loadingTree" wrapper-class-name="w-full">
|
|
|
+ <VbenTree
|
|
|
+ :tree-data="state.treeData"
|
|
|
+ multiple
|
|
|
+ :bordered="false"
|
|
|
+ v-bind="slotProps"
|
|
|
+ :default-expanded-level="2"
|
|
|
+ value-field="value"
|
|
|
+ label-field="label"
|
|
|
+ />
|
|
|
+ </Spin>
|
|
|
+ </template>
|
|
|
+ </Form>
|
|
|
+ </Modal>
|
|
|
+</template>
|
|
|
+<style lang="less" scoped></style>
|