zhangzengfei
2022-02-22 9466f8f5d714c8f72dbaff6ac3898b4d43c7c715
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
<template>
  <div class="clear" v-loading="loading" :element-loading-text="loadingText">
    <div class="head">
      <span class="t">请选择要清理的数据范围</span>
      <el-date-picker
        style="width: 100%"
        v-model="dataRange"
        type="daterange"
        align="right"
        size="small"
        range-separator="至"
        start-placeholder="开始日期"
        end-placeholder="结束日期"
        :picker-options="pickerOptions"
      >
      </el-date-picker>
    </div>
 
    <div class="desc">
      <div class="disk-img"></div>
      <div class="cap">
        <div class="cap-text">磁盘可用:{{ 21 }}%</div>
        <div class="cap-bar">
          <div class="inner-bar"></div>
        </div>
      </div>
 
      <el-button type="primary" @click="deleteData">数据清理</el-button>
 
      <div class="warm">
        <!-- <span class="icon iconfont" style="margin-right:5px">&#xe690;</span> -->
        <i class="iconfont icontishi-zhuyi"></i>
        <span class="text">请注意,按以上日期范围删除的数据不可恢复,立即生效,请谨慎操作!</span>
      </div>
    </div>
  </div>
</template>
 
<script>
import { deleteDate } from "@/api/system"
export default {
  data() {
    return {
      loading: false,
      loadingText: "",
      dataRange: [this.$moment().format("YYYY-MM-DD HH:mm:ss"), this.$moment().format("YYYY-MM-DD HH:mm:ss")],
      pickerOptions: {
        disabledDate(time) {
          var day = new Date()
          day.setTime(day.getTime() - 24 * 60 * 60 * 1000)
          return time.getTime() > day
        }
      }
    }
  },
  mounted() {},
 
  methods: {
    deleteData() {
      var timeRange = this.format(this.dataRange)
      var showStartTime = timeRange[0]
      var showEndTime = timeRange[1]
      this.$confirm(
        "提示:" +
          showStartTime +
          " 至 " +
          showEndTime +
          " 产生的全部数据将被删除,此操作立即生效,不可恢复,是否删除?",
        {
          center: true,
          cancelButtonClass: "comfirm-class-cancle",
          confirmButtonClass: "comfirm-class-sure"
        }
      )
        .then(() => {
          this.loading = true
          this.loadingText = "正在删除数据,请稍候!"
          deleteDate({
            startTime: showStartTime,
            endTime: showEndTime
          })
            .then((resp) => {
              if (resp.success) {
                this.$message({
                  type: "success",
                  message: "删除数据成功"
                })
                this.loading = false
              }
            })
            .catch((err) => {
              this.$message({
                type: "error",
                message: "删除数据失败!"
              })
              this.loading = false
            })
        })
        .catch(() => {})
    },
    format(array) {
      return [this.$moment(array[0]).format("YYYY-MM-DD"), this.$moment(array[1]).format("YYYY-MM-DD")]
    }
  }
}
</script>
<style lang="scss">
.all {
  width: 100%;
}
.clear {
  margin: 0 auto;
  padding: 20px;
  .head {
    height: 50px;
    background-color: rgba(248, 248, 248, 1);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: space-around;
    box-sizing: border-box;
    padding: 0 20px;
    width: 560px;
    margin: 0 auto;
    .t {
      font-size: 14px;
      min-width: 175px;
      text-align: left;
    }
 
    .el-range-editor--small.el-input__inner {
      border: none;
    }
    .el-range-editor--small .el-range-separator {
      line-height: 26px;
    }
  }
  .desc {
    margin-top: 50px;
    .disk-img {
      height: 100px;
      width: 100px;
      margin: 0 auto;
      margin-bottom: 10px;
      background-color: aquamarine;
    }
    .cap {
      height: 50px;
      margin: 0 auto;
      width: 160px;
      margin-bottom: 20px;
      .cap-bar {
        height: 8px;
        background: rgba(242, 242, 242, 1);
        //
        margin: 0 auto;
        border-radius: 2px;
        .inner-bar {
          background: #3a8120;
          width: 40%;
          height: 100%;
          border-radius: 2px;
        }
      }
      .cap-text {
        text-align: right;
        height: 25px;
        line-height: 25px;
        font-size: 12px;
      }
    }
    .el-button--primary {
      width: 200px;
      font-size: 15px;
    }
    .warm {
      line-height: 30px;
      height: 30px;
      margin-top: 10px;
      display: flex;
      align-items: center;
      justify-content: center;
      .iconfont {
        font-size: 16px;
 
        color: #e99038;
        margin-right: 5px;
      }
      .text {
        color: rgba(187, 187, 187, 1);
        font-size: 14px;
      }
    }
  }
}
</style>