Skip to content

Commit

Permalink
style: fix
Browse files Browse the repository at this point in the history
  • Loading branch information
markthree committed Apr 12, 2022
1 parent 8ee5ebe commit 5724208
Show file tree
Hide file tree
Showing 34 changed files with 183 additions and 228 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ VITE_APP_API_AUTO_IMPORT = true
# 项目级 api 自动按需导入
# src/composables 下凡是 use 开头的模块,同时里边有 default 导出,该导出就可以被按需自动引入
# src/stores 下凡是 Store 结尾的模块,同时里边有 default 导出,该导出就可以按需自动引入
VITE_APP_DIR_API_AUTO_IMPORT = true
VITE_APP_DIR_API_AUTO_IMPORT = true
2 changes: 1 addition & 1 deletion .env.development
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@


# 开发时 Inspect 调试支持
# VITE_APP_Inspect = true
# VITE_APP_Inspect = true
2 changes: 1 addition & 1 deletion .env.production
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@


# 生产时压缩算法,可选 gzip, brotliCompress, deflate, deflateRaw
# VITE_APP_COMPRESSINON_ALGORITHM = gzip
# VITE_APP_COMPRESSINON_ALGORITHM = gzip
16 changes: 8 additions & 8 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ MIT LICENSE

Copyright (c) 2022 markthree

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
48 changes: 18 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -413,11 +413,11 @@ export default [
return {
code: 0,
data: {
name: 'vben'
}
name: 'vben',
},
}
}
}
},
},
] as MockMethod[]
```

Expand Down Expand Up @@ -502,14 +502,14 @@ export default 1000
export default defineStore('counter', {
state() {
return {
counter: 1
counter: 1,
}
},
actions: {
inc() {
this.counter++
}
}
},
},
})
```

Expand Down Expand Up @@ -672,9 +672,7 @@ npm i @iconify/mdi -D

```html
<template>
<div class="bg-red-500 text-white">
我是红色背景的白色文本
</div>
<div class="bg-red-500 text-white">我是红色背景的白色文本</div>
<template></template
></template>
```
Expand All @@ -685,9 +683,7 @@ npm i @iconify/mdi -D

```html
<template>
<div text="white" bg="red-500">
我是红色背景的白色文本
</div>
<div text="white" bg="red-500">我是红色背景的白色文本</div>
<template></template
></template>
```
Expand Down Expand Up @@ -748,7 +744,7 @@ export const useDarks = () => ({ isDark, toggleDark })
</script>

