import { createRouter, createWebHistory } from 'vue-router'
import axios from '@/axios'
import { requestSignature, wxReady } from '@/router/initWxSdk'
import { ref } from 'vue';
import { showFailToast } from 'vant';

const router = createRouter({
	history: createWebHistory('/sgsafeh5/'),
	routes: [
		{
			path: '/login',
			name: 'Login',
			component: () => import('@/view/login/index.vue'),
			meta: { requiresAuth: false }
		},
		{
			path: '/login401',
			name: 'login401',
			component: () => import('@/view/login/index401.vue'),
			meta: { requiresAuth: false }
		},
		{
			path: '/Home1',
			component: () => import('@/view/Home1.vue'),
			meta: { requiresAuth: true }
		},
		{
			path: '/',
			redirect: '/Home1'
		},
		{
			path: '/error',
			name: 'error',
			component: () => import('@/view/biz/error/index.vue'),
			meta: { requiresAuth: false }
		},
		{
			path: '/biz/bas/basPartnerH5',
			name: 'basPartnerH5',
			component: () => import('@/view/biz/bas/basPartnerH5.vue'),
			meta: { requiresAuth: false }
		},
		{
			path: '/biz/cot/purContract',
			name: 'purContract',
			component: () => import('@/view/biz/cot/purContract.vue'),
			meta: { requiresAuth: false }
		},
		{
			path: '/biz/cot/salContract',
			name: 'salContract',
			component: () => import('@/view/biz/cot/salContract.vue'),
			meta: { requiresAuth: false }
		},
		{
			path: '/biz/cot/serviceContract',
			name: 'serviceContract',
			component: () => import('@/view/biz/cot/serviceContract.vue'),
			meta: { requiresAuth: false }
		},
		{
			path: '/biz/cot/signRequest',
			name: 'signRequest',
			component: () => import('@/view/biz/cot/signRequest.vue'),
			meta: { requiresAuth: false }
		},
		{
			path: '/biz/pur/purActFinance',
			name: 'purActFinance',
			component: () => import('@/view/biz/pur/purActFinance.vue'),
			meta: { requiresAuth: false }
		},
		{
			path: '/biz/pur/purBillFinance',
			name: 'purBillFinance',
			component: () => import('@/view/biz/pur/purBillFinance.vue'),
			meta: { requiresAuth: false }
		},
		{
			path: '/biz/pur/purPayReqFinance',
			name: 'purPayReqFinance',
			component: () => import('@/view/biz/pur/purPayReqFinance.vue'),
			meta: { requiresAuth: false }
		},
		{
			path: '/biz/pur/purPayRefundFinance',
			name: 'purPayRefundFinance',
			component: () => import('@/view/biz/pur/purPayRefundFinance.vue'),
			meta: { requiresAuth: false }
		},
		{
			path: '/biz/sal/collectionInfoH5',
			name: 'collectionInfoH5',
			component: () => import('@/view/biz/sal/collectionInfoH5.vue'),
			meta: { requiresAuth: false }
		},
		{
			path: '/biz/sal/salPlanH5',
			name: 'salPlanH5',
			component: () => import('@/view/biz/sal/salPlanH5.vue'),
			meta: { requiresAuth: false }
		},
		{
			path: '/biz/sal/salResultH5',
			name: 'salResultH5',
			component: () => import('@/view/biz/sal/salResultH5.vue'),
			meta: { requiresAuth: false }
		},
		{
			path: '/biz/sal/salRetreatH5',
			name: 'salRetreatH5',
			component: () => import('@/view/biz/sal/salRetreatH5.vue'),
			meta: { requiresAuth: false }
		},
		{
			path: '/biz/sal/salUpriceH5',
			name: 'salUpriceH5',
			component: () => import('@/view/biz/sal/salUpriceH5.vue'),
			meta: { requiresAuth: false }
		},
		{
			path: "/yinhuan/home",
			name: "yinhuanHome",
			component: () => import("@/view/yinhuan/home.vue"),
		},
		{
			path: "/projectManage/todo_detail/index",
			name: "projectWorkTodoDetail",
			component: () => import("@/view/projectManage/todo_detail/index.vue"),
		},
		{
			path: "/projectManage/todo_detail/index2",
			name: "projectWorkTodoDetail2",
			component: () => import("@/view/projectManage/todo_detail/index2.vue"),
		},
		{
			path: "/yinhuan/todo_detail/index",
			name: "yinhuanTodoDetail",
			component: () => import("@/view/yinhuan/todo_detail/index.vue"),
		},
		{
			path: "/yinhuan/JuBaotodo_detail/index",
			name: "yinhuanJuBaoTodoDetail",
			component: () => import("@/view/yinhuan/JuBaotodo_detail/index.vue"),
		},
		{
			path: "/yinhuan/registration",
			name: "yinhuanRegistration",
			component: () => import("@/view/yinhuan/registration.vue"),
		},
		{
			path: "/yinhuan/hdRwardReporting",
			name: "yinhuanhdRwardReporting",
			component: () => import("@/view/yinhuan/hdRwardReporting.vue"),
		},
		{
			path: "/yinhuan/registration_edit/index",
			name: "registration_edit",
			component: () => import("@/view/yinhuan/registration_edit/index.vue"),
		},
		{
			path: "/yinhuan/JuBaoregistration_edit/index",
			name: "JuBaoregistration_edit",
			component: () => import("@/view/yinhuan/JuBaoregistration_edit/index.vue"),
		},
		{
			path: "/yinhuan/JuBaoregistration_edit/index",
			name: "JuBaoregistration_edit",
			component: () => import("@/view/yinhuan/JuBaoregistration_edit/index.vue"),
		},
		{
			path: "/yinhuan/hdLedger",
			name: "yinhuanHdLedger",
			component: () => import("@/view/yinhuan/hdLedger.vue"),
		},
		{
			path: "/yinhuan/hdLedgerJuBao",
			name: "yinhuanHdLedgerJuBao",
			component: () => import("@/view/yinhuan/hdLedgerJuBao.vue"),
		},
		{
			path: "/yinhuan/hdLedger_detail",
			name: "yinhuanHdLedgerDtail",
			component: () => import("@/view/yinhuan/heLedger_detail/index.vue"),
		},
		{
			path: "/yinhuan/JuBaohdLedger_detail",
			name: "yinhuanJuBaoHdLedgerDtail",
			component: () => import("@/view/yinhuan/JuBaoheLedger_detail/index.vue"),
		},
		{
			path: "/yinhuan/todo",
			name: "yinhuanTodo",
			component: () => import("@/view/yinhuan/todo.vue"),
		},
		{
			path: "/projectManage/todo",
			name: "projectManagetodo",
			component: () => import("@/view/projectManage/todo.vue"),
		},
		{
			path: "/safeCheck/home",
			name: "checkHome",
			component: () => import("@/view/safeCheck/home.vue"),
		},
		{
			path: "/safeCheck/task",
			name: "safeCheckTask",
			component: () => import("@/view/safeCheck/safeCheckTask.vue"),
		},
		{
			path: "/safeCheck/safeCheckTaskEdit",
			name: "safeCheckTaskEdit",
			component: () => import("@/view/safeCheck/safeCheck_edit/index.vue"),
		},
		{
			path: "/safeCheck/safeCheckTaskItem",
			name: "safeCheckTaskItem",
			component: () => import("@/view/safeCheck/safeCheck_item/index.vue"),
		},
		{
			path: "/projectManage/projectIndex",
			name: "projectIndex",
			component: () => import("@/view/projectManage/projectIndex.vue"),
		},
		{
			path: "/projectManage/projectWorkLedger",
			name: "projectWorkLedger",
			component: () => import("@/view/projectManage/projectWorkLedger.vue"),
		},
		{
			path: "/projectManage/taiZhang",
			name: "taiZhang",
			component: () => import("@/view/projectManage/taiZhangV3.vue"),
		},
		{
			path: "/projectManage/taiZhang_detail",
			name: "taiZhang_detail",
			component: () => import("@/view/projectManage/taiZhang_detail/index.vue"),
		},
		{
			path: "/projectManage/taiZhang_edit",
			name: "taiZhang_indexEdit",
			component: () => import("@/view/projectManage/taiZhang_edit/indexEdit.vue"),
		},
		{
			path: "/projectManage/taiZhang_edit",
			name: "taiZhang_edit",
			component: () => import("@/view/projectManage/taiZhang_edit/index.vue"),
		},
		{
			path: "/projectManage/projectConstructionOperation",
			name: "projectConstructionOperation",
			component: () => import("@/view/projectManage/projectConstructionOperation/index.vue"),
		},
		{
			path: "/projectManage/projectConstructionOperation/projectConstructionOperation_detail",
			name: "projectConstructionOperation_detail",
			component: () => import("@/view/projectManage/projectConstructionOperation/projectConstructionOperation_detail/index.vue"),
		},
		{
			path: "/projectManage/projectConstructionOperation/projectConstructionOperation_detail2",
			name: "projectConstructionOperation_detail2",
			component: () => import("@/view/projectManage/projectConstructionOperation/projectConstructionOperation_detail/indexLook.vue"),
		},
		{
			path: "/projectManage/projectConstructionOperation/projectConstructionOperation_detail3",
			name: "projectConstructionOperation_detail3",
			component: () => import("@/view/projectManage/projectConstructionOperation/projectConstructionOperation_detail/indexLookAll.vue"),
		},
		{
			path: "/lvzhi",
			component: () => import("@/view/lvzhi/dutyList.vue"),
		},
		{
			path: "/lvzhicx",
			component: () => import("@/view/lvzhi/listCx.vue"),
		},
		{
			path: "/lz-rcdcx",
			component: () => import("@/view/lvzhi/dutyRecordListCx.vue"),
		},
		{
			path: "/lz-rcd",
			component: () => import("@/view/lvzhi/dutyRecordList.vue"),
		},
		{
			path: "/lz-rcd-detail",
			component: () => import("@/view/lvzhi/newDutyRecord.vue"),
		},
		{
			path: '/institution/law',
			name: 'Law',
			component: () => import("@/view/institution/law.vue")
		},
		{
			path: '/institution/institutionRegime',
			name: 'InstitutionRegime',
			component: () => import("@/view/institution/institutionRegime.vue")
		},
		{
			path: '/institution/institutionRule',
			name: 'InstitutionRule',
			component: () => import("@/view/institution/institutionRule.vue")
		},
		{
			path: '/institution/riskList',
			name: 'RiskList',
			component: () => import("@/view/institution/riskList.vue")
		},
		{
			path: '/institution/emergencyPlan',
			name: 'EmergencyPlan',
			component: () => import("@/view/institution/emergencyPlan.vue")
		},
		{
			path: '/emergencyResources',
			name: 'EmergencyResources',
			component: () => import("@/view/resources/index.vue")
		},
		{
			path: '/resourcesQuery',
			name: 'ResourcesQuery',
			component: () => import("@/view/resources/resourcesQuery.vue")
		},
		{
			path: '/maintenanceRecords',
			name: 'MaintenanceRecords',
			component: () => import("@/view/resources/maintenanceRecords.vue")
		},
		{
			path: '/recordsQuery',
			name: 'RecordsQuery',
			component: () => import("@/view/resources/recordsQuery.vue")
		},
		{
			path: '/cardManager',
			name: 'CardManager',
			component: () => import("@/view/card/index.vue")
		},
		{
			path: '/cardManager/specialWork',
			name: 'SpecialWork',
			component: () => import("@/view/card/CardSpecialWork.vue")
		},
		{
			path: '/cardManager/equipment',
			name: 'Equipment',
			component: () => import("@/view/card/CardEquipment.vue")
		},
		{
			path: '/cardManager/engineer',
			name: 'Card',
			component: () => import("@/view/card/CardEngineer.vue")
		},
		{
			path: '/cardManager/building',
			name: 'Building',
			component: () => import("@/view/card/CardBuilding.vue")
		},
		{
			path: '/cardManager/manager',
			name: 'Manager',
			component: () => import("@/view/card/CardManager.vue")
		},
		{
			path: '/emergencyDrillPlan',
			name: 'EmergencyDrillPlan',
			component: () => import("@/view/drillPlan/index.vue")
		},
		{
			path: '/emergencyDrillPlanEdit',
			name: 'EmergencyDrillPlanEdit',
			component: () => import("@/view/drillPlan/drillPlanEdit.vue")
		},
		{
			path: '/emergencyDrillActEdit',
			name: 'EmergencyDrillActEdit',
			component: () => import("@/view/drillPlan/drillActEdit.vue")
		},
		{
			path: '/checkTake',
			name: '逢查必考',
			component: () => import("@/view/dati/checkTake/index.vue")
		},
		{
			path: '/examtask',
			name: '考试任务',
			component: () => import("@/view/dati/examCheck/index.vue")
		},
		{
			path: '/checkList',
			name: '考试任务表单',
			component: () => import("@/view/dati/examCheck/checkList.vue")
		},

		{
			path: '/addPeo',
			name: '考试人员添加',
			component: () => import("@/view/dati/examCheck/addPeo.vue")
		},
		{
			path: '/dailyproblem',
			name: 'DailyProblem',
			component: () => import("@/view/dati/daily/index.vue")
		},
		{
			path: '/jieguo1',
			name: 'JieGuo1',
			component: () => import("@/view/dati/checkTake/jieguo1.vue")
		},
		{
			path: '/jieguo2',
			name: 'JieGuo2',
			component: () => import("@/view/dati/checkTake/jieguo2.vue")
		},
		{
			path: '/datistart',
			name: 'DatiStart',
			component: () => import("@/view/dati/daily/datistart.vue")
		},
		{
			path: '/jieguo',
			name: 'JieGuo',
			component: () => import("@/view/dati/daily/jieguo.vue")
		},
		{
			path: '/paiming',
			name: 'PaiMing',
			component: () => import("@/view/dati/daily/paiming.vue")
		},
		{
			path: '/home2',
			name: 'Home2',
			component: () => import("@/view/Home2.vue")
		},
		{
			path: '/homeRole',
			name: 'HomeRole',
			component: () => import("@/view/HomeRole.vue")
		},
		{
			path: '/oldHome',
			name: 'OldHome',
			component: () => import("@/view/Home.vue")
		},
		{
			path: '/pendingMatters',
			name: 'PendingMatters',
			component: () => import("@/view/pendingMatters/index.vue")
		},
		{
			path: '/safeClient',
			name: 'SafeClient',
			component: () => import("@/view/onsiteProcessControl/safeClient.vue")
		},
		{
			path: '/jobCondition',
			name: 'JobCondition',
			component: () => import("@/view/onsiteProcessControl/jobCondition.vue")
		},
		{
			path: '/yinhuan/riskChecklist',
			name: 'RiskChecklist',
			component: () => import("@/view/yinhuan/riskChecklist.vue")
		},
		{
			path: '/yinhuan/riskChecklistView',
			name: 'RiskChecklistView',
			component: () => import("@/view/yinhuan/riskChecklistView.vue")
		},
		{
			path: '/yinhuan/riskChecklistRecords',
			name: 'RiskChecklistRecords',
			component: () => import("@/view/yinhuan/riskChecklistRecords.vue")
		},
		{
			path: '/yinhuan/riskChecklistRecordsView',
			name: 'RiskChecklistRecordsView',
			component: () => import("@/view/yinhuan/riskChecklistRecordsView.vue")
		},
		{
			path: '/drillProcess',
			name: 'DrillProcess',
			component: () => import("@/view/drillPlan/drillProcess.vue")
		},
		{
			path: '/specificSteps',
			name: 'SpecificSteps',
			component: () => import("@/view/drillPlan/specificSteps.vue")
		},
		{
			path: '/specificStepsView',
			name: '/SpecificStepsView',
			component: () => import("@/view/drillPlan/specificStepsView.vue")
		},
		{
			path: '/assRec',
			name: '/考核登记首页',
			component: () => import("@/view/performance/assRec.vue")
		},
		{
			path: '/asscheckList',
			name: '/考核登记新增',
			component: () => import("@/view/performance/checkList.vue")
		},
		{
			path: '/assRecN',
			name: '/考核记录',
			component: () => import("@/view/performance/assRecN.vue")
		},
		{
			path: '/learning',
			name: 'Learning',
			component: () => import('@/view/performance/learning.vue')
		},
		{
			path: '/annex',
			name: '文件发布',
			component: () => import('@/view/announ/annex.vue')
		},
		{
			path: '/annexList',
			name: '文件发布新增',
			component: () => import('@/view/announ/annexList.vue')
		},
		{
			path: '/notice',
			name: '通知公告',
			component: () => import('@/view/announ/notice.vue')
		},
		{
			path: '/noticeList',
			name: '通知公告新增',
			component: () => import('@/view/announ/noticeList.vue')
		},
		{
			path: '/keyMatters',
			name: '重点事项',
			component: () => import('@/view/keyMatters/index.vue')
		},
		{
			path: '/keyMatters/view',
			name: '重点事项查看',
			component: () => import('@/view/keyMatters/view.vue')
		},
		{
			path: '/keyMatters/report',
			name: '重点事项汇报',
			component: () => import('@/view/keyMatters/report.vue')
		},
		{
			path: '/planManagement',
			name: '计划管理',
			component: () => import('@/view/planManagement/index.vue')
		},
		{
			path: '/planManagement/manifest',
			name: '任务清单',
			component: () => import('@/view/planManagement/manifest.vue')
		},
		{
			path: '/planManagement/manifestView',
			name: '任务清单查看',
			component: () => import('@/view/planManagement/manifestView.vue')
		},
		{
			path: '/planManagement/manifestReport',
			name: '任务清单汇报',
			component: () => import('@/view/planManagement/manifestReport.vue')
		},
		{
			path: '/performanceReview/units',
			name: '单位绩效评估',
			component: () => import('@/view/performanceReview/units.vue')
		},
		{
			path: '/accidentManager/accidentBaoGaoLedger/index',
			name: 'accidentBaoGaoLedger',
			component: () => import('@/view/accidentManager/accidentBaoGaoLedger/index.vue')
		},
		{
			path: '/accidentManager/accidentJuBao/index',
			name: 'accidentJuBao',
			component: () => import('@/view/accidentManager/accidentJuBao/index.vue')
		},
		{
			path: '/accidentManager/accidentBaoGaoLedger/accidentBaoGaoLedger_edit/index',
			name: 'accidentBaoGaoLedger_edit',
			component: () => import('@/view/accidentManager/accidentBaoGaoLedger/accidentBaoGaoLedger_edit/index.vue')
		},
		{
			path: '/accidentManager/accidentJuBao/accidentJuBao_edit/index',
			name: 'accidentJuBao_edit',
			component: () => import('@/view/accidentManager/accidentJuBao/accidentJuBao_edit/index.vue')
		},
		{
			path: '/accidentManager/accidentJuBaoLedger/index',
			name: 'accidentJuBaoLedger',
			component: () => import('@/view/accidentManager/accidentJuBaoLedger/index.vue')
		},
		{
			path: '/knowledge/accident',
			name: '事故案例',
			component: () => import('@/view/knowledge/accident.vue')
		},
		{
			path: '/accidentList',
			name: '事故案例编辑',
			component: () => import('@/view/knowledge/accidentList.vue')
		},
		{
			path: '/knowledge/manager',
			name: '管理案例',
			component: () => import('@/view/knowledge/manager.vue')
		},
		{
			path: '/managerList',
			name: '管理案例编辑',
			component: () => import('@/view/knowledge/managerList.vue')
		},
		{
			path: '/knowledge/Culture',
			name: '安全文化',
			component: () => import('@/view/knowledge/Culture.vue')
		},
		{
			path: '/CultureList',
			name: '安全文化编辑',
			component: () => import('@/view/knowledge/CultureList.vue')
		},
		{
			path: '/knowledge/project',
			name: '项目案例库',
			component: () => import('@/view/knowledge/project.vue')
		},
		{
			path: '/projectList',
			name: '项目案例库编辑',
			component: () => import('@/view/knowledge/projectList.vue')
		},
		{
			path: '/moneySafe/safeMoneyManagement',
			name: '安环费用管理',
			component: () => import('@/view/moneySafe/safeMoneyManagement.vue')
		},
		{
			path: '/safeMoneyManagementList',
			name: '安环费用管理编辑',
			component: () => import('@/view/moneySafe/safeMoneyManagementList.vue')
		},
		{
			path: '/moneySafe/safeMoneyBudget',
			name: '安全费用预算',
			component: () => import('@/view/moneySafe/safeMoneyBudget.vue')
		},
		{
			path: '/safeMoneyBudgetList',
			name: '安全费用预算编辑',
			component: () => import('@/view/moneySafe/safeMoneyBudgetList.vue')
		},
		{
			path: '/class2',
			name: '学习课程库',
			component: () => import("@/view/dati/classOne/class2.vue")
		},
		{
			path: '/courseManagement',
			name: '课程管理',
			component: () => import('@/view/dati/courseManagement/courseManagement.vue')
		},
		{
			path: '/courseManagementList',
			name: '课程管理编辑',
			component: () => import('@/view/dati/courseManagement/courseManagementList.vue')
		},
		{
			path: '/courseAddPeo',
			name: '课程添加人员',
			component: () => import('@/view/dati/courseManagement/addPeo.vue')
		},
		{
			path: '/section',
			name: '课程添加小节',
			component: () => import('@/view/dati/courseManagement/section.vue')
		},
		{
			path: '/sectionList',
			name: '人员小节',
			component: () => import('@/view/dati/classOne/sectionList.vue')
		},
		{
			path: '/line',
			name: '人员小节答题',
			component: () => import('@/view/dati/classOne/line.vue')
		},
		{
			path: '/learning1',
			name: '人员学习',
			component: () => import('@/view/dati/classOne/learning.vue')
		},
		{
			path: '/fcbkdatistart',
			name: '逢查必考跳转答题',
			component: () => import('@/view/dati/examCheck/fcbkdatistart.vue')
		},

		{
			path: '/guest-register',
			name: '游客模式（答题）',
			component: () => import('@/view/login/Register.vue'),
			meta: { guestMode: true }
		}
	]
})
function isInWeCom(): boolean {
	return /wxwork/i.test(navigator.userAgent);
}
// 路由守卫
router.beforeEach(async (to, from, next) => {

	const token1 = localStorage.getItem('token');
	const isWeCom = isInWeCom();
	if (to.path === '/fcbkdatistart') {
		// 如果不在企微中，且没有有效 token，且不是已经在游客页
		if (!isWeCom && (!token1 || !isTokenValid(token1)) && from.path !== '/guest-register') {
			console.log('【游客模式】非企微访问 fcbkdatistart，跳转游客注册');
			// ✅ 关键修复：保留 to.query（即 examId 等参数）
			return next({
				path: '/guest-register',
				query: to.query
			});
		}

	}
	function isTokenValid(token : string) : boolean {
		try {
			// 检查 token 是否为合法 JWT 格式（3段）
			const parts = token.split('.');
			if (parts.length !== 3) {
				return false;
			}

			// 解码 payload 部分
			const payloadStr = atob(parts[1]);
			const payload = JSON.parse(payloadStr);

			// 检查是否有 exp 字段
			if (!payload.exp) {
				return false;
			}

			// 判断是否过期（exp 是秒级时间戳）
			const expTime = payload.exp * 1000;
			return Date.now() <= expTime; // ✅ 没过期就返回 true
		} catch (error) {
			console.error('Token 解析失败:', error);
			return false; // 出错也认为无效
		}
	}
	const getDeptPost = () => {
		var url = 'framework/SysDepartment/queryDeptPostByUserId'
		var param = {

		}
		axios.get(url, param).then(response => {
			if (response.data.code == 0) {
				// this.$store.commit('setPost', response.data.data.post)
				// this.$store.commit('setDept', response.data.data.dept)
				localStorage.setItem('post', JSON.stringify(response.data.data.post))
				localStorage.setItem('dept', JSON.stringify(response.data.data.dept))
				localStorage.setItem('role', JSON.stringify(response.data.data.role))
				localStorage.setItem('deptTree', JSON.stringify(response.data.data.deptTree))
			} else {
				localStorage.setItem('post', JSON.stringify([]))
				localStorage.setItem('dept', JSON.stringify([]))
				localStorage.setItem('role', JSON.stringify([]))
				localStorage.setItem('deptTree', JSON.stringify([]))
			}

		})
	}

	//const tableDataUserId=ref({})
	const getTableDataCode = async (userID : string) : Promise<any> => {
		const url = '/framework/SysUser/queryByCode';
		const param = { userCode: userID };

		const response = await axios.get(url, param);

		if (response.data.code === '0') {
			return response.data.data; // 这个 return 是给 async 函数的
		}

		return null; // 或者抛出错误，根据你的业务需求
	}
	console.log(to);
	if (to.path == '/Home1'||to.path=='/yinhuan/todo_detail/index'|| to.path == '/lz-rcd-detail'||to.path == '/emergencyResources'||to.path == '/cardManager/specialWork'
		||to.path == '/cardManager/equipment'||to.path == '/cardManager/engineer') {
		const userId=ref(import.meta.env.VITE_USER_ID)
		console.log(userId.value);
		console.log("当前环境：");
		console.log(import.meta.env.MODE);
		if (import.meta.env.MODE == 'production') {
			//	console.log('当前版本:', import.meta.env.VITE_APP_VERSION);
			const signRes = await requestSignature();
			const userInfo = await wxReady(signRes.data)
			console.log("获取到的用户信息userInfo为：");
			console.log(userInfo);
			console.log("userInfo的userId为：");
			console.log(userInfo.userID);
			//const userData = await getTableDataCode(userInfo.userID)
			userId.value = userInfo.userID
			console.log("userData的userId为：");
			console.log(userId.value);
			if (!userInfo) {
				if (window.history.length > 1) {
					showFailToast("获取信息失败，请联系管理员")
					window.history.back();
				} else {
					// 如果没有历史记录，跳转到首页或其他页面
					router.push('/login');
				}
			}
		}
		//		userId.value='S56077'

		//http://localhost:4200/workflow?userId=2&flowId=100&workId=HZ289fc39448dafa0194492f66c80125
		var url = 'framework/SysLogin/queryPublicKeyToken'
		// var url = 'framework/SysLogin/queryPublicKey'
		var param = {
			param: userId.value
		}

		await axios.post(url, param).then(response => {

			localStorage.setItem('publicKey', response.data.data.publicKey)
			localStorage.setItem('userId', response.data.data.id)
			localStorage.setItem('userCode', response.data.data.userCode)
			localStorage.setItem('userName', response.data.data.userName)
			localStorage.setItem('userDesc', response.data.data.userDesc)
			localStorage.setItem('userType', response.data.data.userType)
			localStorage.setItem('token', response.data.data.token)
			localStorage.setItem('belongId', response.data.data.belongId)

			localStorage.setItem('applications', JSON.stringify(response.data.data
				.applications))
			localStorage.setItem('application', JSON.stringify(response.data.data.applications[
				0]))
			sessionStorage.setItem('workflowQuery', JSON.stringify({
				flowId: to.query.flowId,
				workId: to.query.workId,
				trackId: to.query.trackId,
				date: new Date().getTime()
			}))
		})
		getDeptPost()
		next()
	} else {
		next()
	}



	const token = localStorage.getItem('token')

	/*	if (to.meta.requiresAuth && !token) {
			next('/login')
		} else if (to.path === '/login' && token) {
			next('/Home')
		} else   {
			next()
		}*/
})

export default router
