test
This commit is contained in:
parent
d88a064fc6
commit
5bd9b1a2e2
@ -7,7 +7,6 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { DocumentsApi } from "../openapi";
|
||||
const a = new DocumentsApi();
|
||||
a.libraryLibraryIdDocumentDocumentIdGet("a", "a");
|
||||
import library from '@/plugins/library'
|
||||
// library.libraryLibraryIdDocumentsGet(1,2)
|
||||
</script>
|
||||
|
@ -1,8 +1,8 @@
|
||||
import axios from "axios";
|
||||
// import router from "@/router";
|
||||
import {useUserStore} from "@/stores/user";
|
||||
// const config = useConfigStore()
|
||||
import config from "@/plugins/config"
|
||||
// import {useUserStore} from "@/stores/user";
|
||||
// // const config = useConfigStore()
|
||||
// import config from "@/plugins/config"
|
||||
|
||||
let axios_config = {
|
||||
baseURL: config.baseUrl,
|
||||
|
53
src/plugins/library.ts
Normal file
53
src/plugins/library.ts
Normal file
@ -0,0 +1,53 @@
|
||||
import { DocumentsApi, Configuration } from "../openapi";
|
||||
|
||||
import axios from "axios";
|
||||
import router from "@/router";
|
||||
// import {useUserStore} from "@/stores/user";
|
||||
// // const config = useConfigStore()
|
||||
// import config from "@/plugins/config"
|
||||
|
||||
|
||||
// instance.interceptors.request.use(
|
||||
// (config) => {
|
||||
// if (config.headers === undefined) {
|
||||
// // config.headers = {};
|
||||
// }
|
||||
|
||||
// config.headers["Accept"] = "application/json";
|
||||
|
||||
// // @ts-ignore
|
||||
// if (process.env.NODE_ENV === "development") {
|
||||
// // user.jwt_token 取中间
|
||||
// config.headers["X-Jwt-Payload"] = user.jwt_token?.split(".")[1]
|
||||
// } else {
|
||||
// config.headers["Authorization"] = "Bearer " + user.jwt_token;
|
||||
// }
|
||||
|
||||
// return config;
|
||||
// },
|
||||
// (error) => {
|
||||
// console.error("axios request error", error);
|
||||
// return Promise.reject(error);
|
||||
// }
|
||||
// );
|
||||
|
||||
// instance.interceptors.response.use(
|
||||
// (res) => {
|
||||
// return Promise.resolve(res);
|
||||
// },
|
||||
// (error) => {
|
||||
// console.error("axios response error", error);
|
||||
|
||||
// return Promise.reject(error);
|
||||
// }
|
||||
// );
|
||||
|
||||
// export default instance;
|
||||
|
||||
|
||||
const conf = new Configuration
|
||||
conf.basePath = "https://document.awa.im/api"
|
||||
conf.apiKey = "a"
|
||||
const a = new DocumentsApi(conf);
|
||||
|
||||
export default a
|
25
src/store/config.ts
Normal file
25
src/store/config.ts
Normal file
@ -0,0 +1,25 @@
|
||||
import {defineStore} from 'pinia'
|
||||
// import axios from "axios";
|
||||
|
||||
export const useConfigStore = defineStore('app', {
|
||||
state: () => ({
|
||||
appName: "资料库",
|
||||
description: "Leaf Library",
|
||||
accountServer: "https://httpbin.awa.im",
|
||||
}),
|
||||
actions: {
|
||||
getAppName(): string {
|
||||
return this.appName !== null ? this.appName : "Leaf Library"
|
||||
},
|
||||
getRefreshUrl(): string {
|
||||
return this.accountServer + "/public/auth_request/refresh"
|
||||
},
|
||||
getLoginUrl(): string {
|
||||
let url = new URL(this.accountServer + "/public/auth_request")
|
||||
url.searchParams.append("description", this.description)
|
||||
// url.searchParams.append("callback_uri", window.location.href)
|
||||
url.searchParams.append("attributes[app]", "todo")
|
||||
return url.toString()
|
||||
}
|
||||
},
|
||||
})
|
12
src/store/libraries.ts
Normal file
12
src/store/libraries.ts
Normal file
@ -0,0 +1,12 @@
|
||||
import {defineStore} from 'pinia'
|
||||
import axios from "axios";
|
||||
import {useConfigStore} from "./config";
|
||||
|
||||
export const useLibrariesStore = defineStore('libraries', {
|
||||
state: () => ({
|
||||
libraries: [{
|
||||
ID: 0,
|
||||
Name: "",
|
||||
}],
|
||||
}),
|
||||
})
|
39
src/store/user.ts
Normal file
39
src/store/user.ts
Normal file
@ -0,0 +1,39 @@
|
||||
import {defineStore} from 'pinia'
|
||||
import axios from "axios";
|
||||
import {useConfigStore} from "./config";
|
||||
|
||||
export const useUserStore = defineStore('user', {
|
||||
persist: true,
|
||||
state: () => ({
|
||||
refresh_token: null as null | string,
|
||||
jwt_token: null as null | string,
|
||||
}),
|
||||
getters: {
|
||||
isLoggedIn(): boolean {
|
||||
return this.jwt_token !== null
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
login(refresh_token: string, jwt_token: string) {
|
||||
this.refresh_token = refresh_token
|
||||
this.jwt_token = jwt_token
|
||||
},
|
||||
logout() {
|
||||
console.log("logout")
|
||||
this.refresh_token = null
|
||||
this.jwt_token = null
|
||||
},
|
||||
refresh() {
|
||||
let config = useConfigStore()
|
||||
|
||||
axios.post(config.getRefreshUrl(), {
|
||||
refresh_token: this.refresh_token
|
||||
}).then(r => {
|
||||
this.jwt_token = r.data.token
|
||||
}).catch(e => {
|
||||
console.error(e)
|
||||
this.logout()
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
Loading…
Reference in New Issue
Block a user