<template>
<div m="6"> Hello,This is the tov template!! </div>
<div m="6">Hello,This is the tov template!!</div>
<div m="6" cursor="pointer" @click="toggleDark()">
light: {{ isDark }} click me!!
</div>
Expand Down Expand Up @@ -805,8 +801,8 @@ export const useCounterStore = defineStore('counter', {
actions: {
inc() {
this.count++
}
}
},
},
})
```

Expand Down Expand Up @@ -1069,9 +1065,9 @@ not-found: 未找到页面
</script>
<template>
<div m="6" cursor="pointer" @click="toggleLocale()"
>language: {{ t('index') }} click me!!</div
>
<div m="6" cursor="pointer" @click="toggleLocale()">
language: {{ t('index') }} click me!!
</div>
</template>
```
Expand Down Expand Up @@ -1107,11 +1103,7 @@ not-found: 未找到页面
```html
<!-- 省略各种代码 -->
<template>
<img
src="/notFound/32.svg"
class="cover"
alt="page not found"
/>
<img src="/notFound/32.svg" class="cover" alt="page not found" />
</template>
```
Expand All @@ -1120,11 +1112,7 @@ not-found: 未找到页面
```html
<!-- 省略各种代码 -->
<template>
<img
src="/notFound/33.svg"
class="cover"
alt="page not found"
/>
<img src="/notFound/33.svg" class="cover" alt="page not found" />
</template>
```
Expand All @@ -1146,7 +1134,7 @@ not-found: 未找到页面
export default defineComponent({
render() {
return <div>Test</div>
}
},
})
```
Expand Down
42 changes: 21 additions & 21 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<link rel="icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite App</title>
<script>
;(function () {
const prefersDark =
window.matchMedia &&
window.matchMedia('(prefers-color-scheme: dark)').matches
const setting = localStorage.getItem('vueuse-color-scheme') || 'auto'
if (setting === 'dark' || (prefersDark && setting !== 'light'))
document.documentElement.classList.toggle('dark', true)
})()
</script>
</head>

<head>
<meta charset="UTF-8" />
<link rel="icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite App</title>
<script>
(function () {
const prefersDark = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches
const setting = localStorage.getItem('vueuse-color-scheme') || 'auto'
if (setting === 'dark' || (prefersDark && setting !== 'light'))
document.documentElement.classList.toggle('dark', true)
})()
</script>
</head>

<body>
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
</body>

</html>
<body>
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
</body>
</html>
20 changes: 10 additions & 10 deletions mock/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ export default [
return {
code: 0,
data: {
name: 'vben'
}
name: 'vben',
},
}
}
},
},
{
url: '/api/post',
Expand All @@ -19,24 +19,24 @@ export default [
response: {
code: 0,
data: {
name: 'vben'
}
}
name: 'vben',
},
},
},
{
url: '/api/text',
method: 'post',
rawResponse: async (req, res) => {
let reqbody = ''
await new Promise(resolve => {
req.on('data', chunk => {
await new Promise((resolve) => {
req.on('data', (chunk) => {
reqbody += chunk
})
req.on('end', () => resolve(undefined))
})
res.setHeader('Content-Type', 'text/plain')
res.statusCode = 200
res.end(`hello, ${reqbody}`)
}
}
},
},
] as MockMethod[]
7 changes: 2 additions & 5 deletions presets/plugins/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ export const GenerateTitle = (): Plugin => {
title = config.env.VITE_APP_TITLE
},
transformIndexHtml(html) {
return html.replace(
/<title>(.*?)<\/title>/,
`<title>${title}</title>`
)
}
return html.replace(/<title>(.*?)<\/title>/, `<title>${title}</title>`)
},
}
}
2 changes: 1 addition & 1 deletion presets/plugins/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default () => {
wrapperClasses: markdownWrapperClasses,
markdownItSetup(md) {
md.use(Prism)
}
},
})
)
}
14 changes: 4 additions & 10 deletions presets/shared/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,17 @@ const useEnv = () => {
VITE_APP_API_AUTO_IMPORT,
VITE_APP_MOCK_IN_PRODUCTION,
VITE_APP_DIR_API_AUTO_IMPORT,
VITE_APP_COMPRESSINON_ALGORITHM
VITE_APP_COMPRESSINON_ALGORITHM,
} = env

const newEnv = {
VITE_APP_TITLE,
VITE_APP_COMPRESSINON_ALGORITHM,
VITE_APP_INSPECT: stringToBoolean(VITE_APP_INSPECT),
VITE_APP_MARKDOWN: stringToBoolean(VITE_APP_MARKDOWN),
VITE_APP_API_AUTO_IMPORT: stringToBoolean(
VITE_APP_API_AUTO_IMPORT
),
VITE_APP_MOCK_IN_PRODUCTION: stringToBoolean(
VITE_APP_MOCK_IN_PRODUCTION
),
VITE_APP_DIR_API_AUTO_IMPORT: stringToBoolean(
VITE_APP_DIR_API_AUTO_IMPORT
)
VITE_APP_API_AUTO_IMPORT: stringToBoolean(VITE_APP_API_AUTO_IMPORT),
VITE_APP_MOCK_IN_PRODUCTION: stringToBoolean(VITE_APP_MOCK_IN_PRODUCTION),
VITE_APP_DIR_API_AUTO_IMPORT: stringToBoolean(VITE_APP_DIR_API_AUTO_IMPORT),
}
return newEnv
}
Expand Down
28 changes: 8 additions & 20 deletions presets/shared/mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,8 @@ import Mock from 'mockjs'
export function createFetchSever(mockList: any[]) {
if (!window['originFetch']) {
window['originFetch'] = window.fetch
window.fetch = function (
fetchUrl: string,
init: RequestInit
) {
const currentMock = mockList.find(mi =>
fetchUrl.includes(mi.url)
)
window.fetch = function (fetchUrl: string, init: any) {
const currentMock = mockList.find((mi) => fetchUrl.includes(mi.url))
if (currentMock) {
const result = createFetchReturn(currentMock, init)
return result
Expand All @@ -41,23 +36,19 @@ function __param2Obj__(url: string) {
)
}

function __Fetch2ExpressReqWrapper__(
handle: (d: any) => any
) {
function __Fetch2ExpressReqWrapper__(handle: () => any) {
return function (options: any) {
let result = null
if (typeof handle === 'function') {
const { body, method, url, headers } = options

let b = body
try {
b = JSON.parse(body)
} catch {}
b = JSON.parse(body)
result = handle({
method,
body: b,
query: __param2Obj__(url),
headers
headers,
})
} else {
result = handle
Expand All @@ -69,17 +60,14 @@ function __Fetch2ExpressReqWrapper__(

const sleep = (delay = 0) => {
if (delay) {
return new Promise(resolve => {
return new Promise((resolve) => {
setTimeout(resolve, delay)
})
}
return null
}

async function createFetchReturn(
mock: any,
init: RequestInit
) {
async function createFetchReturn(mock: any, init) {
const { timeout, response } = mock
const mockFn = __Fetch2ExpressReqWrapper__(response)
const data = mockFn(init)
Expand All @@ -95,7 +83,7 @@ async function createFetchReturn(
},
json() {
return Promise.resolve(data)
}
},
}
return result
}
Loading

0 comments on commit 5724208

Please sign in to comment.