Browse Source

feat: 添加上传按钮

refact
song 4 years ago
parent
commit
1a47783aa4
  1. 4
      .hbuilderx/launch.json
  2. 6
      CHANGELOG.md
  3. 89
      components/Calendar/Calendar.vue
  4. 2
      components/Calendar/generateDates.js
  5. 51
      components/Upload/Upload.vue
  6. 208
      pages/index/index.vue

4
.hbuilderx/launch.json

@ -2,6 +2,10 @@
// launchtypelocalremote, localremote
"version": "0.0",
"configurations": [{
"app-plus" :
{
"launchtype" : "local"
},
"default" :
{
"launchtype" : "local"

6
CHANGELOG.md

@ -12,6 +12,12 @@
- | 更新代码 | [392c8cc](https://101.201.226.163:50022/TALL/TALL-MUI-4/commits/392c8cc)
### 🚀 性能优化
范围|描述|commitId
--|--|--
- | 更新代码 | [0dd443b](https://101.201.226.163:50022/TALL/TALL-MUI-4/commits/0dd443b)
### chore
范围|描述|commitId
--|--|--

89
components/Calendar/Calendar.vue

@ -1,9 +1,14 @@
<template>
<view class="zzx-calendar">
<view class="calendar-heander">{{ timeStr }}</view>
<view class="calendar-header">{{ timeStr }}</view>
<!-- 星期几标题 -->
<view class="calendar-weeks">
<view class="calendar-week" :class="{ 'text-red-500': week === '六' || week === '日' }" v-for="(week, index) in data.weeks" :key="index">{{ week }}</view>
<view
class="calendar-week"
:class="{ 'text-red-500': week === '六' || week === '日' }"
v-for="(week, index) in data.weeks"
:key="index"
>{{ week }}</view>
</view>
<view class="calendar-content">
@ -11,30 +16,40 @@
class="calendar-swiper"
:style="{
width: '100%',
height: sheight,
height: calenderHeight,
}"
:indicator-dots="false"
:autoplay="false"
:duration="duration"
:duration="500"
:current="data.current"
@change="changeSwp"
:circular="true"
>
<swiper-item class="calendar-item" v-for="sitem in data.swiper" :key="sitem">
<swiper-item class="calendar-item" v-for="sItem in data.swiper" :key="sItem">
<view class="calendar-days">
<!-- 当前的 -->
<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="date" :class="[item.isToday ? 'is-today' : '', item.fullDate === data.selectedDate ? checkedClass : '']">{{ item.time.getDate() }}</view>
<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="date"
:class="[item.isToday ? 'is-today' : '', item.fullDate === data.selectedDate ? 'is-checked' : '']"
>{{ item.time.getDate() }}</view>
<view class="dot-show" v-if="item.info === '0'" :style="dotStyle"></view>
</view>
</template>
<template v-else>
<!-- 下一个月/ -->
<template v-if="data.current - sitem === 1 || data.current - sitem === -2">
<template v-if="data.current - sItem === 1 || data.current - sItem === -2">
<view
class="calendar-day"
v-for="(item, index) in predays"
v-for="(item, index) in preDays"
:key="index"
:class="{
'day-hidden': !item.show,
@ -43,11 +58,12 @@
<view class="date" :class="[item.isToday ? 'is-today' : '']">{{ item.time.getDate() }}</view>
</view>
</template>
<!-- 上一个月/ -->
<template v-else>
<view
class="calendar-day"
v-for="(item, index) in nextdays"
v-for="(item, index) in nextDays"
:key="index"
:class="{
'day-hidden': !item.show,
@ -63,7 +79,7 @@
<!-- <view class="mode-change" @click="changeMode">
<view :class="weekMode ? 'mode-arrow-bottom' : 'mode-arrow-top'"> </view>
</view> -->
</view>-->
</view>
<view class="flex justify-center u-font-18" style="color: #3b82f6" @click="goToday">今日</view>
@ -74,16 +90,9 @@
import { reactive, computed, watchEffect } from 'vue';
import { useStore } from 'vuex';
import dayjs from 'dayjs';
import { gegerateDates, formatDate } from './generateDates.js';
import { generateDates, formatDate } from './generateDates.js';
defineProps({
duration: { type: Number, default: 500 },
//
showBack: { type: Boolean, default: false },
// class
todayClass: { type: String, default: 'is-today' },
// class
checkedClass: { type: String, default: 'is-checked' },
//
dotStyle: {
type: Object,
@ -103,16 +112,12 @@ const data = reactive({
weekMode: false, // false -> true ->
swiper: [0, 1, 2],
selectedDate: formatDate(new Date(), 'yyyy-MM-dd'), //
start: dayjs()
.startOf('month')
.valueOf(),
end: dayjs()
.endOf('month')
.valueOf(),
start: dayjs().startOf('month').valueOf(),
end: dayjs().endOf('month').valueOf(),
});
const store = useStore();
const dotList = computed(() => store.state.project.dotList);
const sheight = computed(() => {
const calenderHeight = computed(() => {
//
//
let h = '35px';
@ -132,40 +137,41 @@ const sheight = computed(() => {
//
const timeStr = computed(() => {
let str = '';
const y = dayjs().year();
const m = dayjs().month() + 1 <= 9 ? `0${dayjs().month() + 1}` : dayjs().month() + 1;
const d = new Date(data.currentYear, data.currentMonth - 1, data.currentDate);
const y = d.getFullYear();
const m = d.getMonth() + 1 <= 9 ? `0${d.getMonth() + 1}` : d.getMonth() + 1;
str = `${y}${m}`;
return str;
});
// days
const predays = computed(() => {
const preDays = computed(() => {
let pres = [];
if (data.weekMode) {
//
const d = new Date(data.currentYear, data.currentMonth - 1, data.currentDate);
d.setDate(d.getDate() - 7);
pres = gegerateDates(d, 'week');
pres = generateDates(d, 'week');
} else {
//
const d = new Date(data.currentYear, data.currentMonth - 2, 1);
pres = gegerateDates(d, 'month');
pres = generateDates(d, 'month');
}
return pres;
});
// days
const nextdays = computed(() => {
let nexts = [];
const nextDays = computed(() => {
let next = [];
if (data.weekMode) {
//
const d = new Date(data.currentYear, data.currentMonth - 1, data.currentDate);
d.setDate(d.getDate() + 7);
nexts = gegerateDates(d, 'week');
next = generateDates(d, 'week');
} else {
//
const d = new Date(data.currentYear, data.currentMonth, 1);
nexts = gegerateDates(d, 'month');
next = generateDates(d, 'month');
}
return nexts;
return next;
});
watchEffect(() => {
@ -201,10 +207,10 @@ const initDate = cur => {
data.days = [];
let days = [];
if (data.weekMode) {
days = gegerateDates(date, 'week');
days = generateDates(date, 'week');
// this.selectedDate = days[0].fullDate;
} else {
days = gegerateDates(date, 'month');
days = generateDates(date, 'month');
// const sel = new Date(this.selectedDate.replace('-', '/').replace('-', '/'));
// const isMonth = sel.getFullYear() === this.currentYear && (sel.getMonth() + 1) === this.currentMonth;
@ -274,7 +280,7 @@ const daysNext = () => {
*/
const changeSwp = e => {
const pre = data.current;
const { current } = e.target;
const { current } = e.detail;
data.current = current;
if (current - pre === 1 || current - pre === -2) {
//
@ -323,7 +329,6 @@ const goToday = () => {
const d = new Date();
initDate(d);
};
</script>
<style lang="scss" scoped>
@ -333,7 +338,7 @@ const goToday = () => {
background-color: #fff;
padding-bottom: 10px;
.calendar-heander {
.calendar-header {
text-align: center;
padding: 16px 0;
position: relative;

2
components/Calendar/generateDates.js

@ -58,7 +58,7 @@ export const dateEqual = (before, after) => {
}
};
export const gegerateDates = (date = new Date(), type = 'week') => {
export const generateDates = (date = new Date(), type = 'week') => {
const result = [];
if (judgeType(date) === 'Date') {
// 年,月,日

51
components/Upload/Upload.vue

@ -4,35 +4,32 @@
</view>
</template>
<script>
import { mapGetters } from 'vuex';
<script setup>
import { computed } from 'vue';
import { useStore } from 'vuex';
export default {
computed: mapGetters('user', ['userId']),
methods: {
// wbs
async handleUpload() {
try {
const data = await this.$u.api.import();
// WBS
//
this.$emit('success');
data.url && (uni.$t.domain = data.url);
setTimeout(() => {
this.$u.route('/pages/project-webview/project-webview', {
u: this.userId,
p: data.id,
pname: data.pname,
url: data.url,
});
}, 2000);
} catch (error) {
console.log('error: ', error);
this.$emit('error', error);
}
},
},
const emit = defineEmits(['success', 'error']);
const store = useStore();
const userId = computed(() => store.getters['user/userId']);
// wbs
const handleUpload = async cur => {
try {
const res = await uni.$u.api.import();
// WBS
//
emit('success');
res.url && (uni.$t.domain = res.url);
setTimeout(() => {
uni.navigateTo({ url: `/pages/project-webview/project-webview?u=${userId.value}&p=${res.id}&pname=${res.pname}&url=${res.url}` });
}, 2000);
} catch (error) {
console.error('error: ', error);
emit('error', error);
}
};
</script>
<style lang="scss" scoped>

208
pages/index/index.vue

@ -1,102 +1,120 @@
<template>
<view class="flex flex-col h-full bg-gray-50" @click="openAuth">
<view class="relative" @touchmove="onMove">
<!-- 日历 -->
<Calendar @selected-change="onDateChange" :show-back="true" ref="calendar" @handleFindPoint="handleFindPoint" />
<!-- 上传 导入wbs -->
<!-- <Upload @success="onUploadSuccess" @error="onUploadError" /> -->
</view>
<!-- 项目列表 -->
<Projects @getProjects="getProjects" class="flex-1 overflow-y-auto" />
<!-- 全局提示框 -->
<u-top-tips ref="uTips"></u-top-tips>
</view>
</template>
<script setup>
import { reactive, ref, onMounted, computed, watch } from 'vue';
import { useStore } from 'vuex';
import dayjs from 'dayjs';
const data = reactive({
calendar: null,
days: [],
});
const height = ref(null);
const store = useStore();
const token = computed(() => store.state.user.token);
onMounted(() => {
const system = uni.getSystemInfoSync();
height.value = `${system.windowHeight}px`;
});
const handleFindPoint = async (start, end) => {
try {
const startTime = start
|| dayjs()
.startOf('month')
.valueOf();
const endTime = end
|| dayjs()
.endOf('month')
.valueOf();
const res = await uni.$u.api.findRedPoint(startTime, endTime);
store.commit('project/setDotList', res);
} catch (error) {
console.log('error: ', error);
}
};
// token
watch(
() => token.value,
newValue => {
if (!newValue) return;
if (newValue) {
handleFindPoint();
}
},
{ immediate: true },
);
<template>
<view class="flex flex-col h-full bg-gray-50" @click="openAuth">
<view class="relative" @touchmove="onMove">
<!-- 日历 -->
<Calendar @selected-change="onDateChange" :show-back="true" ref="calendar" @handleFindPoint="handleFindPoint" />
<!-- 上传 导入wbs -->
<Upload @success="onUploadSuccess" @error="onUploadError" />
</view>
<!-- 项目列表 -->
<Projects @getProjects="getProjects" class="flex-1 overflow-y-auto" />
<!-- 全局提示框 -->
<u-top-tips ref="uTips"></u-top-tips>
</view>
</template>
<script setup>
import { reactive, ref, onMounted, computed, watch } from 'vue';
import { useStore } from 'vuex';
import dayjs from 'dayjs';
const data = reactive({
calendar: null,
days: [],
});
const height = ref(null);
const store = useStore();
const token = computed(() => store.state.user.token);
onMounted(() => {
const system = uni.getSystemInfoSync();
height.value = `${system.windowHeight}px`;
});
const handleFindPoint = async (start, end) => {
try {
const startTime = start
|| dayjs()
.startOf('month')
.valueOf();
const endTime = end
|| dayjs()
.endOf('month')
.valueOf();
const res = await uni.$u.api.findRedPoint(startTime, endTime);
store.commit('project/setDotList', res);
} catch (error) {
console.log('error: ', error);
}
};
// token
watch(
() => token.value,
newValue => {
if (!newValue) return;
if (newValue) {
handleFindPoint();
}
},
{ 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>
.content {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.logo {
height: 200rpx;
width: 200rpx;
margin-top: 200rpx;
margin-left: auto;
margin-right: auto;
margin-bottom: 50rpx;
}
.text-area {
display: flex;
justify-content: center;
}
.title {
font-size: 36rpx;
color: #8f8f94;
}
};
//
const onUploadSuccess = () => {
uni.$refs.uTips.show({
title: '导入成功,即将打开新项目',
type: 'success',
duration: '3000',
});
};
//
const onUploadError = error => {
uni.$refs.uTips.show({
title: error || '导入失败',
type: 'error',
duration: '6000',
});
};
</script>
<style>
.content {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.logo {
height: 200rpx;
width: 200rpx;
margin-top: 200rpx;
margin-left: auto;
margin-right: auto;
margin-bottom: 50rpx;
}
.text-area {
display: flex;
justify-content: center;
}
.title {
font-size: 36rpx;
color: #8f8f94;
}
</style>

Loading…
Cancel
Save