|
@@ -6,11 +6,11 @@
|
|
|
<p class="tree-label">权限</p>
|
|
|
<a-tree
|
|
|
checkable
|
|
|
- :tree-data="fakeTree"
|
|
|
+ :tree-data="allowRule"
|
|
|
showLine
|
|
|
defaultExpandAll
|
|
|
:replace-fields="replaceFields"
|
|
|
- v-model:checkedKeys="checkedKeys"
|
|
|
+ v-model:checkedKeys="rules"
|
|
|
>
|
|
|
</a-tree>
|
|
|
</div>
|
|
@@ -18,18 +18,21 @@
|
|
|
</template>
|
|
|
<script lang="ts">
|
|
|
import { Tree } from 'ant-design-vue';
|
|
|
- import { defineComponent, PropType, reactive, ref, toRefs, watch } from 'vue';
|
|
|
+ import { defineComponent, PropType, reactive, ref, toRefs } from 'vue';
|
|
|
import { BasicModal, useModalInner } from '/@/components/Modal';
|
|
|
import { BasicForm, useForm } from '/@/components/Form/index';
|
|
|
- import { schemas, fakeTree } from './data';
|
|
|
+ import { schemas } from './data';
|
|
|
+ import { getAllowRule } from '/@/api/sys/user';
|
|
|
|
|
|
interface PopupData {
|
|
|
title: string;
|
|
|
treeData: object[];
|
|
|
- checkedKeys: string[];
|
|
|
}
|
|
|
- interface Role {
|
|
|
- id: string | number;
|
|
|
+ interface ReactData {
|
|
|
+ id: number | string;
|
|
|
+ allowRule: object[];
|
|
|
+ initRules: number[];
|
|
|
+ rules: number[];
|
|
|
}
|
|
|
|
|
|
export default defineComponent({
|
|
@@ -41,8 +44,11 @@
|
|
|
},
|
|
|
},
|
|
|
setup(props, { emit }) {
|
|
|
- const role = reactive<Role>({
|
|
|
+ const reactData = reactive<ReactData>({
|
|
|
id: 0,
|
|
|
+ allowRule: [],
|
|
|
+ initRules: [],
|
|
|
+ rules: [],
|
|
|
});
|
|
|
const popupData: PopupData = props.popupData;
|
|
|
console.log('======popupdata========1');
|
|
@@ -51,9 +57,9 @@
|
|
|
const replaceFields = {
|
|
|
key: 'id',
|
|
|
};
|
|
|
- watch(popupData, () => {
|
|
|
- console.log('checkedKeys', popupData.checkedKeys);
|
|
|
- });
|
|
|
+ // watch(reactData, () => {
|
|
|
+ // console.log('rules', reactData.rules);
|
|
|
+ // });
|
|
|
|
|
|
const [
|
|
|
registerForm,
|
|
@@ -72,33 +78,59 @@
|
|
|
// setFieldsValue(data);
|
|
|
// }
|
|
|
if (data.id) {
|
|
|
- role.id = data.id;
|
|
|
+ reactData.id = data.id;
|
|
|
+ }
|
|
|
+ getRuleTree(data.pid);
|
|
|
+ if (data.rules) {
|
|
|
+ reactData.initRules = data.rules.split(',');
|
|
|
+ reactData.initRules = reactData.initRules.map((item) => parseInt(item));
|
|
|
}
|
|
|
+ console.log(`reactData.rules`, reactData.rules);
|
|
|
+
|
|
|
setFieldsValue(data);
|
|
|
updateSchema({
|
|
|
field: 'pname',
|
|
|
- componentProps: { treeData: popupData.treeData },
|
|
|
+ componentProps: {
|
|
|
+ onChange: (e: ChangeEvent) => {
|
|
|
+ console.log('===========onChange1====ddd===');
|
|
|
+ console.log(e);
|
|
|
+ getRuleTree(e);
|
|
|
+ },
|
|
|
+ treeData: popupData.treeData,
|
|
|
+ },
|
|
|
});
|
|
|
});
|
|
|
|
|
|
+ async function getRuleTree(id) {
|
|
|
+ console.log(`id`, id);
|
|
|
+ if (!id) {
|
|
|
+ id = 1;
|
|
|
+ }
|
|
|
+ await getAllowRule({ id }).then((res) => {
|
|
|
+ console.log(res);
|
|
|
+ reactData.allowRule = res.tree;
|
|
|
+ if (reactData.initRules) {
|
|
|
+ reactData.rules = [];
|
|
|
+ reactData.allowRule.map((item) => {
|
|
|
+ if (reactData.initRules.includes(item.id)) {
|
|
|
+ reactData.rules.push(item.id);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ console.log(` reactData.rules`, reactData.rules);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
function confirm() {
|
|
|
console.log('确定');
|
|
|
const data = getFieldsValue();
|
|
|
- data.menus = popupData.checkedKeys;
|
|
|
- data.menus2 = [...popupData.checkedKeys];
|
|
|
- if (role.id) {
|
|
|
- data.id = role.id;
|
|
|
+ data.rules = [...reactData.rules];
|
|
|
+ if (reactData.id) {
|
|
|
+ data.id = reactData.id;
|
|
|
}
|
|
|
data.pid = data.pname;
|
|
|
// delete data.pname;
|
|
|
console.log(`data`, data);
|
|
|
- // const data = {
|
|
|
- // info,
|
|
|
- // }
|
|
|
- // console.log(data)
|
|
|
- // console.log(getFieldsValue()) // 表单数据
|
|
|
- // console.log('------ 菜单key ------')
|
|
|
- // console.log(popupData.checkedKeys)
|
|
|
const childerData = { closeModal, data };
|
|
|
emit('saveData', childerData);
|
|
|
}
|
|
@@ -109,8 +141,8 @@
|
|
|
replaceFields,
|
|
|
model: modelRef,
|
|
|
confirm,
|
|
|
- fakeTree,
|
|
|
...toRefs(popupData),
|
|
|
+ ...toRefs(reactData),
|
|
|
};
|
|
|
},
|
|
|
});
|