123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610 |
- <template>
- <view class="uni-calendar">
- <view v-if="!insert && show" class="uni-calendar__mask" :class="{ 'uni-calendar--mask-show': aniMaskShow }" @click="clean"></view>
- <view v-if="insert || show" class="uni-calendar__content" :class="{ 'uni-calendar--fixed': !insert, 'uni-calendar--ani-show': aniMaskShow }" @touchstart="touchStart" @touchend="touchEnd">
- <view v-if="!insert" class="uni-calendar__header uni-calendar--fixed-top">
- <view class="uni-calendar__header-btn-box" @click="close">
- <text class="uni-calendar__header-text uni-calendar--fixed-width">{{ cancelText }}</text>
- </view>
- <view class="uni-calendar__header-btn-box" @click="confirm">
- <text class="uni-calendar__header-text uni-calendar--fixed-width">{{ okText }}</text>
- </view>
- </view>
- <view class="uni-calendar__header">
- <!-- <view class="uni-calendar__header-btn-box" @click.stop="pre">
- <view class="uni-calendar__header-btn uni-calendar--left"></view>
- </view> -->
- <picker mode="date" :value="date" fields="month" @change="bindDateChange">
- <text class="uni-calendar__header-text">{{ (nowDate.year || "") + " 年 " + (nowDate.month || "") + " 月" }}</text>
- </picker>
- <!-- <view class="uni-calendar__header-btn-box" @click.stop="next">
- <view class="uni-calendar__header-btn uni-calendar--right"></view>
- </view> -->
- <!-- <text class="uni-calendar__backtoday" @click="backtoday">{{todayText}}</text> -->
- <view style="margin: auto"></view>
- <view style="display: flex">
- <view style="margin: 0px 10px">
- <span style="margin-right: 5px">巡检</span>
- <span style="color: #00cdac">{{ JSON.stringify(currentDateList) === "{}" ? 0 : currentDateList.patrolledCount }}</span>
- </view>
- <view class="margin-left-xs">
- <span style="margin-right: 5px">漏检</span>
- <span style="color: #f07d28">{{ JSON.stringify(currentDateList) === "{}" ? 0 : currentDateList.undetectedCount }}</span>
- </view>
- </view>
- </view>
- <view class="uni-calendar__box">
- <view v-if="showMonth" class="uni-calendar__box-bg">
- <text class="uni-calendar__box-bg-text">{{ nowDate.month }}</text>
- </view>
- <view class="uni-calendar__weeks">
- <view class="uni-calendar__weeks-day">
- <text class="uni-calendar__weeks-day-text">{{ SUNText }}</text>
- </view>
- <view class="uni-calendar__weeks-day">
- <text class="uni-calendar__weeks-day-text">{{ monText }}</text>
- </view>
- <view class="uni-calendar__weeks-day">
- <text class="uni-calendar__weeks-day-text">{{ TUEText }}</text>
- </view>
- <view class="uni-calendar__weeks-day">
- <text class="uni-calendar__weeks-day-text">{{ WEDText }}</text>
- </view>
- <view class="uni-calendar__weeks-day">
- <text class="uni-calendar__weeks-day-text">{{ THUText }}</text>
- </view>
- <view class="uni-calendar__weeks-day">
- <text class="uni-calendar__weeks-day-text">{{ FRIText }}</text>
- </view>
- <view class="uni-calendar__weeks-day">
- <text class="uni-calendar__weeks-day-text">{{ SATText }}</text>
- </view>
- </view>
- <view class="uni-calendar__weeks" v-for="(item, weekIndex) in weeks" :key="weekIndex">
- <view class="uni-calendar__weeks-item" v-for="(weeks, weeksIndex) in item" :key="weeksIndex">
- <calendar-item class="uni-calendar-item--hook" :weeks="weeks" :calendar="calendar" :selected="selected" :lunar="lunar" @change="choiceDate"></calendar-item>
- </view>
- </view>
- </view>
- </view>
- </view>
- </template>
- <script>
- import Calendar from "./util.js";
- import calendarItem from "./uni-calendar-item.vue";
- import { initVueI18n } from "@dcloudio/uni-i18n";
- import messages from "./i18n/index.js";
- const { t } = initVueI18n(messages);
- let touchStartX = 0;
- let touchStartY = 0;
- export default {
- components: {
- calendarItem,
- },
- emits: ["close", "confirm", "change", "monthSwitch"],
- props: {
- date: {
- type: String,
- default: "",
- },
- selected: {
- type: Array,
- default() {
- return [];
- },
- },
- lunar: {
- type: Boolean,
- default: false,
- },
- startDate: {
- type: String,
- default: "",
- },
- endDate: {
- type: String,
- default: "",
- },
- range: {
- type: Boolean,
- default: false,
- },
- insert: {
- type: Boolean,
- default: true,
- },
- showMonth: {
- type: Boolean,
- default: true,
- },
- clearDate: {
- type: Boolean,
- default: true,
- },
- currentDate: {
- type: Object,
- default: {},
- },
- },
- data() {
- return {
- show: false,
- weeks: [],
- calendar: {},
- nowDate: "",
- aniMaskShow: false,
- currentDateList: {},
- };
- },
- computed: {
-
- okText() {
- return t("uni-calender.ok");
- },
- cancelText() {
- return t("uni-calender.cancel");
- },
- todayText() {
- return t("uni-calender.today");
- },
- monText() {
- return t("uni-calender.MON");
- },
- TUEText() {
- return t("uni-calender.TUE");
- },
- WEDText() {
- return t("uni-calender.WED");
- },
- THUText() {
- return t("uni-calender.THU");
- },
- FRIText() {
- return t("uni-calender.FRI");
- },
- SATText() {
- return t("uni-calender.SAT");
- },
- SUNText() {
- return t("uni-calender.SUN");
- },
- },
- watch: {
- date(newVal) {
-
- this.init(newVal);
- },
- startDate(val) {
- this.cale.resetSatrtDate(val);
- this.cale.setDate(this.nowDate.fullDate);
- this.weeks = this.cale.weeks;
- },
- endDate(val) {
- this.cale.resetEndDate(val);
- this.cale.setDate(this.nowDate.fullDate);
- this.weeks = this.cale.weeks;
- },
- selected(newVal) {
- this.cale.setSelectInfo(this.nowDate.fullDate, newVal);
- this.weeks = this.cale.weeks;
- },
- currentDate(obj) {
- this.currentDateList = obj;
- },
- },
- created() {
-
- this.cale = new Calendar({
-
- selected: this.selected,
- startDate: this.startDate,
- endDate: this.endDate,
- range: this.range,
- });
-
-
- this.init(this.date);
-
- },
- methods: {
-
- clean() {},
- bindDateChange(e) {
- const value = e.detail.value + "-1";
- console.log(this.cale.getDate(value));
- this.setDate(value);
- },
-
- init(date) {
- this.cale.setDate(date);
- this.weeks = this.cale.weeks;
- this.nowDate = this.calendar = this.cale.getInfo(date);
- },
-
- open() {
-
- if (this.clearDate && !this.insert) {
- this.cale.cleanMultipleStatus();
-
- this.init(this.date);
- }
- this.show = true;
- this.$nextTick(() => {
- setTimeout(() => {
- this.aniMaskShow = true;
- }, 50);
- });
- },
-
- close() {
- this.aniMaskShow = false;
- this.$nextTick(() => {
- setTimeout(() => {
- this.show = false;
- this.$emit("close");
- }, 300);
- });
- },
-
- confirm() {
- this.setEmit("confirm");
- this.close();
- },
-
- change() {
- if (!this.insert) return;
- this.setEmit("change");
- },
-
- monthSwitch() {
- let { year, month } = this.nowDate;
- this.$emit("monthSwitch", {
- year,
- month: Number(month),
- });
- },
-
- setEmit(name) {
- let { year, month, date, fullDate, lunar, extraInfo } = this.calendar;
- this.$emit(name, {
- range: this.cale.multipleStatus,
- year,
- month,
- date,
- fulldate: fullDate,
- lunar,
- extraInfo: extraInfo || {},
- });
- },
-
- choiceDate(weeks) {
- if (weeks.disable) return;
- this.calendar = weeks;
-
- this.cale.setMultiple(this.calendar.fullDate);
- this.weeks = this.cale.weeks;
- this.change();
- },
-
- backtoday() {
- console.log(this.cale.getDate(new Date()).fullDate);
- let date = this.cale.getDate(new Date()).fullDate;
-
- this.init(date);
- this.change();
- },
-
- pre() {
- const preDate = this.cale.getDate(this.nowDate.fullDate, -1, "month").fullDate;
- this.setDate(preDate);
- this.monthSwitch();
- },
-
- next() {
- const nextDate = this.cale.getDate(this.nowDate.fullDate, +1, "month").fullDate;
- this.setDate(nextDate);
- this.monthSwitch();
- },
-
- setDate(date) {
- this.cale.setDate(date);
- this.weeks = this.cale.weeks;
- this.nowDate = this.cale.getInfo(date);
- },
-
- touchStart(e) {
- console.log("触摸开始");
- touchStartX = e.touches[0].clientX;
- touchStartY = e.touches[0].clientY;
- },
-
- touchEnd(e) {
- console.log("触摸结束");
- let deltaX = e.changedTouches[0].clientX - touchStartX;
- let deltaY = e.changedTouches[0].clientY - touchStartY;
- if (Math.abs(deltaX) > 50 && Math.abs(deltaX) > Math.abs(deltaY)) {
- if (deltaX >= 0) {
- console.log("左滑");
- this.pre();
-
- } else {
- console.log("右滑");
- this.next();
-
- }
- } else if (Math.abs(deltaY) > 50 && Math.abs(deltaX) < Math.abs(deltaY)) {
- if (deltaY < 0) {
- console.log("上滑");
- } else {
- console.log("下滑");
- }
- } else {
- console.log("可能是误触!");
- }
- },
- },
- };
- </script>
- <style lang="scss" scoped>
- $uni-bg-color-mask: rgba(
- $color: #000000,
- $alpha: 0.4,
- );
- $uni-border-color: #ededed;
- $uni-text-color: #333;
- $uni-bg-color-hover: #f1f1f1;
- $uni-font-size-base: 14px;
- $uni-text-color-placeholder: #808080;
- $uni-color-subtitle: #555555;
- $uni-text-color-grey: #999;
- .uni-calendar {
-
- display: flex;
-
- flex-direction: column;
- }
- .uni-calendar__mask {
- position: fixed;
- bottom: 0;
- top: 0;
- left: 0;
- right: 0;
- background-color: $uni-bg-color-mask;
- transition-property: opacity;
- transition-duration: 0.3s;
- opacity: 0;
-
- z-index: 99;
-
- }
- .uni-calendar--mask-show {
- opacity: 1;
- }
- .uni-calendar--fixed {
- position: fixed;
-
- bottom: 0;
-
- left: 0;
- right: 0;
- transition-property: transform;
- transition-duration: 0.3s;
- transform: translateY(460px);
-
- bottom: calc(var(--window-bottom));
- z-index: 99;
-
- }
- .uni-calendar--ani-show {
- transform: translateY(0);
- }
- .uni-calendar__content {
- background-color: #fff;
- }
- .uni-calendar__header {
- position: relative;
-
- display: flex;
-
- flex-direction: row;
-
- align-items: center;
- height: 50px;
- padding: 0 15px;
- border-bottom-color: $uni-border-color;
- border-bottom-style: solid;
- border-bottom-width: 1px;
- }
- .uni-calendar--fixed-top {
-
- display: flex;
-
- flex-direction: row;
- justify-content: space-between;
- border-top-color: $uni-border-color;
- border-top-style: solid;
- border-top-width: 1px;
- }
- .uni-calendar--fixed-width {
- width: 50px;
-
- }
- .uni-calendar__backtoday {
- position: absolute;
- right: 0;
- top: 25rpx;
- padding: 0 5px;
- padding-left: 10px;
- height: 25px;
- line-height: 25px;
- font-size: 12px;
- border-top-left-radius: 25px;
- border-bottom-left-radius: 25px;
- color: $uni-text-color;
- background-color: $uni-bg-color-hover;
- }
- .uni-calendar__header-text {
- text-align: center;
- width: 100px;
- font-size: $uni-font-size-base;
- color: $uni-text-color;
- }
- .uni-calendar__header-btn-box {
-
- display: flex;
-
- flex-direction: row;
- align-items: center;
- justify-content: center;
- width: 50px;
- height: 50px;
- }
- .uni-calendar__header-btn {
- width: 10px;
- height: 10px;
- border-left-color: $uni-text-color-placeholder;
- border-left-style: solid;
- border-left-width: 2px;
- border-top-color: $uni-color-subtitle;
- border-top-style: solid;
- border-top-width: 2px;
- }
- .uni-calendar--left {
- transform: rotate(-45deg);
- }
- .uni-calendar--right {
- transform: rotate(135deg);
- }
- .uni-calendar__weeks {
- position: relative;
-
- display: flex;
-
- flex-direction: row;
- }
- .uni-calendar__weeks-item {
- flex: 1;
- }
- .uni-calendar__weeks-day {
- flex: 1;
-
- display: flex;
-
- flex-direction: column;
- justify-content: center;
- align-items: center;
- height: 45px;
- border-bottom-color: #f5f5f5;
- border-bottom-style: solid;
- border-bottom-width: 1px;
- }
- .uni-calendar__weeks-day-text {
- font-size: 14px;
- }
- .uni-calendar__box {
- position: relative;
- }
- .uni-calendar__box-bg {
-
- display: flex;
-
- justify-content: center;
- align-items: center;
- position: absolute;
- top: 0;
- left: 0;
- right: 0;
- bottom: 0;
- }
- .uni-calendar__box-bg-text {
- font-size: 200px;
- font-weight: bold;
- color: $uni-text-color-grey;
- opacity: 0.1;
- text-align: center;
-
- line-height: 1;
-
- }
- </style>
|