Skip to content

Commit 9307093

Browse files
committed
chore: update docs [deploy]
1 parent a80a913 commit 9307093

9 files changed

Lines changed: 67 additions & 16 deletions

File tree

‎packages/@core/preferences/src/config.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const defaultPreferences: Preferences = {
44
app: {
55
accessMode: 'frontend',
66
authPageLayout: 'panel-right',
7-
checkUpdatesPollingTime: 1,
7+
checkUpdatesInterval: 1,
88
colorGrayMode: false,
99
colorWeakMode: false,
1010
compact: false,

‎packages/@core/preferences/src/types.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ interface AppPreferences {
2222
/** 登录注册页面布局 */
2323
authPageLayout: AuthPageLayoutType;
2424
/** 检查更新轮询时间 */
25-
checkUpdatesPollingTime: number;
25+
checkUpdatesInterval: number;
2626
/** 是否开启灰色模式 */
2727
colorGrayMode: boolean;
2828
/** 是否开启色弱模式 */

‎packages/effects/layouts/src/basic/layout.vue‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ watch(
313313
<Toaster />
314314
<CheckUpdates
315315
v-if="preferences.app.enableCheckUpdates"
316-
:polling-time="preferences.app.checkUpdatesPollingTime"
316+
:check-updates-interval="preferences.app.checkUpdatesInterval"
317317
/>
318318

319319
<Transition v-if="preferences.widget.lockScreen" name="slide-up">

‎packages/effects/layouts/src/widgets/check-updates/check-updates.vue‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ import { ToastAction, useToast } from '@vben-core/shadcn-ui';
66
77
interface Props {
88
// 轮训时间,分钟
9-
pollingTime?: number;
9+
checkUpdatesInterval?: number;
1010
}
1111
1212
defineOptions({ name: 'CheckUpdates' });
1313
1414
const props = withDefaults(defineProps<Props>(), {
15-
pollingTime: 1,
15+
checkUpdatesInterval: 1,
1616
});
1717
1818
const lastVersionTag = ref('');
@@ -38,7 +38,6 @@ async function getVersionTag() {
3838
3939
async function checkForUpdates() {
4040
const versionTag = await getVersionTag();
41-
4241
if (!versionTag) {
4342
return;
4443
}
@@ -50,12 +49,11 @@ async function checkForUpdates() {
5049
}
5150
5251
if (lastVersionTag.value !== versionTag) {
53-
lastVersionTag.value = versionTag;
5452
clearInterval(timer.value);
55-
handleNotice();
53+
handleNotice(versionTag);
5654
}
5755
}
58-
function handleNotice() {
56+
function handleNotice(versionTag: string) {
5957
const { dismiss } = toast({
6058
action: h('div', [
6159
h(
@@ -74,6 +72,7 @@ function handleNotice() {
7472
altText: $t('common.refresh'),
7573
class: 'bg-primary hover:bg-primary-hover mx-1',
7674
onClick: () => {
75+
lastVersionTag.value = versionTag;
7776
window.location.reload();
7877
},
7978
},
@@ -90,7 +89,10 @@ function handleNotice() {
9089
9190
function start() {
9291
// 每5分钟检查一次
93-
timer.value = setInterval(checkForUpdates, props.pollingTime * 60 * 1000);
92+
timer.value = setInterval(
93+
checkForUpdates,
94+
props.checkUpdatesInterval * 60 * 1000,
95+
);
9496
}
9597
9698
function handleVisibilitychange() {

‎website/.vitepress/config.mts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,9 @@ function sidebarGuide(): DefaultTheme.SidebarItem[] {
247247
// { link: 'in-depth/layout', text: '布局' },
248248
{ link: 'in-depth/theme', text: '主题' },
249249
{ link: 'in-depth/access', text: '权限' },
250-
{ link: 'in-depth/features', text: '功能' },
251250
{ link: 'in-depth/locale', text: '国际化' },
251+
{ link: 'in-depth/features', text: '常用功能' },
252+
{ link: 'in-depth/check-updates', text: '检查更新' },
252253
{ link: 'in-depth/loading', text: '全局loading' },
253254
],
254255
},

‎website/src/guide/essentials/settings.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ const defaultPreferences: Preferences = {
174174
app: {
175175
accessMode: 'frontend',
176176
authPageLayout: 'panel-right',
177-
checkUpdatesPollingTime: 1,
177+
checkUpdatesInterval: 1,
178178
colorGrayMode: false,
179179
colorWeakMode: false,
180180
compact: false,
@@ -291,7 +291,7 @@ interface AppPreferences {
291291
/** 登录注册页面布局 */
292292
authPageLayout: AuthPageLayoutType;
293293
/** 检查更新轮询时间 */
294-
checkUpdatesPollingTime: number;
294+
checkUpdatesInterval: number;
295295
/** 是否开启灰色模式 */
296296
colorGrayMode: boolean;
297297
/** 是否开启色弱模式 */
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# 检查更新
2+
3+
## 介绍
4+
5+
当网站更新时,你可能会想要检查更新,框架提供了这个能力,通过轮训检查更新,你可以在应用的 `preferences.ts` 文件中配置 `checkUpdatesInterval` 和 `enableCheckUpdates` 字段,用于开启和设置检查更新的时间间隔,单位为`分钟`。
6+
7+
```ts
8+
import { defineOverridesPreferences } from '@vben/preferences';
9+
10+
export const overridesPreferences = defineOverridesPreferences({
11+
// overrides
12+
app: {
13+
// 是否开启检查更新
14+
enableCheckUpdates: true,
15+
// 检查更新的时间间隔,单位为分钟
16+
checkUpdatesInterval: 1,
17+
},
18+
});
19+
```
20+
21+
## 效果
22+
23+
当检测到更新时,会弹出提示框,提示用户是否刷新页面:
24+
25+
![check-updates](/guide/update-notice.png)
26+
27+
## 替换为检测
28+
29+
如果你需要通过其他方式检查更新,比如通过接口,以便更灵活的控制更新的逻辑,可以做到强制刷新、显示更新内容等,你可以通过修改 `@vben/layouts` 下面的 `src/widgets/check-updates/check-updates.vue`文件来实现。
30+
31+
```ts
32+
// 这里可以替换为你的检查更新逻辑
33+
async function getVersionTag() {
34+
try {
35+
const response = await fetch('/', {
36+
cache: 'no-cache',
37+
method: 'HEAD',
38+
});
39+
40+
return (
41+
response.headers.get('etag') || response.headers.get('last-modified')
42+
);
43+
} catch {
44+
console.error('Failed to fetch version tag');
45+
return null;
46+
}
47+
}
48+
```

‎website/src/guide/in-depth/features.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 功能
1+
# 常用功能
22

33
一些常用的功能合集。
44

@@ -59,7 +59,7 @@ export const overridesPreferences = defineOverridesPreferences({
5959

6060
- 默认值:`false`
6161

62-
开启后网页会显示水印。在应用目录下的`preferences.ts`,开启或者关闭即可。
62+
开启后网页会显示水印,在应用目录下的`preferences.ts`,开启或者关闭即可。
6363

6464
```ts
6565
export const overridesPreferences = defineOverridesPreferences({
@@ -70,7 +70,7 @@ export const overridesPreferences = defineOverridesPreferences({
7070
});
7171
```
7272

73-
如果你想更新水印的内容,可以这么做,参数可以参考 [watermark-js-plus](https://zhensherlock.github.io/watermark-js-plus/):
73+
如果你想更新水印的内容,可以这么做,参数可以参考 [watermark-js-plus](https://zhensherlock.github.io/watermark-js-plus/):
7474

7575
```ts
7676
import { useWatermark } from '@vben/hooks';
400 KB
Loading

0 commit comments

Comments
 (0)