支持复制ck

This commit is contained in:
目棃
2024-07-26 14:27:24 +08:00
parent f0b3a311d7
commit 948db203bd
2 changed files with 62 additions and 3 deletions

View File

@@ -9,8 +9,15 @@
<template #text>{{ userInfo.desc }}</template> <template #text>{{ userInfo.desc }}</template>
<template #actions> <template #actions>
<v-spacer /> <v-spacer />
<v-btn variant="outlined" @click="scan = true" icon="mdi-qrcode-scan" /> <v-btn variant="outlined" @click="scan = true" icon="mdi-qrcode-scan" title="扫码登录" />
<v-btn variant="outlined" @click="confirmRefreshUser" icon="mdi-refresh" :loading="loading" /> <v-btn
variant="outlined"
@click="confirmRefreshUser"
icon="mdi-refresh"
:loading="loading"
title="刷新用户信息"
/>
<v-btn variant="outlined" @click="confirmCopyCookie" icon="mdi-cookie" title="复制Cookie" />
</template> </template>
</v-card> </v-card>
</template> </template>
@@ -218,6 +225,33 @@ async function confirmRefreshUser(): Promise<void> {
await refreshUser(); 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(() => { onUnmounted(() => {
if (signListener) signListener(); if (signListener) signListener();
}); });

View File

@@ -1,7 +1,7 @@
/** /**
* @file store/modules/user.ts * @file store/modules/user.ts
* @description 用户信息模块 * @description 用户信息模块
* @since Beta v0.3.9 * @since Beta v0.5.1
*/ */
import { defineStore } from "pinia"; import { defineStore } from "pinia";
@@ -28,10 +28,35 @@ export const useUserStore = defineStore(
}); });
const cookie = ref<TGApp.User.Account.Cookie>(); 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 { return {
cookie, cookie,
briefInfo, briefInfo,
account, account,
getAllCookie,
}; };
}, },
{ {