Browse Source

feat: 插件参数处理调整

tall
wally 4 years ago
parent
commit
a3e68d3e18
  1. 1
      CHANGELOG.md
  2. 101
      src/components/Plugin/Plugin.vue
  3. 42
      src/components/TimeLine/component/TimeBox.vue
  4. 13
      src/plugins/p-task-description/p-task-description.vue
  5. 24
      src/plugins/p-task-duration-delay/p-task-duration-delay.vue
  6. 15
      src/plugins/p-task-start-time-delay/p-task-start-time-delay.vue
  7. 13
      src/plugins/p-task-title/p-task-title.vue
  8. 2
      src/store/task/actions.js
  9. 1
      src/store/task/getters.js
  10. 2
      src/store/task/mutations.js
  11. 2
      src/store/user/actions.js

1
CHANGELOG.md

@ -52,6 +52,7 @@
### 🐛 Bug 修复 ### 🐛 Bug 修复
范围|描述|commitId 范围|描述|commitId
--|--|-- --|--|--
role | 切换角色的逻辑修正完善 | 4ae534f
task任务逻辑完善 | 减少初始global及regular的不必要请求 | bd4bd38 task任务逻辑完善 | 减少初始global及regular的不必要请求 | bd4bd38
- | 上下滑动加载定期任务 | 4090d89 - | 上下滑动加载定期任务 | 4090d89
- | 上下滚动时间轴 | d533a01 - | 上下滚动时间轴 | d533a01

101
src/components/Plugin/Plugin.vue

@ -1,22 +1,19 @@
<template> <template>
<view class="u-font-14"> <view class="u-font-14" style="height: 100%">
<view style="height: 100%" v-if="pluginContent"> <view v-if="pluginContent">
<view v-if="pluginContent.html"> <view style="height: 100%" v-html="pluginContent"></view>
<view style="height: 100%" v-html="pluginContent.html"></view> </view>
</view>
<view v-else> <view v-else>
<view v-if="item && item.name"> <p-task-title :name="task.name" v-if="pluginId === '1'" />
<p-task-title :item="item" v-if="pluginId === '1'" /> <p-task-description :text="task.description" v-if="pluginId === '2'" />
<p-task-description :item="item" v-if="pluginId === '2'" /> <p-task-duration-delay :realDuration="task.realDuration" :planDuration="task.planDuration" v-if="pluginId === '3'" />
<p-task-duration-delay :item="item" v-if="pluginId === '3'" /> <p-task-start-time-delay :realStart="task.realStart" :planStart="task.planStart" v-if="pluginId === '4'" />
<p-task-start-time-delay :item="item" /> <!-- <p-task-start-time-delay :task="task" v-if="pluginId === '4'" /> -->
<!-- <p-task-start-time-delay :item="item" v-if="pluginId === '4'" /> --> <!-- <p-deliverable :task="task" v-if="pluginId === '5'" /> -->
<p-deliverable :item="item" v-if="pluginId === '5'" /> <!-- <p-subtasks :task="task" v-if="pluginId === '6'" /> -->
<p-subtasks :item="item" v-if="pluginId === '6'" /> <!-- <p-subproject :task="task" v-if="pluginId === '7'" /> -->
<p-subproject :item="item" v-if="pluginId === '7'" /> <!-- <p-task-countdown :task="task" v-if="pluginId === '8'" /> -->
<p-task-countdown :item="item" v-if="pluginId === '8'" />
</view>
</view>
</view> </view>
</view> </view>
</template> </template>
@ -25,48 +22,60 @@
export default { export default {
name: 'Plugin', name: 'Plugin',
props: { props: {
item: { task: { default: () => {}, type: Object },
default: () => {}, pluginId: { default: '1', type: String },
type: Object, styleType: { default: 0, type: Number },
}, pluginTaskId: { default: '0', type: String },
pluginId: {
default: '1',
type: String,
},
styleType: {
default: 0,
type: Number,
},
pluginTaskId: {
default: '0',
type: String,
},
}, },
data() { data() {
return { pluginContent: null }; return { pluginContent: null };
}, },
async created() { created() {
await this.getPlugin(); this.getPlugin();
let domList = Array.from(document.getElementsByTagName('script'));
const index = domList.findIndex(item => item.id === `p${this.pluginContent.pluginId}`);
if (this.pluginContent.js && index === -1) {
var scriptDom = document.createElement('script');
scriptDom.id = `p${this.pluginContent.pluginId}`;
scriptDom.innerHTML = this.pluginContent.js;
document.body.append(scriptDom);
}
}, },
methods: { methods: {
//
async getPlugin() { async getPlugin() {
const { pluginId, styleType } = this; const { pluginId, styleType } = this;
const res = await this.$u.api.getOtherPlugin({ const data = await this.$u.api.getOtherPlugin({
pluginId, pluginId,
styleType, styleType,
}); });
this.pluginContent = res; if (!data || !data.id) return;
if (data.html) {
// data-root=xxx xxx pluginTaskId
const reg = /data-root="(\w+)"/gi;
if (reg.test(data.html)) {
const str = data.html.replace(RegExp.$1, this.pluginTaskId);
this.pluginContent = str;
} else {
this.pluginContent = data.html;
}
}
if (data.js) {
if (reg.test(data.js)) {
const str = data.js.replace(RegExp.$1, this.pluginTaskId);
this.handleDom(str);
} else {
this.handleDom(data.js);
}
}
},
// script dom
handleDom(js) {
const { pluginId } = this;
let domList = Array.from(document.getElementsByTagName('script'));
const index = domList.findIndex(item => item.id === `p${pluginId}`);
if (js && index === -1) {
const scriptDom = document.createElement('script');
scriptDom.id = `p${pluginId}`;
scriptDom.innerHTML = js;
document.body.append(scriptDom);
}
}, },
}, },
}; };

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

