♻️ 替换hutaoEmail

#202
This commit is contained in:
BTMuli
2026-01-04 04:09:33 +08:00
parent a7344388ea
commit 0aae714455
5 changed files with 105 additions and 54 deletions

View File

@@ -59,7 +59,7 @@
<span>统计数据</span>
</v-btn>
<div class="uat-extension-right">
<span @click="editHutaoEmail()">{{ hutaoEmail ?? "胡桃云邮箱" }}</span>
<span @click="tryLoginHutao()">{{ userName ?? "登录胡桃云" }}</span>
<v-btn class="ua-btn" prepend-icon="mdi-upload" variant="elevated" @click="uploadAbyss()">
上传
</v-btn>
@@ -131,6 +131,7 @@ import recordReq from "@req/recordReq.js";
import TSUserAbyss from "@Sqlm/userAbyss.js";
import TSUserAvatar from "@Sqlm/userAvatar.js";
import useAppStore from "@store/app.js";
import useHutaoStore from "@store/hutao.js";
import useUserStore from "@store/user.js";
import { getVersion } from "@tauri-apps/api/app";
import { open } from "@tauri-apps/plugin-dialog";
@@ -142,8 +143,11 @@ import { onMounted, ref, shallowRef, watch } from "vue";
import { useRouter } from "vue-router";
const router = useRouter();
const hutaoStore = useHutaoStore();
const { isLogin } = storeToRefs(useAppStore());
const { account, cookie, hutaoEmail } = storeToRefs(useUserStore());
const { account, cookie } = storeToRefs(useUserStore());
const { userName } = storeToRefs(hutaoStore);
const userTab = ref<number>(0);
const version = ref<string>();
const uidCur = ref<string>();
@@ -185,27 +189,8 @@ async function toWiki(): Promise<void> {
await router.push({ name: "深渊数据库" });
}
async function editHutaoEmail(): Promise<void> {
if (hutaoEmail.value) {
const chgCheck = await showDialog.check("是否更改胡桃云账号", `当前账号:${hutaoEmail.value}`);
if (!chgCheck) {
showSnackbar.cancel("已取消更改胡桃云账号");
return;
}
}
const newEmail = await showDialog.input("请输入胡桃云账号", "胡桃云账号", hutaoEmail.value);
if (!newEmail) {
showSnackbar.cancel("已取消设置胡桃云账号");
return;
}
// 简单验证邮箱格式
const mailReg = /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
if (!mailReg.test(newEmail)) {
showSnackbar.error("邮箱格式错误");
return;
}
hutaoEmail.value = newEmail;
showSnackbar.success("已设置胡桃云账号");
async function tryLoginHutao(): Promise<void> {
if (!userName.value) await hutaoStore.tryLogin();
}
async function loadAbyss(): Promise<void> {
@@ -353,7 +338,7 @@ async function tryReadAbyss(): Promise<void> {
}
async function uploadAbyss(): Promise<void> {
if (!hutaoEmail.value || hutaoEmail.value === "") {
if (!userName.value || userName.value === "") {
const check = await showDialog.check("确定上传?", "未设置胡桃云账号");
if (!check) return;
}
@@ -382,7 +367,7 @@ async function uploadAbyss(): Promise<void> {
try {
await showLoading.start(`正在上传${account.value.gameUid}的深渊数据`, `期数:${abyssData.id}`);
const transAbyss = hutao.Abyss.utils.transData(abyssData);
if (hutaoEmail.value) transAbyss.ReservedUserName = hutaoEmail.value;
if (userName.value) transAbyss.ReservedUserName = userName.value;
await showLoading.update("正在获取角色数据");
const roles = await TSUserAvatar.getAvatars(Number(account.value.gameUid));
if (!roles) {

View File

@@ -64,7 +64,7 @@
<span>统计数据</span>
</v-btn>
<div class="uct-extension-right">
<span @click="editHutaoEmail()">{{ hutaoEmail ?? "设置胡桃云邮箱" }}</span>
<span @click="tryLoginHutao()">{{ userName ?? "登录胡桃云" }}</span>
<v-btn
class="uc-btn"
prepend-icon="mdi-cloud-upload"
@@ -133,6 +133,7 @@ import hutao from "@Hutao/index.js";
import recordReq from "@req/recordReq.js";
import TSUserCombat from "@Sqlm/userCombat.js";
import useAppStore from "@store/app.js";
import useHutaoStore from "@store/hutao.js";
import useUserStore from "@store/user.js";
import { getVersion } from "@tauri-apps/api/app";
import { open } from "@tauri-apps/plugin-dialog";
@@ -144,8 +145,12 @@ import { onMounted, ref, shallowRef, watch } from "vue";
import { useRouter } from "vue-router";
const router = useRouter();
const hutaoStore = useHutaoStore();
const { isLogin } = storeToRefs(useAppStore());
const { account, cookie, hutaoEmail } = storeToRefs(useUserStore());
const { account, cookie } = storeToRefs(useUserStore());
const { userName } = storeToRefs(hutaoStore);
const userTab = ref<number>(0);
const version = ref<string>();
const uidCur = ref<string>();
@@ -204,27 +209,8 @@ async function loadCombat(): Promise<void> {
if (localCombat.value.length > 0) userTab.value = localCombat.value[0].id;
}
async function editHutaoEmail(): Promise<void> {
if (hutaoEmail.value) {
const chgCheck = await showDialog.check("是否更改胡桃云账号", `当前账号:${hutaoEmail.value}`);
if (!chgCheck) {
showSnackbar.cancel("已取消更改胡桃云账号");
return;
}
}
const newEmail = await showDialog.input("请输入胡桃云账号", "胡桃云账号", hutaoEmail.value);
if (!newEmail) {
showSnackbar.cancel("已取消设置胡桃云账号");
return;
}
// 简单验证邮箱格式
const mailReg = /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
if (!mailReg.test(newEmail)) {
showSnackbar.error("邮箱格式错误");
return;
}
hutaoEmail.value = newEmail;
showSnackbar.success("已设置胡桃云账号");
async function tryLoginHutao(): Promise<void> {
if (!userName.value) await hutaoStore.tryLogin();
}
async function refreshCombat(): Promise<void> {
@@ -314,7 +300,7 @@ async function deleteCombat(): Promise<void> {
}
async function uploadCombat(): Promise<void> {
if (!hutaoEmail.value || hutaoEmail.value === "") {
if (!userName.value || userName.value === "") {
const check = await showDialog.check("确定上传?", "未设置胡桃云账号");
if (!check) return;
}

View File

@@ -22,6 +22,10 @@
import showDialog from "@comp/func/dialog.js";
import showSnackbar from "@comp/func/snackbar.js";
import hutao from "@Hutao/index.js";
import useHutaoStore from "@store/hutao.js";
import { storeToRefs } from "pinia";
const { userName, accessToken, refreshToken } = storeToRefs(useHutaoStore());
async function test() {
const inputN = await showDialog.input("UserName");
@@ -30,7 +34,12 @@ async function test() {
const resp = await hutao.Account.login(inputN, inputP);
if ("retcode" in resp) {
showSnackbar.warn(`${resp.retcode}-${resp.message}`);
return;
}
userName.value = inputN;
accessToken.value = resp.AccessToken;
refreshToken.value = resp.RefreshToken;
showSnackbar.success("登录成功!");
}
</script>
<style lang="css" scoped>

View File

@@ -0,0 +1,76 @@
/**
* 胡桃账号
* @since Beta v0.9.1
*/
import showDialog from "@comp/func/dialog.js";
import showLoading from "@comp/func/loading.js";
import showSnackbar from "@comp/func/snackbar.js";
import hutao from "@Hutao/index.js";
import { defineStore } from "pinia";
import { ref } from "vue";
const useHutaoStore = defineStore(
"hutao",
() => {
/** 账号 */
const userName = ref<string>();
/** token */
const accessToken = ref<string>();
/** refresh */
const refreshToken = ref<string>();
/** 超时时间 */
const accessExpire = ref<number>(0);
async function tryLogin(): Promise<void> {
const inputN = await showDialog.input("请输入胡桃云账号", "邮箱:");
if (!inputN) {
showSnackbar.cancel("已取消胡桃云账号输入");
return;
}
const mailReg = /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
if (!mailReg.test(inputN.trim())) {
showSnackbar.warn("请输入合法邮箱地址");
return;
}
const inputP = await showDialog.input("请输入密码", "密码");
if (!inputP) {
showSnackbar.warn("已取消胡桃云登录");
return;
}
await showLoading.start("正在登录胡桃云", inputN);
try {
const resp = await hutao.Account.login(inputN, inputP);
if ("retcode" in resp) {
showSnackbar.warn(`[${resp.retcode}] ${resp.message}`);
console.error(resp);
await showLoading.end();
return;
}
userName.value = inputN;
accessToken.value = resp.AccessToken;
refreshToken.value = resp.RefreshToken;
// TODO: 判断返回单位处理expire
// accessExpire.value = Date.now();
} catch (err) {
console.error(err);
showSnackbar.error("登录胡桃云失败");
} finally {
await showLoading.end();
}
}
return {
userName,
accessToken,
refreshToken,
accessExpire,
tryLogin,
};
},
{
persist: true,
},
);
export default useHutaoStore;

View File

@@ -33,9 +33,6 @@ const useUserStore = defineStore(
const cookie = ref<TGApp.App.Account.Cookie>();
const propMap = ref<TGApp.Game.Avatar.PropMap>();
/** 胡桃云邮箱 */
const hutaoEmail = ref<string>();
function getProp(prop: number): TGApp.Game.Avatar.PropMapItem | false {
if (!propMap.value) return false;
return propMap.value[prop.toString()] || false;
@@ -68,7 +65,6 @@ const useUserStore = defineStore(
briefInfo,
account,
propMap,
hutaoEmail,
getProp,
switchGameAccount,
};
@@ -81,7 +77,6 @@ const useUserStore = defineStore(
pick: ["uid", "briefInfo", "cookie", "account"],
},
{ key: "propMap", storage: window.localStorage, pick: ["propMap"] },
{ key: "hutaoAccount", storage: window.localStorage, pick: ["hutaoEmail"] },
],
},
);