提交 822ecf9a authored 作者: 朱政's avatar 朱政

feat:跳转加密解密智库合作限制

上级 c775eca6
流水线 #628 已取消 于阶段
...@@ -223,12 +223,33 @@ export const useWrittingAsstaintStore = defineStore('writtingAsstaint', { ...@@ -223,12 +223,33 @@ export const useWrittingAsstaintStore = defineStore('writtingAsstaint', {
}, },
// ========== 路由参数处理 ========== // ========== 路由参数处理 ==========
/**
* 与 goToPage 中法案/政令等一致:query.data = btoa(encodeURIComponent(JSON.stringify({ topic, fileId, ... })))
*/
_decodeWrittingRouteDataParam(dataParam) {
if (dataParam == null || dataParam === '') return null
try {
const s = String(dataParam).trim()
if (!s) return null
const normalized = s.replace(/-/g, '+').replace(/_/g, '/')
const padded = normalized + '==='.slice((normalized.length + 3) % 4)
const decoded = atob(padded)
const jsonStr = decodeURIComponent(decoded)
const obj = JSON.parse(jsonStr)
return obj && typeof obj === 'object' && !Array.isArray(obj) ? obj : null
} catch (e) {
console.error('写作助手路由 query.data 解密失败', e)
return null
}
},
async setRouteParams(query) { async setRouteParams(query) {
this.routeQuery = { ...query }; const decoded = query?.data != null ? this._decodeWrittingRouteDataParam(query.data) : null
this._isDisableTemplate = Object.keys(query).length > 0; const effective = decoded ? { ...query, ...decoded } : { ...query }
this.routeQuery = { ...effective }
this._isDisableTemplate = Object.keys(effective).length > 0
if (Object.keys(query).length > 0) { if (Object.keys(effective).length > 0) {
const { topic, fileId } = query; const { topic, fileId } = effective
if (topic) { if (topic) {
this.curTempTitle = topic; this.curTempTitle = topic;
this.tempActiveIndex = this.tempList.findIndex(item => item.title === topic); this.tempActiveIndex = this.tempList.findIndex(item => item.title === topic);
......
...@@ -320,11 +320,20 @@ const decodeRouteId = (raw) => { ...@@ -320,11 +320,20 @@ const decodeRouteId = (raw) => {
const hearingId = computed(() => decodeRouteId(router.currentRoute.value?.params?.id)); const hearingId = computed(() => decodeRouteId(router.currentRoute.value?.params?.id));
const goToAllThinkTank = () => { const goToAllThinkTank = () => {
const thinkTankId = props?.thinkInfo?.thinkTankId || props?.thinkInfo?.id; const thinkTankId = props?.thinkInfo?.thinkTankId || props?.thinkInfo?.id;
const route = router.resolve({ const s = thinkTankId != null && thinkTankId !== "" ? String(thinkTankId).trim() : "";
if (!s) return;
let encodedId;
try {
encodedId = btoa(encodeURIComponent(s));
} catch (_) {
encodedId = s;
}
if (!encodedId) return;
const r = router.resolve({
name: "MultiThinkTankViewAnalysis", name: "MultiThinkTankViewAnalysis",
params: { id: thinkTankId } params: { id: encodedId }
}); });
window.open(route.href, "_blank"); window.open(r.href, "_blank");
}; };
...@@ -466,29 +475,52 @@ const reportAuthors = computed(() => { ...@@ -466,29 +475,52 @@ const reportAuthors = computed(() => {
} }
return []; return [];
}); });
const encodeBase64Param = (val) => {
const s = String(val ?? "").trim();
if (!s) return "";
try {
return btoa(encodeURIComponent(s));
} catch (_) {
return s;
}
};
// 点击报告作者头像,跳转到人物主页 // 点击报告作者头像,跳转到人物主页
// 与核心研究人员逻辑一致:核心依赖 personId,本页面依赖作者的 id(作为 personId 传入) // 与核心研究人员逻辑一致:核心依赖 personId,本页面依赖作者的 id(作为 personId 传入)
const handleClickReportAuthor = async (author) => { const handleClickReportAuthor = async (author) => {
const personId = author?.personId ?? author?.id;
const personId = author?.personId;
if (!personId) return; if (!personId) return;
const personTypeList = JSON.parse(window.sessionStorage.getItem("personTypeList"));
let type = 0;
const params = { personId };
try {
const res = await getPersonSummaryInfo(params);
if (res.code === 200 && res.data) {
const arr = Array.isArray(personTypeList)
? personTypeList.filter((t) => {
const typeIdNum = Number(t.typeId);
const personTypeNum = Number(res.data.personType);
return !Number.isNaN(typeIdNum) && !Number.isNaN(personTypeNum) && typeIdNum === personTypeNum;
})
: [];
const params = { personId };
const res = await getPersonSummaryInfo(params); window.sessionStorage.setItem("curTabName", author?.name || "人物主页");
if (res.code !== 200 || !res.data) return; const encodedPersonId = encodeBase64Param(personId);
window.sessionStorage.setItem("curTabName", author?.name || ""); if (!encodedPersonId) return;
const route = router.resolve({ const route = router.resolve({
path: "/characterPage", path: "/characterPage",
query: { query: {
personId type,
personId: encodedPersonId
} }
}); });
window.open(route.href, "_blank"); window.open(route.href, "_blank");
} else {
ElMessage.warning("找不到当前人员的类型值!");
}
} catch (error) { }
}; };
const riskSignal = computed(() => { const riskSignal = computed(() => {
const info = props.thinkInfo || {}; const info = props.thinkInfo || {};
......
...@@ -314,6 +314,7 @@ ...@@ -314,6 +314,7 @@
</template> </template>
<script setup> <script setup>
import router from '@/router'; import router from '@/router';
import { useRoute } from "vue-router";
import { onMounted, ref, computed, reactive, nextTick, watch } from "vue"; import { onMounted, ref, computed, reactive, nextTick, watch } from "vue";
import AnalysisBox from "@/components/base/boxBackground/analysisBox.vue" import AnalysisBox from "@/components/base/boxBackground/analysisBox.vue"
import AnalysisResultBox from "./boxBackground/analysisBox.vue" import AnalysisResultBox from "./boxBackground/analysisBox.vue"
...@@ -323,6 +324,73 @@ import { ...@@ -323,6 +324,73 @@ import {
getThinkTankReportViewpoint, getThinkTankReportViewpoint,
postReportDomainViewAnalysisStream postReportDomainViewAnalysisStream
} from "@/api/thinkTank/overview"; } from "@/api/thinkTank/overview";
const route = useRoute();
const decodeRouteId = (raw) => {
if (raw == null) return null;
let s0 = String(raw);
if (!s0) return null;
if (s0.includes("%")) {
try {
const decodedOnce = decodeURIComponent(s0);
if (decodedOnce) {
s0 = decodedOnce;
}
} catch (_) { }
}
if (/^\d+$/.test(s0) || /^Rand_/i.test(s0)) {
return s0;
}
const tryParseJson = (str) => {
if (typeof str !== "string") return null;
const s = str.trim();
if (!s) return null;
try {
return JSON.parse(s);
} catch (_) {
return null;
}
};
const tryAtob = (val) => {
if (val == null) return null;
const s = String(val).trim();
if (!s) return null;
const normalized = s.replace(/-/g, "+").replace(/_/g, "/");
const padded = normalized + "===".slice((normalized.length + 3) % 4);
try {
return atob(padded);
} catch (_) {
return null;
}
};
const atobStr = tryAtob(s0);
if (atobStr != null) {
try {
const decoded = decodeURIComponent(atobStr);
return tryParseJson(decoded) ?? decoded;
} catch (_) {
return tryParseJson(atobStr) ?? atobStr;
}
}
try {
const utf8 = decodeURIComponent(escape(s0));
if (utf8 && utf8 !== s0) {
if (/^\d+$/.test(utf8) || /^Rand_/i.test(utf8)) return utf8;
return tryParseJson(utf8) ?? utf8;
}
} catch (_) { }
return s0;
};
/** 与智库详情等一致:路由 id 为 base64(encodeURIComponent(明文)),请求接口前解密 */
const thinkTankIdFromRoute = computed(() => {
const id = decodeRouteId(route.params?.id);
return id != null && id !== "" ? String(id) : "";
});
const sort = ref(""); const sort = ref("");
const searchPolicy = ref(""); const searchPolicy = ref("");
const isBox2 = ref(true) const isBox2 = ref(true)
...@@ -951,7 +1019,7 @@ const handleGetHylyList = async () => { ...@@ -951,7 +1019,7 @@ const handleGetHylyList = async () => {
}; };
//获取智库报告 //获取智库报告
const handleGetetThinkTankReport = async (page = currentPage.value) => { const handleGetetThinkTankReport = async (page = currentPage.value) => {
const thinkTankId = router.currentRoute?.value?.params?.id || ""; const thinkTankId = thinkTankIdFromRoute.value;
const getDateYearsAgo = (years) => { const getDateYearsAgo = (years) => {
const d = new Date(); const d = new Date();
......
...@@ -229,12 +229,17 @@ const switchTab = name => { ...@@ -229,12 +229,17 @@ const switchTab = name => {
const handleAnalysisClick = () => { const handleAnalysisClick = () => {
const id = reportId.value; const id = reportId.value;
if (!id) return; if (!id) return;
const param = { topic: "智库", fileId: id };
const jsonStr = JSON.stringify(param);
let data;
try {
data = btoa(encodeURIComponent(jsonStr));
} catch (_) {
return;
}
router.push({ router.push({
path: "/writtingAsstaint", path: "/writtingAsstaint",
query: { query: { data }
topic: "智库",
fileId: id
}
}); });
}; };
onMounted(async () => { onMounted(async () => {
......
...@@ -302,11 +302,20 @@ const decodeRouteId = (raw) => { ...@@ -302,11 +302,20 @@ const decodeRouteId = (raw) => {
const reportId = computed(() => decodeRouteId(route.params?.id)); const reportId = computed(() => decodeRouteId(route.params?.id));
const goToAllThinkTank = () => { const goToAllThinkTank = () => {
const thinkTankId = props?.thinkInfo?.thinkTankId || props?.thinkInfo?.id; const thinkTankId = props?.thinkInfo?.thinkTankId || props?.thinkInfo?.id;
const route = router.resolve({ const s = thinkTankId != null && thinkTankId !== "" ? String(thinkTankId).trim() : "";
if (!s) return;
let encodedId;
try {
encodedId = btoa(encodeURIComponent(s));
} catch (_) {
encodedId = s;
}
if (!encodedId) return;
const r = router.resolve({
name: "MultiThinkTankViewAnalysis", name: "MultiThinkTankViewAnalysis",
params: { id: thinkTankId } params: { id: encodedId }
}); });
window.open(route.href, "_blank"); window.open(r.href, "_blank");
}; };
...@@ -448,21 +457,9 @@ const handleClickReportAuthor = async (author) => { ...@@ -448,21 +457,9 @@ const handleClickReportAuthor = async (author) => {
return !Number.isNaN(typeIdNum) && !Number.isNaN(personTypeNum) && typeIdNum === personTypeNum; return !Number.isNaN(typeIdNum) && !Number.isNaN(personTypeNum) && typeIdNum === personTypeNum;
}) })
: []; : [];
if (!arr.length) {
ElMessage.warning("找不到当前人员的类型值!");
return;
}
const personTypeName = arr[0]?.typeName || "";
if (personTypeName === "科技企业领袖") {
type = 1;
} else if (personTypeName === "国会议员") {
type = 2;
} else if (personTypeName === "智库研究人员") {
type = 3;
} else {
ElMessage.warning("找不到当前人员的类型值!");
return;
}
window.sessionStorage.setItem("curTabName", author?.name || "人物主页"); window.sessionStorage.setItem("curTabName", author?.name || "人物主页");
const encodedPersonId = encodeBase64Param(personId); const encodedPersonId = encodeBase64Param(personId);
if (!encodedPersonId) return; if (!encodedPersonId) return;
...@@ -1198,6 +1195,7 @@ onMounted(() => { ...@@ -1198,6 +1195,7 @@ onMounted(() => {
background-color: rgb(5, 95, 194); background-color: rgb(5, 95, 194);
border-radius: 6px; border-radius: 6px;
display: flex; display: flex;
cursor: pointer;
.btn-text { .btn-text {
color: rgb(255, 255, 255); color: rgb(255, 255, 255);
......
...@@ -741,21 +741,9 @@ const handleClickPerson = async item => { ...@@ -741,21 +741,9 @@ const handleClickPerson = async item => {
}) })
: []; : [];
console.log("arr", arr); console.log("arr", arr);
if (!arr.length) {
ElMessage.warning("找不到当前人员的类型值!");
return;
}
personTypeName = arr[0]?.typeName || ""; personTypeName = arr[0]?.typeName || "";
if (personTypeName === "科技企业领袖") {
type = 1;
} else if (personTypeName === "国会议员") {
type = 2;
} else if (personTypeName === "智库研究人员") {
type = 3;
} else {
ElMessage.warning("找不到当前人员的类型值!");
return;
}
window.sessionStorage.setItem("curTabName", item.name || "人物主页"); window.sessionStorage.setItem("curTabName", item.name || "人物主页");
const encodedPersonId = encodeBase64Param(item?.personId); const encodedPersonId = encodeBase64Param(item?.personId);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论