Skip to content

Commit fe5e408

Browse files
committed
更新代码
1 parent d433859 commit fe5e408

7 files changed

Lines changed: 207 additions & 18 deletions

File tree

RELEASE.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
`2025-02-14`
1+
`2025-02-27`
22

3-
- 🔥 新增博文 [两步在 Vite 中配置 Tailwindcss](https://wordpress.biaov.cn/docs/35.html)
3+
- 🔥 新增博文 [Vue3.x 封装一个简单的日历](https://wordpress.biaov.cn/docs/36.html)
44
- ⚙️ 更新依赖版本
5-
- 🐞 修复图片问题
5+
- ⚙️ 同步 mine-h5-ui 文档

docs/.vitepress/sidebar/mineh5ui.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@
3939
"datetimePicker",
4040
"addressPicker",
4141
"upload",
42-
"form"
42+
"form",
43+
"calendar"
4344
]
4445
},
4546
{

docs/docs/36.md

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# Vue3.x 封装一个简单的日历
2+
3+
- 技术栈
4+
5+
`Vue3.x` + `Vite`
6+
7+
## 效果
8+
9+
![效果图](https://biaov.cn/static/calendar.svg)
10+
11+
## 初始化一个基于 Vue.3x 的 demo
12+
13+
```sh
14+
npm create vite@latest
15+
16+
npm i less -D
17+
```
18+
19+
20+
21+
## 开发组件
22+
23+
- 展示为 6\*7 的布局
24+
- 6 行 7 列
25+
26+
### 获取指定时间或者当前时间的年,月,日
27+
28+
```js
29+
const date = modelValue.value ? new Date(modelValue.value) : new Date()
30+
const [y, m, d] = [date.getFullYear(), date.getMonth() + 1, date.getDate()]
31+
```
32+
33+
### 获取当月开始星期用于计算前面填充时间
34+
35+
```js
36+
const curDays = []
37+
/**
38+
* 当月开始星期
39+
*/
40+
const startW = new Date(y, m, 1).getDay()
41+
let nm = m - 1
42+
let ny = y
43+
if (nm === 0) {
44+
nm = 12
45+
ny--
46+
}
47+
/**
48+
* 上月总天数
49+
*/
50+
const prevTotalDay = getMonthDay(ny, nm)
51+
Array.from({ length: startW }, (_, i) => {
52+
const newDay = prevTotalDay - i
53+
const tempDate = `${ny}-${nm}-${newDay}`
54+
curDays.push({ y: ny, m: nm, d: newDay, value: addZero(newDay), disabled: true, today: tempDate === nowDate })
55+
})
56+
```
57+
58+
### 填充当月总天数
59+
60+
```js
61+
/**
62+
* 当月总天数
63+
*/
64+
const totalDay = getMonthDay(y, m)
65+
Array.from({ length: totalDay }, (_, i) => {
66+
const nd = i + 1
67+
const tempDate = `${y}-${addZero(m)}-${addZero(nd)}`
68+
const today = tempDate === nowDate
69+
const selected = modelValue.value ? tempDate === modelValue.value : false
70+
curDays.push({ y, m, d: nd, value: addZero(nd), today, selected })
71+
})
72+
```
73+
74+
### 计算后面的填充时间
75+
76+
```js
77+
/**
78+
* 下月
79+
*/
80+
let nextM = m + 1
81+
let nextY = y
82+
if (nextM > 12) {
83+
nextM = 1
84+
nextY++
85+
}
86+
Array.from({ length: total - curDays.length }, (_, i) => {
87+
const nd = i + 1
88+
const tempDate = `${nextY}-${nextM}-${nd}`
89+
curDays.push({ y: nextY, m: nextM, d: nd, value: addZero(nd), disabled: true, today: tempDate === nowDate })
90+
})
91+
```
92+
93+
## 总结
94+
95+
- 这样6\*7的数据计算完成
96+
- 把这个计算封装一个方法,然后切换月和切换年时调用这个方法,这样日历就封装完成
97+
- [演示地址](https://mineh5ui.biaov.cn/v2/doc/calendar)
98+
- [源码地址](https://github.com/biaov/m-simple-calendar)

docs/mine-h5-ui/calendar.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Calendar 日历 `v2.14.0`
2+
3+
---
4+
5+
## 按需引入
6+
7+
```ts
8+
import { createApp } from 'vue'
9+
import App from './App.vue'
10+
import { MeCalendar } from 'mine-h5-ui'
11+
import 'mine-h5-ui/styles/MeCalendar.css'
12+
13+
createApp(App).use(MeCalendar).mount('#app')
14+
```
15+
16+
## 提示
17+
18+
- 如果你觉得重新编写 HTML 结构麻烦,可以直接复制下面的代码。
19+
20+
## 代码演示
21+
22+
### 基础用法
23+
24+
- 通过 `v-model:visible` 来设置是否显示
25+
- 通过 `v-model` 来绑定选择的值
26+
27+
```html
28+
<script setup>
29+
import { ref } from 'vue'
30+
31+
const visible = ref(false)
32+
const calendarValue = ref('')
33+
</script>
34+
<template>
35+
<me-calendar v-model:visible="visible" v-model="calendarValue" />
36+
</template>
37+
```
38+
39+
### 自定义主题
40+
41+
- 通过 `themeColor` 属性来设置自定义主题颜色。
42+
43+
CopyCode
44+
45+
```html
46+
<me-calendar theme-color="#f56c6c" />
47+
```
48+
49+
### 关闭器
50+
51+
- 通过 `closable` 属性来设置是否开启关闭器,点击日历以外的区域关闭组件
52+
- `true`: 开启,点击日期关闭组件
53+
- `false`: 关闭,点击日期不关闭组件
54+
55+
```html
56+
<me-calendar closable />
57+
```
58+
59+
## API
60+
61+
### 参数
62+
63+
| 参数 | 说明 | 类型 | 可选值 | 默认值 | 版本 |
64+
| --------------- | -------- | ------------ | ------------ | ------- | ------- |
65+
| v-model:visible | 显示状态 | boolean | true / false | false | v2.14.0 |
66+
| v-model | 日期 | string | -- | -- | v2.14.0 |
67+
| theme-color | 主题颜色 | string | -- | #409eff | v2.14.0 |
68+
| closable | 关闭器 | boolean | true / false | false | v2.14.0 |
69+
| style | 行内样式 | CSSStyleRule | -- | -- | v2.14.0 |
70+
71+
### 方法
72+
73+
| 方法名 | 说明 | 回调参数 | 版本 |
74+
| ------ | -------------- | ------------ | ------- |
75+
| change | 更新日期时触发 | `YYYY-MM-DD` | v2.14.0 |

docs/mine-h5-ui/logs.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,22 @@
1414

1515
:::TimeLine
1616

17-
## v2.13.0 - 最新版本
17+
## v2.14.0 - 最新版本
18+
19+
- 🔥 新增组件 [MeCalendar](/mine-h5-ui/calendar)
20+
- 🔥 新增依赖 `@tailwindcss/vite`
21+
- ⚙️ 更新依赖版本
22+
- ⚙️ 更新图标
23+
- ⚙️ 优化代码
24+
- ⚙️ 更新依赖 `globals``15.x` -> `16.x`
25+
- ⚙️ 更新依赖 `vite-node``2.x` -> `3.x`
26+
- ⚙️ 更新依赖 `vitest``2.x` -> `3.x`
27+
- ⚙️ 更新依赖 `vite``5.x` -> `6.x`
28+
- ⚙️ 更新依赖 `shiki``1.x` -> `3.x`
29+
- ⚙️ 更新依赖 `tailwindcss``3.x` -> `4.x`
30+
- ⚙️ 移除文档路由切换动画,增加切换效率
31+
32+
## v2.13.0
1833

1934
`2025-01-10`
2035

package-lock.json

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "wordpress",
3-
"version": "3.3.2",
3+
"version": "3.4.0",
44
"description": "一个基于 `vitepress` 搭建的个人博客 👍",
55
"scripts": {
66
"start": "npm run dev",
@@ -37,8 +37,8 @@
3737
},
3838
"homepage": "http://wordpress.biaov.cn/",
3939
"devDependencies": {
40-
"@types/node": "^22.13.4",
41-
"prettier": "^3.5.1",
40+
"@types/node": "^22.13.5",
41+
"prettier": "^3.5.2",
4242
"strip-json-comments": "^5.0.1",
4343
"vitepress": "^1.6.3"
4444
}

0 commit comments

Comments
 (0)