Преглед на файлове

Merge pull request #212 from GreatAuk/feat-utopia

代码优化
菲鸽 преди 8 месеца
родител
ревизия
8381c73377

+ 1 - 1
openapi-ts-request.config.ts

@@ -4,7 +4,7 @@ export default [
   {
     schemaPath: 'http://petstore.swagger.io/v2/swagger.json',
     serversPath: './src/service',
-    requestLibPath: `import request from '@/http/vue-query';\n import { CustomRequestOptions } from '@/http/interceptor';`,
+    requestLibPath: `import request from '@/http/vue-query';\n import { CustomRequestOptions } from '@/http/types';`,
     requestOptionsType: 'CustomRequestOptions',
     isGenReactQuery: true,
     reactQueryMode: 'vue',

+ 0 - 1
package.json

@@ -118,7 +118,6 @@
     "@iconify-json/carbon": "^1.2.4",
     "@rollup/rollup-darwin-x64": "^4.28.0",
     "@types/node": "^20.17.9",
-    "@types/wechat-miniprogram": "^3.4.8",
     "@uni-helper/eslint-config": "^0.4.0",
     "@uni-helper/plugin-uni": "0.1.0",
     "@uni-helper/uni-types": "^1.0.0-alpha.6",

+ 0 - 8
pnpm-lock.yaml

@@ -137,9 +137,6 @@ importers:
       '@types/node':
         specifier: ^20.17.9
         version: 20.19.9
-      '@types/wechat-miniprogram':
-        specifier: ^3.4.8
-        version: 3.4.8
       '@uni-helper/eslint-config':
         specifier: ^0.4.0
         version: 0.4.0(@antfu/eslint-config@4.19.0(@unocss/eslint-plugin@66.4.0(eslint@9.32.0(jiti@2.5.1))(typescript@5.9.2))(@vue/compiler-sfc@3.5.18)(eslint-plugin-format@1.0.1(eslint@9.32.0(jiti@2.5.1)))(eslint@9.32.0(jiti@2.5.1))(typescript@5.9.2))(eslint@9.32.0(jiti@2.5.1))
@@ -2315,9 +2312,6 @@ packages:
   '@types/unist@3.0.3':
     resolution: {integrity: sha512-ko/gIFJRv177XgZsZcBwnqJN5x/Gien8qNOn0D5bQU/zAzVf9Zt3BlcUiLqhV9y4ARk0GbT3tnUiPNgnTXzc/Q==}
 
-  '@types/wechat-miniprogram@3.4.8':
-    resolution: {integrity: sha512-lOqddA707X3SZxVhlZNBZPzYzj7lG/ED2fF30k+aE2oT6R4wfw0Wiup2k2hGrmzYUFyJXfGs01sDCuJMhQMAdg==}
-
   '@types/yargs-parser@21.0.3':
     resolution: {integrity: sha512-I4q9QU9MQv4oEOz4tAHJtNz1cwuLxn2F3xcc2iV5WdqLPpUnj30aUuxt1mAxYTG+oe8CZMV/+6rU4S4gRDzqtQ==}
 
@@ -9243,8 +9237,6 @@ snapshots:
 
   '@types/unist@3.0.3': {}
 
-  '@types/wechat-miniprogram@3.4.8': {}
-
   '@types/yargs-parser@21.0.3': {}
 
   '@types/yargs@16.0.9':

+ 3 - 3
src/App.vue

@@ -6,7 +6,7 @@ import 'abortcontroller-polyfill/dist/abortcontroller-polyfill-only'
 onLaunch((options) => {
   // 处理直接进入页面路由的情况:如h5直接输入路由、微信小程序分享后进入等
   // https://github.com/unibest-tech/unibest/issues/192
-  console.log('App Launch', options?.path)
+  console.log('App Launch', options)
   if (options?.path) {
     navigateToInterceptor.invoke({ url: `/${options.path}` })
   }
@@ -14,8 +14,8 @@ onLaunch((options) => {
     navigateToInterceptor.invoke({ url: '/' })
   }
 })
-onShow(() => {
-  console.log('App Show')
+onShow((options) => {
+  console.log('App Show', options)
 })
 onHide(() => {
   console.log('App Hide')

+ 0 - 0
src/hooks/.gitkeep


+ 1 - 1
src/http/alova.ts

@@ -1,5 +1,5 @@
 import type { uniappRequestAdapter } from '@alova/adapter-uniapp'
-import type { IResponse } from './tools/types'
+import type { IResponse } from './types'
 import AdapterUniapp from '@alova/adapter-uniapp'
 import { createAlova } from 'alova'
 import { createServerTokenAuthentication } from 'alova/client'

+ 1 - 1
src/http/http.ts

@@ -1,4 +1,4 @@
-import type { CustomRequestOptions } from '@/http/interceptor'
+import type { CustomRequestOptions } from '@/http/types'
 
 export function http<T>(options: CustomRequestOptions) {
   // 1. 返回 Promise 对象

+ 1 - 6
src/http/interceptor.ts

@@ -1,14 +1,9 @@
+import type { CustomRequestOptions } from '@/http/types'
 import { useUserStore } from '@/store'
 import { getEnvBaseUrl } from '@/utils'
 import { platform } from '@/utils/platform'
 import { stringifyQuery } from './tools/queryString'
 
-export type CustomRequestOptions = UniApp.RequestOptions & {
-  query?: Record<string, any>
-  /** 出错时是否隐藏错误提示 */
-  hideErrorToast?: boolean
-} & IUniUploadFileOptions // 添加uni.uploadFile参数类型
-
 // 请求基准地址
 const baseUrl = getEnvBaseUrl()
 

+ 9 - 0
src/http/tools/types.ts

@@ -1,3 +1,12 @@
+/**
+ * 在 uniapp 的 RequestOptions 和 IUniUploadFileOptions 基础上,添加自定义参数
+ */
+export type CustomRequestOptions = UniApp.RequestOptions & {
+  query?: Record<string, any>
+  /** 出错时是否隐藏错误提示 */
+  hideErrorToast?: boolean
+} & IUniUploadFileOptions // 添加uni.uploadFile参数类型
+
 // 通用响应格式
 export interface IResponse<T = any> {
   code: number | string

+ 1 - 1
src/http/vue-query.ts

@@ -1,4 +1,4 @@
-import type { CustomRequestOptions } from '@/http/interceptor'
+import type { CustomRequestOptions } from '@/http/types'
 import { http } from './http'
 
 /*

+ 1 - 1
src/service/pet.ts

@@ -1,7 +1,7 @@
 /* eslint-disable */
 // @ts-ignore
 import request from '@/http/vue-query';
-import { CustomRequestOptions } from '@/http/interceptor';
+import type { CustomRequestOptions } from '@/http/types';
 
 import * as API from './types';
 

+ 1 - 1
src/service/pet.vuequery.ts

@@ -3,7 +3,7 @@
 import { queryOptions, useMutation } from '@tanstack/vue-query';
 import type { DefaultError } from '@tanstack/vue-query';
 import request from '@/http/vue-query';
-import { CustomRequestOptions } from '@/http/interceptor';
+import type { CustomRequestOptions } from '@/http/types';
 
 import * as apis from './pet';
 import * as API from './types';

+ 1 - 1
src/service/store.ts

@@ -1,7 +1,7 @@
 /* eslint-disable */
 // @ts-ignore
 import request from '@/http/vue-query';
-import { CustomRequestOptions } from '@/http/interceptor';
+import type { CustomRequestOptions } from '@/http/types';
 
 import * as API from './types';
 

+ 1 - 1
src/service/store.vuequery.ts

@@ -3,7 +3,7 @@
 import { queryOptions, useMutation } from '@tanstack/vue-query';
 import type { DefaultError } from '@tanstack/vue-query';
 import request from '@/http/vue-query';
-import { CustomRequestOptions } from '@/http/interceptor';
+import type { CustomRequestOptions } from '@/http/types';
 
 import * as apis from './store';
 import * as API from './types';

+ 1 - 1
src/service/user.ts

@@ -1,7 +1,7 @@
 /* eslint-disable */
 // @ts-ignore
 import request from '@/http/vue-query';
-import { CustomRequestOptions } from '@/http/interceptor';
+import type { CustomRequestOptions } from '@/http/types';
 
 import * as API from './types';
 

+ 1 - 1
src/service/user.vuequery.ts

@@ -3,7 +3,7 @@
 import { queryOptions, useMutation } from '@tanstack/vue-query';
 import type { DefaultError } from '@tanstack/vue-query';
 import request from '@/http/vue-query';
-import { CustomRequestOptions } from '@/http/interceptor';
+import type { CustomRequestOptions } from '@/http/types';
 
 import * as apis from './user';
 import * as API from './types';

+ 0 - 0
src/static/images/.gitkeep


+ 7 - 4
src/tabbar/config.ts

@@ -94,14 +94,17 @@ export const customTabbarList: CustomTabBarItem[] = [
 ]
 
 // NATIVE_TABBAR(1) 和 CUSTOM_TABBAR_WITH_CACHE(2) 时,需要tabbar缓存
-export const tabbarCacheEnable = selectedTabbarStrategy === TABBAR_MAP.NATIVE_TABBAR
-  || selectedTabbarStrategy === TABBAR_MAP.CUSTOM_TABBAR_WITH_CACHE
+/** 是否启用 tabbar 缓存 */
+export const tabbarCacheEnable
+  = [TABBAR_MAP.NATIVE_TABBAR, TABBAR_MAP.CUSTOM_TABBAR_WITH_CACHE].includes(selectedTabbarStrategy)
 
 // CUSTOM_TABBAR_WITH_CACHE(2) 和 CUSTOM_TABBAR_WITHOUT_CACHE(3) 时,启用自定义tabbar
-export const customTabbarEnable = selectedTabbarStrategy === TABBAR_MAP.CUSTOM_TABBAR_WITH_CACHE
-  || selectedTabbarStrategy === TABBAR_MAP.CUSTOM_TABBAR_WITHOUT_CACHE
+/** 是否启用自定义 tabbar */
+export const customTabbarEnable
+  = [TABBAR_MAP.CUSTOM_TABBAR_WITH_CACHE, TABBAR_MAP.CUSTOM_TABBAR_WITHOUT_CACHE].includes(selectedTabbarStrategy)
 
 // CUSTOM_TABBAR_WITH_CACHE(2)时,需要隐藏原生tabbar
+/** 是否需要隐藏原生 tabbar */
 export const nativeTabbarNeedHide = selectedTabbarStrategy === TABBAR_MAP.CUSTOM_TABBAR_WITH_CACHE
 
 const _tabbar: TabBar = {

+ 19 - 7
src/utils/toast.ts

@@ -12,14 +12,24 @@ interface ToastOptions {
   position?: 'top' | 'middle' | 'bottom'
   icon?: 'success' | 'error' | 'none' | 'loading' | 'fail' | 'exception'
   message: string
+  /**
+   * 是否显示透明蒙层,防止触摸穿透
+   * @default true
+   */
+  mask?: boolean
 }
-
-export function showToast(options: ToastOptions | string) {
+/**
+ * 显示 toast
+ */
+export function showToast(message: string): void
+export function showToast(options: ToastOptions): void
+export function showToast(options: ToastOptions | string): void {
   const defaultOptions: ToastOptions = {
     type: 'info',
     duration: 2000,
     position: 'middle',
     message: '',
+    mask: true,
   }
   const mergedOptions
     = typeof options === 'string'
@@ -49,17 +59,19 @@ export function showToast(options: ToastOptions | string) {
     duration: mergedOptions.duration,
     position: positionMap[mergedOptions.position],
     icon: mergedOptions.icon || iconMap[mergedOptions.type],
-    mask: true,
+    mask: mergedOptions.mask,
   })
 }
 
+type _ToastOptions = Omit<ToastOptions, 'type' | 'message'>
+
 export const toast = {
-  success: (message: string, options?: Omit<ToastOptions, 'type'>) =>
+  success: (message: string, options?: _ToastOptions) =>
     showToast({ ...options, type: 'success', message }),
-  error: (message: string, options?: Omit<ToastOptions, 'type'>) =>
+  error: (message: string, options?: _ToastOptions) =>
     showToast({ ...options, type: 'error', message }),
-  warning: (message: string, options?: Omit<ToastOptions, 'type'>) =>
+  warning: (message: string, options?: _ToastOptions) =>
     showToast({ ...options, type: 'warning', message }),
-  info: (message: string, options?: Omit<ToastOptions, 'type'>) =>
+  info: (message: string, options?: _ToastOptions) =>
     showToast({ ...options, type: 'info', message }),
 }

+ 1 - 1
tsconfig.json

@@ -13,7 +13,7 @@
     "types": [
       "@dcloudio/types",
       "@uni-helper/uni-types",
-      "@types/wechat-miniprogram",
+      "miniprogram-api-typings",
       "wot-design-uni/global.d.ts",
       "z-paging/types",
       "./src/typings.d.ts"