|
|
@@ -0,0 +1,46 @@
|
|
|
+// 门户跳转域名(生产:官网域名;测试/开发:测试域名)
|
|
|
+// 域名切换只需修改 .env.* 中的 VITE_PORTAL_BASE_URL,无需改动业务代码
|
|
|
+export const PORTAL_BASE_URL: string = import.meta.env.VITE_PORTAL_BASE_URL || ''
|
|
|
+
|
|
|
+// 是否为生产环境(使用 Vite 内置 MODE,与 npm run build / build:test 的 --mode 保持一致)
|
|
|
+export const IS_PROD: boolean = import.meta.env.MODE === 'production'
|
|
|
+
|
|
|
+/**
|
|
|
+ * 构建门户跳转 URL
|
|
|
+ * @param hashPath hash 路由部分,如 '/otherLogin'
|
|
|
+ * @param query 查询参数对象,如 { type: 1, schoolId: 'xx', ticket: 'xx' }
|
|
|
+ * @returns 完整 URL,如 https://www.k12100.com/#/otherLogin?type=1&schoolId=xx&ticket=xx
|
|
|
+ */
|
|
|
+export const buildPortalUrl = (
|
|
|
+ hashPath: string,
|
|
|
+ query: Record<string, string | number | boolean | undefined | null> = {}
|
|
|
+): string => {
|
|
|
+ const qs = Object.entries(query)
|
|
|
+ .filter(([, v]) => v !== undefined && v !== null && v !== '')
|
|
|
+ .map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(String(v))}`)
|
|
|
+ .join('&')
|
|
|
+ const path = hashPath.startsWith('/') ? hashPath : `/${hashPath}`
|
|
|
+ return `${PORTAL_BASE_URL}/#${path}${qs ? `?${qs}` : ''}`
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 打开门户 otherLogin 页面(教师/学校统一入口)
|
|
|
+ * @param type 0=学校入口,1=教师入口
|
|
|
+ * @param schoolId 学校 ID
|
|
|
+ * @param ticket 一次性票据
|
|
|
+ * @param userId 用户 ID(type=1 时必传)
|
|
|
+ */
|
|
|
+export const openOtherLogin = (
|
|
|
+ type: 0 | 1,
|
|
|
+ schoolId: string | number,
|
|
|
+ ticket: string,
|
|
|
+ userId?: string | number
|
|
|
+) => {
|
|
|
+ const url = buildPortalUrl('/otherLogin', {
|
|
|
+ type,
|
|
|
+ schoolId,
|
|
|
+ id: userId,
|
|
|
+ ticket,
|
|
|
+ })
|
|
|
+ window.open(url)
|
|
|
+}
|