From 28caa1dea30631e64be18cc1542ca9c9fc122316 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8F=B2=E9=B8=BD?= <1020103647@qq.com> Date: Wed, 17 Apr 2024 15:32:15 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A4=A7=E9=87=8F=E5=8D=87=E7=BA=A7?= =?UTF-8?q?=EF=BC=8Cv2.0.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .eslintrc-auto-import.json | 3 +- .stylelintrc.cjs | 5 +- env/.env | 14 ++--- env/.env.development | 4 +- env/.env.production | 4 +- package.json | 44 +++++++------- shell/postinstall.sh | 10 ---- shell/rename.sh | 17 ------ src/{pages-sub => components}/.gitkeep | 0 src/components/AppTest.vue | 6 -- src/hooks/useRequest.ts | 42 ++++++++++++++ src/i18n.d.ts | 9 --- src/interceptors/index.ts | 1 + src/interceptors/prototype.ts | 13 +++++ src/interceptors/request.ts | 21 ++++--- src/interceptors/route.ts | 23 ++++---- src/layouts/default.vue | 7 --- src/layouts/demo.vue | 2 +- src/main.ts | 4 +- src/manifest.json | 5 +- src/pages-sub/README.md | 19 ------ src/pages.json | 8 +++ src/pages/index/about.vue | 16 ++---- src/pages/index/index.vue | 11 +++- src/pages/index/request.vue | 33 +++++------ src/pages/index/request2.vue | 30 ++++++++++ src/service/{ => index}/foo.d.ts | 0 src/service/{ => index}/foo.ts | 0 src/shime-uni.d.ts | 14 ----- global.d.ts => src/types/global.d.ts | 0 src/typings.ts | 2 - src/utils/http.ts | 9 +-- src/utils/index.ts | 10 +--- tsconfig.json | 11 ++-- uno.config.ts | 10 +--- vite-plugins/imagemin.ts | 43 -------------- vite.config.ts | 80 +++++++++++--------------- 37 files changed, 233 insertions(+), 297 deletions(-) delete mode 100644 shell/postinstall.sh delete mode 100644 shell/rename.sh rename src/{pages-sub => components}/.gitkeep (100%) delete mode 100644 src/components/AppTest.vue create mode 100644 src/hooks/useRequest.ts delete mode 100644 src/i18n.d.ts create mode 100644 src/interceptors/prototype.ts delete mode 100644 src/pages-sub/README.md create mode 100644 src/pages/index/request2.vue rename src/service/{ => index}/foo.d.ts (100%) rename src/service/{ => index}/foo.ts (100%) delete mode 100644 src/shime-uni.d.ts rename global.d.ts => src/types/global.d.ts (100%) delete mode 100644 vite-plugins/imagemin.ts diff --git a/.eslintrc-auto-import.json b/.eslintrc-auto-import.json index be77d70..9988edd 100644 --- a/.eslintrc-auto-import.json +++ b/.eslintrc-auto-import.json @@ -86,6 +86,7 @@ "watch": true, "watchEffect": true, "watchPostEffect": true, - "watchSyncEffect": true + "watchSyncEffect": true, + "useRequest": true } } diff --git a/.stylelintrc.cjs b/.stylelintrc.cjs index 3f6cb98..b2f0a8f 100644 --- a/.stylelintrc.cjs +++ b/.stylelintrc.cjs @@ -4,7 +4,8 @@ module.exports = { root: true, extends: [ 'stylelint-config-standard', - 'stylelint-config-standard-scss', // tips: 本插件也可以替换成 stylelint-config-recommended-scss + // stylelint-config-standard-scss 替换成了更宽松的 stylelint-config-recommended-scss + 'stylelint-config-recommended-scss', 'stylelint-config-recommended-vue/scss', 'stylelint-config-html/vue', 'stylelint-config-recess-order', @@ -49,5 +50,7 @@ module.exports = { 'no-empty-source': null, 'comment-no-empty': null, 'no-duplicate-selectors': null, + 'scss/comment-no-empty': null, + 'selector-class-pattern': null, }, } diff --git a/env/.env b/env/.env index d1bbf28..c71934d 100644 --- a/env/.env +++ b/env/.env @@ -1,18 +1,12 @@ VITE_APP_TITLE = 'unibest' VITE_APP_PORT = 9000 -# github actions 部署地址根路径,用在 manifest.config.ts 里面的 h5.router.base +# h5部署网站的base,配置到 manifest.config.ts 里的 h5.router.base VITE_APP_PUBLIC_BASE=/ -# TODO: 记得修改 -VITE_UNI_APPID = 'H5871D791' +VITE_UNI_APPID = 'H57F2ACE4' VITE_WX_APPID = 'wxa2abb91f64032a2b' -# fallback lacale:en, zh-Hans, zh-Hant 等 -# 必须要在 lacale 文件夹中配置对应的 json 文件!!! -# 参考文档如下 -# https://uniapp.dcloud.net.cn/tutorial/i18n.html -# https://uniapp.dcloud.net.cn/api/ui/locale.html#onlocalechange 打开页面后最下面的注意事项 -VITE_FALLBACK_LOCALE = 'zh-Hans' - +# 非h5端只能使用完整的baseurl,否则无法请求,本地proxy只支持h5端 +# VITE_SERVER_BASEURL = '/api' VITE_SERVER_BASEURL = 'https://ukw0y1.laf.run' diff --git a/env/.env.development b/env/.env.development index dd0a1f2..04fa273 100644 --- a/env/.env.development +++ b/env/.env.development @@ -2,5 +2,5 @@ NODE_ENV = 'development' # 是否去除console 和 debugger VITE_DELETE_CONSOLE = false - -# VITE_SERVER_BASEURL = 'https://ukw0y1.laf.run' +# 是否开启sourcemap +VITE_SHOW_SOURCEMAP = true diff --git a/env/.env.production b/env/.env.production index 94b3031..8a1b50c 100644 --- a/env/.env.production +++ b/env/.env.production @@ -2,5 +2,5 @@ NODE_ENV = 'development' # 是否去除console 和 debugger VITE_DELETE_CONSOLE = true - -# VITE_SERVER_BASEURL = 'https://xxx.com' +# 是否开启sourcemap +VITE_SHOW_SOURCEMAP = false diff --git a/package.json b/package.json index 9260b22..716654b 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "unibest", "type": "commonjs", - "version": "1.5.0", + "version": "2.0.0", "description": "unibest - 最好的 uniapp 开发模板", "author": { "name": "codercup", @@ -22,6 +22,7 @@ "pnpm": ">=7.30" }, "scripts": { + "upgrade": "npx @dcloudio/uvm@latest", "dev:app": "uni -p app", "dev:app-android": "uni -p app-android", "dev:app-ios": "uni -p app-ios", @@ -78,20 +79,20 @@ "bin-wrapper": "npm:bin-wrapper-china" }, "dependencies": { - "@dcloudio/uni-app": "3.0.0-4000720240327002", - "@dcloudio/uni-app-plus": "3.0.0-4000720240327002", - "@dcloudio/uni-components": "3.0.0-4000720240327002", - "@dcloudio/uni-h5": "3.0.0-4000720240327002", - "@dcloudio/uni-mp-alipay": "3.0.0-4000720240327002", - "@dcloudio/uni-mp-baidu": "3.0.0-4000720240327002", - "@dcloudio/uni-mp-jd": "3.0.0-4000720240327002", - "@dcloudio/uni-mp-kuaishou": "3.0.0-4000720240327002", - "@dcloudio/uni-mp-lark": "3.0.0-4000720240327002", - "@dcloudio/uni-mp-qq": "3.0.0-4000720240327002", - "@dcloudio/uni-mp-toutiao": "3.0.0-4000720240327002", - "@dcloudio/uni-mp-weixin": "3.0.0-4000720240327002", - "@dcloudio/uni-mp-xhs": "3.0.0-4000720240327002", - "@dcloudio/uni-quickapp-webview": "3.0.0-4000720240327002", + "@dcloudio/uni-app": "3.0.0-4000820240401001", + "@dcloudio/uni-app-plus": "3.0.0-4000820240401001", + "@dcloudio/uni-components": "3.0.0-4000820240401001", + "@dcloudio/uni-h5": "3.0.0-4000820240401001", + "@dcloudio/uni-mp-alipay": "3.0.0-4000820240401001", + "@dcloudio/uni-mp-baidu": "3.0.0-4000820240401001", + "@dcloudio/uni-mp-jd": "3.0.0-4000820240401001", + "@dcloudio/uni-mp-kuaishou": "3.0.0-4000820240401001", + "@dcloudio/uni-mp-lark": "3.0.0-4000820240401001", + "@dcloudio/uni-mp-qq": "3.0.0-4000820240401001", + "@dcloudio/uni-mp-toutiao": "3.0.0-4000820240401001", + "@dcloudio/uni-mp-weixin": "3.0.0-4000820240401001", + "@dcloudio/uni-mp-xhs": "3.0.0-4000820240401001", + "@dcloudio/uni-quickapp-webview": "3.0.0-4000820240401001", "dayjs": "1.11.10", "pinia": "2.0.36", "pinia-plugin-persistedstate": "3.2.1", @@ -103,22 +104,21 @@ "@commitlint/cli": "^18.4.3", "@commitlint/config-conventional": "^18.4.3", "@dcloudio/types": "^3.4.8", - "@dcloudio/uni-automator": "3.0.0-4000720240327002", - "@dcloudio/uni-cli-shared": "3.0.0-4000720240327002", - "@dcloudio/uni-stacktracey": "3.0.0-4000720240327002", - "@dcloudio/vite-plugin-uni": "3.0.0-4000720240327002", + "@dcloudio/uni-automator": "3.0.0-4000820240401001", + "@dcloudio/uni-cli-shared": "3.0.0-4000820240401001", + "@dcloudio/uni-stacktracey": "3.0.0-4000820240401001", + "@dcloudio/vite-plugin-uni": "3.0.0-4000820240401001", "@iconify-json/carbon": "^1.1.27", "@types/node": "^20.11.5", "@types/wechat-miniprogram": "^3.4.7", "@typescript-eslint/eslint-plugin": "^6.15.0", "@typescript-eslint/parser": "^6.15.0", - "@uni-helper/vite-plugin-uni-components": "^0.0.8", "@uni-helper/vite-plugin-uni-layouts": "^0.1.7", "@uni-helper/vite-plugin-uni-manifest": "^0.2.3", "@uni-helper/vite-plugin-uni-pages": "^0.2.15", "@uni-helper/vite-plugin-uni-platform": "^0.0.4", "@unocss/preset-legacy-compat": "^0.59.1", - "@vue/runtime-core": "^3.3.13", + "@vue/runtime-core": "^3.4.21", "@vue/tsconfig": "^0.1.3", "autoprefixer": "^10.4.16", "commitlint": "^18.4.3", @@ -139,9 +139,9 @@ "stylelint": "^16.0.2", "stylelint-config-html": "^1.1.0", "stylelint-config-recess-order": "^4.4.0", + "stylelint-config-recommended-scss": "^14.0.0", "stylelint-config-recommended-vue": "^1.5.0", "stylelint-config-standard": "^35.0.0", - "stylelint-config-standard-scss": "^12.0.0", "stylelint-prettier": "^5.0.0", "terser": "^5.26.0", "typescript": "^4.9.5", diff --git a/shell/postinstall.sh b/shell/postinstall.sh deleted file mode 100644 index be33812..0000000 --- a/shell/postinstall.sh +++ /dev/null @@ -1,10 +0,0 @@ -# 本文件会在依赖包安装时执行,用以生成 `src/manifest.json` -# 如果不存在 `src/manifest.json` 会运行报错,提示找不到 `src/manifest.json` -# 如果中途自己删除了 'src/manifest.json' 文件,记得手动执行本文件,可以右键 `Run Code` 快速执行 - -if test -f ./src/manifest.json; then - echo ./src/manifest.json 存在 -else - touch ./src/manifest.json - echo "{}" >./src/manifest.json -fi diff --git a/shell/rename.sh b/shell/rename.sh deleted file mode 100644 index 3a5e14e..0000000 --- a/shell/rename.sh +++ /dev/null @@ -1,17 +0,0 @@ -# pnpm build:app 之后会生成 unpackage/dist/build/app -# 我要把它改名为 unpackage/dist/build/unibest_app_build - -# 只有存在新的 app 文件时,才执行这些操作!!否则会误删!! -if test -d ./dist/build/app; then - echo '存在新打包出来的app' - - cd ./dist/build/ - - # 1、删除旧的 rename 后的文件夹 - if test -d './unibest_app_build'; then - rm -rf ./unibest_app_build - fi - - # 2、把 app 命名为 unibest_app_build - mv ./app ./unibest_app_build -fi diff --git a/src/pages-sub/.gitkeep b/src/components/.gitkeep similarity index 100% rename from src/pages-sub/.gitkeep rename to src/components/.gitkeep diff --git a/src/components/AppTest.vue b/src/components/AppTest.vue deleted file mode 100644 index 8c3d438..0000000 --- a/src/components/AppTest.vue +++ /dev/null @@ -1,6 +0,0 @@ - - diff --git a/src/hooks/useRequest.ts b/src/hooks/useRequest.ts new file mode 100644 index 0000000..9cc392b --- /dev/null +++ b/src/hooks/useRequest.ts @@ -0,0 +1,42 @@ +type IUseRequestOptions = { + /** 是否立即执行,如果是则在onLoad执行 */ + immediate?: boolean + /** 初始化数据 */ + initialData?: T +} + +/** + * useRequest是一个定制化的请求钩子,用于处理异步请求和响应。 + * @param func 一个执行异步请求的函数,返回一个包含响应数据的Promise。 + * @param options 包含请求选项的对象 {immediate, initialData}。 + * @param options.immediate 是否立即执行请求,默认为true。 + * @param options.initialData 初始化数据,默认为undefined。 + * @returns 返回一个对象{loading, error, data, run},包含请求的加载状态、错误信息、响应数据和手动触发请求的函数。 + */ +export default function useRequest( + func: () => Promise>, + options: IUseRequestOptions = { immediate: true }, +) { + const loading = ref(false) + const error = ref(false) + const data = ref() + const run = async () => { + loading.value = true + func() + .then((res) => { + data.value = res.data + error.value = false + }) + .catch((err) => { + error.value = err + }) + .finally(() => { + loading.value = false + }) + } + + onLoad(() => { + options.immediate && run() + }) + return { loading, error, data, run } +} diff --git a/src/i18n.d.ts b/src/i18n.d.ts deleted file mode 100644 index b9c76e3..0000000 --- a/src/i18n.d.ts +++ /dev/null @@ -1,9 +0,0 @@ -/* eslint-disable no-unused-vars */ -export {} - -declare module 'vue' { - interface ComponentCustomProperties { - $t: (key: string, opt?: Record) => string - $tm: (key: string, opt?: Record) => [] | { [p: string]: any } - } -} diff --git a/src/interceptors/index.ts b/src/interceptors/index.ts index 477545a..292d9f8 100644 --- a/src/interceptors/index.ts +++ b/src/interceptors/index.ts @@ -1,2 +1,3 @@ export { routeInterceptor } from './route' export { requestInterceptor } from './request' +export { prototypeInterceptor } from './prototype' diff --git a/src/interceptors/prototype.ts b/src/interceptors/prototype.ts new file mode 100644 index 0000000..4e19e02 --- /dev/null +++ b/src/interceptors/prototype.ts @@ -0,0 +1,13 @@ +export const prototypeInterceptor = { + install() { + // 解决低版本手机不识别 array.at() 导致运行报错的问题 + if (typeof Array.prototype.at !== 'function') { + // eslint-disable-next-line no-extend-native + Array.prototype.at = function (index: number) { + if (index < 0) return this[this.length + index] + if (index >= this.length) return undefined + return this[index] + } + } + }, +} diff --git a/src/interceptors/request.ts b/src/interceptors/request.ts index 8e18f62..5ae62f3 100644 --- a/src/interceptors/request.ts +++ b/src/interceptors/request.ts @@ -1,13 +1,16 @@ /* eslint-disable no-param-reassign */ import qs from 'qs' import { useUserStore } from '@/store' +import { platform } from '@/utils/platform' export type CustomRequestOptions = UniApp.RequestOptions & { query?: Record + /** 出错时是否隐藏错误提示 */ + hideErrorToast?: boolean } & IUniUploadFileOptions // 添加uni.uploadFile参数类型 -// 请求基地址 -const baseURL = import.meta.env.VITE_SERVER_BASEURL +// 请求基准地址 +const baseUrl = import.meta.env.VITE_SERVER_BASEURL // 拦截器配置 const httpInterceptor = { @@ -22,19 +25,19 @@ const httpInterceptor = { options.url += `?${queryStr}` } } - - // 1. 非 http 开头需拼接地址 + // 非 http 开头需拼接地址 if (!options.url.startsWith('http')) { - options.url = baseURL + options.url + options.url = baseUrl + options.url + // TIPS: 如果需要对接多个后端服务,也可以在这里处理,拼接成所需要的地址 } - // 2. 请求超时 + // 1. 请求超时 options.timeout = 10000 // 10s - // 3. 添加小程序端请求头标识 + // 2. (可选)添加小程序端请求头标识 options.header = { - platform: 'mp-weixin', // 可选值与 uniapp 定义的平台一致,告诉后台来源 + platform, // 可选,与 uniapp 定义的平台一致,告诉后台来源 ...options.header, } - // 4. 添加 token 请求头标识 + // 3. 添加 token 请求头标识 const userStore = useUserStore() const { token } = userStore.userInfo as unknown as IUserInfo if (token) { diff --git a/src/interceptors/route.ts b/src/interceptors/route.ts index e103bee..fb8ad33 100644 --- a/src/interceptors/route.ts +++ b/src/interceptors/route.ts @@ -21,7 +21,7 @@ const isDev = import.meta.env.DEV const navigateToInterceptor = { // 注意,这里的url是 '/' 开头的,如 '/pages/index/index',跟 'pages.json' 里面的 path 不同 invoke({ url }: { url: string }) { - console.log(url) // /pages/route-interceptor/index?name=feige&age=30 + // console.log(url) // /pages/route-interceptor/index?name=feige&age=30 const path = url.split('?')[0] let needLoginPages: string[] = [] // 为了防止开发时出现BUG,这里每次都获取一下。生产环境可以移到函数外,性能更好 @@ -30,18 +30,17 @@ const navigateToInterceptor = { } else { needLoginPages = _needLoginPages } - console.log(needLoginPages.includes(path)) - - if (needLoginPages.includes(path)) { - const isLogin = isLogined() - if (isLogin) { - return true - } - const redirectRoute = `${loginRoute}?redirect=${encodeURIComponent(url)}` - uni.navigateTo({ url: redirectRoute }) - return false + const isNeedLogin = needLoginPages.includes(path) + if (!isNeedLogin) { + return true } - return true + const hasLogin = isLogined() + if (hasLogin) { + return true + } + const redirectRoute = `${loginRoute}?redirect=${encodeURIComponent(url)}` + uni.navigateTo({ url: redirectRoute }) + return false }, } diff --git a/src/layouts/default.vue b/src/layouts/default.vue index 2e4a040..5a296ff 100644 --- a/src/layouts/default.vue +++ b/src/layouts/default.vue @@ -3,10 +3,3 @@ - - diff --git a/src/layouts/demo.vue b/src/layouts/demo.vue index 2de39ab..44407ec 100644 --- a/src/layouts/demo.vue +++ b/src/layouts/demo.vue @@ -1,5 +1,5 @@ diff --git a/src/main.ts b/src/main.ts index 4035c45..8e4466e 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,8 +1,7 @@ import { createSSRApp } from 'vue' import App from './App.vue' import store from './store' -import { routeInterceptor, requestInterceptor } from './interceptors' -import 'virtual:svg-icons-register' +import { routeInterceptor, requestInterceptor, prototypeInterceptor } from './interceptors' import 'virtual:uno.css' import '@/style/index.scss' @@ -11,6 +10,7 @@ export function createApp() { app.use(store) app.use(routeInterceptor) app.use(requestInterceptor) + app.use(prototypeInterceptor) return { app, } diff --git a/src/manifest.json b/src/manifest.json index 2ef8961..f6ad007 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -1,6 +1,6 @@ { - "name": "unibest", - "appid": "H5871D791", + "name": "unibest-base", + "appid": "H57F2ACE4", "description": "", "versionName": "1.0.0", "versionCode": "100", @@ -71,7 +71,6 @@ "enable": false }, "vueVersion": "3", - "locale": "zh-Hans", "h5": { "router": { "base": "/" diff --git a/src/pages-sub/README.md b/src/pages-sub/README.md deleted file mode 100644 index 02bbfa4..0000000 --- a/src/pages-sub/README.md +++ /dev/null @@ -1,19 +0,0 @@ -# 分包配置 - -在 `vite.config.ts` 中进行配置。 - -```ts -import { defineConfig } from 'vite' -import UniPages from '@uni-helper/vite-plugin-uni-pages' - -export default defineConfig({ - plugins: [ - UniPages({ - // ... 其他配置 - subPackages: [ - 'src/pages-sub', // 是个数组,可以配置多个 - ], - }), - ], -}) -``` diff --git a/src/pages.json b/src/pages.json index 640ab9e..018414c 100644 --- a/src/pages.json +++ b/src/pages.json @@ -59,6 +59,14 @@ "style": { "navigationBarTitleText": "请求" } + }, + { + "path": "pages/index/request2", + "type": "page", + "layout": "demo", + "style": { + "navigationBarTitleText": "请求" + } } ], "subPackages": [] diff --git a/src/pages/index/about.vue b/src/pages/index/about.vue index ef122d9..864ca2e 100644 --- a/src/pages/index/about.vue +++ b/src/pages/index/about.vue @@ -16,27 +16,19 @@ 鸽友们好,我是 菲鸽 - + 去请求页 + + 去请求页2 (请求状态一体化) + - - - 当前平台是: - {{ PLATFORM.platform }} - - 设计稿样式编写: - 设计稿是750px,css里面全部写rpx 即可 diff --git a/src/service/foo.d.ts b/src/service/index/foo.d.ts similarity index 100% rename from src/service/foo.d.ts rename to src/service/index/foo.d.ts diff --git a/src/service/foo.ts b/src/service/index/foo.ts similarity index 100% rename from src/service/foo.ts rename to src/service/index/foo.ts diff --git a/src/shime-uni.d.ts b/src/shime-uni.d.ts deleted file mode 100644 index 06cc283..0000000 --- a/src/shime-uni.d.ts +++ /dev/null @@ -1,14 +0,0 @@ -export {} - -declare module 'vue' { - type Hooks = App.AppInstance & Page.PageInstance - interface ComponentCustomOptions extends Hooks { - $uv?: any - } -} - -declare global { - interface Uni { - $uv?: any - } -} diff --git a/global.d.ts b/src/types/global.d.ts similarity index 100% rename from global.d.ts rename to src/types/global.d.ts diff --git a/src/typings.ts b/src/typings.ts index 69d3e8f..06354be 100644 --- a/src/typings.ts +++ b/src/typings.ts @@ -1,5 +1,3 @@ -/* eslint-disable @typescript-eslint/no-unused-vars */ -/* eslint-disable no-unused-vars */ // 全局要用的类型放到这里 type IResData = { diff --git a/src/utils/http.ts b/src/utils/http.ts index c34a6d3..b275bc2 100644 --- a/src/utils/http.ts +++ b/src/utils/http.ts @@ -22,10 +22,11 @@ export const http = (options: CustomRequestOptions) => { reject(res) } else { // 其他错误 -> 根据后端错误信息轻提示 - uni.showToast({ - icon: 'none', - title: (res.data as IResData).msg || '请求错误', - }) + !options.hideErrorToast && + uni.showToast({ + icon: 'none', + title: (res.data as IResData).msg || '请求错误', + }) reject(res) } }, diff --git a/src/utils/index.ts b/src/utils/index.ts index 4590ede..98fe2b6 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -8,7 +8,7 @@ export const getIsTabbar = () => { return false } const pages = getCurrentPages() - const lastPage = getArrElementByIdx(pages, -1) + const lastPage = pages.at(-1) const currPath = lastPage.route return !!pagesJson.tabBar.list.find((e) => e.pagePath === currPath) } @@ -22,7 +22,7 @@ export const currRoute = () => { const pages = getCurrentPages() console.log('pages:', pages) - const lastPage = getArrElementByIdx(pages, -1) + const lastPage = pages.at(-1) const currRoute = (lastPage as any).$page // console.log('lastPage.$page:', currRoute) // console.log('lastPage.$page.fullpath:', currRoute.fullPath) @@ -105,9 +105,3 @@ export const getNeedLoginPages = (): string[] => getAllPages('needLogin').map((p * 只得到 path 数组 */ export const needLoginPages: string[] = getAllPages('needLogin').map((page) => page.path) - -export const getArrElementByIdx = (arr: any[], index: number) => { - if (index < 0) return arr[arr.length + index] - if (index >= arr.length) return undefined - return arr[index] -} diff --git a/tsconfig.json b/tsconfig.json index f9c8b89..0094d59 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -4,7 +4,10 @@ "skipLibCheck": true, "module": "ESNext", "moduleResolution": "Node", + "resolveJsonModule": true, + "noImplicitThis": true, "allowSyntheticDefaultImports": true, + "allowJs": true, "sourceMap": true, "baseUrl": ".", "paths": { @@ -12,13 +15,7 @@ }, "outDir": "dist", "lib": ["esnext", "dom"], - "types": [ - "@dcloudio/types", - "@types/wechat-miniprogram", - "wot-design-uni/global.d.ts", - "./components.d.ts", - "./global.d.ts" - ] + "types": ["@dcloudio/types", "@types/wechat-miniprogram", "wot-design-uni/global.d.ts"] }, "vueCompilerOptions": { "target": 3, diff --git a/uno.config.ts b/uno.config.ts index 4a32262..63ff448 100644 --- a/uno.config.ts +++ b/uno.config.ts @@ -8,12 +8,7 @@ import { transformerVariantGroup, } from 'unocss' -import { - presetApplet, - presetRemRpx, - transformerApplet, - transformerAttributify, -} from 'unocss-applet' +import { presetApplet, presetRemRpx, transformerAttributify } from 'unocss-applet' // @see https://unocss.dev/presets/legacy-compat import presetLegacyCompat from '@unocss/preset-legacy-compat' @@ -36,8 +31,8 @@ if (!isH5) { } export default defineConfig({ presets: [ - presetApplet({ enable: !isH5 }), ...presets, + presetApplet(), // 支持图标,需要搭配图标库,eg: @iconify-json/carbon, 使用 `