美文网首页
vue混入和async await的用法

vue混入和async await的用法

作者: jesse28 | 来源:发表于2022-08-18 14:19 被阅读0次

    混入:

    
    import dataPermission from "@/dataPermissionMixins";
    export default {
      data() {
        return {
          activeName: "unfinished",
          isLoading: false,
          pageNum: 1,
          pageSize: 10,
          total: 0,
          params: {},
        };
      },
      mixins: [dataPermission],
      components: { UnfinishedList, FinishedList, DiscreditList },
      mounted() {
      
      },
    

    async await

    
    
    import {
        getLoginUserAvailableUnitForOptionApi,
        getLoginUserAvailableDepForOptionApi,
        getLoginUserAvailableUserForOptionApi,
    } from "@/api/dataFilters";
    const dataPermission = {
        data() {
            return {
                params: {},
            }
        },
        mounted() {
            this.getAccessControl();
        },
        methods: {
            async getAccessControl() {
                //获取可见单位
                let visibleUnitRes;
                //获取可见部门
                let visibleDepRes;
                //获取可见人员
                let visibleUserRes;
                visibleUnitRes = await getLoginUserAvailableUnitForOptionApi();
                console.log("获取单位", visibleUnitRes);
                if (visibleUnitRes && visibleUnitRes.length >= 1) {
                    this.params.unitId = visibleUnitRes[0].id;
                    //然后再获取部门数据
                    visibleDepRes = await getLoginUserAvailableDepForOptionApi({
                        limit: -1,
                        page: 1,
                        unitId: visibleUnitRes[0].id,
                    });
                    console.log("获取部门", visibleDepRes);
                    if (visibleDepRes && visibleDepRes.length >= 1) {
                        //如果大于就给params加入depIds参数
                        this.params.depIds = visibleDepRes.map((v) => v.id);
                        visibleUserRes = await getLoginUserAvailableUserForOptionApi({
                            unitId: this.params.unitId,
                            limit: -1,
                            page: 1,
                            depIds: this.params.depIds,
                        });
                        console.log("获取人员", visibleUserRes);
                    } else {
                        this.params.depIds = [];
                        visibleUserRes = await getLoginUserAvailableUserForOptionApi({
                            unitId: this.params.unitId,
                            limit: -1,
                            page: 1,
                            depIds: this.params.depIds,
                        });
                    }
                } else {
                    //一并处理部门和人员  (不穿参数调接口)
                    this.params.unitId = "";
                    visibleDepRes = await getLoginUserAvailableDepForOptionApi({
                        limit: -1,
                        page: 1,
                        unitId: "",
                    });
                    if (visibleDepRes && visibleDepRes.length <= 0) {
                        this.params.depIds = [];
                        visibleUserRes = await getLoginUserAvailableUserForOptionApi({
                            unitId: this.params.unitId,
                            limit: -1,
                            page: 1,
                            depIds: this.params.depIds,
                        });
                    } else {
                        this.params.depIds = visibleDepRes.map((v) => v.id);
                        visibleUserRes = await getLoginUserAvailableUserForOptionApi({
                            unitId: this.params.unitId,
                            limit: -1,
                            page: 1,
                            depIds: this.params.depIds,
                        });
                    }
                }
                let visibleUserList = visibleUserRes && visibleUserRes.list;
                console.log("visibleUserList", visibleUserList);
                if (visibleUserList && visibleUserList.length >= 1) {
                    this.params.userId = visibleUserList[0].id;
                } else {
                    this.params.userId = "";
                }
                console.log('this.params混入的', this.params)
                this.onQuery();
            },
        }
    }
    export default dataPermission;
    

    相关文章

      网友评论

          本文标题:vue混入和async await的用法

          本文链接:https://www.haomeiwen.com/subject/wulugrtx.html