diff --git a/.github/release.yml b/.github/release.yml
index f31e34c..6ae23b0 100644
--- a/.github/release.yml
+++ b/.github/release.yml
@@ -1,31 +1,31 @@
categories:
- - title: '🚀 新功能'
- labels: ['feat', 'feature']
- - title: '🛠️ 修复'
- labels: ['fix', 'bugfix']
- - title: '💅 样式'
- labels: ['style']
- - title: '📄 文档'
- labels: ['docs']
- - title: '⚡️ 性能'
- labels: ['perf']
- - title: '🧪 测试'
- labels: ['test']
- - title: '♻️ 重构'
- labels: ['refactor']
- - title: '📦 构建'
- labels: ['build']
- - title: '🚨 补丁'
- labels: ['patch', 'hotfix']
- - title: '🌐 发布'
- labels: ['release', 'publish']
- - title: '🔧 流程'
- labels: ['ci', 'cd', 'workflow']
- - title: '⚙️ 配置'
- labels: ['config', 'chore']
- - title: '📁 文件'
- labels: ['file']
- - title: '🎨 格式化'
- labels: ['format']
- - title: '🔀 其他'
- labels: ['other', 'misc']
+ - title: 🚀 新功能
+ labels: [feat, feature]
+ - title: 🛠️ 修复
+ labels: [fix, bugfix]
+ - title: 💅 样式
+ labels: [style]
+ - title: 📄 文档
+ labels: [docs]
+ - title: ⚡️ 性能
+ labels: [perf]
+ - title: 🧪 测试
+ labels: [test]
+ - title: ♻️ 重构
+ labels: [refactor]
+ - title: 📦 构建
+ labels: [build]
+ - title: 🚨 补丁
+ labels: [patch, hotfix]
+ - title: 🌐 发布
+ labels: [release, publish]
+ - title: 🔧 流程
+ labels: [ci, cd, workflow]
+ - title: ⚙️ 配置
+ labels: [config, chore]
+ - title: 📁 文件
+ labels: [file]
+ - title: 🎨 格式化
+ labels: [format]
+ - title: 🔀 其他
+ labels: [other, misc]
diff --git a/manifest.config.ts b/manifest.config.ts
index 2a8b454..5358d43 100644
--- a/manifest.config.ts
+++ b/manifest.config.ts
@@ -1,6 +1,6 @@
+import path from 'node:path'
// manifest.config.ts
import { defineManifestConfig } from '@uni-helper/vite-plugin-uni-manifest'
-import path from 'node:path'
import { loadEnv } from 'vite'
// 获取环境变量的范例
@@ -14,14 +14,14 @@ const {
} = env
export default defineManifestConfig({
- name: VITE_APP_TITLE,
- appid: VITE_UNI_APPID,
- description: '',
- versionName: '1.0.0',
- versionCode: '100',
- transformPx: false,
- locale: VITE_FALLBACK_LOCALE, // 'zh-Hans'
- h5: {
+ 'name': VITE_APP_TITLE,
+ 'appid': VITE_UNI_APPID,
+ 'description': '',
+ 'versionName': '1.0.0',
+ 'versionCode': '100',
+ 'transformPx': false,
+ 'locale': VITE_FALLBACK_LOCALE, // 'zh-Hans'
+ 'h5': {
router: {
base: VITE_APP_PUBLIC_BASE,
},
@@ -82,14 +82,14 @@ export default defineManifestConfig({
ios: {
appstore: 'static/app/icons/1024x1024.png',
ipad: {
- app: 'static/app/icons/76x76.png',
+ 'app': 'static/app/icons/76x76.png',
'app@2x': 'static/app/icons/152x152.png',
- notification: 'static/app/icons/20x20.png',
+ 'notification': 'static/app/icons/20x20.png',
'notification@2x': 'static/app/icons/40x40.png',
'proapp@2x': 'static/app/icons/167x167.png',
- settings: 'static/app/icons/29x29.png',
+ 'settings': 'static/app/icons/29x29.png',
'settings@2x': 'static/app/icons/58x58.png',
- spotlight: 'static/app/icons/40x40.png',
+ 'spotlight': 'static/app/icons/40x40.png',
'spotlight@2x': 'static/app/icons/80x80.png',
},
iphone: {
@@ -107,7 +107,7 @@ export default defineManifestConfig({
},
},
/* 快应用特有相关 */
- quickapp: {},
+ 'quickapp': {},
/* 小程序特有相关 */
'mp-weixin': {
appid: VITE_WX_APPID,
@@ -130,8 +130,8 @@ export default defineManifestConfig({
'mp-toutiao': {
usingComponents: true,
},
- uniStatistics: {
+ 'uniStatistics': {
enable: false,
},
- vueVersion: '3',
+ 'vueVersion': '3',
})
diff --git a/scripts/postupgrade.js b/scripts/postupgrade.js
index 05b8849..f8ada60 100644
--- a/scripts/postupgrade.js
+++ b/scripts/postupgrade.js
@@ -3,7 +3,7 @@
// # 只需要执行下面的命令即可
// eslint-disable-next-line @typescript-eslint/no-var-requires
-const { exec } = require('child_process')
+const { exec } = require('node:child_process')
// 定义要执行的命令
const dependencies = [
diff --git a/src/App.vue b/src/App.vue
index 302878f..fc282a1 100644
--- a/src/App.vue
+++ b/src/App.vue
@@ -1,7 +1,7 @@
+
+
+
+
+
+
+
+
diff --git a/src/layouts/demo.vue b/src/layouts/demo.vue
index 768d875..360c6b2 100644
--- a/src/layouts/demo.vue
+++ b/src/layouts/demo.vue
@@ -1,11 +1,3 @@
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
diff --git a/src/layouts/fg-tabbar/fg-tabbar.vue b/src/layouts/fg-tabbar/fg-tabbar.vue
index e9ae386..0079c25 100644
--- a/src/layouts/fg-tabbar/fg-tabbar.vue
+++ b/src/layouts/fg-tabbar/fg-tabbar.vue
@@ -1,11 +1,43 @@
+
+
@@ -13,7 +45,7 @@
v-if="item.iconType === 'wot'"
:title="item.text"
:icon="item.icon"
- >
+ />
+ />
@@ -34,35 +66,3 @@
-
-
diff --git a/src/layouts/tabbar.vue b/src/layouts/tabbar.vue
index 9ccc2a4..0c1bb1c 100644
--- a/src/layouts/tabbar.vue
+++ b/src/layouts/tabbar.vue
@@ -1,15 +1,6 @@
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
diff --git a/src/main.ts b/src/main.ts
index 74fb026..b86a5fd 100644
--- a/src/main.ts
+++ b/src/main.ts
@@ -1,11 +1,11 @@
-import '@/style/index.scss'
import { VueQueryPlugin } from '@tanstack/vue-query'
-import 'virtual:uno.css'
import { createSSRApp } from 'vue'
-
import App from './App.vue'
import { prototypeInterceptor, requestInterceptor, routeInterceptor } from './interceptors'
+
import store from './store'
+import '@/style/index.scss'
+import 'virtual:uno.css'
export function createApp() {
const app = createSSRApp(App)
diff --git a/src/manifest.json b/src/manifest.json
index 791ddeb..77be573 100644
--- a/src/manifest.json
+++ b/src/manifest.json
@@ -110,4 +110,4 @@
"base": "/"
}
}
-}
\ No newline at end of file
+}
diff --git a/src/pages-sub/demo/index.vue b/src/pages-sub/demo/index.vue
index d2033ad..bee8a77 100644
--- a/src/pages-sub/demo/index.vue
+++ b/src/pages-sub/demo/index.vue
@@ -7,17 +7,21 @@
}
-
-
- http://localhost:9000/#/pages-sub/demo/index
- 分包页面demo
-
-
-
+
+
+
+ http://localhost:9000/#/pages-sub/demo/index
+
+
+ 分包页面demo
+
+
+
+
diff --git a/src/pages.json b/src/pages.json
index 15c7ff1..9b32bb1 100644
--- a/src/pages.json
+++ b/src/pages.json
@@ -62,4 +62,4 @@
}
],
"subPackages": []
-}
\ No newline at end of file
+}
diff --git a/src/pages/about/about.vue b/src/pages/about/about.vue
index 5f11f82..71ca5fe 100644
--- a/src/pages/about/about.vue
+++ b/src/pages/about/about.vue
@@ -7,17 +7,6 @@
}
-
-
-
- 鸽友们好,我是
- 菲鸽
-
-
-
-
-
-
+
+
+
+ 鸽友们好,我是
+
+ 菲鸽
+
+
+
+
+
+
+
diff --git a/src/pages/index/index.vue b/src/pages/index/index.vue
index 968a26a..ec3bcbf 100644
--- a/src/pages/index/index.vue
+++ b/src/pages/index/index.vue
@@ -9,25 +9,6 @@
},
}
-
-
-
-
-
- unibest
- 最好用的 uniapp 开发模板
-
- {{ description }}
-
- 当前平台是:
- {{ PLATFORM.platform }}
-
-
- 模板分支是:
- base
-
-
-
+
+
+
+
+
+
+
+ unibest
+
+
+ 最好用的 uniapp 开发模板
+
+
+
+ {{ description }}
+
+
+ 当前平台是:
+
+ {{ PLATFORM.platform }}
+
+
+
+ 模板分支是:
+
+ base
+
+
+
+
diff --git a/src/service/index/foo.ts b/src/service/index/foo.ts
index 34d523e..88c1138 100644
--- a/src/service/index/foo.ts
+++ b/src/service/index/foo.ts
@@ -1,27 +1,28 @@
import { http } from '@/utils/http'
+
export interface IFooItem {
id: string
name: string
}
/** GET 请求 */
-export const getFooAPI = (name: string) => {
+export function getFooAPI(name: string) {
return http.get('/foo', { name })
}
/** GET 请求;支持 传递 header 的范例 */
-export const getFooAPI2 = (name: string) => {
+export function getFooAPI2(name: string) {
return http.get('/foo', { name }, { 'Content-Type-100': '100' })
}
/** POST 请求 */
-export const postFooAPI = (name: string) => {
+export function postFooAPI(name: string) {
return http.post('/foo', { name })
}
/** POST 请求;需要传递 query 参数的范例;微信小程序经常有同时需要query参数和body参数的场景 */
-export const postFooAPI2 = (name: string) => {
+export function postFooAPI2(name: string) {
return http.post('/foo', { name })
}
/** POST 请求;支持 传递 header 的范例 */
-export const postFooAPI3 = (name: string) => {
+export function postFooAPI3(name: string) {
return http.post('/foo', { name }, { name }, { 'Content-Type-100': '100' })
}
diff --git a/src/store/user.ts b/src/store/user.ts
index a6a1a84..522036f 100644
--- a/src/store/user.ts
+++ b/src/store/user.ts
@@ -1,14 +1,14 @@
-import {
- login as _login,
- getUserInfo as _getUserInfo,
- wxLogin as _wxLogin,
- logout as _logout,
- getWxCode,
-} from '@/api/login'
+import type { IUserInfoVo } from '@/api/login.typings'
import { defineStore } from 'pinia'
import { ref } from 'vue'
+import {
+ getUserInfo as _getUserInfo,
+ login as _login,
+ logout as _logout,
+ wxLogin as _wxLogin,
+ getWxCode,
+} from '@/api/login'
import { toast } from '@/utils/toast'
-import { IUserInfoVo } from '@/api/login.typings'
// 初始化状态
const userInfoState: IUserInfoVo = {
@@ -29,7 +29,8 @@ export const useUserStore = defineStore(
// 若头像为空 则使用默认头像
if (!val.avatar) {
val.avatar = userInfoState.avatar
- } else {
+ }
+ else {
val.avatar = 'https://oss.laf.run/ukw0y1-site/avatar.jpg?feige'
}
userInfo.value = val
diff --git a/src/typings.d.ts b/src/typings.d.ts
index 0ab0858..9ead3fb 100644
--- a/src/typings.d.ts
+++ b/src/typings.d.ts
@@ -1,14 +1,14 @@
// 全局要用的类型放到这里
declare global {
- type IResData = {
+ interface IResData {
code: number
msg: string
data: T
}
// uni.uploadFile文件上传参数
- type IUniUploadFileOptions = {
+ interface IUniUploadFileOptions {
file?: File
files?: UniApp.UploadFileOptionFiles[]
filePath?: string
@@ -16,7 +16,7 @@ declare global {
formData?: any
}
- type IUserInfo = {
+ interface IUserInfo {
nickname?: string
avatar?: string
/** 微信的 openid,非微信没有这个字段 */
diff --git a/src/typings.ts b/src/typings.ts
index cadb468..b48b630 100644
--- a/src/typings.ts
+++ b/src/typings.ts
@@ -6,7 +6,7 @@ export enum TestEnum {
}
// uni.uploadFile文件上传参数
-export type IUniUploadFileOptions = {
+export interface IUniUploadFileOptions {
file?: File
files?: UniApp.UploadFileOptionFiles[]
filePath?: string
diff --git a/src/utils/http.ts b/src/utils/http.ts
index f4ccd36..fb4d9bd 100644
--- a/src/utils/http.ts
+++ b/src/utils/http.ts
@@ -1,6 +1,6 @@
-import { CustomRequestOptions } from '@/interceptors/request'
+import type { CustomRequestOptions } from '@/interceptors/request'
-export const http = (options: CustomRequestOptions) => {
+export function http(options: CustomRequestOptions) {
// 1. 返回 Promise 对象
return new Promise>((resolve, reject) => {
uni.request({
@@ -15,18 +15,20 @@ export const http = (options: CustomRequestOptions) => {
if (res.statusCode >= 200 && res.statusCode < 300) {
// 2.1 提取核心数据 res.data
resolve(res.data as IResData)
- } else if (res.statusCode === 401) {
+ }
+ else if (res.statusCode === 401) {
// 401错误 -> 清理用户信息,跳转到登录页
// userStore.clearUserInfo()
// uni.navigateTo({ url: '/pages/login/login' })
reject(res)
- } else {
+ }
+ else {
// 其他错误 -> 根据后端错误信息轻提示
- !options.hideErrorToast &&
- uni.showToast({
- icon: 'none',
- title: (res.data as IResData).msg || '请求错误',
- })
+ !options.hideErrorToast
+ && uni.showToast({
+ icon: 'none',
+ title: (res.data as IResData).msg || '请求错误',
+ })
reject(res)
}
},
@@ -49,12 +51,7 @@ export const http = (options: CustomRequestOptions) => {
* @param header 请求头,默认为json格式
* @returns
*/
-export const httpGet = (
- url: string,
- query?: Record,
- header?: Record,
- options?: Partial,
-) => {
+export function httpGet(url: string, query?: Record, header?: Record, options?: Partial) {
return http({
url,
query,
@@ -72,13 +69,7 @@ export const httpGet = (
* @param header 请求头,默认为json格式
* @returns
*/
-export const httpPost = (
- url: string,
- data?: Record,
- query?: Record,
- header?: Record,
- options?: Partial,
-) => {
+export function httpPost(url: string, data?: Record, query?: Record, header?: Record, options?: Partial) {
return http({
url,
query,
@@ -91,13 +82,7 @@ export const httpPost = (
/**
* PUT 请求
*/
-export const httpPut = (
- url: string,
- data?: Record,
- query?: Record,
- header?: Record,
- options?: Partial,
-) => {
+export function httpPut(url: string, data?: Record, query?: Record, header?: Record, options?: Partial) {
return http({
url,
data,
@@ -111,12 +96,7 @@ export const httpPut = (
/**
* DELETE 请求(无请求体,仅 query)
*/
-export const httpDelete = (
- url: string,
- query?: Record,
- header?: Record,
- options?: Partial,
-) => {
+export function httpDelete(url: string, query?: Record, header?: Record, options?: Partial) {
return http({
url,
query,
diff --git a/src/utils/index.ts b/src/utils/index.ts
index 42a8016..e015753 100644
--- a/src/utils/index.ts
+++ b/src/utils/index.ts
@@ -1,7 +1,7 @@
import { pages, subPackages } from '@/pages.json'
import { isMpWeixin } from './platform'
-export const getLastPage = () => {
+export function getLastPage() {
// getCurrentPages() 至少有1个元素,所以不再额外判断
// const lastPage = getCurrentPages().at(-1)
// 上面那个在低版本安卓中打包会报错,所以改用下面这个【虽然我加了 src/interceptions/prototype.ts,但依然报错】
@@ -14,7 +14,7 @@ export const getLastPage = () => {
* path 如 '/pages/login/index'
* redirectPath 如 '/pages/demo/base/route-interceptor'
*/
-export const currRoute = () => {
+export function currRoute() {
const lastPage = getLastPage()
const currRoute = (lastPage as any).$page
// console.log('lastPage.$page:', currRoute)
@@ -29,7 +29,7 @@ export const currRoute = () => {
return getUrlObj(fullPath)
}
-const ensureDecodeURIComponent = (url: string) => {
+function ensureDecodeURIComponent(url: string) {
if (url.startsWith('%')) {
return ensureDecodeURIComponent(decodeURIComponent(url))
}
@@ -40,7 +40,7 @@ const ensureDecodeURIComponent = (url: string) => {
* 比如输入url: /pages/login/index?redirect=%2Fpages%2Fdemo%2Fbase%2Froute-interceptor
* 输出: {path: /pages/login/index, query: {redirect: /pages/demo/base/route-interceptor}}
*/
-export const getUrlObj = (url: string) => {
+export function getUrlObj(url: string) {
const [path, queryStr] = url.split('?')
// console.log(path, queryStr)
@@ -63,11 +63,11 @@ export const getUrlObj = (url: string) => {
* 这里设计得通用一点,可以传递 key 作为判断依据,默认是 needLogin, 与 route-block 配对使用
* 如果没有传 key,则表示所有的 pages,如果传递了 key, 则表示通过 key 过滤
*/
-export const getAllPages = (key = 'needLogin') => {
+export function getAllPages(key = 'needLogin') {
// 这里处理主包
const mainPages = pages
- .filter((page) => !key || page[key])
- .map((page) => ({
+ .filter(page => !key || page[key])
+ .map(page => ({
...page,
path: `/${page.path}`,
}))
@@ -79,7 +79,7 @@ export const getAllPages = (key = 'needLogin') => {
const { root } = subPageObj
subPageObj.pages
- .filter((page) => !key || page[key])
+ .filter(page => !key || page[key])
.forEach((page: { path: string } & Record) => {
subPages.push({
...page,
@@ -96,18 +96,18 @@ export const getAllPages = (key = 'needLogin') => {
* 得到所有的需要登录的 pages,包括主包和分包的
* 只得到 path 数组
*/
-export const getNeedLoginPages = (): string[] => getAllPages('needLogin').map((page) => page.path)
+export const getNeedLoginPages = (): string[] => getAllPages('needLogin').map(page => page.path)
/**
* 得到所有的需要登录的 pages,包括主包和分包的
* 只得到 path 数组
*/
-export const needLoginPages: string[] = getAllPages('needLogin').map((page) => page.path)
+export const needLoginPages: string[] = getAllPages('needLogin').map(page => page.path)
/**
* 根据微信小程序当前环境,判断应该获取的 baseUrl
*/
-export const getEnvBaseUrl = () => {
+export function getEnvBaseUrl() {
// 请求基准地址
let baseUrl = import.meta.env.VITE_SERVER_BASEURL
@@ -136,7 +136,7 @@ export const getEnvBaseUrl = () => {
/**
* 根据微信小程序当前环境,判断应该获取的 UPLOAD_BASEURL
*/
-export const getEnvBaseUploadUrl = () => {
+export function getEnvBaseUploadUrl() {
// 请求基准地址
let baseUploadUrl = import.meta.env.VITE_UPLOAD_BASEURL
diff --git a/src/utils/request.ts b/src/utils/request.ts
index 79f05ab..9879f25 100644
--- a/src/utils/request.ts
+++ b/src/utils/request.ts
@@ -1,11 +1,11 @@
-import { CustomRequestOptions } from '@/interceptors/request'
+import type { CustomRequestOptions } from '@/interceptors/request'
/**
* 请求方法: 主要是对 uni.request 的封装,去适配 openapi-ts-request 的 request 方法
* @param options 请求参数
* @returns 返回 Promise 对象
*/
-const http = (options: CustomRequestOptions) => {
+function http(options: CustomRequestOptions) {
// 1. 返回 Promise 对象
return new Promise((resolve, reject) => {
uni.request({
@@ -20,18 +20,20 @@ const http = (options: CustomRequestOptions) => {
if (res.statusCode >= 200 && res.statusCode < 300) {
// 2.1 提取核心数据 res.data
resolve(res.data as T)
- } else if (res.statusCode === 401) {
+ }
+ else if (res.statusCode === 401) {
// 401错误 -> 清理用户信息,跳转到登录页
// userStore.clearUserInfo()
// uni.navigateTo({ url: '/pages/login/login' })
reject(res)
- } else {
+ }
+ else {
// 其他错误 -> 根据后端错误信息轻提示
- !options.hideErrorToast &&
- uni.showToast({
- icon: 'none',
- title: (res.data as T & { msg?: string })?.msg || '请求错误',
- })
+ !options.hideErrorToast
+ && uni.showToast({
+ icon: 'none',
+ title: (res.data as T & { msg?: string })?.msg || '请求错误',
+ })
reject(res)
}
},
diff --git a/src/utils/toast.ts b/src/utils/toast.ts
index 30f6522..e524b00 100644
--- a/src/utils/toast.ts
+++ b/src/utils/toast.ts
@@ -21,8 +21,8 @@ export function showToast(options: ToastOptions | string) {
position: 'middle',
message: '',
}
- const mergedOptions =
- typeof options === 'string'
+ const mergedOptions
+ = typeof options === 'string'
? { ...defaultOptions, message: options }
: { ...defaultOptions, ...options }
// 映射position到uniapp支持的格式
diff --git a/src/utils/uploadFile.ts b/src/utils/uploadFile.ts
index 6c7f0a1..416d39c 100644
--- a/src/utils/uploadFile.ts
+++ b/src/utils/uploadFile.ts
@@ -21,7 +21,7 @@ import { toast } from './toast'
*/
export const uploadFileUrl = {
/** 用户头像上传地址 */
- USER_AVATAR: import.meta.env.VITE_SERVER_BASEURL + '/user/avatar',
+ USER_AVATAR: `${import.meta.env.VITE_SERVER_BASEURL}/user/avatar`,
}
/**
@@ -31,12 +31,7 @@ export const uploadFileUrl = {
* @param formData 额外表单数据
* @param options 上传选项
*/
-export const useFileUpload = (
- url: string,
- filePath: string,
- formData: Record = {},
- options: Omit = {},
-) => {
+export function useFileUpload(url: string, filePath: string, formData: Record = {}, options: Omit = {}) {
return useUpload(
url,
formData,
@@ -76,13 +71,9 @@ export interface UploadOptions {
* @param options 上传选项
* @returns 上传状态和控制对象
*/
-export const useUpload = (
- url: string,
- formData: Record = {},
- options: UploadOptions = {},
+export function useUpload(url: string, formData: Record = {}, options: UploadOptions = {},
/** 直接传入文件路径,跳过选择器 */
- directFilePath?: string,
-) => {
+ directFilePath?: string) {
/** 上传中状态 */
const loading = ref(false)
/** 上传错误状态 */
@@ -161,7 +152,8 @@ export const useUpload = (
success: (res) => {
const file = res.tempFiles[0]
// 检查文件大小是否符合限制
- if (!checkFileSize(file.size)) return
+ if (!checkFileSize(file.size))
+ return
// 开始上传
loading.value = true
@@ -295,7 +287,8 @@ function uploadFile({
// 上传成功
data.value = _data as T
onSuccess?.(_data)
- } catch (err) {
+ }
+ catch (err) {
// 响应解析错误
console.error('解析上传响应失败:', err)
error.value = true
@@ -320,7 +313,8 @@ function uploadFile({
progress.value = res.progress
onProgress?.(res.progress)
})
- } catch (err) {
+ }
+ catch (err) {
// 创建上传任务失败
console.error('创建上传任务失败:', err)
error.value = true
diff --git a/tsconfig.json b/tsconfig.json
index d096903..7d03c63 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -1,21 +1,15 @@
{
"compilerOptions": {
"composite": true,
- "skipLibCheck": true,
+ "lib": ["esnext", "dom"],
+ "baseUrl": ".",
"module": "ESNext",
"moduleResolution": "Node",
- "resolveJsonModule": true,
- "noImplicitThis": true,
- "allowSyntheticDefaultImports": true,
- "allowJs": true,
- "sourceMap": true,
- "baseUrl": ".",
"paths": {
"@/*": ["./src/*"],
"@img/*": ["./src/static/*"]
},
- "outDir": "dist",
- "lib": ["esnext", "dom"],
+ "resolveJsonModule": true,
"types": [
"@dcloudio/types",
"@uni-helper/uni-types",
@@ -23,12 +17,17 @@
"wot-design-uni/global.d.ts",
"z-paging/types",
"./src/typings.d.ts"
- ]
+ ],
+ "allowJs": true,
+ "noImplicitThis": true,
+ "sourceMap": true,
+ "skipLibCheck": true,
+ "allowSyntheticDefaultImports": true,
+ "outDir": "dist"
},
"vueCompilerOptions": {
"plugins": ["@uni-helper/uni-types/volar-plugin"]
},
- "exclude": ["node_modules"],
"include": [
"src/**/*.ts",
"src/**/*.js",
@@ -37,5 +36,6 @@
"src/**/*.jsx",
"src/**/*.vue",
"src/**/*.json"
- ]
+ ],
+ "exclude": ["node_modules"]
}
diff --git a/uno.config.ts b/uno.config.ts
index c7b15b5..2ddbd83 100644
--- a/uno.config.ts
+++ b/uno.config.ts
@@ -2,8 +2,8 @@
import { presetUni } from '@uni-helper/unocss-preset-uni'
import {
defineConfig,
- presetIcons,
presetAttributify,
+ presetIcons,
transformerDirectives,
transformerVariantGroup,
} from 'unocss'
@@ -20,7 +20,7 @@ export default defineConfig({
scale: 1.2,
warn: true,
extraProperties: {
- display: 'inline-block',
+ 'display': 'inline-block',
'vertical-align': 'middle',
},
}),
diff --git a/vite-plugins/copyNativeRes.ts b/vite-plugins/copyNativeRes.ts
index f92aebc..69f32c4 100644
--- a/vite-plugins/copyNativeRes.ts
+++ b/vite-plugins/copyNativeRes.ts
@@ -1,5 +1,5 @@
+import path from 'node:path'
import fs from 'fs-extra'
-import path from 'path'
export function copyNativeRes() {
const waitPath = path.resolve(__dirname, '../src/nativeResources')
@@ -31,7 +31,8 @@ export function copyNativeRes() {
console.log(
`[copyNativeRes] 成功将 nativeResources 目录中的资源移动到构建目录:${buildPath}`,
)
- } catch (error) {
+ }
+ catch (error) {
console.error(`[copyNativeRes] 复制资源失败:`, error)
}
},
diff --git a/vite-plugins/updatePackageJson.ts b/vite-plugins/updatePackageJson.ts
index 0d2282f..0915b50 100644
--- a/vite-plugins/updatePackageJson.ts
+++ b/vite-plugins/updatePackageJson.ts
@@ -1,14 +1,15 @@
// src/plugins/updatePackageJson.ts
-import { Plugin } from 'vite'
-import fs from 'fs/promises'
-import path from 'path'
+import type { Plugin } from 'vite'
+import fs from 'node:fs/promises'
+import path from 'node:path'
-const updatePackageJson = (): Plugin => {
+function updatePackageJson(): Plugin {
return {
name: 'update-package-json',
async buildStart() {
// 只在生产环境构建时执行
- if (process.env.NODE_ENV !== 'production') return
+ if (process.env.NODE_ENV !== 'production')
+ return
const packageJsonPath = path.resolve(process.cwd(), 'package.json')
@@ -21,10 +22,11 @@ const updatePackageJson = (): Plugin => {
packageJson['update-time'] = new Date().toISOString().split('T')[0] // YYYY-MM-DD
// 写回文件(保持 2 空格缩进)
- await fs.writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2) + '\n', 'utf-8')
+ await fs.writeFile(packageJsonPath, `${JSON.stringify(packageJson, null, 2)}\n`, 'utf-8')
console.log(`[update-package-json] 更新时间戳: ${packageJson['update-time']}`)
- } catch (error) {
+ }
+ catch (error) {
console.error('[update-package-json] 插件执行失败:', error)
}
},
diff --git a/vite.config.ts b/vite.config.ts
index 3efc208..f48749e 100644
--- a/vite.config.ts
+++ b/vite.config.ts
@@ -1,27 +1,26 @@
-import Uni from '@dcloudio/vite-plugin-uni'
-import dayjs from 'dayjs'
import path from 'node:path'
-import { defineConfig, loadEnv } from 'vite'
-// @see https://uni-helper.js.org/vite-plugin-uni-pages
-import UniPages from '@uni-helper/vite-plugin-uni-pages'
+import Uni from '@dcloudio/vite-plugin-uni'
+import Components from '@uni-helper/vite-plugin-uni-components'
// @see https://uni-helper.js.org/vite-plugin-uni-layouts
import UniLayouts from '@uni-helper/vite-plugin-uni-layouts'
+// @see https://github.com/uni-helper/vite-plugin-uni-manifest
+import UniManifest from '@uni-helper/vite-plugin-uni-manifest'
+// @see https://uni-helper.js.org/vite-plugin-uni-pages
+import UniPages from '@uni-helper/vite-plugin-uni-pages'
// @see https://github.com/uni-helper/vite-plugin-uni-platform
// 需要与 @uni-helper/vite-plugin-uni-pages 插件一起使用
import UniPlatform from '@uni-helper/vite-plugin-uni-platform'
-// @see https://github.com/uni-helper/vite-plugin-uni-manifest
-import UniManifest from '@uni-helper/vite-plugin-uni-manifest'
/**
* 分包优化、模块异步跨包调用、组件异步跨包引用
* @see https://github.com/uni-ku/bundle-optimizer
*/
import Optimization from '@uni-ku/bundle-optimizer'
+import dayjs from 'dayjs'
import { visualizer } from 'rollup-plugin-visualizer'
import AutoImport from 'unplugin-auto-import/vite'
+import { defineConfig, loadEnv } from 'vite'
import ViteRestart from 'vite-plugin-restart'
-import { copyNativeRes } from './vite-plugins/copyNativeRes'
import updatePackageJson from './vite-plugins/updatePackageJson'
-import Components from '@uni-helper/vite-plugin-uni-components'
// https://vitejs.dev/config/
export default async ({ command, mode }) => {
@@ -75,7 +74,7 @@ export default async ({ command, mode }) => {
// 自定义插件禁用 vite:vue 插件的 devToolsEnabled,强制编译 vue 模板时 inline 为 true
name: 'fix-vite-plugin-vue',
configResolved(config) {
- const plugin = config.plugins.find((p) => p.name === 'vite:vue')
+ const plugin = config.plugins.find(p => p.name === 'vite:vue')
if (plugin && plugin.api && plugin.api.options) {
plugin.api.options.devToolsEnabled = false
}
@@ -91,7 +90,7 @@ export default async ({ command, mode }) => {
// Optimization 插件需要 page.json 文件,故应在 UniPages 插件之后执行
Optimization({
enable: {
- optimization: true,
+ 'optimization': true,
'async-import': true,
'async-component': true,
},
@@ -113,14 +112,14 @@ export default async ({ command, mode }) => {
},
},
// 打包分析插件,h5 + 生产环境才弹出
- UNI_PLATFORM === 'h5' &&
- mode === 'production' &&
- visualizer({
- filename: './node_modules/.cache/visualizer/stats.html',
- open: true,
- gzipSize: true,
- brotliSize: true,
- }),
+ UNI_PLATFORM === 'h5'
+ && mode === 'production'
+ && visualizer({
+ filename: './node_modules/.cache/visualizer/stats.html',
+ open: true,
+ gzipSize: true,
+ brotliSize: true,
+ }),
// 只有在 app 平台时才启用 copyNativeRes 插件
// UNI_PLATFORM === 'app' && copyNativeRes(),
Components({
@@ -163,7 +162,7 @@ export default async ({ command, mode }) => {
[VITE_APP_PROXY_PREFIX]: {
target: VITE_SERVER_BASEURL,
changeOrigin: true,
- rewrite: (path) => path.replace(new RegExp(`^${VITE_APP_PROXY_PREFIX}`), ''),
+ rewrite: path => path.replace(new RegExp(`^${VITE_APP_PROXY_PREFIX}`), ''),
},
}
: undefined,