diff --git a/.eslintignore b/.eslintignore
index 07d8227..98768fc 100644
--- a/.eslintignore
+++ b/.eslintignore
@@ -1,21 +1,20 @@
-# eslint 忽略检查 (根据项目需要自行添加)
-node_modules
-dist
-.idea
-.vscode
-.hbuilderx
-src/manifest.json
-src/pages.json
-src/tmui/
-*.sh
-node_modules
-*.md
-*.woff
-*.ttf
-*.yaml
-dist
+# 忽略目录
+/dist
+/build
+/tests
+/node_modules
/public
-/docs
-.husky
-.local
-/bin
\ No newline at end of file
+/src/public
+/src/static
+/src/manifest.json
+/vite.config.ts
+/unocss.config.js
+
+# node 覆盖率文件
+coverage/
+
+# 忽略文件
+**/*-min.js
+**/*.min.js
+**/*-min.css
+**/*.min.css
\ No newline at end of file
diff --git a/.eslintrc.js b/.eslintrc.js
index 26e930a..a91d224 100644
--- a/.eslintrc.js
+++ b/.eslintrc.js
@@ -1,97 +1,102 @@
+// 参考:https://eslint.bootcss.com/docs/rules/
+// 参考:https://blog.csdn.net/x550392236/article/details/89497202
+// 参考:https://blog.csdn.net/brokenkay/article/details/111106266
+
module.exports = {
- env: {
- browser: true,
- es2021: true,
- },
- parser: 'vue-eslint-parser',
- extends: [
- 'plugin:@typescript-eslint/recommended',
- 'plugin:vue/vue3-essential',
- 'prettier',
- ],
- parserOptions: {
- ecmaVersion: 'latest',
- parser: '@typescript-eslint/parser',
- sourceType: 'module',
- },
- settings: {
- 'import/resolver': {
- alias: {
- map: [['@', './src']],
- extensions: ['.ts', '.js', '.jsx', '.json'],
- },
+ root: true,
+ env: {
+ node: true, //允许运行在node环境下
+ browser: true, //允许运行在浏览器环境下
+ es2021: true, //允许运行es2021环境下语法
+ },
+ parser: 'vue-eslint-parser',
+ parserOptions: {
+ ecmaVersion: 'latest',
+ sourceType: 'module',
+ parser: '@typescript-eslint/parser',
+ },
+ extends: ['plugin:vue/vue3-essential', 'eslint:recommended', 'plugin:@typescript-eslint/recommended', 'prettier'],
+ plugins: ['vue', '@typescript-eslint', 'prettier'],
+ settings: {
+ 'import/resolver': {
+ alias: {
+ map: [['@', './src']],
+ extensions: ['.ts', '.js', '.jsx', '.json'],
+ },
+ },
+ },
+ globals: {
+ //可以定义全局中的变量的权限(只读,可读可写)
+ defineProps: 'readonly',
+ defineEmits: 'readonly',
+ defineExpose: 'readonly',
+ withDefaults: 'readonly',
+ uni: 'readonly',
+ },
+ rules: {
+ 'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
+ 'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
+ 'no-var': 'error', //要求使用 let 或 const 而不是 var
+ 'prettier/prettier': 'error',
+ 'vue/no-multiple-template-root': 'off',
+ 'no-mutating-props': 'off',
+ 'vue/no-v-html': 'off',
+ camelcase: 'error', // 双峰驼命名格式
+ // indent: ['error', 4], //代码缩进4个空格 (switch时与prettier发生冲突)
+ eqeqeq: ['error', 'always', { null: 'ignore' }], //比较时强制使用 === 或者 !==,但对null作比较时可以不用全等
+ quotes: [
+ 'error',
+ 'single',
+ {
+ avoidEscape: true,
+ allowTemplateLiterals: true,
+ },
+ ], // @fixable 必须使用单引号,禁止使用双引号
+ // 结尾必须有分号;
+ semi: [
+ 'error',
+ 'always',
+ {
+ omitLastInOneLineBlock: true,
+ },
+ ], // 结尾必须有分号;
+ 'vue/script-setup-uses-vars': 'error',
+ '@typescript-eslint/ban-ts-ignore': 'off',
+ '@typescript-eslint/explicit-function-return-type': 'off',
+ '@typescript-eslint/no-explicit-any': 'off',
+ '@typescript-eslint/no-var-requires': 'off',
+ '@typescript-eslint/no-empty-function': 'off',
+ 'vue/custom-event-name-casing': 'off',
+ 'no-use-before-define': 'off',
+ '@typescript-eslint/no-use-before-define': 'off',
+ '@typescript-eslint/ban-ts-comment': 'off',
+ '@typescript-eslint/ban-types': 'off',
+ '@typescript-eslint/no-non-null-assertion': 'off',
+ '@typescript-eslint/explicit-module-boundary-types': 'off',
+ '@typescript-eslint/no-unused-vars': [
+ 'warn',
+ {
+ argsIgnorePattern: '^_',
+ varsIgnorePattern: '^_',
+ },
+ ],
+ 'no-unused-vars': [
+ 'warn',
+ {
+ argsIgnorePattern: '^_',
+ varsIgnorePattern: '^_',
+ },
+ ],
+ 'space-before-function-paren': 'off',
+ 'vue/attributes-order': 'off',
+ 'vue/v-on-event-hyphenation': 'off',
+ 'vue/multi-word-component-names': 'off',
+ 'vue/one-component-per-file': 'off',
+ 'vue/html-closing-bracket-newline': 'off',
+ 'vue/max-attributes-per-line': 'off',
+ 'vue/multiline-html-element-content-newline': 'off',
+ 'vue/singleline-html-element-content-newline': 'off',
+ 'vue/attribute-hyphenation': 'off',
+ 'vue/require-default-prop': 'off',
},
- },
- plugins: ['vue', '@typescript-eslint', 'prettier'],
- rules: {
- 'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
- 'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
- 'no-var': 'error',
- 'prettier/prettier': 'error',
- 'vue/no-multiple-template-root': 'off',
- 'no-mutating-props': 'off',
- 'vue/no-v-html': 'off',
- // @fixable 必须使用单引号,禁止使用双引号
- quotes: [
- 'error',
- 'single',
- {
- avoidEscape: true,
- allowTemplateLiterals: true,
- },
- ],
- // 结尾必须有分号;
- semi: [
- 'error',
- 'always',
- {
- omitLastInOneLineBlock: true,
- },
- ],
- 'vue/script-setup-uses-vars': 'error',
- '@typescript-eslint/ban-ts-ignore': 'off',
- '@typescript-eslint/explicit-function-return-type': 'off',
- '@typescript-eslint/no-explicit-any': 'off',
- '@typescript-eslint/no-var-requires': 'off',
- '@typescript-eslint/no-empty-function': 'off',
- 'vue/custom-event-name-casing': 'off',
- 'no-use-before-define': 'off',
- '@typescript-eslint/no-use-before-define': 'off',
- '@typescript-eslint/ban-ts-comment': 'off',
- '@typescript-eslint/ban-types': 'off',
- '@typescript-eslint/no-non-null-assertion': 'off',
- '@typescript-eslint/explicit-module-boundary-types': 'off',
- '@typescript-eslint/no-unused-vars': [
- 'warn',
- {
- argsIgnorePattern: '^_',
- varsIgnorePattern: '^_',
- },
- ],
- 'no-unused-vars': [
- 'warn',
- {
- argsIgnorePattern: '^_',
- varsIgnorePattern: '^_',
- },
- ],
- 'space-before-function-paren': 'off',
- 'vue/attributes-order': 'off',
- 'vue/v-on-event-hyphenation': 'off',
- 'vue/multi-word-component-names': 'off',
- 'vue/one-component-per-file': 'off',
- 'vue/html-closing-bracket-newline': 'off',
- 'vue/max-attributes-per-line': 'off',
- 'vue/multiline-html-element-content-newline': 'off',
- 'vue/singleline-html-element-content-newline': 'off',
- 'vue/attribute-hyphenation': 'off',
- 'vue/require-default-prop': 'off',
- },
- globals: {
- defineProps: 'readonly',
- defineEmits: 'readonly',
- defineExpose: 'readonly',
- withDefaults: 'readonly',
- uni: 'readonly',
- },
};
diff --git a/.gitignore b/.gitignore
index 2f46287..6347ba2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,11 +1,34 @@
-node_modules
-dist
-.eslintcache
-.pnpm-lock.yaml
-*.local
+# 日志
+logs
+*.log
+npm-debug.log*
+yarn-debug.log*
+yarn-error.log*
+pnpm-debug.log*
+lerna-debug.log*
+node_modules
+.DS_Store
+dist
+dist-ssr
+coverage
+*.local
+.eslintcache
+
+/cypress/videos/
+/cypress/screenshots/
# 编辑器目录和文件
+.vscode/*
+.hbuilderx/*
+!.vscode/extensions.json
+!.vscode/settings.json
.idea
+*.suo
+*.ntvs*
+*.njsproj
+*.sln
+*.sw?
+.eslintcache
.hbuilderx
pnpm-lock.yaml
\ No newline at end of file
diff --git a/.prettierignore b/.prettierignore
index 364db71..a11f08e 100644
--- a/.prettierignore
+++ b/.prettierignore
@@ -1,20 +1,18 @@
-# 忽略格式化文件 (根据项目需要自行添加)
-node_modules
-dist
-.idea
-.vscode
-.hbuilderx
-src/manifest.json
-src/pages.json
-*.sh
-node_modules
-*.md
-*.woff
-*.ttf
-*.yaml
-dist
+# 忽略目录
+/dist
+/build
+/tests
+/node_modules
/public
-/docs
-.husky
-.local
-/bin
\ No newline at end of file
+/src/public
+/src/static
+/src/manifest.json
+
+# node 覆盖率文件
+coverage/
+
+# 忽略文件
+**/*-min.js
+**/*.min.js
+**/*-min.css
+**/*.min.css
\ No newline at end of file
diff --git a/.prettierrc.js b/.prettierrc.js
index 5521157..e5c5a7d 100644
--- a/.prettierrc.js
+++ b/.prettierrc.js
@@ -1,40 +1,37 @@
module.exports = {
- // 一行最多 160 字符
- printWidth: 160,
- // 不使用缩进符,而使用空格
- useTabs: true,
- // 使用 2 个空格缩进
- tabWidth: 4,
- tabSize: 4,
- // 行尾需要有分号
- semi: true,
- // 使用单引号
- singleQuote: true,
- // 对象的 key 仅在必要时用引号 (可选值as-needed|consistent|preserve)
- quoteProps: 'as-needed',
- // jsx 不使用单引号,而使用双引号
- jsxSingleQuote: false,
- // 末尾不需要逗号 'es5' (可选值none|es5|all,默认none)
- trailingComma: 'es5',
- // 大括号内的首尾需要空格
- bracketSpacing: true,
- // jsx 标签的反尖括号需要换行
- jsxBracketSameLine: false,
- // 箭头函数,只有一个参数的时候,也需要括号
- arrowParens: 'always',
- // 每个文件格式化的范围是文件的全部内容
- rangeStart: 0,
- rangeEnd: Infinity,
- // 不需要写文件开头的 @prettier
- requirePragma: false,
- // 不需要自动在文件开头插入 @prettier
- insertPragma: false,
- // 使用默认的折行标准 (可选值always|never|preserve)
- proseWrap: 'preserve',
- // 根据显示样式决定 html 要不要折行 (可选值css|strict|ignore)
- htmlWhitespaceSensitivity: 'css',
- // vue脚本文件和样式的缩进
- vueIndentScriptAndStyle: false,
- // 换行符使用 lf 结尾是 (可选值auto|lf|crlf|cr)
- endOfLine: 'lf',
+ // .pellerrc 的架构 官网参考:https://prettier.io/docs/en/options.html#tab-width
+ $schema: 'https://json.schemastore.org/prettierrc',
+ // 一行最多 120 字符
+ printWidth: 160,
+ // 使用 4 个空格缩进
+ tabWidth: 4,
+ // 不使用 tab 缩进,而使用空格
+ useTabs: false,
+ // 行尾需要有分号
+ semi: true,
+ // 使用单引号代替双引号
+ singleQuote: true,
+ // 对象的 key 仅在必要时用引号
+ quoteProps: 'as-needed',
+ // jsx 不使用单引号,而使用双引号
+ jsxSingleQuote: false,
+ // 末尾使用逗号
+ trailingComma: 'all',
+ // 大括号内的首尾需要空格 { foo: bar }
+ bracketSpacing: true,
+ // 箭头函数,只有一个参数的时候,也需要括号
+ arrowParens: 'always',
+ // 每个文件格式化的范围是文件的全部内容
+ rangeStart: 0,
+ rangeEnd: Infinity,
+ // 不需要写文件开头的 @prettier
+ requirePragma: false,
+ // 不需要自动在文件开头插入 @prettier
+ insertPragma: false,
+ // 使用默认的折行标准
+ proseWrap: 'preserve',
+ // 根据显示样式决定 html 要不要折行
+ htmlWhitespaceSensitivity: 'css',
+ // 换行符使用 lf
+ endOfLine: 'lf',
};
diff --git a/.vscode/extensions.json b/.vscode/extensions.json
index 696747b..8cff2f2 100644
--- a/.vscode/extensions.json
+++ b/.vscode/extensions.json
@@ -1,10 +1,10 @@
{
"recommendations": [
- "CodeInChinese.EnglishChineseDictionary", // 翻译(英汉词典)
- "kisstkondoros.vscode-gutter-preview", // Image 预览
- "ritwickdey.LiveServer", // 为静态和动态页面启动具有实时重载功能的本地开发服务器
- "antfu.unocss", // UnoCSS 原子化css
- "esbenp.prettier-vscode", // 格式化
+ "Vue.volar", // Vue语言支持扩展
+ "Vue.vscode-typescript-vue-plugin", // 一个TS服务器插件,使TS服务器知道*.vue文件。
+ "esbenp.prettier-vscode", // 代码格式化
+ "dbaeumer.vscode-eslint", //代码质量检查
+ "antfu.unocss", // UnoCSS 原子化css
+ "mrmlnc.vscode-autoprefixer" //将less/scss/css文件自动添加浏览器兼容前缀
]
- }
-
\ No newline at end of file
+}
diff --git a/.vscode/settings.json b/.vscode/settings.json
index f1715a1..8ea3fa5 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -3,11 +3,12 @@
"editor.defaultFormatter": "esbenp.prettier-vscode", // 定义一个默认格式化程序, 该格式化程序优先于所有其他格式化程序设置。必须是提供格式化程序的扩展的标识符。
"editor.formatOnSave": true, //在保存时格式化文件。格式化程序必须可用,延迟后文件不能保存,并且编辑器不能关闭。
- "editor.detectIndentation": false, // 控制在基于文件内容打开文件时是否自动检测 #editor.tabSize# 和 #editor.insertSpaces#。
- "editor.tabSize": 4,
+ "editor.detectIndentation": false, // 控制在基于文件内容打开文件时是否自动检测 #editor.tabSize# 和 #editor.insertSpaces#。
+ "editor.tabSize": 4, // 一个制表符等于的空格数。当 #editor.detectIndentation# 打开时,将根据文件内容替代此设置。
"editor.codeActionsOnSave": {
- "source.fixAll": true, // 控制是否应在文件保存时运行自动修复操作。
- "source.fixAll.eslint": true,
- "source.fixAll.stylelint": true
+ "source.fixAll": true, // 控制是否应在文件保存时运行自动修复操作。
+ "source.fixAll.eslint": true,
+ "source.fixAll.stylelint": true
}, // 要在保存时运行的代码操作种类。
-}
\ No newline at end of file
+ "files.eol": "\n" //行尾字符与.prettierrc.cjs配置一致
+}
diff --git a/README.md b/README.md
index adcf580..abc229d 100644
--- a/README.md
+++ b/README.md
@@ -11,28 +11,28 @@
## 简介
-- **uni-app Vue3 Vite4 pinia2 TypeScript 基础框架**
-- cli创建的Vue3/Vite项目 与 使用HBuilderX导入插件 的包有差异,请直接访问 [开源地址](https://gitee.com/h_mo/uniapp-vue3-vite-ts-template)
-- 访问[uniapp插件](https://ext.dcloud.net.cn/plugin?id=8559)
-
+- **uni-app Vue3 Vite4 pinia2 TypeScript 基础框架**
+- cli 创建的 Vue3/Vite 项目 与 使用 HBuilderX 导入插件 的包有差异,请直接访问 [开源地址](https://gitee.com/h_mo/uniapp-vue3-vite-ts-template)
+- 访问[uniapp 插件](https://ext.dcloud.net.cn/plugin?id=8559)
### 说明
-- 框架完全基于Vue3 SFC `
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/package.json b/package.json
index 27da273..0693a5a 100644
--- a/package.json
+++ b/package.json
@@ -1,105 +1,103 @@
{
- "name": "uniapp_vue3_vite_ts",
- "version": "1.1.2",
- "scripts": {
- "dev:app": "uni -p app",
- "dev:custom": "uni -p",
- "dev:h5": "uni",
- "dev:h5:ssr": "uni --ssr",
- "dev:mp-alipay": "uni -p mp-alipay",
- "dev:mp-baidu": "uni -p mp-baidu",
- "dev:mp-kuaishou": "uni -p mp-kuaishou",
- "dev:mp-lark": "uni -p mp-lark",
- "dev:mp-qq": "uni -p mp-qq",
- "dev:mp-toutiao": "uni -p mp-toutiao",
- "dev:mp-weixin": "uni -p mp-weixin",
- "dev:quickapp-webview": "uni -p quickapp-webview",
- "dev:quickapp-webview-huawei": "uni -p quickapp-webview-huawei",
- "dev:quickapp-webview-union": "uni -p quickapp-webview-union",
- "build:app": "uni build -p app",
- "build:custom": "uni build -p",
- "build:h5": "uni build --minify",
- "build:h5:ssr": "uni build --ssr",
- "build:mp-alipay": "uni build -p mp-alipay",
- "build:mp-baidu": "uni build -p mp-baidu",
- "build:mp-kuaishou": "uni build -p mp-kuaishou",
- "build:mp-lark": "uni build -p mp-lark",
- "build:mp-qq": "uni build -p mp-qq",
- "build:mp-toutiao": "uni build -p mp-toutiao",
- "build:mp-weixin": "uni build -p mp-weixin --minify",
- "build:quickapp-webview": "uni build -p quickapp-webview",
- "build:quickapp-webview-huawei": "uni build -p quickapp-webview-huawei",
- "build:quickapp-webview-union": "uni build -p quickapp-webview-union",
- "lint": "eslint --cache --max-warnings 0 \"src/**/*.{vue,ts}\" --fix",
- "prettier": "prettier --write \"src/**/*.{js,ts,json,css,scss,vue}\"",
- "prepare": "husky install"
- },
- "dependencies": {
- "@dcloudio/uni-app": "3.0.0-alpha-3070620230227001",
- "@dcloudio/uni-app-plus": "3.0.0-alpha-3070620230227001",
- "@dcloudio/uni-components": "3.0.0-alpha-3070620230227001",
- "@dcloudio/uni-h5": "3.0.0-alpha-3070620230227001",
- "@dcloudio/uni-i18n": "3.0.0-alpha-3061620230106001",
- "@dcloudio/uni-mp-alipay": "3.0.0-alpha-3070620230227001",
- "@dcloudio/uni-mp-baidu": "3.0.0-alpha-3070620230227001",
- "@dcloudio/uni-mp-kuaishou": "3.0.0-alpha-3070620230227001",
- "@dcloudio/uni-mp-lark": "3.0.0-alpha-3070620230227001",
- "@dcloudio/uni-mp-qq": "3.0.0-alpha-3070620230227001",
- "@dcloudio/uni-mp-toutiao": "3.0.0-alpha-3070620230227001",
- "@dcloudio/uni-mp-weixin": "3.0.0-alpha-3070620230227001",
- "@dcloudio/uni-quickapp-webview": "3.0.0-alpha-3070620230227001",
- "@fortawesome/fontawesome-free": "^6.3.0",
- "@iconify/iconify": "^3.1.0",
- "crypto-js": "^4.1.1",
- "echarts": "^5.4.1",
- "lodash-es": "^4.17.21",
- "luch-request": "^3.0.8",
- "pinia": "^2.0.33",
- "qs": "^6.11.1",
- "vue": "^3.2.47",
- "vue-i18n": "^9.2.2"
- },
- "devDependencies": {
- "@dcloudio/types": "^3.2.11",
- "@dcloudio/uni-automator": "3.0.0-alpha-3070620230227001",
- "@dcloudio/uni-cli-shared": "3.0.0-alpha-3070620230227001",
- "@dcloudio/uni-stacktracey": "3.0.0-alpha-3070620230227001",
- "@dcloudio/vite-plugin-uni": "3.0.0-alpha-3070620230227001",
- "@iconify/json": "^2.2.31",
- "@types/crypto-js": "^4.1.1",
- "@types/lodash-es": "^4.17.6",
- "@types/node": "^17.0.45",
- "@types/qs": "^6.9.7",
- "@typescript-eslint/eslint-plugin": "^5.54.1",
- "@typescript-eslint/parser": "^5.54.1",
- "@unocss/preset-icons": "^0.46.5",
- "autoprefixer": "^10.4.13",
- "eslint": "^8.35.0",
- "eslint-config-prettier": "^8.7.0",
- "eslint-plugin-prettier": "^4.2.1",
- "eslint-plugin-vue": "^9.9.0",
- "husky": "^8.0.3",
- "lint-staged": "^13.1.2",
- "mrm": "^4.1.13",
- "postcss": "^8.4.21",
- "prettier": "^2.8.4",
- "sass": "^1.58.3",
- "typescript": "^4.9.5",
- "unocss": "^0.46.5",
- "unocss-preset-weapp": "^0.2.5",
- "unplugin-vue-components": "^0.22.12",
- "vite": "^4.1.4",
- "vite-plugin-eslint": "^1.8.1"
- },
- "husky": {
- "hooks": {
- "pre-commit": "lint-staged"
- }
- },
- "lint-staged": {
- "*.{js,jsx,vue,ts,tsx}": [
- "prettier --write",
- "git add"
- ]
- }
+ "name": "uniapp_vue3_vite_ts",
+ "version": "1.1.2",
+ "scripts": {
+ "dev:app": "uni -p app",
+ "dev:custom": "uni -p",
+ "dev:h5": "uni",
+ "dev:h5:ssr": "uni --ssr",
+ "dev:mp-alipay": "uni -p mp-alipay",
+ "dev:mp-baidu": "uni -p mp-baidu",
+ "dev:mp-kuaishou": "uni -p mp-kuaishou",
+ "dev:mp-lark": "uni -p mp-lark",
+ "dev:mp-qq": "uni -p mp-qq",
+ "dev:mp-toutiao": "uni -p mp-toutiao",
+ "dev:mp-weixin": "uni -p mp-weixin",
+ "dev:quickapp-webview": "uni -p quickapp-webview",
+ "dev:quickapp-webview-huawei": "uni -p quickapp-webview-huawei",
+ "dev:quickapp-webview-union": "uni -p quickapp-webview-union",
+ "build:app": "uni build -p app",
+ "build:custom": "uni build -p",
+ "build:h5": "uni build --minify",
+ "build:h5:ssr": "uni build --ssr",
+ "build:mp-alipay": "uni build -p mp-alipay",
+ "build:mp-baidu": "uni build -p mp-baidu",
+ "build:mp-kuaishou": "uni build -p mp-kuaishou",
+ "build:mp-lark": "uni build -p mp-lark",
+ "build:mp-qq": "uni build -p mp-qq",
+ "build:mp-toutiao": "uni build -p mp-toutiao",
+ "build:mp-weixin": "uni build -p mp-weixin --minify",
+ "build:quickapp-webview": "uni build -p quickapp-webview",
+ "build:quickapp-webview-huawei": "uni build -p quickapp-webview-huawei",
+ "build:quickapp-webview-union": "uni build -p quickapp-webview-union",
+ "lint": "eslint --cache --max-warnings 0 \"src/**/*.{vue,ts}\" --fix",
+ "format": "prettier --write src/",
+ "prepare": "husky install"
+ },
+ "dependencies": {
+ "@dcloudio/uni-app": "3.0.0-alpha-3070620230227001",
+ "@dcloudio/uni-app-plus": "3.0.0-alpha-3070620230227001",
+ "@dcloudio/uni-components": "3.0.0-alpha-3070620230227001",
+ "@dcloudio/uni-h5": "3.0.0-alpha-3070620230227001",
+ "@dcloudio/uni-i18n": "3.0.0-alpha-3061620230106001",
+ "@dcloudio/uni-mp-alipay": "3.0.0-alpha-3070620230227001",
+ "@dcloudio/uni-mp-baidu": "3.0.0-alpha-3070620230227001",
+ "@dcloudio/uni-mp-kuaishou": "3.0.0-alpha-3070620230227001",
+ "@dcloudio/uni-mp-lark": "3.0.0-alpha-3070620230227001",
+ "@dcloudio/uni-mp-qq": "3.0.0-alpha-3070620230227001",
+ "@dcloudio/uni-mp-toutiao": "3.0.0-alpha-3070620230227001",
+ "@dcloudio/uni-mp-weixin": "3.0.0-alpha-3070620230227001",
+ "@dcloudio/uni-quickapp-webview": "3.0.0-alpha-3070620230227001",
+ "@fortawesome/fontawesome-free": "^6.3.0",
+ "@iconify/iconify": "^3.1.0",
+ "crypto-js": "^4.1.1",
+ "echarts": "^5.4.1",
+ "lodash-es": "^4.17.21",
+ "luch-request": "^3.0.8",
+ "pinia": "^2.0.33",
+ "qs": "^6.11.1",
+ "vue": "^3.2.47",
+ "vue-i18n": "^9.2.2"
+ },
+ "devDependencies": {
+ "@dcloudio/types": "^3.2.11",
+ "@dcloudio/uni-automator": "3.0.0-alpha-3070620230227001",
+ "@dcloudio/uni-cli-shared": "3.0.0-alpha-3070620230227001",
+ "@dcloudio/uni-stacktracey": "3.0.0-alpha-3070620230227001",
+ "@dcloudio/vite-plugin-uni": "3.0.0-alpha-3070620230227001",
+ "@iconify/json": "^2.2.31",
+ "@types/crypto-js": "^4.1.1",
+ "@types/lodash-es": "^4.17.6",
+ "@types/node": "^17.0.45",
+ "@types/qs": "^6.9.7",
+ "@typescript-eslint/eslint-plugin": "^5.54.1",
+ "@typescript-eslint/parser": "^5.54.1",
+ "@unocss/preset-icons": "^0.46.5",
+ "autoprefixer": "^10.4.13",
+ "eslint": "^8.35.0",
+ "eslint-config-prettier": "^8.7.0",
+ "eslint-plugin-prettier": "^4.2.1",
+ "eslint-plugin-vue": "^9.9.0",
+ "husky": "^8.0.3",
+ "lint-staged": "^13.1.2",
+ "mrm": "^4.1.13",
+ "postcss": "^8.4.21",
+ "prettier": "^2.8.4",
+ "sass": "^1.58.3",
+ "typescript": "^4.9.5",
+ "unocss": "^0.46.5",
+ "unocss-preset-weapp": "^0.2.5",
+ "vite": "^4.1.4"
+ },
+ "husky": {
+ "hooks": {
+ "pre-commit": "lint-staged"
+ }
+ },
+ "lint-staged": {
+ "*.{js,jsx,vue,ts,tsx}": [
+ "prettier --write",
+ "git add"
+ ]
+ }
}
diff --git a/src/App.vue b/src/App.vue
index b5fe7dc..1ae0729 100644
--- a/src/App.vue
+++ b/src/App.vue
@@ -4,20 +4,20 @@ import { useAuthStore } from '@/state/modules/auth';
import { removeInterceptor, setupInterceptors } from '@/utils/interceptors';
import { useRouterStore } from '@/state/modules/router';
onLaunch(() => {
- console.log('App Launch');
- removeInterceptor();
+ console.log('App Launch');
+ removeInterceptor();
- setupInterceptors();
- const appStore = useRouterStore();
- appStore.initialize();
+ setupInterceptors();
+ const appStore = useRouterStore();
+ appStore.initialize();
});
onShow(() => {
- const authStore = useAuthStore();
- authStore.initToken();
- console.log('App Show');
+ const authStore = useAuthStore();
+ authStore.initToken();
+ console.log('App Show');
});
onHide(() => {
- console.log('App Hide');
+ console.log('App Hide');
});
diff --git a/src/components/BasicButton/index.vue b/src/components/BasicButton/index.vue
index a660ccc..15ae372 100644
--- a/src/components/BasicButton/index.vue
+++ b/src/components/BasicButton/index.vue
@@ -4,29 +4,29 @@ import { buttonProps } from '@/components/BasicButton/prpos';
const props = defineProps(buttonProps);
const emits = defineEmits(['click']);
const click = () => {
- emits('click');
+ emits('click');
};
-
-
-
+
+
+
diff --git a/src/components/BasicButton/prpos.ts b/src/components/BasicButton/prpos.ts
index 1613b8a..5522c56 100644
--- a/src/components/BasicButton/prpos.ts
+++ b/src/components/BasicButton/prpos.ts
@@ -1,4 +1,4 @@
export const buttonProps = {
- disabled: { type: Boolean, default: false },
- click: { type: Function },
+ disabled: { type: Boolean, default: false },
+ click: { type: Function },
};
diff --git a/src/components/BasicInput/index.vue b/src/components/BasicInput/index.vue
index df5e66c..aaf35bb 100644
--- a/src/components/BasicInput/index.vue
+++ b/src/components/BasicInput/index.vue
@@ -1,30 +1,30 @@
-
+
diff --git a/src/components/Iconify/index.vue b/src/components/Iconify/index.vue
index 1848a2d..01216e9 100644
--- a/src/components/Iconify/index.vue
+++ b/src/components/Iconify/index.vue
@@ -3,40 +3,40 @@ import { computed, ref, unref } from 'vue';
import { assign } from 'lodash-es';
const props = defineProps({
- icon: {
- type: String,
- },
- size: {
- type: [Number, String],
- },
- color: {
- type: String,
- },
+ icon: {
+ type: String,
+ },
+ size: {
+ type: [Number, String],
+ },
+ color: {
+ type: String,
+ },
});
const iconSize = ref(props.size ? `${props.size}rpx` : false);
const style = computed(() => {
- return assign(unref(iconSize) ? { width: unref(iconSize), height: unref(iconSize) } : {}, props.color ? { color: props.color } : {});
+ return assign(unref(iconSize) ? { width: unref(iconSize), height: unref(iconSize) } : {}, props.color ? { color: props.color } : {});
});
const emit = defineEmits(['click']);
const onClick = () => {
- emit('click');
+ emit('click');
};
-
+
diff --git a/src/components/Navbar/index.vue b/src/components/Navbar/index.vue
index 45075dc..aca9aea 100644
--- a/src/components/Navbar/index.vue
+++ b/src/components/Navbar/index.vue
@@ -16,15 +16,15 @@ const { navigationBarBackgroundColor, navigationBarTitleText, navigationBarTextS
const { currentRoute, currentPages } = useRoute();
const props = defineProps({
- bgColor: { type: String },
- title: { type: String },
- titleColor: { type: String },
- titleSize: { type: [String, Number] },
- iconSize: { type: [String, Number] },
- gap: { type: Number, default: 8 },
- isBackShow: { type: Boolean, default: true },
- isHomeShow: { type: Boolean },
- shadow: { type: Boolean, default: true },
+ bgColor: { type: String },
+ title: { type: String },
+ titleColor: { type: String },
+ titleSize: { type: [String, Number] },
+ iconSize: { type: [String, Number] },
+ gap: { type: Number, default: 8 },
+ isBackShow: { type: Boolean, default: true },
+ isHomeShow: { type: Boolean },
+ shadow: { type: Boolean, default: true },
});
const { statusBarHeight } = useSystem();
@@ -39,81 +39,81 @@ const navbarBgColor = computed(() => props.bgColor || navigationBarBackgroundCol
const navbarTitle = computed(() => props.title || currentRoute?.style?.navigationBarTitleText || navigationBarTitleText);
const navbarTitleColor = computed(() => props.titleColor || currentRoute?.style?.navigationBarTextStyle || navigationBarTextStyle);
const navbarTitleSize = computed(() => {
- return `${px2rpx(defaultTitleSize.value) || props.titleSize}rpx`;
+ return `${px2rpx(defaultTitleSize.value) || props.titleSize}rpx`;
});
const navbarLeftIconSize = computed(() => {
- return `${px2rpx(defaultIconSize.value) || props.titleSize}`;
+ return `${px2rpx(defaultIconSize.value) || props.titleSize}`;
});
const backShow = computed(() => {
- return currentPages.length > 1 && props.isBackShow;
+ return currentPages.length > 1 && props.isBackShow;
});
const backHomeShow = computed(() => {
- return !currentRoute?.meta?.tabBar && props.isHomeShow;
+ return !currentRoute?.meta?.tabBar && props.isHomeShow;
});
const router = useRouter();
const onBack = () => {
- router.back();
+ router.back();
};
const onBackHome = () => {
- router.pushTab(HOME_PAGE);
+ router.pushTab(HOME_PAGE);
};
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- {{ navbarTitle }}
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {{ navbarTitle }}
+
+
+
+
+
+
+
+
+
+
diff --git a/src/components/Test/index.vue b/src/components/Test/index.vue
index 8fcf4f1..451257e 100644
--- a/src/components/Test/index.vue
+++ b/src/components/Test/index.vue
@@ -1,14 +1,14 @@
- {{ text }}
+ {{ text }}
diff --git a/src/enums/appEnum.ts b/src/enums/appEnum.ts
index 73e5334..85f2094 100644
--- a/src/enums/appEnum.ts
+++ b/src/enums/appEnum.ts
@@ -2,6 +2,6 @@
* @description: 客户端 api 返回结果设置
*/
export enum ClientApiResultEnum {
- CLIENT_SUCCESS = 1,
- CLIENT_ERROR = 0,
+ CLIENT_SUCCESS = 1,
+ CLIENT_ERROR = 0,
}
diff --git a/src/enums/httpEnum.ts b/src/enums/httpEnum.ts
index 18cd6a5..67f5822 100644
--- a/src/enums/httpEnum.ts
+++ b/src/enums/httpEnum.ts
@@ -2,8 +2,8 @@
* @description: 请求结果设置
*/
export enum ResultEnum {
- SUCCESS = 10000,
- ERROR = 1,
- TIMEOUT = 401,
- TYPE = 'success',
+ SUCCESS = 10000,
+ ERROR = 1,
+ TIMEOUT = 401,
+ TYPE = 'success',
}
diff --git a/src/enums/platformEnum.ts b/src/enums/platformEnum.ts
index e9b1ddb..0fe4f82 100644
--- a/src/enums/platformEnum.ts
+++ b/src/enums/platformEnum.ts
@@ -2,25 +2,25 @@
* 平台
*/
export enum PLATFORMS {
- DEFAULT = 'DEFAULT' /* 默认 */,
- VUE3 = 'VUE3' /* HBuilderX 3.2.0+ */,
- APP_PLUS = 'APP-PLUS' /* App */,
- APP_PLUS_NVUE = 'APP-PLUS-NVUE' /* App nvue 页面 */,
- APP_NVUE = 'APP-NVUE' /* App nvue 页面 */,
- H5 = 'H5' /* H5 */,
- MP_WEIXIN = 'MP-WEIXIN' /* 微信小程序 */,
- MP_ALIPAY = 'MP-ALIPAY' /* 支付宝小程序 */,
- MP_BAIDU = 'MP_BAIDU' /* 百度小程序 */,
- MP_TOUTIAO = 'MP-TOUTIAO' /* 字节跳动小程序 */,
- MP_LARK = 'MP-LARK' /* 飞书小程序 */,
- MP_QQ = 'MP-QQ' /* QQ小程序 */,
- MP_KUAISHOU = 'MP-KUAISHOU' /* 快手小程序 */,
- MP_JD = 'MP-JD' /* 京东小程序 */,
- MP_360 = 'MP-360' /* 360小程序 */,
- MP = 'MP' /* 微信小程序/支付宝小程序/百度小程序/字节跳动小程序/飞书小程序/QQ小程序/360小程序 */,
- QUICKAPP_WEBVIEW = 'QUICKAPP-WEBVIEW' /* 快应用通用(包含联盟、华为) */,
- QUICKAPP_WEBVIEW_UNION = 'QUICKAPP-WEBVIEW-UNION' /* 快应用联盟 */,
- QUICKAPP_WEBVIEW_HUAWEI = 'QUICKAPP-WEBVIEW-HUAWEI' /* 快应用华为 */,
+ DEFAULT = 'DEFAULT' /* 默认 */,
+ VUE3 = 'VUE3' /* HBuilderX 3.2.0+ */,
+ APP_PLUS = 'APP-PLUS' /* App */,
+ APP_PLUS_NVUE = 'APP-PLUS-NVUE' /* App nvue 页面 */,
+ APP_NVUE = 'APP-NVUE' /* App nvue 页面 */,
+ H5 = 'H5' /* H5 */,
+ MP_WEIXIN = 'MP-WEIXIN' /* 微信小程序 */,
+ MP_ALIPAY = 'MP-ALIPAY' /* 支付宝小程序 */,
+ MP_BAIDU = 'MP_BAIDU' /* 百度小程序 */,
+ MP_TOUTIAO = 'MP-TOUTIAO' /* 字节跳动小程序 */,
+ MP_LARK = 'MP-LARK' /* 飞书小程序 */,
+ MP_QQ = 'MP-QQ' /* QQ小程序 */,
+ MP_KUAISHOU = 'MP-KUAISHOU' /* 快手小程序 */,
+ MP_JD = 'MP-JD' /* 京东小程序 */,
+ MP_360 = 'MP-360' /* 360小程序 */,
+ MP = 'MP' /* 微信小程序/支付宝小程序/百度小程序/字节跳动小程序/飞书小程序/QQ小程序/360小程序 */,
+ QUICKAPP_WEBVIEW = 'QUICKAPP-WEBVIEW' /* 快应用通用(包含联盟、华为) */,
+ QUICKAPP_WEBVIEW_UNION = 'QUICKAPP-WEBVIEW-UNION' /* 快应用联盟 */,
+ QUICKAPP_WEBVIEW_HUAWEI = 'QUICKAPP-WEBVIEW-HUAWEI' /* 快应用华为 */,
}
/**
@@ -28,81 +28,81 @@ export enum PLATFORMS {
* @constructor
*/
function PLATFORM_ENV() {
- let platform = PLATFORMS.DEFAULT;
+ let platform = PLATFORMS.DEFAULT;
- /* #ifdef VUE3 */
- platform = PLATFORMS.VUE3;
- /* #endif */
+ /* #ifdef VUE3 */
+ platform = PLATFORMS.VUE3;
+ /* #endif */
- /* #ifdef APP-PLUS */
- platform = PLATFORMS.APP_PLUS;
- /* #endif */
+ /* #ifdef APP-PLUS */
+ platform = PLATFORMS.APP_PLUS;
+ /* #endif */
- /* #ifdef APP-PLUS-NVUE */
- platform = PLATFORMS.APP_PLUS_NVUE;
- /* #endif */
+ /* #ifdef APP-PLUS-NVUE */
+ platform = PLATFORMS.APP_PLUS_NVUE;
+ /* #endif */
- /* #ifdef APP-NVUE */
- platform = PLATFORMS.APP_NVUE;
- /* #endif */
+ /* #ifdef APP-NVUE */
+ platform = PLATFORMS.APP_NVUE;
+ /* #endif */
- /* #ifdef H5 */
- platform = PLATFORMS.H5;
- /* #endif */
+ /* #ifdef H5 */
+ platform = PLATFORMS.H5;
+ /* #endif */
- /* #ifdef MP */
- platform = PLATFORMS.MP;
- /* #endif */
+ /* #ifdef MP */
+ platform = PLATFORMS.MP;
+ /* #endif */
- /* #ifdef MP-WEIXIN */
- platform = PLATFORMS.MP_WEIXIN;
- /* #endif */
+ /* #ifdef MP-WEIXIN */
+ platform = PLATFORMS.MP_WEIXIN;
+ /* #endif */
- /* #ifdef MP-ALIPAY */
- platform = PLATFORMS.MP_ALIPAY;
- /* #endif */
+ /* #ifdef MP-ALIPAY */
+ platform = PLATFORMS.MP_ALIPAY;
+ /* #endif */
- /* #ifdef MP_BAIDU */
- platform = PLATFORMS.MP_BAIDU;
- /* #endif */
+ /* #ifdef MP_BAIDU */
+ platform = PLATFORMS.MP_BAIDU;
+ /* #endif */
- /* #ifdef MP-TOUTIAO */
- platform = PLATFORMS.MP_TOUTIAO;
- /* #endif */
+ /* #ifdef MP-TOUTIAO */
+ platform = PLATFORMS.MP_TOUTIAO;
+ /* #endif */
- /* #ifdef MP-LARK */
- platform = PLATFORMS.MP_LARK;
- /* #endif */
+ /* #ifdef MP-LARK */
+ platform = PLATFORMS.MP_LARK;
+ /* #endif */
- /* #ifdef MP-QQ */
- platform = PLATFORMS.MP_QQ;
- /* #endif */
+ /* #ifdef MP-QQ */
+ platform = PLATFORMS.MP_QQ;
+ /* #endif */
- /* #ifdef MP-KUAISHOU */
- platform = PLATFORMS.MP_KUAISHOU;
- /* #endif */
+ /* #ifdef MP-KUAISHOU */
+ platform = PLATFORMS.MP_KUAISHOU;
+ /* #endif */
- /* #ifdef MP-JD */
- platform = PLATFORMS.MP_JD;
- /* #endif */
+ /* #ifdef MP-JD */
+ platform = PLATFORMS.MP_JD;
+ /* #endif */
- /* #ifdef MP-360 */
- platform = PLATFORMS.MP_360;
- /* #endif */
+ /* #ifdef MP-360 */
+ platform = PLATFORMS.MP_360;
+ /* #endif */
- /* #ifdef QUICKAPP-WEBVIEW */
- platform = PLATFORMS.QUICKAPP_WEBVIEW;
- /* #endif */
+ /* #ifdef QUICKAPP-WEBVIEW */
+ platform = PLATFORMS.QUICKAPP_WEBVIEW;
+ /* #endif */
- /* #ifdef QUICKAPP-WEBVIEW-UNION */
- platform = PLATFORMS.QUICKAPP_WEBVIEW_UNION;
- /* #endif */
+ /* #ifdef QUICKAPP-WEBVIEW-UNION */
+ platform = PLATFORMS.QUICKAPP_WEBVIEW_UNION;
+ /* #endif */
- /* #ifdef QUICKAPP-WEBVIEW-HUAWEI */
- platform = PLATFORMS.QUICKAPP_WEBVIEW_HUAWEI;
- /* #endif */
+ /* #ifdef QUICKAPP-WEBVIEW-HUAWEI */
+ platform = PLATFORMS.QUICKAPP_WEBVIEW_HUAWEI;
+ /* #endif */
- return platform;
+ return platform;
}
/* 当前平台 */
diff --git a/src/enums/routerEnum.ts b/src/enums/routerEnum.ts
index 5d01d90..38bc8b7 100644
--- a/src/enums/routerEnum.ts
+++ b/src/enums/routerEnum.ts
@@ -1,9 +1,9 @@
export enum NAVIGATE_TYPE {
- NAVIGATE_TO = 'navigateTo',
- REDIRECT_TO = 'redirectTo',
- RE_LAUNCH = 'reLaunch',
- SWITCH_TAB = 'switchTab',
- NAVIGATE_BACK = 'navigateBack',
+ NAVIGATE_TO = 'navigateTo',
+ REDIRECT_TO = 'redirectTo',
+ RE_LAUNCH = 'reLaunch',
+ SWITCH_TAB = 'switchTab',
+ NAVIGATE_BACK = 'navigateBack',
}
export const NAVIGATE_TYPE_LIST = ['navigateTo', 'redirectTo', 'reLaunch', 'switchTab'];
diff --git a/src/hooks/router.ts b/src/hooks/router.ts
index c33c0d0..738f1d4 100644
--- a/src/hooks/router.ts
+++ b/src/hooks/router.ts
@@ -8,7 +8,7 @@ const router = new Navigates();
* 路由hook
*/
export function useRouter() {
- return router;
+ return router;
}
/**
@@ -19,26 +19,26 @@ export function useRouter() {
* @return RouteLocationNormalized
*/
export function useRoute(): RouteLocationNormalized {
- const currentPages = getCurrentPages();
- const currentPage = currentPages[currentPages.length - 1];
- const path = currentPage?.route || '';
- const routerStore = useRouterStore();
- const currentRoute = routerStore.getRoutes?.get(path as string);
- let query = {};
- /* #ifndef MP-WEIXIN */
- // @ts-ignore
- query = currentPage?.$page?.options || {};
- /* #endif */
+ const currentPages = getCurrentPages();
+ const currentPage = currentPages[currentPages.length - 1];
+ const path = currentPage?.route || '';
+ const routerStore = useRouterStore();
+ const currentRoute = routerStore.getRoutes?.get(path as string);
+ let query = {};
+ /* #ifndef MP-WEIXIN */
+ // @ts-ignore
+ query = currentPage?.$page?.options || {};
+ /* #endif */
- /* #ifdef MP-WEIXIN */
- // @ts-ignore
- query = currentPage?.options || {};
- /* #endif */
- return {
- currentPages,
- currentPage,
- path,
- currentRoute,
- query,
- };
+ /* #ifdef MP-WEIXIN */
+ // @ts-ignore
+ query = currentPage?.options || {};
+ /* #endif */
+ return {
+ currentPages,
+ currentPage,
+ path,
+ currentRoute,
+ query,
+ };
}
diff --git a/src/hooks/useGlobalStyle.ts b/src/hooks/useGlobalStyle.ts
index 259f533..0c58cb2 100644
--- a/src/hooks/useGlobalStyle.ts
+++ b/src/hooks/useGlobalStyle.ts
@@ -5,11 +5,11 @@ const { globalStyle } = pagesJson;
* 全局样式
*/
export const useGlobalStyle = () => {
- const { navigationBarTextStyle, navigationBarTitleText, navigationBarBackgroundColor, backgroundColor } = globalStyle;
- return {
- navigationBarTextStyle,
- navigationBarTitleText,
- navigationBarBackgroundColor,
- backgroundColor,
- };
+ const { navigationBarTextStyle, navigationBarTitleText, navigationBarBackgroundColor, backgroundColor } = globalStyle;
+ return {
+ navigationBarTextStyle,
+ navigationBarTitleText,
+ navigationBarBackgroundColor,
+ backgroundColor,
+ };
};
diff --git a/src/hooks/useSystem.ts b/src/hooks/useSystem.ts
index c6c08f8..847b1c0 100644
--- a/src/hooks/useSystem.ts
+++ b/src/hooks/useSystem.ts
@@ -4,149 +4,149 @@
* @link https://uniapp.dcloud.net.cn/api/system/info.html
*/
export const useSystem = () => {
- const {
- // device
- deviceId,
- deviceBrand,
- deviceModel,
- deviceType,
- devicePixelRatio,
- deviceOrientation,
- // os
- osName,
- osVersion,
- osLanguage,
- osTheme,
- // @ts-ignore
- osAndroidAPILevel,
- // rom
- romName,
- romVersion,
- // browser
- browserName,
- browserVersion,
- // host
- hostFontSizeSetting,
- hostSDKVersion,
- hostName,
- hostVersion,
- hostLanguage,
- hostTheme,
- hostPackageName,
- // uni-app框架
- uniPlatform,
- uniCompileVersion,
- uniRuntimeVersion,
- // app
- appId,
- appName,
- appVersion,
- appVersionCode,
- appLanguage,
- // @ts-ignore
- appWgtVersion,
- // 其他
- ua,
- screenWidth,
- screenHeight,
- windowWidth,
- windowHeight,
- windowTop,
- windowBottom,
- statusBarHeight,
- safeArea,
- safeAreaInsets,
- // 某些小程序特殊的返回参数
- // @ts-ignore
- benchmarkLevel,
- // @ts-ignore
- batteryLevel,
- currentBattery,
- navigationBarHeight,
- titleBarHeight,
- albumAuthorized,
- cameraAuthorized,
- locationAuthorized,
- microphoneAuthorized,
- notificationAuthorized,
- notificationAlertAuthorized,
- notificationBadgeAuthorized,
- notificationSoundAuthorized,
- bluetoothEnabled,
- locationEnabled,
- wifiEnabled,
- cacheLocation,
- storage,
- } = uni.getSystemInfoSync();
- const { top: safeAreaTop, bottom: safeAreaBottom, left: safeAreaLeft, right: safeAreaRight, height: safeAreaHeight, width: safeAreaWidth } = safeArea!;
- const { top: safeAreaInsetsTop, bottom: safeAreaInsetsBottom, left: safeAreaInsetsLeft, right: safeAreaInsetsRight } = safeAreaInsets!;
- return {
- deviceId,
- deviceBrand,
- deviceModel,
- deviceType,
- devicePixelRatio,
- deviceOrientation,
- osName,
- osVersion,
- osLanguage,
- osTheme,
- osAndroidAPILevel,
- romName,
- romVersion,
- browserName,
- browserVersion,
- hostFontSizeSetting,
- hostSDKVersion,
- hostName,
- hostVersion,
- hostLanguage,
- hostTheme,
- hostPackageName,
- uniPlatform,
- uniCompileVersion,
- uniRuntimeVersion,
- appId,
- appName,
- appVersion,
- appVersionCode,
- appLanguage,
- appWgtVersion,
- ua,
- screenWidth,
- screenHeight,
- windowWidth,
- windowHeight,
- windowTop,
- windowBottom,
- statusBarHeight,
- safeAreaTop,
- safeAreaBottom,
- safeAreaLeft,
- safeAreaRight,
- safeAreaHeight,
- safeAreaWidth,
- safeAreaInsetsTop,
- safeAreaInsetsBottom,
- safeAreaInsetsLeft,
- safeAreaInsetsRight,
- benchmarkLevel,
- batteryLevel,
- currentBattery,
- navigationBarHeight,
- titleBarHeight,
- albumAuthorized,
- cameraAuthorized,
- locationAuthorized,
- microphoneAuthorized,
- notificationAuthorized,
- notificationAlertAuthorized,
- notificationBadgeAuthorized,
- notificationSoundAuthorized,
- bluetoothEnabled,
- locationEnabled,
- wifiEnabled,
- cacheLocation,
- storage,
- };
+ const {
+ // device
+ deviceId,
+ deviceBrand,
+ deviceModel,
+ deviceType,
+ devicePixelRatio,
+ deviceOrientation,
+ // os
+ osName,
+ osVersion,
+ osLanguage,
+ osTheme,
+ // @ts-ignore
+ osAndroidAPILevel,
+ // rom
+ romName,
+ romVersion,
+ // browser
+ browserName,
+ browserVersion,
+ // host
+ hostFontSizeSetting,
+ hostSDKVersion,
+ hostName,
+ hostVersion,
+ hostLanguage,
+ hostTheme,
+ hostPackageName,
+ // uni-app框架
+ uniPlatform,
+ uniCompileVersion,
+ uniRuntimeVersion,
+ // app
+ appId,
+ appName,
+ appVersion,
+ appVersionCode,
+ appLanguage,
+ // @ts-ignore
+ appWgtVersion,
+ // 其他
+ ua,
+ screenWidth,
+ screenHeight,
+ windowWidth,
+ windowHeight,
+ windowTop,
+ windowBottom,
+ statusBarHeight,
+ safeArea,
+ safeAreaInsets,
+ // 某些小程序特殊的返回参数
+ // @ts-ignore
+ benchmarkLevel,
+ // @ts-ignore
+ batteryLevel,
+ currentBattery,
+ navigationBarHeight,
+ titleBarHeight,
+ albumAuthorized,
+ cameraAuthorized,
+ locationAuthorized,
+ microphoneAuthorized,
+ notificationAuthorized,
+ notificationAlertAuthorized,
+ notificationBadgeAuthorized,
+ notificationSoundAuthorized,
+ bluetoothEnabled,
+ locationEnabled,
+ wifiEnabled,
+ cacheLocation,
+ storage,
+ } = uni.getSystemInfoSync();
+ const { top: safeAreaTop, bottom: safeAreaBottom, left: safeAreaLeft, right: safeAreaRight, height: safeAreaHeight, width: safeAreaWidth } = safeArea!;
+ const { top: safeAreaInsetsTop, bottom: safeAreaInsetsBottom, left: safeAreaInsetsLeft, right: safeAreaInsetsRight } = safeAreaInsets!;
+ return {
+ deviceId,
+ deviceBrand,
+ deviceModel,
+ deviceType,
+ devicePixelRatio,
+ deviceOrientation,
+ osName,
+ osVersion,
+ osLanguage,
+ osTheme,
+ osAndroidAPILevel,
+ romName,
+ romVersion,
+ browserName,
+ browserVersion,
+ hostFontSizeSetting,
+ hostSDKVersion,
+ hostName,
+ hostVersion,
+ hostLanguage,
+ hostTheme,
+ hostPackageName,
+ uniPlatform,
+ uniCompileVersion,
+ uniRuntimeVersion,
+ appId,
+ appName,
+ appVersion,
+ appVersionCode,
+ appLanguage,
+ appWgtVersion,
+ ua,
+ screenWidth,
+ screenHeight,
+ windowWidth,
+ windowHeight,
+ windowTop,
+ windowBottom,
+ statusBarHeight,
+ safeAreaTop,
+ safeAreaBottom,
+ safeAreaLeft,
+ safeAreaRight,
+ safeAreaHeight,
+ safeAreaWidth,
+ safeAreaInsetsTop,
+ safeAreaInsetsBottom,
+ safeAreaInsetsLeft,
+ safeAreaInsetsRight,
+ benchmarkLevel,
+ batteryLevel,
+ currentBattery,
+ navigationBarHeight,
+ titleBarHeight,
+ albumAuthorized,
+ cameraAuthorized,
+ locationAuthorized,
+ microphoneAuthorized,
+ notificationAuthorized,
+ notificationAlertAuthorized,
+ notificationBadgeAuthorized,
+ notificationSoundAuthorized,
+ bluetoothEnabled,
+ locationEnabled,
+ wifiEnabled,
+ cacheLocation,
+ storage,
+ };
};
diff --git a/src/main.ts b/src/main.ts
index fbbb9a4..bc4e868 100644
--- a/src/main.ts
+++ b/src/main.ts
@@ -4,12 +4,12 @@ import { setupStore } from '@/state';
import 'uno.css';
export function createApp() {
- const app = createSSRApp(App);
+ const app = createSSRApp(App);
- // Configure store
- setupStore(app);
+ // Configure store
+ setupStore(app);
- return {
- app,
- };
+ return {
+ app,
+ };
}
diff --git a/src/pages.json b/src/pages.json
index 406fed7..791b3d3 100644
--- a/src/pages.json
+++ b/src/pages.json
@@ -1,118 +1,130 @@
{
- "pages": [
- {
- "path": "pages/index/index",
- "style": {
- "navigationBarTitleText": "首页",
- "navigationStyle":"custom"
- },
- "meta": {
- "ignoreAuth": true
- }
+ "pages": [
+ {
+ "path": "pages/index/index",
+ "style": {
+ "navigationBarTitleText": "首页",
+ "navigationStyle": "custom"
+ },
+ "meta": {
+ "ignoreAuth": true
+ }
+ },
+ {
+ "path": "pages/demo/index",
+ "style": {
+ "navigationBarTitleText": "Demo"
+ },
+ "meta": {
+ "ignoreAuth": true
+ }
+ },
+ {
+ "path": "pages/about/index",
+ "style": {
+ "navigationBarTitleText": "关于"
+ },
+ "meta": {
+ "ignoreAuth": true
+ }
+ },
+ {
+ "path": "pages/login/index",
+ "style": {
+ "navigationBarTitleText": "登录"
+ },
+ "meta": {
+ "ignoreAuth": true
+ }
+ },
+ {
+ "path": "pages/log/index",
+ "style": {
+ "navigationBarTitleText": "日志"
+ }
+ },
+ {
+ "path": "pages/notFound/404",
+ "style": {
+ "navigationBarTitleText": "Not Found"
+ },
+ "meta": {
+ "ignoreAuth": true
+ }
+ }
+ ],
+ "subPackages": [
+ {
+ "root": "pagesA",
+ "pages": [
+ {
+ "path": "list/test1/index",
+ "style": {
+ "navigationBarTitleText": "test1"
+ },
+ "meta": {
+ "ignoreAuth": true
+ }
+ },
+ {
+ "path": "list/test2/index",
+ "style": {
+ "navigationBarTitleText": "test2",
+ "navigationStyle": "custom"
+ },
+ "meta": {
+ "ignoreAuth": true
+ }
+ }
+ ]
+ },
+ {
+ "root": "pagesB",
+ "pages": [
+ {
+ "path": "detail/index",
+ "style": {
+ "navigationBarTitleText": "Detail"
+ },
+ "meta": {
+ "ignoreAuth": true
+ }
+ }
+ ]
+ }
+ ],
+ "globalStyle": {
+ "navigationBarTextStyle": "black",
+ "navigationBarTitleText": "uni-app",
+ "navigationBarBackgroundColor": "#262833",
+ "backgroundColor": "#F8F8F8",
+ "navigationStyle": "default",
+ "renderingMode": "seperated",
+ "pageOrientation": "portrait"
},
- {
- "path": "pages/demo/index",
- "style": {
- "navigationBarTitleText": "Demo"
- },
- "meta": {
- "ignoreAuth": true
- }
- },
- {
- "path": "pages/about/index",
- "style": {
- "navigationBarTitleText": "关于"
- },
- "meta": {
- "ignoreAuth": true
- }
- },
- {
- "path": "pages/login/index",
- "style": {
- "navigationBarTitleText": "登录"
- },
- "meta": {
- "ignoreAuth": true
- }
- },
- {
- "path": "pages/log/index",
- "style": {
- "navigationBarTitleText": "日志"
- }
- },
- {
- "path": "pages/notFound/404",
- "style": {
- "navigationBarTitleText": "Not Found"
- },
- "meta": {
- "ignoreAuth": true
- }
+ "tabBar": {
+ "color": "#474747",
+ "selectedColor": "#9BC6FC",
+ "backgroundColor": "#FFFFFF",
+ "list": [
+ {
+ "pagePath": "pages/index/index",
+ "text": "首页",
+ "iconPath": "static/images/tabBar/home.png",
+ "selectedIconPath": "static/images/tabBar/selectedHome.png"
+ },
+ {
+ "pagePath": "pages/demo/index",
+ "text": "Demo",
+ "iconPath": "static/images/tabBar/demo.png",
+ "selectedIconPath": "static/images/tabBar/selectedDemo.png"
+ },
+ {
+ "pagePath": "pages/about/index",
+ "text": "关于",
+ "iconPath": "static/images/tabBar/about.png",
+ "selectedIconPath": "static/images/tabBar/selectedAbout.png"
+ }
+ ]
}
- ],
- "subPackages": [{
- "root": "pagesA",
- "pages": [{
- "path": "list/test1/index",
- "style": {
- "navigationBarTitleText": "test1"
- },
- "meta": {
- "ignoreAuth": true
- }
- },{
- "path": "list/test2/index",
- "style": {
- "navigationBarTitleText": "test2",
- "navigationStyle":"custom"
- },
- "meta": {
- "ignoreAuth": true
- }
- }]
- }, {
- "root": "pagesB",
- "pages": [{
- "path": "detail/index",
- "style": {
- "navigationBarTitleText": "Detail"
- },
- "meta": {
- "ignoreAuth": true
- }
- }]
- }],
- "globalStyle": {
- "navigationBarTextStyle": "black",
- "navigationBarTitleText": "uni-app",
- "navigationBarBackgroundColor": "#262833",
- "backgroundColor": "#F8F8F8",
- "navigationStyle": "default",
- "renderingMode": "seperated",
- "pageOrientation": "portrait"
- },
- "tabBar": {
- "color": "#474747",
- "selectedColor": "#9BC6FC",
- "backgroundColor": "#FFFFFF",
- "list": [{
- "pagePath": "pages/index/index",
- "text": "首页",
- "iconPath": "static/images/tabBar/home.png",
- "selectedIconPath": "static/images/tabBar/selectedHome.png"
- },{
- "pagePath": "pages/demo/index",
- "text": "Demo",
- "iconPath": "static/images/tabBar/demo.png",
- "selectedIconPath": "static/images/tabBar/selectedDemo.png"
- },{
- "pagePath": "pages/about/index",
- "text": "关于",
- "iconPath": "static/images/tabBar/about.png",
- "selectedIconPath": "static/images/tabBar/selectedAbout.png"
- }]
- }
}
diff --git a/src/pages/about/index.vue b/src/pages/about/index.vue
index c5d233b..b253e50 100644
--- a/src/pages/about/index.vue
+++ b/src/pages/about/index.vue
@@ -10,65 +10,65 @@ const authStore = useAuthStore();
const isLogin = ref(false);
const router = useRouter();
onShow(() => {
- isLogin.value = authStore.isLogin;
+ isLogin.value = authStore.isLogin;
});
const handleJump = (url: string) => {
- router.push(url);
+ router.push(url);
};
// 登出
const handleLoginOut = () => {
- authStore.loginOut().then(() => {
- isLogin.value = false;
- });
+ authStore.loginOut().then(() => {
+ isLogin.value = false;
+ });
};
-
-
-
-
-
-
- {{ isLogin ? '测试' : '未登入' }}
-
- log
- 登出
-
- 登入
-
-
-
+
+
+
+
+
+
+ {{ isLogin ? '测试' : '未登入' }}
+
+ log
+ 登出
+
+ 登入
+
+
+
diff --git a/src/pages/demo/index.vue b/src/pages/demo/index.vue
index 100fc63..b4496f7 100644
--- a/src/pages/demo/index.vue
+++ b/src/pages/demo/index.vue
@@ -5,22 +5,22 @@ import { useRouter } from '@/hooks/router';
const router = useRouter();
const jumpList1 = () => {
- router.push('/pagesA/list/test1/index?key=words&page=1&limit=15');
+ router.push('/pagesA/list/test1/index?key=words&page=1&limit=15');
};
-
- 页面构建中...
-
- List1 →
-
-
+
+ 页面构建中...
+
+ List1 →
+
+
diff --git a/src/pages/index/index.vue b/src/pages/index/index.vue
index 00982f9..141d583 100644
--- a/src/pages/index/index.vue
+++ b/src/pages/index/index.vue
@@ -15,55 +15,55 @@ const isVue3 = judgePlatform(PLATFORMS.VUE3);
const router = useRouter();
const handleGetStarted = () => {
- router.pushTab('/pages/demo/index');
- // router.push('/pages/log/index?id=4345&title=log');
+ router.pushTab('/pages/demo/index');
+ // router.push('/pages/log/index?id=4345&title=log');
};
-
-
-
-
- {{ title }}
-
-
- 是否是Vue3: {{ isVue3 }}
-
-
- 当前平台: {{ platform }}
-
- Get Started →
- uno css
-
-
-
-
-
-
-
+
+
+
+
+ {{ title }}
+
+
+ 是否是Vue3: {{ isVue3 }}
+
+
+ 当前平台: {{ platform }}
+
+ Get Started →
+ uno css
+
+
+
+
+
+
+
diff --git a/src/pages/log/index.vue b/src/pages/log/index.vue
index 907258a..1fb423a 100644
--- a/src/pages/log/index.vue
+++ b/src/pages/log/index.vue
@@ -1,12 +1,12 @@
- 登录后访问log
+ 登录后访问log
diff --git a/src/pages/login/index.vue b/src/pages/login/index.vue
index f2522d9..0865405 100644
--- a/src/pages/login/index.vue
+++ b/src/pages/login/index.vue
@@ -7,85 +7,85 @@ import { useRouter } from '@/hooks/router';
const redirect = ref(undefined);
onLoad((query) => {
- redirect.value = query.redirect ? decodeURIComponent(query.redirect) : undefined;
+ redirect.value = query.redirect ? decodeURIComponent(query.redirect) : undefined;
});
const router = useRouter();
const form = reactive({
- email: 'uni-app@test.com',
- password: 'Vue3_Ts_Vite',
+ email: 'uni-app@test.com',
+ password: 'Vue3_Ts_Vite',
});
const authStore = useAuthStore();
const submit = (e: any) => {
- authStore.login(e.detail.value).then(() => {
- Toast('登录成功', { duration: 1500 });
- setTimeout(() => {
- if (redirect.value) {
- router.go(redirect.value, { replace: true });
- return;
- }
- router.pushTab('/pages/about/index');
- }, 1500);
- });
+ authStore.login(e.detail.value).then(() => {
+ Toast('登录成功', { duration: 1500 });
+ setTimeout(() => {
+ if (redirect.value) {
+ router.go(redirect.value, { replace: true });
+ return;
+ }
+ router.pushTab('/pages/about/index');
+ }, 1500);
+ });
};
-
- 登录
-
-
-
-
+
+ 登录
+
+
+
+
diff --git a/src/pages/notFound/404.vue b/src/pages/notFound/404.vue
index 246f4b9..c66df18 100644
--- a/src/pages/notFound/404.vue
+++ b/src/pages/notFound/404.vue
@@ -8,26 +8,26 @@ const go = ref('');
const router = useRouter();
const redirect = ref('');
onLoad((query) => {
- go.value = query.go || '';
- redirect.value = query.redirect || '';
+ go.value = query.go || '';
+ redirect.value = query.redirect || '';
});
/**
* 返回首页
*/
const backHome = () => {
- router.pushTab(redirect.value);
+ router.pushTab(redirect.value);
};
-
-
-
- {{ go }} 页面找不到了~
-
- 返回首页
-
+
+
+
+ {{ go }} 页面找不到了~
+
+ 返回首页
+
diff --git a/src/pages/template/index.vue b/src/pages/template/index.vue
index 6d8783a..1dc1042 100644
--- a/src/pages/template/index.vue
+++ b/src/pages/template/index.vue
@@ -1,7 +1,7 @@
- 页面模板,新建pages,将此页面内容复制粘贴到新建.vue文件
+ 页面模板,新建pages,将此页面内容复制粘贴到新建.vue文件
diff --git a/src/pagesA/list/test1/index.vue b/src/pagesA/list/test1/index.vue
index 4eab012..bcaa727 100644
--- a/src/pagesA/list/test1/index.vue
+++ b/src/pagesA/list/test1/index.vue
@@ -4,11 +4,11 @@ import { useRouter } from '@/hooks/router';
const router = useRouter();
const jumpTest2 = () => {
- router.push('/pagesA/list/test2/index?id=256');
+ router.push('/pagesA/list/test2/index?id=256');
};
- Test1
- Test2 →
+ Test1
+ Test2 →
diff --git a/src/pagesA/list/test2/index.vue b/src/pagesA/list/test2/index.vue
index a065f34..e8fee61 100644
--- a/src/pagesA/list/test2/index.vue
+++ b/src/pagesA/list/test2/index.vue
@@ -4,13 +4,13 @@ import { useRouter } from '@/hooks/router';
const router = useRouter();
const jumpDetail = () => {
- router.push('/pagesB/detail/index?page=1&limit=20');
+ router.push('/pagesB/detail/index?page=1&limit=20');
};
-
- Test2
- Detail →
-
+
+ Test2
+ Detail →
+
diff --git a/src/services/api/auth.ts b/src/services/api/auth.ts
index b517b4c..6d0eccb 100644
--- a/src/services/api/auth.ts
+++ b/src/services/api/auth.ts
@@ -9,23 +9,23 @@ const REFRESH_TOKEN = '/refresh/token';
* @param params
*/
export function login(params: LoginParams) {
- return request.post(LOGIN, params, {
- custom: {
- auth: false,
- },
- });
+ return request.post(LOGIN, params, {
+ custom: {
+ auth: false,
+ },
+ });
}
/**
* 登出
*/
export function logout() {
- return request.post(LOGIN_OUT, {});
+ return request.post(LOGIN_OUT, {});
}
/**
* 刷新token
*/
export function refreshToken() {
- return request.post(REFRESH_TOKEN, {});
+ return request.post(REFRESH_TOKEN, {});
}
diff --git a/src/services/api/user.ts b/src/services/api/user.ts
index 2be05ab..7f785e1 100644
--- a/src/services/api/user.ts
+++ b/src/services/api/user.ts
@@ -1 +1,2 @@
-import { request } from '@/utils/http';
+// import { request } from '@/utils/http';
+export {};
diff --git a/src/services/model/authModel.d.ts b/src/services/model/authModel.d.ts
index 29e46db..5bbd2f9 100644
--- a/src/services/model/authModel.d.ts
+++ b/src/services/model/authModel.d.ts
@@ -1,7 +1,7 @@
declare interface LoginParams {
- email: string;
- password: string;
+ email: string;
+ password: string;
}
declare interface LoginModel {
- token: string;
+ token: string;
}
diff --git a/src/services/model/baseModel.d.ts b/src/services/model/baseModel.d.ts
index 5f7d96e..3e8a577 100644
--- a/src/services/model/baseModel.d.ts
+++ b/src/services/model/baseModel.d.ts
@@ -1,5 +1,5 @@
declare interface API {
- code: number;
- data?: T;
- message: string;
+ code: number;
+ data?: T;
+ message: string;
}
diff --git a/src/settings/encryptionSetting.ts b/src/settings/encryptionSetting.ts
index a305dc3..90ae133 100644
--- a/src/settings/encryptionSetting.ts
+++ b/src/settings/encryptionSetting.ts
@@ -7,8 +7,8 @@ export const DEFAULT_PREFIX_KEY = `${PREFIX}${getPkgVersion()}`;
// aes encryption key
export const cacheCipher = {
- key: 'aQ0{gD1@c_0@oH5:',
- iv: 'aF0#gC_$hE1$eA1!',
+ key: 'aQ0{gD1@c_0@oH5:',
+ iv: 'aF0#gC_$hE1$eA1!',
};
// Whether the system cache is encrypted using aes
diff --git a/src/state/app.ts b/src/state/app.ts
index 824a503..ffc0478 100644
--- a/src/state/app.ts
+++ b/src/state/app.ts
@@ -1,12 +1,12 @@
import { defineStore } from 'pinia';
interface AppState {
- sys?: string | number;
+ sys?: string | number;
}
export const useAppStore = defineStore({
- id: 'app-store',
- state: (): AppState => ({}),
- getters: {},
- actions: {},
+ id: 'app-store',
+ state: (): AppState => ({}),
+ getters: {},
+ actions: {},
});
diff --git a/src/state/index.ts b/src/state/index.ts
index 0e27f43..d31e790 100644
--- a/src/state/index.ts
+++ b/src/state/index.ts
@@ -4,7 +4,7 @@ import { createPinia } from 'pinia';
const store = createPinia();
export function setupStore(app: App) {
- app.use(store);
+ app.use(store);
}
export { store };
diff --git a/src/state/modules/auth.ts b/src/state/modules/auth.ts
index 1c6a2a9..e208b89 100644
--- a/src/state/modules/auth.ts
+++ b/src/state/modules/auth.ts
@@ -4,62 +4,62 @@ import { TOKEN_KEY } from '@/enums/cacheEnum';
import { login, logout, refreshToken } from '@/services/api/auth';
interface AuthState {
- token?: string;
+ token?: string;
}
export const useAuthStore = defineStore({
- id: 'auth',
- state: (): AuthState => ({
- token: undefined,
- }),
- getters: {
- getToken: (state) => state.token,
- isLogin: (state): boolean => !!state.token,
- },
- actions: {
- initToken() {
- this.token = getCache(TOKEN_KEY) || undefined;
- },
- setToken(token: string | undefined) {
- setCache(TOKEN_KEY, token);
- this.token = token;
- },
- /**
- * @description 登录
- */
- async login(params: LoginParams): Promise {
- try {
- const { data } = await login(params);
- this.setToken(data.token);
- return Promise.resolve(data);
- } catch (err: any) {
- return Promise.reject(err);
- }
- },
- /**
- * @description 登出
- */
- async loginOut(): Promise {
- try {
- const res = await logout();
- removeCache(TOKEN_KEY);
- this.setToken(undefined);
- return Promise.resolve(res);
- } catch (err: any) {
- return Promise.reject(err);
- }
- },
- /**
- * @description 刷新token
- */
- async refreshToken(): Promise {
- try {
- const { data } = await refreshToken();
- this.setToken(data.token);
- return Promise.resolve(data);
- } catch (err: any) {
- return Promise.reject(err);
- }
- },
- },
+ id: 'auth',
+ state: (): AuthState => ({
+ token: undefined,
+ }),
+ getters: {
+ getToken: (state) => state.token,
+ isLogin: (state): boolean => !!state.token,
+ },
+ actions: {
+ initToken() {
+ this.token = getCache(TOKEN_KEY) || undefined;
+ },
+ setToken(token: string | undefined) {
+ setCache(TOKEN_KEY, token);
+ this.token = token;
+ },
+ /**
+ * @description 登录
+ */
+ async login(params: LoginParams): Promise {
+ try {
+ const { data } = await login(params);
+ this.setToken(data.token);
+ return Promise.resolve(data);
+ } catch (err: any) {
+ return Promise.reject(err);
+ }
+ },
+ /**
+ * @description 登出
+ */
+ async loginOut(): Promise {
+ try {
+ const res = await logout();
+ removeCache(TOKEN_KEY);
+ this.setToken(undefined);
+ return Promise.resolve(res);
+ } catch (err: any) {
+ return Promise.reject(err);
+ }
+ },
+ /**
+ * @description 刷新token
+ */
+ async refreshToken(): Promise {
+ try {
+ const { data } = await refreshToken();
+ this.setToken(data.token);
+ return Promise.resolve(data);
+ } catch (err: any) {
+ return Promise.reject(err);
+ }
+ },
+ },
});
diff --git a/src/state/modules/router.ts b/src/state/modules/router.ts
index 00d92b9..d7b27c0 100644
--- a/src/state/modules/router.ts
+++ b/src/state/modules/router.ts
@@ -3,33 +3,33 @@ import { Route } from '@/types/router/route';
import { pagesMap } from '@/utils/router/routes';
interface routeStore {
- routes: Map | undefined;
- currentRouter: Route | undefined;
+ routes: Map | undefined;
+ currentRouter: Route | undefined;
}
export const useRouterStore = defineStore({
- id: 'routerStore',
- state: (): routeStore => ({
- routes: undefined,
- currentRouter: undefined,
- }),
- getters: {
- getRoutes(state) {
- return state.routes;
- },
- getCurrentRoute(state) {
- return state.currentRouter;
- },
- },
- actions: {
- initialize() {
- this.setRoutes();
- },
- setRoutes() {
- this.routes = pagesMap;
- },
- setCurrentRoute(path: string) {
- this.currentRouter = this.routes?.get(path) || undefined;
- },
- },
+ id: 'routerStore',
+ state: (): routeStore => ({
+ routes: undefined,
+ currentRouter: undefined,
+ }),
+ getters: {
+ getRoutes(state) {
+ return state.routes;
+ },
+ getCurrentRoute(state) {
+ return state.currentRouter;
+ },
+ },
+ actions: {
+ initialize() {
+ this.setRoutes();
+ },
+ setRoutes() {
+ this.routes = pagesMap;
+ },
+ setCurrentRoute(path: string) {
+ this.currentRouter = this.routes?.get(path) || undefined;
+ },
+ },
});
diff --git a/src/state/modules/user.ts b/src/state/modules/user.ts
index ad861ce..1d434b5 100644
--- a/src/state/modules/user.ts
+++ b/src/state/modules/user.ts
@@ -1,12 +1,12 @@
import { defineStore } from 'pinia';
interface UserState {
- id?: string | number;
+ id?: string | number;
}
export const useUserStore = defineStore({
- id: 'user',
- state: (): UserState => ({}),
- getters: {},
- actions: {},
+ id: 'user',
+ state: (): UserState => ({}),
+ getters: {},
+ actions: {},
});
diff --git a/src/types/env.d.ts b/src/types/env.d.ts
index 480a3d9..37a74ab 100644
--- a/src/types/env.d.ts
+++ b/src/types/env.d.ts
@@ -1,23 +1,23 @@
// /
declare module '*.vue' {
- import { DefineComponent } from 'vue';
- // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types
- const component: DefineComponent<{}, {}, any>;
- export default component;
+ import { DefineComponent } from 'vue';
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types
+ const component: DefineComponent<{}, {}, any>;
+ export default component;
}
interface ImportMetaEnv {
- readonly VITE_ENV: string;
- readonly VITE_APP_TITLE: string;
- readonly VITE_BASE_URL: string;
- readonly VITE_UPLOAD_URL: string;
- readonly VITE_PROD: boolean;
- readonly VITE_DEV: boolean;
- readonly VITE_APP_CACHE_PREFIX: string;
- readonly VITE_PORT: number;
+ readonly VITE_ENV: string;
+ readonly VITE_APP_TITLE: string;
+ readonly VITE_BASE_URL: string;
+ readonly VITE_UPLOAD_URL: string;
+ readonly VITE_PROD: boolean;
+ readonly VITE_DEV: boolean;
+ readonly VITE_APP_CACHE_PREFIX: string;
+ readonly VITE_PORT: number;
}
interface ImportMeta {
- readonly env: ImportMetaEnv;
+ readonly env: ImportMetaEnv;
}
diff --git a/src/types/router/route.d.ts b/src/types/router/route.d.ts
index ce61a9b..502697f 100644
--- a/src/types/router/route.d.ts
+++ b/src/types/router/route.d.ts
@@ -1,32 +1,32 @@
-import { types } from 'sass';
-import Boolean = types.Boolean;
+// import { types } from 'sass';
+// import Boolean = types.Boolean;
export interface Route extends Record {
- path: string;
- meta?: {
- ignoreAuth?: boolean;
- tabBar: boolean;
- };
- style: {
- navigationBarTitleText: string;
- [key: string]: string | boolean;
- };
+ path: string;
+ meta?: {
+ ignoreAuth?: boolean;
+ tabBar: boolean;
+ };
+ style: {
+ navigationBarTitleText: string;
+ [key: string]: string | boolean;
+ };
}
export interface SubPackages {
- root: string;
- pages: Route[];
+ root: string;
+ pages: Route[];
}
export interface RouteLocationNormalized {
- /* 当前页面栈的实例 */
- currentPages: Page.PageInstance[];
- /* 当前页面的实例 */
- currentPage: Page.PageInstance | undefined;
- /* 当前页面在pages.json中的配置 */
- currentRoute?: Route;
- /* 当前页面的path */
- path?: string;
- /* 当前页面的url参数 */
- query: Record;
+ /* 当前页面栈的实例 */
+ currentPages: Page.PageInstance[];
+ /* 当前页面的实例 */
+ currentPage: Page.PageInstance | undefined;
+ /* 当前页面在pages.json中的配置 */
+ currentRoute?: Route;
+ /* 当前页面的path */
+ path?: string;
+ /* 当前页面的url参数 */
+ query: Record;
}
diff --git a/src/utils/cache/index.ts b/src/utils/cache/index.ts
index 67ea1ba..d902dfc 100644
--- a/src/utils/cache/index.ts
+++ b/src/utils/cache/index.ts
@@ -2,27 +2,27 @@ import { createStorage, CreateStorageParams } from './storageCache';
import { cacheCipher, DEFAULT_CACHE_TIME, DEFAULT_PREFIX_KEY, enableStorageEncryption } from '@/settings/encryptionSetting';
const options: Partial = {
- prefixKey: DEFAULT_PREFIX_KEY,
- key: cacheCipher.key,
- iv: cacheCipher.iv,
- hasEncrypt: enableStorageEncryption,
- timeout: DEFAULT_CACHE_TIME,
+ prefixKey: DEFAULT_PREFIX_KEY,
+ key: cacheCipher.key,
+ iv: cacheCipher.iv,
+ hasEncrypt: enableStorageEncryption,
+ timeout: DEFAULT_CACHE_TIME,
};
export const storage = createStorage(options);
export function setCache(key: string, value: any, expire?: number | null): void {
- storage.set(key, value, expire);
+ storage.set(key, value, expire);
}
export function getCache(key: string): T {
- return storage.get(key);
+ return storage.get(key);
}
export function removeCache(key: string): void {
- return storage.remove(key);
+ return storage.remove(key);
}
export function clearCache(): void {
- return storage.clear();
+ return storage.clear();
}
diff --git a/src/utils/cache/storageCache.ts b/src/utils/cache/storageCache.ts
index cf20668..180efbc 100644
--- a/src/utils/cache/storageCache.ts
+++ b/src/utils/cache/storageCache.ts
@@ -4,110 +4,110 @@ import { AesEncryption } from '@/utils/cipher';
import { isNullOrUnDef } from '@/utils/is';
export interface CreateStorageParams extends EncryptionParams {
- prefixKey: string;
- hasEncrypt: boolean;
- timeout?: number | null;
+ prefixKey: string;
+ hasEncrypt: boolean;
+ timeout?: number | null;
}
export const createStorage = ({
- prefixKey = '',
- key = cacheCipher.key,
- iv = cacheCipher.iv,
- timeout = null,
- hasEncrypt = true,
+ prefixKey = '',
+ key = cacheCipher.key,
+ iv = cacheCipher.iv,
+ timeout = null,
+ hasEncrypt = true,
}: Partial = {}) => {
- if (hasEncrypt && [key.length, iv.length].some((item) => item !== 16)) {
- throw new Error('When hasEncrypt is true, the key or iv must be 16 bits!');
- }
+ if (hasEncrypt && [key.length, iv.length].some((item) => item !== 16)) {
+ throw new Error('When hasEncrypt is true, the key or iv must be 16 bits!');
+ }
- const encryption = new AesEncryption({ key, iv });
+ const encryption = new AesEncryption({ key, iv });
- /**
- * Cache class
- * Construction parameters can be passed into sessionStorage, localStorage,
- * @class Cache
- * @example
- */
- class Storage {
- private prefixKey?: string;
+ /**
+ * Cache class
+ * Construction parameters can be passed into sessionStorage, localStorage,
+ * @class Cache
+ * @example
+ */
+ class Storage {
+ private prefixKey?: string;
- private encryption: AesEncryption;
+ private encryption: AesEncryption;
- private hasEncrypt: boolean;
+ private hasEncrypt: boolean;
- /**
- *
- * @param {*} storage
- */
- constructor() {
- this.prefixKey = prefixKey;
- this.encryption = encryption;
- this.hasEncrypt = hasEncrypt;
- }
+ /**
+ *
+ * @param {*} storage
+ */
+ constructor() {
+ this.prefixKey = prefixKey;
+ this.encryption = encryption;
+ this.hasEncrypt = hasEncrypt;
+ }
- private getKey(key: string) {
- return `${this.prefixKey}${key}`.toUpperCase();
- }
+ private getKey(key: string) {
+ return `${this.prefixKey}${key}`.toUpperCase();
+ }
- /**
- * Set cache
- * @param {string} key
- * @param {*} value
- * @param {*} expire Expiration time in seconds
- * @memberof Cache
- */
- set(key: string, value: any, expire: number | null = timeout) {
- try {
- const stringData = JSON.stringify({
- value,
- time: Date.now(),
- expire: !isNullOrUnDef(expire) ? new Date().getTime() + expire * 1000 : null,
- });
- const stringifyValue = this.hasEncrypt ? this.encryption.encryptByAES(stringData) : stringData;
- uni.setStorageSync(this.getKey(key), stringifyValue);
- } catch (err) {
- throw new Error(`setStorageSync error: ${err}`);
- }
- }
+ /**
+ * Set cache
+ * @param {string} key
+ * @param {*} value
+ * @param {*} expire Expiration time in seconds
+ * @memberof Cache
+ */
+ set(key: string, value: any, expire: number | null = timeout) {
+ try {
+ const stringData = JSON.stringify({
+ value,
+ time: Date.now(),
+ expire: !isNullOrUnDef(expire) ? new Date().getTime() + expire * 1000 : null,
+ });
+ const stringifyValue = this.hasEncrypt ? this.encryption.encryptByAES(stringData) : stringData;
+ uni.setStorageSync(this.getKey(key), stringifyValue);
+ } catch (err) {
+ throw new Error(`setStorageSync error: ${err}`);
+ }
+ }
- /**
- * Read cache
- * @param {string} key
- * @param {*} def
- * @memberof Cache
- */
- get(key: string, def: any = null): T {
- const val = uni.getStorageSync(this.getKey(key));
- if (!val) return def;
+ /**
+ * Read cache
+ * @param {string} key
+ * @param {*} def
+ * @memberof Cache
+ */
+ get(key: string, def: any = null): T {
+ const val = uni.getStorageSync(this.getKey(key));
+ if (!val) return def;
- try {
- const decVal = this.hasEncrypt ? this.encryption.decryptByAES(val) : val;
- const data = JSON.parse(decVal);
- const { value, expire } = data;
- if (isNullOrUnDef(expire) || expire < new Date().getTime()) {
- this.remove(key);
- return def;
- }
- return value;
- } catch (e) {
- return def;
- }
- }
+ try {
+ const decVal = this.hasEncrypt ? this.encryption.decryptByAES(val) : val;
+ const data = JSON.parse(decVal);
+ const { value, expire } = data;
+ if (isNullOrUnDef(expire) || expire < new Date().getTime()) {
+ this.remove(key);
+ return def;
+ }
+ return value;
+ } catch (e) {
+ return def;
+ }
+ }
- /**
- * Delete cache based on key
- * @param {string} key
- * @memberof Cache
- */
- remove(key: string) {
- uni.removeStorageSync(this.getKey(key));
- }
+ /**
+ * Delete cache based on key
+ * @param {string} key
+ * @memberof Cache
+ */
+ remove(key: string) {
+ uni.removeStorageSync(this.getKey(key));
+ }
- /**
- * Delete all caches of this instance
- */
- clear(): void {
- uni.clearStorageSync();
- }
- }
- return new Storage();
+ /**
+ * Delete all caches of this instance
+ */
+ clear(): void {
+ uni.clearStorageSync();
+ }
+ }
+ return new Storage();
};
diff --git a/src/utils/cipher.ts b/src/utils/cipher.ts
index 9289e68..135ee79 100644
--- a/src/utils/cipher.ts
+++ b/src/utils/cipher.ts
@@ -7,43 +7,43 @@ import md5 from 'crypto-js/md5';
import Base64 from 'crypto-js/enc-base64';
export interface EncryptionParams {
- key: string;
- iv: string;
+ key: string;
+ iv: string;
}
/**
* AES 加密解密
*/
export class AesEncryption {
- private key;
+ private key;
- private iv;
+ private iv;
- constructor(opt: Partial = {}) {
- const { key, iv } = opt;
- if (key) {
- this.key = parse(key);
- }
- if (iv) {
- this.iv = parse(iv);
- }
- }
+ constructor(opt: Partial = {}) {
+ const { key, iv } = opt;
+ if (key) {
+ this.key = parse(key);
+ }
+ if (iv) {
+ this.iv = parse(iv);
+ }
+ }
- get getOptions() {
- return {
- mode: ECB,
- padding: pkcs7,
- iv: this.iv,
- };
- }
+ get getOptions() {
+ return {
+ mode: ECB,
+ padding: pkcs7,
+ iv: this.iv,
+ };
+ }
- encryptByAES(cipherText: string) {
- return encrypt(cipherText, this.key!, this.getOptions).toString();
- }
+ encryptByAES(cipherText: string) {
+ return encrypt(cipherText, this.key!, this.getOptions).toString();
+ }
- decryptByAES(cipherText: string) {
- return decrypt(cipherText, this.key!, this.getOptions).toString(UTF8);
- }
+ decryptByAES(cipherText: string) {
+ return decrypt(cipherText, this.key!, this.getOptions).toString(UTF8);
+ }
}
/**
@@ -51,7 +51,7 @@ export class AesEncryption {
* @param cipherText
*/
export function encryptByBase64(cipherText: string) {
- return UTF8.parse(cipherText).toString(Base64);
+ return UTF8.parse(cipherText).toString(Base64);
}
/**
@@ -59,7 +59,7 @@ export function encryptByBase64(cipherText: string) {
* @param cipherText
*/
export function decodeByBase64(cipherText: string) {
- return Base64.parse(cipherText).toString(UTF8);
+ return Base64.parse(cipherText).toString(UTF8);
}
/**
@@ -67,5 +67,5 @@ export function decodeByBase64(cipherText: string) {
* @param password
*/
export function encryptByMd5(password: string) {
- return md5(password).toString();
+ return md5(password).toString();
}
diff --git a/src/utils/env.ts b/src/utils/env.ts
index a0721cf..077b99e 100644
--- a/src/utils/env.ts
+++ b/src/utils/env.ts
@@ -6,7 +6,7 @@ import { PLATFORMS } from '@/enums/platformEnum';
* @description: Generate cache key according to version
*/
export function getPkgVersion() {
- return `${`__${pkg.version}`}__`.toUpperCase();
+ return `${`__${pkg.version}`}__`.toUpperCase();
}
/**
@@ -25,7 +25,7 @@ export const prodMode = 'production';
* @example:
*/
export function getEnvMode(): string {
- return isDevMode() ? devMode : prodMode;
+ return isDevMode() ? devMode : prodMode;
}
/**
@@ -34,8 +34,8 @@ export function getEnvMode(): string {
* @example:
*/
export function getEnvValue(key: string): T {
- // @ts-ignore
- return import.meta.env[key];
+ // @ts-ignore
+ return import.meta.env[key];
}
/**
@@ -44,7 +44,7 @@ export function getEnvValue(key: string): T {
* @example:
*/
export function isDevMode(): boolean {
- return getEnvValue('VITE_DEV');
+ return getEnvValue('VITE_DEV');
}
/**
@@ -53,7 +53,7 @@ export function isDevMode(): boolean {
* @example:
*/
export function isProdMode(): boolean {
- return getEnvValue('VITE_PROD');
+ return getEnvValue('VITE_PROD');
}
/**
@@ -62,8 +62,8 @@ export function isProdMode(): boolean {
* @example:
*/
export function getBaseUrl(): string {
- if (judgePlatform(PLATFORMS.H5) && isDevMode()) return '/api';
- return getEnvValue('VITE_BASE_URL');
+ if (judgePlatform(PLATFORMS.H5) && isDevMode()) return '/api';
+ return getEnvValue('VITE_BASE_URL');
}
/**
@@ -72,6 +72,6 @@ export function getBaseUrl(): string {
* @example:
*/
export function getUploadUrl(): string {
- if (judgePlatform(PLATFORMS.H5) && isDevMode()) return '/upload';
- return getEnvValue('VITE_UPLOAD_URL');
+ if (judgePlatform(PLATFORMS.H5) && isDevMode()) return '/upload';
+ return getEnvValue('VITE_UPLOAD_URL');
}
diff --git a/src/utils/http/index.ts b/src/utils/http/index.ts
index 0ed0a67..c2b23ae 100644
--- a/src/utils/http/index.ts
+++ b/src/utils/http/index.ts
@@ -7,18 +7,18 @@ import { ResultEnum } from '@/enums/httpEnum';
const BASE_URL = getBaseUrl();
const HEADER = {
- 'Content-Type': 'application/json;charset=UTF-8;',
- Accept: 'application/json, text/plain, */*',
+ 'Content-Type': 'application/json;charset=UTF-8;',
+ Accept: 'application/json, text/plain, */*',
};
function createRequest() {
- return new Request({
- baseURL: BASE_URL,
- header: HEADER,
- custom: {
- auth: true,
- },
- });
+ return new Request({
+ baseURL: BASE_URL,
+ header: HEADER,
+ custom: {
+ auth: true,
+ },
+ });
}
const request = createRequest();
@@ -26,40 +26,40 @@ const request = createRequest();
* 请求拦截器
*/
request.interceptors.request.use(
- (options) => {
- if (options.custom?.auth) {
- const authStore = useAuthStore();
- if (!authStore.isLogin) {
- Toast('请先登录');
- // token不存在跳转到登录页
- return Promise.reject(options);
- }
- options.header = assign(options.header, {
- authorization: `Bearer ${authStore.getToken}`,
- });
- }
- return options;
- },
- (options) => Promise.reject(options)
+ (options) => {
+ if (options.custom?.auth) {
+ const authStore = useAuthStore();
+ if (!authStore.isLogin) {
+ Toast('请先登录');
+ // token不存在跳转到登录页
+ return Promise.reject(options);
+ }
+ options.header = assign(options.header, {
+ authorization: `Bearer ${authStore.getToken}`,
+ });
+ }
+ return options;
+ },
+ (options) => Promise.reject(options),
);
/**
* 响应拦截器
*/
request.interceptors.response.use(
- async (response) => {
- const { data: resData } = response;
- const { code, message } = resData;
- if (code === ResultEnum.SUCCESS) {
- return resData as any;
- }
- Toast(message);
- return Promise.reject(resData);
- },
- (response) =>
- // 请求错误做点什么。可以使用async await 做异步操作
- // error('Request Error!');
- Promise.reject(response)
+ async (response) => {
+ const { data: resData } = response;
+ const { code, message } = resData;
+ if (code === ResultEnum.SUCCESS) {
+ return resData as any;
+ }
+ Toast(message);
+ return Promise.reject(resData);
+ },
+ (response) =>
+ // 请求错误做点什么。可以使用async await 做异步操作
+ // error('Request Error!');
+ Promise.reject(response),
);
export { request };
diff --git a/src/utils/index.ts b/src/utils/index.ts
index e2bd4e0..0801b72 100644
--- a/src/utils/index.ts
+++ b/src/utils/index.ts
@@ -6,9 +6,9 @@ import { isObject } from '@/utils/is';
* @param target
*/
export function deepMerge(src: any = {}, target: any = {}): T {
- let key: string;
- for (key in target) {
- src[key] = isObject(src[key]) ? deepMerge(src[key], target[key]) : (src[key] = target[key]);
- }
- return src;
+ let key: string;
+ for (key in target) {
+ src[key] = isObject(src[key]) ? deepMerge(src[key], target[key]) : (src[key] = target[key]);
+ }
+ return src;
}
diff --git a/src/utils/interceptors/index.ts b/src/utils/interceptors/index.ts
index bce0a04..17afa8d 100644
--- a/src/utils/interceptors/index.ts
+++ b/src/utils/interceptors/index.ts
@@ -1,9 +1,9 @@
import { routerInterceptor, routerRemoveInterceptor } from '@/utils/router/interceptor';
export function setupInterceptors() {
- routerInterceptor();
+ routerInterceptor();
}
export function removeInterceptor() {
- routerRemoveInterceptor();
+ routerRemoveInterceptor();
}
diff --git a/src/utils/is.ts b/src/utils/is.ts
index b43e7c9..de2a640 100644
--- a/src/utils/is.ts
+++ b/src/utils/is.ts
@@ -1,91 +1,91 @@
const { toString } = Object.prototype;
export function is(val: unknown, type: string) {
- return toString.call(val) === `[object ${type}]`;
+ return toString.call(val) === `[object ${type}]`;
}
export function isDef(val?: T): val is T {
- return typeof val !== 'undefined';
+ return typeof val !== 'undefined';
}
export function isUnDef(val?: T): val is T {
- return !isDef(val);
+ return !isDef(val);
}
export function isObject(val: any): val is Record {
- return val !== null && is(val, 'Object');
+ return val !== null && is(val, 'Object');
}
export function isEmpty(val: T): val is T {
- if (isArray(val) || isString(val)) {
- return val.length === 0;
- }
+ if (isArray(val) || isString(val)) {
+ return val.length === 0;
+ }
- if (val instanceof Map || val instanceof Set) {
- return val.size === 0;
- }
+ if (val instanceof Map || val instanceof Set) {
+ return val.size === 0;
+ }
- if (isObject(val)) {
- return Object.keys(val).length === 0;
- }
+ if (isObject(val)) {
+ return Object.keys(val).length === 0;
+ }
- return false;
+ return false;
}
export function isDate(val: unknown): val is Date {
- return is(val, 'Date');
+ return is(val, 'Date');
}
export function isNull(val: unknown): val is null {
- return val === null;
+ return val === null;
}
export function isNullAndUnDef(val: unknown): val is null | undefined {
- return isUnDef(val) && isNull(val);
+ return isUnDef(val) && isNull(val);
}
export function isNullOrUnDef(val: unknown): val is null | undefined {
- return isUnDef(val) || isNull(val);
+ return isUnDef(val) || isNull(val);
}
export function isNumber(val: unknown): val is number {
- return is(val, 'Number');
+ return is(val, 'Number');
}
export function isPromise(val: unknown): val is Promise {
- return is(val, 'Promise') && isObject(val) && isFunction(val.then) && isFunction(val.catch);
+ return is(val, 'Promise') && isObject(val) && isFunction(val.then) && isFunction(val.catch);
}
export function isString(val: unknown): val is string {
- return is(val, 'String');
+ return is(val, 'String');
}
export function isFunction(val: unknown): val is Function {
- return typeof val === 'function';
+ return typeof val === 'function';
}
export function isBoolean(val: unknown): val is boolean {
- return is(val, 'Boolean');
+ return is(val, 'Boolean');
}
export function isRegExp(val: unknown): val is RegExp {
- return is(val, 'RegExp');
+ return is(val, 'RegExp');
}
export function isArray(val: any): val is Array {
- return val && Array.isArray(val);
+ return val && Array.isArray(val);
}
export function isWindow(val: any): val is Window {
- return typeof window !== 'undefined' && is(val, 'Window');
+ return typeof window !== 'undefined' && is(val, 'Window');
}
export function isElement(val: unknown): val is Element {
- return isObject(val) && !!val.tagName;
+ return isObject(val) && !!val.tagName;
}
export function isMap(val: unknown): val is Map {
- return is(val, 'Map');
+ return is(val, 'Map');
}
export const isServer = typeof window === 'undefined';
@@ -93,8 +93,8 @@ export const isServer = typeof window === 'undefined';
export const isClient = !isServer;
export function isUrl(path: string): boolean {
- // @ts-ignore
- const reg =
- /^((https|http|ftp|rtsp|mms):\/\/)(([0-9a-zA-Z_!~*'().&=+$%-]+: )?[0-9a-zA-Z_!~*'().&=+$%-]+@)?(([0-9]{1,3}.){3}[0-9]{1,3}|([0-9a-zA-Z_!~*'()-]+.)*([0-9a-zA-Z][0-9a-zA-Z-]{0,61})?[0-9a-zA-Z].[a-zA-Z]{2,6})(:[0-9]{1,4})?((\/?)|(\/[0-9a-zA-Z_!~*'().;?:@&=+$,%#-]+)+\/?)$/;
- return reg.test(path);
+ // @ts-ignore
+ const reg =
+ /^((https|http|ftp|rtsp|mms):\/\/)(([0-9a-zA-Z_!~*'().&=+$%-]+: )?[0-9a-zA-Z_!~*'().&=+$%-]+@)?(([0-9]{1,3}.){3}[0-9]{1,3}|([0-9a-zA-Z_!~*'()-]+.)*([0-9a-zA-Z][0-9a-zA-Z-]{0,61})?[0-9a-zA-Z].[a-zA-Z]{2,6})(:[0-9]{1,4})?((\/?)|(\/[0-9a-zA-Z_!~*'().;?:@&=+$,%#-]+)+\/?)$/;
+ return reg.test(path);
}
diff --git a/src/utils/log.ts b/src/utils/log.ts
index 56725e8..e99d0aa 100644
--- a/src/utils/log.ts
+++ b/src/utils/log.ts
@@ -3,9 +3,9 @@ import { getEnvValue } from '@/utils/env';
const projectName = getEnvValue('VITE_APP_TITLE');
export function warn(message: string) {
- console.warn(`[${projectName} warn]:${message}`);
+ console.warn(`[${projectName} warn]:${message}`);
}
export function error(message: string) {
- throw new Error(`[${projectName} error]:${message}`);
+ throw new Error(`[${projectName} error]:${message}`);
}
diff --git a/src/utils/platform.ts b/src/utils/platform.ts
index b95fb13..23be0ef 100644
--- a/src/utils/platform.ts
+++ b/src/utils/platform.ts
@@ -7,136 +7,118 @@ import { PLATFORMS } from '@/enums/platformEnum';
* @return boolean
*/
export function judgePlatform(target: PLATFORMS): boolean {
- let isVue3 = false;
- let isAppPlus = false;
- let isAppPlusNvue = false;
- let isAppNvue = false;
- let isH5 = false;
- let isMp = false;
- let isMpWeinxin = false;
- let isMpAlipay = false;
- let isMpBaidu = false;
- let isMpToutiao = false;
- let isMpLark = false;
- let isMpQq = false;
- let isMpKuaishou = false;
- let isMpJd = false;
- let isMp360 = false;
- let isQuickAppWebView = false;
- let isQuickAppWebViewUnion = false;
- let isQuickAppWebViewHuawei = false;
+ let isVue3 = false;
+ let isAppPlus = false;
+ let isAppPlusNvue = false;
+ let isAppNvue = false;
+ let isH5 = false;
+ let isMp = false;
+ let isMpWeinxin = false;
+ let isMpAlipay = false;
+ let isMpBaidu = false;
+ let isMpToutiao = false;
+ let isMpLark = false;
+ let isMpQq = false;
+ let isMpKuaishou = false;
+ // let isMpJd = false;
+ let isMp360 = false;
+ let isQuickAppWebView = false;
+ let isQuickAppWebViewUnion = false;
+ let isQuickAppWebViewHuawei = false;
- switch (target) {
- case PLATFORMS.VUE3:
- /* #ifdef VUE3 */
- isVue3 = true;
- /* #endif */
- return isVue3;
- break;
- case PLATFORMS.APP_PLUS:
- /* #ifdef APP-PLUS */
- isAppPlus = true;
- /* #endif */
- return isAppPlus;
- break;
- case PLATFORMS.APP_PLUS_NVUE:
- /* #ifdef APP-PLUS-NVUE */
- isAppPlusNvue = true;
- /* #endif */
- return isAppPlusNvue;
- break;
- case PLATFORMS.APP_NVUE:
- /* #ifdef APP-NVUE */
- isAppNvue = true;
- /* #endif */
- return isAppNvue;
- break;
- case PLATFORMS.H5:
- /* #ifdef H5 */
- isH5 = true;
- /* #endif */
- return isH5;
- break;
- case PLATFORMS.MP:
- /* #ifdef MP */
- isMp = true;
- /* #endif */
- return isMp;
- break;
- case PLATFORMS.MP_WEIXIN:
- /* #ifdef MP-WEIXIN */
- isMpWeinxin = true;
- /* #endif */
- return isMpWeinxin;
- break;
- case PLATFORMS.MP_ALIPAY:
- /* #ifdef MP-ALIPAY */
- isMpAlipay = true;
- /* #endif */
- return isMpAlipay;
- break;
- case PLATFORMS.MP_BAIDU:
- /* #ifdef MP_BAIDU */
- isMpBaidu = true;
- /* #endif */
- return isMpBaidu;
- break;
- case PLATFORMS.MP_TOUTIAO:
- /* #ifdef MP-TOUTIAO */
- isMpToutiao = true;
- /* #endif */
- return isMpToutiao;
- break;
- case PLATFORMS.MP_LARK:
- /* #ifdef MP-LARK */
- isMpLark = true;
- /* #endif */
- return isMpLark;
- break;
- case PLATFORMS.MP_QQ:
- /* #ifdef MP-QQ */
- isMpQq = true;
- /* #endif */
- return isMpQq;
- break;
- case PLATFORMS.MP_KUAISHOU:
- /* #ifdef MP-KUAISHOU */
- isMpKuaishou = true;
- /* #endif */
- return isMpKuaishou;
- break;
- case PLATFORMS.MP_JD:
- /* #ifdef MP-JD */
- isMpJd = true;
- /* #endif */
- return (isMpJd = true);
- break;
- case PLATFORMS.MP_360:
- /* #ifdef MP-360 */
- isMp360 = true;
- /* #endif */
- return isMp360;
- break;
- case PLATFORMS.QUICKAPP_WEBVIEW:
- /* #ifdef QUICKAPP-WEBVIEW */
- isQuickAppWebView = true;
- /* #endif */
- return isQuickAppWebView;
- break;
- case PLATFORMS.QUICKAPP_WEBVIEW_UNION:
- /* #ifdef QUICKAPP-WEBVIEW-UNION */
- isQuickAppWebViewUnion = true;
- /* #endif */
- return isQuickAppWebViewUnion;
- break;
- case PLATFORMS.QUICKAPP_WEBVIEW_HUAWEI:
- /* #ifdef QUICKAPP-WEBVIEW-HUAWEI */
- isQuickAppWebViewHuawei = true;
- /* #endif */
- return isQuickAppWebViewHuawei;
- break;
- default:
- return false;
- }
- return false;
+ switch (target) {
+ case PLATFORMS.VUE3:
+ /* #ifdef VUE3 */
+ isVue3 = true;
+ /* #endif */
+ return isVue3;
+ case PLATFORMS.APP_PLUS:
+ /* #ifdef APP-PLUS */
+ isAppPlus = true;
+ /* #endif */
+ return isAppPlus;
+ case PLATFORMS.APP_PLUS_NVUE:
+ /* #ifdef APP-PLUS-NVUE */
+ isAppPlusNvue = true;
+ /* #endif */
+ return isAppPlusNvue;
+ case PLATFORMS.APP_NVUE:
+ /* #ifdef APP-NVUE */
+ isAppNvue = true;
+ /* #endif */
+ return isAppNvue;
+ case PLATFORMS.H5:
+ /* #ifdef H5 */
+ isH5 = true;
+ /* #endif */
+ return isH5;
+ case PLATFORMS.MP:
+ /* #ifdef MP */
+ isMp = true;
+ /* #endif */
+ return isMp;
+ case PLATFORMS.MP_WEIXIN:
+ /* #ifdef MP-WEIXIN */
+ isMpWeinxin = true;
+ /* #endif */
+ return isMpWeinxin;
+ case PLATFORMS.MP_ALIPAY:
+ /* #ifdef MP-ALIPAY */
+ isMpAlipay = true;
+ /* #endif */
+ return isMpAlipay;
+ case PLATFORMS.MP_BAIDU:
+ /* #ifdef MP_BAIDU */
+ isMpBaidu = true;
+ /* #endif */
+ return isMpBaidu;
+ case PLATFORMS.MP_TOUTIAO:
+ /* #ifdef MP-TOUTIAO */
+ isMpToutiao = true;
+ /* #endif */
+ return isMpToutiao;
+ case PLATFORMS.MP_LARK:
+ /* #ifdef MP-LARK */
+ isMpLark = true;
+ /* #endif */
+ return isMpLark;
+ case PLATFORMS.MP_QQ:
+ /* #ifdef MP-QQ */
+ isMpQq = true;
+ /* #endif */
+ return isMpQq;
+ case PLATFORMS.MP_KUAISHOU:
+ /* #ifdef MP-KUAISHOU */
+ isMpKuaishou = true;
+ /* #endif */
+ return isMpKuaishou;
+ // case PLATFORMS.MP_JD:
+ // /* #ifdef MP-JD */
+ // isMpJd = true;
+ // /* #endif */
+ // return (isMpJd = true);
+ // break;
+ case PLATFORMS.MP_360:
+ /* #ifdef MP-360 */
+ isMp360 = true;
+ /* #endif */
+ return isMp360;
+ case PLATFORMS.QUICKAPP_WEBVIEW:
+ /* #ifdef QUICKAPP-WEBVIEW */
+ isQuickAppWebView = true;
+ /* #endif */
+ return isQuickAppWebView;
+ case PLATFORMS.QUICKAPP_WEBVIEW_UNION:
+ /* #ifdef QUICKAPP-WEBVIEW-UNION */
+ isQuickAppWebViewUnion = true;
+ /* #endif */
+ return isQuickAppWebViewUnion;
+ case PLATFORMS.QUICKAPP_WEBVIEW_HUAWEI:
+ /* #ifdef QUICKAPP-WEBVIEW-HUAWEI */
+ isQuickAppWebViewHuawei = true;
+ /* #endif */
+ return isQuickAppWebViewHuawei;
+ default:
+ return false;
+ }
}
diff --git a/src/utils/router/constant.ts b/src/utils/router/constant.ts
index 4821aa7..5245a0f 100644
--- a/src/utils/router/constant.ts
+++ b/src/utils/router/constant.ts
@@ -8,12 +8,12 @@ import { useRouter } from '@/hooks/router';
* @return boolean
*/
export function isIgnoreAuth(path: string): boolean {
- const _path = filterPath(path);
- const routerStore = useRouterStore();
- const routes = routerStore.getRoutes;
- if (!routes) return false;
- const route = routes.get(_path);
- return route === undefined ? true : !!route?.meta?.ignoreAuth;
+ const _path = filterPath(path);
+ const routerStore = useRouterStore();
+ const routes = routerStore.getRoutes;
+ if (!routes) return false;
+ const route = routes.get(_path);
+ return route === undefined ? true : !!route?.meta?.ignoreAuth;
}
/**
@@ -21,10 +21,10 @@ export function isIgnoreAuth(path: string): boolean {
* @param path
*/
export function jumpLogin(path: string) {
- const _path = path.startsWith('/') ? path : `/${path}`;
- const pathQuery = encodeURIComponent(_path);
- const router = useRouter();
- router.push(`${LOGIN_PAGE}?redirect=${pathQuery}`);
+ const _path = path.startsWith('/') ? path : `/${path}`;
+ const pathQuery = encodeURIComponent(_path);
+ const router = useRouter();
+ router.push(`${LOGIN_PAGE}?redirect=${pathQuery}`);
}
/**
@@ -33,6 +33,6 @@ export function jumpLogin(path: string) {
* @param prefix
*/
export function filterPath(url: string, prefix = '') {
- const path = url.split('?')[0];
- return prefix + (path.startsWith('/') ? path.substring(1) : path);
+ const path = url.split('?')[0];
+ return prefix + (path.startsWith('/') ? path.substring(1) : path);
}
diff --git a/src/utils/router/interceptor.ts b/src/utils/router/interceptor.ts
index 49bfee8..b45f2d0 100644
--- a/src/utils/router/interceptor.ts
+++ b/src/utils/router/interceptor.ts
@@ -9,12 +9,12 @@ import { isIgnoreAuth, jumpLogin } from '@/utils/router/constant';
*/
export function routerBeforeEach(path: string): boolean {
- const isIgnore = isIgnoreAuth(path);
- if (isIgnore) return true;
- const authStore = useAuthStore();
- if (authStore.isLogin) return true;
- jumpLogin(path);
- return false;
+ const isIgnore = isIgnoreAuth(path);
+ if (isIgnore) return true;
+ const authStore = useAuthStore();
+ if (authStore.isLogin) return true;
+ jumpLogin(path);
+ return false;
}
/**
@@ -26,50 +26,50 @@ export function routerBeforeEach(path: string): boolean {
* @export void
*/
function addInterceptor(routerName: string) {
- uni.addInterceptor(routerName, {
- // 跳转前拦截
- invoke: (args) => {
- const flag = routerBeforeEach(args.url);
- return flag ? args : false;
- },
- // 成功回调拦截
- success: () => {},
- // 失败回调拦截
- fail: (err: any) => {
- let reg: RegExp;
- /* #ifdef MP-WEIXIN */
- reg = /(.*)?(fail page ")(.*)(" is not found$)/;
- /* #endif */
- /* #ifndef MP-WEIXIN */
- reg = /(.*)?(fail page `)(.*)(` is not found$)/;
- /* #endif */
- if (reg.test(err.errMsg)) {
- const go = err.errMsg.replace(reg, '$3') || '';
- uni.navigateTo({
- url: `${NOT_FOUND_PAGE}?redirect=${HOME_PAGE}&go=${go}`,
- });
- }
- return false;
- },
- // 完成回调拦截
- complete: () => {},
- });
+ uni.addInterceptor(routerName, {
+ // 跳转前拦截
+ invoke: (args) => {
+ const flag = routerBeforeEach(args.url);
+ return flag ? args : false;
+ },
+ // 成功回调拦截
+ success: () => {},
+ // 失败回调拦截
+ fail: (err: any) => {
+ let reg: RegExp;
+ /* #ifdef MP-WEIXIN */
+ reg = /(.*)?(fail page ")(.*)(" is not found$)/;
+ /* #endif */
+ /* #ifndef MP-WEIXIN */
+ reg = /(.*)?(fail page `)(.*)(` is not found$)/;
+ /* #endif */
+ if (reg.test(err.errMsg)) {
+ const go = err.errMsg.replace(reg, '$3') || '';
+ uni.navigateTo({
+ url: `${NOT_FOUND_PAGE}?redirect=${HOME_PAGE}&go=${go}`,
+ });
+ }
+ return false;
+ },
+ // 完成回调拦截
+ complete: () => {},
+ });
}
/**
* 添加路由拦截器
*/
export function routerInterceptor() {
- NAVIGATE_TYPE_LIST.forEach((item) => {
- addInterceptor(item);
- });
+ NAVIGATE_TYPE_LIST.forEach((item) => {
+ addInterceptor(item);
+ });
}
/**
* 移除路由拦截器
*/
export function routerRemoveInterceptor() {
- NAVIGATE_TYPE_LIST.forEach((item) => {
- uni.removeInterceptor(item);
- });
+ NAVIGATE_TYPE_LIST.forEach((item) => {
+ uni.removeInterceptor(item);
+ });
}
diff --git a/src/utils/router/navigates.ts b/src/utils/router/navigates.ts
index 360fcf1..eca56b1 100644
--- a/src/utils/router/navigates.ts
+++ b/src/utils/router/navigates.ts
@@ -7,117 +7,117 @@ import { useRouterStore } from '@/state/modules/router';
import { filterPath } from '@/utils/router/constant';
export type NavigateOptions = Partial> & {
- delta?: number;
+ delta?: number;
};
export class Navigates {
- private type: string;
+ private type: string;
- private readonly options: NavigateOptions;
+ private readonly options: NavigateOptions;
- constructor(type?: string, options?: NavigateOptions) {
- this.type = type || NAVIGATE_TYPE.NAVIGATE_TO;
- this.options = options || {};
- }
+ constructor(type?: string, options?: NavigateOptions) {
+ this.type = type || NAVIGATE_TYPE.NAVIGATE_TO;
+ this.options = options || {};
+ }
- navigate(url: string, options?: NavigateOptions) {
- const navigateOptions = deepMerge(cloneDeep(this.options), options);
- const _options = deepMerge({ url }, navigateOptions);
- switch (this.type) {
- case NAVIGATE_TYPE.NAVIGATE_TO:
- uni.navigateTo(_options);
- break;
- case NAVIGATE_TYPE.REDIRECT_TO:
- uni.redirectTo(_options);
- break;
- case NAVIGATE_TYPE.RE_LAUNCH:
- uni.reLaunch(_options);
- break;
- case NAVIGATE_TYPE.SWITCH_TAB:
- uni.switchTab(_options);
- break;
- case NAVIGATE_TYPE.NAVIGATE_BACK:
- uni.navigateBack(navigateOptions);
- break;
- default:
- warn('navigate Error');
- break;
- }
- }
+ navigate(url: string, options?: NavigateOptions) {
+ const navigateOptions = deepMerge(cloneDeep(this.options), options);
+ const _options = deepMerge({ url }, navigateOptions);
+ switch (this.type) {
+ case NAVIGATE_TYPE.NAVIGATE_TO:
+ uni.navigateTo(_options);
+ break;
+ case NAVIGATE_TYPE.REDIRECT_TO:
+ uni.redirectTo(_options);
+ break;
+ case NAVIGATE_TYPE.RE_LAUNCH:
+ uni.reLaunch(_options);
+ break;
+ case NAVIGATE_TYPE.SWITCH_TAB:
+ uni.switchTab(_options);
+ break;
+ case NAVIGATE_TYPE.NAVIGATE_BACK:
+ uni.navigateBack(navigateOptions);
+ break;
+ default:
+ warn('navigate Error');
+ break;
+ }
+ }
- /**
- * uni.navigateTo
- * @param url
- * @param options
- */
- push(url: string, options?: NavigateOptions) {
- this.type = NAVIGATE_TYPE.NAVIGATE_TO;
- this.navigate(url, options);
- }
+ /**
+ * uni.navigateTo
+ * @param url
+ * @param options
+ */
+ push(url: string, options?: NavigateOptions) {
+ this.type = NAVIGATE_TYPE.NAVIGATE_TO;
+ this.navigate(url, options);
+ }
- /**
- * uni.redirectTo
- * @param url
- * @param options
- */
- replace(url: string, options?: NavigateOptions) {
- this.type = NAVIGATE_TYPE.REDIRECT_TO;
- this.navigate(url, options);
- }
+ /**
+ * uni.redirectTo
+ * @param url
+ * @param options
+ */
+ replace(url: string, options?: NavigateOptions) {
+ this.type = NAVIGATE_TYPE.REDIRECT_TO;
+ this.navigate(url, options);
+ }
- /**
- * uni.reLaunch
- * @param url
- * @param options
- */
- replaceAll(url: string, options?: NavigateOptions) {
- this.type = NAVIGATE_TYPE.RE_LAUNCH;
- this.navigate(url, options);
- }
+ /**
+ * uni.reLaunch
+ * @param url
+ * @param options
+ */
+ replaceAll(url: string, options?: NavigateOptions) {
+ this.type = NAVIGATE_TYPE.RE_LAUNCH;
+ this.navigate(url, options);
+ }
- /**
- * uni.switchTab
- * @param url
- * @param options
- */
- pushTab(url: string, options?: NavigateOptions) {
- // 微信小程序端uni.switchTab拦截无效处理
- /* #ifdef MP-WEIXIN */
- if (!routerBeforeEach(url)) {
- return;
- }
- /* #endif */
- this.type = NAVIGATE_TYPE.SWITCH_TAB;
- this.navigate(url, options);
- }
+ /**
+ * uni.switchTab
+ * @param url
+ * @param options
+ */
+ pushTab(url: string, options?: NavigateOptions) {
+ // 微信小程序端uni.switchTab拦截无效处理
+ /* #ifdef MP-WEIXIN */
+ if (!routerBeforeEach(url)) {
+ return;
+ }
+ /* #endif */
+ this.type = NAVIGATE_TYPE.SWITCH_TAB;
+ this.navigate(url, options);
+ }
- /**
- * uni.navigateBack
- * @param options
- */
- back(options?: NavigateOptions) {
- this.type = NAVIGATE_TYPE.NAVIGATE_BACK;
- this.navigate('', options);
- }
+ /**
+ * uni.navigateBack
+ * @param options
+ */
+ back(options?: NavigateOptions) {
+ this.type = NAVIGATE_TYPE.NAVIGATE_BACK;
+ this.navigate('', options);
+ }
- /**
- * 自动判断跳转页面 (navigateTo|switchTab)
- * @param url
- * @param options
- */
- go(url: string, options?: NavigateOptions & { replace?: boolean }) {
- const path = filterPath(url);
- const routerStore = useRouterStore();
- const routes = routerStore.getRoutes;
- const route = routes?.get(path);
- if (route?.meta?.tabBar) {
- this.pushTab(url, options);
- return;
- }
- if (options?.replace) {
- this.replace(url, options);
- return;
- }
- this.push(url, options);
- }
+ /**
+ * 自动判断跳转页面 (navigateTo|switchTab)
+ * @param url
+ * @param options
+ */
+ go(url: string, options?: NavigateOptions & { replace?: boolean }) {
+ const path = filterPath(url);
+ const routerStore = useRouterStore();
+ const routes = routerStore.getRoutes;
+ const route = routes?.get(path);
+ if (route?.meta?.tabBar) {
+ this.pushTab(url, options);
+ return;
+ }
+ if (options?.replace) {
+ this.replace(url, options);
+ return;
+ }
+ this.push(url, options);
+ }
}
diff --git a/src/utils/router/routes.ts b/src/utils/router/routes.ts
index 77ebd61..5aa2468 100644
--- a/src/utils/router/routes.ts
+++ b/src/utils/router/routes.ts
@@ -8,34 +8,34 @@ const { pages, subPackages, tabBar } = pagesJson;
const pagesMap = new Map();
pages.forEach((page) => {
- pagesMap.set(page.path, page as Route);
+ pagesMap.set(page.path, page as Route);
});
if (Array.isArray(subPackages) && subPackages.length) {
- subPackages.forEach((el) => {
- const rootPath = el.root;
- el.pages.forEach((page) => {
- page.path = `${rootPath}/${page.path}`;
- pagesMap.set(page.path, page as Route);
- });
- });
+ subPackages.forEach((el) => {
+ const rootPath = el.root;
+ el.pages.forEach((page) => {
+ page.path = `${rootPath}/${page.path}`;
+ pagesMap.set(page.path, page as Route);
+ });
+ });
}
if (tabBar) {
- const tabBarList = tabBar.list;
- if (Array.isArray(tabBarList)) {
- tabBarList.forEach((el) => {
- if (pagesMap.has(el.pagePath)) {
- const page = pagesMap.get(el.pagePath);
- const meta = page?.meta || {};
- // @ts-ignore
- meta.tabBar = true;
- // @ts-ignore
- page.meta = assign({}, meta);
- pagesMap.set(el.pagePath, page as Route);
- }
- });
- }
+ const tabBarList = tabBar.list;
+ if (Array.isArray(tabBarList)) {
+ tabBarList.forEach((el) => {
+ if (pagesMap.has(el.pagePath)) {
+ const page = pagesMap.get(el.pagePath);
+ const meta = page?.meta || {};
+ // @ts-ignore
+ meta.tabBar = true;
+ // @ts-ignore
+ page.meta = assign({}, meta);
+ pagesMap.set(el.pagePath, page as Route);
+ }
+ });
+ }
}
export { pagesMap };
diff --git a/src/utils/uniapi/index.ts b/src/utils/uniapi/index.ts
index ee1a667..dfcae41 100644
--- a/src/utils/uniapi/index.ts
+++ b/src/utils/uniapi/index.ts
@@ -5,41 +5,41 @@
* @constructor
*/
export const SetClipboardData = (data: string, showToast = true) =>
- new Promise((resolve, reject) => {
- uni.setClipboardData({
- data,
- showToast,
- success: (res) => {
- resolve(res);
- },
- fail: (err) => {
- reject(err);
- },
- });
- });
+ new Promise((resolve, reject) => {
+ uni.setClipboardData({
+ data,
+ showToast,
+ success: (res) => {
+ resolve(res);
+ },
+ fail: (err) => {
+ reject(err);
+ },
+ });
+ });
/**
* @description 获取系统剪贴板内容
* @constructor
*/
export const GetClipboardData = () =>
- new Promise((resolve, reject) => {
- uni.getClipboardData({
- success: (res) => {
- resolve(res);
- },
- fail: (err) => {
- reject(err);
- },
- });
- });
+ new Promise((resolve, reject) => {
+ uni.getClipboardData({
+ success: (res) => {
+ resolve(res);
+ },
+ fail: (err) => {
+ reject(err);
+ },
+ });
+ });
/**
* rpx 换算为 px
* @param upx
*/
export const rpx2px = (upx: number) => {
- return uni.upx2px(upx);
+ return uni.upx2px(upx);
};
/**
@@ -47,5 +47,5 @@ export const rpx2px = (upx: number) => {
* @param upx
*/
export const px2rpx = (px: number) => {
- return px / (uni.upx2px(100) / 100);
+ return px / (uni.upx2px(100) / 100);
};
diff --git a/src/utils/uniapi/prompt.ts b/src/utils/uniapi/prompt.ts
index 9ece681..6b129fc 100644
--- a/src/utils/uniapi/prompt.ts
+++ b/src/utils/uniapi/prompt.ts
@@ -10,20 +10,20 @@
* @constructor
*/
export function Toast(title: string, options?: Partial) {
- uni.showToast({
- title,
- duration: 1500,
- icon: 'none',
- mask: true,
- ...options,
- });
+ uni.showToast({
+ title,
+ duration: 1500,
+ icon: 'none',
+ mask: true,
+ ...options,
+ });
}
/**
* 隐藏消息提示框
*/
export function HideToast() {
- uni.hideToast();
+ uni.hideToast();
}
/**
@@ -33,18 +33,18 @@ export function HideToast() {
* @constructor
*/
export function Loading(title: string, options?: Partial) {
- uni.showLoading({
- title,
- mask: true,
- ...options,
- });
+ uni.showLoading({
+ title,
+ mask: true,
+ ...options,
+ });
}
/**
* 隐藏 loading 提示框
*/
export function HideLoading() {
- uni.hideLoading();
+ uni.hideLoading();
}
/**
@@ -53,17 +53,17 @@ export function HideLoading() {
* @constructor
*/
export function Modal(options: UniApp.ShowModalOptions) {
- return new Promise((resolve, reject) => {
- uni.showModal({
- ...options,
- success: (res) => {
- resolve(res);
- },
- fail: (res) => {
- reject(res);
- },
- });
- });
+ return new Promise((resolve, reject) => {
+ uni.showModal({
+ ...options,
+ success: (res) => {
+ resolve(res);
+ },
+ fail: (res) => {
+ reject(res);
+ },
+ });
+ });
}
/**
@@ -72,15 +72,15 @@ export function Modal(options: UniApp.ShowModalOptions) {
* @constructor
*/
export function ActionSheet(options: UniApp.ShowActionSheetOptions) {
- return new Promise((resolve, reject) => {
- uni.showActionSheet({
- ...options,
- success: (res) => {
- resolve(res);
- },
- fail: (res) => {
- reject(res);
- },
- });
- });
+ return new Promise((resolve, reject) => {
+ uni.showActionSheet({
+ ...options,
+ success: (res) => {
+ resolve(res);
+ },
+ fail: (res) => {
+ reject(res);
+ },
+ });
+ });
}
diff --git a/tsconfig.json b/tsconfig.json
index 1092940..aee314d 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -1,54 +1,25 @@
{
- /* 根选项 */
- "include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"], // 指定被编译文件所在的目录
- "exclude": [], // 指定不需要被编译的目录
- //使用小技巧:在填写路径时 ** 表示任意目录, * 表示任意文件。
-
- /* 项目选项 */
- "compilerOptions": {
- "target": "esnext", // 目标语言的版本
- "useDefineForClassFields": true, //发出符合ecmascript标准的类字段
- "module": "esnext", // 生成代码的模板标准
- "moduleResolution": "node", //指定TypeScript如何从给定的模块说明符中查找文件
- "jsx": "preserve", //指定生成什么JSX代码。
- "sourceMap": true, //为发出的JavaScript文件创建源映射文件。
- "esModuleInterop": true, // 允许export=导出,由import from 导入
- "lib": ["esnext", "dom"], // TS需要引用的库
- "types": ["@dcloudio/types"],
- // "allowJs": true, // 允许编译器编译JS,JSX文件
- // "checkJs": false, // 允许在JS文件中报错,通常与allowJS一起使用
- "removeComments": true, // 删除注释
- "paths": {
- "@/*": ["./src/*"]
- }, //指定一组条目,它们将导入重新映射到其他查找位置。
-
- /* 严格检查选项 */
- "strict": true, // 开启所有严格的类型检查
- "alwaysStrict": true, // 在代码中注入'use strict'
- "noImplicitAny": true, // 不允许隐式的any类型
- "noImplicitThis": true, // 不允许this有隐式的any类型
- "strictNullChecks": true, // 在进行类型检查时,请考虑null和undefined。
- "strictBindCallApply": true, // 检查bind、call和apply方法的参数是否与原始函数匹配。
- "strictFunctionTypes": true, // 在给函数赋值时,要确保参数和返回值是子类型兼容的。
- "strictPropertyInitialization": true, // 类的实例属性必须初始化
-
- /* 额外检查 */
- "noUnusedLocals": true, //是否检查未使用的局部变量
- "noUnusedParameters": true, //是否检查未使用的参数
- "noImplicitReturns": true, //检查函数是否不含有隐式返回值
- "noImplicitOverride": true, //是否检查子类继承自基类时,其重载的函数命名与基类的函数不同步问题
- "noFallthroughCasesInSwitch": true, //检查switch中是否含有case没有使用break跳出
- "noUncheckedIndexedAccess": true, //是否通过索引签名来描述对象上有未知键但已知值的对象
- "noPropertyAccessFromIndexSignature": false, //是否通过" . “(obj.key) 语法访问字段和"索引”( obj[“key”]), 以及在类型中声明属性的方式之间的一致性
-
- /* 实验选项 */
- "experimentalDecorators": true, //是否启用对装饰器的实验性支持,装饰器是一种语言特性,还没有完全被 JavaScript 规范批准
- "emitDecoratorMetadata": true, //为装饰器启用对发出类型元数据的实验性支持
-
- /* 高级选项 */
- "forceConsistentCasingInFileNames": true, //是否区分文件系统大小写规则
- "extendedDiagnostics": false, //是否查看 TS 在编译时花费的时间
- "noEmitOnError": true, //有错误时不进行编译
- "resolveJsonModule": true //是否解析 JSON 模块
- }
+ "compilerOptions": {
+ "target": "ESNext", // 目标语言的版本
+ "useDefineForClassFields": true, //发出符合ECMAScript标准的类字段
+ "module": "ESNext", // 生成代码的模板标准
+ "moduleResolution": "Node", //指定TypeScript如何从给定的模块说明符中查找文件
+ "strict": true, // 开启所有严格的类型检查
+ "jsx": "preserve", //指定生成什么JSX代码。
+ "resolveJsonModule": true, //是否解析 JSON 模块
+ "isolatedModules": true, // 确保每个文件都可以安全地转译,而不依赖于其他导入。
+ "esModuleInterop": true, // 发出额外的JavaScript以简化对导入Common/S模块的支持。这使得allowsyntheticdefaulultimports类型兼容。
+ "removeComments": true, // 删除注释
+ "types": ["@dcloudio/types"],
+ "paths": { "@/*": ["./src/*"] }, //指定一组条目,它们将导入重新映射到其他查找位置。
+ "lib": ["ESNext", "DOM"], // TS需要引用的库
+ "skipLibCheck": true, // 跳过所有.d.ts文件的类型检查
+ "noEmit": true, // 从编译中禁用发射文件。
+ "noEmitOnError": true, //有错误时不进行编译
+ "forceConsistentCasingInFileNames": true, //是否区分文件系统大小写规则
+ "experimentalDecorators": true, //是否启用对装饰器的实验性支持,装饰器是一种语言特性,还没有完全被 JavaScript 规范批准
+ "emitDecoratorMetadata": true //为装饰器启用对发出类型元数据的实验性支持
+ },
+ "include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"],
+ "references": [{ "path": "./tsconfig.node.json" }] // 引用的项目。要求TypeScript 3.0或更高版本。
}
diff --git a/tsconfig.node.json b/tsconfig.node.json
new file mode 100644
index 0000000..1a7ab1b
--- /dev/null
+++ b/tsconfig.node.json
@@ -0,0 +1,9 @@
+{
+ "compilerOptions": {
+ "composite": true,
+ "module": "ESNext",
+ "moduleResolution": "Node",
+ "allowSyntheticDefaultImports": true
+ },
+ "include": ["vite.config.*", "vitest.config.*", "cypress.config.*", "playwright.config.*"]
+}
diff --git a/unocss.config.js b/unocss.config.js
index 5a8c9b9..8e8f3f3 100644
--- a/unocss.config.js
+++ b/unocss.config.js
@@ -6,61 +6,58 @@
import { defineConfig, presetIcons } from 'unocss';
import presetWeapp from 'unocss-preset-weapp';
-import {
- transformerAttributify,
- transformerClass,
-} from 'unocss-preset-weapp/transformer';
+import { transformerAttributify, transformerClass } from 'unocss-preset-weapp/transformer';
const transformRules = {
- '.': '-d111-',
- '/': '-s111-',
- ':': '-c111-',
- '%': '-p111-',
- '!': '-e111-',
- '#': '-w111-',
- '(': '-b111l-',
- ')': '-b111r-',
- '[': '-f111l-',
- ']': '-f111r-',
- $: '-r111-',
- ',': '-r222-',
+ '.': '-d111-',
+ '/': '-s111-',
+ ':': '-c111-',
+ '%': '-p111-',
+ '!': '-e111-',
+ '#': '-w111-',
+ '(': '-b111l-',
+ ')': '-b111r-',
+ '[': '-f111l-',
+ ']': '-f111r-',
+ $: '-r111-',
+ ',': '-r222-',
};
const prefix = `_u_`;
export default defineConfig({
- presets: [
- // https://github.com/MellowCo/unocss-preset-weapp
- presetWeapp({
- nonValuedAttribute: true,
- prefix: prefix,
- whRpx: true,
- transform: true,
- platform: 'uniapp',
- transformRules,
- }),
- presetIcons({
- scale: 1.2,
- warn: true,
- }),
- ],
- shortcuts: [
- {
- 'border-base': 'border border-gray-500_10',
- '_u_z-tar-both': '_u_z-988',
- '_u_head-fixed': '_u_fixed _u_top-0 _u_left-0 _u_w-full _u_z-tar-both',
- _u_center: '_u_flex _u_justify-center _u_items-center',
- },
- ],
- theme: {},
- transformers: [
- transformerAttributify({
- classPrefix: prefix,
- transformRules,
- nonValuedAttribute: true,
- }),
- transformerClass({
- transformRules,
- }),
- ],
+ presets: [
+ // https://github.com/MellowCo/unocss-preset-weapp
+ presetWeapp({
+ nonValuedAttribute: true,
+ prefix: prefix,
+ whRpx: true,
+ transform: true,
+ platform: 'uniapp',
+ transformRules,
+ }),
+ presetIcons({
+ scale: 1.2,
+ warn: true,
+ }),
+ ],
+ shortcuts: [
+ {
+ 'border-base': 'border border-gray-500_10',
+ '_u_z-tar-both': '_u_z-988',
+ '_u_head-fixed': '_u_fixed _u_top-0 _u_left-0 _u_w-full _u_z-tar-both',
+ _u_center: '_u_flex _u_justify-center _u_items-center',
+ },
+ ],
+ theme: {},
+ transformers: [
+ transformerAttributify({
+ classPrefix: prefix,
+ transformRules,
+ nonValuedAttribute: true,
+ }),
+ transformerClass({
+ transformRules,
+ }),
+ ],
});
diff --git a/vite.config.ts b/vite.config.ts
index 1b4c409..6d17f3f 100644
--- a/vite.config.ts
+++ b/vite.config.ts
@@ -1,99 +1,61 @@
-import { ConfigEnv, UserConfig } from 'vite';
-import uni from '@dcloudio/vite-plugin-uni';
-import eslintPlugin from 'vite-plugin-eslint';
+// Vite中文网:https://vitejs.cn/config/
+import { ConfigEnv, loadEnv, UserConfig } from 'vite';
import { resolve } from 'path';
-import { loadEnv } from 'vite';
+import uni from '@dcloudio/vite-plugin-uni';
import Unocss from 'unocss/vite';
-//发布时动态修改 manifest.json
-// if (process.env.NODE_ENV === 'production') {
-// // 读取 manifest.json ,修改后重新写入
-// const fs = require('fs');
-// const manifestPath = './src/manifest.json';
-// let Manifest = fs.readFileSync(manifestPath, { encoding: 'utf-8' });
-// function replaceManifest(path: string, value: any) {
-// const arr = path.split('.');
-// const len = arr.length;
-// const lastItem = arr[len - 1];
-
-// let i = 0;
-// let ManifestArr = Manifest.split(/\n/);
-
-// for (let index = 0; index < ManifestArr.length; index++) {
-// const item = ManifestArr[index];
-// if (new RegExp(`"${arr[i]}"`).test(item)) ++i;
-// if (i === len) {
-// const hasComma = /,/.test(item);
-// ManifestArr[index] = item.replace(new RegExp(`"${lastItem}"[\\s\\S]*:[\\s\\S]*`), `"${lastItem}": ${value}${hasComma ? ',' : ''}`);
-// break;
-// }
-// }
-
-// Manifest = ManifestArr.join('\n');
-// }
-// let Data1 = new Date().toLocaleDateString();
-// let Data2 = new Date().toLocaleTimeString();
-// let Data_ = Data1.replace(/\//g, '-') + ' ' + Data2;
-// // 使用
-// replaceManifest('description', JSON.stringify(`app平台-${Data_}`));
-// replaceManifest(
-// 'versionName',
-// JSON.stringify(
-// String(Number(JSON.parse(Manifest).versionCode) + 1)
-// .split('')
-// .join('.')
-// )
-// );
-// replaceManifest('versionCode', JSON.stringify(String(Number(JSON.parse(Manifest).versionCode) + 1)));
-// fs.writeFileSync(manifestPath, Manifest, { flag: 'w' });
-// }
-
-// https://vitejs.cn/config/
export default ({ mode }: ConfigEnv): UserConfig => {
- const root = process.cwd();
- const env = loadEnv(mode, root);
- return {
- base: './',
- resolve: {
- alias: {
- '@': resolve('./src'),
- },
- },
- define: {
- 'process.env': {},
- },
- server: {
- host: true,
- // open: true,
- port: env.VITE_PORT as any,
- proxy: {
- '/api': {
- target: env.VITE_BASE_URL,
- changeOrigin: true,
- rewrite: (path) => path.replace(/^\/api/, ''),
- },
- '/upload': {
- target: env.VITE_BASE_URL,
- changeOrigin: true,
- rewrite: (path) => path.replace(/^\/upload/, ''),
- },
- },
- },
- plugins: [
- uni(),
- Unocss(),
- // eslintPlugin({
- // include: ['src/**/*.js', 'src/**/*.vue', 'src/**/*.ts'],
- // exclude: ['./node_modules/**'],
- // cache: false,
- // }),
- ],
- css: {
- preprocessorOptions: {
- scss: {
- // additionalData: '@import "@/assets/style/main.scss";',
- },
- },
- },
- };
+ const root = process.cwd();
+ const env = loadEnv(mode, root);
+ return {
+ base: './',
+ // 设置路径别名
+ resolve: {
+ alias: {
+ '@': resolve('./src'),
+ },
+ extensions: ['.js', '.json', '.ts', '.vue'], // 使用路径别名时想要省略的后缀名,可以自己 增减
+ },
+ // 自定义全局变量
+ define: {
+ 'process.env': {},
+ },
+ // 开发服务器配置
+ server: {
+ host: true,
+ // open: true,
+ port: env.VITE_PORT as any,
+ proxy: {
+ '/api': {
+ target: env.VITE_BASE_URL,
+ changeOrigin: true,
+ rewrite: (path) => path.replace(/^\/api/, ''),
+ },
+ '/upload': {
+ target: env.VITE_BASE_URL,
+ changeOrigin: true,
+ rewrite: (path) => path.replace(/^\/upload/, ''),
+ },
+ },
+ },
+ // 构建配置
+ build: {
+ outDir: 'dist',
+ chunkSizeWarningLimit: 1500,
+ rollupOptions: {
+ output: {
+ entryFileNames: `assets/[name].${new Date().getTime()}.js`,
+ chunkFileNames: `assets/[name].${new Date().getTime()}.js`,
+ assetFileNames: `assets/[name].${new Date().getTime()}.[ext]`,
+ compact: true,
+ // manualChunks: {
+ // vue: ['vue', 'vue-router', 'vuex'],
+ // echarts: ['echarts'],
+ // },
+ },
+ },
+ },
+ // 插件
+ plugins: [uni(), Unocss()],
+ };
};