@ -1,12 +1,12 @@
<template> <template>
<view class="column"> <view class="column">
<view :key="index" v-for="(item, index) in tasks"> <view :key="index" v-for="(task, index) in tasks">
<view class="flex"> <view class="flex">
<TimeStatus :content="JSON.stringify(item.process)" :status="item.process" /> <TimeStatus :content="JSON.stringify(task.process)" :status="task.process" />
<view class="flex items-center justify-between flex-1 ml-2 task-column"> <view class="flex items-center justify-between flex-1 ml-2 task-column">
<view> <view>
<span>{{ $moment(+item.planStart).format(startTimeFormat) }}</span> <span>{{ $moment(+task.planStart).format(startTimeFormat) }}</span>
</view> </view>
<!-- 任务功能菜单 --> <!-- 任务功能菜单 -->
@ -18,27 +18,29 @@
<u-card <u-card
:show-foot="false" :show-foot="false"
:show-head="false" :show-head="false"
:style="{ height: setHeight(item.panel) }" :style="{ height: setHeight(task.panel) }"
@click="changeTimeNode(item.planStart)" @click="onClickTask(+task.planStart)"
class="h-16" class="h-16"
margin="0" margin="0"
v-if="item.plugins" v-if="task.plugins && task.plugins.length"
> >
<!-- 任务面板插件 --> <!-- 任务面板插件 -->
<view slot="body"> <view slot="body">
<view v-if="!item.plugins.length"> <!-- TODO: 逻辑不完善 -->
<view v-if="!task.plugins.length">
<skeleton :banner="false" :loading="true" :row="4" animate class="mt-2 u-line-2 skeleton"></skeleton> <skeleton :banner="false" :loading="true" :row="4" animate class="mt-2 u-line-2 skeleton"></skeleton>
</view> </view>
<view class="p-0 u-col-between" v-else> <view class="p-0 u-col-between" v-else>
<view :key="pIndex" v-for="(p, pIndex) in item.plugins"> <view :key="pIndex" v-for="(row, pIndex) in task.plugins">
<view class="grid gap-2" v-if="p.length"> <view class="grid gap-2" v-if="row.length">
<Plugin <Plugin
:class="getClass(plugin.col, plugin.row)" :class="getClass(plugin.col, plugin.row)"
:item="item" :task="task"
:key="plugin.pluginTaskId" :key="plugin.pluginTaskId"
:pluginId="plugin.pluginId" :pluginId="plugin.pluginId"
:styleType="styleType || 0" :styleType="styleType || 0"
v-for="plugin in p" v-for="plugin in row"
/> />
</view> </view>
</view> </view>
@ -48,14 +50,15 @@
</view> </view>
</view> </view>
</view> </view>
<!-- 局部弹框操作栏 -->
<Tips /> <Tips />
</view> </view>
</template> </template>
<script> <script>
import { mapState, mapMutations, mapGetters } from 'vuex'; import { mapState, mapMutations, mapGetters, mapActions } from 'vuex';
import TimeStatus from './TimeStatus.vue';
import Skeleton from '@/components/Skeleton/Skeleton'; import Skeleton from '@/components/Skeleton/Skeleton';
import TimeStatus from './TimeStatus.vue';
import TaskTools from './TaskTools.vue'; import TaskTools from './TaskTools.vue';
export default { export default {
@ -67,11 +70,12 @@ export default {
computed: { computed: {
...mapState('role', ['roleId']), ...mapState('role', ['roleId']),
...mapState('task', ['timeNode', 'timeUnit', 'tasks', 'taskLoading']), ...mapState('task', ['timeUnit', 'tasks', 'taskLoading']),
...mapGetters('task', ['startTimeFormat']), ...mapGetters('task', ['startTimeFormat']),
}, },
methods: { methods: {
...mapActions('task', ['getGlobal']),
...mapMutations('task', ['setTipsContent', 'setTipsContent', 'setTimeNode']), ...mapMutations('task', ['setTipsContent', 'setTipsContent', 'setTimeNode']),
// //
@ -83,9 +87,13 @@ export default {
} }
}, },
// store /**
changeTimeNode(time) { * 点击了定期任务的面板 更新可变的日常任务
this.setTimeNode(time); * @param {number} planStart 任务计划开始时间
*/
onClickTask(planStart) {
const param = { roleId: this.roleId, timeNode: planStart, timeUnit: this.timeUnit };
this.getGlobal(param);
}, },
// //

13
src/plugins/p-task-description/p-task-description.vue

@ -1,20 +1,11 @@
<template> <template>
<!-- 任务描述 --> <!-- 任务描述 -->
<view>{{ item.description }}</view> <view>{{ text }}</view>
</template> </template>
<script> <script>
export default { export default {
name: 'p-task-description', name: 'p-task-description',
props: { item: { type: Object, default: null } }, props: { text: { type: String, default: '' } },
data() {
return {};
},
computed: {},
methods: {},
watch: {},
}; };
</script> </script>
<style></style>

24
src/plugins/p-task-duration-delay/p-task-duration-delay.vue

@ -1,28 +1,20 @@
<template> <template>
<view v-if="item.realDuration && item.planDuration"> <view v-if="realDuration && planDuration">
<!-- 任务时长延迟插件 --> <!-- 任务时长延迟插件 -->
<!-- 超时 --> <!-- 超时 -->
<span class="text-green-500 font-bold" v-if="+item.realDuration > +item.planDuration" <span class="font-bold text-green-500" v-if="+realDuration > +planDuration">
>+{{ $t.time.formatDuration(+item.realDuration - +item.planDuration) }}</span +{{ $t.time.formatDuration(+realDuration - +planDuration) }}
> </span>
<!-- 延时 --> <!-- 延时 -->
<span class="text-red-500 font-bold" v-if="+item.realDuration < +item.planDuration" <span class="font-bold text-red-500" v-if="+realDuration < +planDuration">
>-{{ $t.time.formatDuration(+item.planDuration - +item.realDuration) }}</span -{{ $t.time.formatDuration(+planDuration - +realDuration) }}
> </span>
</view> </view>
</template> </template>
<script> <script>
export default { export default {
name: 'p-task-duration-delay', name: 'p-task-duration-delay',
props: { item: { type: Object, default: null } }, props: { planDuration: { type: String, default: '0' }, realDuration: { type: String, default: '0' } },
data() {
return {};
},
computed: {},
methods: {},
watch: {},
}; };
</script> </script>
<style></style>

15
src/plugins/p-task-start-time-delay/p-task-start-time-delay.vue

@ -1,23 +1,14 @@
<template> <template>
<view v-if="item.realStart && item.planStart"> <view v-if="realStart && planStart">
<!-- 任务开始时间延迟插件 --> <!-- 任务开始时间延迟插件 -->
<!-- 超时 --> <!-- 超时 -->
<span>{{ $t.time.formatDuration(+item.realStart - +item.planStart) }}</span> <span>{{ $t.time.formatDuration(+realStart - +planStart) }}</span>
</view> </view>
</template> </template>
<script> <script>
export default { export default {
name: 'p-task-start-time-delay', name: 'p-task-start-time-delay',
props: { item: { type: Object, default: null } }, props: { realStart: { type: String, default: '0' }, planStart: { type: String, default: '0' } },
data() {
return {};
},
computed: {},
methods: {},
watch: {},
}; };
</script> </script>
<style></style>

13
src/plugins/p-task-title/p-task-title.vue

@ -1,20 +1,11 @@
<template> <template>
<!-- 任务名插件 --> <!-- 任务名插件 -->
<view>{{ item.name }}</view> <view>{{ name }}</view>
</template> </template>
<script> <script>
export default { export default {
name: 'p-task-title', name: 'p-task-title',
props: { item: { type: Object, default: null } }, props: { name: { type: String, default: '' } },
data() {
return {};
},
computed: {},
methods: {},
watch: {},
}; };
</script> </script>
<style></style>

2
src/store/task/actions.js

@ -16,7 +16,7 @@ const actions = {
/** /**
* 根据时间和角色查找日常任务 * 根据时间和角色查找日常任务
* @param {*} commit * @param {*} commit
* @param {object} param 请求参数 * @param {object} param 请求参数 roleId, timeNode, timeUnit
*/ */
async getGlobal({ commit }, param) { async getGlobal({ commit }, param) {
try { try {

1
src/store/task/getters.js

@ -6,7 +6,6 @@ const getters = {
// 计算任务开始时间的格式 // 计算任务开始时间的格式
startTimeFormat({ timeUnit }) { startTimeFormat({ timeUnit }) {
console.log(uni.$t);
const target = uni.$t.timeConfig.timeUnits.find(item => item.id === timeUnit); const target = uni.$t.timeConfig.timeUnits.find(item => item.id === timeUnit);
return target.format || 'D日 HH:mm'; return target.format || 'D日 HH:mm';
}, },

2
src/store/task/mutations.js

@ -96,7 +96,7 @@ const mutations = {
if (!data || !data.length) { if (!data || !data.length) {
state.bottomEnd = true; state.bottomEnd = true;
} }
if (!state.tasks[0].name) { if (!state.tasks[0] || !state.tasks[0].name) {
state.tasks = [...data]; state.tasks = [...data];
} else { } else {
state.tasks = [...state.tasks.concat(data)]; state.tasks = [...state.tasks.concat(data)];

2
src/store/user/actions.js

@ -11,7 +11,7 @@ const actions = {
commit('setUser', res); commit('setUser', res);
return res; return res;
} catch (error) { } catch (error) {
throw error || '获取个人信息失败'; uni.$t.ui.showToast(error.msg || '获取个人信息失败');
} }
}, },
}; };

Loading…
Cancel
Save