= {
+ timeout: 12 * 1000
+};
+
+type RequestOptionsType = {
+ urlPrefix?: string;
+ method?: keyof Taro.request.Method;
+ /** GET 请求的 Query 参数,其他请求的 Body 数据 */
+ params?: P;
+ /** TODO: 将请求参数转换成 snack case,将响应数据转换成 camel case */
+ useCamelCase?: boolean;
+ /** 请求是否携带 Cookie,默认为 true,若没有 Cookie 还请求则会触发登录获取 Cookie */
+ auth?: boolean;
+};
+
+/**
+ * 发送接收 application/json 请求
+ *
+ * @param url 请求地址,不包含协议和域名,会和 `options.urlPrefix` 组成完整的地址
+ * @param options
+ * @throws {RequestError}
+ * @returns 转换成对象的响应 JSON 数据
+ */
+async function request>(
+ url: string,
+ options?: RequestOptionsType
+): Promise {
+ const {
+ urlPrefix = import.meta.env.VITE_HOST,
+ method = "GET",
+ params,
+ auth = true
+ } = options || {};
+
+ const cookie = auth ? await CookieUtils.get() : "";
+
+ try {
+ const taroWrapped = await Taro.request | undefined>({
+ ...globalConfig,
+ url: urlPrefix + url,
+ method,
+ header: {
+ "Cookie": cookie
+ },
+ data: params
+ });
+
+ const realResponse = taroWrapped.data;
+ if (realResponse) {
+ if (realResponse.code === ServiceErrorCode.OK) {
+ return realResponse.data;
+ }
+ return Promise.reject(
+ new RequestError(realResponse.msg, realResponse.code)
+ );
+ }
+ throw new RequestError("小程序网络异常", MPErrorCode.MP_INVALID_RESPONSE_BODY);
+ } catch (e: any) {
+ console.error(e);
+ throw e instanceof RequestError
+ ? e
+ : new RequestError("小程序网络异常", MPErrorCode.MP_NETWORK_ERROR);
+ }
+}
+
+export default request;
diff --git a/src/utils/storage.ts b/src/utils/storage.ts
new file mode 100644
index 00000000..1923b1bf
--- /dev/null
+++ b/src/utils/storage.ts
@@ -0,0 +1,13 @@
+import Taro from "@tarojs/taro";
+
+export const persistedStorage = {
+ setItem(key: string, value: string) {
+ return Taro.setStorageSync(key, value);
+ },
+ getItem(key: string) {
+ return Taro.getStorageSync(key);
+ },
+ removeItem(key: string) {
+ return Taro.removeStorageSync(key);
+ }
+};
diff --git a/tsconfig.json b/tsconfig.json
index 158c13f9..92c54443 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -17,6 +17,7 @@
"rootDir": ".",
"resolveJsonModule": true,
"jsx": "preserve",
+ "skipLibCheck": true,
"typeRoots": [
"node_modules/@types",
],