diff --git a/.env.development b/.env.development new file mode 100644 index 0000000..7010158 --- /dev/null +++ b/.env.development @@ -0,0 +1,4 @@ +VITE_ENABLE_MOCK=false +VITE_API_PREFIX=/api +VITE_PROXY_ENDPOINT=https://bright.yilibili.com + diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..92b86ee --- /dev/null +++ b/.env.example @@ -0,0 +1 @@ +VITE_ENABLE_MOCK=true diff --git a/pet-manual/components/CardList.vue b/pet-manual/components/CardList.vue new file mode 100644 index 0000000..bc7973a --- /dev/null +++ b/pet-manual/components/CardList.vue @@ -0,0 +1,36 @@ + + + + + diff --git a/pet-manual/index.vue b/pet-manual/index.vue new file mode 100644 index 0000000..21de306 --- /dev/null +++ b/pet-manual/index.vue @@ -0,0 +1,232 @@ + + + + + diff --git a/src/api/carousal.ts b/src/api/carousal.ts new file mode 100644 index 0000000..89a3736 --- /dev/null +++ b/src/api/carousal.ts @@ -0,0 +1,9 @@ +import { get } from '@/api/request' + +function getCarousalList() { + return get('https://bright.yilibili.com/api/carousals/active-list') +} + +export default { + getCarousalList, +} diff --git a/src/api/request.ts b/src/api/request.ts new file mode 100644 index 0000000..971f474 --- /dev/null +++ b/src/api/request.ts @@ -0,0 +1,26 @@ +export function get(url: string, params: string | AnyObject | ArrayBuffer = {}) { + return _request('GET', url, params) +} +export function post(url: string, data: string | AnyObject | ArrayBuffer) { + return _request('POST', url, data) +} + +function _request( + method: 'OPTIONS' | 'GET' | 'HEAD' | 'POST' | 'PUT' | 'DELETE' | 'TRACE' | 'CONNECT', + url: string, + data: string | AnyObject | ArrayBuffer = {}, +) { + return new Promise((resolve, reject) => { + uni.request({ + method, + url, + data, + success: (result) => { + resolve(result.data as T) + }, + fail: (result) => { + reject('服务器无法触达') + }, + }) + }) +} diff --git a/src/model/carousals.ts b/src/model/carousals.ts new file mode 100644 index 0000000..e69de29 diff --git a/src/pages/pet-manual/components/CardList.vue b/src/pages/pet-manual/components/CardList.vue new file mode 100644 index 0000000..bc7973a --- /dev/null +++ b/src/pages/pet-manual/components/CardList.vue @@ -0,0 +1,36 @@ + + + + + diff --git a/src/pages/pet-manual/index.vue b/src/pages/pet-manual/index.vue index c373ab1..21de306 100644 --- a/src/pages/pet-manual/index.vue +++ b/src/pages/pet-manual/index.vue @@ -1,9 +1,11 @@ diff --git a/src/utils/index.ts b/src/utils/index.ts index 7a9782d..0aa1a54 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -5,6 +5,6 @@ function getSafeHeight(): number { return safeAreaInsetBottom + menuButtonInfoHeight } -export { +export default { getSafeHeight, } diff --git a/vite.config.ts b/vite.config.ts index 23167d0..c253cfc 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -8,13 +8,14 @@ import postcssPresetEnv from 'postcss-preset-env' import tailwindcss from 'tailwindcss' import nested from 'tailwindcss/nesting' import AutoImport from 'unplugin-auto-import/vite' -import { defineConfig } from 'vite' +import { defineConfig, loadEnv } from 'vite' import tailwindcssConfig from './tailwind.config' // 注意匹配实际文件 // 注意匹配实际文件 // https://vitejs.dev/config/ -export default async () => { +export default async ({ command, mode }) => { + const env = loadEnv(mode, process.cwd(), '') return defineConfig({ css: { postcss: { @@ -30,6 +31,15 @@ export default async () => { ], }, }, + server: { + proxy: { + '/api': { + target: env.VITE_PROXY_ENDPOINT, + changeOrigin: true, + rewrite: path => path.replace(/^\/api/, ''), + }, + }, + }, plugins: [ // https://github.com/uni-helper/vite-plugin-uni-manifest UniHelperManifest(),