Browse Source

perf: 解决警告

develop
lucky 4 years ago
parent
commit
c932b09765
  1. 1
      CHANGELOG.md
  2. 10
      src/apis/project.js
  3. 9
      src/components/Globals/Globals.vue
  4. 22
      src/components/Project/Project.vue
  5. 37
      src/components/Project/component/TimeBar.vue
  6. 80
      src/components/Project/component/TimeLine.vue
  7. 114
      src/components/Roles/component/RoleList.vue
  8. 11
      src/components/TimeLine/TimeLine.vue
  9. 7
      src/components/TimeLine/component/TimeBox.vue
  10. 23
      src/components/Title/Title.vue
  11. 34
      src/mock/mock.js
  12. 57
      src/pages/project/project.vue
  13. 51
      src/store/home/actions.js
  14. 61
      src/store/home/mutations.js
  15. 22
      src/store/home/state.js
  16. 9
      src/utils/request.js

1
CHANGELOG.md

@ -5,6 +5,7 @@
--|--|--
- | 标题栏变化 | [c0fcd9d](https://dd.tall.wiki/gitea/wally/TALL-MUI-3/commits/c0fcd9d)
- | 标题栏角色栏全局任务组件新建 | [0500cb4](https://dd.tall.wiki/gitea/wally/TALL-MUI-3/commits/0500cb4)
- | 存token | [b8a178d](https://dd.tall.wiki/gitea/wally/TALL-MUI-3/commits/b8a178d)
- | 角色栏实现 | [94cd671](https://dd.tall.wiki/gitea/wally/TALL-MUI-3/commits/94cd671)
- | 模拟接口测试 | [69e7931](https://dd.tall.wiki/gitea/wally/TALL-MUI-3/commits/69e7931)
- | 时间基准线,默认插件 | [a33ba1e](https://dd.tall.wiki/gitea/wally/TALL-MUI-3/commits/a33ba1e)

10
src/apis/project.js

@ -1,9 +1,17 @@
const apiUrl = process.env.VUE_APP_API_URL;
const tall = `${apiUrl}/defaultwbs`;
const project = `${tall}/project`;
const role = `${tall}/role`;
const task = `${tall}/task`;
const install = (Vue, vm) => {
vm.$u.api = { ...vm.$u.api } || {};
vm.$u.api.findProjectById = params => vm.$u.post(`${tall}/project/findProjectById`, params);
//根据id获取项目信息
vm.$u.api.findProjectById = params => vm.$u.post(`${project}/findProjectById`, params);
//查询角色栏展示的角色
vm.$u.api.findShowRoles = params => vm.$u.post(`${role}/show`, params);
//根据时间基准点和角色查找定期任务
vm.$u.api.getRegularTask = params => vm.$u.post(`${task}/regular`, params);
};
export default { install };

9
src/components/Globals/Globals.vue

@ -1,7 +1,6 @@
<template>
<view class="m-2">
<u-card :show-foot="false" :show-head="false" :style="{ height: isShrink ? '96rpx' : '300rpx' }" border-radius="25" margin="0">
<!-- <u-card margin="0" :show-head="false" :show-foot="false" border-radius="25" style="height: 300rpx"> -->
<view slot="body">
<scroll-view :scrollY="true" :style="{ height: isShrink ? '40rpx' : '240rpx' }">
<skeleton :banner="false" :loading="loading" :row="4" animate class="u-line-2 mt-2 skeleton"></skeleton>
@ -22,9 +21,6 @@
</scroll-view>
</view>
</u-card>
<!-- 骨架屏 -->
<u-skeleton :animation="true" :loading="loading" bg-color="#fff"></u-skeleton>
</view>
</template>
@ -36,14 +32,15 @@ export default {
name: 'Global',
components: { Skeleton },
data() {
return { loading: true };
return { loading: false };
},
computed: mapState('home', ['isShrink']),
mounted() {
this.loading = true;
setTimeout(() => {
this.loading = false;
console.log('this.loading: ', this.loading);
}, 5000);
}, 10000);
},
};
</script>

22
src/components/Project/Project.vue

@ -1,22 +0,0 @@
<template>
<view class="wrap">
<time-bar />
<view class="container p-2">
<time-line />
</view>
</view>
</template>
<script>
import TimeBar from './component/TimeBar';
import TimeLine from './component/TimeLine';
export default {
name: 'Project',
components: { TimeBar, TimeLine },
data() {
return {};
},
methods: {},
};
</script>

37
src/components/Project/component/TimeBar.vue

@ -1,37 +0,0 @@
<template>
<view class>
<!-- :class="{ active: cycleTasks.time.start === filter.startTime }" -->
<view class="cycle-time active">
<!-- {{ $util.formatStartTimeToCycleTime(filter.time, cycleTasks.time.start) }} -->
2021年30周
</view>
</view>
</template>
<script>
export default {
name: 'TimeBar',
data() {
return {};
},
};
</script>
<style scoped lang="scss">
.cycle-time {
padding: 8rpx 16rpx;
margin-bottom: 16rpx;
background: #fafafc;
color: $uni-text-color;
font-size: 14px;
position: sticky;
top: -1px;
left: 0;
z-index: 99;
&.active {
background: $uni-color-primary;
color: $uni-text-color-inverse;
}
}
</style>

80
src/components/Project/component/TimeLine.vue

@ -1,80 +0,0 @@
<template>
<u-time-line>
<u-time-line-item nodeTop="2">
<!-- 此处自定义了左边内容用一个图标替代 -->
<template v-slot:node>
<view class="u-node state">
<!-- 此处为uView的icon组件 -->
<!-- <u-icon :size="24" color="#fff" name="play-right-fill"></u-icon> -->
<u-circle-progress :percent="100" active-color="#2979ff" borderWidth="4" width="66">
<view class="u-progress-content">
<view class="u-progress-dot"></view>
<text class="u-progress-info">
<u-icon name="checkmark" size="30"></u-icon>
</text>
</view>
</u-circle-progress>
</view>
</template>
<template v-slot:content>
<view>
<view class="u-order-title">待取件</view>
<view class="u-order-desc">[自提柜]您的快件已放在楼下侧门直走前方53.6</view>
<view class="u-order-time">2019-05-08 12:12</view>
</view>
</template>
</u-time-line-item>
<u-time-line-item>
<!-- 此处没有自定义左边的内容会默认显示一个点 -->
<template v-slot:content>
<view>
<view class="u-order-desc">深圳市日照香炉生紫烟遥看瀑布挂前川飞流直下三千尺疑是银河落九天</view>
<view class="u-order-time">2019-12-06 22:30</view>
</view>
</template>
</u-time-line-item>
</u-time-line>
</template>
<script>
export default {
name: 'TimeLine',
data() {
return {};
},
};
</script>
<style lang="scss" scoped>
.u-node {
width: 44rpx;
height: 44rpx;
border-radius: 100rpx;
display: flex;
justify-content: center;
align-items: center;
background: #d0d0d0;
}
.state {
border: 2px solid #999;
background: #fff;
}
.u-order-title {
color: #333333;
font-weight: bold;
font-size: 32rpx;
}
.u-order-desc {
color: rgb(150, 150, 150);
font-size: 28rpx;
margin-bottom: 6rpx;
}
.u-order-time {
color: rgb(200, 200, 200);
font-size: 26rpx;
}
</style>

114
src/components/Roles/component/RoleList.vue

@ -3,8 +3,8 @@
<view class="home-box u-skeleton">
<scroll-view :enable-flex="true" :scroll-left="scrollLeft" :throttle="false" scroll-with-animation scroll-x>
<view class="tab-box">
<view :key="index" @click="changeIndex(index)" class="tab-item" v-for="(item, index) in roles">
<view :class="setColor(item.mine, tabIndex, index)" class="tab-children u-skeleton-fillet">{{ item.name }}</view>
<view :key="index" @click="changeIndex(item.id, index)" class="tab-item" v-for="(item, index) in roles">
<view :class="setColor(item.mine, item.id)" class="tab-children u-skeleton-fillet">{{ item.name }}</view>
</view>
</view>
</scroll-view>
@ -14,6 +14,8 @@
</template>
<script>
import { mapState, mapMutations, mapActions } from 'vuex';
export default {
name: 'RoleList',
data() {
@ -21,6 +23,7 @@ export default {
tabIndex: 0, //访 index 0
tabList: [], //tab dom
scrollLeft: 0, //scrollview
loading: false, //
roles: [
{
id: 1,
@ -57,68 +60,40 @@ export default {
pm: 0,
sequence: 5,
},
{
id: 6,
name: '导师四',
mine: 1,
pm: 0,
sequence: 6,
},
{
id: 7,
name: '导师五',
mine: 1,
pm: 0,
sequence: 7,
},
{
id: 8,
name: '导师六',
mine: 1,
pm: 0,
sequence: 8,
},
{
id: 9,
name: '导师七',
mine: 1,
pm: 0,
sequence: 9,
},
{
id: 10,
name: '导师八',
mine: 1,
pm: 0,
sequence: 10,
},
],
loading: true, //
};
},
mounted() {
this.init();
setTimeout(() => {
computed: { ...mapState('home', ['visibleRoles', 'roleId']) },
watch: {
visibleRoles(val) {
if (val && val.length) {
this.roles = [...this.visibleRoles];
this.loading = false;
}, 5000);
}
},
},
mounted() {
if (!this.visibleRoles || !this.visibleRoles.length) {
this.loading = true;
}
},
methods: {
init() {
...mapMutations('home', ['setRoleId']),
...mapActions('home', ['handleRegularTask']),
setCurrentRole(index) {
const data = document.getElementsByClassName('tab-children');
// TODO tabList
// tabList
data.forEach(item => {
this.tabList.push({
width: item.clientWidth,
left: item.offsetLeft,
});
});
},
changeIndex(index) {
//index
this.tabIndex = index;
//
let left = 0;
let screenWidth = window.screen.width;
@ -129,15 +104,44 @@ export default {
this.scrollLeft = left - screenWidth / 2;
},
changeIndex(id, index) {
this.setRoleId(id);
//index
this.setCurrentRole(index);
//
this.getTasks();
},
/**
* 根据时间基准点和角色查找定期任务
* @param {string} roleId 角色id
* @param {string} timeNode 时间基准点 默认当前
* @param {string} timeUnit 时间颗粒度 默认天
*/
async getTasks() {
try {
const { roleId, timeNode, timeUnit } = this;
const params = {
roleId,
timeNode,
timeUnit,
};
await this.handleRegularTask(params);
} catch (error) {
console.log('error: ', error);
}
},
//
setColor(mine, tabIndex, index) {
if (mine === 1 && tabIndex === index) {
setColor(mine, id) {
const { roleId } = this;
if (mine === 1 && roleId === id) {
return 'default-tab-choice';
}
if (mine === 1 && tabIndex !== index) {
if (mine === 1 && roleId !== id) {
return 'default-tab-item';
}
if (mine === 0 && tabIndex === index) {
if (mine === 0 && roleId === id) {
return 'tab-choice';
}
},
@ -160,9 +164,11 @@ export default {
.tab-box {
position: relative;
white-space: nowrap;
// height: 88rpx;
// height: 84rpx;
.tab-item {
// width: 20%;
// height: 84rpx;
padding: 20rpx 24rpx;
position: relative;
display: inline-block;

11
src/components/TimeLine/TimeLine.vue

@ -6,6 +6,7 @@
* @LastEditTime: 2021-07-20 14:22:11
-->
<template>
<!-- 时间间隔栏 -->
<!-- <Barrier /> -->
<scroll-view
:lower-threshold="300"
@ -17,6 +18,7 @@
@scrolltoupper="handleScrollTop"
id="scroll"
>
<!-- 时间轴 -->
<TimeBox ref="child" />
</scroll-view>
</template>
@ -47,7 +49,9 @@ export default {
],
};
},
computed: mapState('home', ['scrollTop', 'showTips']),
computed: mapState('home', ['scrollTop', 'showTips', 'visibleRoles']),
mounted() {
let tasksHeight = 0;
const scrollHeight = document.getElementById('scroll').clientHeight;
@ -55,9 +59,12 @@ export default {
tasksHeight += this.list1[i].TaskPanel.height - 0 + 42;
}
this.top = tasksHeight - scrollHeight / 2;
console.log('this.top: ', this.top);
},
methods: {
...mapMutations('home', ['setScrollTop', 'setShrink']),
...mapMutations('home', ['setScrollTop', 'setShrink', 'setRoleId']),
//
scroll(e) {
this.top = e.detail.scrollTop;

7
src/components/TimeLine/component/TimeBox.vue

@ -47,6 +47,7 @@
</template>
<script>
import { mapState, mapMutations } from 'vuex';
import TaskDesc from '@/plugins/TaskDesc/TaskDesc.vue';
import TaskTitle from '@/plugins/TaskTitle/TaskTitle.vue';
import TimeStatus from './TimeStatus.vue';
@ -109,7 +110,13 @@ export default {
};
},
computed: mapState('home', ['roleId', 'timeNode', 'timeUnit']),
created() {},
methods: {
...mapMutations('home', ['setTipsContent', 'setTipsContent']),
addTopList() {
this.list = this.addList.concat(this.list);
},

23
src/components/Title/Title.vue

@ -2,8 +2,7 @@
<view>
<u-navbar back-text="返回">
<view class="flex justify-center flex-1">
<view v-if="Istrue">{{ title }}</view>
<view v-else>{{ titleBar }}</view>
<view>{{ project.name }}</view>
</view>
<view class="mr-2" slot="right">
<u-icon class="m-1" name="checkmark-circle"></u-icon>
@ -15,23 +14,17 @@
</view>
</template>
<script>
import { mapState } from 'vuex';
export default {
name: 'Title',
data() {
return {
title: '加载中...',
titleBar: '项目名称',
Istrue: true,
};
},
mounted() {
this.getTitle();
},
methods: {
getTitle() {
this.Istrue = !this.Istrue;
},
return { title: '加载中...' };
},
computed: mapState('home', ['project']),
mounted() {},
methods: {},
};
</script>

34
src/mock/mock.js

@ -95,11 +95,39 @@ export default [
], //展示的角色
visibleList: [
{
id: 12345678932165,
id: 1,
name: '项目经理',
mine: 0,
name: 'string',
pm: 1,
sequence: 1,
},
{
id: 2,
name: '运维',
mine: 0,
pm: 0,
sequence: 2,
},
{
id: 3,
name: '导师一',
mine: 1,
pm: 0,
sequence: 3,
},
{
id: 4,
name: '导师二',
mine: 1,
pm: 0,
sequence: 4,
},
{
id: 5,
name: '导师三',
mine: 1,
pm: 0,
sequence: 22,
sequence: 5,
},
],
},

57
src/pages/project/project.vue

@ -16,18 +16,27 @@ export default {
return { title: 'Hello', height: '', scrollHeight: null };
},
computed: { ...mapState('user', ['user', 'token']) },
computed: {
...mapState('user', ['user', 'token']),
...mapState('home', ['visibleRoles', 'roleId', 'timeNode', 'timeUnit']),
},
onLoad(options) {
async onLoad(options) {
console.log('options: ', options);
console.log(this.$u.config.v);
// this.openPage();
// DEBUG:
this.getUserId('1217651354919636992');
const params = { param: { projectId: '1235555' } };
this.$u.api.findProjectById(params);
let TOKEN = uni.getStorageSync('anyringToken');
if (!TOKEN) {
await this.getUserId('1217651354919636992');
}
const params = { projectId: '1235555' };
// id
await this.getProjectById(params);
// id
await this.getRoles(params);
console.log('this.visibleRoles: ', this.visibleRoles);
this.setInitialRoleId(this.visibleRoles);
//
await this.getTasks();
},
mounted() {
@ -36,12 +45,42 @@ export default {
methods: {
...mapMutations('user', ['setToken', 'setUser']),
...mapMutations('home', ['setProject', 'setInvisibleRoles', 'setVisibleRoles', 'setRoleId']),
...mapActions('user', ['getUserId']),
...mapActions('home', ['getProjectById', 'getRoles', 'handleRegularTask']),
openPage() {
console.log('open');
this.$u.route('/pages/pinch/pinch');
},
//
setInitialRoleId(visibleList) {
const index = visibleList.findIndex(item => item.mine);
const currentRole = index > 0 ? visibleList[index] : visibleList[0];
const currentRoleId = currentRole ? currentRole.id : '';
this.setRoleId(currentRoleId);
},
/**
* 根据时间基准点和角色查找定期任务
* @param {string} roleId 角色id
* @param {string} timeNode 时间基准点 默认当前
* @param {string} timeUnit 时间颗粒度 默认天
*/
async getTasks() {
try {
const { roleId, timeNode, timeUnit } = this;
const params = {
roleId,
timeNode,
timeUnit,
};
await this.handleRegularTask(params);
} catch (error) {
console.log('error: ', error);
}
},
},
};
</script>

51
src/store/home/actions.js

@ -1,3 +1,52 @@
const actions = {};
const actions = {
/**
* 通过项目id获取项目信息
* @param {any} commit
* @param {object} params 提交的参数
*/
async getProjectById({ commit }, params) {
try {
uni.$u.api.findProjectById(params).then(res => {
commit('setProject', res);
return res;
});
} catch (error) {
throw error || '获取项目信息失败';
}
},
/**
* 通过项目id获取角色信息
* @param {any} commit
* @param {object} params 提交的参数
*/
async getRoles({ commit }, params) {
try {
const res = await uni.$u.api.findShowRoles(params);
commit('setInvisibleRoles', res.invisibleList);
commit('setVisibleRoles', res.visibleList);
return res;
} catch (error) {
throw error || '获取角色信息失败';
}
},
/**
* 根据时间基准点和角色查找定期任务
* @param {string} roleId 角色id
* @param {string} timeNode 时间基准点 默认当前
* @param {string} timeUnit 时间颗粒度 默认天
*/
async handleRegularTask({ commit }, params) {
try {
uni.$u.api.getRegularTask(params).then(res => {
commit('setTasks', res);
return res;
});
} catch (error) {
throw error || '获取定期任务失败';
}
},
};
export default actions;

61
src/store/home/mutations.js

@ -47,6 +47,67 @@ const mutations = {
setTipsContent(state, data) {
state.tipsContent = data;
},
/**
* 设置当前项目信息
* @param { object } state
* @param { object } data
*/
setProject(state, data) {
state.project = { ...data };
},
/**
* 设置不展示的角色信息
* @param {Object} state
* @param {Array} data 服务端返回的模板数组
*/
setInvisibleRoles(state, data) {
state.invisibleRoles = data || [];
},
/**
* 设置展示的角色信息
* @param {Object} state
* @param {Array} data 服务端返回的模板数组
*/
setVisibleRoles(state, data) {
state.visibleRoles = data || [];
},
/**
* 设置当前角色信息
* @param {Object} state
* @param {string} roleId 当前正在展示的角色的id
*/
setRoleId(state, roleId) {
state.roleId = roleId;
},
/**
* 设置时间基准点
* @param { object } state
* @param { number } data
*/
setTimeNode(state, data) {
state.timeNode = data;
},
/**
* 设置时间颗粒度
* @param { object } state
* @param { number } data
*/
setTimeUnit(state, data) {
state.timeUnit = data;
},
/**
* 设置定期任务数据
* @param {Object} state
* @param {Array} data 服务端返回的模板数组
*/
setTasks(state, data) {
state.tasks = data || [];
},
};
export default mutations;

22
src/store/home/state.js

@ -8,6 +8,28 @@ const state = {
showTips: false,
status: 0, // 点击了时间轴上的哪种样式,默认点击了开始
tipsContent: '', // 提示框内的内容,需要传入
project: { name: '加载中...' }, // 当前项目信息
invisibleRoles: [], // 不展示的角色信息
visibleRoles: [], // 展示的角色信息
roleId: '', // 当前展示查看的角色id
timeNode: new Date().getTime(), // 时间基准点
timeUnit: 4, // // 时间颗粒度
timeUnits: [
// 时间颗粒度
{ id: 0, value: '毫秒' },
{ id: 1, value: '秒' },
{ id: 2, value: '分' },
{ id: 3, value: '时' },
{ id: 4, value: '天' },
{ id: 5, value: '周' },
{ id: 6, value: '月' },
{ id: 7, value: '季度' },
{ id: 8, value: '年' },
{ id: 9, value: '年代' },
{ id: 10, value: '世纪' },
{ id: 11, value: '千年' },
],
tasks: [], // 定期任务
};
export default state;

9
src/utils/request.js

@ -41,6 +41,15 @@ const install = (Vue, vm) => {
return false;
}
};
Vue.prototype.$u.post = (url, param = {}, header = {}) => {
return Vue.prototype.$u.http.request({
url,
method: 'POST',
header,
data: { param },
});
};
};
export default { install };

Loading…
Cancel
Save