提交 2fa9f773 编写于 作者: B baiy 提交者: ninecents

#51 fix

上级 bdb1ca11
......@@ -20,7 +20,7 @@
<FormItem>
<Input v-model="poor">
<Select transfer v-model="current.poor.unit" slot="append" style="width: 60px">
<Option v-for="v in poorUnit" :value="v.v" :key="v.v">{{v.n}}</Option>
<Option v-for="v in poorUnit" :value="v.v" :key="v.v">{{ v.n }}</Option>
</Select>
</Input>
</FormItem>
......@@ -44,12 +44,12 @@
<FormItem>
<Input v-model="current.duration.length" type="number" number>
<Select transfer v-model="current.duration.unit" slot="append" style="width: 60px">
<Option v-for="v in poorUnit" :value="v.v" :key="v.v">{{v.n}}</Option>
<Option v-for="v in poorUnit" :value="v.v" :key="v.v">{{ v.n }}</Option>
</Select>
</Input>
</FormItem>
<FormItem>
后, 为 <strong>{{duration}}</strong>
后, 为 <strong>{{ duration }}</strong>
</FormItem>
</option-block>
</TabPane>
......@@ -57,64 +57,89 @@
</div>
</template>
<script>
import moment from 'moment'
import moment from 'moment'
export default {
created () {
export default {
created() {
this.current = Object.assign(this.current, this.$getToolData())
},
computed: {
poor () {
poor() {
let a = moment(this.current.poor.input1)
let b = moment(this.current.poor.input2)
this.$saveToolData(this.current)
return b.diff(a, this.current.poor.unit)
},
duration () {
this.$saveToolData(this.current)
duration() {
if (!this.current.duration.length){
return "";
}
let rate = this.getRate(this.current.duration.unit)
let result;
if (rate === 0) {
if (!Number.isInteger(this.current.duration.length)){
return "年/月间隔只能是整数";
}
const type = this.current.duration.type === '+' ? 'add' : 'subtract'
return moment(this.current.duration.input)[type](this.current.duration.length, this.current.duration.unit).
format('YYYY-MM-DD HH:mm:ss')
result = moment(this.current.duration.input)[type](this.current.duration.length, this.current.duration.unit)
} else {
result = moment(
moment(this.current.duration.input).unix() * 1000
+ (rate * this.current.duration.length) * (this.current.duration.type === '+' ? 1 : -1)
)
}
this.$saveToolData(this.current)
return result.format('YYYY-MM-DD HH:mm:ss');
},
},
data () {
methods: {
getRate(unit) {
for (let item of this.poorUnit) {
if (item.v === unit) {
return parseInt(item.rate)
}
}
return 0;
}
},
data() {
return {
options: {
shortcuts: [
{
text: '当前时间',
value () {
value() {
return moment().toDate()
},
},
{
text: '当前日期',
value () {
value() {
return moment(moment().format('YYYY-MM-DD')).toDate()
},
},
{
text: '当月日期',
value () {
value() {
return moment(moment().format('YYYY-MM-01')).toDate()
},
},
{
text: '当年日期',
value () {
value() {
return moment(moment().format('YYYY-01-01')).toDate()
},
},
],
},
poorUnit: [
{ v: 'years', n: '' },
{ v: 'months', n: '' },
{ v: 'weeks', n: '' },
{ v: 'days', n: '' },
{ v: 'hours', n: '小时' },
{ v: 'minutes', n: '分钟' },
{ v: 'seconds', n: '' },
{v: 'years', n: '', rate: 0},
{v: 'months', n: '', rate: 0},
{v: 'weeks', n: '', rate: 1000 * 60 * 60 * 24 * 7},
{v: 'days', n: '', rate: 1000 * 60 * 60 * 24},
{v: 'hours', n: '小时', rate: 1000 * 60 * 60},
{v: 'minutes', n: '分钟', rate: 1000 * 60},
{v: 'seconds', n: '', rate: 1000},
],
current: {
poor: {
......@@ -131,5 +156,5 @@
},
}
},
}
}
</script>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册