-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2d2828a
commit b713808
Showing
26 changed files
with
4,011 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false | ||
|
||
[*.{ts,js,vue,css}] | ||
indent_size = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
dist | ||
node_modules | ||
!.prettierrc.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
{ | ||
"extends": [ | ||
"plugin:@typescript-eslint/recommended", | ||
"@vue/typescript/recommended", | ||
"plugin:vue/vue3-recommended", | ||
"plugin:prettier/recommended" | ||
], | ||
"env": { | ||
"browser": true, | ||
"node": true, | ||
"jest": true, | ||
"es6": true | ||
}, | ||
"globals": { | ||
"defineProps": "readonly", | ||
"defineEmits": "readonly" | ||
}, | ||
"plugins": ["vue", "@typescript-eslint"], | ||
"parserOptions": { | ||
"parser": "@typescript-eslint/parser", | ||
"sourceType": "module", | ||
"allowImportExportEverywhere": true, | ||
"ecmaFeatures": { | ||
"jsx": true | ||
} | ||
}, | ||
"settings": { | ||
"import/extensions": [".js", ".jsx", ".ts", ".tsx"] | ||
}, | ||
"rules": { | ||
"no-console": "off", | ||
"no-continue": "off", | ||
"no-restricted-syntax": "off", | ||
"no-plusplus": "off", | ||
"no-param-reassign": "off", | ||
"no-shadow": "off", | ||
"guard-for-in": "off", | ||
|
||
"import/extensions": "off", | ||
"import/no-unresolved": "off", | ||
"import/no-extraneous-dependencies": "off", | ||
"import/prefer-default-export": "off", | ||
"import/first": "off", // https://github.com/vuejs/vue-eslint-parser/issues/58 | ||
"@typescript-eslint/no-explicit-any": "off", | ||
"@typescript-eslint/explicit-module-boundary-types": "off", | ||
"vue/first-attribute-linebreak": 0, | ||
|
||
"@typescript-eslint/no-unused-vars": [ | ||
"error", | ||
{ | ||
"argsIgnorePattern": "^_", | ||
"varsIgnorePattern": "^_" | ||
} | ||
], | ||
"no-unused-vars": [ | ||
"error", | ||
{ | ||
"argsIgnorePattern": "^_", | ||
"varsIgnorePattern": "^_" | ||
} | ||
], | ||
"no-use-before-define": "off", | ||
"@typescript-eslint/no-use-before-define": "off", | ||
"@typescript-eslint/ban-ts-comment": "off", | ||
"@typescript-eslint/ban-types": "off", | ||
"class-methods-use-this": "off" // 因为AxiosCancel必须实例化而能静态化所以加的规则,如果有办法解决可以取消 | ||
}, | ||
"overrides": [ | ||
{ | ||
"files": ["*.vue"], | ||
"rules": { | ||
"vue/component-name-in-template-casing": [2, "kebab-case"], | ||
"vue/require-default-prop": 0, | ||
"vue/multi-word-component-names": 0, | ||
"vue/no-reserved-props": 0, | ||
"vue/no-v-html": 0 | ||
} | ||
}, | ||
{ | ||
"files": ["*.ts", "*.tsx"], // https://github.com/typescript-eslint eslint-recommended | ||
"rules": { | ||
"constructor-super": "off", // ts(2335) & ts(2377) | ||
"getter-return": "off", // ts(2378) | ||
"no-const-assign": "off", // ts(2588) | ||
"no-dupe-args": "off", // ts(2300) | ||
"no-dupe-class-members": "off", // ts(2393) & ts(2300) | ||
"no-dupe-keys": "off", // ts(1117) | ||
"no-func-assign": "off", // ts(2539) | ||
"no-import-assign": "off", // ts(2539) & ts(2540) | ||
"no-new-symbol": "off", // ts(2588) | ||
"no-obj-calls": "off", // ts(2349) | ||
"no-redeclare": "off", // ts(2451) | ||
"no-setter-return": "off", // ts(2408) | ||
"no-this-before-super": "off", // ts(2376) | ||
"no-undef": "off", // ts(2304) | ||
"no-unreachable": "off", // ts(7027) | ||
"no-unsafe-negation": "off", // ts(2365) & ts(2360) & ts(2358) | ||
"no-var": "error", // ts transpiles let/const to var, so no need for vars any more | ||
"prefer-const": "error", // ts provides better types with const | ||
"prefer-rest-params": "error", // ts provides better types with rest args over arguments | ||
"prefer-spread": "error", // ts transpiles spread to apply, so no need for manual apply | ||
"valid-typeof": "off" // ts(2367) | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
node_modules | ||
.DS_Store | ||
dist | ||
dist-ssr | ||
*.local | ||
.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/sh | ||
. "$(dirname "$0")/_/husky.sh" | ||
|
||
npx --no-install commitlint --edit "$1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/sh | ||
. "$(dirname "$0")/_/husky.sh" | ||
|
||
npx lint-staged |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
module.exports = { | ||
// 一行最多 120 字符.. | ||
printWidth: 120, | ||
// 使用 2 个空格缩进 | ||
tabWidth: 2, | ||
// 不使用缩进符,而使用空格 | ||
useTabs: false, | ||
// 行尾需要有分号 | ||
semi: true, | ||
// 使用单引号 | ||
singleQuote: true, | ||
// 对象的 key 仅在必要时用引号 | ||
quoteProps: 'as-needed', | ||
// jsx 不使用单引号,而使用双引号 | ||
jsxSingleQuote: false, | ||
// 末尾需要有逗号 | ||
trailingComma: 'all', | ||
// 大括号内的首尾需要空格 | ||
bracketSpacing: true, | ||
// jsx 标签的反尖括号需要换行 | ||
jsxBracketSameLine: false, | ||
// 箭头函数,只有一个参数的时候,也需要括号 | ||
arrowParens: 'always', | ||
// 每个文件格式化的范围是文件的全部内容 | ||
rangeStart: 0, | ||
rangeEnd: Infinity, | ||
// 不需要写文件开头的 @prettier | ||
requirePragma: false, | ||
// 不需要自动在文件开头插入 @prettier | ||
insertPragma: false, | ||
// 使用默认的折行标准 | ||
proseWrap: 'preserve', | ||
// 根据显示样式决定 html 要不要折行 | ||
htmlWhitespaceSensitivity: 'css', | ||
// vue 文件中的 script 和 style 内不用缩进 | ||
vueIndentScriptAndStyle: false, | ||
// 换行符使用 lf | ||
endOfLine: 'lf', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# .stylelintignore | ||
# 其他类型文件 | ||
*.js | ||
*.jpg | ||
*.woff |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// commit-lint config | ||
module.exports = { extends: ['@commitlint/config-conventional'] }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<!DOCTYPE html> | ||
<html lang="zh-cn"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<link rel="icon" class="js-site-favicon" type="image/svg+xml" href="/favicon.ico"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Vue3Ts通用模板</title> | ||
</head> | ||
<body> | ||
<div id="app"></div> | ||
<script type="module" src="/src/main.ts"></script> | ||
<script> | ||
window.global = window; | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
{ | ||
"name": "vue3-ts-template", | ||
"version": "1.0.0", | ||
"license": "MIT", | ||
"scripts": { | ||
"dev": "vite", | ||
"build": "vue-tsc --noEmit && vite build", | ||
"preview": "vite preview", | ||
"prettier": "prettier --write .", | ||
"lint": "eslint --ext .vue,.js,jsx,.ts,.tsx ./ --max-warnings 0 --fix", | ||
"stylelint": "stylelint --fix src/**/*.{html,vue,less}", | ||
"prepare": "husky install" | ||
}, | ||
"dependencies": { | ||
"axios": "^0.27.2", | ||
"pinia": "^2.0.17", | ||
"vue": "^3.2.37", | ||
"vue-router": "^4.1.3" | ||
}, | ||
"devDependencies": { | ||
"@commitlint/cli": "^17.0.3", | ||
"@commitlint/config-conventional": "^17.0.3", | ||
"@types/node": "^18.6.3", | ||
"@typescript-eslint/eslint-plugin": "^5.31.0", | ||
"@typescript-eslint/parser": "^5.31.0", | ||
"@vitejs/plugin-vue": "^3.0.1", | ||
"@vue/compiler-sfc": "^3.2.37", | ||
"@vue/eslint-config-typescript": "^11.0.0", | ||
"eslint": "^8.21.0", | ||
"eslint-config-prettier": "^8.5.0", | ||
"eslint-plugin-import": "^2.26.0", | ||
"eslint-plugin-prettier": "^4.2.1", | ||
"eslint-plugin-vue": "^9.3.0", | ||
"husky": "^8.0.1", | ||
"less": "^4.1.3", | ||
"lint-staged": "^13.0.3", | ||
"mockjs": "^1.1.0", | ||
"prettier": "^2.7.1", | ||
"typescript": "^4.7.4", | ||
"vite": "^3.0.4", | ||
"vite-plugin-mock": "^2.9.6", | ||
"vue-tsc": "^0.39.4" | ||
}, | ||
"lint-staged": { | ||
"*.{js,jsx,vue,ts,tsx}": [ | ||
"prettier --write", | ||
"yarn lint" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<template> | ||
<router-view /> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<template> | ||
<div id="index"> | ||
<router-view /> | ||
</div> | ||
</template> | ||
|
||
<script lang="ts" setup></script> | ||
|
||
<style scoped></style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { createApp } from 'vue'; | ||
|
||
import { store } from './store'; | ||
import router from './router'; | ||
import '@/style/index.less'; | ||
import App from './App.vue'; | ||
|
||
const app = createApp(App); | ||
|
||
app.use(store); | ||
app.use(router); | ||
|
||
app.mount('#app'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { useRoute, createRouter, RouteRecordRaw, createWebHistory } from 'vue-router'; | ||
|
||
// 自动导入modules文件夹下所有ts文件 | ||
const modules = import.meta.glob('./modules/**/*.ts', { eager: true }) as Record<string, { [p: string]: any }>; | ||
|
||
// 路由暂存 | ||
const routeModuleList: Array<RouteRecordRaw> = []; | ||
|
||
Object.keys(modules).forEach((key) => { | ||
const mod = modules[key].default || {}; | ||
const modList = Array.isArray(mod) ? [...mod] : [mod]; | ||
routeModuleList.push(...modList); | ||
}); | ||
|
||
// 存放动态路由 | ||
export const asyncRouterList: Array<RouteRecordRaw> = [...routeModuleList]; | ||
|
||
// 存放固定的路由 | ||
const defaultRouterList: Array<RouteRecordRaw> = [ | ||
{ | ||
path: '/', | ||
redirect: '/index', | ||
}, | ||
{ | ||
path: '/:w+', | ||
name: '404Page', | ||
redirect: '/404', | ||
}, | ||
]; | ||
|
||
export const allRoutes = [...defaultRouterList, ...asyncRouterList]; | ||
|
||
export const getActive = (maxLevel = 3): string => { | ||
const route = useRoute(); | ||
if (!route.path) { | ||
return ''; | ||
} | ||
return route.path | ||
.split('/') | ||
.filter((_item: string, index: number) => index <= maxLevel && index > 0) | ||
.map((item: string) => `/${item}`) | ||
.join(''); | ||
}; | ||
|
||
const router = createRouter({ | ||
history: createWebHistory(), | ||
routes: allRoutes, | ||
scrollBehavior() { | ||
return { | ||
el: '#app', | ||
top: 0, | ||
behavior: 'smooth', | ||
}; | ||
}, | ||
}); | ||
|
||
export default router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import Layout from '@/layouts/index.vue'; | ||
|
||
export default [ | ||
{ | ||
path: '/index', | ||
component: Layout, | ||
name: 'HomeLayout', | ||
meta: { title: '首页' }, | ||
children: [ | ||
{ | ||
path: '', | ||
name: 'Home', | ||
component: () => import('@/views/home/index.vue'), | ||
meta: { title: '首页' }, | ||
}, | ||
], | ||
}, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export default [ | ||
{ | ||
path: '/404', | ||
name: '404', | ||
component: () => import('@/views/exception/404.vue'), | ||
}, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { createPinia } from 'pinia'; | ||
|
||
const store = createPinia(); | ||
|
||
export { store }; | ||
|
||
export * from './modules/user'; | ||
|
||
export default store; |
Oops, something went wrong.