Skip to content

Commit 55acd22

Browse files
committed
🐛 Fixed date selection issue in countdown widget
1 parent 809e12a commit 55acd22

10 files changed

+107
-115
lines changed

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
"@vueuse/integrations": "^10.5.0",
2222
"@vueuse/motion": "2.0.0-beta.12",
2323
"@vueuse/router": "^9.9.0",
24-
"@widget-js/core": "^0.11.22-beta.1",
25-
"@widget-js/vue3": "^0.11.21-rc.5",
24+
"@widget-js/core": "^0.11.22-beta.2",
25+
"@widget-js/vue3": "^0.11.21-rc.6",
2626
"animate.css": "^4.1.1",
2727
"axios": "^1.6.0",
2828
"color": "^4.2.3",
@@ -33,7 +33,7 @@
3333
"element-plus": "^2.2.26",
3434
"localforage": "^1.10.0",
3535
"lodash-es": "^4.17.21",
36-
"lunar-typescript": "^1.6.6",
36+
"lunar-typescript": "^1.7.0",
3737
"lyric-resolver": "^0.1.6",
3838
"nanoid": "^4.0.2",
3939
"pinia": "^2.1.6",

public/widget.json

+47-47
Original file line numberDiff line numberDiff line change
@@ -238,35 +238,36 @@
238238
"routes": []
239239
},
240240
{
241-
"name": "cn.widgetjs.widgets.labor_progress",
241+
"name": "cn.widgetjs.widgets.key_stroke",
242242
"title": {
243-
"zh-CN": "打工进度"
243+
"zh-CN": "键盘演示"
244244
},
245245
"description": {
246-
"zh-CN": "打工人,打工魂"
246+
"zh-CN": "在屏幕显示每一次快捷键敲击"
247247
},
248248
"keywords": [
249249
"recommend"
250250
],
251251
"security": false,
252-
"permissions": [],
252+
"permissions": [
253+
"keyboard"
254+
],
253255
"lang": "zh-CN",
254256
"width": 4,
255-
"height": 1,
256-
"maxWidth": 6,
257+
"height": 3,
258+
"maxWidth": 4,
257259
"webviewTag": false,
258-
"maxHeight": 2,
259-
"minWidth": 3,
260-
"minHeight": 1,
261-
"movable": true,
260+
"maxHeight": 3,
261+
"minWidth": 4,
262+
"minHeight": 3,
263+
"movable": false,
262264
"singleton": false,
263265
"resizable": true,
264-
"path": "/widget/labor_progress",
266+
"path": "/widget/key_stroke",
265267
"meta": {},
266-
"backgroundThrottling": true,
267-
"previewImage": "/images/preview_labor_progress.png",
268-
"supportDeployMode": 17,
269-
"configPagePath": "/widget/config/labor_progress",
268+
"backgroundThrottling": false,
269+
"previewImage": "/images/preview_keystroke.png",
270+
"supportDeployMode": 65536,
270271
"routes": []
271272
},
272273
{
@@ -302,40 +303,39 @@
302303
"routes": []
303304
},
304305
{
305-
"name": "cn.widgetjs.widgets.key_stroke",
306+
"name": "cn.widgetjs.widgets.countdown2",
306307
"title": {
307-
"zh-CN": "键盘演示"
308+
"zh-CN": "倒计时"
308309
},
309310
"description": {
310-
"zh-CN": "在屏幕显示每一次快捷键敲击"
311+
"zh-CN": "简单的倒计时组件,支持农历"
311312
},
312313
"keywords": [
313314
"recommend"
314315
],
315316
"security": false,
316-
"permissions": [
317-
"keyboard"
318-
],
317+
"permissions": [],
319318
"lang": "zh-CN",
320-
"width": 4,
321-
"height": 3,
319+
"width": 2,
320+
"height": 2,
322321
"maxWidth": 4,
323322
"webviewTag": false,
324-
"maxHeight": 3,
325-
"minWidth": 4,
326-
"minHeight": 3,
327-
"movable": false,
323+
"maxHeight": 4,
324+
"minWidth": 2,
325+
"minHeight": 2,
326+
"movable": true,
328327
"singleton": false,
329328
"resizable": true,
330-
"path": "/widget/key_stroke",
329+
"path": "/widget/countdown2",
331330
"meta": {},
332-
"backgroundThrottling": false,
333-
"previewImage": "/images/preview_keystroke.png",
334-
"supportDeployMode": 65536,
331+
"backgroundThrottling": true,
332+
"previewImage": "/images/preview_countdown2.png",
333+
"supportDeployMode": 17,
334+
"configPagePath": "/widget/config/countdown2",
335335
"routes": []
336336
},
337337
{
338-
"name": "cn.widgetjs.widgets.countdown2",
338+
"name": "cn.widgetjs.widgets.countdown",
339339
"title": {
340340
"zh-CN": "倒计时"
341341
},
@@ -358,44 +358,44 @@
358358
"movable": true,
359359
"singleton": false,
360360
"resizable": true,
361-
"path": "/widget/countdown2",
361+
"path": "/widget/countdown",
362362
"meta": {},
363363
"backgroundThrottling": true,
364-
"previewImage": "/images/preview_countdown2.png",
364+
"previewImage": "/images/preview_countdown.png",
365365
"supportDeployMode": 17,
366-
"configPagePath": "/widget/config/countdown2",
366+
"configPagePath": "/widget/config/countdown",
367367
"routes": []
368368
},
369369
{
370-
"name": "cn.widgetjs.widgets.countdown",
370+
"name": "cn.widgetjs.widgets.labor_progress",
371371
"title": {
372-
"zh-CN": "倒计时"
372+
"zh-CN": "打工进度"
373373
},
374374
"description": {
375-
"zh-CN": "简单的倒计时组件,支持农历"
375+
"zh-CN": "打工人,打工魂"
376376
},
377377
"keywords": [
378378
"recommend"
379379
],
380380
"security": false,
381381
"permissions": [],
382382
"lang": "zh-CN",
383-
"width": 2,
384-
"height": 2,
385-
"maxWidth": 4,
383+
"width": 4,
384+
"height": 1,
385+
"maxWidth": 6,
386386
"webviewTag": false,
387-
"maxHeight": 4,
388-
"minWidth": 2,
389-
"minHeight": 2,
387+
"maxHeight": 2,
388+
"minWidth": 3,
389+
"minHeight": 1,
390390
"movable": true,
391391
"singleton": false,
392392
"resizable": true,
393-
"path": "/widget/countdown",
393+
"path": "/widget/labor_progress",
394394
"meta": {},
395395
"backgroundThrottling": true,
396-
"previewImage": "/images/preview_countdown.png",
396+
"previewImage": "/images/preview_labor_progress.png",
397397
"supportDeployMode": 17,
398-
"configPagePath": "/widget/config/countdown",
398+
"configPagePath": "/widget/config/labor_progress",
399399
"routes": []
400400
},
401401
{

src/components/DatePickerDialog.vue

+20-21
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,47 @@
11
<script lang="ts" setup>
22
import {
3-
nextTick,
4-
onMounted,
53
ref,
64
} from 'vue'
75
import 'vue-scroll-picker/lib/style.css'
8-
import { useVModels } from '@vueuse/core'
6+
import { useVModel } from '@vueuse/core'
97
import SolarDatePicker from '@/components/SolarDatePicker.vue'
108
import LunarDatePicker from '@/components/LunarDatePicker.vue'
119
1210
const props = defineProps({
13-
visible: {
11+
modelValue: {
1412
type: Boolean,
1513
default: false,
1614
},
17-
modelValue: {
15+
date: {
1816
type: Date,
19-
required: true,
17+
default: new Date(),
2018
},
2119
lunar: {
2220
type: Boolean,
2321
default: false,
2422
},
2523
})
26-
const emits = defineEmits(['update:visible', 'update:modelValue', 'update:lunar'])
24+
const emits = defineEmits(['update:visible', 'update:modelValue', 'update:lunar', 'confirm'])
2725
const opened = ref(false)
28-
const {
29-
visible,
30-
modelValue,
31-
lunar,
32-
} = useVModels(props, emits)
33-
onMounted(async () => {
34-
await nextTick()
35-
})
26+
const model = useVModel(props, 'modelValue', emits)
27+
28+
const isLunar = ref(props.lunar)
29+
const dateModel = ref(props.date)
30+
31+
function onConfirmClick() {
32+
model.value = false
33+
emits('confirm', dateModel.value, isLunar.value)
34+
}
3635
</script>
3736

3837
<template>
3938
<div class="picker-group">
4039
<el-dialog
41-
v-model="visible" :modal="false" :show-close="false" @opened="opened = true"
40+
v-model="model" :modal="false" :show-close="false" @opened="opened = true"
4241
@closed="opened = false"
4342
>
4443
<div class="header">
45-
<el-radio-group v-model="lunar" label="label position">
44+
<el-radio-group v-model="isLunar" label="label position">
4645
<el-radio-button :label="false">
4746
公历
4847
</el-radio-button>
@@ -53,15 +52,15 @@ onMounted(async () => {
5352
</div>
5453
<template #footer>
5554
<span class="dialog-footer">
56-
<el-button @click="visible = false">取消</el-button>
57-
<el-button type="primary" @click="visible = false">
55+
<el-button @click="model = false">取消</el-button>
56+
<el-button type="primary" @click="onConfirmClick">
5857
确定
5958
</el-button>
6059
</span>
6160
</template>
6261
<template v-if="opened">
63-
<LunarDatePicker v-if="lunar" v-model="modelValue" />
64-
<SolarDatePicker v-else v-model="modelValue" />
62+
<LunarDatePicker v-if="isLunar" v-model="dateModel" />
63+
<SolarDatePicker v-else v-model="dateModel" />
6564
</template>
6665
</el-dialog>
6766
</div>

src/components/SolarDatePicker.vue

+1-6
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
} from 'vue'
99
import { VueScrollPicker } from 'vue-scroll-picker'
1010
import 'vue-scroll-picker/lib/style.css'
11-
import dayjs from 'dayjs'
1211
1312
const props = defineProps({
1413
height: {
@@ -42,11 +41,7 @@ const solarDates = computed(() => {
4241
})
4342
4443
function emitDateUpdate() {
45-
emits('update:modelValue', dayjs({
46-
year: selectedYear.value,
47-
month: selectedMonth.value - 1,
48-
date: selectedDate.value,
49-
}).toDate())
44+
emits('update:modelValue', new Date(selectedYear.value, selectedMonth.value - 1, selectedDate.value))
5045
}
5146
5247
watch(selectedYear, () => {

src/widgets/countdown/Countdown.widget.ts

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import {
33
WidgetKeyword,
44
} from '@widget-js/core'
55

6-
// TODO 修改组件信息,标题,描述,关键词
76
const name = 'cn.widgetjs.widgets.countdown'
87
// 组件标题
98
const title = { 'zh-CN': '倒计时' }

src/widgets/countdown/CountdownConfigView.vue

+8-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { Lunar } from 'lunar-typescript'
1010
import {
1111
BrowserWindowApi,
1212
WidgetDataApi,
13+
WidgetParams,
1314
} from '@widget-js/core'
1415
import { CountdownModel } from '@/widgets/countdown/model/CountdownModel'
1516
import DatePickerDialog from '@/components/DatePickerDialog.vue'
@@ -23,16 +24,16 @@ export default {
2324
WidgetEditDialog,
2425
},
2526
setup() {
26-
BrowserWindowApi.setSize(600, 400)
27+
BrowserWindowApi.setSize(600, 500)
2728
BrowserWindowApi.center()
2829
const showDatePicker = ref(false)
2930
const date = ref(CountdownModel.DEFAULT_DATE)
3031
const isLunar = ref(false)
32+
const widgetParams = WidgetParams.fromCurrentLocation()
3133
const defaultData = new CountdownModel(CountdownWidgetDefine.name)
3234
defaultData.theme.backgroundColor = '#FFC455'
3335
const {
3436
widgetData,
35-
widgetParams,
3637
} = useWidget(CountdownModel, {
3738
defaultData,
3839
onDataLoaded: (data) => {
@@ -84,6 +85,10 @@ export default {
8485
this.widgetData.dateType = this.isLunar ? DateType.LUNAR : DateType.SOLAR
8586
await WidgetDataApi.save(this.widgetData)
8687
},
88+
onDateConfirm(date: Date, isLunar: boolean) {
89+
this.date = date
90+
this.isLunar = isLunar
91+
},
8792
async onSaveClick() {
8893
await this.onApplyClick()
8994
window.close()
@@ -105,7 +110,7 @@ export default {
105110
<el-input v-model="widgetData.title" />
106111
</el-form-item>
107112
<el-form-item label="事项日期">
108-
<DatePickerDialog v-model:visible="showDatePicker" v-model="date" v-model:is-lunar="isLunar" />
113+
<DatePickerDialog v-model="showDatePicker" :date="date" :is-lunar="isLunar" @confirm="onDateConfirm" />
109114
<el-button @click="showDatePicker = !showDatePicker">
110115
{{ dateStr }}
111116
</el-button>

src/widgets/countdown2/Countdown2.widget.ts

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import {
33
WidgetKeyword,
44
} from '@widget-js/core'
55

6-
// TODO 修改组件信息,标题,描述,关键词
76
const name = 'cn.widgetjs.widgets.countdown2'
87
// 组件标题
98
const title = { 'zh-CN': '倒计时' }

0 commit comments

Comments
 (0)