Skip to content

Commit

Permalink
✨ 支持复制ck
Browse files Browse the repository at this point in the history
  • Loading branch information
BTMuli committed Jul 26, 2024
1 parent f0b3a31 commit 948db20
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 3 deletions.
38 changes: 36 additions & 2 deletions src/components/config/tc-userBadge.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,15 @@
<template #text>{{ userInfo.desc }}</template>
<template #actions>
<v-spacer />
<v-btn variant="outlined" @click="scan = true" icon="mdi-qrcode-scan" />
<v-btn variant="outlined" @click="confirmRefreshUser" icon="mdi-refresh" :loading="loading" />
<v-btn variant="outlined" @click="scan = true" icon="mdi-qrcode-scan" title="扫码登录" />
<v-btn
variant="outlined"
@click="confirmRefreshUser"
icon="mdi-refresh"
:loading="loading"
title="刷新用户信息"
/>
<v-btn variant="outlined" @click="confirmCopyCookie" icon="mdi-cookie" title="复制Cookie" />
</template>
</v-card>
</template>
Expand Down Expand Up @@ -218,6 +225,33 @@ async function confirmRefreshUser(): Promise<void> {
await refreshUser();
}
async function confirmCopyCookie(): Promise<void> {
const res = await showConfirm({
title: "确认复制 Cookie 吗?",
text: "将会复制当前登录的 Cookie",
});
if (!res) {
showSnackbar({
color: "cancel",
text: "已取消复制",
});
return;
}
if (!userStore.cookie) {
showSnackbar({
color: "error",
text: "请先登录",
});
return;
}
const ckText = useUserStore().getAllCookie();
await navigator.clipboard.writeText(ckText);
showSnackbar({
text: "已复制 Cookie!",
color: "success",
});
}
onUnmounted(() => {
if (signListener) signListener();
});
Expand Down
27 changes: 26 additions & 1 deletion src/store/modules/user.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @file store/modules/user.ts
* @description 用户信息模块
* @since Beta v0.3.9
* @since Beta v0.5.1
*/

import { defineStore } from "pinia";
Expand All @@ -28,10 +28,35 @@ export const useUserStore = defineStore(
});
const cookie = ref<TGApp.User.Account.Cookie>();

function getAllCookie(): string {
let res = "";
if (!cookie.value) return res;
if (cookie.value.ltuid && cookie.value.ltuid !== "") {
res += `ltuid=${cookie.value.ltuid};`;
}
if (cookie.value.ltoken && cookie.value.ltoken !== "") {
res += `ltoken=${cookie.value.ltoken};`;
}
if (cookie.value.mid && cookie.value.mid !== "") {
res += `mid=${cookie.value.mid};`;
}
if (cookie.value.cookie_token && cookie.value.cookie_token !== "") {
res += `cookie_token=${cookie.value.cookie_token};`;
}
if (cookie.value.stoken && cookie.value.stoken !== "") {
res += `stoken=${cookie.value.stoken};`;
}
if (cookie.value.account_id && cookie.value.account_id !== "") {
res += `account_id=${cookie.value.account_id};`;
}
return res;
}

return {
cookie,
briefInfo,
account,
getAllCookie,
};
},
{
Expand Down

0 comments on commit 948db20

Please sign in to comment.