riku
2024-10-14 7e1d38f401555ac635c9ce10f63902d9a4c402e0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
<template>
  <div>
    <el-tabs v-model="activeName" type="card">
      <el-tab-pane v-for="item in ranges" :label="item" :name="item"> </el-tab-pane>
    </el-tabs>
    <div class="proList">
      <el-card class="card-style" shadow="hover">
        <el-descriptions v-loading="loading">
          <el-descriptions-item label="总出现次数">{{ curProList.length }}</el-descriptions-item>
          <!-- <el-descriptions-item label="复现率">{{ repeteRate }}%</el-descriptions-item> -->
        </el-descriptions>
        <!-- <el-descriptions v-loading="loading" column="3">
          <div v-for="pro in curProList">
            <el-descriptions-item>{{ pro.problemname }}</el-descriptions-item>
            <el-descriptions-item label="任务名称">{{ pro._stName }}</el-descriptions-item>
            <el-descriptions-item>
              <el-button link type="primary" @click="info(pro)">详情</el-button>
            </el-descriptions-item>
          </div>
        </el-descriptions> -->
        <el-table :data="curProList" style="width: 100%">
          <el-table-column type="index" width="50" />
          <el-table-column prop="problemname" label="问题"/>
          <el-table-column prop="_time" label="时间" width="250" />
          <el-table-column prop="操作" label="操作" width="180">
            <template v-slot="scope">
              <el-button link type="primary" @click="info(scope.row)">详情</el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-card>
      <el-dialog
        title="预览"
        v-model="proAddOrUpdDialogVisible"
        :before-close="proAddOrUpdDialogClose"
        width="80%"
      >
        <CompProblemAddOrUpd
          v-if="proAddOrUpdDialogVisible"
          :subtask="subtask"
          :topTask="topTask"
          :problem="previewPro"
          :readonly="true"
          ref="compProblemAddOrUpdRef"
        />
      </el-dialog>
    </div>
  </div>
</template>
<script>
import CompProblemAddOrUpd from './CompProblemAddOrUpd.vue';
import taskApi from '@/api/fysp/taskApi';
import { useCloned } from '@vueuse/core';
export default {
  computed: {
    // repeteRate() {
    //   return this.curProList.length !== 0 ? (this.curProList.length - 1) / this.subtaskCount * 1.0 : 0 
    // },
  },
  props: {
    problem: {
      type: Object,
      default: () => {}
    },
    topTask: {
      type: Object,
      default: () => {
        return {};
      }
    },
    subtask: {
      type: Object,
      default: () => {
        return {};
      }
    }
  },
  watch: {
    activeName: {
      handler(newObj, oldObj) {
        this.handleClick();
      }
    }
  },
  components: {
    CompProblemAddOrUpd
  },
  mounted() {
    console.log('subtask', this.subtask);
 
    this.deepCopyPro = useCloned(this.problem).cloned.value;
    this.getRecentPros();
  },
  data() {
    return {
      proAddOrUpdDialogVisible: false,
      previewPro: {},
      // 加载统计信息
      loading: false,
      // 时间和问题对象列表
      timeProMap: new Map(),
      curProList: [],
      activeName: '近三个月',
      ranges: ['近三个月', '近半年', '近一年'],
      deepCopyPro: {}
    };
  },
  methods: {
    // 转换为北京时间
    convertTime(time) {
      time.setHours(time.getHours);
      return time;
    },
    // 打开详情页面
    info(pro) {
      this.previewPro = pro;
      this.proAddOrUpdDialogVisible = true;
    },
    // 关闭详情弹窗
    proAddOrUpdDialogClose() {
      this.proAddOrUpdDialogVisible = false;
    },
    // 切换时间范围
    handleClick() {
      this.getRecentPros();
    },
    updateSubtask() {},
    generateQueryParam() {
      // 今天的日期
      const today = new Date();
      // 三个月前
      const threeMonthsAgo = new Date(today);
      threeMonthsAgo.setMonth(today.getMonth() - 3);
      // 计算半年前的日期
      const sixMonthsAgo = new Date(today);
      sixMonthsAgo.setMonth(today.getMonth() - 6);
      // 计算一年前的日期
      const oneYearAgo = new Date(today);
      oneYearAgo.setFullYear(today.getFullYear() - 1);
      console.log('today', this.$fm.formatYMDH(today));
      console.log('threeMonthsAgo', this.$fm.formatYMDH(threeMonthsAgo));
      console.log('sixMonthsAgo', this.$fm.formatYMDH(sixMonthsAgo));
      console.log('oneYearAgo', this.$fm.formatYMDH(oneYearAgo));
      return {
        startTime:
          this.activeName === '近三个月'
            ? this.$fm.formatYMDH(threeMonthsAgo)
            : this.activeName === '近半年'
              ? this.$fm.formatYMDH(sixMonthsAgo)
              : this.$fm.formatYMDH(oneYearAgo),
        endTime: this.$fm.formatYMDH(today),
        sceneId: this.deepCopyPro.sguid
      };
    },
    /**
     * 获取近期情况
     * */
    async getRecentPros() {
      this.loading = true;
      this.subtaskCount = 0
      // 获取子任务列表
      await taskApi.getSubtaskByScene(this.generateQueryParam()).then((subtasks) => {
        this.curProList = [];
        if (subtasks) {
          subtasks.forEach((subtask) => {
            // 获取问题列表
            this.getProBySubtask(subtask);
          });
        }
        
      });
      // 额外处理
      console.log('curr', this.curProList);
      this.curProList.sort((o1, o2) => o2.getTime() - o1.getTime());
      this.loading = false;
    },
    // 根据子任务获取里面的问题列表
    async getProBySubtask(subtask) {
      taskApi.getProBySubtask(subtask.stGuid).then((pros) => {
        if (pros) {
          pros.forEach((pro) => {
            if (pro.ptguid == this.deepCopyPro.ptguid) {
              pro._stName = subtask.stName;
              pro._time = this.$fm.formatYM(subtask.stPlanTime)
              this.curProList.push(pro);
            }
          });
        }
      });
    }
  }
};
</script>
<style scoped>
.problem-style {
  margin-bottom: 10px;
}
</style>