Skip to content

Commit 8037b76

Browse files
author
Kenneth Cheng
committed
remove moment dependency
1 parent 9c84f5f commit 8037b76

File tree

5 files changed

+42
-184
lines changed

5 files changed

+42
-184
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ In your template
5151
```html
5252
<template>
5353
<vue-excel-editor v-model="jsondata">
54-
<vue-excel-column field="user" label="User" />
55-
<vue-excel-column field="name" label="Name" />
56-
<vue-excel-column field="phone" label="Contact" />
57-
<vue-excel-column field="gender" label="Gender" />
58-
<vue-excel-column field="age" label="Age" />
59-
<vue-excel-column field="birth" label="Date Of Birth" />
54+
<vue-excel-column field="user" label="User ID" type="string" width="80px" />
55+
<vue-excel-column field="name" label="Name" type="string" width="150px" />
56+
<vue-excel-column field="phone" label="Contact" type="string" width="130px" />
57+
<vue-excel-column field="gender" label="Gender" type="select" width="50px" :options="['F','M','U']" />
58+
<vue-excel-column field="age" label="Age" type="number" width="70px" />
59+
<vue-excel-column field="birth" label="Date Of Birth" type="date" width="80px" />
6060
</vue-excel-editor>
6161
</template>
6262

package-lock.json

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

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22
"name": "vue3-excel-editor",
33
"email": "apple.6502@gmail.com",
44
"description": "Vue3 plugin for displaying and editing the array-of-object in Excel style",
5-
"version": "1.0.6",
5+
"version": "1.0.7",
66
"main": "src/main.js",
77
"dependencies": {
88
"@vuepic/vue-datepicker": "^3.3.0",
9-
"moment": "^2.29.1",
109
"vuedraggable": "^4.1.0",
1110
"xlsx": "^0.18.5"
1211
},

src/VueExcelColumn.vue

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
</template>
44

55
<script>
6-
import moment from 'moment'
7-
86
export default {
97
props: {
108
field: {type: String, default: ''},
@@ -44,11 +42,14 @@ export default {
4442
}
4543
switch (this.type) {
4644
case 'datetick':
47-
return moment(text, 'YYYY-MM-DD').valueOf()
45+
// return moment(text, 'YYYY-MM-DD').valueOf()
46+
return new Date(text + ' GMT+0').getTime()
4847
case 'datetimetick':
49-
return moment(text, 'YYYY-MM-DD HH:mm').valueOf()
48+
// return moment(text, 'YYYY-MM-DD HH:mm').valueOf()
49+
return new Date(text + ' GMT+0').getTime()
5050
case 'datetimesectick':
51-
return moment(text, 'YYYY-MM-DD HH:mm:ss').valueOf()
51+
// return moment(text, 'YYYY-MM-DD HH:mm:ss').valueOf()
52+
return new Date(text + ' GMT+0').getTime()
5253
case 'check10':
5354
case 'checkYN':
5455
case 'checkTF':
@@ -70,17 +71,21 @@ export default {
7071
default (val) {
7172
// § magic to hide the temp key
7273
if (this.keyField && val && val.toString().startsWith('§')) return ''
73-
74+
const offset = new Date().getTimezoneOffset() * 60 * 1000
7475
switch (this.type) {
7576
case 'date':
76-
return val? moment(val).format('YYYY-MM-DD'): ''
77+
// return val? moment(val).format('YYYY-MM-DD'): ''
78+
return val? new Date(new Date(val) - offset).toISOString().slice(0, 10) : ''
7779
case 'datetick':
78-
return val? moment(Number(val)).format('YYYY-MM-DD'): ''
80+
// return val? moment(Number(val)).format('YYYY-MM-DD'): ''
81+
return val? new Date(Number(val) - offset).toISOString().slice(10) : ''
7982
case 'datetimetick':
80-
return val? moment(Number(val)).format('YYYY-MM-DD HH:mm'): ''
83+
// return val? moment(Number(val)).format('YYYY-MM-DD HH:mm'): ''
84+
return val? new Date(Number(val) - offset).toISOString().replace('T', ' ').slice(0, 16) : ''
8185
case 'datetimesectick':
82-
if (!val) return ''
83-
return val? moment(Number(val)).format('YYYY-MM-DD HH:mm:ss'): ''
86+
// if (!val) return ''
87+
// return val? moment(Number(val)).format('YYYY-MM-DD HH:mm:ss'): ''
88+
return val? new Date(Number(val) - offset).toISOString().replace('T', ' ').slice(0, 19) : ''
8489
case 'map':
8590
if (this.options.constructor.name.endsWith('Function'))
8691
return this.options(val)[val]
@@ -113,23 +118,26 @@ export default {
113118
allowKeys = allowKeys || ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-']
114119
if (!validate) validate = (val) => {
115120
if (val === '') return ''
116-
if (!moment(val, 'YYYY-MM-DD', true).isValid()) return this.$parent.localizedLabel.invalidInputValue
121+
// if (!moment(val, 'YYYY-MM-DD', true).isValid()) return this.$parent.localizedLabel.invalidInputValue
122+
if (!/^\d{4}-\d{2}-\d{2}$/.test(val)) return this.$parent.localizedLabel.invalidInputValue
117123
return ''
118124
}
119125
break
120126
case 'datetime':
121127
allowKeys = allowKeys || ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-', ' ', ':']
122128
if (!validate) validate = (val) => {
123129
if (val === '') return ''
124-
if (!moment(val, 'YY-MM-DD hh:mm', true).isValid()) return this.$parent.localizedLabel.invalidInputValue
130+
// if (!moment(val, 'YY-MM-DD hh:mm', true).isValid()) return this.$parent.localizedLabel.invalidInputValue
131+
if (!/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}$/.test(val)) return this.$parent.localizedLabel.invalidInputValue
125132
return ''
126133
}
127134
break
128135
case 'datetimesec':
129136
allowKeys = allowKeys || ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-', ' ', ':']
130137
if (!validate) validate = (val) => {
131138
if (val === '') return ''
132-
if (!moment(val, 'YY-MM-DD hh:mm:ss', true).isValid()) return this.$parent.localizedLabel.invalidInputValue
139+
// if (!moment(val, 'YY-MM-DD hh:mm:ss', true).isValid()) return this.$parent.localizedLabel.invalidInputValue
140+
if (!/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/.test(val)) return this.$parent.localizedLabel.invalidInputValue
133141
return ''
134142
}
135143
break

src/VueExcelEditor.vue

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,6 @@ import PanelSetting from './PanelSetting.vue'
281281
import PanelFind from './PanelFind.vue'
282282
import DatePicker from '@vuepic/vue-datepicker'
283283
import {read, writeFile, utils} from 'xlsx'
284-
import moment from 'moment'
285284
286285
import '@vuepic/vue-datepicker/dist/main.css'
287286
@@ -1054,20 +1053,24 @@ export default {
10541053
})
10551054
},
10561055
datepickerClick () {
1057-
const m = moment(this.inputDateTime)
1056+
const offset = new Date().getTimezoneOffset() * 60 * 1000
1057+
// const m = moment(this.inputDateTime)
10581058
switch(this.currentField.type) {
10591059
case 'date':
1060-
this.inputBox.value = m.format('YYYY-MM-DD')
1060+
// this.inputBox.value = m.format('YYYY-MM-DD')
1061+
this.inputBox.value = new Date(new Date(this.inputDateTime) - offset).toISOString().slice(0, 10)
10611062
break
10621063
case 'datetime':
1063-
this.inputBox.value = m.format('YYYY-MM-DD hh:mn:00')
1064+
// this.inputBox.value = m.format('YYYY-MM-DD hh:mn:00')
1065+
this.inputBox.value = new Date(new Date(this.inputDateTime) - offset).toISOString().replace('T', ' ').slice(0, 16) + ':00'
10641066
break
1065-
case 'datetimesec':
1067+
case 'datetimesec':
1068+
this.inputBox.value = new Date(new Date(this.inputDateTime) - offset).toISOString().replace('T', ' ').slice(0, 19)
10661069
this.inputBox.value = m.format('YYYY-MM-DD hh:mn:ss')
10671070
break
1068-
case 'datetick':
1069-
case 'datetimetick':
1070-
case 'datetimesectick':
1071+
case 'datetick':
1072+
case 'datetimetick':
1073+
case 'datetimesectick':
10711074
this.inputBox.value = m.valueOf()
10721075
break
10731076
}

0 commit comments

Comments
 (0)