mission-icon.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <template>
  2. <div id="mission-icon">
  3. <el-tooltip class="item" effect="light" placement="bottom-end">
  4. <el-badge class="icon" :value="list.length">
  5. <i class="el-icon-bell icon"></i>
  6. </el-badge>
  7. <template #content>
  8. <!-- <el-row type="flex" align="middle" v-for="(i, index) in list" :key="`mission-${index}`">
  9. <el-col :span="14" class="out">{{ i.title }}</el-col>
  10. <el-col :span="4">{{ getProgress(i) }}</el-col>
  11. <el-col :span="6" style="text-align:right;width:80px;">
  12. <el-link type="primary" size="mini" @click="noDot(i)">[不再提示]</el-link>
  13. </el-col>
  14. </el-row> -->
  15. <el-table :data="list" size="mini" border :show-header="false" max-height="200px">
  16. <el-table-column align="center" prop="title" show-overflow-tooltip min-width="200px"></el-table-column>
  17. <el-table-column align="center">
  18. <template v-slot="{ row }">
  19. {{ getProgress(row) }}
  20. </template>
  21. </el-table-column>
  22. <el-table-column align="center">
  23. <template v-slot="{ row }">
  24. <el-button type="text" icon="el-icon-close-notification" @click="noDot(row)"></el-button>
  25. </template>
  26. </el-table-column>
  27. </el-table>
  28. </template>
  29. </el-tooltip>
  30. </div>
  31. </template>
  32. <script>
  33. // import Vue from 'vue';\
  34. const _ = require('lodash');
  35. import { mapState, createNamespacedHelpers } from 'vuex';
  36. const { mapActions: mission } = createNamespacedHelpers('mission');
  37. export default {
  38. name: 'mission-icon',
  39. props: {},
  40. components: {},
  41. data: function() {
  42. return {
  43. list: [],
  44. };
  45. },
  46. created() {
  47. this.search();
  48. },
  49. mounted() {
  50. this.channel();
  51. },
  52. methods: {
  53. ...mission(['query', 'update']),
  54. async search() {
  55. const res = await this.query({ dot: true });
  56. if (this.$checkRes(res)) {
  57. let newData = _.cloneDeep(res.data);
  58. const oldData = _.cloneDeep(this.list);
  59. if (oldData.length !== 0) {
  60. // 非初始化提示,初始化不提示
  61. for (const nd of newData) {
  62. const sr = oldData.find(f => nd.id === f.id && nd.status === '2' && f.status === '1');
  63. let ntitle, type, message;
  64. if (sr) {
  65. const { title } = sr;
  66. ntitle = title;
  67. type = 'success';
  68. message = '已完成,请在 菜单-待办事项 中查看结果';
  69. }
  70. const er = oldData.find(f => nd.id === f.id && nd.status === '3' && f.status === '1');
  71. if (er) {
  72. const { title } = er;
  73. ntitle = title;
  74. type = 'error';
  75. message = '任务失败,请在 菜单-待办事项 中重新执行任务.若多次执行仍错误,请联系开发人员!';
  76. }
  77. if (ntitle && message && type) {
  78. this.$notify({
  79. title: ntitle,
  80. message,
  81. type,
  82. });
  83. }
  84. }
  85. }
  86. this.$set(this, `list`, newData);
  87. }
  88. },
  89. async noDot(data) {
  90. data.dot = false;
  91. const res = await this.update(data);
  92. if (this.$checkRes(res, '已取消提示', res.errmsg || '取消提示失败')) {
  93. this.search();
  94. }
  95. },
  96. getProgress(data) {
  97. const { status } = data;
  98. if (!status) return '';
  99. if (status === '0') return '未开始';
  100. if (status === '2') return '已完成';
  101. if (status === '3') return '失败';
  102. if (status === '1') return `${data.progress || 0}%`;
  103. },
  104. channel() {
  105. this.$stomp({
  106. [`/exchange/mission/remind`]: this.onMessage,
  107. });
  108. },
  109. onMessage(message) {
  110. this.search();
  111. console.log('receive a message: ', message.body);
  112. },
  113. },
  114. computed: {
  115. ...mapState(['user']),
  116. pageTitle() {
  117. return `${this.$route.meta.title}`;
  118. },
  119. },
  120. metaInfo() {
  121. return { title: this.$route.meta.title };
  122. },
  123. };
  124. </script>
  125. <style lang="less" scoped>
  126. .icon {
  127. display: inline-block;
  128. font-size: 1.25rem;
  129. text-align: center;
  130. z-index: 100;
  131. }
  132. .out {
  133. white-space: nowrap;
  134. text-overflow: ellipsis;
  135. overflow: hidden;
  136. word-break: break-all;
  137. width: 150px;
  138. font-size: 16px;
  139. padding: 5px 0;
  140. }
  141. </style>