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

#51 fix

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