Skip to content

Commit

Permalink
feat: add template-vue-a
Browse files Browse the repository at this point in the history
  • Loading branch information
zhengyuzi committed Jul 25, 2024
1 parent 52bc820 commit 3c86604
Show file tree
Hide file tree
Showing 24 changed files with 384 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ pnpm create yu [project-name] --template [template-name]

## Template List:

None
- vue-a (Vue3 + TypeScript + Vite + VueRouter + UnoCss + VueUse + Axios)
4 changes: 2 additions & 2 deletions src/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { green } from 'kolorist'

export default [
{
name: 'vue-ts',
display: 'vue-ts',
name: 'vue-a',
display: 'vue-a (Vue3 + TypeScript + Vite + VueRouter + UnoCss + VueUse + Axios)',
color: green,
},
]
3 changes: 3 additions & 0 deletions template-vue-a/.vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"recommendations": ["Vue.volar"]
}
72 changes: 72 additions & 0 deletions template-vue-a/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{
"prettier.enable": false,
"editor.formatOnSave": false,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit",
"source.organizeImports": "never"
},
"eslint.rules.customizations": [
{
"rule": "style/*",
"severity": "off"
},
{
"rule": "format/*",
"severity": "off"
},
{
"rule": "*-indent",
"severity": "off"
},
{
"rule": "*-spacing",
"severity": "off"
},
{
"rule": "*-spaces",
"severity": "off"
},
{
"rule": "*-order",
"severity": "off"
},
{
"rule": "*-dangle",
"severity": "off"
},
{
"rule": "*-newline",
"severity": "off"
},
{
"rule": "*quotes",
"severity": "off"
},
{
"rule": "*semi",
"severity": "off"
}
],
"eslint.validate": [
"javascript",
"javascriptreact",
"typescript",
"typescriptreact",
"vue",
"html",
"markdown",
"json",
"jsonc",
"yaml",
"toml",
"xml",
"gql",
"graphql",
"astro",
"css",
"less",
"scss",
"pcss",
"postcss"
]
}
3 changes: 3 additions & 0 deletions template-vue-a/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# vue-a

Vue3 + TypeScript + Vite + VueRouter + UnoCss + VueUse + Axios
22 changes: 22 additions & 0 deletions template-vue-a/_gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
3 changes: 3 additions & 0 deletions template-vue-a/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import antfu from '@antfu/eslint-config'

export default antfu()
12 changes: 12 additions & 0 deletions template-vue-a/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + Vue + TS</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
</body>
</html>
32 changes: 32 additions & 0 deletions template-vue-a/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "my-vue-app",
"type": "module",
"version": "0.0.0",
"private": true,
"scripts": {
"dev": "vite",
"build": "vue-tsc -b && vite build",
"preview": "vite preview"
},
"dependencies": {
"@unocss/reset": "^0.61.5",
"@vueuse/core": "^10.11.0",
"@vueuse/integrations": "^10.11.0",
"axios": "^1.7.2",
"crypto-js": "^4.2.0",
"vue": "^3.4.31",
"vue-router": "^4.4.0"
},
"devDependencies": {
"@antfu/eslint-config": "^2.21.3",
"@types/crypto-js": "^4.2.2",
"@vitejs/plugin-vue": "^5.0.5",
"eslint": "^9.6.0",
"typescript": "^5.2.2",
"unocss": "^0.61.5",
"unplugin-auto-import": "^0.18.2",
"unplugin-vue-components": "^0.27.3",
"vite": "^5.3.4",
"vue-tsc": "^2.0.24"
}
}
7 changes: 7 additions & 0 deletions template-vue-a/src/App.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<script setup lang="ts">
</script>

<template>
<router-view />
</template>
10 changes: 10 additions & 0 deletions template-vue-a/src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { createApp } from 'vue'
import App from './App.vue'
import router from './router'

import 'virtual:uno.css'

// https://unocss.dev/guide/style-reset
import '@unocss/reset/tailwind-compat.css'

createApp(App).use(router).mount('#app')
7 changes: 7 additions & 0 deletions template-vue-a/src/pages/home/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<script setup lang="ts">
</script>

<template>
<div>Home</div>
</template>
31 changes: 31 additions & 0 deletions template-vue-a/src/request/axios.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import axios from 'axios'

export const instance = axios.create({
baseURL: '',
// timeout: 20000,
// withCredentials: true,
})

// 请求拦截
instance.interceptors.request.use(
(config) => {
//
return config
},
(error) => {
//
return Promise.reject(error)
},
)

