mirror of
https://github.com/XiaoDaiGua-Ray/ray-template.git
synced 2025-10-08 00:05:31 +08:00
Compare commits
164 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
49af61a339 | ||
|
4bce5f7713 | ||
|
34c20d4be7 | ||
|
c28c353f7d | ||
|
c68491fca9 | ||
|
0f2193cc14 | ||
|
ba6ceef0dc | ||
|
5e9ffb14a3 | ||
|
eb5a6aa9e2 | ||
|
674539edd3 | ||
|
ff0bcb5022 | ||
|
d3d98190a3 | ||
|
0bb707bba0 | ||
|
4bfdbccd88 | ||
|
3b2bba391e | ||
|
7647508935 | ||
|
852d7ca90a | ||
|
2c84e3ce4c | ||
|
83e0c19ba9 | ||
|
ff1a67c843 | ||
|
8f3969268a | ||
|
7783872ef6 | ||
|
707300774d | ||
|
2f42571b3b | ||
|
73792144a8 | ||
|
11cbf8bca3 | ||
|
f9473114e7 | ||
|
7394e0bf30 | ||
|
d12fcd18b6 | ||
|
60ed09a0c5 | ||
|
fa8d52601f | ||
|
3f7e3722fd | ||
|
ab6593f022 | ||
|
d306ac8804 | ||
|
8405cc5709 | ||
|
6975af2368 | ||
|
b0cd545c99 | ||
|
7ca9663cb1 | ||
|
85f0d43d7e | ||
|
09315473a3 | ||
|
52dc6038da | ||
|
27db2293f3 | ||
|
5b035815eb | ||
|
b06006b442 | ||
|
557ab0467a | ||
|
e5c16b3497 | ||
|
f97b25e626 | ||
|
8097296f8f | ||
|
43df660ab6 | ||
|
4e14f6a02d | ||
|
472518af99 | ||
|
d9ea6cbdf5 | ||
|
01287743e7 | ||
|
41dce4920f | ||
|
1ee3ce0500 | ||
|
ae67b7b8b9 | ||
|
87d0a7a4af | ||
|
683367cfd8 | ||
|
a6f7843ff9 | ||
|
e95c06b009 | ||
|
85f7f28dc4 | ||
|
7c429338d4 | ||
|
a0f7763778 | ||
|
03628890cb | ||
|
3e36144cf9 | ||
|
5c52f2f88c | ||
|
bed8432cda | ||
|
c21df42187 | ||
|
3bf297d81c | ||
|
70eee28aa8 | ||
|
e20dbb4cd2 | ||
|
f28e343e6c | ||
|
8db423a018 | ||
|
0c1842cbbd | ||
|
9a4e2e723d | ||
|
3fa9478ee4 | ||
|
25599cea24 | ||
|
a00e3ca557 | ||
|
8ced024a94 | ||
|
af1eeac035 | ||
|
cc0577eb8f | ||
|
bb61081ddd | ||
|
a3341450f1 | ||
|
b97e2ee701 | ||
|
b41d0490ca | ||
|
43bf252d84 | ||
|
8c1e215013 | ||
|
79056e8846 | ||
|
5660530d8a | ||
|
57ed469543 | ||
|
c2041b2bb6 | ||
|
77a4fcb9a2 | ||
|
f60a107997 | ||
|
17e60fdf51 | ||
|
f663cf5b41 | ||
|
740d415a3f | ||
|
8b56327eaa | ||
|
9d38f99af2 | ||
|
d98a42380d | ||
|
f5ae01f33a | ||
|
c1205d9912 | ||
|
ade9a03f1e | ||
|
45be191112 | ||
|
8a6f983bf3 | ||
|
7d8b1b123f | ||
|
6649579a0c | ||
|
0b4a0cc237 | ||
|
0c9105b54e | ||
|
7c51a5c78f | ||
|
49fc22d601 | ||
|
66cf689d70 | ||
|
e7733fa105 | ||
|
c67f5d6734 | ||
|
e9caa52401 | ||
|
998b07cdd7 | ||
|
fdff8c7fe7 | ||
|
89618e402f | ||
|
30e6d6dddb | ||
|
2c24ae5d94 | ||
|
5299a0245f | ||
|
c304f37146 | ||
|
f272832a8c | ||
|
9e3cbac091 | ||
|
429e51fc30 | ||
|
cda4216493 | ||
|
38069b5b8c | ||
|
e76723adb6 | ||
|
3767861fe4 | ||
|
416fbd7990 | ||
|
23e80137b7 | ||
|
e521b7643c | ||
|
b1dfa53d7f | ||
|
6c389eb496 | ||
|
94f975eaff | ||
|
335e456688 | ||
|
711be2006b | ||
|
9168cd876e | ||
|
aff8437089 | ||
|
04daa39e49 | ||
|
32183d0ab9 | ||
|
f7887989f9 | ||
|
36d646d8ba | ||
|
a840693455 | ||
|
f6c343911e | ||
|
b05edfeaeb | ||
|
9e3f199d21 | ||
|
e81bb3f9a5 | ||
|
1f2ae05ca4 | ||
|
d698db587f | ||
|
0c7adb9584 | ||
|
fac9f9413d | ||
|
3fb016513b | ||
|
43be9bc3f2 | ||
|
a82b28fb93 | ||
|
353bc7d809 | ||
|
5e0c85c7f5 | ||
|
7a96b58541 | ||
|
4960eb8175 | ||
|
4d4d5451dc | ||
|
405e62c762 | ||
|
d2773d62bc | ||
|
4331b6a3b1 | ||
|
6acc80f18a | ||
|
689813f1a0 |
5
.dockerignore
Normal file
5
.dockerignore
Normal file
@ -0,0 +1,5 @@
|
||||
node_modules
|
||||
.git
|
||||
.gitignore
|
||||
*.md
|
||||
dist
|
@ -1,6 +1,4 @@
|
||||
#生产环境
|
||||
NODE_ENV = 'production'
|
||||
|
||||
VITE_APP_URL = '/'
|
||||
|
||||
# office 服务代理地址
|
||||
|
@ -1,18 +0,0 @@
|
||||
dist/*
|
||||
node_modules/*
|
||||
auto-imports.d.ts
|
||||
components.d.ts
|
||||
.gitignore
|
||||
.vscode
|
||||
public
|
||||
yarn.*
|
||||
vite-env.*
|
||||
.prettierrc.*
|
||||
visualizer.*
|
||||
visualizer.html
|
||||
.env.*
|
||||
src/locales/lang
|
||||
.depcheckrc
|
||||
src/components/RayChart/theme
|
||||
*.md
|
||||
src/icons/*.svg
|
196
.eslintrc.cjs
196
.eslintrc.cjs
@ -1,196 +0,0 @@
|
||||
/* eslint-env node */
|
||||
module.exports = {
|
||||
root: true,
|
||||
env: {
|
||||
browser: true,
|
||||
node: true,
|
||||
},
|
||||
ignorePatterns: ['node_modules/', 'dist/'],
|
||||
extends: [
|
||||
'eslint-config-prettier',
|
||||
'eslint:recommended',
|
||||
'plugin:@typescript-eslint/recommended',
|
||||
'plugin:vue/vue3-recommended',
|
||||
'plugin:vue/vue3-essential',
|
||||
'plugin:prettier/recommended',
|
||||
'prettier',
|
||||
'./unplugin/.eslintrc-auto-import.json',
|
||||
],
|
||||
parser: 'vue-eslint-parser',
|
||||
parserOptions: {
|
||||
ecmaVersion: 2020,
|
||||
sourceType: 'module',
|
||||
parser: '@typescript-eslint/parser',
|
||||
ecmaFeatures: {
|
||||
jsx: true,
|
||||
tsx: true,
|
||||
},
|
||||
},
|
||||
plugins: ['vue', '@typescript-eslint', 'prettier'],
|
||||
globals: {
|
||||
defineProps: 'readonly',
|
||||
defineEmits: 'readonly',
|
||||
defineExpose: 'readonly',
|
||||
withDefaults: 'readonly',
|
||||
defineOptions: 'readonly',
|
||||
},
|
||||
rules: {
|
||||
'linebreak-style': ['error', 'unix'],
|
||||
'@typescript-eslint/no-explicit-any': [
|
||||
'error',
|
||||
{
|
||||
ignoreRestArgs: true,
|
||||
},
|
||||
],
|
||||
'prettier/prettier': 'error',
|
||||
'no-unused-vars': 'off',
|
||||
'@typescript-eslint/no-unused-vars': 'off',
|
||||
'@typescript-eslint/ban-types': 'off',
|
||||
'@typescript-eslint/explicit-module-boundary-types': 'off',
|
||||
'@typescript-eslint/no-var-requires': 'off',
|
||||
'@typescript-eslint/no-non-null-assertion': 'off',
|
||||
'@typescript-eslint/no-non-null-asserted-optional-chain': 'off',
|
||||
'@typescript-eslint/consistent-type-imports': [
|
||||
'error',
|
||||
{ disallowTypeAnnotations: false },
|
||||
], // 强制导入类型显示标注 `import type xxx from 'xxx'`
|
||||
'@typescript-eslint/no-empty-interface': [
|
||||
'error',
|
||||
{
|
||||
allowSingleExtends: true,
|
||||
},
|
||||
],
|
||||
'accessor-pairs': 2, // 强制同时存在 `get` 与 `set`
|
||||
'constructor-super': 0, // 强制子类构造函数中使用 `super` 调用父类的构造函数
|
||||
'default-case': 2, // `switch` 中强制含有 `default`
|
||||
eqeqeq: [2, 'allow-null'], // 强制使用严格判断 `===`
|
||||
'no-alert': 0, // 禁止使用 `alert`、`confirm`
|
||||
'no-array-constructor': 2, // 禁止使用数组构造器
|
||||
'no-bitwise': 0, // 禁止使用按位运算符
|
||||
'no-caller': 1, // 禁止使用 `arguments.caller`、`arguments.callee`
|
||||
'no-catch-shadow': 2, // 禁止 `catch` 子句参数与外部作用域变量同名
|
||||
'no-class-assign': 2, // 禁止给类赋值
|
||||
'no-cond-assign': 2, // 禁止在条件表达式中使用赋值语句
|
||||
'no-const-assign': 2, // 禁止修改 `const` 声明的变量
|
||||
'no-constant-condition': 2, // 禁止在条件中使用常量表达式 `if(true)`、`if(1)`
|
||||
'no-dupe-keys': 2, // 在创建对象字面量时不允许 `key` 重复
|
||||
'no-dupe-args': 2, // 函数参数不能重复
|
||||
'no-duplicate-case': 2, // `switch` 中的 `case` 标签不能重复
|
||||
'no-eval': 1, // 禁止使用 `eval`
|
||||
'no-ex-assign': 2, // 禁止给 `catch` 语句中的异常参数赋值
|
||||
'no-extend-native': 2, // 禁止扩展 `native` 对象
|
||||
'no-extra-bind': 2, // 禁止不必要的函数绑定
|
||||
'no-extra-boolean-cast': [
|
||||
'error',
|
||||
{
|
||||
enforceForLogicalOperands: true,
|
||||
},
|
||||
], // 禁止不必要的 `bool` 转换
|
||||
'no-extra-parens': 0, // 禁止非必要的括号
|
||||
semi: ['error', 'never', { beforeStatementContinuationChars: 'always' }],
|
||||
'no-fallthrough': 1, // 禁止 `switch` 穿透
|
||||
'no-func-assign': 2, // 禁止重复的函数声明
|
||||
'no-implicit-coercion': [
|
||||
'error',
|
||||
{
|
||||
allow: ['!!', '~'],
|
||||
},
|
||||
], // 禁止隐式转换
|
||||
'no-implied-eval': 2, // 禁止使用隐式 `eval`
|
||||
'no-invalid-regexp': 2, // 禁止无效的正则表达式
|
||||
'no-invalid-this': 2, // 禁止无效的 `this`
|
||||
'no-irregular-whitespace': 2, // 禁止含有不合法空格
|
||||
'no-iterator': 2, // 禁止使用 `__iterator__ ` 属性
|
||||
'no-label-var': 2, // `label` 名不能与 `var` 声明的变量名相同
|
||||
'no-labels': 2, // 禁止标签声明
|
||||
'no-lone-blocks': 2, // 禁止不必要的嵌套块
|
||||
'no-multi-spaces': 1, // 禁止使用多余的空格
|
||||
'no-multiple-empty-lines': [
|
||||
'error',
|
||||
{
|
||||
max: 2,
|
||||
},
|
||||
], // 空行最多不能超过 `2` 行
|
||||
'no-new-func': 2, // 禁止使用 `new Function`
|
||||
'no-new-object': 2, // 禁止使用 `new Object`
|
||||
'no-new-require': 2, // 禁止使用 `new require`
|
||||
'no-sparse-arrays': 2, // 禁止稀疏数组
|
||||
'no-trailing-spaces': 1, // 一行结束后面不要有空格
|
||||
'no-unreachable': 2, // 禁止有无法执行的代码
|
||||
'no-unused-expressions': [
|
||||
'error',
|
||||
{
|
||||
allowShortCircuit: true,
|
||||
allowTernary: true,
|
||||
allowTaggedTemplates: true,
|
||||
enforceForJSX: true,
|
||||
},
|
||||
], // 禁止无用的表达式
|
||||
'no-useless-call': 2, // 禁止不必要的 `call` 和 `apply`
|
||||
'no-var': 'error', // 禁用 `var`
|
||||
'no-with': 2, // 禁用 `with`
|
||||
'use-isnan': 2, // 强制使用 isNaN 判断 NaN
|
||||
'no-multi-assign': 2, // 禁止连续声明变量
|
||||
'prefer-arrow-callback': 2, // 强制使用箭头函数作为回调
|
||||
curly: ['error', 'all'],
|
||||
'vue/multi-word-component-names': [
|
||||
'error',
|
||||
{
|
||||
ignores: [],
|
||||
},
|
||||
],
|
||||
'vue/no-use-v-if-with-v-for': [
|
||||
'error',
|
||||
{
|
||||
allowUsingIterationVar: false,
|
||||
},
|
||||
],
|
||||
'vue/require-v-for-key': ['error'],
|
||||
'vue/require-valid-default-prop': ['error'],
|
||||
'vue/component-definition-name-casing': ['error', 'PascalCase'],
|
||||
'vue/html-closing-bracket-newline': [
|
||||
'error',
|
||||
{
|
||||
singleline: 'never',
|
||||
multiline: 'always',
|
||||
},
|
||||
],
|
||||
'vue/v-on-event-hyphenation': ['error', 'never'],
|
||||
'vue/component-tags-order': [
|
||||
'error',
|
||||
{
|
||||
order: ['template', 'script', 'style'],
|
||||
},
|
||||
],
|
||||
'vue/no-v-html': ['error'],
|
||||
'vue/no-v-text': ['error'],
|
||||
'vue/component-api-style': [
|
||||
'error',
|
||||
['script-setup', 'composition', 'composition-vue2'],
|
||||
],
|
||||
'vue/component-name-in-template-casing': [
|
||||
'error',
|
||||
'PascalCase',
|
||||
{
|
||||
registeredComponentsOnly: false,
|
||||
},
|
||||
],
|
||||
'vue/no-unused-refs': ['error'],
|
||||
'vue/prop-name-casing': ['error', 'camelCase'],
|
||||
'vue/component-options-name-casing': ['error', 'PascalCase'],
|
||||
'vue/attribute-hyphenation': [
|
||||
'error',
|
||||
'never',
|
||||
{
|
||||
ignore: [],
|
||||
},
|
||||
],
|
||||
'vue/no-restricted-static-attribute': [
|
||||
'error',
|
||||
{
|
||||
key: 'key',
|
||||
message: 'Disallow using key as a custom attribute',
|
||||
},
|
||||
],
|
||||
},
|
||||
}
|
12
.gitattributes
vendored
12
.gitattributes
vendored
@ -1,2 +1,14 @@
|
||||
# 将换行符设置为lf
|
||||
* text eol=lf
|
||||
# 将静态资源文件以二进制形式处理
|
||||
*.png binary
|
||||
*.jpg binary
|
||||
*.jpeg binary
|
||||
*.gif binary
|
||||
*.svg binary
|
||||
*.webp binary
|
||||
*.mp4 binary
|
||||
*.mov binary
|
||||
*.avi binary
|
||||
*.mp3 binary
|
||||
*.wav binary
|
38
.github/workflows/docs-deploy.yaml
vendored
Normal file
38
.github/workflows/docs-deploy.yaml
vendored
Normal file
@ -0,0 +1,38 @@
|
||||
name: ray-template documents deploy
|
||||
|
||||
on:
|
||||
push:
|
||||
pull_request:
|
||||
types:
|
||||
- closed
|
||||
|
||||
jobs:
|
||||
build-and-deploy:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Install Node.js 22.x
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: 22.x
|
||||
|
||||
- uses: pnpm/action-setup@v2
|
||||
name: Install pnpm
|
||||
with:
|
||||
version: 9
|
||||
run_install: false
|
||||
|
||||
- name: Install dependencies
|
||||
run: pnpm install
|
||||
|
||||
- name: Pnpm build
|
||||
run: pnpm build
|
||||
|
||||
- name: Deploy to dist branch
|
||||
uses: JamesIves/github-pages-deploy-action@4.1.4
|
||||
with:
|
||||
branch: dist
|
||||
folder: dist/production
|
8
.github/workflows/push-build.yaml
vendored
8
.github/workflows/push-build.yaml
vendored
@ -8,9 +8,9 @@ jobs:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
node-version: [ 16.x, 18.x ]
|
||||
os: [ ubuntu-latest, windows-latest, macos-latest ]
|
||||
experimental: [ true ]
|
||||
node-version: [22.x]
|
||||
os: [ubuntu-latest, windows-latest, macos-latest]
|
||||
experimental: [true]
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
@ -24,7 +24,7 @@ jobs:
|
||||
- uses: pnpm/action-setup@v2
|
||||
name: Install pnpm
|
||||
with:
|
||||
version: 8
|
||||
version: 9
|
||||
run_install: false
|
||||
|
||||
- name: Get pnpm store directory
|
||||
|
2
.gitignore
vendored
2
.gitignore
vendored
@ -15,6 +15,7 @@ dist/
|
||||
*.local
|
||||
visualizer.*
|
||||
.eslintcache
|
||||
.history
|
||||
|
||||
# Editor directories and files
|
||||
.idea
|
||||
@ -27,4 +28,3 @@ visualizer.*
|
||||
yarn-*.*
|
||||
yarn.*
|
||||
pnpm.*
|
||||
pnpm-lock.yaml
|
||||
|
@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env sh
|
||||
. "$(dirname "$0")/_/husky.sh"
|
||||
. "$(dirname -- "$0")/_/husky.sh"
|
||||
|
||||
pnpm lint-staged --allow-empty "$1"
|
||||
npx --no-install commitlint --edit "$1"
|
||||
|
8
.husky/common.sh
Normal file
8
.husky/common.sh
Normal file
@ -0,0 +1,8 @@
|
||||
#!/bin/sh
|
||||
command_exists () {
|
||||
command -v "$1" >/dev/null 2>&1
|
||||
}
|
||||
|
||||
if command_exists winpty && test -t 1; then
|
||||
exec < /dev/tty
|
||||
fi
|
@ -1,4 +1,7 @@
|
||||
#!/usr/bin/env sh
|
||||
. "$(dirname "$0")/_/husky.sh"
|
||||
. "$(dirname -- "$0")/_/husky.sh"
|
||||
. "$(dirname "$0")/common.sh"
|
||||
|
||||
[ -n "$CI" ] && exit 0
|
||||
|
||||
pnpm lint-staged --allow-empty "$1"
|
@ -1,9 +1,6 @@
|
||||
node_modules/*
|
||||
dist/*
|
||||
yarn.lock
|
||||
yarn-error.log
|
||||
visualizer.html
|
||||
pnpm-lock.yaml
|
||||
.idea
|
||||
auto-imports.d.ts
|
||||
components.d.ts
|
||||
|
@ -9,3 +9,4 @@ yarn.*
|
||||
visualizer.*
|
||||
visualizer.html
|
||||
.env.*
|
||||
*-lock.yaml
|
@ -8,7 +8,6 @@ module.exports = {
|
||||
jsxSingleQuote: false, // `jsx` 不使用单引号, 而使用双引号
|
||||
trailingComma: 'all', // 尾随逗号
|
||||
bracketSpacing: true, // 大括号内的首尾需要空格
|
||||
jsxBracketSameLine: false, // `jsx` 标签的反尖括号需要换行
|
||||
arrowParens: 'always', // 箭头函数, 只有一个参数的时候, 也需要括号
|
||||
rangeStart: 0, // 每个文件格式化的范围是文件的全部内容
|
||||
rangeEnd: Infinity,
|
||||
@ -16,5 +15,6 @@ module.exports = {
|
||||
insertPragma: false, // 不需要自动在文件开头插入 `@prettier`
|
||||
proseWrap: 'preserve', // 使用默认的折行标准
|
||||
htmlWhitespaceSensitivity: 'css', // 根据显示样式决定 `html` 要不要折行
|
||||
endOfLine: 'lf', // 换行符使用 `lf`
|
||||
endOfLine: 'lf', // 换行符使用 `lf`,
|
||||
singleAttributePerLine: false,
|
||||
}
|
||||
|
33
.vscode/settings.json
vendored
33
.vscode/settings.json
vendored
@ -1,4 +1,5 @@
|
||||
{
|
||||
"editor.formatOnSave": true,
|
||||
"i18n-ally.localesPaths": ["src/locales/lang"],
|
||||
"i18n-ally.keystyle": "nested",
|
||||
"i18n-ally.sortKeys": true,
|
||||
@ -17,5 +18,35 @@
|
||||
"@mock": "/mock"
|
||||
},
|
||||
"alias-skip.allowedsuffix": ["ts", "tsx"],
|
||||
"alias-skip.rootpath": "package.json"
|
||||
"alias-skip.rootpath": "package.json",
|
||||
"cSpell.words": [
|
||||
"baomitu",
|
||||
"bezier",
|
||||
"Cascader",
|
||||
"Clickoutside",
|
||||
"codabar",
|
||||
"commitmsg",
|
||||
"crossorigin",
|
||||
"datetimerange",
|
||||
"domtoimage",
|
||||
"EDITMSG",
|
||||
"iife",
|
||||
"internalkey",
|
||||
"jsbarcode",
|
||||
"linebreak",
|
||||
"logicflow",
|
||||
"macarons",
|
||||
"menutag",
|
||||
"ndata",
|
||||
"persistedstate",
|
||||
"pharmacode",
|
||||
"Popselect",
|
||||
"precommit",
|
||||
"siderbar",
|
||||
"snapline",
|
||||
"stylelint",
|
||||
"unocss",
|
||||
"WUJIE",
|
||||
"zlevel"
|
||||
]
|
||||
}
|
||||
|
1858
CHANGELOG.md
1858
CHANGELOG.md
File diff suppressed because it is too large
Load Diff
221
CODE_OF_CONDUCT.md
Normal file
221
CODE_OF_CONDUCT.md
Normal file
@ -0,0 +1,221 @@
|
||||
|
||||
# Contributor Covenant Code of Conduct
|
||||
|
||||
## Our Pledge
|
||||
|
||||
We as members, contributors, and leaders pledge to make participation in our
|
||||
community a harassment-free experience for everyone, regardless of age, body
|
||||
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
||||
identity and expression, level of experience, education, socio-economic status,
|
||||
nationality, personal appearance, race, caste, color, religion, or sexual
|
||||
identity and orientation.
|
||||
|
||||
We pledge to act and interact in ways that contribute to an open, welcoming,
|
||||
diverse, inclusive, and healthy community.
|
||||
|
||||
## Our Standards
|
||||
|
||||
Examples of behavior that contributes to a positive environment for our
|
||||
community include:
|
||||
|
||||
* Demonstrating empathy and kindness toward other people
|
||||
* Being respectful of differing opinions, viewpoints, and experiences
|
||||
* Giving and gracefully accepting constructive feedback
|
||||
* Accepting responsibility and apologizing to those affected by our mistakes,
|
||||
and learning from the experience
|
||||
* Focusing on what is best not just for us as individuals, but for the overall
|
||||
community
|
||||
|
||||
Examples of unacceptable behavior include:
|
||||
|
||||
* The use of sexualized language or imagery, and sexual attention or advances of
|
||||
any kind
|
||||
* Trolling, insulting or derogatory comments, and personal or political attacks
|
||||
* Public or private harassment
|
||||
* Publishing others' private information, such as a physical or email address,
|
||||
without their explicit permission
|
||||
* Other conduct which could reasonably be considered inappropriate in a
|
||||
professional setting
|
||||
|
||||
## Enforcement Responsibilities
|
||||
|
||||
Community leaders are responsible for clarifying and enforcing our standards of
|
||||
acceptable behavior and will take appropriate and fair corrective action in
|
||||
response to any behavior that they deem inappropriate, threatening, offensive,
|
||||
or harmful.
|
||||
|
||||
Community leaders have the right and responsibility to remove, edit, or reject
|
||||
comments, commits, code, wiki edits, issues, and other contributions that are
|
||||
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
||||
decisions when appropriate.
|
||||
|
||||
## Scope
|
||||
|
||||
This Code of Conduct applies within all community spaces, and also applies when
|
||||
an individual is officially representing the community in public spaces.
|
||||
Examples of representing our community include using an official email address,
|
||||
posting via an official social media account, or acting as an appointed
|
||||
representative at an online or offline event.
|
||||
|
||||
## Enforcement
|
||||
|
||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
||||
reported to the community leaders responsible for enforcement at
|
||||
<443547225@qq.com>.
|
||||
All complaints will be reviewed and investigated promptly and fairly.
|
||||
|
||||
All community leaders are obligated to respect the privacy and security of the
|
||||
reporter of any incident.
|
||||
|
||||
## Enforcement Guidelines
|
||||
|
||||
Community leaders will follow these Community Impact Guidelines in determining
|
||||
the consequences for any action they deem in violation of this Code of Conduct:
|
||||
|
||||
### 1. Correction
|
||||
|
||||
**Community Impact**: Use of inappropriate language or other behavior deemed
|
||||
unprofessional or unwelcome in the community.
|
||||
|
||||
**Consequence**: A private, written warning from community leaders, providing
|
||||
clarity around the nature of the violation and an explanation of why the
|
||||
behavior was inappropriate. A public apology may be requested.
|
||||
|
||||
### 2. Warning
|
||||
|
||||
**Community Impact**: A violation through a single incident or series of
|
||||
actions.
|
||||
|
||||
**Consequence**: A warning with consequences for continued behavior. No
|
||||
interaction with the people involved, including unsolicited interaction with
|
||||
those enforcing the Code of Conduct, for a specified period of time. This
|
||||
includes avoiding interactions in community spaces as well as external channels
|
||||
like social media. Violating these terms may lead to a temporary or permanent
|
||||
ban.
|
||||
|
||||
### 3. Temporary Ban
|
||||
|
||||
**Community Impact**: A serious violation of community standards, including
|
||||
sustained inappropriate behavior.
|
||||
|
||||
**Consequence**: A temporary ban from any sort of interaction or public
|
||||
communication with the community for a specified period of time. No public or
|
||||
private interaction with the people involved, including unsolicited interaction
|
||||
with those enforcing the Code of Conduct, is allowed during this period.
|
||||
Violating these terms may lead to a permanent ban.
|
||||
|
||||
### 4. Permanent Ban
|
||||
|
||||
**Community Impact**: Demonstrating a pattern of violation of community
|
||||
standards, including sustained inappropriate behavior, harassment of an
|
||||
individual, or aggression toward or disparagement of classes of individuals.
|
||||
|
||||
**Consequence**: A permanent ban from any sort of public interaction within the
|
||||
community.
|
||||
|
||||
## Attribution
|
||||
|
||||
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
||||
version 2.1, available at
|
||||
[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
|
||||
|
||||
Community Impact Guidelines were inspired by
|
||||
[Mozilla's code of conduct enforcement ladder][Mozilla CoC].
|
||||
|
||||
For answers to common questions about this code of conduct, see the FAQ at
|
||||
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
|
||||
[https://www.contributor-covenant.org/translations][translations].
|
||||
|
||||
[homepage]: https://www.contributor-covenant.org
|
||||
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
|
||||
[Mozilla CoC]: https://github.com/mozilla/diversity
|
||||
[FAQ]: https://www.contributor-covenant.org/faq
|
||||
[translations]: https://www.contributor-covenant.org/translations
|
||||
|
||||
# 贡献者公约
|
||||
|
||||
## 我们的承诺
|
||||
|
||||
身为社区成员、贡献者和领袖,我们承诺使社区参与者不受骚扰,无论其年龄、体型、可见或不可见的缺陷、族裔、性征、性别认同和表达、经验水平、教育程度、社会与经济地位、国籍、相貌、种族、种姓、肤色、宗教信仰、性倾向或性取向如何。
|
||||
|
||||
我们承诺以有助于建立开放、友善、多样化、包容、健康社区的方式行事和互动。
|
||||
|
||||
## 我们的准则
|
||||
|
||||
有助于为我们的社区创造积极环境的行为例子包括但不限于:
|
||||
|
||||
* 表现出对他人的同情和善意
|
||||
* 尊重不同的主张、观点和感受
|
||||
* 提出和大方接受建设性意见
|
||||
* 承担责任并向受我们错误影响的人道歉
|
||||
* 注重社区共同诉求,而非个人得失
|
||||
|
||||
不当行为例子包括:
|
||||
|
||||
* 使用情色化的语言或图像,及性引诱或挑逗
|
||||
* 嘲弄、侮辱或诋毁性评论,以及人身或政治攻击
|
||||
* 公开或私下的骚扰行为
|
||||
* 未经他人明确许可,公布他人的私人信息,如物理或电子邮件地址
|
||||
* 其他有理由认定为违反职业操守的不当行为
|
||||
|
||||
## 责任和权力
|
||||
|
||||
社区领袖有责任解释和落实我们所认可的行为准则,并妥善公正地对他们认为不当、威胁、冒犯或有害的任何行为采取纠正措施。
|
||||
|
||||
社区领导有权力和责任删除、编辑或拒绝或拒绝与本行为准则不相符的评论(comment)、提交(commits)、代码、维基(wiki)编辑、议题(issues)或其他贡献,并在适当时机知采取措施的理由。
|
||||
|
||||
## 适用范围
|
||||
|
||||
本行为准则适用于所有社区场合,也适用于在公共场所代表社区时的个人。
|
||||
|
||||
代表社区的情形包括使用官方电子邮件地址、通过官方社交媒体帐户发帖或在线上或线下活动中担任指定代表。
|
||||
|
||||
## 监督
|
||||
|
||||
辱骂、骚扰或其他不可接受的行为可通过 <443547225@qq.com> 向负责监督的社区领袖报告。
|
||||
所有投诉都将得到及时和公平的审查和调查。
|
||||
|
||||
所有社区领袖都有义务尊重任何事件报告者的隐私和安全。
|
||||
|
||||
## 处理方针
|
||||
|
||||
社区领袖将遵循下列社区处理方针来明确他们所认定违反本行为准则的行为的处理方式:
|
||||
|
||||
### 1. 纠正
|
||||
|
||||
**社区影响**:使用不恰当的语言或其他在社区中被认定为不符合职业道德或不受欢迎的行为。
|
||||
|
||||
**处理意见**:由社区领袖发出非公开的书面警告,明确说明违规行为的性质,并解释举止如何不妥。或将要求公开道歉。
|
||||
|
||||
### 2. 警告
|
||||
|
||||
**社区影响**:单个或一系列违规行为。
|
||||
|
||||
**处理意见**:警告并对连续性行为进行处理。在指定时间内,不得与相关人员互动,包括主动与行为准则执行者互动。这包括避免在社区场所和外部渠道中的互动。违反这些条款可能会导致临时或永久封禁。
|
||||
|
||||
### 3. 临时封禁
|
||||
|
||||
**社区影响**: 严重违反社区准则,包括持续的不当行为。
|
||||
|
||||
**处理意见**: 在指定时间内,暂时禁止与社区进行任何形式的互动或公开交流。在此期间,不得与相关人员进行公开或私下互动,包括主动与行为准则执行者互动。违反这些条款可能会导致永久封禁。
|
||||
|
||||
### 4. 永久封禁
|
||||
|
||||
**社区影响**:行为模式表现出违反社区准则,包括持续的不当行为、骚扰个人或攻击或贬低某个类别的个体。
|
||||
|
||||
**处理意见**:永久禁止在社区内进行任何形式的公开互动。
|
||||
|
||||
## 参见
|
||||
|
||||
本行为准则改编自 [Contributor Covenant][homepage] 2.1 版, 参见 [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1]。
|
||||
|
||||
社区处理方针灵感来源于 [Mozilla's code of conduct enforcement ladder][Mozilla CoC]。
|
||||
|
||||
有关本行为准则的常见问题的答案,参见 [https://www.contributor-covenant.org/faq][FAQ]。
|
||||
其他语言翻译参见 [https://www.contributor-covenant.org/translations][translations]。
|
||||
|
||||
[homepage]: https://www.contributor-covenant.org
|
||||
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
|
||||
[Mozilla CoC]: https://github.com/mozilla/diversity
|
||||
[FAQ]: https://www.contributor-covenant.org/faq
|
||||
[translations]: https://www.contributor-covenant.org/translations
|
@ -1,21 +0,0 @@
|
||||
## 常见问题
|
||||
|
||||
### 路由
|
||||
|
||||
#### 缓存失效
|
||||
|
||||
> 如果出现缓存配置不生效的情况可以按照如下方法进行排查
|
||||
|
||||
- 查看 APP_KEEP_ALIVE setupKeepAlive 属性是否配置为 true
|
||||
- 查看每个组件的 `name` 是否唯一,[`KeepAlive`](https://cn.vuejs.org/guide/built-ins/keep-alive.html) 组件重度依赖组件 `name` 作为唯一标识。详情可以查看官方文档
|
||||
- 查看该页面的路由配置是否正确,比如:`path` 是否按照模板约定方式进行配置
|
||||
|
||||
#### 自动导入失败
|
||||
|
||||
> 模板采用自动导入路由模块方式。如果发现路由导入有误、或者导入报错,请查看文件命名是否有误。
|
||||
|
||||
### 国际化
|
||||
|
||||
#### 国际化切换错误、警告
|
||||
|
||||
> 模板二次封装 [`useI18n`](https://github.com/XiaoDaiGua-Ray/ray-template/blob/main/src/locales/useI18n.ts) 方法,首选该方法作为国际化语言切换方法。
|
11
Dockerfile
Normal file
11
Dockerfile
Normal file
@ -0,0 +1,11 @@
|
||||
FROM debian:11
|
||||
COPY . /app
|
||||
WORKDIR /app
|
||||
RUN apt-get update
|
||||
RUN apt-get install -y wget curl make sudo unzip
|
||||
RUN curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
|
||||
RUN apt-get install -y nodejs
|
||||
RUN npm i -g pnpm
|
||||
RUN pnpm install
|
||||
EXPOSE 9527
|
||||
CMD [ "pnpm", "dev" ]
|
22
README.commit.md
Normal file
22
README.commit.md
Normal file
@ -0,0 +1,22 @@
|
||||
# commit 规范
|
||||
|
||||
## commit message 格式
|
||||
|
||||
在提交代码时,`commit message` 遵循以下格式:
|
||||
|
||||
- feat: 新功能`(feature)`
|
||||
- fix: 修补 `bug`
|
||||
- update: 更新代码
|
||||
- docs: 文档(documentation)
|
||||
- style: 格式(不影响代码运行的变动)
|
||||
- refactor: 重构(即不是新增功能,也不是修改bug的代码变动)
|
||||
- test: 增加测试
|
||||
- chore: 构建过程或辅助工具的变动
|
||||
- revert: 撤销
|
||||
- merge: 合并分支
|
||||
- perf: 优化相关,比如提升性能、体验
|
||||
- build: 构建
|
||||
- plugin: 插件更新
|
||||
- publish: 发布
|
||||
|
||||
当你需要定制化自己的`commit message`格式时,可以在`commitlint.config.cjs`文件中进行配置。
|
167
README.md
167
README.md
@ -1,153 +1,154 @@
|
||||
<div align="center"> <a href="https://github.com/XiaoDaiGua-Ray/ray-template"> <img alt="Ray Template" width="200" height="200" src="https://usc1.contabostorage.com/c2e495d7890844d392e8ec0c6e5d77eb:alist/ray/ray.svg?sign=ZklU9Bh5b6oKp1X0LOhGwkx4g5mW4wk_w9Jt5zlZ5EQ=:0"> </a> <br> <br>
|
||||
|
||||
<div align="center">
|
||||
<a href="https://github.com/XiaoDaiGua-Ray/ray-template">
|
||||
<img
|
||||
alt="Ray Template"
|
||||
width="200"
|
||||
height="200"
|
||||
src="https://avatars.githubusercontent.com/u/51957438?v=4"
|
||||
/>
|
||||
</a>
|
||||
<br />
|
||||
<br />
|
||||
<a href="https://nodejs.org/en/about/previous-releases"><img src="https://img.shields.io/node/v/vite.svg" alt="node compatibility"></a>
|
||||
<a href="https://github.com/XiaoDaiGua-Ray/ray-template/blob/main/LICENSE"
|
||||
><img
|
||||
src="https://img.shields.io/github/license/XiaoDaiGua-Ray/ray-template"
|
||||
alt="LICENSE"
|
||||
/></a>
|
||||
<a href="#badge"><img src="https://img.shields.io/github/languages/top/XiaoDaiGua-Ray/ray-template" alt="language"></a>
|
||||
<a href="https://www.npmjs.com/package/ray-template"><img src="https://img.shields.io/npm/v/ray-template" alt="npm package"></a>
|
||||
</div>
|
||||
|
||||
<div align="center">
|
||||
|
||||
# Ray Template
|
||||
|
||||
一个基于 vite4.x & ts(x) & pinia & vue3.x 的中后台模板
|
||||
English | [简体中文](https://github.com/XiaoDaiGua-Ray/ray-template/blob/main/README.zh-CN.md)
|
||||
|
||||
A `completely free`, `efficient`, `feature complete` and based on vite5. x & ts(x) & pinia & vue3. x and other latest technology in the background template.
|
||||
|
||||
</div>
|
||||
|
||||
## ✨ 特性
|
||||
## 🌻 Intro
|
||||
|
||||
- **最新技术栈**:使用 Vue3.x/vite4.x 等前端前沿技术开发
|
||||
- **TypeScript**:应用程序级 JavaScript 的语言
|
||||
- **主题**:可配置的主题
|
||||
- **国际化**:内置完善的国际化方案
|
||||
- **Mock 数据**:内置 Mock 数据方案
|
||||
- **权限**:内置完善的动态路由权限生成方案
|
||||
- **组件**:二次封装了多个常用的组件
|
||||
- **Axios 请求**:二次封装 axios 库
|
||||
`Ray Template` uses cutting-edge front-end technology, abandoning complexity and bloat, using modular design, decoupling data, methods and views, focusing on business development. Provide rich configuration and rich template `Hooks`, support personalized customization, to meet your project needs.
|
||||
|
||||
## 🪄 预览地址
|
||||
## ✨ Features
|
||||
|
||||
- [点击预览](https://xiaodaigua-ray.github.io/ray-template/#/)
|
||||
- [点击预览(加速地址)](https://ray-template.yunkuangao.com/#/)
|
||||
- `New technology stack:` using ts(x), vite5. x, vue3. x, pinia and other front-end cutting-edge technology development
|
||||
- `Theme:` configurable theme
|
||||
- `Internationalization:` built-in perfect internationalization solution
|
||||
- `Permissions:` built-in perfect dynamic routing permission generation solution
|
||||
- `Components:` secondary encapsulation of multiple common components
|
||||
- `Toolkit:` common tool function packaging
|
||||
- `Cache:` arbitrary depth page caching
|
||||
- `Modular design:` decoupling management data, methods, views, rest assured secondary development
|
||||
- `Configurable:` support rich configuration items
|
||||
- `Code style:` built-in prettier, eslint and other code style tools
|
||||
- `Multi-terminal adaptation:` support pc, phone, pad
|
||||
- `Documentation:` complete documentation
|
||||
- `Mock data:` built-in Mock data solution
|
||||
- `Axios request:` the plug-in design is used to encapsulate the axios library interceptor twice, which makes the interceptor more flexible
|
||||
- `SVG:` built-in svg icon solution
|
||||
- `Hooks:` based on the template characteristics of the encapsulated hooks to make it easier to use some functions of the template
|
||||
- `TypeScript:` provide a complete type
|
||||
- `Vitest:` built-in vitest test solution
|
||||
|
||||
## 🦾 文档地址
|
||||
## 👀 Preview
|
||||
|
||||
- [文档](https://xiaodaigua-ray.github.io/ray-template-doc/)
|
||||
- [文档(加速地址)](https://ray-template.yunkuangao.com/ray-template-doc/)
|
||||
- [Preview](https://xiaodaigua-ray.github.io/ray-template/#/)
|
||||
|
||||
## 🔋 更新日志
|
||||
## 📌 Documentation
|
||||
|
||||
- [更新日志](https://github.com/XiaoDaiGua-Ray/xiaodaigua-ray.github.io/blob/main/CHANGELOG.md)
|
||||
- [Documentation](https://xiaodaigua-ray.github.io/ray-template-doc/)
|
||||
|
||||
## 🪴 准备
|
||||
## 🔋 Change Log
|
||||
|
||||
- [node](http://nodejs.org/) 和 [git](https://git-scm.com/) -项目开发环境
|
||||
- [Vite](https://vitejs.dev/) - 熟悉 vite 特性
|
||||
- [Vue3](https://v3.vuejs.org/) - 熟悉 Vue 基础语法
|
||||
- [TypeScript](https://www.typescriptlang.org/) - 熟悉 TypeScript 基本语法
|
||||
- [Es6+](http://es6.ruanyifeng.com/) - 熟悉 es6 基本语法
|
||||
- [Vue-Router-Next](https://next.router.vuejs.org/) - 熟悉 vue-router4.x 基本使用
|
||||
- [Naive-UI](https://www.naiveui.com) - ui 基本使用
|
||||
- [Mock.js](https://github.com/nuysoft/Mock) - mockjs 基本语法
|
||||
- [Pinia](https://pinia.vuejs.org/zh/introduction.html) - 状态管理器 pinia 使用
|
||||
- [TSX](https://github.com/vuejs/babel-plugin-jsx/blob/main/packages/babel-plugin-jsx/README-zh_CN.md) - tsx 基本语法
|
||||
- [Change Log](https://github.com/XiaoDaiGua-Ray/xiaodaigua-ray.github.io/blob/main/CHANGELOG.md)
|
||||
|
||||
## 📦 起步
|
||||
## 🪴 Prepare
|
||||
|
||||
### 获取项目
|
||||
- [Node](http://nodejs.org/) and [git](https://git-scm.com/) - project development environment
|
||||
- [Vite](https://vitejs.dev/) - familiar with vite features
|
||||
- [Vue3](https://v3.vuejs.org/) - familiar with Vue basic syntax
|
||||
- [TypeScript](https://www.typescriptlang.org/) - familiar with TypeScript basic syntax
|
||||
- [ES6+](http://es6.ruanyifeng.com/) - familiar with es6 basic syntax
|
||||
- [Vue-Hooks-Plus](https://inhiblabcore.github.io/docs/hooks/) - familiar with vue-hooks-plus useRequest method basic use
|
||||
- [Vue-Router-Next](https://next.router.vuejs.org/) - familiar with vue-router4.x basic use
|
||||
- [Naive-UI](https://www.naiveui.com) - naive ui basic use
|
||||
- [Mock.js](https://github.com/nuysoft/Mock) - mockjs basic syntax
|
||||
- [Pinia](https://pinia.vuejs.org/zh/introduction.html) - state manager pinia usage
|
||||
- [TSX](https://github.com/vuejs/babel-plugin-jsx/blob/main/packages/babel-plugin-jsx/README-zh_CN.md) - tsx basic syntax
|
||||
- [Vitest](https://cn.vitest.dev/guide/) - vitest basic use
|
||||
|
||||
## 📦 Setup
|
||||
|
||||
### Get Project
|
||||
|
||||
```sh
|
||||
# github
|
||||
git clone https://github.com/XiaoDaiGua-Ray/ray-template.git
|
||||
|
||||
# 如果你的下载速度很慢,可以切换到下面的代理地址
|
||||
git clone https://gh.yka.moe/https://github.com/XiaoDaiGua-Ray/ray-template.git
|
||||
```
|
||||
|
||||
### 拉取依赖
|
||||
### Pull dependencies
|
||||
|
||||
```sh
|
||||
# pnpm
|
||||
|
||||
pnpm
|
||||
pnpm i
|
||||
```
|
||||
|
||||
```sh
|
||||
# npm
|
||||
### Test project
|
||||
|
||||
npm install
|
||||
```sh
|
||||
|
||||
pnpm test
|
||||
```
|
||||
|
||||
### 启动项目
|
||||
### Startup project
|
||||
|
||||
```sh
|
||||
# pnpm
|
||||
|
||||
pnpm dev
|
||||
```
|
||||
|
||||
```sh
|
||||
# npm
|
||||
|
||||
npm run dev
|
||||
```
|
||||
|
||||
### 项目打包
|
||||
### Build project
|
||||
|
||||
```sh
|
||||
# pnpm
|
||||
|
||||
pnpm build
|
||||
```
|
||||
|
||||
```sh
|
||||
# npm
|
||||
|
||||
npm run build
|
||||
```
|
||||
|
||||
### 预览项目
|
||||
### Preview project
|
||||
|
||||
```sh
|
||||
# pnpm
|
||||
|
||||
pnpm preview
|
||||
```
|
||||
|
||||
```sh
|
||||
# npm
|
||||
|
||||
npm run preview
|
||||
```
|
||||
|
||||
### 体积分析
|
||||
### Report project
|
||||
|
||||
```sh
|
||||
# pnpm
|
||||
|
||||
pnpm report
|
||||
```
|
||||
|
||||
```sh
|
||||
# npm
|
||||
### Development
|
||||
|
||||
npm run report
|
||||
```
|
||||
Just delete the files under `views/demo`, `router/modules/demo` to get a clean project template.
|
||||
|
||||
## 🪴 项目活动
|
||||
## 🪴 Project Activities
|
||||
|
||||

|
||||
|
||||
### 贡献者
|
||||
### Contributors
|
||||
|
||||
感谢他们的所做的一切贡献 🐝 !
|
||||
Thanks for all their contributions 🐝 !
|
||||
|
||||
<a href="https://github.com/XiaoDaiGua-Ray/ray-template/graphs/contributors">
|
||||
<img src="https://contrib.rocks/image?repo=XiaoDaiGua-Ray/ray-template" />
|
||||
</a>
|
||||
|
||||
## 浏览器支持
|
||||
## Browser Support
|
||||
|
||||
| [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/edge/edge_48x48.png" alt=" Edge" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)</br>IE | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/edge/edge_48x48.png" alt=" Edge" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)</br>Edge | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/firefox/firefox_48x48.png" alt="Firefox" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)</br>Firefox | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/chrome/chrome_48x48.png" alt="Chrome" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)</br>Chrome | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/safari/safari_48x48.png" alt="Safari" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)</br>Safari |
|
||||
| :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: |
|
||||
| not support | last 2 versions | last 2 versions | last 2 versions | last 2 versions |
|
||||
|
||||
## 📄 证书
|
||||
## 📄 License
|
||||
|
||||
[MIT License](https://github.com/XiaoDaiGua-Ray/ray-template/blob/main/LICENSE) © 2022-PRESENT [Ray](https://github.com/XiaoDaiGua-Ray/ray-template)
|
||||
[MIT License](https://github.com/XiaoDaiGua-Ray/ray-template/blob/main/LICENSE) © 2022-PRESENT [Ray](https://github.com/XiaoDaiGua-Ray)
|
||||
|
154
README.zh-CN.md
Normal file
154
README.zh-CN.md
Normal file
@ -0,0 +1,154 @@
|
||||
<div align="center">
|
||||
<a href="https://github.com/XiaoDaiGua-Ray/ray-template">
|
||||
<img
|
||||
alt="Ray Template"
|
||||
width="200"
|
||||
height="200"
|
||||
src="https://avatars.githubusercontent.com/u/51957438?v=4"
|
||||
/>
|
||||
</a>
|
||||
<br />
|
||||
<br />
|
||||
<a href="https://nodejs.org/en/about/previous-releases"><img src="https://img.shields.io/node/v/vite.svg" alt="node compatibility"></a>
|
||||
<a href="https://github.com/XiaoDaiGua-Ray/ray-template/blob/main/LICENSE"
|
||||
><img
|
||||
src="https://img.shields.io/github/license/XiaoDaiGua-Ray/ray-template"
|
||||
alt="LICENSE"
|
||||
/></a>
|
||||
<a href="#badge"><img src="https://img.shields.io/github/languages/top/XiaoDaiGua-Ray/ray-template" alt="language"></a>
|
||||
<a href="https://www.npmjs.com/package/ray-template"><img src="https://img.shields.io/npm/v/ray-template" alt="npm package"></a>
|
||||
</div>
|
||||
|
||||
<div align="center">
|
||||
|
||||
# Ray Template
|
||||
|
||||
简体中文 | [English](https://github.com/XiaoDaiGua-Ray/ray-template/blob/main/README.md)
|
||||
|
||||
一个 `完全免费`、`高效`、`特性完整` 并且基于 vite5.x & ts(x) & pinia & vue3.x 等最新技术的中后台模板。
|
||||
|
||||
</div>
|
||||
|
||||
## 🌻 简介
|
||||
|
||||
`Ray Template`采用前沿前端技术,摒弃繁杂与臃肿,采用模块化设计,解耦数据、方法和视图,专注业务开发。提供丰富配置和丰富的模板 `Hooks`,支持个性化定制,满足你的项目需求。
|
||||
|
||||
## ✨ 特性
|
||||
|
||||
- `全新技术栈:`使用 ts(x), vite5.x, vue3.x, pinia 等前端前沿技术开发
|
||||
- `主题:`可配置的主题
|
||||
- `国际化:`内置完善的国际化方案
|
||||
- `权限:`内置完善的动态路由权限生成方案
|
||||
- `组件:`二次封装了多个常用的组件
|
||||
- `工具包:`常用的工具函数封装
|
||||
- `缓存:`任意深度页面缓存
|
||||
- `模块化设计:`解耦管理的数据、方法、视图,放心二次开发
|
||||
- `配置化:`支持丰富的配置项
|
||||
- `代码风格:`内置 prettier, eslint 等代码风格工具
|
||||
- `多端适配:`支持 pc, phone, pad
|
||||
- `文档:`完善的文档
|
||||
- `Mock 数据:`内置 Mock 数据方案
|
||||
- `Axios 请求:`采用插件式设计二次封装 axios 库拦截器,让拦截器更加灵活
|
||||
- `SVG:`内置 svg icon 解决方案
|
||||
- `Hooks:`基于模板特性封装的 hooks 让你更加方便的使用模板一些功能
|
||||
- `TypeScript:`提供完整的类型
|
||||
- `Vitest:`内置 vitest 测试方案
|
||||
|
||||
## 👀 预览地址
|
||||
|
||||
- [点击预览](https://xiaodaigua-ray.github.io/ray-template/#/)
|
||||
|
||||
## 📌 文档地址
|
||||
|
||||
- [文档](https://xiaodaigua-ray.github.io/ray-template-doc/)
|
||||
|
||||
## 🔋 更新日志
|
||||
|
||||
- [更新日志](https://github.com/XiaoDaiGua-Ray/xiaodaigua-ray.github.io/blob/main/CHANGELOG.md)
|
||||
|
||||
## 🪴 准备
|
||||
|
||||
- [Node](http://nodejs.org/) 和 [git](https://git-scm.com/) - 项目开发环境
|
||||
- [Vite](https://vitejs.dev/) - 熟悉 vite 特性
|
||||
- [Vue3](https://v3.vuejs.org/) - 熟悉 Vue 基础语法
|
||||
- [TypeScript](https://www.typescriptlang.org/) - 熟悉 TypeScript 基本语法
|
||||
- [ES6+](http://es6.ruanyifeng.com/) - 熟悉 es6 基本语法
|
||||
- [Vue-Hooks-Plus](https://inhiblabcore.github.io/docs/hooks/) - 熟悉 vue-hooks-plus useRequest 方法的基本使用
|
||||
- [Vue-Router-Next](https://next.router.vuejs.org/) - 熟悉 vue-router4.x 基本使用
|
||||
- [Naive-UI](https://www.naiveui.com) - naive ui 基本使用
|
||||
- [Mock.js](https://github.com/nuysoft/Mock) - mockjs 基本语法
|
||||
- [Pinia](https://pinia.vuejs.org/zh/introduction.html) - 状态管理器 pinia 使用
|
||||
- [TSX](https://github.com/vuejs/babel-plugin-jsx/blob/main/packages/babel-plugin-jsx/README-zh_CN.md) - tsx 基本语法
|
||||
- [Vitest](https://cn.vitest.dev/guide/) - vitest 基本使用
|
||||
|
||||
## 📦 起步
|
||||
|
||||
### 获取项目
|
||||
|
||||
```sh
|
||||
# github
|
||||
git clone https://github.com/XiaoDaiGua-Ray/ray-template.git
|
||||
```
|
||||
|
||||
### 拉取依赖
|
||||
|
||||
```sh
|
||||
pnpm i
|
||||
```
|
||||
|
||||
### 测试项目
|
||||
|
||||
```sh
|
||||
|
||||
pnpm test
|
||||
```
|
||||
|
||||
### 启动项目
|
||||
|
||||
```sh
|
||||
pnpm dev
|
||||
```
|
||||
|
||||
### 项目打包
|
||||
|
||||
```sh
|
||||
pnpm build
|
||||
```
|
||||
|
||||
### 预览项目
|
||||
|
||||
```sh
|
||||
pnpm preview
|
||||
```
|
||||
|
||||
### 体积分析
|
||||
|
||||
```sh
|
||||
pnpm report
|
||||
```
|
||||
|
||||
### 快速开发
|
||||
|
||||
只需要删除 `views/demo`, `router/modules/demo` 下的文件即可得到一个干净的项目模板。
|
||||
|
||||
## 🪴 项目活动
|
||||
|
||||

|
||||
|
||||
### 贡献者
|
||||
|
||||
感谢他们的所做的一切贡献 🐝 !
|
||||
|
||||
<a href="https://github.com/XiaoDaiGua-Ray/ray-template/graphs/contributors">
|
||||
<img src="https://contrib.rocks/image?repo=XiaoDaiGua-Ray/ray-template" />
|
||||
</a>
|
||||
|
||||
## 浏览器支持
|
||||
|
||||
| [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/edge/edge_48x48.png" alt=" Edge" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)</br>IE | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/edge/edge_48x48.png" alt=" Edge" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)</br>Edge | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/firefox/firefox_48x48.png" alt="Firefox" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)</br>Firefox | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/chrome/chrome_48x48.png" alt="Chrome" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)</br>Chrome | [<img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/safari/safari_48x48.png" alt="Safari" width="24px" height="24px" />](http://godban.github.io/browsers-support-badges/)</br>Safari |
|
||||
| :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: |
|
||||
| not support | last 2 versions | last 2 versions | last 2 versions | last 2 versions |
|
||||
|
||||
## 📄 证书
|
||||
|
||||
[MIT License](https://github.com/XiaoDaiGua-Ray/ray-template/blob/main/LICENSE) © 2022-PRESENT [Ray](https://github.com/XiaoDaiGua-Ray)
|
16
__test__/app/prefixCacheKey.spec.ts
Normal file
16
__test__/app/prefixCacheKey.spec.ts
Normal file
@ -0,0 +1,16 @@
|
||||
import { prefixCacheKey } from '../../src/utils/app/prefix-cache-key'
|
||||
|
||||
describe('prefixCacheKey', () => {
|
||||
it('should return the key with the default prefix', () => {
|
||||
const key = 'signing'
|
||||
|
||||
expect(prefixCacheKey(key)).toBe(key)
|
||||
})
|
||||
|
||||
it('should return the key with the custom prefix', () => {
|
||||
const key = 'signing'
|
||||
const customPrefix = 'ray-'
|
||||
|
||||
expect(prefixCacheKey(key, { customPrefix })).toBe(customPrefix + key)
|
||||
})
|
||||
})
|
18
__test__/basic/arrayBufferToBase64Image.spec.ts
Normal file
18
__test__/basic/arrayBufferToBase64Image.spec.ts
Normal file
@ -0,0 +1,18 @@
|
||||
import { arrayBufferToBase64Image } from '../../src/utils/basic'
|
||||
|
||||
describe('arrayBufferToBase64Image', () => {
|
||||
const arrayBuffer = new ArrayBuffer(8)
|
||||
const base64ImagePrefix = 'data:image/png;base64,'
|
||||
|
||||
it('should convert array buffer to base64 image', () => {
|
||||
const base64Image = arrayBufferToBase64Image(arrayBuffer)
|
||||
|
||||
expect(base64Image).toBe(`${base64ImagePrefix}AAAAAAAAAAA=`)
|
||||
})
|
||||
|
||||
it('should convert array buffer to base64 image with prefix', () => {
|
||||
const base64Image = arrayBufferToBase64Image(arrayBuffer)
|
||||
|
||||
expect(base64Image.startsWith(base64ImagePrefix)).toBe(true)
|
||||
})
|
||||
})
|
27
__test__/basic/callWithAsyncErrorHandling.spec.ts
Normal file
27
__test__/basic/callWithAsyncErrorHandling.spec.ts
Normal file
@ -0,0 +1,27 @@
|
||||
import { callWithAsyncErrorHandling } from '../../src/utils/basic'
|
||||
|
||||
describe('callWithAsyncErrorHandling', () => {
|
||||
it('should call the function and return the result', () => {
|
||||
const fn = (x: number) => x
|
||||
|
||||
const callbackFn = () => {}
|
||||
|
||||
expect(callWithAsyncErrorHandling(fn, callbackFn, [1])).resolves.toBe(1)
|
||||
})
|
||||
|
||||
it('should call the callback function when the function throws an error', () => {
|
||||
let callbackFnExecuted = 1
|
||||
|
||||
const fn = () => {
|
||||
throw new Error('test error')
|
||||
}
|
||||
|
||||
const callbackFn = () => {
|
||||
callbackFnExecuted = 2
|
||||
}
|
||||
|
||||
callWithAsyncErrorHandling(fn, callbackFn)
|
||||
|
||||
expect(callbackFnExecuted).toBe(2)
|
||||
})
|
||||
})
|
27
__test__/basic/callWithErrorHandling.spec.ts
Normal file
27
__test__/basic/callWithErrorHandling.spec.ts
Normal file
@ -0,0 +1,27 @@
|
||||
import { callWithErrorHandling } from '../../src/utils/basic'
|
||||
|
||||
describe('callWithErrorHandling', () => {
|
||||
it('should call the function and return the result', () => {
|
||||
const fn = (x: number) => x
|
||||
|
||||
const callbackFn = () => {}
|
||||
|
||||
expect(callWithErrorHandling(fn, callbackFn, [1])).toBe(1)
|
||||
})
|
||||
|
||||
it('should call the callback function when the function throws an error', () => {
|
||||
let callbackFnExecuted = 1
|
||||
|
||||
const fn = () => {
|
||||
throw new Error('test error')
|
||||
}
|
||||
|
||||
const callbackFn = () => {
|
||||
callbackFnExecuted = 2
|
||||
}
|
||||
|
||||
callWithErrorHandling(fn, callbackFn)
|
||||
|
||||
expect(callbackFnExecuted).toBe(2)
|
||||
})
|
||||
})
|
7
__test__/basic/detectOperatingSystem.spec.ts
Normal file
7
__test__/basic/detectOperatingSystem.spec.ts
Normal file
@ -0,0 +1,7 @@
|
||||
import { detectOperatingSystem } from '../../src/utils/basic'
|
||||
|
||||
describe('detectOperatingSystem', () => {
|
||||
it('should return Unknown', () => {
|
||||
expect(detectOperatingSystem()).toBe('Unknown')
|
||||
})
|
||||
})
|
33
__test__/basic/downloadAnyFile.spec.ts
Normal file
33
__test__/basic/downloadAnyFile.spec.ts
Normal file
@ -0,0 +1,33 @@
|
||||
import { downloadAnyFile } from '../../src/utils/basic'
|
||||
|
||||
describe('downloadAnyFile', () => {
|
||||
it('should download data when data is a string', () => {
|
||||
const data = 'test data'
|
||||
const fileName = 'test.txt'
|
||||
|
||||
expect(downloadAnyFile(data, fileName)).resolves.toBeUndefined()
|
||||
})
|
||||
|
||||
// it('should download data when data is a ArrayBuffer', () => {
|
||||
// const data = new ArrayBuffer(8)
|
||||
// const fileName = 'test.txt'
|
||||
|
||||
// expect(downloadAnyFile(data, fileName)).resolves.toBeUndefined()
|
||||
// })
|
||||
|
||||
// it('should download data when data is a Blob', () => {
|
||||
// const data = new Blob(['hello', 'world'], {
|
||||
// type: 'text/plain',
|
||||
// })
|
||||
// const fileName = 'test.txt'
|
||||
|
||||
// expect(downloadAnyFile(data, fileName)).resolves.toBeUndefined()
|
||||
// })
|
||||
|
||||
// it('should download data when data is a File', () => {
|
||||
// const data = new File(['hello', 'world'], 'test.txt')
|
||||
// const fileName = 'test.txt'
|
||||
|
||||
// expect(downloadAnyFile(data, fileName)).resolves.toBeUndefined()
|
||||
// })
|
||||
})
|
12
__test__/basic/downloadBase64File.spec.ts
Normal file
12
__test__/basic/downloadBase64File.spec.ts
Normal file
@ -0,0 +1,12 @@
|
||||
import { downloadBase64File } from '../../src/utils/basic'
|
||||
|
||||
describe('downloadBase64File', () => {
|
||||
const base64 =
|
||||
'data:image/png;base64,AAABAAEAEBAQAAEABAAoAQAAFgAAACgAAAAQAAAAIAAAAAEABAAAAAAAgAAAAAAAAAAAAAAAE'
|
||||
|
||||
it('download base64 to file', () => {
|
||||
const result = downloadBase64File(base64, 'test.png')
|
||||
|
||||
expect(result).toBe(void 0)
|
||||
})
|
||||
})
|
17
__test__/basic/equalRouterPath.spec.ts
Normal file
17
__test__/basic/equalRouterPath.spec.ts
Normal file
@ -0,0 +1,17 @@
|
||||
import { equalRouterPath } from '../../src/utils/basic'
|
||||
|
||||
describe('equalRouterPath', () => {
|
||||
it('compare paths with parameters', () => {
|
||||
const p1 = '/a?b=1'
|
||||
const p2 = '/a?b=2'
|
||||
|
||||
expect(equalRouterPath(p1, p2)).toBe(true)
|
||||
})
|
||||
|
||||
it('compare paths', () => {
|
||||
const p1 = '/a'
|
||||
const p2 = '/a/'
|
||||
|
||||
expect(equalRouterPath(p1, p2)).toBe(true)
|
||||
})
|
||||
})
|
21
__test__/basic/getAppEnvironment.spec.ts
Normal file
21
__test__/basic/getAppEnvironment.spec.ts
Normal file
@ -0,0 +1,21 @@
|
||||
import { getAppEnvironment } from '../../src/utils/basic'
|
||||
|
||||
describe('getAppEnvironment', () => {
|
||||
it('should return MODE is test', () => {
|
||||
const { MODE } = getAppEnvironment()
|
||||
|
||||
expect(MODE).toBe('test')
|
||||
})
|
||||
|
||||
it('SSR should be false', () => {
|
||||
const { SSR } = getAppEnvironment()
|
||||
|
||||
expect(SSR).toBe(false)
|
||||
})
|
||||
|
||||
it('deconstruction value should be undefined', () => {
|
||||
const { UNDEFINED_MODE } = getAppEnvironment()
|
||||
|
||||
expect(UNDEFINED_MODE).toBe(void 0)
|
||||
})
|
||||
})
|
33
__test__/basic/isAsyncFunction.spec.ts
Normal file
33
__test__/basic/isAsyncFunction.spec.ts
Normal file
@ -0,0 +1,33 @@
|
||||
import { isAsyncFunction } from '../../src/utils/basic'
|
||||
|
||||
describe('isAsyncFunction', () => {
|
||||
it('should return true if the function is async', () => {
|
||||
const asyncFn = async () => {}
|
||||
|
||||
expect(isAsyncFunction(asyncFn)).toBe(true)
|
||||
})
|
||||
|
||||
it('should return false if the function is not async', () => {
|
||||
const syncFn = () => {}
|
||||
|
||||
expect(isAsyncFunction(syncFn)).toBe(false)
|
||||
})
|
||||
|
||||
it('should return false if the function is not a function', () => {
|
||||
const notFn = 'not a function'
|
||||
|
||||
expect(isAsyncFunction(notFn)).toBe(false)
|
||||
})
|
||||
|
||||
it('should return false if the function is a class', () => {
|
||||
class MyClass {}
|
||||
|
||||
expect(isAsyncFunction(MyClass)).toBe(false)
|
||||
})
|
||||
|
||||
it('should return false if the function is a Promise', () => {
|
||||
const promise = Promise.resolve('')
|
||||
|
||||
expect(isAsyncFunction(promise)).toBe(false)
|
||||
})
|
||||
})
|
33
__test__/basic/isPromise.spec.ts
Normal file
33
__test__/basic/isPromise.spec.ts
Normal file
@ -0,0 +1,33 @@
|
||||
import { isPromise } from '../../src/utils/basic'
|
||||
|
||||
describe('isPromise', () => {
|
||||
it('should return true if the value is a Promise', () => {
|
||||
const promise = Promise.resolve('')
|
||||
|
||||
expect(isPromise(promise)).toBe(true)
|
||||
})
|
||||
|
||||
it('should return false if the value is not a Promise', () => {
|
||||
const notPromise = 'not a Promise'
|
||||
|
||||
expect(isPromise(notPromise)).toBe(false)
|
||||
})
|
||||
|
||||
it('should return false if the value is a class', () => {
|
||||
class MyClass {}
|
||||
|
||||
expect(isPromise(MyClass)).toBe(false)
|
||||
})
|
||||
|
||||
it('should return false if the value is a function', () => {
|
||||
const fn = () => {}
|
||||
|
||||
expect(isPromise(fn)).toBe(false)
|
||||
})
|
||||
|
||||
it('should return true if the value is an async function', () => {
|
||||
const asyncFn = async () => {}
|
||||
|
||||
expect(isPromise(asyncFn)).toBe(true)
|
||||
})
|
||||
})
|
48
__test__/basic/isValueType.spec.ts
Normal file
48
__test__/basic/isValueType.spec.ts
Normal file
@ -0,0 +1,48 @@
|
||||
import { isValueType } from '../../src/utils/basic'
|
||||
|
||||
describe('isValueType', () => {
|
||||
it('should return true for string', () => {
|
||||
expect(isValueType<string>('string', 'String')).toBe(true)
|
||||
})
|
||||
|
||||
it('should return true for number', () => {
|
||||
expect(isValueType<number>(123, 'Number')).toBe(true)
|
||||
})
|
||||
|
||||
it('should return true for array', () => {
|
||||
expect(isValueType<unknown[]>([], 'Array')).toBe(true)
|
||||
})
|
||||
|
||||
it('should return true for null', () => {
|
||||
expect(isValueType<null>(null, 'Null')).toBe(true)
|
||||
})
|
||||
|
||||
it('should return true for undefined', () => {
|
||||
expect(isValueType<undefined>(void 0, 'Undefined')).toBe(true)
|
||||
})
|
||||
|
||||
it('should return true for object', () => {
|
||||
expect(isValueType<object>({}, 'Object')).toBe(true)
|
||||
})
|
||||
|
||||
it('should return true for Map', () => {
|
||||
expect(isValueType<Map<unknown, unknown>>(new Map(), 'Map')).toBe(true)
|
||||
})
|
||||
|
||||
it('should return true for Set', () => {
|
||||
expect(isValueType<Set<unknown>>(new Set(), 'Set')).toBe(true)
|
||||
})
|
||||
|
||||
it('should return true for Date', () => {
|
||||
expect(isValueType<Date>(new Date(), 'Date')).toBe(true)
|
||||
})
|
||||
|
||||
it('should return true for RegExp', () => {
|
||||
expect(isValueType<RegExp>(/a/i, 'RegExp')).toBe(true)
|
||||
})
|
||||
|
||||
it('should return false for Function', () => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
||||
expect(isValueType<Function>(/a/i, 'Function')).toBe(false)
|
||||
})
|
||||
})
|
20
__test__/basic/uuid.spec.ts
Normal file
20
__test__/basic/uuid.spec.ts
Normal file
@ -0,0 +1,20 @@
|
||||
import { uuid } from '../../src/utils/basic'
|
||||
|
||||
describe('uuid', () => {
|
||||
it('should return String', () => {
|
||||
expectTypeOf(uuid()).toEqualTypeOf<string>()
|
||||
})
|
||||
|
||||
it('the return value should be unique', () => {
|
||||
const uuid1 = uuid()
|
||||
const uuid2 = uuid()
|
||||
|
||||
expect(uuid1).not.toBe(uuid2)
|
||||
})
|
||||
|
||||
it('should return a string with length 36', () => {
|
||||
const uid = uuid(36)
|
||||
|
||||
expect(uid.length).toBe(36)
|
||||
})
|
||||
})
|
117
__test__/cache/index.spec.ts
vendored
Normal file
117
__test__/cache/index.spec.ts
vendored
Normal file
@ -0,0 +1,117 @@
|
||||
import {
|
||||
hasStorage,
|
||||
setStorage,
|
||||
getStorage,
|
||||
removeStorage,
|
||||
} from '../../src/utils/cache'
|
||||
|
||||
describe('cache utils', () => {
|
||||
const __DEMO__KEY = '__DEMO__KEY'
|
||||
const __DEMO__VALUE = '__DEMO__VALUE'
|
||||
const __PRE__KEY = '__PRE__KEY'
|
||||
|
||||
it('use setStorage set cache in localStorage and sessionStorage', () => {
|
||||
setStorage(__DEMO__KEY, __DEMO__VALUE, 'sessionStorage')
|
||||
setStorage(__DEMO__KEY, __DEMO__VALUE, 'localStorage')
|
||||
|
||||
expect(hasStorage(__DEMO__KEY, 'sessionStorage')).toBe(true)
|
||||
expect(hasStorage(__DEMO__KEY, 'localStorage')).toBe(true)
|
||||
})
|
||||
|
||||
it('use getStorage get cache', () => {
|
||||
expect(getStorage(__DEMO__KEY, 'sessionStorage')).toBe(__DEMO__VALUE)
|
||||
expect(getStorage(__DEMO__KEY, 'localStorage')).toBe(__DEMO__VALUE)
|
||||
})
|
||||
|
||||
it('use removeStorage remove cache', () => {
|
||||
removeStorage(__DEMO__KEY, 'sessionStorage')
|
||||
removeStorage(__DEMO__KEY, 'localStorage')
|
||||
|
||||
expect(hasStorage(__DEMO__KEY, 'sessionStorage')).toBe(false)
|
||||
expect(hasStorage(__DEMO__KEY, 'localStorage')).toBe(false)
|
||||
})
|
||||
|
||||
it('use removeStorage remove all localStorage and sessionStorage cache', () => {
|
||||
setStorage(__DEMO__KEY, __DEMO__VALUE, 'sessionStorage')
|
||||
setStorage(__DEMO__KEY, __DEMO__VALUE, 'localStorage')
|
||||
|
||||
removeStorage('__all_sessionStorage__', 'sessionStorage')
|
||||
removeStorage('__all_localStorage__', 'localStorage')
|
||||
|
||||
expect(hasStorage(__DEMO__KEY, 'sessionStorage')).toBe(false)
|
||||
expect(hasStorage(__DEMO__KEY, 'localStorage')).toBe(false)
|
||||
})
|
||||
|
||||
it('use removeStorage remove all cache', () => {
|
||||
setStorage(__DEMO__KEY, __DEMO__VALUE, 'sessionStorage')
|
||||
setStorage(__DEMO__KEY, __DEMO__VALUE, 'localStorage')
|
||||
|
||||
removeStorage('__all__', 'all')
|
||||
|
||||
expect(hasStorage(__DEMO__KEY, 'sessionStorage')).toBe(false)
|
||||
expect(hasStorage(__DEMO__KEY, 'localStorage')).toBe(false)
|
||||
})
|
||||
|
||||
it('setStorage with prefix', () => {
|
||||
setStorage(__DEMO__KEY, __DEMO__VALUE, 'sessionStorage', {
|
||||
prefix: true,
|
||||
prefixKey: __PRE__KEY,
|
||||
})
|
||||
setStorage(__DEMO__KEY, __DEMO__VALUE, 'localStorage', {
|
||||
prefix: true,
|
||||
prefixKey: __PRE__KEY,
|
||||
})
|
||||
|
||||
expect(
|
||||
hasStorage(__DEMO__KEY, 'sessionStorage', {
|
||||
prefix: true,
|
||||
prefixKey: __PRE__KEY,
|
||||
}),
|
||||
).toBe(true)
|
||||
expect(
|
||||
hasStorage(__DEMO__KEY, 'localStorage', {
|
||||
prefix: true,
|
||||
prefixKey: __PRE__KEY,
|
||||
}),
|
||||
).toBe(true)
|
||||
})
|
||||
|
||||
it('getStorage with prefix', () => {
|
||||
expect(
|
||||
getStorage(__DEMO__KEY, 'sessionStorage', {
|
||||
prefix: true,
|
||||
prefixKey: __PRE__KEY,
|
||||
}),
|
||||
).toBe(__DEMO__VALUE)
|
||||
expect(
|
||||
getStorage(__DEMO__KEY, 'localStorage', {
|
||||
prefix: true,
|
||||
prefixKey: __PRE__KEY,
|
||||
}),
|
||||
).toBe(__DEMO__VALUE)
|
||||
})
|
||||
|
||||
it('removeStorage with prefix', () => {
|
||||
removeStorage(__DEMO__KEY, 'sessionStorage', {
|
||||
prefix: true,
|
||||
prefixKey: __PRE__KEY,
|
||||
})
|
||||
removeStorage(__DEMO__KEY, 'localStorage', {
|
||||
prefix: true,
|
||||
prefixKey: __PRE__KEY,
|
||||
})
|
||||
|
||||
expect(
|
||||
hasStorage(__DEMO__KEY, 'sessionStorage', {
|
||||
prefix: true,
|
||||
prefixKey: __PRE__KEY,
|
||||
}),
|
||||
).toBe(false)
|
||||
expect(
|
||||
hasStorage(__DEMO__KEY, 'localStorage', {
|
||||
prefix: true,
|
||||
prefixKey: __PRE__KEY,
|
||||
}),
|
||||
).toBe(false)
|
||||
})
|
||||
})
|
36
__test__/components/modal.spec.ts
Normal file
36
__test__/components/modal.spec.ts
Normal file
@ -0,0 +1,36 @@
|
||||
import { RModal } from '../../src/components/base/RModal/index'
|
||||
import { mount } from '@vue/test-utils'
|
||||
|
||||
describe('RModal', () => {
|
||||
it('should execute the onAfterEnter callback', () => {
|
||||
mount(RModal, {
|
||||
props: {
|
||||
show: true,
|
||||
onAfterEnter: () => {
|
||||
assert(true)
|
||||
},
|
||||
},
|
||||
slots: {
|
||||
default: h('div', 'Hello World'),
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
it('should render a modal', async () => {
|
||||
const wrapper = mount(RModal, {
|
||||
props: {
|
||||
show: true,
|
||||
},
|
||||
slots: {
|
||||
default: h('div', 'Hello World'),
|
||||
},
|
||||
})
|
||||
const classStr = 'n-modal-container'
|
||||
|
||||
const modal = document.body.querySelector(`.${classStr}`)
|
||||
const modalClassList = Array.from(modal?.classList || [])
|
||||
|
||||
expect(modalClassList.length).not.toBe(0)
|
||||
expect(modalClassList.includes(classStr)).toBe(true)
|
||||
})
|
||||
})
|
49
__test__/dom/printDom.spec.tsx
Normal file
49
__test__/dom/printDom.spec.tsx
Normal file
@ -0,0 +1,49 @@
|
||||
import { printDom } from '../../src/utils/dom'
|
||||
import { mount } from '@vue/test-utils'
|
||||
import renderHook from '../utils/renderHook'
|
||||
|
||||
// happy-dom 官方有一个 bug,无法使用 canvas.toDataURL 方法。所以该模块单测暂时无法通过
|
||||
describe('printDom', () => {
|
||||
// let count = 1
|
||||
// const domRef = ref<HTMLElement>()
|
||||
// const canvas = document.createElement('canvas')
|
||||
// canvas.width = 100
|
||||
// canvas.height = 100
|
||||
// console.log('canvas.toDataURL result', canvas.toDataURL)
|
||||
// const wrapper = mount(
|
||||
// defineComponent({
|
||||
// setup() {
|
||||
// const print = () => {
|
||||
// count = 2
|
||||
// printDom(canvas, {
|
||||
// domToImageOptions: {
|
||||
// created: () => {
|
||||
// count = 2
|
||||
// },
|
||||
// },
|
||||
// })
|
||||
// }
|
||||
// return {
|
||||
// domRef,
|
||||
// print,
|
||||
// }
|
||||
// },
|
||||
// render() {
|
||||
// const { print } = this
|
||||
// return (
|
||||
// <>
|
||||
// <div ref="domRef">print html</div>
|
||||
// <button onClick={print.bind(this)}>print</button>
|
||||
// </>
|
||||
// )
|
||||
// },
|
||||
// }),
|
||||
// )
|
||||
// it('print dom', () => {
|
||||
// const button = wrapper.find('button')
|
||||
// button.trigger('click')
|
||||
// expect(count).toBe(2)
|
||||
// })
|
||||
|
||||
it('print dom', () => {})
|
||||
})
|
19
__test__/element/autoPrefixStyle.spec.ts
Normal file
19
__test__/element/autoPrefixStyle.spec.ts
Normal file
@ -0,0 +1,19 @@
|
||||
import { autoPrefixStyle } from '../../src/utils/element'
|
||||
|
||||
describe('autoPrefixStyle', () => {
|
||||
it('should be defined', () => {
|
||||
expect(autoPrefixStyle).toBeDefined()
|
||||
})
|
||||
|
||||
it('should complete css prefix', () => {
|
||||
const result = autoPrefixStyle('transform')
|
||||
|
||||
expect(result).toEqual({
|
||||
webkitTransform: 'transform',
|
||||
mozTransform: 'transform',
|
||||
msTransform: 'transform',
|
||||
oTransform: 'transform',
|
||||
transform: 'transform',
|
||||
})
|
||||
})
|
||||
})
|
68
__test__/element/classMethods.spec.tsx
Normal file
68
__test__/element/classMethods.spec.tsx
Normal file
@ -0,0 +1,68 @@
|
||||
import { setClass, hasClass, removeClass } from '../../src/utils/element'
|
||||
import createRefElement from '../utils/createRefElement'
|
||||
|
||||
describe('setClass', () => {
|
||||
const wrapper = createRefElement()
|
||||
const CLASS_NAME = 'test'
|
||||
const CLASS_NAME_2 = 'test2'
|
||||
|
||||
it('set ref element class', () => {
|
||||
setClass(wrapper.element, CLASS_NAME)
|
||||
|
||||
const classList = Array.from(wrapper.element.classList)
|
||||
|
||||
expect(classList.includes(CLASS_NAME)).toBe(true)
|
||||
})
|
||||
|
||||
it('set ref element class with multiple class names', () => {
|
||||
setClass(wrapper.element, `${CLASS_NAME} ${CLASS_NAME_2}`)
|
||||
|
||||
const classList = Array.from(wrapper.element.classList)
|
||||
|
||||
expect(classList.includes(CLASS_NAME)).toBe(true)
|
||||
expect(classList.includes(CLASS_NAME_2)).toBe(true)
|
||||
})
|
||||
|
||||
it('set ref element class with multiple class names use array params', () => {
|
||||
setClass(wrapper.element, [CLASS_NAME, CLASS_NAME_2])
|
||||
|
||||
const classList = Array.from(wrapper.element.classList)
|
||||
|
||||
expect(classList.includes(CLASS_NAME)).toBe(true)
|
||||
expect(classList.includes(CLASS_NAME_2)).toBe(true)
|
||||
})
|
||||
|
||||
it('get ref element class', () => {
|
||||
setClass(wrapper.element, CLASS_NAME)
|
||||
|
||||
const hasClassResult = hasClass(wrapper.element, CLASS_NAME)
|
||||
|
||||
expect(hasClassResult.value).toBe(true)
|
||||
})
|
||||
|
||||
it('get ref element class with multiple class names', () => {
|
||||
setClass(wrapper.element, `${CLASS_NAME} ${CLASS_NAME_2}`)
|
||||
|
||||
const hasClassResult = hasClass(wrapper.element, CLASS_NAME)
|
||||
|
||||
expect(hasClassResult.value).toBe(true)
|
||||
})
|
||||
|
||||
it('get ref element class with multiple class names use array params', () => {
|
||||
setClass(wrapper.element, [CLASS_NAME, CLASS_NAME_2])
|
||||
|
||||
const hasClassResult = hasClass(wrapper.element, CLASS_NAME)
|
||||
|
||||
expect(hasClassResult.value).toBe(true)
|
||||
})
|
||||
|
||||
it('remove ref element class', () => {
|
||||
setClass(wrapper.element, CLASS_NAME)
|
||||
|
||||
removeClass(wrapper.element, CLASS_NAME)
|
||||
|
||||
const classList = Array.from(wrapper.element.classList)
|
||||
|
||||
expect(classList.includes(CLASS_NAME)).toBe(false)
|
||||
})
|
||||
})
|
23
__test__/element/colorToRgba.spec.ts
Normal file
23
__test__/element/colorToRgba.spec.ts
Normal file
@ -0,0 +1,23 @@
|
||||
import { colorToRgba } from '../../src/utils/element'
|
||||
|
||||
describe('colorToRgba', () => {
|
||||
it('should be defined', () => {
|
||||
expect(colorToRgba).toBeDefined()
|
||||
})
|
||||
|
||||
it('should return rgba color', () => {
|
||||
expect(colorToRgba('rgb(255, 255, 255)', 0.5)).toBe(
|
||||
'rgba(255, 255, 255, 0.5)',
|
||||
)
|
||||
expect(colorToRgba('rgba(255, 255, 255, 0.5)', 0.5)).toBe(
|
||||
'rgba(255, 255, 255, 0.5)',
|
||||
)
|
||||
expect(colorToRgba('#fff', 0.1)).toBe('rgba(255, 255, 255, 0.1)')
|
||||
expect(colorToRgba('#000000', 0.1)).toBe('rgba(0, 0, 0, 0.1)')
|
||||
expect(colorToRgba('#fffffafa', 0.1)).toBe('rgba(255, 255, 250, 0.98)')
|
||||
})
|
||||
|
||||
it('should return input color', () => {
|
||||
expect(colorToRgba('hi')).toBe('hi')
|
||||
})
|
||||
})
|
17
__test__/element/completeSize.spec.ts
Normal file
17
__test__/element/completeSize.spec.ts
Normal file
@ -0,0 +1,17 @@
|
||||
import { completeSize } from '../../src/utils/element'
|
||||
|
||||
describe('completeSize', () => {
|
||||
it('should be defined', () => {
|
||||
expect(completeSize).toBeDefined()
|
||||
})
|
||||
|
||||
it('should return size', () => {
|
||||
expect(completeSize('100px')).toBe('100px')
|
||||
expect(completeSize('100%')).toBe('100%')
|
||||
expect(completeSize('100vw')).toBe('100vw')
|
||||
})
|
||||
|
||||
it('should return default size', () => {
|
||||
expect(completeSize(0)).toBe('0px')
|
||||
})
|
||||
})
|
52
__test__/element/queryElements.spec.ts
Normal file
52
__test__/element/queryElements.spec.ts
Normal file
@ -0,0 +1,52 @@
|
||||
import { queryElements } from '../../src/utils/element'
|
||||
|
||||
describe('queryElements', () => {
|
||||
const div = document.createElement('div')
|
||||
const CLASS_NAME = 'demo'
|
||||
const ATTR_KEY = 'attr_key'
|
||||
const ATTR_VALUE = 'attr_value'
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(queryElements).toBeDefined()
|
||||
})
|
||||
|
||||
it('should return empty array', () => {
|
||||
const el = queryElements('.demo')
|
||||
|
||||
expect(el?.length).toBe(0)
|
||||
})
|
||||
|
||||
it('should return element list', () => {
|
||||
div.parentNode?.removeChild(div)
|
||||
|
||||
div.classList.add(CLASS_NAME)
|
||||
document.body.appendChild(div)
|
||||
|
||||
const el = queryElements('.demo')
|
||||
|
||||
expect(el?.length).toBe(1)
|
||||
})
|
||||
|
||||
it('should return default element', () => {
|
||||
div.parentNode?.removeChild(div)
|
||||
|
||||
const el = queryElements('.demo', {
|
||||
defaultElement: document.body,
|
||||
})
|
||||
|
||||
expect(el?.length).toBe(1)
|
||||
})
|
||||
|
||||
it('should return element list by attr', () => {
|
||||
div.parentNode?.removeChild(div)
|
||||
|
||||
div.setAttribute(ATTR_KEY, ATTR_VALUE)
|
||||
document.body.appendChild(div)
|
||||
|
||||
const el = queryElements(`attr:${ATTR_KEY}`)
|
||||
const el2 = queryElements(`attr:${ATTR_KEY}=${ATTR_VALUE}`)
|
||||
|
||||
expect(el?.length).toBe(1)
|
||||
expect(el2?.length).toBe(1)
|
||||
})
|
||||
})
|
71
__test__/element/styleMethods.spec.ts
Normal file
71
__test__/element/styleMethods.spec.ts
Normal file
@ -0,0 +1,71 @@
|
||||
import { setStyle, removeStyle } from '../../src/utils/element'
|
||||
import createRefElement from '../utils/createRefElement'
|
||||
|
||||
describe('setStyle', () => {
|
||||
const div = document.createElement('div')
|
||||
const removeKeys = ['width', 'height']
|
||||
const wrapper = createRefElement()
|
||||
|
||||
document.body.appendChild(div)
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(setStyle).toBeDefined()
|
||||
})
|
||||
|
||||
it('should set style', () => {
|
||||
removeStyle(div, removeKeys)
|
||||
|
||||
setStyle(div, {
|
||||
width: '100px',
|
||||
height: '100px',
|
||||
})
|
||||
|
||||
expect(div.style.width).toBe('100px')
|
||||
expect(div.style.height).toBe('100px')
|
||||
})
|
||||
|
||||
it('should set style with string', () => {
|
||||
removeStyle(div, removeKeys)
|
||||
|
||||
setStyle(div, 'width: 100px; height: 100px;')
|
||||
|
||||
expect(div.style.width).toBe('100px')
|
||||
expect(div.style.height).toBe('100px')
|
||||
})
|
||||
|
||||
it('should set style with string array', () => {
|
||||
removeStyle(div, removeKeys)
|
||||
|
||||
setStyle(div, ['width: 100px', 'height: 100px'])
|
||||
|
||||
expect(div.style.width).toBe('100px')
|
||||
expect(div.style.height).toBe('100px')
|
||||
})
|
||||
|
||||
it('should set style with css variable', () => {
|
||||
removeStyle(div, ['--width', '--height'])
|
||||
|
||||
setStyle(div, {
|
||||
'--width': '100px',
|
||||
'--height': '100px',
|
||||
})
|
||||
|
||||
expect(div.style.getPropertyValue('--width')).toBe('100px')
|
||||
expect(div.style.getPropertyValue('--height')).toBe('100px')
|
||||
})
|
||||
|
||||
it('should set style to ref element', () => {
|
||||
const element = wrapper.vm.domRef as HTMLElement
|
||||
const style = element.style
|
||||
|
||||
removeStyle(element, removeKeys)
|
||||
|
||||
setStyle(element, {
|
||||
width: '100px',
|
||||
height: '100px',
|
||||
})
|
||||
|
||||
expect(style.width).toBe('100px')
|
||||
expect(style.height).toBe('100px')
|
||||
})
|
||||
})
|
18
__test__/hooks/useAppNavigation.spec.ts
Normal file
18
__test__/hooks/useAppNavigation.spec.ts
Normal file
@ -0,0 +1,18 @@
|
||||
import { useAppNavigation } from '../../src/hooks/template/useAppNavigation'
|
||||
import { useMenuGetters } from '../../src/store'
|
||||
import setupMiniApp from '../utils/setupMiniApp'
|
||||
|
||||
describe('useAppNavigation', async () => {
|
||||
await setupMiniApp()
|
||||
|
||||
const { navigationTo } = useAppNavigation()
|
||||
const { getMenuOptions } = useMenuGetters()
|
||||
|
||||
it('navigationTo', () => {
|
||||
const [dashboard] = getMenuOptions.value
|
||||
|
||||
expect(navigationTo(dashboard.fullPath)).toBeUndefined()
|
||||
expect(navigationTo(dashboard)).toBeUndefined()
|
||||
expect(navigationTo(0)).toBeUndefined()
|
||||
})
|
||||
})
|
51
__test__/hooks/useAppRoot.spec.ts
Normal file
51
__test__/hooks/useAppRoot.spec.ts
Normal file
@ -0,0 +1,51 @@
|
||||
import setupMiniApp from '../utils/setupMiniApp'
|
||||
import { useAppRoot } from '../../src/hooks/template/useAppRoot'
|
||||
|
||||
describe('useAppRoot', async () => {
|
||||
await setupMiniApp()
|
||||
|
||||
const { setRootRoute } = useAppRoot()
|
||||
|
||||
it(`should return '/test' and 'test'`, () => {
|
||||
setRootRoute({
|
||||
path: '/test',
|
||||
name: 'test',
|
||||
})
|
||||
|
||||
const { getRootPath, getRootName } = useAppRoot()
|
||||
|
||||
expect(getRootPath.value).toBe('/test')
|
||||
expect(getRootName.value).toBe('test')
|
||||
})
|
||||
|
||||
it(`should be returned a object like: {path: /test2, name: test2}`, () => {
|
||||
const baseRootRoute = {
|
||||
path: '/test2',
|
||||
name: 'test2',
|
||||
}
|
||||
|
||||
setRootRoute(baseRootRoute)
|
||||
|
||||
const { getRootRoute } = useAppRoot()
|
||||
|
||||
expect(getRootRoute.value).toEqual(baseRootRoute)
|
||||
})
|
||||
|
||||
it('should update root route when setRootRoute is called', () => {
|
||||
const baseRootRoute = {
|
||||
path: '/test3',
|
||||
name: 'test3',
|
||||
}
|
||||
|
||||
setRootRoute({
|
||||
path: '/test3',
|
||||
name: 'test3',
|
||||
})
|
||||
|
||||
const { getRootPath, getRootName, getRootRoute } = useAppRoot()
|
||||
|
||||
expect(getRootPath.value).toBe('/test3')
|
||||
expect(getRootName.value).toBe('test3')
|
||||
expect(getRootRoute.value).toEqual(baseRootRoute)
|
||||
})
|
||||
})
|
67
__test__/hooks/useBadge.spec.ts
Normal file
67
__test__/hooks/useBadge.spec.ts
Normal file
@ -0,0 +1,67 @@
|
||||
import setupMiniApp from '../utils/setupMiniApp'
|
||||
import { useBadge } from '../../src/hooks/template/useBadge'
|
||||
import { useMenuGetters } from '../../src/store'
|
||||
|
||||
import type { AppMenuExtraOptions } from '../../src/router/types'
|
||||
|
||||
describe('useBadge', async () => {
|
||||
await setupMiniApp()
|
||||
|
||||
const { show, hidden, update } = useBadge()
|
||||
const { getMenuOptions } = useMenuGetters()
|
||||
|
||||
const baseBadge = (extra: AppMenuExtraOptions) =>
|
||||
Object.assign(
|
||||
{},
|
||||
{
|
||||
label: 'new',
|
||||
type: 'error',
|
||||
} as AppMenuExtraOptions,
|
||||
extra,
|
||||
)
|
||||
|
||||
it('should hide badge', () => {
|
||||
const [dashboard] = getMenuOptions.value
|
||||
|
||||
update(
|
||||
dashboard,
|
||||
baseBadge({
|
||||
show: false,
|
||||
label: 'new',
|
||||
}),
|
||||
)
|
||||
hidden(dashboard)
|
||||
|
||||
expect(dashboard.meta.extra?.show).toBe(false)
|
||||
})
|
||||
|
||||
it('should show badge', () => {
|
||||
const [dashboard] = getMenuOptions.value
|
||||
|
||||
update(
|
||||
dashboard,
|
||||
baseBadge({
|
||||
show: true,
|
||||
label: 'new',
|
||||
}),
|
||||
)
|
||||
show(dashboard)
|
||||
|
||||
expect(dashboard.meta.extra?.show).toBe(true)
|
||||
})
|
||||
|
||||
it('should show badge with new label', () => {
|
||||
const [dashboard] = getMenuOptions.value
|
||||
const label = 'update new'
|
||||
|
||||
update(
|
||||
dashboard,
|
||||
baseBadge({
|
||||
show: true,
|
||||
label,
|
||||
}),
|
||||
)
|
||||
|
||||
expect(dashboard.meta.extra?.label).toBe(label)
|
||||
})
|
||||
})
|
50
__test__/hooks/useContextmenuCoordinate.spec.tsx
Normal file
50
__test__/hooks/useContextmenuCoordinate.spec.tsx
Normal file
@ -0,0 +1,50 @@
|
||||
import { useContextmenuCoordinate } from '../../src/hooks/components/useContextmenuCoordinate'
|
||||
import renderHook from '../utils/renderHook'
|
||||
import createRefElement from '../utils/createRefElement'
|
||||
|
||||
describe('useContextmenuCoordinate', () => {
|
||||
const wrapperRef = createRefElement()
|
||||
const [result] = renderHook(() =>
|
||||
useContextmenuCoordinate(wrapperRef.element),
|
||||
)
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(useContextmenuCoordinate).toBeDefined()
|
||||
})
|
||||
|
||||
it('should update show value to true when contextmenu event is triggered', async () => {
|
||||
wrapperRef.element.dispatchEvent(new MouseEvent('contextmenu'))
|
||||
|
||||
await nextTick()
|
||||
|
||||
expect(result.show.value).toBe(true)
|
||||
})
|
||||
|
||||
it('should update show value when calling updateShow method', async () => {
|
||||
result.updateShow(false)
|
||||
|
||||
await nextTick()
|
||||
|
||||
expect(result.show.value).toBe(false)
|
||||
|
||||
result.updateShow(true)
|
||||
|
||||
await nextTick()
|
||||
|
||||
expect(result.show.value).toBe(true)
|
||||
})
|
||||
|
||||
it('should get the clientX and clientY value when contextmenu event is triggered', async () => {
|
||||
const event = new MouseEvent('contextmenu', {
|
||||
clientX: 100,
|
||||
clientY: 200,
|
||||
})
|
||||
|
||||
wrapperRef.element.dispatchEvent(event)
|
||||
|
||||
await nextTick()
|
||||
|
||||
expect(result.x.value).toBe(100)
|
||||
expect(result.y.value).toBe(200)
|
||||
})
|
||||
})
|
101
__test__/hooks/useDayjs.spec.ts
Normal file
101
__test__/hooks/useDayjs.spec.ts
Normal file
@ -0,0 +1,101 @@
|
||||
import { useDayjs } from '../../src/hooks/web/useDayjs'
|
||||
import dayjs from 'dayjs'
|
||||
|
||||
describe('useDayjs', () => {
|
||||
const {
|
||||
locale,
|
||||
getStartAndEndOfDay,
|
||||
format,
|
||||
isDayjs,
|
||||
daysDiff,
|
||||
isDateInRange,
|
||||
} = useDayjs()
|
||||
|
||||
it('check whether the locale method runs properly', () => {
|
||||
const m = {
|
||||
locale,
|
||||
}
|
||||
const localSpy = vi.spyOn(m, 'locale')
|
||||
|
||||
m.locale('en-US')
|
||||
m.locale('zh-CN')
|
||||
|
||||
expect(localSpy).toHaveBeenCalledTimes(2)
|
||||
})
|
||||
|
||||
it('gets Returns the current date, start time, and end time of the current date ', () => {
|
||||
const formatOptions = {
|
||||
format: 'YYYY/M/DD HH:mm:ss',
|
||||
}
|
||||
const formatOptions2 = {
|
||||
format: 'YYYY/M/DD',
|
||||
}
|
||||
const {
|
||||
today,
|
||||
startOfDay,
|
||||
endOfDay,
|
||||
formatToday,
|
||||
formatStartOfDay,
|
||||
formatEndOfDay,
|
||||
} = getStartAndEndOfDay(formatOptions)
|
||||
const _today = dayjs(new Date()).format(formatOptions2.format)
|
||||
const _startOfDay = dayjs(new Date().setHours(0, 0, 0, 0)).format(
|
||||
formatOptions.format,
|
||||
)
|
||||
const _endOfDay = dayjs(new Date().setHours(23, 59, 59, 999)).format(
|
||||
formatOptions.format,
|
||||
)
|
||||
|
||||
expect(format(today, formatOptions2)).toBe(_today)
|
||||
expect(format(startOfDay, formatOptions)).toBe(_startOfDay)
|
||||
expect(format(endOfDay, formatOptions)).toBe(_endOfDay)
|
||||
expect(format(formatToday, formatOptions2)).toBe(_today)
|
||||
expect(formatStartOfDay).toBe(_startOfDay)
|
||||
expect(formatEndOfDay).toBe(_endOfDay)
|
||||
})
|
||||
|
||||
it('check format method', () => {
|
||||
const formatOptions1 = {
|
||||
format: 'YYYY/M/DD HH:mm:ss',
|
||||
}
|
||||
const formatOptions2 = {
|
||||
format: 'YYYY/M/DD',
|
||||
}
|
||||
const formatOptions3 = {
|
||||
format: 'YYYY-MM-DD HH:mm:ss',
|
||||
}
|
||||
const formatOptions4 = {
|
||||
format: 'YYYY-MM-DD',
|
||||
}
|
||||
const date = new Date('2022-01-11 00:00:00')
|
||||
|
||||
expect(format(date, formatOptions1)).toBe('2022/1/11 00:00:00')
|
||||
expect(format(date, formatOptions2)).toBe('2022/1/11')
|
||||
expect(format(date, formatOptions3)).toBe('2022-01-11 00:00:00')
|
||||
expect(format(date, formatOptions4)).toBe('2022-01-11')
|
||||
})
|
||||
|
||||
it('check isDayjs object', () => {
|
||||
const { today } = getStartAndEndOfDay()
|
||||
|
||||
expect(isDayjs(new Date())).toBe(false)
|
||||
expect(isDayjs(today)).toBe(true)
|
||||
})
|
||||
|
||||
it('check daysDiff method', () => {
|
||||
expect(daysDiff('2022-01-11', '2022-01-12')).toBe(1)
|
||||
expect(daysDiff('2021-01-11', '2022-01-12')).toBe(366)
|
||||
expect(daysDiff('2023-01-11', '2022-01-12')).toBe(-364)
|
||||
})
|
||||
|
||||
it('check isDateInRange method', () => {
|
||||
const range = {
|
||||
start: '2023-01-15',
|
||||
end: '2023-01-20',
|
||||
}
|
||||
|
||||
expect(isDateInRange('2023-01-16', range)).toBe(true)
|
||||
expect(isDateInRange('2023-01-15', range)).toBe(false)
|
||||
expect(isDateInRange('2023-01-20', range)).toBe(false)
|
||||
})
|
||||
})
|
116
__test__/hooks/useDevice.spec.ts
Normal file
116
__test__/hooks/useDevice.spec.ts
Normal file
@ -0,0 +1,116 @@
|
||||
import { useDevice } from '../../src/hooks/web/useDevice'
|
||||
|
||||
describe('useDevice', () => {
|
||||
const addEventListenerSpy = vi.spyOn(window, 'addEventListener')
|
||||
const matchMediaSpy = vi
|
||||
.spyOn(window, 'matchMedia')
|
||||
.mockImplementation((query) => ({
|
||||
matches: false,
|
||||
media: query,
|
||||
onchange: null,
|
||||
addListener: vi.fn(),
|
||||
removeListener: vi.fn(),
|
||||
addEventListener: vi.fn(),
|
||||
removeEventListener: vi.fn(),
|
||||
dispatchEvent: vi.fn(),
|
||||
}))
|
||||
|
||||
beforeEach(() => {
|
||||
addEventListenerSpy.mockClear()
|
||||
matchMediaSpy.mockClear()
|
||||
})
|
||||
|
||||
afterAll(() => {
|
||||
addEventListenerSpy.mockRestore()
|
||||
matchMediaSpy.mockRestore()
|
||||
})
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(useDevice).toBeDefined()
|
||||
})
|
||||
|
||||
it('should work', () => {
|
||||
const { width, height } = useDevice({
|
||||
initialWidth: 100,
|
||||
initialHeight: 200,
|
||||
})
|
||||
|
||||
expect(width.value).toBe(window.innerWidth)
|
||||
expect(height.value).toBe(window.innerHeight)
|
||||
})
|
||||
|
||||
it('should exclude scrollbar', () => {
|
||||
const { width, height } = useDevice({
|
||||
initialWidth: 100,
|
||||
initialHeight: 200,
|
||||
includeScrollbar: false,
|
||||
})
|
||||
|
||||
expect(width.value).toBe(window.document.documentElement.clientWidth)
|
||||
expect(height.value).toBe(window.document.documentElement.clientHeight)
|
||||
})
|
||||
|
||||
it('sets handler for window resize event', async () => {
|
||||
useDevice({
|
||||
initialWidth: 100,
|
||||
initialHeight: 200,
|
||||
listenOrientation: false,
|
||||
})
|
||||
|
||||
await nextTick()
|
||||
|
||||
expect(addEventListenerSpy).toHaveBeenCalledOnce()
|
||||
|
||||
const call = addEventListenerSpy.mock.calls[0]
|
||||
|
||||
expect(call[0]).toEqual('resize')
|
||||
expect(call[2]).toEqual({
|
||||
passive: true,
|
||||
})
|
||||
})
|
||||
|
||||
it('sets handler for window.matchMedia("(orientation: portrait)") change event', async () => {
|
||||
useDevice({
|
||||
initialWidth: 100,
|
||||
initialHeight: 200,
|
||||
})
|
||||
|
||||
await nextTick()
|
||||
|
||||
expect(addEventListenerSpy).toHaveBeenCalledTimes(1)
|
||||
expect(matchMediaSpy).toHaveBeenCalledTimes(1)
|
||||
|
||||
const call = matchMediaSpy.mock.calls[0]
|
||||
|
||||
expect(call[0]).toEqual('(orientation: portrait)')
|
||||
})
|
||||
|
||||
it('should update width and height on window resize', async () => {
|
||||
const { width, height } = useDevice({
|
||||
initialWidth: 100,
|
||||
initialHeight: 200,
|
||||
})
|
||||
|
||||
window.innerWidth = 300
|
||||
window.innerHeight = 400
|
||||
|
||||
window.dispatchEvent(new Event('resize'))
|
||||
|
||||
await nextTick()
|
||||
|
||||
expect(width.value).toBe(300)
|
||||
expect(height.value).toBe(400)
|
||||
})
|
||||
|
||||
it('should update isTabletOrSmaller on window resize', async () => {
|
||||
const { isTabletOrSmaller } = useDevice()
|
||||
|
||||
window.innerWidth = 300
|
||||
|
||||
window.dispatchEvent(new Event('resize'))
|
||||
|
||||
await nextTick()
|
||||
|
||||
expect(isTabletOrSmaller.value).toBe(true)
|
||||
})
|
||||
})
|
54
__test__/hooks/useElementFullscreen.spec.ts
Normal file
54
__test__/hooks/useElementFullscreen.spec.ts
Normal file
@ -0,0 +1,54 @@
|
||||
import { useElementFullscreen } from '../../src/hooks/web/useElementFullscreen'
|
||||
|
||||
describe('useElementFullscreen', async () => {
|
||||
const div = document.createElement('div')
|
||||
const transition = 'all 0.3s var(--r-bezier)'
|
||||
const __ID__ = '__ID__'
|
||||
|
||||
div.setAttribute('id', __ID__)
|
||||
document.body.appendChild(div)
|
||||
|
||||
const resetDivStyle = () => {
|
||||
const element = document.getElementById(__ID__)
|
||||
|
||||
if (element) {
|
||||
element.style.transition = ''
|
||||
}
|
||||
}
|
||||
|
||||
const { enter, exit, toggleFullscreen } = useElementFullscreen(div)
|
||||
|
||||
it('should enter fullscreen', async () => {
|
||||
resetDivStyle()
|
||||
enter()
|
||||
|
||||
await nextTick()
|
||||
|
||||
expect(div.style.transition).toBe(transition)
|
||||
})
|
||||
|
||||
it('should exit fullscreen', async () => {
|
||||
resetDivStyle()
|
||||
exit()
|
||||
|
||||
await nextTick()
|
||||
|
||||
expect(div.style.transition).toBe('')
|
||||
})
|
||||
|
||||
it('should toggle fullscreen', async () => {
|
||||
resetDivStyle()
|
||||
enter()
|
||||
enter() // 为了兼容测试环境,故而调用两次
|
||||
|
||||
await nextTick()
|
||||
|
||||
expect(div.style.transition).toBe(transition)
|
||||
|
||||
toggleFullscreen()
|
||||
|
||||
await nextTick()
|
||||
|
||||
expect(!div.style.transition).not.toBe(true)
|
||||
})
|
||||
})
|
66
__test__/hooks/usePagination.spec.ts
Normal file
66
__test__/hooks/usePagination.spec.ts
Normal file
@ -0,0 +1,66 @@
|
||||
import { usePagination } from '../../src/hooks/web/usePagination'
|
||||
|
||||
describe('usePagination', () => {
|
||||
let count = 0
|
||||
const defaultOptions = {
|
||||
itemCount: 200,
|
||||
page: 1,
|
||||
pageSize: 10,
|
||||
}
|
||||
|
||||
const [
|
||||
_,
|
||||
{
|
||||
getItemCount,
|
||||
getCallback,
|
||||
getPage,
|
||||
getPageSize,
|
||||
getPagination,
|
||||
setItemCount,
|
||||
setPage,
|
||||
setPageSize,
|
||||
},
|
||||
] = usePagination(() => {
|
||||
count++
|
||||
}, defaultOptions)
|
||||
|
||||
it('should get current itemCount', () => {
|
||||
setItemCount(200)
|
||||
|
||||
expect(getItemCount()).toBe(200)
|
||||
|
||||
setItemCount(100)
|
||||
|
||||
expect(getItemCount()).toBe(100)
|
||||
})
|
||||
|
||||
it('should get current page', () => {
|
||||
setPage(1)
|
||||
|
||||
expect(getPage()).toBe(1)
|
||||
})
|
||||
|
||||
it('should get current pageSize', () => {
|
||||
setPageSize(10)
|
||||
|
||||
expect(getPageSize()).toBe(10)
|
||||
})
|
||||
|
||||
it('should get current pagination', () => {
|
||||
setItemCount(200)
|
||||
|
||||
expect(getPagination()).toMatchObject(defaultOptions)
|
||||
})
|
||||
|
||||
it('should update count when page or pageSize changes', () => {
|
||||
count = 0
|
||||
|
||||
setPage(2)
|
||||
|
||||
expect(count).toBe(1)
|
||||
|
||||
setPageSize(20)
|
||||
|
||||
expect(count).toBe(2)
|
||||
})
|
||||
})
|
167
__test__/hooks/useSiderBar.spec.ts
Normal file
167
__test__/hooks/useSiderBar.spec.ts
Normal file
@ -0,0 +1,167 @@
|
||||
import setupMiniApp from '../utils/setupMiniApp'
|
||||
import { useSiderBar } from '../../src/hooks/template/useSiderBar'
|
||||
import { useMenuGetters, useMenuActions } from '../../src/store'
|
||||
import { useVueRouter } from '../../src/hooks/web/useVueRouter'
|
||||
|
||||
import type { AppMenuOption, MenuTagOptions } from '../../src/types/modules/app'
|
||||
|
||||
describe('useSiderBar', async () => {
|
||||
await setupMiniApp()
|
||||
|
||||
const { setMenuTagOptions, resolveOption } = useMenuActions()
|
||||
const {
|
||||
close,
|
||||
closeAll,
|
||||
closeRight,
|
||||
closeLeft,
|
||||
closeOther,
|
||||
getCurrentTagIndex,
|
||||
checkCloseRight,
|
||||
checkCloseLeft,
|
||||
} = useSiderBar()
|
||||
|
||||
const updateMenuTagOptions = () => {
|
||||
const { router } = useVueRouter()
|
||||
const routes = router.getRoutes() as unknown as AppMenuOption[]
|
||||
|
||||
routes.forEach((curr) =>
|
||||
setMenuTagOptions(
|
||||
resolveOption({
|
||||
...curr,
|
||||
fullPath: curr.path,
|
||||
}),
|
||||
true,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
it('should close target tag', async () => {
|
||||
updateMenuTagOptions()
|
||||
|
||||
const { getMenuOptions, getMenuTagOptions } = useMenuGetters()
|
||||
const [dashboard] = getMenuOptions.value
|
||||
const beforeIndex = getMenuTagOptions.value.findIndex(
|
||||
(curr) => curr.fullPath === dashboard.fullPath,
|
||||
)
|
||||
|
||||
close(dashboard.fullPath)
|
||||
|
||||
await nextTick()
|
||||
|
||||
const afterIndex = getMenuTagOptions.value.findIndex(
|
||||
(curr) => curr.fullPath === dashboard.fullPath,
|
||||
)
|
||||
|
||||
expect(beforeIndex).not.toBe(afterIndex)
|
||||
})
|
||||
|
||||
it('should close all tags', async () => {
|
||||
updateMenuTagOptions()
|
||||
|
||||
const { getMenuTagOptions } = useMenuGetters()
|
||||
|
||||
closeAll()
|
||||
|
||||
await nextTick()
|
||||
|
||||
const afterLength = getMenuTagOptions.value.length
|
||||
|
||||
expect(afterLength).toBe(1)
|
||||
})
|
||||
|
||||
it('should close right tags', async () => {
|
||||
updateMenuTagOptions()
|
||||
|
||||
const { getMenuOptions, getMenuTagOptions } = useMenuGetters()
|
||||
const [dashboard] = getMenuOptions.value
|
||||
const beforeIndex = getMenuTagOptions.value.findIndex(
|
||||
(curr) => curr.fullPath === dashboard.fullPath,
|
||||
)
|
||||
|
||||
expect(!!getMenuTagOptions.value[beforeIndex + 1]).toBe(true)
|
||||
|
||||
closeRight(dashboard.fullPath)
|
||||
|
||||
await nextTick()
|
||||
|
||||
const afterIndex = getMenuTagOptions.value.findIndex(
|
||||
(curr) => curr.fullPath === dashboard.fullPath,
|
||||
)
|
||||
|
||||
expect(getMenuTagOptions.value[afterIndex + 1]).toBe(void 0)
|
||||
})
|
||||
|
||||
it('should close left tags', async () => {
|
||||
updateMenuTagOptions()
|
||||
|
||||
const { getMenuOptions, getMenuTagOptions } = useMenuGetters()
|
||||
const [dashboard] = getMenuOptions.value
|
||||
|
||||
closeLeft(dashboard.fullPath)
|
||||
|
||||
await nextTick()
|
||||
|
||||
const afterIndex = getMenuTagOptions.value.findIndex(
|
||||
(curr) => curr.fullPath === dashboard.fullPath,
|
||||
)
|
||||
|
||||
expect(getMenuTagOptions.value[afterIndex - 1]).toBe(void 0)
|
||||
})
|
||||
|
||||
it('should get current tag index', async () => {
|
||||
updateMenuTagOptions()
|
||||
|
||||
const { getMenuOptions, getMenuTagOptions } = useMenuGetters()
|
||||
const [dashboard] = getMenuOptions.value
|
||||
|
||||
const index = getMenuOptions.value.findIndex(
|
||||
(curr) => curr.fullPath === dashboard.fullPath,
|
||||
)
|
||||
|
||||
expect(getCurrentTagIndex()).toBe(index)
|
||||
})
|
||||
|
||||
it('should close other tags', async () => {
|
||||
updateMenuTagOptions()
|
||||
|
||||
const { getMenuOptions, getMenuTagOptions } = useMenuGetters()
|
||||
const [dashboard] = getMenuOptions.value
|
||||
|
||||
closeOther(dashboard.fullPath)
|
||||
|
||||
await nextTick()
|
||||
|
||||
expect(getMenuTagOptions.value[0].fullPath).toBe(dashboard.fullPath)
|
||||
expect(getMenuTagOptions.value.length).toBe(1)
|
||||
})
|
||||
|
||||
it('check menuTagOptions left or right can close', async () => {
|
||||
updateMenuTagOptions()
|
||||
|
||||
const { getMenuOptions, getMenuTagOptions } = useMenuGetters()
|
||||
const [f, s] = getMenuOptions.value
|
||||
|
||||
closeRight(f.fullPath)
|
||||
|
||||
await nextTick()
|
||||
|
||||
const canClose = checkCloseRight(f.fullPath)
|
||||
|
||||
expect(canClose).toBe(false)
|
||||
|
||||
updateMenuTagOptions()
|
||||
|
||||
closeLeft(f.fullPath)
|
||||
|
||||
await nextTick()
|
||||
|
||||
const canCloseLeft = checkCloseLeft(f.fullPath)
|
||||
|
||||
expect(canCloseLeft).toBe(false)
|
||||
|
||||
updateMenuTagOptions()
|
||||
|
||||
expect(checkCloseRight(s.fullPath)).toBe(true)
|
||||
expect(checkCloseLeft(s.fullPath)).toBe(true)
|
||||
})
|
||||
})
|
38
__test__/hooks/useSpinning.spec.ts
Normal file
38
__test__/hooks/useSpinning.spec.ts
Normal file
@ -0,0 +1,38 @@
|
||||
import setupMiniApp from '../utils/setupMiniApp'
|
||||
import { useSpinning } from '../../src/hooks/template/useSpinning'
|
||||
import { setVariable, getVariableToRefs } from '../../src/global-variable'
|
||||
|
||||
describe('useSpinning', async () => {
|
||||
await setupMiniApp()
|
||||
|
||||
const { reload, openSpin, closeSpin } = useSpinning()
|
||||
const globalMainLayoutLoad = getVariableToRefs('globalMainLayoutLoad')
|
||||
|
||||
it('should open spinning', () => {
|
||||
openSpin()
|
||||
|
||||
expect(globalMainLayoutLoad.value).toBe(true)
|
||||
})
|
||||
|
||||
it('should close spinning', () => {
|
||||
openSpin()
|
||||
|
||||
expect(globalMainLayoutLoad.value).toBe(true)
|
||||
|
||||
closeSpin()
|
||||
|
||||
expect(globalMainLayoutLoad.value).toBe(true)
|
||||
})
|
||||
|
||||
it('should reload', () => {
|
||||
const wait = 1000
|
||||
|
||||
reload(wait)
|
||||
|
||||
expect(globalMainLayoutLoad.value).toBe(false)
|
||||
|
||||
setTimeout(() => {
|
||||
expect(globalMainLayoutLoad.value).toBe(true)
|
||||
}, wait)
|
||||
})
|
||||
})
|
46
__test__/hooks/useTheme.spec.ts
Normal file
46
__test__/hooks/useTheme.spec.ts
Normal file
@ -0,0 +1,46 @@
|
||||
import setupMiniApp from '../utils/setupMiniApp'
|
||||
import { useTheme } from '../../src/hooks/template/useTheme'
|
||||
|
||||
describe('useTheme', async () => {
|
||||
await setupMiniApp()
|
||||
|
||||
const { darkTheme, lightTheme, toggleTheme, getAppTheme } = useTheme()
|
||||
|
||||
it('should change to dark theme', () => {
|
||||
darkTheme()
|
||||
|
||||
expect(getAppTheme().theme).toBe(true)
|
||||
})
|
||||
|
||||
it('should change to light theme', () => {
|
||||
lightTheme()
|
||||
|
||||
expect(getAppTheme().theme).toBe(false)
|
||||
})
|
||||
|
||||
it('should toggle theme', () => {
|
||||
lightTheme()
|
||||
|
||||
expect(getAppTheme().theme).toBe(false)
|
||||
|
||||
toggleTheme()
|
||||
|
||||
expect(getAppTheme().theme).toBe(true)
|
||||
})
|
||||
|
||||
it('should return current theme', () => {
|
||||
darkTheme()
|
||||
|
||||
const { theme: _darkTheme, themeLabel: _darkThemeLabel } = getAppTheme()
|
||||
|
||||
expect(_darkTheme).toBe(true)
|
||||
expect(_darkThemeLabel).toBe('Dark')
|
||||
|
||||
lightTheme()
|
||||
|
||||
const { theme: __lightTheme, themeLabel: __lightThemeLabel } = getAppTheme()
|
||||
|
||||
expect(__lightTheme).toBe(false)
|
||||
expect(__lightThemeLabel).toBe('Light')
|
||||
})
|
||||
})
|
15
__test__/hooks/useVueRouter.spec.ts
Normal file
15
__test__/hooks/useVueRouter.spec.ts
Normal file
@ -0,0 +1,15 @@
|
||||
import setupMiniApp from '../utils/setupMiniApp'
|
||||
import { useVueRouter } from '../../src/hooks/web/useVueRouter'
|
||||
|
||||
describe('useVueRouter', async () => {
|
||||
await setupMiniApp()
|
||||
|
||||
const { router } = useVueRouter()
|
||||
|
||||
it('should get push and replace methods', () => {
|
||||
const { push, replace } = router
|
||||
|
||||
assert.isFunction(push)
|
||||
assert.isFunction(replace)
|
||||
})
|
||||
})
|
33
__test__/hooks/useWatermark.spec.ts
Normal file
33
__test__/hooks/useWatermark.spec.ts
Normal file
@ -0,0 +1,33 @@
|
||||
import setupMiniApp from '../utils/setupMiniApp'
|
||||
import { useWatermark } from '../../src/hooks/template/useWatermark'
|
||||
import { useSettingGetters } from '../../src/store'
|
||||
|
||||
describe('useWatermark', async () => {
|
||||
await setupMiniApp()
|
||||
|
||||
const { setWatermarkContent, showWatermark, hiddenWatermark } = useWatermark()
|
||||
|
||||
it('should set watermark content', () => {
|
||||
const { getWatermarkConfig } = useSettingGetters()
|
||||
const watermarkConfig = getWatermarkConfig.value
|
||||
const content = 'Ray Template Yes!'
|
||||
|
||||
setWatermarkContent(content)
|
||||
|
||||
expect(watermarkConfig.content).toBe(content)
|
||||
})
|
||||
|
||||
it('should update watermark', () => {
|
||||
showWatermark()
|
||||
|
||||
const { getWatermarkSwitch: show } = useSettingGetters()
|
||||
|
||||
expect(show.value).toBe(true)
|
||||
|
||||
hiddenWatermark()
|
||||
|
||||
const { getWatermarkSwitch: hidden } = useSettingGetters()
|
||||
|
||||
expect(hidden.value).toBe(false)
|
||||
})
|
||||
})
|
82
__test__/precision/index.spec.ts
Normal file
82
__test__/precision/index.spec.ts
Normal file
@ -0,0 +1,82 @@
|
||||
import {
|
||||
isCurrency,
|
||||
format,
|
||||
add,
|
||||
subtract,
|
||||
multiply,
|
||||
divide,
|
||||
distribute,
|
||||
} from '../../src/utils/precision'
|
||||
|
||||
describe('precision', () => {
|
||||
it('check value is currency object', () => {
|
||||
expect(isCurrency(1)).toBeFalsy()
|
||||
expect(isCurrency('1')).toBeFalsy()
|
||||
expect(isCurrency({})).toBeFalsy()
|
||||
expect(isCurrency({ s: 1 })).toBeFalsy()
|
||||
expect(isCurrency(add(1, 1))).toBeTruthy()
|
||||
})
|
||||
|
||||
it('format value', () => {
|
||||
expect(format(1)).toBe(1)
|
||||
expect(
|
||||
format(1.1, {
|
||||
type: 'number',
|
||||
}),
|
||||
).toBe(1.1)
|
||||
expect(
|
||||
format(1.11, {
|
||||
type: 'string',
|
||||
precision: 2,
|
||||
}),
|
||||
).toBe('1.11')
|
||||
expect(format(add(1, 1))).toBe(2)
|
||||
expect(format(add(0.1, 0.2))).toBe(0.3)
|
||||
})
|
||||
|
||||
it('add value', () => {
|
||||
expect(format(add(1, 1))).toBe(2)
|
||||
expect(format(add(0.1, 0.2))).toBe(0.3)
|
||||
expect(format(add(0.1, 0.2, 0.3))).toBe(0.6)
|
||||
expect(format(add(0.1, 0.2, 0.3, 0.4))).toBe(1)
|
||||
expect(format(add(0.1, 0.2, 0.3, 0.4, 0.5))).toBe(1.5)
|
||||
})
|
||||
|
||||
it('subtract value', () => {
|
||||
expect(format(subtract(1, 1))).toBe(0)
|
||||
expect(format(subtract(0.3, 0.2))).toBe(0.1)
|
||||
expect(format(subtract(0.6, 0.3, 0.2))).toBe(0.1)
|
||||
expect(format(subtract(1, 0.5, 0.4, 0.3, 0.2))).toBe(-0.4)
|
||||
})
|
||||
|
||||
it('multiply value', () => {
|
||||
expect(format(multiply(1, 1))).toBe(1)
|
||||
expect(format(multiply(0.1, 0.2))).toBe(0.02)
|
||||
expect(format(multiply(0.1, 0.2, 0.3))).toBe(0.006)
|
||||
expect(format(multiply(0.1, 0.2, 0.3, 0.4))).toBe(0.0024)
|
||||
expect(format(multiply(0.1, 0.2, 0.3, 0.4, 0.5))).toBe(0.0012)
|
||||
})
|
||||
|
||||
it('divide value', () => {
|
||||
expect(format(divide(1, 1))).toBe(1)
|
||||
expect(format(divide(0.1, 0.2))).toBe(0.5)
|
||||
expect(
|
||||
format(divide(0.1, 0.2, 0.3), {
|
||||
precision: 2,
|
||||
}),
|
||||
).toBe(1.67)
|
||||
})
|
||||
|
||||
it('distribute value', () => {
|
||||
expect(distribute(1, 1)).toEqual([1])
|
||||
expect(distribute(1, 0)).toEqual([1])
|
||||
expect(distribute(0, 3)).toEqual([0, 0, 0])
|
||||
expect(distribute(10, 3)).toEqual([3.33333334, 3.33333333, 3.33333333])
|
||||
expect(
|
||||
distribute(20, 3, {
|
||||
precision: 4,
|
||||
}),
|
||||
).toEqual([6.6667, 6.6667, 6.6666])
|
||||
expect(distribute(add(20, 1), 3)).toEqual([7, 7, 7])
|
||||
})
|
||||
})
|
16
__test__/utils/canUseDom.ts
Normal file
16
__test__/utils/canUseDom.ts
Normal file
@ -0,0 +1,16 @@
|
||||
/**
|
||||
*
|
||||
* @description
|
||||
* 判断是否可以操作 DOM。
|
||||
*
|
||||
* 如果可以操作 DOM,则返回 true,否则返回 false。
|
||||
*/
|
||||
const canUseDom = () => {
|
||||
return !!(
|
||||
typeof window !== 'undefined' &&
|
||||
window.document &&
|
||||
window.document.createElement
|
||||
)
|
||||
}
|
||||
|
||||
export default canUseDom
|
36
__test__/utils/createRefElement.tsx
Normal file
36
__test__/utils/createRefElement.tsx
Normal file
@ -0,0 +1,36 @@
|
||||
import { mount } from '@vue/test-utils'
|
||||
|
||||
/**
|
||||
*
|
||||
* @param slots 需要传递的插槽
|
||||
*
|
||||
* @description
|
||||
* 创建一个包含 ref 为 domRef 的组件。
|
||||
* 并且允许传递插槽。
|
||||
*
|
||||
* @example
|
||||
* const wrapper = createRefElement({ default: () => <div>hello</div> })
|
||||
*
|
||||
* const text = wrapper.find('div').text() // hello
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
||||
const createRefElement = (slots?: Record<string, Function>) => {
|
||||
const wrapper = mount(
|
||||
defineComponent({
|
||||
setup() {
|
||||
const domRef = ref<HTMLElement>()
|
||||
|
||||
return {
|
||||
domRef,
|
||||
}
|
||||
},
|
||||
render() {
|
||||
return <div ref="domRef">{{ ...slots }}</div>
|
||||
},
|
||||
}),
|
||||
)
|
||||
|
||||
return wrapper
|
||||
}
|
||||
|
||||
export default createRefElement
|
15
__test__/utils/isBrowser.ts
Normal file
15
__test__/utils/isBrowser.ts
Normal file
@ -0,0 +1,15 @@
|
||||
/**
|
||||
*
|
||||
* @description
|
||||
* 获取当前环境是否为浏览器环境。
|
||||
*
|
||||
* 如果是浏览器环境,则返回 true,否则返回 false。
|
||||
*/
|
||||
const isBrowser = () =>
|
||||
!!(
|
||||
typeof window !== 'undefined' &&
|
||||
window.document &&
|
||||
window.document.createElement
|
||||
)
|
||||
|
||||
export default isBrowser
|
34
__test__/utils/renderHook.ts
Normal file
34
__test__/utils/renderHook.ts
Normal file
@ -0,0 +1,34 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
import { createApp, defineComponent } from 'vue'
|
||||
|
||||
import type { App } from 'vue'
|
||||
|
||||
export default function renderHook<R = any>(
|
||||
renderFC: () => R,
|
||||
): [
|
||||
R,
|
||||
App<Element>,
|
||||
{
|
||||
act?: (fn: () => void) => void
|
||||
},
|
||||
] {
|
||||
let result: any
|
||||
let act: ((fn: () => void) => void) | undefined
|
||||
const app = createApp(
|
||||
defineComponent({
|
||||
setup() {
|
||||
result = renderFC()
|
||||
|
||||
act = (fn: () => void) => {
|
||||
fn()
|
||||
}
|
||||
|
||||
return () => {}
|
||||
},
|
||||
}),
|
||||
)
|
||||
|
||||
app.mount(document.createElement('div'))
|
||||
|
||||
return [result, app, { act }]
|
||||
}
|
27
__test__/utils/setupMiniApp.ts
Normal file
27
__test__/utils/setupMiniApp.ts
Normal file
@ -0,0 +1,27 @@
|
||||
import { setupStore } from '../../src/store'
|
||||
import { setupRouter } from '../../src/router'
|
||||
import { setupI18n } from '../../src/locales'
|
||||
import renderHook from '../utils/renderHook'
|
||||
|
||||
/**
|
||||
*
|
||||
* @description
|
||||
* 初始化 mini ray template 应用环境。
|
||||
* 该方法会初始化 store、router、i18n 等环境。
|
||||
*
|
||||
* @example
|
||||
* const { app } = await setupMiniApp()
|
||||
*/
|
||||
const setupMiniApp = async () => {
|
||||
const [_, app] = renderHook(() => {})
|
||||
|
||||
setupStore(app)
|
||||
setupRouter(app)
|
||||
await setupI18n(app)
|
||||
|
||||
return {
|
||||
app,
|
||||
}
|
||||
}
|
||||
|
||||
export default setupMiniApp
|
17
__test__/utils/sleep.ts
Normal file
17
__test__/utils/sleep.ts
Normal file
@ -0,0 +1,17 @@
|
||||
/**
|
||||
*
|
||||
* @param timer 等待时间
|
||||
*
|
||||
* @description
|
||||
* 等待一段时间,模拟睡眠。
|
||||
*
|
||||
* @example
|
||||
* await sleep(1000)
|
||||
*/
|
||||
const sleep = (timer: number) => {
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(resolve, timer)
|
||||
})
|
||||
}
|
||||
|
||||
export default sleep
|
27
__test__/vue/call.spec.ts
Normal file
27
__test__/vue/call.spec.ts
Normal file
@ -0,0 +1,27 @@
|
||||
import { call } from '../../src/utils/vue/call'
|
||||
|
||||
describe('call', () => {
|
||||
it('should be executed once', () => {
|
||||
const fn = vi.fn()
|
||||
|
||||
call(() => fn())
|
||||
|
||||
expect(fn).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('should be executed with an argument', () => {
|
||||
const fn = vi.fn()
|
||||
|
||||
call((a: number) => fn(a), 1)
|
||||
|
||||
expect(fn).toHaveBeenCalledWith(1)
|
||||
})
|
||||
|
||||
it('should be executed with multiple arguments', () => {
|
||||
const fn = vi.fn()
|
||||
|
||||
call((a: number, b: number) => fn(a, b), 1, 2)
|
||||
|
||||
expect(fn).toHaveBeenCalledWith(1, 2)
|
||||
})
|
||||
})
|
7
__test__/vue/effectDispose.spec.ts
Normal file
7
__test__/vue/effectDispose.spec.ts
Normal file
@ -0,0 +1,7 @@
|
||||
import { effectDispose } from '../../src/utils/vue/effect-dispose'
|
||||
|
||||
describe('effectDispose', () => {
|
||||
it('should return false if getCurrentScope is null', () => {
|
||||
expect(effectDispose(() => {})).toBe(false)
|
||||
})
|
||||
})
|
14
__test__/vue/renderNode.spec.tsx
Normal file
14
__test__/vue/renderNode.spec.tsx
Normal file
@ -0,0 +1,14 @@
|
||||
import { renderNode } from '../../src/utils/vue/render-node'
|
||||
import createRefElement from '../utils/createRefElement'
|
||||
|
||||
describe('renderNode', () => {
|
||||
it('should render string', () => {
|
||||
const wrapper = createRefElement({
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
||||
default: renderNode('hello world') as Function,
|
||||
})
|
||||
const text = wrapper.text()
|
||||
|
||||
expect(text).toBe('hello world')
|
||||
})
|
||||
})
|
145
cfg.ts
145
cfg.ts
@ -1,145 +0,0 @@
|
||||
/**
|
||||
*
|
||||
* @author Ray <https://github.com/XiaoDaiGua-Ray>
|
||||
*
|
||||
* @date 2023-04-06
|
||||
*
|
||||
* @workspace ray-template
|
||||
*
|
||||
* @remark 今天也是元气满满撸代码的一天
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* 系统配置文件入口
|
||||
*
|
||||
* 配置范围:
|
||||
* - 构建: 开发构建、打包构建、预览构建、体积分析构建等
|
||||
* - 系统: 根路由、标题、浏览器标题、别名等
|
||||
* - 请求: 代理配置
|
||||
*
|
||||
* 如果需要新增相关内容, 需要在 src/types/modules/cfg.ts 中进行类型配置
|
||||
* ```
|
||||
* interface Config // config 内容类型配置
|
||||
*
|
||||
* interface AppConfig // __APP_CFG__ 内容配置
|
||||
* ```
|
||||
*
|
||||
* __APP_CFG__ 说明
|
||||
* ```
|
||||
* 该属性是用于全局注入的配置方法
|
||||
*
|
||||
* const { appPrimaryColor } = __APP_CFG__
|
||||
*
|
||||
* 以上例子展示, 从 __APP_CFG__ 中解构取出 appPrimaryColor 根路由配置信息
|
||||
* __APP_CFG__ 会被挂载于全局变量 `window` 下(vite define 默认是挂载于 window 下)
|
||||
* ```
|
||||
*/
|
||||
|
||||
import path from 'node:path'
|
||||
|
||||
import {
|
||||
HTMLTitlePlugin,
|
||||
buildOptions,
|
||||
mixinCSSPlugin,
|
||||
} from './vite-plugin/index'
|
||||
import { APP_THEME } from './src/appConfig/designConfig'
|
||||
import { PRE_LOADING_CONFIG, SIDE_BAR_LOGO } from './src/appConfig/appConfig'
|
||||
|
||||
import type { AppConfigExport } from '@/types/modules/cfg'
|
||||
|
||||
const config: AppConfigExport = {
|
||||
/** 公共基础路径配置, 如果为空则会默认以 '/' 填充 */
|
||||
base: '/ray-template/',
|
||||
/** 配置首屏加载信息 */
|
||||
preloadingConfig: PRE_LOADING_CONFIG,
|
||||
/** 默认主题色(不可省略, 必填), 也用于 ejs 注入 */
|
||||
appPrimaryColor: APP_THEME.APP_PRIMARY_COLOR,
|
||||
sideBarLogo: SIDE_BAR_LOGO,
|
||||
/**
|
||||
*
|
||||
* 预处理全局需要注入的 css 文件
|
||||
*
|
||||
* 预设:
|
||||
* - ./src/styles/mixins.scss
|
||||
* - ./src/styles/setting.scss
|
||||
* - ./src/styles/theme.scss
|
||||
*
|
||||
* 如果需要删除或者修改, 需要同步修改目录下的 css 文件
|
||||
*/
|
||||
mixinCSS: mixinCSSPlugin([
|
||||
'./src/styles/mixins.scss',
|
||||
'./src/styles/setting.scss',
|
||||
]),
|
||||
/**
|
||||
*
|
||||
* 版权信息
|
||||
*
|
||||
* 也可以当作页底设置, 看实际业务需求
|
||||
*/
|
||||
copyright: 'Copyright © 2022-present Ray',
|
||||
/**
|
||||
*
|
||||
* 浏览器标题
|
||||
*/
|
||||
title: HTMLTitlePlugin('Ray Template'),
|
||||
/**
|
||||
*
|
||||
* 配置 HMR 特定选项(端口、主机、路径和协议)
|
||||
*/
|
||||
server: {
|
||||
host: '0.0.0.0',
|
||||
port: 9527,
|
||||
open: false,
|
||||
https: false,
|
||||
strictPort: false,
|
||||
fs: {
|
||||
strict: false,
|
||||
allow: [],
|
||||
},
|
||||
proxy: {
|
||||
'^/api': {
|
||||
target: 'http://localhost',
|
||||
changeOrigin: true,
|
||||
rewrite: (path) => path.replace(/^\/api/, ''),
|
||||
},
|
||||
},
|
||||
},
|
||||
/**
|
||||
*
|
||||
* 打包相关配置
|
||||
*/
|
||||
buildOptions: buildOptions,
|
||||
/**
|
||||
*
|
||||
* 预设别名
|
||||
* - `@`: `src` 根目录
|
||||
* - `@use-utils`: `src/utils` 根目录
|
||||
* - `@use-api`: `src/axios/api` 根目录
|
||||
* - `@use-images`: `src/assets/images` 根目录
|
||||
*/
|
||||
alias: [
|
||||
{
|
||||
find: '@',
|
||||
replacement: path.resolve(__dirname, './src'),
|
||||
},
|
||||
{
|
||||
find: '@use-utils',
|
||||
replacement: path.resolve(__dirname, './src/utils'),
|
||||
},
|
||||
{
|
||||
find: '@use-api',
|
||||
replacement: path.resolve(__dirname, './src/axios/api'),
|
||||
},
|
||||
{
|
||||
find: '@use-images',
|
||||
replacement: path.resolve(__dirname, './src/assets/images'),
|
||||
},
|
||||
{
|
||||
find: '@mock',
|
||||
replacement: path.resolve(__dirname, './mock'),
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
export default config
|
@ -1,20 +1,40 @@
|
||||
// update: 更新代码 | Update code
|
||||
// fix: 修复 bug | Fix bug
|
||||
// feat: 新功能 | New feature
|
||||
// chore: 构建过程或辅助工具的变动 | Build process or auxiliary tool changes
|
||||
// docs: 文档 | Documentation
|
||||
// refactor: 重构(即不是新增功能,也不是修改 bug 的代码变动) | Refactor (i.e. code changes that are neither new features nor bug fixes)
|
||||
// test: 增加测试 | Add test
|
||||
// style: 代码格式(不影响功能,例如空格、分号等格式修正) | Code format (no functional impact, such as space, semicolon, etc.)
|
||||
// version: 更新迭代 package.json 版本号 | Update the package.json version number
|
||||
// build: 构建 | Build
|
||||
// plugin: 更新插件版本 | Update plugin version
|
||||
|
||||
module.exports = {
|
||||
ignores: [(commit) => commit.includes('init')],
|
||||
extends: ['@commitlint/config-conventional'],
|
||||
rules: {
|
||||
'body-leading-blank': [2, 'always'],
|
||||
'footer-leading-blank': [1, 'always'],
|
||||
'header-max-length': [2, 'always', 108],
|
||||
'subject-empty': [2, 'never'],
|
||||
'type-empty': [2, 'never'],
|
||||
'subject-case': [0],
|
||||
'type-enum': [
|
||||
2,
|
||||
'always',
|
||||
[
|
||||
'bug',
|
||||
'feat',
|
||||
'update',
|
||||
'fix',
|
||||
'feat',
|
||||
'chore',
|
||||
'docs',
|
||||
'style',
|
||||
'refactor',
|
||||
'test',
|
||||
'chore',
|
||||
'revert',
|
||||
'merge',
|
||||
'style',
|
||||
'version',
|
||||
'build',
|
||||
'plugin',
|
||||
],
|
||||
],
|
||||
},
|
||||
|
14
docker-compose.yml
Normal file
14
docker-compose.yml
Normal file
@ -0,0 +1,14 @@
|
||||
version: '3'
|
||||
|
||||
services:
|
||||
ray-template:
|
||||
build: .
|
||||
container_name: ray-template
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
- TZ=Asia/Shanghai
|
||||
ports:
|
||||
- "9527:9527"
|
||||
# if you want to persist
|
||||
# volumes:
|
||||
# - ./app:/app
|
365
eslint.config.mjs
Normal file
365
eslint.config.mjs
Normal file
@ -0,0 +1,365 @@
|
||||
import vue from 'eslint-plugin-vue'
|
||||
import typescriptEslint from '@typescript-eslint/eslint-plugin'
|
||||
import prettier from 'eslint-plugin-prettier'
|
||||
import globals from 'globals'
|
||||
import parser from 'vue-eslint-parser'
|
||||
import path from 'node:path'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
import js from '@eslint/js'
|
||||
import { FlatCompat } from '@eslint/eslintrc'
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url)
|
||||
const __dirname = path.dirname(__filename)
|
||||
const compat = new FlatCompat({
|
||||
baseDirectory: __dirname,
|
||||
recommendedConfig: js.configs.recommended,
|
||||
allConfig: js.configs.all,
|
||||
})
|
||||
|
||||
export default [
|
||||
{
|
||||
ignores: [
|
||||
'**/node_modules/',
|
||||
'**/dist/',
|
||||
'dist/*',
|
||||
'node_modules/*',
|
||||
'**/auto-imports.d.ts',
|
||||
'**/components.d.ts',
|
||||
'**/.gitignore',
|
||||
'**/.vscode',
|
||||
'**/public',
|
||||
'**/yarn.*',
|
||||
'**/vite-env.*',
|
||||
'**/.prettierrc.*',
|
||||
'**/visualizer.*',
|
||||
'**/visualizer.html',
|
||||
'**/.env.*',
|
||||
'src/locales/lang',
|
||||
'**/.depcheckrc',
|
||||
'src/app-config/echart-themes/**/*.json',
|
||||
'**/*.md',
|
||||
'src/icons/*.svg',
|
||||
],
|
||||
},
|
||||
{
|
||||
files: ['**/*.js', '**/*.ts', '**/*.jsx', '**/*.tsx', '**/*.vue'],
|
||||
},
|
||||
...compat.extends(
|
||||
'eslint-config-prettier',
|
||||
'eslint:recommended',
|
||||
'plugin:@typescript-eslint/recommended',
|
||||
'plugin:vue/vue3-recommended',
|
||||
'plugin:vue/vue3-essential',
|
||||
'plugin:prettier/recommended',
|
||||
'prettier',
|
||||
'./unplugin/.eslintrc-auto-import.json',
|
||||
),
|
||||
{
|
||||
plugins: {
|
||||
vue,
|
||||
'@typescript-eslint': typescriptEslint,
|
||||
prettier,
|
||||
},
|
||||
languageOptions: {
|
||||
globals: {
|
||||
...globals.browser,
|
||||
...globals.node,
|
||||
defineProps: 'readonly',
|
||||
defineEmits: 'readonly',
|
||||
defineExpose: 'readonly',
|
||||
withDefaults: 'readonly',
|
||||
defineOptions: 'readonly',
|
||||
defineModel: 'readonly',
|
||||
},
|
||||
parser: parser,
|
||||
ecmaVersion: 2020,
|
||||
sourceType: 'module',
|
||||
parserOptions: {
|
||||
parser: '@typescript-eslint/parser',
|
||||
ecmaFeatures: {
|
||||
jsx: true,
|
||||
tsx: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
rules: {
|
||||
'no-undefined': ['error'],
|
||||
'linebreak-style': ['error', 'unix'],
|
||||
'@typescript-eslint/no-explicit-any': [
|
||||
'error',
|
||||
{
|
||||
ignoreRestArgs: true,
|
||||
},
|
||||
],
|
||||
'prettier/prettier': 'error',
|
||||
'no-unused-vars': 'off',
|
||||
'@typescript-eslint/no-unused-vars': 'off',
|
||||
'@typescript-eslint/ban-types': 'off',
|
||||
'@typescript-eslint/explicit-module-boundary-types': 'off',
|
||||
'@typescript-eslint/no-var-requires': 'off',
|
||||
'@typescript-eslint/no-non-null-assertion': 'off',
|
||||
'@typescript-eslint/no-non-null-asserted-optional-chain': 'off',
|
||||
'@typescript-eslint/consistent-type-imports': [
|
||||
'error',
|
||||
{
|
||||
disallowTypeAnnotations: false,
|
||||
},
|
||||
],
|
||||
'@typescript-eslint/no-empty-interface': [
|
||||
'error',
|
||||
{
|
||||
allowSingleExtends: true,
|
||||
},
|
||||
],
|
||||
'accessor-pairs': 2,
|
||||
'constructor-super': 0,
|
||||
'default-case': 2,
|
||||
eqeqeq: [2, 'allow-null'],
|
||||
'no-alert': 0,
|
||||
'no-array-constructor': 2,
|
||||
'no-bitwise': 0,
|
||||
'no-caller': 1,
|
||||
'no-catch-shadow': 2,
|
||||
'no-class-assign': 2,
|
||||
'no-cond-assign': 2,
|
||||
'no-const-assign': 2,
|
||||
'no-constant-condition': 2,
|
||||
'no-dupe-keys': 2,
|
||||
'no-dupe-args': 2,
|
||||
'no-duplicate-case': 2,
|
||||
'no-eval': 1,
|
||||
'no-ex-assign': 2,
|
||||
'no-extend-native': 2,
|
||||
'no-extra-bind': 2,
|
||||
'no-extra-boolean-cast': [
|
||||
'error',
|
||||
{
|
||||
enforceForLogicalOperands: true,
|
||||
},
|
||||
],
|
||||
'no-extra-parens': 0,
|
||||
semi: [
|
||||
'error',
|
||||
'never',
|
||||
{
|
||||
beforeStatementContinuationChars: 'always',
|
||||
},
|
||||
],
|
||||
'no-fallthrough': 1,
|
||||
'no-func-assign': 2,
|
||||
'no-implicit-coercion': [
|
||||
'error',
|
||||
{
|
||||
allow: ['!!', '~'],
|
||||
},
|
||||
],
|
||||
'no-implied-eval': 2,
|
||||
'no-invalid-regexp': 2,
|
||||
'no-invalid-this': 2,
|
||||
'no-irregular-whitespace': 2,
|
||||
'no-iterator': 2,
|
||||
'no-label-var': 2,
|
||||
'no-labels': 2,
|
||||
'no-lone-blocks': 2,
|
||||
'no-multi-spaces': 1,
|
||||
'no-multiple-empty-lines': [
|
||||
'error',
|
||||
{
|
||||
max: 2,
|
||||
},
|
||||
],
|
||||
'no-new-func': 2,
|
||||
'no-new-object': 2,
|
||||
'no-new-require': 2,
|
||||
'no-sparse-arrays': 2,
|
||||
'no-trailing-spaces': 1,
|
||||
'no-unreachable': 2,
|
||||
'no-unused-expressions': [
|
||||
'error',
|
||||
{
|
||||
allowShortCircuit: true,
|
||||
allowTernary: true,
|
||||
allowTaggedTemplates: true,
|
||||
enforceForJSX: true,
|
||||
},
|
||||
],
|
||||
'no-useless-call': 2,
|
||||
'no-var': 'error',
|
||||
'no-with': 2,
|
||||
'use-isnan': 2,
|
||||
'no-multi-assign': 2,
|
||||
'prefer-arrow-callback': 2,
|
||||
curly: ['error', 'all'],
|
||||
'vue/multi-word-component-names': [
|
||||
'error',
|
||||
{
|
||||
ignores: [],
|
||||
},
|
||||
],
|
||||
'vue/no-use-v-if-with-v-for': [
|
||||
'error',
|
||||
{
|
||||
allowUsingIterationVar: false,
|
||||
},
|
||||
],
|
||||
'vue/require-v-for-key': ['error'],
|
||||
'vue/require-valid-default-prop': ['error'],
|
||||
'vue/component-definition-name-casing': ['error', 'PascalCase'],
|
||||
'vue/html-closing-bracket-newline': [
|
||||
'error',
|
||||
{
|
||||
singleline: 'never',
|
||||
multiline: 'always',
|
||||
},
|
||||
],
|
||||
'vue/v-on-event-hyphenation': ['error', 'never'],
|
||||
'vue/component-tags-order': [
|
||||
'error',
|
||||
{
|
||||
order: ['template', 'script', 'style'],
|
||||
},
|
||||
],
|
||||
'vue/no-v-html': ['error'],
|
||||
'vue/no-v-text': ['error'],
|
||||
'vue/component-api-style': [
|
||||
'error',
|
||||
['script-setup', 'composition', 'composition-vue2'],
|
||||
],
|
||||
'vue/component-name-in-template-casing': [
|
||||
'error',
|
||||
'PascalCase',
|
||||
{
|
||||
registeredComponentsOnly: false,
|
||||
},
|
||||
],
|
||||
'vue/no-unused-refs': ['error'],
|
||||
'vue/prop-name-casing': ['error', 'camelCase'],
|
||||
'vue/component-options-name-casing': ['error', 'PascalCase'],
|
||||
'vue/attribute-hyphenation': [
|
||||
'error',
|
||||
'never',
|
||||
{
|
||||
ignore: [],
|
||||
},
|
||||
],
|
||||
'vue/no-restricted-static-attribute': [
|
||||
'error',
|
||||
{
|
||||
key: 'key',
|
||||
message: 'Disallow using key as a custom attribute',
|
||||
},
|
||||
],
|
||||
'no-restricted-syntax': [
|
||||
'error',
|
||||
{
|
||||
selector: "CallExpression[callee.property.name='deprecated']",
|
||||
message: 'Using deprecated API is not allowed.',
|
||||
},
|
||||
],
|
||||
'padding-line-between-statements': [
|
||||
'error',
|
||||
{
|
||||
blankLine: 'always',
|
||||
prev: ['import'],
|
||||
next: '*',
|
||||
},
|
||||
{
|
||||
blankLine: 'any',
|
||||
prev: 'import',
|
||||
next: 'import',
|
||||
},
|
||||
{
|
||||
blankLine: 'always',
|
||||
prev: '*',
|
||||
next: 'export',
|
||||
},
|
||||
{
|
||||
blankLine: 'any',
|
||||
prev: 'export',
|
||||
next: 'export',
|
||||
},
|
||||
{
|
||||
blankLine: 'always',
|
||||
prev: ['const', 'let', 'var'],
|
||||
next: '*',
|
||||
},
|
||||
{
|
||||
blankLine: 'any',
|
||||
prev: ['const', 'let', 'var'],
|
||||
next: ['const', 'let', 'var'],
|
||||
},
|
||||
{
|
||||
blankLine: 'always',
|
||||
prev: 'directive',
|
||||
next: '*',
|
||||
},
|
||||
{
|
||||
blankLine: 'any',
|
||||
prev: 'directive',
|
||||
next: 'directive',
|
||||
},
|
||||
{
|
||||
blankLine: 'always',
|
||||
prev: '*',
|
||||
next: [
|
||||
'if',
|
||||
'class',
|
||||
'for',
|
||||
'do',
|
||||
'while',
|
||||
'switch',
|
||||
'try',
|
||||
'with',
|
||||
'function',
|
||||
'block',
|
||||
'block-like',
|
||||
'break',
|
||||
'case',
|
||||
'continue',
|
||||
'return',
|
||||
'throw',
|
||||
'debugger',
|
||||
],
|
||||
},
|
||||
{
|
||||
blankLine: 'always',
|
||||
prev: [
|
||||
'if',
|
||||
'class',
|
||||
'for',
|
||||
'do',
|
||||
'while',
|
||||
'switch',
|
||||
'try',
|
||||
'with',
|
||||
'function',
|
||||
'block',
|
||||
'block-like',
|
||||
'break',
|
||||
'case',
|
||||
'continue',
|
||||
'return',
|
||||
'throw',
|
||||
'debugger',
|
||||
],
|
||||
next: '*',
|
||||
},
|
||||
],
|
||||
'@typescript-eslint/no-unused-expressions': [
|
||||
'error',
|
||||
{
|
||||
allowShortCircuit: true,
|
||||
allowTernary: true,
|
||||
allowTaggedTemplates: true,
|
||||
},
|
||||
],
|
||||
'@typescript-eslint/no-empty-object-type': [
|
||||
'error',
|
||||
{
|
||||
allowInterfaces: 'with-single-extends',
|
||||
allowObjectTypes: 'always',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
]
|
49
index.html
49
index.html
@ -1,9 +1,12 @@
|
||||
<!DOCTYPE html>
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" type="image/svg+xml" href="/ray.svg" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta
|
||||
name="viewport"
|
||||
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"
|
||||
/>
|
||||
<title>Vite + Vue + TS</title>
|
||||
</head>
|
||||
<style>
|
||||
@ -12,6 +15,27 @@
|
||||
--preloading-title-color: <%= preloadingConfig.titleColor %>;
|
||||
--ray-theme-primary-fade-color: <%= appPrimaryColor.primaryFadeColor %>;
|
||||
--ray-theme-primary-color: <%= appPrimaryColor.primaryColor %>;
|
||||
--global-loading-bg-color: #ffffff;
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
#pre-loading-animation {
|
||||
background-color: var(--global-loading-bg-color);
|
||||
}
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: light) {
|
||||
#pre-loading-animation {
|
||||
background-color: var(--global-loading-bg-color);
|
||||
}
|
||||
}
|
||||
|
||||
html.dark #pre-loading-animation {
|
||||
background-color: var(--global-loading-bg-color);
|
||||
}
|
||||
|
||||
html.light #pre-loading-animation {
|
||||
background-color: var(--global-loading-bg-color);
|
||||
}
|
||||
|
||||
#pre-loading-animation {
|
||||
@ -20,13 +44,9 @@
|
||||
right: 0;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
background-color: #ffffff;
|
||||
color: var(--preloading-title-color);
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.ray-template--dark #pre-loading-animation {
|
||||
background-color: #2a3146;
|
||||
background-color: var(--global-loading-bg-color);
|
||||
}
|
||||
|
||||
#pre-loading-animation .pre-loading-animation__wrapper {
|
||||
@ -41,8 +61,9 @@
|
||||
#pre-loading-animation
|
||||
.pre-loading-animation__wrapper
|
||||
.pre-loading-animation__wrapper-title {
|
||||
font-size: 30px;
|
||||
font-size: 32px;
|
||||
padding-bottom: 48px;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.pre-loading-animation__wrapper-loading {
|
||||
@ -91,6 +112,18 @@
|
||||
}
|
||||
}
|
||||
</style>
|
||||
<script>
|
||||
;(function () {
|
||||
const html = document.documentElement
|
||||
const store = window.localStorage.getItem('piniaSettingStore')
|
||||
const { _appTheme = false } = store ? JSON.parse(store) : {}
|
||||
const loadingBgColor = _appTheme ? '#1c1e23' : '#ffffff'
|
||||
|
||||
html.classList.add(_appTheme ? 'dark' : 'light')
|
||||
html.style.setProperty('--global-loading-bg-color', loadingBgColor)
|
||||
html.style.setProperty('background-color', loadingBgColor)
|
||||
})()
|
||||
</script>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<div id="pre-loading-animation">
|
||||
|
@ -1,14 +1,3 @@
|
||||
/**
|
||||
*
|
||||
* @author Ray <https://github.com/XiaoDaiGua-Ray>
|
||||
*
|
||||
* @date 2023-08-11
|
||||
*
|
||||
* @workspace ray-template
|
||||
*
|
||||
* @remark 今天也是元气满满撸代码的一天
|
||||
*/
|
||||
|
||||
import Mock from 'mockjs'
|
||||
|
||||
/**
|
||||
|
@ -1,14 +1,3 @@
|
||||
/**
|
||||
*
|
||||
* @author Ray <https://github.com/XiaoDaiGua-Ray>
|
||||
*
|
||||
* @date 2023-08-11
|
||||
*
|
||||
* @workspace ray-template
|
||||
*
|
||||
* @remark 今天也是元气满满撸代码的一天
|
||||
*/
|
||||
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
|
||||
export function array(length: number) {
|
||||
|
161
package.json
Normal file → Executable file
161
package.json
Normal file → Executable file
@ -1,100 +1,113 @@
|
||||
{
|
||||
"name": "ray-template",
|
||||
"private": false,
|
||||
"version": "4.1.9",
|
||||
"version": "5.2.2",
|
||||
"type": "module",
|
||||
"engines": {
|
||||
"node": ">=16.0.0",
|
||||
"pnpm": ">=8.0.0"
|
||||
"node": "^18.0.0 || ^20.0.0 || >=22.0.0",
|
||||
"pnpm": ">=9.0.0"
|
||||
},
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "vue-tsc --noEmit && vite build --mode production",
|
||||
"build": "vue-tsc --noEmit && vite build",
|
||||
"preview": "vite preview",
|
||||
"test": "vue-tsc --noEmit && vite build --mode test",
|
||||
"dev-build": "vue-tsc --noEmit && vite build --mode development",
|
||||
"report": "vue-tsc --noEmit && vite build --mode report",
|
||||
"prepare": "husky install"
|
||||
"report": "vite build --mode report",
|
||||
"prepare": "husky install",
|
||||
"test": "vitest",
|
||||
"test:ui": "vitest --ui",
|
||||
"lint": "vue-tsc --noEmit && eslint --fix && prettier --write \"**/*.{ts,tsx,json,.vue}\""
|
||||
},
|
||||
"husky": {
|
||||
"hooks": {
|
||||
"pre-commit": "lint-staged",
|
||||
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
|
||||
}
|
||||
},
|
||||
"lint-staged": {
|
||||
"src/**/*.{vue,jsx,ts,tsx,json}": [
|
||||
"prettier --write",
|
||||
"eslint src",
|
||||
"git add"
|
||||
"*.{ts,tsx,json}": [
|
||||
"prettier --write"
|
||||
],
|
||||
"*.{ts,tsx,vue}": [
|
||||
"eslint --fix"
|
||||
]
|
||||
},
|
||||
"dependencies": {
|
||||
"@vueuse/core": "^9.1.0",
|
||||
"awesome-qr": "2.1.5-rc.0",
|
||||
"axios": "^1.2.0",
|
||||
"@logicflow/core": "2.0.10",
|
||||
"@logicflow/extension": "2.0.14",
|
||||
"@vueuse/core": "^13.1.0",
|
||||
"axios": "^1.9.0",
|
||||
"clipboard": "^2.0.11",
|
||||
"crypto-js": "^4.1.1",
|
||||
"crypto-js": "4.2.0",
|
||||
"currency.js": "^2.0.4",
|
||||
"dayjs": "^1.11.7",
|
||||
"echarts": "^5.4.0",
|
||||
"dayjs": "^1.11.13",
|
||||
"echarts": "^5.6.0",
|
||||
"html-to-image": "1.11.13",
|
||||
"interactjs": "1.10.27",
|
||||
"jsbarcode": "3.11.6",
|
||||
"lodash-es": "^4.17.21",
|
||||
"mockjs": "1.1.0",
|
||||
"naive-ui": "^2.34.4",
|
||||
"pinia": "^2.1.4",
|
||||
"pinia-plugin-persistedstate": "^3.1.0",
|
||||
"naive-ui": "^2.42.0",
|
||||
"pinia": "^3.0.3",
|
||||
"pinia-plugin-persistedstate": "^4.4.1",
|
||||
"print-js": "^1.6.0",
|
||||
"sass": "^1.54.3",
|
||||
"screenfull": "^6.0.2",
|
||||
"vue": "^3.3.4",
|
||||
"vue-hooks-plus": "1.8.1",
|
||||
"vue-i18n": "^9.2.2",
|
||||
"vue-router": "^4.2.4",
|
||||
"vuedraggable": "^4.1.0",
|
||||
"xlsx": "^0.18.5"
|
||||
"vue": "^3.5.17",
|
||||
"vue-demi": "0.14.10",
|
||||
"vue-hooks-plus": "2.4.0",
|
||||
"vue-i18n": "^9.13.1",
|
||||
"vue-router": "^4.5.1",
|
||||
"vue3-next-qrcode": "3.0.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.20.2",
|
||||
"@babel/eslint-parser": "^7.19.1",
|
||||
"@commitlint/cli": "^17.4.2",
|
||||
"@commitlint/config-conventional": "^17.4.2",
|
||||
"@intlify/unplugin-vue-i18n": "^0.12.1",
|
||||
"@types/crypto-js": "^4.1.1",
|
||||
"@types/lodash-es": "^4.17.7",
|
||||
"@types/mockjs": "1.0.7",
|
||||
"@types/scrollreveal": "^0.0.8",
|
||||
"@typescript-eslint/eslint-plugin": "^5.61.0",
|
||||
"@typescript-eslint/parser": "^5.61.0",
|
||||
"@vitejs/plugin-vue": "^4.2.3",
|
||||
"@vitejs/plugin-vue-jsx": "^3.0.1",
|
||||
"@vue-hooks-plus/resolvers": "1.2.4",
|
||||
"@vue/eslint-config-prettier": "^7.1.0",
|
||||
"@vue/eslint-config-typescript": "^11.0.3",
|
||||
"autoprefixer": "^10.4.8",
|
||||
"depcheck": "^1.4.3",
|
||||
"eslint": "^8.44.0",
|
||||
"eslint-config-prettier": "^8.8.0",
|
||||
"eslint-config-standard-with-typescript": "^23.0.0",
|
||||
"eslint-plugin-import": "^2.25.2",
|
||||
"eslint-plugin-n": "^15.0.0",
|
||||
"eslint-plugin-prettier": "^4.2.1",
|
||||
"eslint-plugin-promise": "^6.0.0",
|
||||
"eslint-plugin-react": "^7.31.10",
|
||||
"eslint-plugin-vue": "^9.15.1",
|
||||
"husky": "^8.0.3",
|
||||
"lint-staged": "^13.1.0",
|
||||
"postcss": "^8.1.0",
|
||||
"postcss-px-to-viewport-8-plugin": "1.2.2",
|
||||
"prettier": "^2.7.1",
|
||||
"rollup-plugin-visualizer": "^5.8.3",
|
||||
"svg-sprite-loader": "^6.0.11",
|
||||
"typescript": "^5.0.2",
|
||||
"unplugin-auto-import": "^0.15.0",
|
||||
"unplugin-vue-components": "^0.25.1",
|
||||
"vite": "^4.4.9",
|
||||
"vite-plugin-compression": "^0.5.1",
|
||||
"vite-plugin-ejs": "^1.6.4",
|
||||
"@commitlint/cli": "19.7.1",
|
||||
"@commitlint/config-conventional": "19.7.1",
|
||||
"@eslint/js": "9.28.0",
|
||||
"@interactjs/types": "1.10.27",
|
||||
"@intlify/unplugin-vue-i18n": "4.0.0",
|
||||
"@types/crypto-js": "4.2.2",
|
||||
"@types/jsbarcode": "3.11.4",
|
||||
"@types/lodash-es": "4.17.12",
|
||||
"@types/mockjs": "1.0.10",
|
||||
"@typescript-eslint/eslint-plugin": "8.24.0",
|
||||
"@typescript-eslint/parser": "8.24.0",
|
||||
"@vitejs/plugin-vue": "5.2.3",
|
||||
"@vitejs/plugin-vue-jsx": "4.1.2",
|
||||
"@vitest/ui": "2.1.8",
|
||||
"@vue/eslint-config-prettier": "10.1.0",
|
||||
"@vue/eslint-config-typescript": "14.2.0",
|
||||
"@vue/test-utils": "2.4.6",
|
||||
"autoprefixer": "10.4.21",
|
||||
"depcheck": "1.4.7",
|
||||
"eslint": "9.20.1",
|
||||
"eslint-config-prettier": "10.1.2",
|
||||
"eslint-plugin-prettier": "5.2.6",
|
||||
"eslint-plugin-vue": "9.32.0",
|
||||
"globals": "16.0.0",
|
||||
"happy-dom": "17.1.0",
|
||||
"husky": "8.0.3",
|
||||
"lint-staged": "15.4.3",
|
||||
"postcss": "8.5.4",
|
||||
"postcss-px-to-viewport-8-with-include": "1.2.2",
|
||||
"prettier": "3.5.3",
|
||||
"rollup-plugin-gzip": "4.0.1",
|
||||
"sass": "1.86.3",
|
||||
"svg-sprite-loader": "6.0.11",
|
||||
"typescript": "5.8.3",
|
||||
"unocss": "66.3.3",
|
||||
"unplugin-auto-import": "19.1.2",
|
||||
"unplugin-vue-components": "0.28.0",
|
||||
"vite": "6.3.5",
|
||||
"vite-bundle-analyzer": "0.16.0",
|
||||
"vite-plugin-cdn2": "1.1.0",
|
||||
"vite-plugin-ejs": "1.7.0",
|
||||
"vite-plugin-eslint": "1.8.1",
|
||||
"vite-plugin-imp": "^2.3.1",
|
||||
"vite-plugin-inspect": "^0.7.26",
|
||||
"vite-plugin-mock-dev-server": "1.3.0",
|
||||
"vite-plugin-svg-icons": "^2.0.1",
|
||||
"vite-svg-loader": "^4.0.0",
|
||||
"vue-tsc": "^1.8.4"
|
||||
"vite-plugin-inspect": "0.8.4",
|
||||
"vite-plugin-mock-dev-server": "1.8.3",
|
||||
"vite-plugin-svg-icons": "2.0.1",
|
||||
"vite-svg-loader": "5.1.0",
|
||||
"vitest": "2.1.8",
|
||||
"vue-eslint-parser": "9.4.3",
|
||||
"vue-tsc": "2.2.8"
|
||||
},
|
||||
"description": "<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->",
|
||||
"main": "index.ts",
|
||||
|
10101
pnpm-lock.yaml
generated
Normal file
10101
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -8,31 +8,32 @@ module.exports = {
|
||||
'ff > 31',
|
||||
'ie >= 8',
|
||||
'last 10 versions',
|
||||
'not dead',
|
||||
],
|
||||
grid: true,
|
||||
},
|
||||
// 为了适配 postcss8.x 版本的转换库
|
||||
'postcss-px-to-viewport-8-plugin': {
|
||||
inlinePxToViewport: true,
|
||||
/** 视窗的宽度(设计稿的宽度) */
|
||||
'postcss-px-to-viewport-8-with-include': {
|
||||
// 横屏时使用的视口宽度
|
||||
landscapeWidth: 1920,
|
||||
// 视窗的宽度(设计稿的宽度)
|
||||
viewportWidth: 1920,
|
||||
/** 视窗的高度(设计稿高度, 一般无需指定) */
|
||||
viewportHeight: 1080,
|
||||
/** 指定 px 转换为视窗单位值的小数位数 */
|
||||
// 指定 px 转换为视窗单位值的小数位数
|
||||
unitPrecision: 3,
|
||||
/** 指定需要转换成的视窗单位 */
|
||||
viewportUnit: 'rem',
|
||||
/** 制定字体转换单位 */
|
||||
fontViewportUnit: 'rem',
|
||||
/** 指定不转换为视窗单位的类 */
|
||||
// 指定需要转换成的视窗单位
|
||||
viewportUnit: 'vw',
|
||||
// 制定字体转换单位
|
||||
fontViewportUnit: 'vw',
|
||||
// 指定不转换为视窗单位的类
|
||||
selectorBlackList: ['.ignore'],
|
||||
/** 小于或等于 1px 不转换为视窗单位 */
|
||||
// 小于或等于 1px 不转换为视窗单位
|
||||
minPixelValue: 1,
|
||||
/** 允许在媒体查询中转换 px */
|
||||
// 允许在媒体查询中转换 px
|
||||
mediaQuery: false,
|
||||
// exclude: /(\/|\\)(node_modules)(\/|\\)/, // 忽略某些文件夹下的文件或特定文件,例如 'node_modules' 下的文件
|
||||
include: [/^src[/\\].*\.(vue|tsx|jsx|ts(?!d))$/],
|
||||
preserve: true,
|
||||
// 忽略某些文件夹下的文件或特定文件,例如 'node_modules' 下的文件
|
||||
exclude: /node_modules/,
|
||||
// 指定一个空的文件夹,避免影响到无需转换的文件
|
||||
include: [],
|
||||
},
|
||||
},
|
||||
}
|
||||
|
21
src/App.tsx
21
src/App.tsx
@ -1,26 +1,29 @@
|
||||
import { RouterView } from 'vue-router'
|
||||
import AppNaiveGlobalProvider from '@/app-components/provider/AppNaiveGlobalProvider/index'
|
||||
import AppStyleProvider from '@/app-components/provider/AppStyleProvider/index'
|
||||
import AppLockScreen from '@/app-components/app/AppLockScreen/index'
|
||||
import AppGlobalSpin from '@/spin/index'
|
||||
import AppNaiveGlobalProvider from '@/app-components/provider/AppNaiveGlobalProvider'
|
||||
import AppStyleProvider from '@/app-components/provider/AppStyleProvider'
|
||||
import AppLockScreen from '@/app-components/app/AppLockScreen'
|
||||
import AppWatermarkProvider from '@/app-components/provider/AppWatermarkProvider'
|
||||
import AppGlobalSpin from '@/app-components/app/AppGlobalSpin'
|
||||
import AppVersionProvider from '@/app-components/provider/AppVersionProvider'
|
||||
|
||||
const App = defineComponent({
|
||||
import { APP_GLOBAL_LOADING } from '@/app-config'
|
||||
|
||||
export default defineComponent({
|
||||
name: 'App',
|
||||
render() {
|
||||
return (
|
||||
<AppNaiveGlobalProvider>
|
||||
<AppVersionProvider />
|
||||
<AppLockScreen />
|
||||
<AppStyleProvider />
|
||||
|
||||
<AppWatermarkProvider />
|
||||
<AppGlobalSpin>
|
||||
{{
|
||||
default: () => <RouterView />,
|
||||
description: () => 'lodaing...',
|
||||
description: () => APP_GLOBAL_LOADING,
|
||||
}}
|
||||
</AppGlobalSpin>
|
||||
</AppNaiveGlobalProvider>
|
||||
)
|
||||
},
|
||||
})
|
||||
|
||||
export default App
|
||||
|
14
src/__ray-template/README.md
Normal file
14
src/__ray-template/README.md
Normal file
@ -0,0 +1,14 @@
|
||||
# \_\_ray-template
|
||||
|
||||
该包用于管理一些模板的管理,例如:
|
||||
|
||||
- validAppRootPath: 检查模板 `appRootPath` 是否配置正确
|
||||
- validLocal: 检查模板 `localConfig` 是否配置正确
|
||||
|
||||
## 拓展
|
||||
|
||||
当你需要在做一些定制化操作的时候,可以尝试在这个包里做一些事情。
|
||||
|
||||
最后在 `main.ts` 中导入并且调用即可。
|
||||
|
||||
> 出于一些考虑,并没有做自动化导入调用,所以需要自己手动来。(好吧,其实就是我懒-,-)
|
16
src/__ray-template/index.ts
Normal file
16
src/__ray-template/index.ts
Normal file
@ -0,0 +1,16 @@
|
||||
import { validAppRootPath } from './valid/valid-app-root-path'
|
||||
import { validLocal } from './valid/valid-local'
|
||||
|
||||
/**
|
||||
*
|
||||
* @description
|
||||
* 该方法用于初始化 ray-template 配置。
|
||||
*/
|
||||
export const setupRayTemplateCore = async () => {
|
||||
if (!__DEV__) {
|
||||
return
|
||||
}
|
||||
|
||||
await validAppRootPath()
|
||||
await validLocal()
|
||||
}
|
28
src/__ray-template/valid/valid-app-root-path.ts
Normal file
28
src/__ray-template/valid/valid-app-root-path.ts
Normal file
@ -0,0 +1,28 @@
|
||||
import { useSettingGetters } from '@/store'
|
||||
import { useVueRouter } from '@/hooks'
|
||||
|
||||
/**
|
||||
*
|
||||
* @description
|
||||
* 检查 appRootRoute.path 是否存配置正确。如果配置错误,将抛出错误。
|
||||
*
|
||||
* 如果配置错误可以检查: [src/store/modules/setting/index.ts] 中的 appRootRoute 配置。
|
||||
*
|
||||
* 该方法会通过调用 getRoutes 方法获取所有路由,也就意味着检查的路由格式是铺开之后的格式。当你的路由是嵌套路由时,需要注意检查完整的路径。
|
||||
*/
|
||||
export const validAppRootPath = async () => {
|
||||
const { getAppRootRoute } = useSettingGetters()
|
||||
const {
|
||||
router: { getRoutes },
|
||||
} = useVueRouter()
|
||||
|
||||
const find = getRoutes().find(
|
||||
(curr) => curr.path === getAppRootRoute.value.path,
|
||||
)
|
||||
|
||||
if (!find) {
|
||||
throw new Error(
|
||||
`[validAppRootPath]: 'store setting appRootRoute path: ' '${getAppRootRoute.value.path}' not found in router, please check the 'appRootRoute' setting in the store setting module.`,
|
||||
)
|
||||
}
|
||||
}
|
99
src/__ray-template/valid/valid-local.ts
Normal file
99
src/__ray-template/valid/valid-local.ts
Normal file
@ -0,0 +1,99 @@
|
||||
import {
|
||||
LOCAL_OPTIONS,
|
||||
SYSTEM_DEFAULT_LOCAL,
|
||||
SYSTEM_FALLBACK_LOCALE,
|
||||
DAYJS_LOCAL_MAP,
|
||||
DEFAULT_DAYJS_LOCAL,
|
||||
} from '@/app-config'
|
||||
|
||||
/**
|
||||
*
|
||||
* @description
|
||||
* 获取所有的 LOCAL_OPTIONS 的 key。
|
||||
*/
|
||||
const getLocalOptionKeys = () => {
|
||||
return LOCAL_OPTIONS.map((curr) => curr.key)
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @description
|
||||
* 验证 SYSTEM_DEFAULT_LOCAL 是否在 LOCAL_OPTIONS 中。
|
||||
*/
|
||||
const validSystemDefaultLocal = () => {
|
||||
const localOptionKeys = getLocalOptionKeys()
|
||||
|
||||
if (!localOptionKeys.includes(SYSTEM_DEFAULT_LOCAL)) {
|
||||
throw new Error(
|
||||
`[validLocal validSystemDefaultLocal:] SYSTEM_DEFAULT_LOCAL: '${SYSTEM_DEFAULT_LOCAL}' is not in LOCAL_OPTIONS: [${localOptionKeys.join(
|
||||
', ',
|
||||
)}]`,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @description
|
||||
* 验证 SYSTEM_FALLBACK_LOCALE 是否在 LOCAL_OPTIONS 中。
|
||||
*/
|
||||
const validSystemFallbackLocale = () => {
|
||||
const localOptionKeys = getLocalOptionKeys()
|
||||
|
||||
if (!localOptionKeys.includes(SYSTEM_FALLBACK_LOCALE)) {
|
||||
throw new Error(
|
||||
`[validLocal validSystemFallbackLocale:] SYSTEM_FALLBACK_LOCALE: '${SYSTEM_FALLBACK_LOCALE}' is not in LOCAL_OPTIONS: [${localOptionKeys.join(
|
||||
', ',
|
||||
)}]`,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @description
|
||||
* 验证 DAYJS_LOCAL_MAP 是否在 LOCAL_OPTIONS 中。
|
||||
*/
|
||||
const validDayjsLocalMap = () => {
|
||||
const localOptionKeys = getLocalOptionKeys() as string[]
|
||||
const dayjsLocalKeys = Object.keys(DAYJS_LOCAL_MAP)
|
||||
|
||||
dayjsLocalKeys.forEach((key) => {
|
||||
if (!localOptionKeys.includes(key)) {
|
||||
throw new Error(
|
||||
`[validLocal validDayjsLocalMap:] DAYJS_LOCAL_MAP: '${key}' is not in LOCAL_OPTIONS: [${localOptionKeys.join(
|
||||
', ',
|
||||
)}]`,
|
||||
)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @description
|
||||
* 验证 DEFAULT_DAYJS_LOCAL 是否在 DAYJS_LOCAL_MAP 中。
|
||||
*/
|
||||
const validDefaultDayjsLocal = () => {
|
||||
const dayjsLocalKeys = Object.values(DAYJS_LOCAL_MAP)
|
||||
|
||||
if (!dayjsLocalKeys.includes(DEFAULT_DAYJS_LOCAL)) {
|
||||
throw new Error(
|
||||
`[validLocal validDefaultDayjsLocal:] DEFAULT_DAYJS_LOCAL: '${DEFAULT_DAYJS_LOCAL}' is not in DAYJS_LOCAL_MAP: [${dayjsLocalKeys.join(
|
||||
', ',
|
||||
)}]`,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @description
|
||||
* 验证所有的 localConfig 相关的配置。
|
||||
*/
|
||||
export const validLocal = async () => {
|
||||
validSystemDefaultLocal()
|
||||
validSystemFallbackLocale()
|
||||
validDayjsLocalMap()
|
||||
validDefaultDayjsLocal()
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
import { request } from '@/axios/index'
|
||||
import { request } from '@/axios'
|
||||
|
||||
import type { BasicResponse, PaginationResponse } from '@/types/modules/axios'
|
||||
import type { PaginationResponse } from '@/types'
|
||||
|
||||
export interface MockListParams {
|
||||
page: number
|
@ -1,14 +1,3 @@
|
||||
/**
|
||||
*
|
||||
* @author Ray <https://github.com/XiaoDaiGua-Ray>
|
||||
*
|
||||
* @date 2023-03-31
|
||||
*
|
||||
* @workspace ray-template
|
||||
*
|
||||
* @remark 今天也是元气满满撸代码的一天
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* 该方法演示如何封装一个通用请求方法
|
||||
@ -19,9 +8,9 @@
|
||||
* 3. 如果该方法在 setup 环境中使用,则可以使用 useHookPlusRequest 包裹该方法,即可便捷使用该请求函数。如果请求方法在非 setup 环境中使用,直接使用即可
|
||||
*/
|
||||
|
||||
import { request } from '@/axios/index'
|
||||
import { request } from '@/axios'
|
||||
|
||||
import type { BasicResponse } from '@/types/modules/axios'
|
||||
import type { BasicResponse } from '@/types'
|
||||
|
||||
interface AxiosTestResponse extends UnknownObjectKey {
|
||||
data: UnknownObjectKey[]
|
||||
@ -39,7 +28,7 @@ interface JSONPlaceholder {
|
||||
*
|
||||
* @returns 测试
|
||||
*
|
||||
* @medthod get
|
||||
* @method get
|
||||
*/
|
||||
export const getWeather = (city: string) => {
|
||||
return request<AxiosTestResponse>({
|
||||
@ -48,7 +37,7 @@ export const getWeather = (city: string) => {
|
||||
})
|
||||
}
|
||||
|
||||
export const getTypicode = () => {
|
||||
export const getTypicCode = () => {
|
||||
return request<JSONPlaceholder>({
|
||||
url: 'https://jsonplaceholder.typicode.com/todos/1',
|
||||
method: 'get',
|
@ -3,4 +3,4 @@
|
||||
该包存放与模板深度绑定的组件:
|
||||
|
||||
- app:存放与模板数据绑定的组件
|
||||
- sys:存放模板注入类组件
|
||||
- provider:存放模板注入类组件
|
||||
|
@ -1,14 +1,3 @@
|
||||
/**
|
||||
*
|
||||
* @author Ray <https://github.com/XiaoDaiGua-Ray>
|
||||
*
|
||||
* @date 2023-05-31
|
||||
*
|
||||
* @workspace ray-template
|
||||
*
|
||||
* @remark 今天也是元气满满撸代码的一天
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* 系统管理员头像与名称
|
||||
@ -17,70 +6,65 @@
|
||||
* 默认读取本地 session catch 缓存
|
||||
*/
|
||||
|
||||
import './index.scss'
|
||||
import { NAvatar, NButton, NFlex } from 'naive-ui'
|
||||
|
||||
import { NAvatar, NSpace } from 'naive-ui'
|
||||
|
||||
import { avatarProps, spaceProps } from 'naive-ui'
|
||||
import { APP_CATCH_KEY } from '@/appConfig/appConfig'
|
||||
import { getStorage } from '@/utils/cache'
|
||||
import { avatarProps } from 'naive-ui'
|
||||
import { useSigningGetters } from '@/store'
|
||||
|
||||
import type { PropType } from 'vue'
|
||||
import type { AvatarProps, SpaceProps } from 'naive-ui'
|
||||
import type { SigninCallback } from '@/store/modules/signin/type'
|
||||
import type { AvatarProps, FlexProps } from 'naive-ui'
|
||||
|
||||
const AppAvatar = defineComponent({
|
||||
name: 'AppAvatar',
|
||||
props: {
|
||||
...avatarProps,
|
||||
...spaceProps,
|
||||
cursor: {
|
||||
type: String,
|
||||
default: 'auto',
|
||||
},
|
||||
spaceSize: {
|
||||
type: [String, Number] as PropType<SpaceProps['size']>,
|
||||
type: [String, Number, Array] as PropType<FlexProps['size']>,
|
||||
default: 'medium',
|
||||
},
|
||||
avatarSize: {
|
||||
type: [String, Number] as PropType<AvatarProps['size']>,
|
||||
default: 'medium',
|
||||
},
|
||||
vertical: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
},
|
||||
setup(props) {
|
||||
const signin = getStorage<SigninCallback>(APP_CATCH_KEY.signin)
|
||||
const cssVars = computed(() => {
|
||||
const vars = {
|
||||
'--app-avatar-cursor': props.cursor,
|
||||
}
|
||||
|
||||
return vars
|
||||
})
|
||||
setup() {
|
||||
const { getSigningCallback } = useSigningGetters()
|
||||
|
||||
return {
|
||||
signin,
|
||||
cssVars,
|
||||
getSigningCallback,
|
||||
}
|
||||
},
|
||||
render() {
|
||||
const { getSigningCallback, avatarSize, spaceSize, $props, vertical } = this
|
||||
|
||||
return (
|
||||
<NSpace
|
||||
class="app-avatar"
|
||||
{...this.$props}
|
||||
wrapItem={false}
|
||||
style={this.cssVars}
|
||||
size={this.spaceSize}
|
||||
>
|
||||
<NAvatar
|
||||
// eslint-disable-next-line prettier/prettier, @typescript-eslint/no-explicit-any
|
||||
{...(this.$props as any)}
|
||||
src={this.signin?.avatar}
|
||||
objectFit="cover"
|
||||
round
|
||||
size={this.avatarSize}
|
||||
/>
|
||||
<div class="app-avatar__name">{this.signin?.name}</div>
|
||||
</NSpace>
|
||||
<NButton quaternary strong focusable={false}>
|
||||
<NFlex align="center" size={spaceSize} vertical={vertical}>
|
||||
<NAvatar
|
||||
{...($props as AvatarProps)}
|
||||
src={getSigningCallback?.avatar}
|
||||
objectFit="cover"
|
||||
round
|
||||
size={avatarSize}
|
||||
>
|
||||
{{
|
||||
default: () =>
|
||||
getSigningCallback.avatar
|
||||
? null
|
||||
: getSigningCallback?.name?.[0],
|
||||
}}
|
||||
</NAvatar>
|
||||
{getSigningCallback?.name}
|
||||
</NFlex>
|
||||
</NButton>
|
||||
)
|
||||
},
|
||||
})
|
||||
|
@ -1,14 +1,3 @@
|
||||
/**
|
||||
*
|
||||
* @author Ray <https://github.com/XiaoDaiGua-Ray>
|
||||
*
|
||||
* @date 2023-01-18
|
||||
*
|
||||
* @workspace ray-template
|
||||
*
|
||||
* @remark 今天也是元气满满撸代码的一天
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* 全屏加载效果
|
||||
@ -16,8 +5,8 @@
|
||||
* 基于 Naive UI Spin 组件
|
||||
*
|
||||
* 使用方法
|
||||
* 1. import { setSpin } from '@/spin'
|
||||
* 2. setSpin(true) | setSpin(false)
|
||||
* 1. import { setVariable } from '@/hooks'
|
||||
* 2. setVariable('globalSpinning', true) | setVariable('globalSpinning', false)
|
||||
*
|
||||
* 仅需按照上述步骤实现全屏加载动画
|
||||
*
|
||||
@ -29,9 +18,9 @@
|
||||
import { NSpin } from 'naive-ui'
|
||||
|
||||
import { spinProps } from 'naive-ui'
|
||||
import { spinValue } from './hook'
|
||||
import { getVariableToRefs } from '@/global-variable'
|
||||
|
||||
export { setSpin } from './hook'
|
||||
import type { SpinProps } from 'naive-ui'
|
||||
|
||||
const GlobalSpin = defineComponent({
|
||||
name: 'GlobalSpin',
|
||||
@ -42,6 +31,7 @@ const GlobalSpin = defineComponent({
|
||||
const overrides = {
|
||||
opacitySpinning: '0.3',
|
||||
}
|
||||
const spinValue = getVariableToRefs('globalSpinning')
|
||||
|
||||
return {
|
||||
spinValue,
|
||||
@ -51,11 +41,14 @@ const GlobalSpin = defineComponent({
|
||||
render() {
|
||||
return (
|
||||
<NSpin
|
||||
{...this.$props}
|
||||
{...(this.$props as SpinProps)}
|
||||
show={this.spinValue}
|
||||
themeOverrides={this.overrides}
|
||||
style="height: var(--html-height)"
|
||||
>
|
||||
{{ ...this.$slots }}
|
||||
{{
|
||||
...this.$slots,
|
||||
}}
|
||||
</NSpin>
|
||||
)
|
||||
},
|
@ -1,24 +1,14 @@
|
||||
/**
|
||||
*
|
||||
* @author Ray <https://github.com/XiaoDaiGua-Ray>
|
||||
*
|
||||
* @date 2023-06-20
|
||||
*
|
||||
* @workspace ray-template
|
||||
*
|
||||
* @remark 今天也是元气满满撸代码的一天
|
||||
*/
|
||||
import { useStorage } from '@vueuse/core'
|
||||
import { APP_CATCH_KEY } from '@/app-config'
|
||||
|
||||
/**
|
||||
*
|
||||
* 统一管理是否处于锁屏状态
|
||||
*
|
||||
* 可以根据后台接口进行替换该变量, 只要是一个响应式的变量值即可
|
||||
*/
|
||||
|
||||
const appLockScreen = useStorage('isAppLockScreen', false, sessionStorage, {
|
||||
mergeDefaults: true,
|
||||
})
|
||||
const appLockScreen = useStorage(
|
||||
APP_CATCH_KEY.isAppLockScreen,
|
||||
false,
|
||||
window.localStorage,
|
||||
{
|
||||
mergeDefaults: true,
|
||||
},
|
||||
)
|
||||
|
||||
const useAppLockScreen = () => {
|
||||
const setLockAppScreen = (bool: boolean) => {
|
||||
|
@ -1,47 +1,41 @@
|
||||
/**
|
||||
*
|
||||
* @author Ray <https://github.com/XiaoDaiGua-Ray>
|
||||
*
|
||||
* @date 2023-06-20
|
||||
*
|
||||
* @workspace ray-template
|
||||
*
|
||||
* @remark 今天也是元气满满撸代码的一天
|
||||
*/
|
||||
import { NInput, NFormItem, NButton } from 'naive-ui'
|
||||
import AppAvatar from '@/app-components/app/AppAvatar'
|
||||
import { RForm } from '@/components'
|
||||
|
||||
/** 锁屏界面 */
|
||||
|
||||
import { NInput, NForm, NFormItem, NButton, NSpace } from 'naive-ui'
|
||||
import AppAvatar from '@/app-components/app/AppAvatar/index'
|
||||
|
||||
import { useSetting } from '@/store'
|
||||
import useAppLockScreen from '@/app-components/app/AppLockScreen/appLockVar'
|
||||
import { rules, useCondition } from '@/app-components/app/AppLockScreen/hook'
|
||||
import { rules, useCondition } from '@/app-components/app/AppLockScreen/shared'
|
||||
import { useSettingActions } from '@/store'
|
||||
import { useTemplateRef } from 'vue'
|
||||
import { useForm } from '@/components'
|
||||
import { APP_CATCH_KEY } from '@/app-config'
|
||||
import { setStorage, encrypt } from '@/utils'
|
||||
|
||||
import type { FormInst, InputInst } from 'naive-ui'
|
||||
import type { InputInst } from 'naive-ui'
|
||||
|
||||
const LockScreen = defineComponent({
|
||||
name: 'LockScreen',
|
||||
setup() {
|
||||
const formInstRef = ref<FormInst | null>(null)
|
||||
const inputInstRef = ref<InputInst | null>(null)
|
||||
const [register, { validate }] = useForm()
|
||||
const inputInstRef = useTemplateRef<InputInst | null>('inputInstRef')
|
||||
|
||||
const { setLockAppScreen } = useAppLockScreen()
|
||||
const { changeSwitcher } = useSetting()
|
||||
const { updateSettingState } = useSettingActions()
|
||||
|
||||
const state = reactive({
|
||||
lockCondition: useCondition(),
|
||||
})
|
||||
|
||||
/** 锁屏 */
|
||||
const lockScreen = () => {
|
||||
formInstRef.value?.validate((error) => {
|
||||
if (!error) {
|
||||
setLockAppScreen(true)
|
||||
changeSwitcher(true, 'lockScreenSwitch')
|
||||
validate().then(() => {
|
||||
setLockAppScreen(true)
|
||||
updateSettingState('lockScreenSwitch', false)
|
||||
setStorage(
|
||||
APP_CATCH_KEY.appLockScreenPasswordKey,
|
||||
encrypt(state.lockCondition.lockPassword),
|
||||
'localStorage',
|
||||
)
|
||||
|
||||
state.lockCondition = useCondition()
|
||||
}
|
||||
state.lockCondition = useCondition()
|
||||
})
|
||||
}
|
||||
|
||||
@ -54,35 +48,51 @@ const LockScreen = defineComponent({
|
||||
return {
|
||||
...toRefs(state),
|
||||
lockScreen,
|
||||
formInstRef,
|
||||
register,
|
||||
inputInstRef,
|
||||
}
|
||||
},
|
||||
render() {
|
||||
const { register } = this
|
||||
|
||||
return (
|
||||
<div class="app-lock-screen__input">
|
||||
<AppAvatar vertical align="center" avatarSize={52} />
|
||||
<NForm
|
||||
ref="formInstRef"
|
||||
model={this.lockCondition}
|
||||
rules={rules}
|
||||
labelPlacement="left"
|
||||
>
|
||||
<NFormItem path="lockPassword">
|
||||
<NInput
|
||||
ref="inputInstRef"
|
||||
v-model:value={this.lockCondition.lockPassword}
|
||||
type="password"
|
||||
placeholder="请输入锁屏密码"
|
||||
clearable
|
||||
minlength={6}
|
||||
maxlength={12}
|
||||
/>
|
||||
</NFormItem>
|
||||
<NButton type="primary" onClick={this.lockScreen.bind(this)}>
|
||||
锁屏
|
||||
</NButton>
|
||||
</NForm>
|
||||
<div class="app-lock-screen__content">
|
||||
<div class="app-lock-screen__input">
|
||||
<AppAvatar
|
||||
avatarSize={52}
|
||||
style="pointer-events: none;margin: 24px 0;"
|
||||
vertical
|
||||
/>
|
||||
<RForm
|
||||
ref="formInstRef"
|
||||
model={this.lockCondition}
|
||||
rules={rules}
|
||||
labelPlacement="left"
|
||||
onRegister={register}
|
||||
>
|
||||
<NFormItem path="lockPassword">
|
||||
<NInput
|
||||
ref="inputInstRef"
|
||||
v-model:value={this.lockCondition.lockPassword}
|
||||
type="password"
|
||||
placeholder="请输入锁屏密码"
|
||||
clearable
|
||||
showPasswordOn="click"
|
||||
minlength={6}
|
||||
maxlength={12}
|
||||
onKeydown={(e: KeyboardEvent) => {
|
||||
if (e.code === 'Enter') {
|
||||
this.lockScreen()
|
||||
}
|
||||
}}
|
||||
autofocus
|
||||
/>
|
||||
</NFormItem>
|
||||
<NButton type="primary" onClick={this.lockScreen.bind(this)}>
|
||||
锁屏
|
||||
</NButton>
|
||||
</RForm>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
},
|
||||
|
@ -1,45 +1,37 @@
|
||||
/**
|
||||
*
|
||||
* @author Ray <https://github.com/XiaoDaiGua-Ray>
|
||||
*
|
||||
* @date 2023-06-20
|
||||
*
|
||||
* @workspace ray-template
|
||||
*
|
||||
* @remark 今天也是元气满满撸代码的一天
|
||||
*/
|
||||
import '../../index.scss'
|
||||
|
||||
/** 解锁界面 */
|
||||
|
||||
import { NInput, NForm, NFormItem, NButton, NSpace } from 'naive-ui'
|
||||
import AppAvatar from '@/app-components/app/AppAvatar/index'
|
||||
import { NInput, NFormItem, NButton, NFlex } from 'naive-ui'
|
||||
import AppAvatar from '@/app-components/app/AppAvatar'
|
||||
import { RForm } from '@/components'
|
||||
|
||||
import dayjs from 'dayjs'
|
||||
import { useSetting, useSignin } from '@/store'
|
||||
import { rules, useCondition } from '@/app-components/app/AppLockScreen/hook'
|
||||
import { useSigningActions, useSettingActions } from '@/store'
|
||||
import { rules, useCondition } from '@/app-components/app/AppLockScreen/shared'
|
||||
import useAppLockScreen from '@/app-components/app/AppLockScreen/appLockVar'
|
||||
import { useDevice } from '@/hooks'
|
||||
import { useForm } from '@/components'
|
||||
import { APP_CATCH_KEY } from '@/app-config'
|
||||
import { removeStorage, decrypt, getStorage } from '@/utils'
|
||||
|
||||
import type { FormInst, InputInst } from 'naive-ui'
|
||||
|
||||
const UnlockScreen = defineComponent({
|
||||
export default defineComponent({
|
||||
name: 'UnlockScreen',
|
||||
setup() {
|
||||
const formRef = ref<FormInst | null>(null)
|
||||
const inputInstRef = ref<InputInst | null>(null)
|
||||
const [register, { validate }] = useForm()
|
||||
|
||||
const { logout } = useSignin()
|
||||
const { changeSwitcher } = useSetting()
|
||||
const { logout } = useSigningActions()
|
||||
const { updateSettingState } = useSettingActions()
|
||||
const { setLockAppScreen } = useAppLockScreen()
|
||||
const { isTabletOrSmaller } = useDevice()
|
||||
|
||||
const HH_MM_FORMAT = 'HH:mm'
|
||||
const AM_PM_FORMAT = 'A'
|
||||
const YY_MM_DD_FORMAT = 'YY年MM月DD日'
|
||||
const YY_MM_DD_FORMAT = 'YYYY-MM-DD'
|
||||
const DDD_FORMAT = 'ddd'
|
||||
|
||||
const state = reactive({
|
||||
lockCondition: useCondition(),
|
||||
HH_MM: dayjs().format(HH_MM_FORMAT),
|
||||
AM_PM: dayjs().locale('en').format(AM_PM_FORMAT),
|
||||
AM_PM: dayjs().format(AM_PM_FORMAT),
|
||||
YY_MM_DD: dayjs().format(YY_MM_DD_FORMAT),
|
||||
DDD: dayjs().format(DDD_FORMAT),
|
||||
})
|
||||
@ -52,30 +44,55 @@ const UnlockScreen = defineComponent({
|
||||
state.DDD = dayjs().format(DDD_FORMAT)
|
||||
}, 86_400_000)
|
||||
|
||||
/** 退出登陆并且回到登陆页 */
|
||||
const backToSignin = () => {
|
||||
const toSigningFn = () => {
|
||||
removeStorage(APP_CATCH_KEY.appLockScreenPasswordKey, 'localStorage')
|
||||
updateSettingState('lockScreenSwitch', false)
|
||||
setTimeout(() => {
|
||||
logout()
|
||||
}, 100)
|
||||
}
|
||||
|
||||
const backToSigning = () => {
|
||||
window.$dialog.warning({
|
||||
title: '警告',
|
||||
content: '是否返回到登陆页?',
|
||||
content: '是否返回到登陆页并且重新登录',
|
||||
positiveText: '确定',
|
||||
negativeText: '取消',
|
||||
onPositiveClick: () => {
|
||||
logout()
|
||||
setTimeout(() => {
|
||||
changeSwitcher(false, 'lockScreenSwitch')
|
||||
})
|
||||
},
|
||||
negativeText: '重新登录',
|
||||
onPositiveClick: toSigningFn,
|
||||
})
|
||||
}
|
||||
|
||||
/** 解锁 */
|
||||
const unlockScreen = () => {
|
||||
formRef.value?.validate((error) => {
|
||||
if (!error) {
|
||||
const catchPassword = getStorage<string>(
|
||||
APP_CATCH_KEY.appLockScreenPasswordKey,
|
||||
'localStorage',
|
||||
)
|
||||
|
||||
if (!catchPassword) {
|
||||
window.$dialog.warning({
|
||||
title: '警告',
|
||||
content: () => '检测到锁屏密码被修改,请重新登录',
|
||||
closable: false,
|
||||
maskClosable: false,
|
||||
closeOnEsc: false,
|
||||
positiveText: '重新登录',
|
||||
onPositiveClick: toSigningFn,
|
||||
})
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
const dCatchPassword = decrypt(catchPassword)
|
||||
|
||||
validate().then(() => {
|
||||
if (dCatchPassword === state.lockCondition.lockPassword) {
|
||||
setLockAppScreen(false)
|
||||
changeSwitcher(false, 'lockScreenSwitch')
|
||||
updateSettingState('lockScreenSwitch', false)
|
||||
removeStorage(APP_CATCH_KEY.appLockScreenPasswordKey, 'localStorage')
|
||||
|
||||
state.lockCondition = useCondition()
|
||||
} else {
|
||||
window.$message.warning('密码错误,请重新输入')
|
||||
}
|
||||
})
|
||||
}
|
||||
@ -87,60 +104,86 @@ const UnlockScreen = defineComponent({
|
||||
|
||||
return {
|
||||
...toRefs(state),
|
||||
backToSignin,
|
||||
backToSigning,
|
||||
unlockScreen,
|
||||
formRef,
|
||||
inputInstRef,
|
||||
isTabletOrSmaller,
|
||||
register,
|
||||
}
|
||||
},
|
||||
render() {
|
||||
const { isTabletOrSmaller } = this
|
||||
const { HH_MM, AM_PM, YY_MM_DD, DDD } = this
|
||||
const hmSplit = HH_MM.split(':')
|
||||
const { unlockScreen, backToSigning, register } = this
|
||||
|
||||
return (
|
||||
<div class="app-lock-screen__unlock">
|
||||
<div class="app-lock-screen__unlock__content">
|
||||
<div class="app-lock-screen__unlock__content-bg">
|
||||
<div class="left">{this.HH_MM?.split(':')[0]}</div>
|
||||
<div class="right">{this.HH_MM?.split(':')[1]}</div>
|
||||
</div>
|
||||
<div class="app-lock-screen__unlock__content-avatar">
|
||||
<AppAvatar vertical align="center" avatarSize={52} />
|
||||
</div>
|
||||
<div class="app-lock-screen__unlock__content-input">
|
||||
<NForm ref="formRef" model={this.lockCondition} rules={rules}>
|
||||
<NFormItem path="lockPassword">
|
||||
<NInput
|
||||
ref="inputInstRef"
|
||||
v-model:value={this.lockCondition.lockPassword}
|
||||
type="password"
|
||||
placeholder="请输入解锁密码"
|
||||
clearable
|
||||
minlength={6}
|
||||
maxlength={12}
|
||||
/>
|
||||
</NFormItem>
|
||||
<NSpace justify="space-between">
|
||||
<NButton
|
||||
type="primary"
|
||||
text
|
||||
onClick={this.backToSignin.bind(this)}
|
||||
>
|
||||
返回登陆
|
||||
</NButton>
|
||||
<NButton
|
||||
type="primary"
|
||||
text
|
||||
onClick={this.unlockScreen.bind(this)}
|
||||
>
|
||||
进入系统
|
||||
</NButton>
|
||||
</NSpace>
|
||||
</NForm>
|
||||
</div>
|
||||
<div class="app-lock-screen__unlock__content-date">
|
||||
<div class="current-date">
|
||||
{this.HH_MM} <span>{this.AM_PM}</span>
|
||||
<div class="app-lock-screen__content app-lock-screen__content--full">
|
||||
<div class="app-lock-screen__unlock">
|
||||
<div class="app-lock-screen__unlock__content">
|
||||
<div class="app-lock-screen__unlock__content-wrapper">
|
||||
<div
|
||||
class={[
|
||||
'app-lock-screen__unlock__content-bg__wrapper',
|
||||
'app-lock-screen__unlock__content-bg',
|
||||
isTabletOrSmaller
|
||||
? 'app-lock-screen__unlock__content-bg--smaller'
|
||||
: '',
|
||||
]}
|
||||
>
|
||||
<div class="left">{hmSplit[0]}</div>
|
||||
<div class="right">{hmSplit[1]}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="current-year">
|
||||
{this.YY_MM_DD} <span>{this.DDD}</span>
|
||||
<div class="app-lock-screen__unlock__content-avatar">
|
||||
<AppAvatar
|
||||
avatarSize={52}
|
||||
style="pointer-events: none;"
|
||||
vertical
|
||||
/>
|
||||
</div>
|
||||
<div class="app-lock-screen__unlock__content-input">
|
||||
<RForm
|
||||
onRegister={register}
|
||||
model={this.lockCondition}
|
||||
rules={rules}
|
||||
>
|
||||
<NFormItem path="lockPassword">
|
||||
<NInput
|
||||
autofocus
|
||||
v-model:value={this.lockCondition.lockPassword}
|
||||
type="password"
|
||||
placeholder="请输入解锁密码"
|
||||
clearable
|
||||
minlength={6}
|
||||
onKeydown={(e: KeyboardEvent) => {
|
||||
if (e.code === 'Enter') {
|
||||
unlockScreen()
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</NFormItem>
|
||||
<NFlex justify="space-between">
|
||||
<NButton
|
||||
type="primary"
|
||||
text
|
||||
onClick={backToSigning.bind(this)}
|
||||
>
|
||||
返回登陆
|
||||
</NButton>
|
||||
<NButton
|
||||
type="primary"
|
||||
text
|
||||
onClick={unlockScreen.bind(this)}
|
||||
>
|
||||
进入系统
|
||||
</NButton>
|
||||
</NFlex>
|
||||
</RForm>
|
||||
</div>
|
||||
<div class="app-lock-screen__unlock__content-date">
|
||||
<div class="current-year">
|
||||
{YY_MM_DD} <span>{DDD}</span> <span>{AM_PM}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -148,5 +191,3 @@ const UnlockScreen = defineComponent({
|
||||
)
|
||||
},
|
||||
})
|
||||
|
||||
export default UnlockScreen
|
||||
|
@ -1,10 +1,16 @@
|
||||
.app-lock-screen__content {
|
||||
&.app-lock-screen__content--full {
|
||||
width: 100%;
|
||||
height: var(--html-height);
|
||||
@include flexCenter;
|
||||
}
|
||||
|
||||
& .app-lock-screen__input {
|
||||
& button[class*="n-button"] {
|
||||
& button[class*='n-button'] {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
& form[class*="n-form"] {
|
||||
& form[class*='n-form'] {
|
||||
margin: 24px 0px;
|
||||
}
|
||||
}
|
||||
@ -12,35 +18,54 @@
|
||||
& .app-lock-screen__unlock {
|
||||
.app-lock-screen__unlock__content {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
@include flexCenter;
|
||||
flex-direction: column;
|
||||
|
||||
& .app-lock-screen__unlock__content-bg {
|
||||
position: absolute;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
@include flexCenter;
|
||||
font-size: 220px;
|
||||
gap: 80px;
|
||||
z-index: 0;
|
||||
& .app-lock-screen__unlock__content-wrapper {
|
||||
position: fixed;
|
||||
inset: 0px;
|
||||
|
||||
& .left,
|
||||
& .right {
|
||||
& .app-lock-screen__unlock__content-bg__wrapper {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background-color: rgb(16, 16, 20);
|
||||
}
|
||||
|
||||
& .app-lock-screen__unlock__content-bg {
|
||||
position: absolute;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
@include flexCenter;
|
||||
border-radius: 30px;
|
||||
background-color: #141313;
|
||||
font-weight: 700;
|
||||
padding: 80px;
|
||||
filter: blur(4px);
|
||||
font-size: 16.67rem;
|
||||
gap: 80px;
|
||||
z-index: 0;
|
||||
|
||||
&.app-lock-screen__unlock__content-bg--smaller {
|
||||
& .left,
|
||||
& .right {
|
||||
padding: 0px;
|
||||
font-size: 90px;
|
||||
padding: 24px;
|
||||
border-radius: 4px;
|
||||
}
|
||||
}
|
||||
|
||||
& .left,
|
||||
& .right {
|
||||
@include flexCenter;
|
||||
border-radius: 30px;
|
||||
background-color: #141313;
|
||||
font-weight: 700;
|
||||
padding: 80px;
|
||||
filter: blur(4px);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
& .app-lock-screen__unlock__content-avatar {
|
||||
margin-top: 5px;
|
||||
color: #bababa;
|
||||
font-weight: 500;
|
||||
font-weight: bolder;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
@ -60,9 +85,23 @@
|
||||
|
||||
& .current-year,
|
||||
& .current-date span {
|
||||
font-size: 1.5rem;
|
||||
font-size: 1.875rem;
|
||||
line-height: 2.25rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.ray-template--light {
|
||||
.app-lock-screen__unlock__content-bg__wrapper {
|
||||
background-color: #fff !important;
|
||||
}
|
||||
|
||||
.app-lock-screen__unlock__content-bg {
|
||||
& .left,
|
||||
& .right {
|
||||
background-color: rgba(244, 244, 245, 1) !important;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,57 +1,38 @@
|
||||
/**
|
||||
*
|
||||
* @author Ray <https://github.com/XiaoDaiGua-Ray>
|
||||
*
|
||||
* @date 2023-05-13
|
||||
*
|
||||
* @workspace ray-template
|
||||
*
|
||||
* @remark 今天也是元气满满撸代码的一天
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* 这里没有做解锁密码校验, 只要符合校验规则值皆可
|
||||
* 可以根据需求自行更改
|
||||
*/
|
||||
|
||||
import './index.scss'
|
||||
|
||||
import { NModal } from 'naive-ui'
|
||||
import { RModal } from '@/components'
|
||||
import LockScreen from './components/LockScreen'
|
||||
import UnlockScreen from './components/UnlockScreen'
|
||||
|
||||
import { useSetting } from '@/store'
|
||||
import useAppLockScreen from '@/app-components/app/AppLockScreen/appLockVar'
|
||||
import { useSettingGetters, useSettingActions } from '@/store'
|
||||
|
||||
const AppLockScreen = defineComponent({
|
||||
name: 'AppLockScreen',
|
||||
setup() {
|
||||
const settingStore = useSetting()
|
||||
const { lockScreenSwitch } = storeToRefs(settingStore)
|
||||
|
||||
const { getLockAppScreen } = useAppLockScreen()
|
||||
const { updateSettingState } = useSettingActions()
|
||||
const { getLockScreenSwitch } = useSettingGetters()
|
||||
const lockScreenSwitchRef = computed({
|
||||
get: () => getLockScreenSwitch.value,
|
||||
set: (val) => {
|
||||
updateSettingState('lockScreenSwitch', val)
|
||||
},
|
||||
})
|
||||
|
||||
return {
|
||||
lockScreenSwitch,
|
||||
getLockAppScreen,
|
||||
lockScreenSwitchRef,
|
||||
}
|
||||
},
|
||||
render() {
|
||||
return (
|
||||
<NModal
|
||||
v-model:show={this.lockScreenSwitch}
|
||||
<RModal
|
||||
v-model:show={this.lockScreenSwitchRef}
|
||||
transformOrigin="center"
|
||||
show
|
||||
autoFocus={false}
|
||||
maskClosable={false}
|
||||
closeOnEsc={false}
|
||||
preset={!this.getLockAppScreen() ? 'dialog' : undefined}
|
||||
preset="dialog"
|
||||
title="锁定屏幕"
|
||||
>
|
||||
<div class="app-lock-screen__content">
|
||||
{!this.getLockAppScreen() ? <LockScreen /> : <UnlockScreen />}
|
||||
</div>
|
||||
</NModal>
|
||||
<LockScreen />
|
||||
</RModal>
|
||||
)
|
||||
},
|
||||
})
|
||||
|
@ -1,14 +1,3 @@
|
||||
/**
|
||||
*
|
||||
* @author Ray <https://github.com/XiaoDaiGua-Ray>
|
||||
*
|
||||
* @date 2023-06-20
|
||||
*
|
||||
* @workspace ray-template
|
||||
*
|
||||
* @remark 今天也是元气满满撸代码的一天
|
||||
*/
|
||||
|
||||
import type { InputInst } from 'naive-ui'
|
||||
import type { Ref } from 'vue'
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { NAvatar, NTooltip, NSpace } from 'naive-ui'
|
||||
import { NAvatar, NTooltip, NFlex } from 'naive-ui'
|
||||
|
||||
interface AvatarOptions {
|
||||
key: string
|
||||
@ -7,45 +7,33 @@ interface AvatarOptions {
|
||||
icon: string
|
||||
}
|
||||
|
||||
const RayLink = defineComponent({
|
||||
name: 'RayLink',
|
||||
export default defineComponent({
|
||||
name: 'AppShareLink',
|
||||
setup() {
|
||||
const avatarOptions: AvatarOptions[] = [
|
||||
{
|
||||
key: 'yunhome',
|
||||
src: 'https://yunkuangao.me/',
|
||||
tooltip: '云之家',
|
||||
icon: 'https://yunkuangao.me/wp-content/uploads/2022/05/cropped-cropped-QQ%E5%9B%BE%E7%89%8720220511113928.jpg',
|
||||
},
|
||||
{
|
||||
key: 'yun-cloud-images',
|
||||
src: 'https://yunkuangao.com/',
|
||||
tooltip: '云图床',
|
||||
icon: 'https://yunkuangao.me/wp-content/uploads/2022/05/cropped-cropped-QQ%E5%9B%BE%E7%89%8720220511113928.jpg',
|
||||
},
|
||||
{
|
||||
key: 'ray-js-note',
|
||||
src: 'https://note.youdao.com/s/ObWEe2BB',
|
||||
tooltip: 'Ray的前端学习笔记',
|
||||
icon: 'https://usc1.contabostorage.com/c2e495d7890844d392e8ec0c6e5d77eb:image/longmao.jpeg',
|
||||
icon: 'https://avatars.githubusercontent.com/u/51957438?v=4',
|
||||
},
|
||||
{
|
||||
key: 'ray-js-cover',
|
||||
src: 'https://note.youdao.com/s/IC8xKPdB',
|
||||
tooltip: 'Ray的面试题总结',
|
||||
icon: 'https://usc1.contabostorage.com/c2e495d7890844d392e8ec0c6e5d77eb:image/longmao.jpeg',
|
||||
icon: 'https://avatars.githubusercontent.com/u/51957438?v=4',
|
||||
},
|
||||
{
|
||||
key: 'ray-template-doc',
|
||||
src: 'https://xiaodaigua-ray.github.io/ray-template-doc/',
|
||||
tooltip: 'Ray Template Doc',
|
||||
icon: 'https://usc1.contabostorage.com/c2e495d7890844d392e8ec0c6e5d77eb:image/longmao.jpeg',
|
||||
icon: 'https://avatars.githubusercontent.com/u/51957438?v=4',
|
||||
},
|
||||
{
|
||||
key: 'ray-template-doc-out',
|
||||
src: 'https://ray-template.yunkuangao.com/',
|
||||
tooltip: 'Ray Template Doc (国内地址)',
|
||||
icon: 'https://usc1.contabostorage.com/c2e495d7890844d392e8ec0c6e5d77eb:image/longmao.jpeg',
|
||||
icon: 'https://avatars.githubusercontent.com/u/51957438?v=4',
|
||||
},
|
||||
]
|
||||
|
||||
@ -60,9 +48,9 @@ const RayLink = defineComponent({
|
||||
},
|
||||
render() {
|
||||
return (
|
||||
<NSpace>
|
||||
<NFlex>
|
||||
{this.avatarOptions.map((curr) => (
|
||||
<NTooltip>
|
||||
<NTooltip key={curr.key}>
|
||||
{{
|
||||
trigger: () => (
|
||||
<NAvatar
|
||||
@ -80,16 +68,7 @@ const RayLink = defineComponent({
|
||||
}}
|
||||
</NTooltip>
|
||||
))}
|
||||
</NSpace>
|
||||
</NFlex>
|
||||
)
|
||||
},
|
||||
})
|
||||
|
||||
export default RayLink
|
||||
|
||||
/**
|
||||
*
|
||||
* 友链组件
|
||||
*
|
||||
* 这个组件用作初试模板中, 不喜欢自行删除
|
||||
*/
|
@ -1,14 +1,3 @@
|
||||
/**
|
||||
*
|
||||
* @author Ray <https://github.com/XiaoDaiGua-Ray>
|
||||
*
|
||||
* @date 2023-06-14
|
||||
*
|
||||
* @workspace ray-template
|
||||
*
|
||||
* @remark 今天也是元气满满撸代码的一天
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* 全局注入 naive ui 提示性组件
|
||||
@ -26,63 +15,82 @@ import {
|
||||
createDiscreteApi,
|
||||
darkTheme,
|
||||
NGlobalStyle,
|
||||
NModalProvider,
|
||||
} from 'naive-ui'
|
||||
|
||||
import { useSetting } from '@/store'
|
||||
import { naiveLocales } from '@/locales/helper'
|
||||
import { getNaiveLocales } from '@/locales/utils'
|
||||
import { useSettingGetters } from '@/store'
|
||||
import { MESSAGE_PROVIDER } from '@/app-config'
|
||||
|
||||
const GlobalProvider = defineComponent({
|
||||
export default defineComponent({
|
||||
name: 'GlobalProvider',
|
||||
setup() {
|
||||
const settingStore = useSetting()
|
||||
setup(_, { expose }) {
|
||||
const { getPrimaryColorOverride, getAppTheme, getLocaleLanguage } =
|
||||
useSettingGetters()
|
||||
|
||||
const modelPrimaryColorOverride = computed(
|
||||
() => settingStore.primaryColorOverride,
|
||||
)
|
||||
const modelThemeValue = computed(() =>
|
||||
settingStore.themeValue ? darkTheme : null,
|
||||
)
|
||||
const localePackage = computed(() => {
|
||||
const key = settingStore.localeLanguage
|
||||
const key = getLocaleLanguage.value
|
||||
|
||||
return naiveLocales(key)
|
||||
return getNaiveLocales(key)
|
||||
})
|
||||
|
||||
const { message, notification, dialog, loadingBar } = createDiscreteApi(
|
||||
['message', 'dialog', 'notification', 'loadingBar'],
|
||||
{
|
||||
configProviderProps: computed(() => ({
|
||||
theme: modelThemeValue.value,
|
||||
})),
|
||||
},
|
||||
)
|
||||
/**
|
||||
*
|
||||
* 使用 createDiscreteApi 脱离上下文 api 注入一些常用的组件
|
||||
* 通过 window.$message、window.$notification、window.$dialog、window.$loadingBar 访问
|
||||
* 但是,使用该组件注册后,使用 window.$notification 组件时不能更改 placement 位置(只能默认右上角弹出)
|
||||
*
|
||||
* 改为函数包裹,避免 `slot default invoked outside of render` 警告
|
||||
*/
|
||||
const discreteApi = () => {
|
||||
const { message, notification, dialog, loadingBar } = createDiscreteApi(
|
||||
['message', 'dialog', 'notification', 'loadingBar'],
|
||||
{
|
||||
configProviderProps: computed(() => ({
|
||||
theme: getAppTheme.value ? darkTheme : null,
|
||||
})),
|
||||
},
|
||||
)
|
||||
|
||||
window.$dialog = dialog // 注入 `dialog`
|
||||
window.$message = message // 注入 `message`
|
||||
window.$loadingBar = loadingBar // 注入 `loadingBar`
|
||||
window.$notification = notification // 注入 `notification`
|
||||
window.$dialog = dialog // 注入 `dialog`
|
||||
window.$message = message // 注入 `message`
|
||||
window.$loadingBar = loadingBar // 注入 `loadingBar`
|
||||
window.$notification = notification // 注入 `notification`
|
||||
}
|
||||
|
||||
expose()
|
||||
|
||||
return {
|
||||
modelPrimaryColorOverride,
|
||||
modelThemeValue,
|
||||
getPrimaryColorOverride,
|
||||
localePackage,
|
||||
getAppTheme,
|
||||
discreteApi,
|
||||
}
|
||||
},
|
||||
render() {
|
||||
const {
|
||||
$slots: { default: slotDefault },
|
||||
discreteApi,
|
||||
} = this
|
||||
const { getPrimaryColorOverride, getAppTheme, localePackage } = this
|
||||
|
||||
return (
|
||||
<NConfigProvider
|
||||
themeOverrides={this.modelPrimaryColorOverride}
|
||||
theme={this.modelThemeValue}
|
||||
locale={this.localePackage.locale}
|
||||
dateLocale={this.localePackage.dateLocal}
|
||||
themeOverrides={getPrimaryColorOverride}
|
||||
theme={getAppTheme ? darkTheme : null}
|
||||
locale={localePackage.locale}
|
||||
dateLocale={localePackage.dateLocal}
|
||||
>
|
||||
<NLoadingBarProvider>
|
||||
<NMessageProvider>
|
||||
<NMessageProvider {...MESSAGE_PROVIDER}>
|
||||
<NDialogProvider>
|
||||
<NNotificationProvider>
|
||||
<NGlobalStyle />
|
||||
{this.$slots.default?.()}
|
||||
</NNotificationProvider>
|
||||
<NModalProvider>
|
||||
<NNotificationProvider>
|
||||
<NGlobalStyle />
|
||||
{slotDefault?.()}
|
||||
{discreteApi()}
|
||||
</NNotificationProvider>
|
||||
</NModalProvider>
|
||||
</NDialogProvider>
|
||||
</NMessageProvider>
|
||||
</NLoadingBarProvider>
|
||||
@ -90,5 +98,3 @@ const GlobalProvider = defineComponent({
|
||||
)
|
||||
},
|
||||
})
|
||||
|
||||
export default GlobalProvider
|
||||
|
@ -1,40 +0,0 @@
|
||||
/**
|
||||
*
|
||||
* @author Ray <https://github.com/XiaoDaiGua-Ray>
|
||||
*
|
||||
* @date 2023-07-21
|
||||
*
|
||||
* @workspace ray-template
|
||||
*
|
||||
* @remark 今天也是元气满满撸代码的一天
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* 路由更新前,取消上一路由所有请求
|
||||
*
|
||||
* 生命周期示意图:
|
||||
* beforeRouteUpdate -> cancelAllRequest -> routeUpdate
|
||||
*/
|
||||
|
||||
import { axiosCanceler } from '@/axios/helper/interceptor'
|
||||
|
||||
const AppRequestCanceler = defineComponent({
|
||||
name: 'AppRequestCanceler',
|
||||
setup() {
|
||||
onBeforeRouteUpdate(() => {
|
||||
axiosCanceler.cancelAllRequest()
|
||||
})
|
||||
},
|
||||
render() {
|
||||
return (
|
||||
<div
|
||||
style={{
|
||||
display: 'none',
|
||||
}}
|
||||
></div>
|
||||
)
|
||||
},
|
||||
})
|
||||
|
||||
export default AppRequestCanceler
|
@ -0,0 +1,25 @@
|
||||
/**
|
||||
*
|
||||
* 路由更新前,取消上一路由所有请求
|
||||
*
|
||||
* 生命周期示意图:
|
||||
* beforeRouteUpdate -> cancelAllRequest -> routeUpdate
|
||||
*/
|
||||
|
||||
import { axiosCanceler } from '@/axios/utils/interceptor'
|
||||
|
||||
const AppRequestCancelerProvider = defineComponent({
|
||||
name: 'AppRequestCancelerProvider',
|
||||
setup(_, { expose }) {
|
||||
onBeforeRouteUpdate(() => {
|
||||
axiosCanceler.cancelAllRequest()
|
||||
})
|
||||
|
||||
expose()
|
||||
},
|
||||
render() {
|
||||
return <div class="app-style-provider"></div>
|
||||
},
|
||||
})
|
||||
|
||||
export default AppRequestCancelerProvider
|
@ -1,106 +1,101 @@
|
||||
/**
|
||||
*
|
||||
* @author Ray <https://github.com/XiaoDaiGua-Ray>
|
||||
*
|
||||
* @date 2023-07-08
|
||||
*
|
||||
* @workspace ray-template
|
||||
*
|
||||
* @remark 今天也是元气满满撸代码的一天
|
||||
*/
|
||||
|
||||
import './index.scss'
|
||||
|
||||
import { getStorage } from '@/utils/cache'
|
||||
import { get } from 'lodash-es'
|
||||
import { useSetting } from '@/store'
|
||||
import { addClass, removeClass, addStyle, colorToRgba } from '@/utils/element'
|
||||
import {
|
||||
setClass,
|
||||
removeClass,
|
||||
setStyle,
|
||||
colorToRgba,
|
||||
getStorage,
|
||||
} from '@/utils'
|
||||
import { useSettingGetters } from '@/store'
|
||||
import { APP_CATCH_KEY, GLOBAL_CLASS_NAMES, APP_THEME } from '@/app-config'
|
||||
import { useWindowSize } from '@vueuse/core'
|
||||
|
||||
import type { SettingState } from '@/store/modules/setting/type'
|
||||
import type { SettingState } from '@/store/modules/setting/types'
|
||||
|
||||
const AppStyleProvider = defineComponent({
|
||||
export default defineComponent({
|
||||
name: 'AppStyleProvider',
|
||||
setup() {
|
||||
const settingStore = useSetting()
|
||||
setup(_, { expose }) {
|
||||
const { getAppTheme } = useSettingGetters()
|
||||
const { height, width } = useWindowSize()
|
||||
|
||||
const { themeValue } = storeToRefs(settingStore)
|
||||
|
||||
/** 同步主题色变量至 body, 如果未获取到缓存值则已默认值填充 */
|
||||
// 同步主题色变量至 html,如果未获取到缓存值则已默认值填充
|
||||
const syncPrimaryColorToBody = () => {
|
||||
// 默认主题色
|
||||
const {
|
||||
appPrimaryColor: { primaryColor, primaryFadeColor },
|
||||
} = __APP_CFG__ // 默认主题色
|
||||
const body = document.body
|
||||
} = APP_THEME
|
||||
// 主题色配置 class 名
|
||||
const { rayTemplateThemePrimaryColor, rayTemplateThemePrimaryFadeColor } =
|
||||
GLOBAL_CLASS_NAMES
|
||||
|
||||
const html = document.documentElement
|
||||
|
||||
// 获取缓存 naive ui 配置项
|
||||
const primaryColorOverride = getStorage<SettingState>(
|
||||
'piniaSettingStore',
|
||||
APP_CATCH_KEY.appPiniaSettingStore,
|
||||
'localStorage',
|
||||
)
|
||||
|
||||
if (primaryColorOverride) {
|
||||
const _p = get(
|
||||
// 获取主色调
|
||||
const p = get(
|
||||
primaryColorOverride,
|
||||
'primaryColorOverride.common.primaryColor',
|
||||
primaryColor,
|
||||
)
|
||||
const _fp = colorToRgba(_p, 0.38)
|
||||
// 将主色调任意颜色转换为 rgba 格式
|
||||
const fp = colorToRgba(p, 0.85)
|
||||
|
||||
/** 设置全局主题色 css 变量 */
|
||||
body.style.setProperty('--ray-theme-primary-color', _p)
|
||||
body.style.setProperty(
|
||||
'--ray-theme-primary-fade-color',
|
||||
_fp || primaryFadeColor,
|
||||
// 设置全局主题色 css 变量
|
||||
html.style.setProperty(rayTemplateThemePrimaryColor, p) // 主色调
|
||||
// 降低透明度后的主色调
|
||||
html.style.setProperty(
|
||||
rayTemplateThemePrimaryFadeColor,
|
||||
fp || primaryFadeColor,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/** 隐藏加载动画 */
|
||||
// 隐藏加载动画
|
||||
const hiddenLoadingAnimation = () => {
|
||||
/** pre-loading-animation 是默认 id */
|
||||
const el = document.getElementById('pre-loading-animation')
|
||||
// pre-loading-animation 是默认 id
|
||||
const el = document.getElementById(GLOBAL_CLASS_NAMES.preLoadingAnimation)
|
||||
|
||||
if (el) {
|
||||
addStyle(el, {
|
||||
setStyle(el, {
|
||||
display: 'none',
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/** 切换主题时, 同步更新 body class 以便于进行自定义 css 配置 */
|
||||
// 切换主题时,同步更新 html class 以便于进行自定义 css 配置
|
||||
const updateGlobalThemeClass = (bool: boolean) => {
|
||||
/**
|
||||
*
|
||||
* 初始化时根据当前主题色进行初始化 body 的 class 属性
|
||||
*
|
||||
* 根据 themeValue 进行初始化
|
||||
*/
|
||||
const body = document.body
|
||||
const darkClassName = 'ray-template--dark'
|
||||
const lightClassName = 'ray-template--light'
|
||||
const html = document.documentElement
|
||||
const { darkClassName, lightClassName } = GLOBAL_CLASS_NAMES
|
||||
|
||||
bool
|
||||
? removeClass(body, lightClassName)
|
||||
: removeClass(body, darkClassName)
|
||||
? removeClass(html, lightClassName)
|
||||
: removeClass(html, darkClassName)
|
||||
|
||||
addClass(body, bool ? darkClassName : lightClassName)
|
||||
setClass(html, bool ? darkClassName : lightClassName)
|
||||
}
|
||||
|
||||
syncPrimaryColorToBody()
|
||||
hiddenLoadingAnimation()
|
||||
|
||||
watch(
|
||||
() => themeValue.value,
|
||||
(ndata) => {
|
||||
updateGlobalThemeClass(ndata)
|
||||
},
|
||||
{
|
||||
immediate: true,
|
||||
},
|
||||
)
|
||||
watchEffect(() => {
|
||||
// 当切换主题时,更新 html 当前的注入 class
|
||||
updateGlobalThemeClass(getAppTheme.value)
|
||||
// 注入全局宽高尺寸
|
||||
setStyle(document.documentElement, {
|
||||
[GLOBAL_CLASS_NAMES.htmlHeight]: `${height.value}px`,
|
||||
[GLOBAL_CLASS_NAMES.htmlWidth]: `${width.value}px`,
|
||||
})
|
||||
})
|
||||
|
||||
expose()
|
||||
},
|
||||
render() {
|
||||
return <div class="app-style-provider"></div>
|
||||
},
|
||||
})
|
||||
|
||||
export default AppStyleProvider
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user