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'),
} }
} }
}) })
...@@ -132,4 +132,12 @@ export async function getProjectSkins(projectId, env) { ...@@ -132,4 +132,12 @@ 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,23 +109,53 @@ export default { ...@@ -107,23 +109,53 @@ 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 { } else {
this.$message({ // 如果是测试环境,ticket过期,则重新获取ticket
message: data.message, if (currentEnv === "test" && data.notLogin) {
type: "error" localStorage.setItem("ticket", "");
}); await this.getTicket(getTestEnvTicket);
this.skinList = []; this.getSkinsList(this.projectId);
return; } 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,
type: "error"
});
this.skinList = [];
return;
}
} }
} catch (e) { } catch (e) {
this.skinList = []; this.skinList = [];
...@@ -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