Skip to content

Commit

Permalink
Merge pull request #1 from xh-polaris/master
Browse files Browse the repository at this point in the history
chore: 配置pages和utils
  • Loading branch information
LLLzzh authored Jul 29, 2024
2 parents 7bbe0fc + 336a263 commit 69c4823
Show file tree
Hide file tree
Showing 16 changed files with 385 additions and 53 deletions.
22 changes: 22 additions & 0 deletions src/env.d.ts
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;
}
40 changes: 40 additions & 0 deletions src/interceptor.ts
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"
});
}
});
}
57 changes: 55 additions & 2 deletions src/pages.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,62 @@
{
"pages": [ //pages数组中第一项表示应用启动页,参考:https://uniapp.dcloud.io/collocation/pages
{
"path": "pages/index/index",
"path": "pages/first-page/first-page",
"style": {
"navigationBarTitleText": "uni-app"
"navigationBarTitleText": ""
}
},
{
"path": "pages/album/meow-album",
"style": {
"navigationBarTitleText": "猫猫相册"
}
},
{
"path": "pages/album/time-album",
"style": {
"navigationBarTitleText": "时间轴"
}
},
{
"path": "pages/album/location-album",
"style": {
"navigationBarTitleText": "地点相册"
}
},
{
"path": "pages/album/album-detail",
"style": {
}
},
{
"path": "pages/album/photo-detail",
"style": {
"navigationBarTitleText": "相片详情"
}
},
{
"path": "pages/album/album-settings",
"style": {
"navigationBarTitleText": "相册设置"
}
},
{
"path": "pages/album/album-comment",
"style": {
"navigationBarTitleText": "相册评论"
}
},
{
"path": "pages/meow-planet/meow-planet",
"style": {
"navigationBarTitleText": "喵星"
}
},
{
"path": "pages/profile/profile",
"style": {
"navigationBarTitleText": "我的"
}
}
],
Expand Down
11 changes: 11 additions & 0 deletions src/pages/album/album-detail/album-detail.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<script setup lang="ts">
</script>

<template>

</template>

<style scoped>
</style>
11 changes: 11 additions & 0 deletions src/pages/album/album-settings/album-settings.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<script setup lang="ts">
</script>

<template>

</template>

<style scoped>
</style>
11 changes: 11 additions & 0 deletions src/pages/album/meow-album/meow-album.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<script setup lang="ts">
</script>

<template>

</template>

<style scoped>
</style>
11 changes: 11 additions & 0 deletions src/pages/album/photo-detail/photo-detail.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<script setup lang="ts">
</script>

<template>

</template>

<style scoped>
</style>
11 changes: 11 additions & 0 deletions src/pages/album/time-album/time-album.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<script setup lang="ts">
</script>

<template>

</template>

<style scoped>
</style>
11 changes: 11 additions & 0 deletions src/pages/first-page/first-page.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<script setup lang="ts">
</script>

<template>

</template>

<style scoped>
</style>
51 changes: 0 additions & 51 deletions src/pages/index/index.vue

This file was deleted.

11 changes: 11 additions & 0 deletions src/pages/meow-planet/meow-planet.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<script setup lang="ts">
</script>

<template>

</template>

<style scoped>
</style>
11 changes: 11 additions & 0 deletions src/pages/profile/profile.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<script setup lang="ts">
</script>

<template>

</template>

<style scoped>
</style>
28 changes: 28 additions & 0 deletions src/utils/const.ts
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;
Loading

0 comments on commit 69c4823

Please sign in to comment.