Commit 562a0bc2 authored by bianlongting's avatar bianlongting 💬

optimize

parent f911b66d
......@@ -124,7 +124,7 @@ export async function getProjectSkins(projectId, env) {
cookie: {
dev: getCookie('sso_ticket'),
test: localStorage.getItem('ticket'),
prod: getCookie('prod_ticket'),
prod: localStorage.getItem('prod_ticket'),
}
}
})
......@@ -133,3 +133,11 @@ export async function getProjectSkins(projectId, env) {
export async function getTestEnvTicket() {
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";
import {
getProjectSkins,
saveSkins,
getTestEnvTicket
getTestEnvTicket,
getProdTicket,
sendDingTalk
} from "../../../../src/api/project";
export default {
name: "ProjectxOptions",
......@@ -107,16 +109,45 @@ export default {
return this.projectId;
},
changeCurrentEnv(e) {
if (e === "test") {
this.getTicket(getTestEnvTicket);
} else if (e === "prod") {
this.getTicket(getProdTicket, "prod_ticket");
}
const projectId = this.getProjectId(e);
this.skinId = "";
this.getSkinsList(projectId);
},
async getSkinsList(projectId) {
const { currentEnv } = this;
if (!projectId) {
this.$message({
message: `请先配置${currentEnv}环境下的projectId`,
type: "error"
});
return;
}
try {
const data = await getProjectSkins(projectId, currentEnv);
if (data.success !== false) {
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 {
this.$message({
message: data.message,
......@@ -125,6 +156,7 @@ export default {
this.skinList = [];
return;
}
}
} catch (e) {
this.skinList = [];
throw new Error(e.message);
......@@ -180,8 +212,11 @@ export default {
if (currentTypes !== "2") {
// 2为修改,修改不需重新获取列表
this.getSkinsList(projectId);
} else if (currentTypes !== "3") {
this.name = "";
}
},
/** 获取访问链接 */
getUrl() {
const { currentHtmlType, currentEnv, skinId, projectId } = this;
const mapping = {
......@@ -197,6 +232,14 @@ export default {
message: "链接复制成功",
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() {
......@@ -205,13 +248,7 @@ export default {
this.projectId = projectId;
this.getSkinsList(projectId);
},
async created() {
let ticket = localStorage.getItem("ticket");
if (!ticket) {
ticket = await getTestEnvTicket();
localStorage.setItem("ticket", ticket);
}
}
async created() {}
};
</script>
<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