自動採番アクション追加・ドメイン追加

This commit is contained in:
2023-11-01 10:47:24 +09:00
parent df593d2ffe
commit cfc416fd14
20 changed files with 529 additions and 56 deletions

View File

@@ -1,13 +1,20 @@
import { defineStore } from 'pinia';
import { api } from 'boot/axios';
import { Router } from '../router';
import {IDomainInfo} from '../types/ActionTypes';
export interface IUserState{
token?:string;
returnUrl:string;
currentDomain:IDomainInfo;
}
export const useAuthStore = defineStore({
id: 'auth',
state: () => ({
token: localStorage.getItem('token'),
returnUrl: ''
state: () :IUserState => ({
token: localStorage.getItem('token')||'',
returnUrl: '',
currentDomain: JSON.parse(localStorage.getItem('currentDomain')||"{}")
}),
actions: {
async login(username:string, password:string) {
@@ -19,6 +26,8 @@ export const useAuthStore = defineStore({
console.info(result);
this.token =result.data.access_token;
localStorage.setItem('token', result.data.access_token);
this.currentDomain=await this.getCurrentDomain();
localStorage.setItem('currentDomain',JSON.stringify(this.currentDomain));
Router.push(this.returnUrl || '/');
return true;
}catch(e)
@@ -27,10 +36,33 @@ export const useAuthStore = defineStore({
return false;
}
},
async getCurrentDomain():Promise<IDomainInfo>{
return {
domainName:'mfu07rkgnb7c',
kintoneUrl:'https://mfu07rkgnb7c.cybozu.com'
}
},
async getUserDomains():Promise<IDomainInfo[]>{
return [
{
domainName:'mfu07rkgnb7c',
kintoneUrl:'https://mfu07rkgnb7c.cybozu.com'
},
{
domainName:'alicorn',
kintoneUrl:'https://alicorn.cybozu.com'
}
]
},
logout() {
this.token = null;
this.token = undefined;
localStorage.removeItem('token');
localStorage.removeItem('currentDomain');
Router.push('/login');
},
setCurrentDomain(domain:IDomainInfo){
this.currentDomain=domain;
localStorage.setItem('currentDomain',JSON.stringify(this.currentDomain));
}
}
});