Browse Source

perf: 更新代码

refact
song 4 years ago
parent
commit
0dd443b3c1
  1. 7
      CHANGELOG.md
  2. 171
      components/Calendar/Calendar.vue
  3. 8
      pages/index/index.vue

7
CHANGELOG.md

@ -7,10 +7,17 @@
- | first commit | [8dc26de](https://101.201.226.163:50022/TALL/TALL-MUI-4/commits/8dc26de)
- | vue3 | [12ed2ad](https://101.201.226.163:50022/TALL/TALL-MUI-4/commits/12ed2ad)
- | 使用uview完成api请求 | [1b3efd8](https://101.201.226.163:50022/TALL/TALL-MUI-4/commits/1b3efd8)
- | 日历页添加 | [1b46a91](https://101.201.226.163:50022/TALL/TALL-MUI-4/commits/1b46a91)
- | 日历页首页 | [561c8e6](https://101.201.226.163:50022/TALL/TALL-MUI-4/commits/561c8e6)
- | 更新代码 | [392c8cc](https://101.201.226.163:50022/TALL/TALL-MUI-4/commits/392c8cc)
### chore
范围|描述|commitId
--|--|--
- | editorconfig update | [0c08089](https://101.201.226.163:50022/TALL/TALL-MUI-4/commits/0c08089)
范围|描述|commitId
--|--|--
- | Initial commit | [52b8f49](https://101.201.226.163:50022/TALL/TALL-MUI-4/commits/52b8f49)

171
components/Calendar/Calendar.vue

@ -16,7 +16,7 @@
:indicator-dots="false"
:autoplay="false"
:duration="duration"
:current="current"
:current="data.current"
@change="changeSwp"
:circular="true"
>
@ -25,7 +25,7 @@
<!-- 当前的 -->
<template v-if="sitem === data.current">
<view class="calendar-day" v-for="(item, index) in data.days" :key="index" :class="{ 'day-hidden': !item.show }" @click="clickItem(item)">
<view class="date1 is-today" :class="[item.isToday ? 'is-today' : '', item.fullDate === data.selectedDate ? checkedClass : '']">{{ item.time.getDate() }}</view>
<view class="date" :class="[item.isToday ? 'is-today' : '', item.fullDate === data.selectedDate ? checkedClass : '']">{{ item.time.getDate() }}</view>
<view class="dot-show" v-if="item.info === '0'" :style="dotStyle"></view>
</view>
</template>
@ -40,7 +40,7 @@
'day-hidden': !item.show,
}"
>
<view class="date2" :class="[item.isToday ? 'is-today' : '']">{{ item.time.getDate() }}</view>
<view class="date" :class="[item.isToday ? 'is-today' : '']">{{ item.time.getDate() }}</view>
</view>
</template>
<!-- 上一个月/ -->
@ -71,7 +71,7 @@
</template>
<script setup>
import { reactive, computed, watchEffect, defineProps, defineEmits } from 'vue';
import { reactive, computed, watchEffect } from 'vue';
import { useStore } from 'vuex';
import dayjs from 'dayjs';
import { gegerateDates, formatDate } from './generateDates.js';
@ -91,7 +91,7 @@ defineProps({
},
});
const emit = defineEmits(['handleFindPoint', 'handleFindPoint', 'days-change']);
const emit = defineEmits(['handleFindPoint', 'handleFindPoint', 'days-change', 'selected-change']);
const data = reactive({
weeks: ['日', '一', '二', '三', '四', '五', '六'], //
@ -179,78 +179,8 @@ watchEffect(() => {
});
});
data.days = days;
console.log('data.days', data.days);
});
// watch(dotList, newValue => {
// //
// const days = data.days.slice(0);
// console.log('days ', days);
// const index = days.findIndex(day => day.show);
// days.forEach((day, i) => {
// newValue.forEach((item, j) => {
// if (i - index === j) {
// day.info = item;
// }
// });
// });
// data.days = days;
// console.log('data.days ', data.days);
// });
//
const daysPre = () => {
// if (this.weekMode) {
// const d = new Date(this.currentYear, this.currentMonth - 1, this.currentDate);
// d.setDate(d.getDate() - 7);
// this.initDate(d);
// } else {
// const d = new Date(this.currentYear, this.currentMonth - 2, 1);
// this.initDate(d);
// }
};
//
const daysNext = () => {
// if (this.weekMode) {
// const d = new Date(this.currentYear, this.currentMonth - 1, this.currentDate);
// d.setDate(d.getDate() + 7);
// this.initDate(d);
// } else {
// const d = new Date(this.currentYear, this.currentMonth, 1);
// this.initDate(d);
// }
};
/**
* 滑动切换上下周期
* 根据前一个减去目前的值我们可以判断是下一个月/周还是上一个月/
* current - pre === 1, -2 下一个月/
* current - pre === -1, 2 上一个月或者上一周
*/
const changeSwp = e => {
const pre = data.current;
const { current } = e.target;
data.current = current;
if (current - pre === 1 || current - pre === -2) {
//
daysNext();
const arr = data.days.filter(s => s.show);
const end = `${arr[arr.length - 1].fullDate} 23:59:59`;
data.start = dayjs(arr[0].fullDate).valueOf();
data.end = dayjs(end).valueOf();
emit('handleFindPoint', this.start, this.end);
} else {
//
daysPre();
const arr = data.days.filter(s => s.show);
const end = `${arr[arr.length - 1].fullDate} 23:59:59`;
data.start = dayjs(arr[0].fullDate).valueOf();
data.end = dayjs(end).valueOf();
emit('handleFindPoint', this.start, this.end);
}
};
//
const initDate = cur => {
let date = '';
@ -312,33 +242,86 @@ const initDate = cur => {
initDate();
//
const changeMode = () => {
// const premode = this.weekMode;
// let isweek = false;
// if (premode) {
// isweek = !!this.days.find((item) => item.fullDate === this.selectedDate);
// }
// this.weekMode = !this.weekMode;
// let d = new Date(this.currentYear, this.currentMonth - 1, this.currentDate);
// const sel = new Date(this.selectedDate.replace('-', '/').replace('-', '/'));
// const isMonth = sel.getFullYear() === this.currentYear && sel.getMonth() + 1 === this.currentMonth;
// if ((this.selectedDate && isMonth) || isweek) {
// d = new Date(this.selectedDate.replace('-', '/').replace('-', '/'));
// }
// this.initDate(d);
//
const daysPre = () => {
if (data.weekMode) {
const d = new Date(data.currentYear, data.currentMonth - 1, data.currentDate);
d.setDate(d.getDate() - 7);
initDate(d);
} else {
const d = new Date(data.currentYear, data.currentMonth - 2, 1);
initDate(d);
}
};
//
const daysNext = () => {
if (data.weekMode) {
const d = new Date(data.currentYear, data.currentMonth - 1, data.currentDate);
d.setDate(d.getDate() + 7);
initDate(d);
} else {
const d = new Date(data.currentYear, data.currentMonth, 1);
initDate(d);
}
};
/**
* 滑动切换上下周期
* 根据前一个减去目前的值我们可以判断是下一个月/周还是上一个月/
* current - pre === 1, -2 下一个月/
* current - pre === -1, 2 上一个月或者上一周
*/
const changeSwp = e => {
const pre = data.current;
const { current } = e.target;
data.current = current;
if (current - pre === 1 || current - pre === -2) {
//
daysNext();
const arr = data.days.filter(s => s.show);
const end = `${arr[arr.length - 1].fullDate} 23:59:59`;
data.start = dayjs(arr[0].fullDate).valueOf();
data.end = dayjs(end).valueOf();
emit('handleFindPoint', data.start, data.end);
} else {
//
daysPre();
const arr = data.days.filter(s => s.show);
const end = `${arr[arr.length - 1].fullDate} 23:59:59`;
data.start = dayjs(arr[0].fullDate).valueOf();
data.end = dayjs(end).valueOf();
emit('handleFindPoint', data.start, data.end);
}
};
//
// const changeMode = () => {
// const premode = this.weekMode;
// let isweek = false;
// if (premode) {
// isweek = !!this.days.find((item) => item.fullDate === this.selectedDate);
// }
// this.weekMode = !this.weekMode;
// let d = new Date(this.currentYear, this.currentMonth - 1, this.currentDate);
// const sel = new Date(this.selectedDate.replace('-', '/').replace('-', '/'));
// const isMonth = sel.getFullYear() === this.currentYear && sel.getMonth() + 1 === this.currentMonth;
// if ((this.selectedDate && isMonth) || isweek) {
// d = new Date(this.selectedDate.replace('-', '/').replace('-', '/'));
// }
// this.initDate(d);
// };
//
const clickItem = e => {
// this.selectedDate = e.fullDate;
// this.$emit('selected-change', e);
data.selectedDate = e.fullDate;
emit('selected-change', e);
};
//
const goToday = () => {
// const d = new Date();
// this.initDate(d);
const d = new Date();
initDate(d);
};
</script>

8
pages/index/index.vue

@ -63,6 +63,14 @@ watch(
{ immediate: true },
);
//
const onDateChange = event => {
// const day = dayjs(event.fullDate);
// const start = day.startOf('date').valueOf();
// const end = day.endOf('date').valueOf();
// this.getProjects(start, end);
};
</script>
<style>

Loading…
Cancel
Save