-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from xh-polaris/master
chore: 配置pages和utils
- Loading branch information
Showing
16 changed files
with
385 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/// <reference types="vite/client" /> | ||
|
||
declare module "*.vue" { | ||
import { DefineComponent } from "vue"; | ||
const component: DefineComponent< | ||
Record<string, unknown>, | ||
Record<string, unknown>, | ||
Record<string, unknown> | ||
>; | ||
export default component; | ||
} | ||
|
||
// 环境变量声明 | ||
interface ImportMetaEnv extends Readonly<Record<string, string>> { | ||
readonly VITE_BASIC_URL: string; | ||
readonly VITE_NAME: string; | ||
readonly VITE_ENABLE_DEBUG: boolean; | ||
} | ||
|
||
interface ImportMeta { | ||
readonly env: ImportMetaEnv; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { BackendEnvMap, StorageKeys } from "@/utils/const"; | ||
import { refreshToken } from "@/utils/init"; | ||
import { Pages } from "@/utils/url"; | ||
|
||
export function createInterceptors() { | ||
uni.addInterceptor("request", { | ||
invoke(args: UniNamespace.RequestOptions) { | ||
if (args.url.startsWith("/")) { | ||
const env = uni.getStorageSync(StorageKeys.BackendEnv); | ||
const lane = uni.getStorageSync(StorageKeys.BackendLane); | ||
args.url = import.meta.env.VITE_BASIC_URL + args.url; | ||
args.header = { | ||
Authorization: uni.getStorageSync(StorageKeys.AccessToken).token, | ||
"X-Xh-Env": env | ||
? env | ||
: BackendEnvMap[uni.getAccountInfoSync().miniProgram.envVersion], | ||
"X-Xh-Lane": lane ? lane : "" | ||
}; | ||
} | ||
}, | ||
success(result: any) { | ||
if (result.statusCode === 401) { | ||
refreshToken(uni.getAccountInfoSync().miniProgram.appId).then(() => { | ||
uni.reLaunch({ url: Pages.FirstPage }); | ||
}); | ||
} else if (result.statusCode >= 400) { | ||
uni.showToast({ | ||
title: "请求失败", | ||
icon: "error" | ||
}); | ||
} | ||
}, | ||
fail() { | ||
uni.showToast({ | ||
title: "网络异常", | ||
icon: "error" | ||
}); | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<script setup lang="ts"> | ||
</script> | ||
|
||
<template> | ||
|
||
</template> | ||
|
||
<style scoped> | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<script setup lang="ts"> | ||
</script> | ||
|
||
<template> | ||
|
||
</template> | ||
|
||
<style scoped> | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<script setup lang="ts"> | ||
</script> | ||
|
||
<template> | ||
|
||
</template> | ||
|
||
<style scoped> | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<script setup lang="ts"> | ||
</script> | ||
|
||
<template> | ||
|
||
</template> | ||
|
||
<style scoped> | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<script setup lang="ts"> | ||
</script> | ||
|
||
<template> | ||
|
||
</template> | ||
|
||
<style scoped> | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<script setup lang="ts"> | ||
</script> | ||
|
||
<template> | ||
|
||
</template> | ||
|
||
<style scoped> | ||
</style> |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<script setup lang="ts"> | ||
</script> | ||
|
||
<template> | ||
|
||
</template> | ||
|
||
<style scoped> | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<script setup lang="ts"> | ||
</script> | ||
|
||
<template> | ||
|
||
</template> | ||
|
||
<style scoped> | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
export const enum StorageKeys { | ||
CommunityId = "communityId", | ||
UserId = "userId", | ||
AccessToken = "accessToken", | ||
HistoryCampuses = "historyCampuses", | ||
IdSelected = "idSelected", | ||
NameSelected = "nameSelected", | ||
AvatarSelected = "avatarSelected", | ||
DraftMoment = "draftMoment", | ||
DraftPost = "draftPost", | ||
BackendEnv = "backendEnv", | ||
BackendLane = "backendLane", | ||
EnabledDebug = "enableDebug", | ||
HistorySearchText = "historySearchText" | ||
} | ||
|
||
export const enum BackendEnv { | ||
Product = "pro", | ||
Test = "test" | ||
} | ||
|
||
export const BackendEnvMap = { | ||
release: BackendEnv.Product, | ||
trial: BackendEnv.Test, | ||
develop: BackendEnv.Test | ||
}; | ||
|
||
export const AppId = 1; |
Oops, something went wrong.