Commit 562a0bc2 authored by bianlongting's avatar bianlongting 💬

optimize

parent f911b66d
...@@ -124,7 +124,7 @@ export async function getProjectSkins(projectId, env) { ...@@ -124,7 +124,7 @@ export async function getProjectSkins(projectId, env) {
cookie: { cookie: {
dev: getCookie('sso_ticket'), dev: getCookie('sso_ticket'),
test: localStorage.getItem('ticket'), test: localStorage.getItem('ticket'),
prod: getCookie('prod_ticket'), prod: localStorage.getItem('prod_ticket'),
} }
} }
}) })
...@@ -133,3 +133,11 @@ export async function getProjectSkins(projectId, env) { ...@@ -133,3 +133,11 @@ export async function getProjectSkins(projectId, env) {
export async function getTestEnvTicket() { export async function getTestEnvTicket() {
return await fetchApi(`/polaris/getTestEnvTicket`, { method: 'get' }) return await fetchApi(`/polaris/getTestEnvTicket`, { method: 'get' })
} }
export async function getProdTicket() {
return await fetchApi(`/polaris/getProdTicket`, { method: 'get' })
}
export async function sendDingTalk() {
return await fetchApi(`/polaris/sendMessage`, { method: 'post' })
}
\ No newline at end of file
...@@ -65,7 +65,9 @@ import copy from "copy-to-clipboard"; ...@@ -65,7 +65,9 @@ import copy from "copy-to-clipboard";
import { import {
getProjectSkins, getProjectSkins,
saveSkins, saveSkins,
getTestEnvTicket getTestEnvTicket,
getProdTicket,
sendDingTalk
} from "../../../../src/api/project"; } from "../../../../src/api/project";
export default { export default {
name: "ProjectxOptions", name: "ProjectxOptions",
...@@ -107,16 +109,45 @@ export default { ...@@ -107,16 +109,45 @@ export default {
return this.projectId; return this.projectId;
}, },
changeCurrentEnv(e) { changeCurrentEnv(e) {
if (e === "test") {
this.getTicket(getTestEnvTicket);
} else if (e === "prod") {
this.getTicket(getProdTicket, "prod_ticket");
}
const projectId = this.getProjectId(e); const projectId = this.getProjectId(e);
this.skinId = ""; this.skinId = "";
this.getSkinsList(projectId); this.getSkinsList(projectId);
}, },
async getSkinsList(projectId) { async getSkinsList(projectId) {
const { currentEnv } = this; const { currentEnv } = this;
if (!projectId) {
this.$message({
message: `请先配置${currentEnv}环境下的projectId`,
type: "error"
});
return;
}
try { try {
const data = await getProjectSkins(projectId, currentEnv); const data = await getProjectSkins(projectId, currentEnv);
if (data.success !== false) { if (data.success !== false) {
this.skinList = data; this.skinList = data;
} else {
// 如果是测试环境,ticket过期,则重新获取ticket
if (currentEnv === "test" && data.notLogin) {
localStorage.setItem("ticket", "");
await this.getTicket(getTestEnvTicket);
this.getSkinsList(this.projectId);
} else if (currentEnv === "prod" && data.notLogin) {
// 如果是线上环境,则发送钉钉消息
sendDingTalk();
localStorage.setItem("prod_ticket", "");
this.$message({
message: "线上tickct失效,已给相关人员发送消息",
type: "info"
});
this.skinList = [];
return;
// sendDingTalk();
} else { } else {
this.$message({ this.$message({
message: data.message, message: data.message,
...@@ -125,6 +156,7 @@ export default { ...@@ -125,6 +156,7 @@ export default {
this.skinList = []; this.skinList = [];
return; return;
} }
}
} catch (e) { } catch (e) {
this.skinList = []; this.skinList = [];
throw new Error(e.message); throw new Error(e.message);
...@@ -180,8 +212,11 @@ export default { ...@@ -180,8 +212,11 @@ export default {
if (currentTypes !== "2") { if (currentTypes !== "2") {
// 2为修改,修改不需重新获取列表 // 2为修改,修改不需重新获取列表
this.getSkinsList(projectId); this.getSkinsList(projectId);
} else if (currentTypes !== "3") {
this.name = "";
} }
}, },
/** 获取访问链接 */
getUrl() { getUrl() {
const { currentHtmlType, currentEnv, skinId, projectId } = this; const { currentHtmlType, currentEnv, skinId, projectId } = this;
const mapping = { const mapping = {
...@@ -197,6 +232,14 @@ export default { ...@@ -197,6 +232,14 @@ export default {
message: "链接复制成功", message: "链接复制成功",
type: "success" type: "success"
}); });
},
async getTicket(fn, name = "ticket") {
let ticket = localStorage.getItem(name);
if (!ticket) {
ticket = await fn();
console.log(ticket, "ticketticket");
localStorage.setItem(name, ticket);
}
} }
}, },
async mounted() { async mounted() {
...@@ -205,13 +248,7 @@ export default { ...@@ -205,13 +248,7 @@ export default {
this.projectId = projectId; this.projectId = projectId;
this.getSkinsList(projectId); this.getSkinsList(projectId);
}, },
async created() { async created() {}
let ticket = localStorage.getItem("ticket");
if (!ticket) {
ticket = await getTestEnvTicket();
localStorage.setItem("ticket", ticket);
}
}
}; };
</script> </script>
<style lang="scss"> <style lang="scss">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment