🔥 添加自定义后缀

This commit is contained in:
7836246
2024-03-18 00:19:08 +08:00
parent 168013cb27
commit 4c6250b1f9
10 changed files with 208 additions and 10 deletions
+49
View File
@@ -0,0 +1,49 @@
import { defineStore } from 'pinia';
import serversData from '~/server/whois/json/whois-servers.json';
// 定义接口来描述state的结构
interface DomainState {
SupportedTLDs: Record<string, string>;
}
export const useDomainStore = defineStore('domain', {
// 使用箭头函数和类型注解定义state
state: (): DomainState => ({
SupportedTLDs: { ...serversData },
}),
actions: {
async addSuffix(suffix: string, server: string) {
const response = await $fetch('/api/addSuffix', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({suffix, server}),
});
if (response.message === 'ok') {
// 更新本地状态
await nextTick();
this.SupportedTLDs[suffix] = server;
}
},
async removeSuffix(suffix: string) {
const response = await $fetch('/api/removeSuffix', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({suffix}),
});
if (response.message === 'ok') {
await nextTick();
// 更新本地状态
delete this.SupportedTLDs[suffix];
}
}
},
persist:{
storage: persistedState.localStorage,
}
});