Skip to content

Commit 36498a1

Browse files
authored
chore: annotate code in english (#2)
1 parent 063ff65 commit 36498a1

File tree

6 files changed

+99
-100
lines changed

6 files changed

+99
-100
lines changed

build/vite/vconsole.ts

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,44 @@
1-
import path from 'node:path'
2-
import { viteVConsole } from 'vite-plugin-vconsole'
3-
4-
export function createViteVConsole() {
5-
return viteVConsole({
6-
entry: [path.resolve('src/main.ts')],
7-
enabled: false,
8-
config: {
9-
maxLogNumber: 1000,
10-
theme: 'light',
11-
},
12-
// https://github.com/vadxq/vite-plugin-vconsole/issues/21
13-
dynamicConfig: {
14-
theme: `document.documentElement.classList.contains('dark') ? 'dark' : 'light'`,
15-
},
16-
eventListener: `
17-
const targetElement = document.querySelector('html'); // 择要监听的元素
18-
const observerOptions = {
19-
attributes: true, // 监听属性变化
20-
attributeFilter: ['class'] // 只监听class属性变化
21-
};
22-
23-
// 定义回调函数来处理观察到的变化
24-
function handleAttributeChange(mutationsList) {
25-
for(let mutation of mutationsList) {
26-
if (mutation.type === 'attributes' && mutation.attributeName === 'class') {
27-
if (window && window.vConsole) {
28-
window.vConsole.dynamicChange.value = new Date().getTime();
29-
}
30-
}
31-
}
32-
}
33-
34-
// 创建观察者实例并传入回调函数
35-
const observer = new MutationObserver(handleAttributeChange);
36-
37-
// 开始观察目标元素
38-
observer.observe(targetElement, observerOptions);
39-
40-
// 当不再需要观察时,停止观察
41-
// observer.disconnect();
42-
`,
43-
})
44-
}
1+
import path from 'node:path'
2+
import { viteVConsole } from 'vite-plugin-vconsole'
3+
4+
export function createViteVConsole() {
5+
return viteVConsole({
6+
entry: [path.resolve('src/main.ts')],
7+
enabled: false,
8+
config: {
9+
maxLogNumber: 1000,
10+
theme: 'light',
11+
},
12+
// https://github.com/vadxq/vite-plugin-vconsole/issues/21
13+
dynamicConfig: {
14+
theme: `document.documentElement.classList.contains('dark') ? 'dark' : 'light'`,
15+
},
16+
eventListener: `
17+
const targetElement = document.querySelector('html'); // Choose the elements to be monitored
18+
const observerOptions = {
19+
attributes: true, // Monitor attribute changes
20+
attributeFilter: ['class'] // Only listen to changes in class attributes
21+
};
22+
23+
// Define a callback function to deal with observed changes
24+
function handleAttributeChange(mutationsList) {
25+
for(let mutation of mutationsList) {
26+
if (mutation.type === 'attributes' && mutation.attributeName === 'class') {
27+
if (window && window.vConsole) {
28+
window.vConsole.dynamicChange.value = new Date().getTime();
29+
}
30+
}
31+
}
32+
}
33+
34+
// Create an observer instance and pass in the callback function
35+
const observer = new MutationObserver(handleAttributeChange);
36+
37+
// Start observing the target element
38+
observer.observe(targetElement, observerOptions);
39+
40+
// Stop observing when you no longer need to observe.
41+
// observer.disconnect();
42+
`,
43+
})
44+
}

src/api/typing.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ export interface ResponseBody<T = any> {
55
success: boolean
66
}
77

8-
/** 统一返回结构体 */
9-
8+
/** Unified return structure */
109
export interface PageResult<T = any> {
1110
data: T[]
1211
current?: number

src/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import 'virtual:uno.css'
77
import '@/styles/app.less'
88
import { i18n } from '@/utils/i18n'
99

10-
// Varlet 桌面端适配
10+
// Varlet Desktop adaptation
1111
import '@varlet/touch-emulator'
1212

1313
const app = createApp(App)

src/utils/i18n.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ export const i18n = createI18n({
1414
messages,
1515
})
1616

17-
/** 多语言 picker columns */
17+
/** i18n picker columns */
1818
export const languageColumns: PickerColumnOption[] = [
1919
{ text: '简体中文', value: 'zh-CN' },
2020
{ text: 'English', value: 'en-US' },
2121
]
2222

23-
/** 当前语言 */
23+
/** Current language */
2424
export const locale = computed({
2525
get() {
2626
return (i18n.global.locale as unknown as Ref<string>).value
@@ -32,9 +32,9 @@ export const locale = computed({
3232
},
3333
})
3434

35-
// 载入 varlet 语言包
35+
// Load the varlet language package
3636
Locale.add('zh-CN', Locale.zhCN)
3737
Locale.add('en-US', Locale.enUS)
3838

39-
// 根据当前语言切换 varlet 语言包
39+
// Switch current language
4040
Locale.use(locale.value)

src/utils/request.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@ import axios from 'axios'
33
import { localStorage } from '@/utils/local-storage'
44
import { STORAGE_TOKEN_KEY } from '@/stores/mutation-type'
55

6-
// 这里是用于设定请求后端时,所用的 Token KEY
7-
// 可以根据自己的需要修改,常见的如 Access-Token,Authorization
8-
// 需要注意的是,请尽量保证使用中横线`-` 来作为分隔符,
9-
// 避免被 nginx 等负载均衡器丢弃了自定义的请求头
6+
// This is the Token KEY used to set the request backend.
7+
// You can modify it according to your own needs, such as Access-Token,Authorization
8+
// It should be noted that please try to use the horizontal line `-` as the separator
9+
// Avoid discarding custom request headers by load balancers such as nginx
1010
export const REQUEST_TOKEN_KEY = 'Access-Token'
1111

12-
// 创建 axios 实例
12+
// Create an axios instance
1313
const request = axios.create({
14-
// API 请求的默认前缀
14+
// API Default prefix for requests
1515
baseURL: import.meta.env.VITE_APP_API_BASE_URL,
16-
timeout: 6000, // 请求超时时间
16+
timeout: 6000, // Request timeout
1717
})
1818

1919
export type RequestError = AxiosError<{
@@ -22,28 +22,28 @@ export type RequestError = AxiosError<{
2222
errorMessage?: string
2323
}>
2424

25-
// 异常拦截处理器
25+
// Abnormal interception processor
2626
function errorHandler(error: RequestError): Promise<any> {
2727
if (error.response) {
2828
const { data = {}, status, statusText } = error.response
29-
// 403 无权限
29+
// 403 No permission
3030
if (status === 403)
3131
Snackbar({ type: 'warning', content: (data && data.message) || statusText })
3232

33-
// 401 未登录/未授权
33+
// 401 Not logged in/Unauthorized
3434
if (status === 401 && data.result && data.result.isLogin)
3535
Snackbar({ type: 'warning', content: 'Authorization verification failed' })
36-
// 如果你需要直接跳转登录页面
36+
// If you need to jump directly to the login page
3737
// location.replace(loginRoutePath)
3838
}
3939
return Promise.reject(error)
4040
}
4141

42-
// 请求拦截器
42+
// Request interceptor
4343
function requestHandler(config: InternalAxiosRequestConfig): InternalAxiosRequestConfig | Promise<InternalAxiosRequestConfig> {
4444
const savedToken = localStorage.get(STORAGE_TOKEN_KEY)
45-
// 如果 token 存在
46-
// 让每个请求携带自定义 token, 请根据实际情况修改
45+
// If the token exists
46+
// Let each request carry a custom token, please modify it according to the actual situation.
4747
if (savedToken)
4848
config.headers[REQUEST_TOKEN_KEY] = savedToken
4949

@@ -53,7 +53,7 @@ function requestHandler(config: InternalAxiosRequestConfig): InternalAxiosReques
5353
// Add a request interceptor
5454
request.interceptors.request.use(requestHandler, errorHandler)
5555

56-
// 响应拦截器
56+
// Response interceptor
5757
function responseHandler(response: { data: any }) {
5858
return response.data
5959
}

uno.config.ts

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
1-
import {
2-
defineConfig,
3-
presetAttributify,
4-
presetIcons,
5-
presetMini,
6-
presetUno,
7-
} from 'unocss'
8-
import { presetVarlet } from '@varlet/preset-unocss'
9-
10-
import presetRemToPx from '@unocss/preset-rem-to-px'
11-
12-
// 刚使用unocss的朋友,可以借助这个工具: https://to-unocss.netlify.app
13-
14-
export default defineConfig({
15-
presets: [
16-
presetUno,
17-
presetVarlet(),
18-
presetAttributify,
19-
presetIcons(),
20-
// 为什么要用到这个插件?
21-
// 模板使用 viewport 作为移动端适配方案,unocss 默认单位为 rem
22-
// 所以需要转成 px,然后由 postcss px 转成 vw/vh,完成适配
23-
presetRemToPx({
24-
// 这里为什么要设置基础字体大小?看下面这篇文章
25-
// https://juejin.cn/post/7262975395620618298
26-
baseFontSize: 4,
27-
}),
28-
presetMini(),
29-
],
30-
shortcuts: [
31-
// shortcuts to multiple utilities
32-
['btn', 'px-6 py-3 rounded-3 border-none inline-block bg-green-400 text-white cursor-pointer !outline-none hover:bg-green-600 disabled:cursor-default disabled:bg-gray-600 disabled:opacity-50'],
33-
],
34-
})
1+
import {
2+
defineConfig,
3+
presetAttributify,
4+
presetIcons,
5+
presetMini,
6+
presetUno,
7+
} from 'unocss'
8+
import { presetVarlet } from '@varlet/preset-unocss'
9+
10+
import presetRemToPx from '@unocss/preset-rem-to-px'
11+
12+
// Friends who have just used unocss can use this tool: https://to-unocss.netlify.app
13+
14+
export default defineConfig({
15+
presets: [
16+
presetUno,
17+
presetVarlet(),
18+
presetAttributify,
19+
presetIcons(),
20+
// Why use this plug-in?
21+
// The template uses viewport as the mobile adaptation scheme, and the default unit of unocss is rem
22+
// So it needs to be converted to px, and then postcss converts px to vw/vh to complete the adaptation.
23+
presetRemToPx({
24+
// Why do you want to set the basic font size here? Read the following article.
25+
// https://juejin.cn/post/7262975395620618298
26+
baseFontSize: 4,
27+
}),
28+
presetMini(),
29+
],
30+
shortcuts: [
31+
// shortcuts to multiple utilities
32+
['btn', 'px-6 py-3 rounded-3 border-none inline-block bg-green-400 text-white cursor-pointer !outline-none hover:bg-green-600 disabled:cursor-default disabled:bg-gray-600 disabled:opacity-50'],
33+
],
34+
})

0 commit comments

Comments
 (0)