|
@@ -75,8 +75,7 @@
|
|
|
</template>
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
-import { ref, reactive, onBeforeMount, watch } from "vue";
|
|
|
-import { EditRole } from "@/api/apiAuthority";
|
|
|
+import { ref, onBeforeMount, watch } from "vue";
|
|
|
import { Query, GeneralDataReception } from "@/api/dataIntegration";
|
|
|
import { translateDataToTreeAll } from "@/utils/validate";
|
|
|
import { ElMessage, ElTree } from "element-plus";
|
|
@@ -98,31 +97,34 @@ const form = ref({
|
|
|
edit_row_condition: "",
|
|
|
edit_col_condition: "",
|
|
|
});
|
|
|
+const maxReq = ref(20);
|
|
|
+const proAll = ref<any>([]);
|
|
|
+const proNum = ref(0);
|
|
|
const checkObj = ref<any>(null);
|
|
|
const data = ref<any>([]);
|
|
|
const newData = ref<any>([]);
|
|
|
const checkData = ref<any>([]);
|
|
|
-const checkKeys = ref<any>([]);
|
|
|
+const checkKeys = ref<any>([-1]);
|
|
|
+const boxData = ref<any>([]);
|
|
|
const treeRef = ref<InstanceType<typeof ElTree>>();
|
|
|
onBeforeMount(() => {
|
|
|
roleDetails();
|
|
|
getTree();
|
|
|
- roleAuths();
|
|
|
});
|
|
|
|
|
|
watch(
|
|
|
() => form,
|
|
|
(newValue) => {
|
|
|
newData.value.forEach((item) => {
|
|
|
+ if (item.children) {
|
|
|
+ delete item.children;
|
|
|
+ }
|
|
|
if (item.auth_id == checkObj.value.auth_id) {
|
|
|
item = Object.assign(item, newValue.value);
|
|
|
- checkData.value.push(item);
|
|
|
- const datas = _.unionBy(checkData.value, "auth_id");
|
|
|
- checkData.value = datas;
|
|
|
}
|
|
|
});
|
|
|
checkKeys.value = [checkObj.value.auth_id];
|
|
|
- data.value = [tree.setTree(newData.value)];
|
|
|
+ toTree();
|
|
|
},
|
|
|
{ deep: true }
|
|
|
);
|
|
@@ -142,11 +144,64 @@ const roleDetails = async () => {
|
|
|
} catch (error) {}
|
|
|
};
|
|
|
|
|
|
+const toTree = () => {
|
|
|
+ data.value = [];
|
|
|
+ const chks = treeRef.value!.getCheckedNodes(false, true);
|
|
|
+ const arr = translateDataToTreeAll(newData.value, "up_auth_id", "auth_id");
|
|
|
+ const items = {
|
|
|
+ auth_id: -1,
|
|
|
+ auth_name: "所有权限",
|
|
|
+ auth_status: 0,
|
|
|
+ up_auth_id: -2,
|
|
|
+ auth_type: 0,
|
|
|
+ children: arr,
|
|
|
+ disabled: true,
|
|
|
+ };
|
|
|
+ data.value = [items];
|
|
|
+ if (chks && chks.length) {
|
|
|
+ checkBox(chks, newData.value);
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
//权限树
|
|
|
const getTree = async () => {
|
|
|
- const res = await tree.getTree();
|
|
|
- newData.value = await tree.newData.value;
|
|
|
- data.value = res.value;
|
|
|
+ try {
|
|
|
+ const { returnData, code } = await Query({
|
|
|
+ id: DATACONTENT_ID.authTreeNewId,
|
|
|
+ dataContent: [sessionStorage.getItem("User_Id")],
|
|
|
+ });
|
|
|
+ if (code == 0 && returnData.listValues) {
|
|
|
+ newData.value = _.cloneDeep(returnData.listValues);
|
|
|
+ toTree();
|
|
|
+ roleAuths();
|
|
|
+ } else {
|
|
|
+ }
|
|
|
+ } catch (error) {}
|
|
|
+ // const res = await tree.getTree();
|
|
|
+ // newData.value = await tree.newData.value;
|
|
|
+ // data.value = res.value;
|
|
|
+};
|
|
|
+
|
|
|
+const checkBox = (arr, all) => {
|
|
|
+ const checks: any = [];
|
|
|
+ const nots = _.cloneDeep(arr);
|
|
|
+ const caps = _.cloneDeep(all);
|
|
|
+ arr.forEach((item) => {
|
|
|
+ checks.push(item.auth_id);
|
|
|
+ });
|
|
|
+ const res = [...caps, ...nots].filter(
|
|
|
+ (item) =>
|
|
|
+ !(
|
|
|
+ caps.some((p) => item.auth_id == p.auth_id) &&
|
|
|
+ nots.some((c) => item.auth_id == c.auth_id)
|
|
|
+ )
|
|
|
+ );
|
|
|
+ treeRef.value!.setCheckedKeys(checks);
|
|
|
+ setTimeout(() => {
|
|
|
+ res.forEach((item) => {
|
|
|
+ treeRef.value!.setChecked(item.auth_id, false, false);
|
|
|
+ });
|
|
|
+ }, 0);
|
|
|
};
|
|
|
|
|
|
//权限详情
|
|
@@ -157,11 +212,8 @@ const roleAuths = async () => {
|
|
|
dataContent: [role_id],
|
|
|
});
|
|
|
if (code == 0 && returnData.listValues) {
|
|
|
- const datas: any = [];
|
|
|
- returnData.listValues.forEach((item) => {
|
|
|
- datas.push(item.auth_id);
|
|
|
- });
|
|
|
- treeRef.value!.setCheckedKeys(datas, false);
|
|
|
+ boxData.value.push(returnData.listValues);
|
|
|
+ checkBox(returnData.listValues, newData.value);
|
|
|
} else {
|
|
|
ElMessage.error(message);
|
|
|
}
|
|
@@ -170,6 +222,9 @@ const roleAuths = async () => {
|
|
|
|
|
|
const handleNodeClick = (data) => {
|
|
|
checkObj.value = data;
|
|
|
+ checkData.value.push(_.cloneDeep(data));
|
|
|
+ const datas = _.unionBy(checkData.value, "auth_id");
|
|
|
+ checkData.value = datas;
|
|
|
const checkNode = checkData.value.filter(
|
|
|
(item) => item.auth_id == data.auth_id
|
|
|
);
|
|
@@ -192,7 +247,124 @@ const clearFormData = () => {
|
|
|
|
|
|
const currentChange = () => {
|
|
|
const datas = treeRef.value!.getCheckedNodes(false, true);
|
|
|
- console.log(datas);
|
|
|
+ datas.forEach((item, index) => {
|
|
|
+ if (item.auth_id == -1) {
|
|
|
+ datas.splice(index, 1);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ boxData.value.push(datas);
|
|
|
+ const data1 = boxData.value[boxData.value.length - 1]; //最后一条数据
|
|
|
+ const data2 = boxData.value[boxData.value.length - 2]; //倒数第二条数据
|
|
|
+ if (data1.length > data2.length) {
|
|
|
+ checksBoxTs(data1, data2, "add");
|
|
|
+ } else {
|
|
|
+ checksBoxTs(data2, data1, "del");
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
+const checksBoxTs = async (datas, arr, type) => {
|
|
|
+ const res = [...datas, ...arr].filter(
|
|
|
+ (item) =>
|
|
|
+ !(
|
|
|
+ datas.some((p) => item.auth_id == p.auth_id) &&
|
|
|
+ arr.some((c) => item.auth_id == c.auth_id)
|
|
|
+ )
|
|
|
+ );
|
|
|
+ const [msg1, msg2] = [<any>[], <any>[]];
|
|
|
+ if (res && res.length) {
|
|
|
+ for (let i = 0; i < res.length; i++) {
|
|
|
+ delete res[i].children;
|
|
|
+ let obj = <any>{
|
|
|
+ auth_id: res[i].auth_id || res[i].AuthId,
|
|
|
+ role_id: role_id,
|
|
|
+ };
|
|
|
+ let authObj = res[i].AuthList
|
|
|
+ ? Object.assign(_.cloneDeep(obj), res[i].AuthList)
|
|
|
+ : Object.assign(_.cloneDeep(obj), res[i]);
|
|
|
+ if (type == "add") {
|
|
|
+ obj.event = 1;
|
|
|
+ authObj.event = 1;
|
|
|
+ msg1.push(obj);
|
|
|
+ msg2.push(authObj);
|
|
|
+ } else {
|
|
|
+ obj.event = 3;
|
|
|
+ authObj.event = 3;
|
|
|
+ msg1.push(obj);
|
|
|
+ msg2.push(authObj);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ GeneralDataReception({
|
|
|
+ serviceId: SERVICE_ID.roleMsgTreeId,
|
|
|
+ dataContent: JSON.stringify(msg1),
|
|
|
+ }).then((result) => {
|
|
|
+ if (result.code == 0) {
|
|
|
+ if (type == "add") {
|
|
|
+ ElMessage.success("操作权限成功");
|
|
|
+ } else {
|
|
|
+ ElMessage.success("操作权限成功");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (type == "add") {
|
|
|
+ ElMessage.error("操作权限失败");
|
|
|
+ } else {
|
|
|
+ ElMessage.error("操作权限失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ if (msg2.length > maxReq.value) {
|
|
|
+ foxFunc(msg2);
|
|
|
+ } else {
|
|
|
+ GeneralDataReception({
|
|
|
+ serviceId: SERVICE_ID.roleMsgAuthId,
|
|
|
+ dataContent: JSON.stringify(msg2),
|
|
|
+ }).then((result) => {
|
|
|
+ if (result.code == 0) {
|
|
|
+ if (type == "add") {
|
|
|
+ ElMessage.success("操作规则成功");
|
|
|
+ } else {
|
|
|
+ ElMessage.success("操作规则成功");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (type == "add") {
|
|
|
+ ElMessage.error("操作规则失败");
|
|
|
+ } else {
|
|
|
+ ElMessage.error("操作规则失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // this.$message.error('未选中数据')
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
+const foxFunc = async (arr?: Array<any>) => {
|
|
|
+ if (proAll.value.length == 0) {
|
|
|
+ proAll.value = _.cloneDeep(arr);
|
|
|
+ }
|
|
|
+ const limit = _.chunk(proAll.value, maxReq.value);
|
|
|
+ const reqUts = [];
|
|
|
+ limit.forEach((item, index) => {
|
|
|
+ const req = GeneralDataReception({
|
|
|
+ serviceId: SERVICE_ID.roleMsgAuthId,
|
|
|
+ dataContent: JSON.stringify(limit[index]),
|
|
|
+ });
|
|
|
+ reqUts.push(req);
|
|
|
+ });
|
|
|
+ const result = Promise.all(reqUts);
|
|
|
+ const resultLen = await result;
|
|
|
+ if (limit.length == resultLen.length) {
|
|
|
+ proAll.value = [];
|
|
|
+ proNum.value = 0;
|
|
|
+ ElMessage.success("操作规则成功");
|
|
|
+ } else {
|
|
|
+ proNum.value += 1;
|
|
|
+ if (proNum.value == 4) {
|
|
|
+ ElMessage.success("网络错误,请稍后重试");
|
|
|
+ } else {
|
|
|
+ foxFunc();
|
|
|
+ }
|
|
|
+ }
|
|
|
};
|
|
|
|
|
|
const defaultProps = {
|