import Vue from "vue";
import VueRouter from "vue-router";

if (process.env.NODE_ENV === "development") {
    Vue.use(VueRouter);
}

import {ROUTER_MODE} from "../config/app";

import Home from "../views/home/index.vue";
import Empty from "../views/home/Empty.vue";

import showText from "../views/other/showText";

// 权限管理相关
import authAdmin from "../views/userManage/admin/authAdmin.vue";
import authRole from "../views/userManage/admin/authRole.vue";
import authPermissionRule from "../views/userManage/admin/authPermissionRule.vue";
import systemParamConfig from "../views/userManage/param/systemParamConfig.vue";


import thrProductsImport from "../views/sync/ThrProductsImport.vue";
import thrOrderImport from "../views/sync/ThrOrderImport.vue";
import udiInfoImport from "../views/sync/UdiInfoImport.vue";
import corpImport from "../views/sync/CorpImport.vue";
import udiInfoUpload from "../views/sync/SpUdiInfoUpload.vue";
import spOrderFloder from "../views/sync/SpOrderFloder";
import SpBasicFolder from "../views/sync/SpBasicFolder";

//数据同步
import sysUploadData from "../views/sync/SysUploadData.vue";
import sysDownloadData from "../views/sync/SysDownloadData.vue";


const err401 = r =>
    require.ensure([], () => r(require("../views/error/err401.vue")), "home");

const register = r =>
    require.ensure([], () => r(require("../views/userManage/register.vue")), "home");

const registerApp = r =>
    require.ensure([], () => r(require("../views/userManage/registerApp.vue")), "home");

const forgetPasswd = r =>
    require.ensure([], () => r(require("../views/userManage/forgetPasswd.vue")), "home");

const err404 = r =>
    require.ensure([], () => r(require("../views/error/err404.vue")), "home");
const login = r =>
    require.ensure([], () => r(require("../views/login/index.vue")), "home");
const main = r =>
    require.ensure([], () => r(require("../views/home/main.vue")), "home");

// 注意 权限字段 authRule （严格区分大小写）
export const constantRouterMap = [
    {
        path: "*",
        component: err404,
        hidden: true
    },
    {
        path: "/401",
        component: err401,
        name: "401",
        hidden: true
    },
    {
        path: "/404",
        component: err404,
        name: "404",
        hidden: true
    },
    {
        path: "/500",
        component: err404,
        name: "500",
        hidden: true
    },

    {
        path: "/login",
        component: login,
        name: "登录",
        hidden: true
    },
    {
        path: "/register",
        component: register,
        name: "注册",
        hidden: true
    },
    {
        path: "/registerApp",
        component: registerApp,
        name: "注册",
        hidden: true
    },

    {
        path: "/forgetPasswd",
        component: forgetPasswd,
        name: "忘记密码",
        hidden: true
    },


    {
        path: "/",
        icon: "shouye",
        component: Home,
        redirect: "main",
        name: "首页",
        hidden: true,
        noDropdown: true,
        children: [
            {
                path: "main",
                component: main,
                name: "首页",
            },
        ]
    },

    {
        path: "/",
        icon: "showText",
        component: showText,
        redirect: "showText",
        name: "文本",
        hidden: true,
        noDropdown: true,
        children: [
            {
                path: "showText",
                component: showText,
                name: "文本",
            },
        ]
    },


];

export default new VueRouter({
    // mode: 'history', //后端支持可开
    mode: ROUTER_MODE,
    routes: constantRouterMap,
    strict: process.env.NODE_ENV !== "production"
});

export const asyncRouterMap = [

    {
        path: "/userManage",
        redirect: "/userManage/adminManage/index",
        component: Home,
        icon: "guanliyuan1",
        name: "系统管理",
        hidden: false,
        meta: {
            authRule: ["user_manage"]
        },

        // noDropdown: true,
        children: [

            {
                path: "authAdmin",
                component: authAdmin,
                name: "用户管理",
                icon: "",
                meta: {
                    authRule: ["admin/auth_admin"]
                }
            },


            {
                path: "authRole",
                component: authRole,
                hidden: true,
                name: "角色管理",
                icon: "",
                meta: {
                    authRule: ["admin/auth_role"]
                }
            },
            {
                path: "authPermissionRule",
                component: authPermissionRule,
                hidden: true,
                name: "权限管理",
                icon: "",
                meta: {
                    authRule: ["admin/auth_permission_rule"]
                }
            },

            {
                path: "systemParamConfig",
                component: systemParamConfig,
                name: "运行参数",
                icon: "",
                meta: {
                    authRule: ["admin/systemParamConfig"]
                },
            },
        ]
    },

    {
        path: "/spsync",
        redirect: "/spsync/udiInfoUpload",
        component: Home,
        icon: "tongyong",
        name: "数据同步",
        hidden: false,
        noDropdown: false,
        meta: {
            authRule: ["spsync"]
        },
        children: [
            {
                path: "sysUploadData",
                component: sysUploadData,
                name: "接收&上传记录",
                icon: "",
                meta: {
                    authRule: ["spsync/sysUploadData"]
                }
            },
            {
                path: "sysDownloadData",
                component: sysDownloadData,
                name: "下载&同步记录",
                icon: "",
                meta: {
                    authRule: ["spsync/sysDownloadData"]
                }
            },

        ]
    },
];
