export default {

    data(){
        return {
            component:'',
            componentDraw:{}
        }
    },

    watch:{

        page:{
            handler(){
                if (this.page) {
                    return this.openPage(this.page);
                }
            },
            immediate:true
        }

    },

    provide(){
      return {

          // 打开页面
          openPage: (name:string,params?:Record<string, any>)=> this.openPage(name,params),

          // 返回页面参数
          getPageParams:(name:string)=> {
              return this.componentParams[name];
          }

      }
    },

    methods:{

        openPage(name:string,params?:Record<string, any>){

            if (name && this.component !== name) {

                // 设置渲染
                if (this.componentDraw[name] !== true) {
                    this.componentDraw[name] = true;
                }

                if (this.componentParams === undefined) {
                    this.componentParams = {};
                }
                // 重新设置 参数
                this.componentParams[name] = params;

                this.component = name;

            }

        }

    },

    created() {
        this.componentParams = {};
    }

}