diff --git a/CHANGELOG.md b/CHANGELOG.md index a295d8d..ef42060 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -66,6 +66,7 @@ ### 🔨 代码重构 范围|描述|commitId --|--|-- + - | project 代码健壮性完善 | [a3202c5](http://gitea@dd.tall.wiki:wally/TALL-MUI-3/commits/a3202c5) - | 下滑时间轴添加备注 | [4fd20e3](http://gitea@dd.tall.wiki:wally/TALL-MUI-3/commits/4fd20e3) template | eslint prettier sass uview tailwindcss | [9c966a1](http://gitea@dd.tall.wiki:wally/TALL-MUI-3/commits/9c966a1) diff --git a/src/apis/plugin.js b/src/apis/plugin.js index cb952b4..caeb006 100644 --- a/src/apis/plugin.js +++ b/src/apis/plugin.js @@ -1,9 +1,11 @@ const apiUrl = process.env.VUE_APP_API_URL; const mock = `${apiUrl}/defaultwbs`; +const plugin = `${apiUrl}/pluginshop/plugin`; const install = (Vue, vm) => { vm.$u.api = { ...vm.$u.api } || {}; - vm.$u.api.getPlugin = param => vm.$u.post(`${mock}/plugin`, { param }); + vm.$u.api.getPlugin = param => vm.$u.post(`${mock}/plugin`, param); + vm.$u.api.getOtherPlugin = param => vm.$u.post(`${plugin}/query`, param); }; export default { install }; diff --git a/src/components/Globals/Globals.vue b/src/components/Globals/Globals.vue index e33a2e1..a71929d 100644 --- a/src/components/Globals/Globals.vue +++ b/src/components/Globals/Globals.vue @@ -3,14 +3,14 @@ - + - + @@ -31,16 +31,16 @@ export default { props: { plugins: { type: Array, default: () => [] } }, data() { return { - loading: true, + // loading: true, pluginId: 0, styleType: 0, task: null, }; }, - mounted() { - setTimeout(() => (this.loading = false), 2000); - }, + // mounted() { + // setTimeout(() => (this.loading = false), 2000); + // }, computed: mapState('home', ['isShrink']), methods: { getClass(col, row) { diff --git a/src/components/Plugin/Plugin.vue b/src/components/Plugin/Plugin.vue index 8be59a6..c70d838 100644 --- a/src/components/Plugin/Plugin.vue +++ b/src/components/Plugin/Plugin.vue @@ -1,28 +1,64 @@ diff --git a/src/config/time.js b/src/config/time.js new file mode 100644 index 0000000..7c8ecd4 --- /dev/null +++ b/src/config/time.js @@ -0,0 +1,17 @@ +export default { + 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: '千年' }, + ], +}; diff --git a/src/main.js b/src/main.js index 045017f..0d2bfa6 100644 --- a/src/main.js +++ b/src/main.js @@ -17,9 +17,11 @@ Vue.use(indexedDB); //#endif Vue.config.productionTip = false; +Vue.prototype.$moment = dayjs; Vue.use(uView); Vue.use(Tall); -Vue.use(dayjs); + +dayjs.locale('zh-cn'); App.mpType = 'app'; diff --git a/src/mock/mock.js b/src/mock/mock.js index ab406fa..2a9e7d4 100644 --- a/src/mock/mock.js +++ b/src/mock/mock.js @@ -177,11 +177,11 @@ export default [ plugins: [ [ { - col: 123, + col: 1, colspan: 123, param: 123, - pluginId: 123456789, - row: 123, + pluginId: 13, + row: 2, rowspan: 123, }, ], @@ -226,11 +226,11 @@ export default [ plugins: [ [ { - col: 123, + col: 1, colspan: 123, param: 123, - pluginId: 123456789, - row: 123, + pluginId: 13, + row: 1, rowspan: 123, }, ], @@ -387,7 +387,7 @@ export default [ msg: 'ok', success: true, data: { - html: 'string', + html: '
', id: 13, intro: 'string', js: 'string', diff --git a/src/pages/project/project.vue b/src/pages/project/project.vue index 0415ea6..999710d 100644 --- a/src/pages/project/project.vue +++ b/src/pages/project/project.vue @@ -30,6 +30,29 @@ export default { this.init(options); }, + watch: { + /** + * 当时间基准点发生变化时 + * 重新根据时间和角色查询普通日常任务 + * 永久日常任务不发生改变 + */ + async timeNode() { + // 根据时间和角色查找日常任务 + await this.getGlobal(); + }, + /** + * 当角色发生变化时 + * 重新查询永久日常任务和普通日常任务 + */ + async roleId() { + this.setTimeNode(new Date().getTime()); + // 根据角色查找永久的日常任务 + await this.getPermanent(); + // 根据时间和角色查找日常任务 + await this.getGlobal(); + }, + }, + mounted() { this.height = window.screen.height + 'px'; }, @@ -44,6 +67,7 @@ export default { 'setDownTasks', 'setDailyTasks', 'setProjectName', + 'setTimeNode', ]), ...mapActions('user', ['getUserId']), ...mapActions('home', ['getProjectById', 'getRoles', 'handleRegularTask']), @@ -141,8 +165,11 @@ export default { */ async getPermanent() { try { + this.allPlugins = []; const res = await this.$u.api.getPermanent({ roleId: this.roleId }); - // TODO: + for (let item of res) { + this.allPlugins = this.allPlugins.concat(item.plugins); + } console.log('res', res); } catch (error) { console.log('error: ', error); @@ -157,12 +184,13 @@ export default { */ async getGlobal() { try { + this.timePlugins = []; const { roleId, timeNode, timeUnit } = this; const params = { roleId, timeNode, timeUnit }; const res = await this.$u.api.getGlobal(params); for (let task of res) { for (let item of task.plugins) { - this.plugins.push(...item); + this.timePlugins.push(...item); } } this.setDailyTasks(res); @@ -176,15 +204,20 @@ export default { try { await this.getTasks({ queryType: 0 }); await this.getTasks({ queryType: 1 }); - // 查上下的任务 + // 查上页的任务 const upQuery = { timeNode: +this.tasks[0].planStart, queryType: 0, queryNum: 6, }; await this.getTasks(upQuery); + + // 查下页的任务 + // 时间基准点=最后一个任务的开始时间+当前时间颗粒度 + const cycle = this.$t.time.computeCycle('天'); + const timeNode = this.$t.time.add(+this.tasks[this.tasks.length - 1].planStart, 1, cycle).valueOf(); const downQuery = { - timeNode: +this.tasks[this.tasks.length - 1].planStart, + timeNode, queryType: 1, queryNum: 6, }; diff --git a/src/store/home/mutations.js b/src/store/home/mutations.js index ec844a5..c44dd92 100644 --- a/src/store/home/mutations.js +++ b/src/store/home/mutations.js @@ -125,7 +125,12 @@ const mutations = { if (!data || !data.length) { state.topEnd = true; } - state.tasks = [...data.concat(state.tasks)] || []; + console.log('!state.tasks.plugins.length: ', !state.tasks[0].name); + if (!state.tasks[0].name) { + state.tasks = [...data]; + } else { + state.tasks = [...data.concat(state.tasks)]; + } }, /** @@ -137,16 +142,36 @@ const mutations = { if (!data || !data.length) { state.bottomEnd = true; } - state.tasks = [...state.tasks.concat(data)] || []; + if (!state.tasks[0].name) { + state.tasks = [...data]; + } else { + state.tasks = [...state.tasks.concat(data)]; + } }, /** * 清空定期任务数据 * @param {Object} state - * @param {Array} data 服务端返回的模板数组 */ - setTasks(state, data) { - state.tasks = data || []; + setTasks(state) { + const data = [ + { + panel: {}, + plugins: [], + planStart: new Date().getTime(), + }, + { + panel: {}, + plugins: [], + planStart: new Date().getTime(), + }, + { + panel: {}, + plugins: [], + planStart: new Date().getTime(), + }, + ]; + state.tasks = data; }, /** diff --git a/src/store/home/state.js b/src/store/home/state.js index 7389c48..553a3c1 100644 --- a/src/store/home/state.js +++ b/src/store/home/state.js @@ -14,22 +14,23 @@ const state = { 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: [], // 定期任务 + tasks: [ + { + panel: {}, + plugins: [], + planStart: new Date().getTime(), + }, + { + panel: {}, + plugins: [], + planStart: new Date().getTime(), + }, + { + panel: {}, + plugins: [], + planStart: new Date().getTime(), + }, + ], // 定期任务 topEnd: false, // 时间轴向上查任务到顶了 bottomEnd: false, // 时间轴向下查任务到底了 dailyTasks: [], // 日常任务 diff --git a/src/utils/time.js b/src/utils/time.js index 1ffe1d7..eb7e9c4 100644 --- a/src/utils/time.js +++ b/src/utils/time.js @@ -30,6 +30,17 @@ const formatTime = beginTime => { return `${[year, month, day].map(formatNumber).join('/')} ${[hour, minute, second].map(formatNumber).join(':')}`; }; +/** + * 添加一定时间的时长 + * @param {number | date} time + * @param {number} num + * @param {string} cycle + */ +const add = (time, num, cycle) => { + const str = dayjs(time).add(num, cycle); + return str; +}; + /** * 时间转换 08:00 转换成8小时0分钟 * @param {string} time @@ -286,6 +297,7 @@ const formatStartTimeToCycleTime = (cycle, time) => { export default { formatNumber, formatTime, + add, convertTime, secondToMinute, setTimestampToStr,