马宇豪
2024-04-02 d91fd1557ebed3e9bcb8c051c71b9d41c0e36eef
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
<template>
    <div class="home-container">
        <div style="height: 100%">
          <div class="homeCard">
            <div class="main-card">
            <el-row class="cardTop">
              <el-col :span="12" class="mainCardBtn">
                <el-button type="primary" icon="Plus" size="default" @click="openDialog('add',{})">新增</el-button>
              </el-col>
            </el-row>
            <el-table :data="reportData" style="width: 100%" height="calc(100% - 48px)" :header-cell-style="{ background: '#fafafa' }">
              <el-table-column prop="id" label="id" show-overflow-tooltip></el-table-column>
              <el-table-column prop="createTime" label="上报时间" show-overflow-tooltip></el-table-column>
              <el-table-column prop="craftName" label="工艺名称" show-overflow-tooltip></el-table-column>
              <el-table-column prop="craftContent" label="工艺简介" show-overflow-tooltip></el-table-column>
              <el-table-column prop="mainProdEquip" label="主要生产设备" show-overflow-tooltip></el-table-column>
              <el-table-column prop="keyParts" label="重点部位" show-overflow-tooltip></el-table-column>
              <el-table-column prop="hazardCode" label="重大危险源" show-overflow-tooltip></el-table-column>
              <el-table-column prop="msds" label="涉及的危险化学品" show-overflow-tooltip></el-table-column>
              <el-table-column prop="hazardCharacteristic" label="工艺危险特点" show-overflow-tooltip></el-table-column>
              <el-table-column prop="parameterIndex" label="重点监控工艺参数指标" show-overflow-tooltip></el-table-column>
              <el-table-column prop="controlMean" label="现有安全控制手段" show-overflow-tooltip></el-table-column>
              <el-table-column prop="craftDraw" label="工艺图纸" show-overflow-tooltip>
                <template #default="scope">
<!--                  <el-button v-if="scope.row.craftDraw !== ''" v-for="item in scope.row.craftDraw.split(',')" size="small" text type="primary" @click="openFile(item)">查看</el-button>-->
                  <div v-if="scope.row.craftDraw !== ''">
                    <el-image
                        v-for="(item,index) in scope.row.craftDraw.split(',')"
                        style="width: 50px; height: 50px"
                        :src="item"
                        fit="cover"
                        :preview-teleported= true
                    />
                  </div>
 
                </template>
              </el-table-column>
              <el-table-column prop="reactionType" label="反应类型" show-overflow-tooltip></el-table-column>
              <el-table-column prop="keyMonitorUnit" label="重点监控单元" show-overflow-tooltip></el-table-column>
              <el-table-column label="操作" width="140">
                  <template #default="scope">
                    <el-button size="small" text type="primary" @click="openDialog('update',scope.row)">重新上报</el-button>
                    <el-button style="color: red" size="small" text type="primary" @click="onRowDel(scope.row)">删除</el-button>
                  </template>
              </el-table-column>
            </el-table>
            <div class="pageBtn">
              <el-pagination @size-change="onHandleSizeChange" small="false" @current-change="onHandleCurrentChange" class="page-position" :pager-count="5" :page-sizes="[10, 20, 30]" v-model:current-page="listQuery.pageIndex" background v-model:page-size="listQuery.pageSize" layout="total, sizes, prev, pager, next, jumper" :total="total"> </el-pagination>
            </div>
            </div>
          </div>
        </div>
        <add-report ref="reportRef" @refresh="getData"></add-report>
    </div>
</template>
 
<script lang="ts">
import { toRefs, reactive, onMounted, ref, defineComponent } from 'vue'
import { ElMessageBox, ElMessage } from 'element-plus'
import { Plus } from '@element-plus/icons-vue'
import addReport from "./components/addReport.vue"
import {judgeReportApi} from "/@/api/dataUpload/saftyBaseInfo/judgeReport";
import axios from "axios";
import Cookies from "js-cookie";
 
// 定义接口来定义对象的类型
interface TableDataRow {
  id: number|null
  reportTime: string
  craftName: string
  craftContent: string
  mainProdEquip: string
  keyParts: string
  hazardCode: string
  msds: string
  hazardCharacter: string
  parameterIndex: string
  controlMean: string
  craftDraw: string
  reactionType: string
  keyMonitorUnit: string
}
interface TableDataState {
  reportData: [],
  listQuery: {
    searchParams: {}
    pageIndex: number
    pageSize: number
  }
  total: null | number
  baseUrl: string
}
 