// 响应拦截
instance.interceptors.response.use(
(response) => {
//
return response
},
(error) => {
//
return Promise.reject(error)
},
)
12 changes: 12 additions & 0 deletions template-vue-a/src/request/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// import { useAxios } from '@vueuse/integrations/useAxios'
// import { instance } from './axios'

// export function getTestList() {
// return useAxios(
// '/test',
// {
// method: 'GET',
// },
// instance,
// )
// }
18 changes: 18 additions & 0 deletions template-vue-a/src/router/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import type { RouteRecordRaw } from 'vue-router'
import { createRouter, createWebHashHistory } from 'vue-router'

const routes: Array<RouteRecordRaw> = [
{
path: '/',
name: 'Home',
component: () => import('@/pages/home/index.vue'),
},
]

const router = createRouter({
// createWebHistory or createWebHashHistory
history: createWebHashHistory(),
routes,
})

export default router
1 change: 1 addition & 0 deletions template-vue-a/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// @/utils
34 changes: 34 additions & 0 deletions template-vue-a/src/utils/storage/crypto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import CryptoJS from 'crypto-js'

// 十六位十六进制数作为密钥
const SECRET_KEY = CryptoJS.enc.Utf8.parse('86f1fda459fa47c7')
// 十六位十六进制数作为密钥偏移量
const SECRET_IV = CryptoJS.enc.Utf8.parse('c18eea9cbe12489e')

/**
* 加密方法
*/
export function encrypt(data: string) {
const dataHex = CryptoJS.enc.Utf8.parse(data)
const encrypted = CryptoJS.AES.encrypt(dataHex, SECRET_KEY, {
iv: SECRET_IV,
mode: CryptoJS.mode.CBC,
padding: CryptoJS.pad.Pkcs7,
})
return encrypted.ciphertext.toString()
}

/**
* 解密方法
*/
export function decrypt(data: string) {
const encryptedHexStr = CryptoJS.enc.Hex.parse(data)
const str = CryptoJS.enc.Base64.stringify(encryptedHexStr)
const decrypt = CryptoJS.AES.decrypt(str, SECRET_KEY, {
iv: SECRET_IV,
mode: CryptoJS.mode.CBC,
padding: CryptoJS.pad.Pkcs7,
})
const decryptedStr = decrypt.toString(CryptoJS.enc.Utf8)
return decryptedStr.toString()
}
24 changes: 24 additions & 0 deletions template-vue-a/src/utils/storage/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* @/utils/storage/index.ts
* localstorage集中管理
*
* 添加: AUTH.value = {...}
* 清空: AUTH.value = null
*/
import { StorageSerializers, useStorage } from '@vueuse/core'

// 加密
// import { decrypt, encrypt } from './crypto'

// const serializer = {
// read: (v: any) => (v ? JSON.parse(decrypt(v)) : null),
// write: (v: any) => encrypt(JSON.stringify(v)),
// }

export interface Auth {
//
}

export const AUTH = useStorage<Auth | null>('AUTH', null, undefined, {
serializer: StorageSerializers.object,
})
1 change: 1 addition & 0 deletions template-vue-a/src/vite-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="vite/client" />
32 changes: 32 additions & 0 deletions template-vue-a/tsconfig.app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"compilerOptions": {
"composite": true,
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
"target": "ES2020",
"jsx": "preserve",
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"moduleDetection": "force",
"useDefineForClassFields": true,
"baseUrl": "./",
"module": "ESNext",

/* Bundler mode */
"moduleResolution": "bundler",
"paths": {
"@": ["src"],
"@/*": ["src/*"]
},
"resolveJsonModule": true,
"allowImportingTsExtensions": true,

/* Linting */
"strict": true,
"noFallthroughCasesInSwitch": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noEmit": true,
"isolatedModules": true,
"skipLibCheck": true
},
"include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.vue"]
}
11 changes: 11 additions & 0 deletions template-vue-a/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"references": [
{
"path": "./tsconfig.app.json"
},
{
"path": "./tsconfig.node.json"
}
],
"files": []
}
13 changes: 13 additions & 0 deletions template-vue-a/tsconfig.node.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"compilerOptions": {
"composite": true,
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
"module": "ESNext",
"moduleResolution": "bundler",
"strict": true,
"noEmit": true,
"allowSyntheticDefaultImports": true,
"skipLibCheck": true
},
"include": ["vite.config.ts"]
}
8 changes: 8 additions & 0 deletions template-vue-a/uno.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// uno.config.ts
import { defineConfig, presetUno } from 'unocss'

export default defineConfig({
presets: [
presetUno(),
],
})
Loading

0 comments on commit 3c86604

Please sign in to comment.