/*
 * @Author: zy1125 1515706227@qq.com
 * @Date: 2023-11-09 09:07:06
 * @LastEditors: zy1125 1515706227@qq.com
 * @LastEditTime: 2023-12-25 13:59:36
 * @FilePath: \v3_yyz\src\router\index.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { createRouter, createWebHashHistory } from 'vue-router'
import Home from '../components/UeVideo.vue'
import Login from '../components/Login.vue'
import { getvalidateLogin } from '../request/api2'

const routes = [

  {
    path: '/',
    name: 'Home',
    component: Home
  },
  {
    path: '/login',
    name: 'Login',
    component: Login
  }
]

const router = createRouter({
  history: createWebHashHistory(),
  routes
})


router.beforeEach(function (to, from, next) {

  let urlA = location.href.indexOf('ticket')
  if (urlA == -1) {
    if (to.path == '/') {
      return next('/login')
    }
  } else {
    const url = window.location.href;
    const paramStr = url.split("?")[1].split("#")[0];
    // console.log('sadasd' ,paramStr);
    let query = {
      casLoginUrl: "https://cas.huanghuai.edu.cn/cas/serviceValidate?" + paramStr + '&service=https://weizhi.huanghuai.edu.cn/xyyzioc/#/'
    }
    console.log('aslddddd',query);
    getvalidateLogin(query).then(res => {

      
      console.log('yzzzzzzz',res);
      let resjson=res
      console.log('asdjbasbd',typeof(resjson));

      if (resjson.indexOf('INVALID_TICKET')!==-1) {
        console.log('校验失效了');
        window.location.href='https://cas.huanghuai.edu.cn/cas/?service=https://weizhi.huanghuai.edu.cn/xyyzioc/#/'
      }

    })

  }
  next()
})

export default router