export default defineComponent({
    name: 'productionInfo',
    components: {addReport },
    setup() {
      const reportRef= ref();
      const state = reactive<TableDataState>({
        reportData: [],
        listQuery: {
          searchParams: {},
          pageIndex: 1,
          pageSize: 10
        },
        total: null,
        baseUrl: import.meta.env.VITE_API_URL
      });
 
      // 页面加载时
      onMounted(() => {
        getData()
        console.log(state.baseUrl)
      });
 
      const getData = async ()=>{
        const res = await judgeReportApi().getProductList(state.listQuery)
        if(res.data.code == 200){
          state.reportData = res.data.data
          state.total = res.data.total
        }else{
          ElMessage({
            type: 'warning',
            message: res.data.msg
          })
        }
      }
 
      const openDialog=(type:string,data:object)=>{
        reportRef.value.open(type,data)
      }
 
      // 删除用户
      const onRowDel = (row: TableDataRow) => {
          ElMessageBox.confirm(`此操作将永久删除账户名称:“${row.craftName}”,是否继续?`, '提示', {
              confirmButtonText: '确认',
              cancelButtonText: '取消',
              type: 'warning'
          })
              .then(async () => {
                const res = await judgeReportApi().delProduct({ids: [row.id]})
                if(res.data.code == 200){
                  ElMessage({
                    type: 'success',
                    message: '删除成功'
                  })
                  await getData()
                }else{
                  ElMessage({
                    type: 'warning',
                    message: res.data.msg
                  })
                }
              })
              .catch(() => {});
      };
      // 分页改变
      const onHandleSizeChange = (val: number) => {
          state.listQuery.pageSize = val;
          getData()
      };
      // 分页改变
      const onHandleCurrentChange = (val: number) => {
          state.listQuery.pageIndex = val;
          getData()
      };
 
      const openFile=(file: string)=>{
        axios.get(import.meta.env.VITE_API_URL + file,{headers:{'Content-Type': 'application/json','Authorization': `${Cookies.get('token')}`,'uid':`${Cookies.get('uid')}`},responseType: 'blob'}).then(res=>{
          if (res) {
            const link = document.createElement('a')
            let blob = new Blob([res.data],{type: res.data.type})
            link.style.display = "none";
            link.href = URL.createObjectURL(blob); // 创建URL
            window.open(link.href)
          } else {
            ElMessage({
              type: 'warning',
              message: '文件读取失败'
            });
          }
        })
      }
 
      return {
        reportRef,
        openDialog,
        openFile,
        getData,
        onRowDel,
        onHandleSizeChange,
        onHandleCurrentChange,
        ...toRefs(state)
      };
    }
});
</script>
<style lang="scss" scoped>
.home-container {
  height: calc(100vh - 144px);
  box-sizing: border-box;
  overflow: hidden;
  .demo-tabs {
    width: 100%;
    height: 100%;
 
    &::v-deep(.el-tabs__content) {
      height: calc(100% - 60px);
    }
 
    .el-tab-pane {
      height: 100%;
    }
  }
  .homeCard {
    width: 100%;
    padding: 20px;
    box-sizing: border-box;
    background: #fff;
    border-radius: 4px;
 
    .main-card {
      width: 100%;
      height: 100%;
      .cardTop {
        display: flex;
        align-items: center;
        justify-content: space-between;
        margin-bottom: 20px;
        .mainCardBtn {
          margin: 0;
        }
      }
      .pageBtn {
        height: 60px;
        display: flex;
        align-items: center;
        justify-content: right;
 
        .demo-pagination-block + .demo-pagination-block {
          margin-top: 10px;
        }
        .demo-pagination-block .demonstration {
          margin-bottom: 16px;
        }
      }
    }
    &:last-of-type {
      height: calc(100% - 100px);
    }
  }
  .el-row {
    display: flex;
    align-items: center;
    margin-bottom: 20px;
    &:last-child {
      margin-bottom: 0;
    }
    .grid-content {
      align-items: center;
      min-height: 36px;
    }
 
    .topInfo {
      display: flex;
      align-items: center;
      font-size: 16px;
      font-weight: bold;
 
      & > div {
        white-space: nowrap;
        margin-right: 20px;
      }
    }
  }
  .el-card {
    border: 0;
  }
}
</style>