spring
2025-04-02 b34e4348df3f9f697fcb4da64ee7ff11deca3170
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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
<template>
  <!-- 文件清单 -->
  <div class="file-list" style="height: 100%;">
    <div class="search">
      <div class="search_thing">
        <div class="search_label">文件名称:</div>
        <div class="search_input"><el-input size="small" placeholder="请输入" clearable v-model="componentData.entity.name"
            @keyup.enter.native="refreshTable()"></el-input></div>
      </div>
      <div class="search_thing">
        <div class="search_label">文件状态:</div>
        <div class="search_input">
          <el-select v-model="componentData.entity.state" size="small" @change="refreshTable()">
            <el-option :label="item.label" :value="item.value" v-for="(item,index) in fileState" :key="index"></el-option>
          </el-select>
        </div>
      </div>
      <div class="search_thing" style="padding-left: 30px;">
        <el-button size="small" @click="refresh()">重 置</el-button>
        <el-button size="small" type="primary" @click="refreshTable()">查 询</el-button>
      </div>
      <div class="btns" style="padding-left: 30px;">
        <el-upload :action="action" :multiple="false"
        accept='.xls,.xlsx' :headers="headers" :on-change="beforeUpload"
        :on-error="onError" ref='upload' v-if="addPower" :on-success="handleSuccessUp" :show-file-list="false">
        <el-button size="small" type="primary" :loading="upLoading">导入</el-button></el-upload>
      </div>
    </div>
    <div class="table">
      <ValueTable ref="ValueTable" :url="$api.manageDocumentList.pageManageDocumentList"
        :componentData="componentData" :upUrl="$api.manageDocumentList.doManageDocumentList" :delUrl="$api.manageDocumentList.delManageDocumentList" :key="upIndex"/>
    </div>
    <el-dialog
      title="上传"
      :visible.sync="addDialogVisible"
      width="1000px" top="3vh">
      <UpPdfStamp ref="UpPdfStamp" v-if="addDialogVisible" @uploadPDF="uploadPDF" :isUpFile="true" @uploadPDFErr="uploadPDFErr" style="max-height: 85vh;overflow-y: auto;"></UpPdfStamp>
      <span slot="footer" class="dialog-footer">
        <el-button @click="addDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="handleAdd" v-loading="addLoading">确 定</el-button>
      </span>
    </el-dialog>
    <el-dialog
      title="查看附件"
      :visible.sync="lookDialogVisible"
      width="800px" top="5vh" fullscreen>
      <filePreview v-if="lookDialogVisible" :fileUrl="javaApi+'/word/'+currentInfo.url"
      :currentFile="{}" style="height: 90vh;overflow-y: auto;"/>
    </el-dialog>
  </div>
</template>
 
<script>
import ValueTable from '../../tool/value-table.vue'
import UpPdfStamp from '../../tool/upPdfStamp.vue'
import filePreview from '../../tool/file-preview.vue'
export default {
  components: {
    ValueTable,
    UpPdfStamp,
    filePreview,
  },
  data() {
    return {
      addDialogVisible:false,
      lookDialogVisible:false,
      addPower:false,
      upLoading:false,
      addLoading:false,
      componentData: {
        entity: {
          name: null,
          state: null,
          orderBy: {
            field: 'createTime',
            order: 'desc'
          }
        },
        isIndex: true,
        showSelect: false,
        select: false,
        do: [{
          id: 'update',
          font: '编辑',
          type: 'text',
          method: 'doDiy',
          field:[]
        },
        {
          id: 'handleUp',
          font: '上传',
          type: 'text',
          method: 'handleUp'
        },
        {
          id: 'handleDown',
          font: '下载',
          type: 'text',
          method: 'handleDown'
        },
        {
          id: 'handleLook',
          font: '查看附件',
          type: 'text',
          method: 'handleLook'
        }, {
          id: 'delete',
          font: '删除',
          type: 'text',
          method: 'doDiy'
        },],
        tagField: {
          state:{
            select: []
          },
          type:{
            select: []
          },
        },
        selectField: {
          state:{
            select: []
          },
          type:{
            select: []
          },
        },
        datePicker:['effectiveDate'],
        addUpload:['signatoryUrl'],
        requiredAdd: ['documentCode'],
        requiredUp: ['documentCode'],
        needSort: [],
        inputType: ''
      },
      entityCopy: {},
      upIndex: 0,
      currentInfo:{},
      fileType:[],
      fileState:[],
    }
  },
  // 用于上传文件的信息
  computed: {
    headers() {
      return {
        'token': sessionStorage.getItem('token')
      }
    },
    action() {
      return this.javaApi +this.$api.manageDocumentList.exportManageDocumentList
    }
  },
  mounted() {
    this.entityCopy = this.HaveJson(this.componentData.entity);
    this.getPower()
    this.selectEnumByCategory()
  },
  methods: {
    // 下载文件
    handleDown(row) {
      if(!row.url) return this.$message.warning('文件未上传')
      let url = this.javaApi+'/word/'+row.url
      const link = document.createElement('a');
      link.href = url;
      link.click();
    },
    // 查看文件
    handleLook(row){
      if(!row.url) return this.$message.warning('文件未上传')
      this.currentInfo = row
      this.lookDialogVisible = true
    },
    getPower(){
      let power = JSON.parse(sessionStorage.getItem('power'))
      let up = false
      let upFile = false
      let add = false
      for (var i = 0; i < power.length; i++) {
        if (power[i].menuMethod == 'doManageDocumentList') {
          up = true
        }
        if (power[i].menuMethod == 'exportManageDocumentList') {
          add = true
        }
        if (power[i].menuMethod == 'uploadFileManageDocumentList') {
          upFile = true
        }
      }
      if (!upFile) {
        this.componentData.do.splice(1, 1)
      }
      if (!up) {
        this.componentData.do.splice(0, 1)
      }
      this.addPower = add
    },
    refreshTable() {
      this.$refs['ValueTable'].selectList()
    },
    refresh() {
      this.componentData.entity = this.HaveJson(this.entityCopy)
      this.upIndex++
      this.refreshTable()
    },
    // 上传文件
    handleUp(row) {
      this.currentInfo = row
      this.addDialogVisible = true;
    },
    // 提交上传
    handleAdd(){
      this.addLoading = true
      this.$refs['UpPdfStamp'].generatePDF()
    },
    uploadPDFErr(){
      this.addLoading = false
    },
    beforeUpload(file) {
      if (file.size > 1024 * 1024 * 10) {
        this.$message.error('上传文件不超过10M');
        this.$refs.upload.clearFiles()
        return false;
      } else {
        // this.upLoading = true;
        return true;
      }
    },
    onError(err, file, fileList) {
      this.$message.error('上传失败')
      this.$refs.upload.clearFiles()
    },
    handleSuccessUp(response) {
      this.upLoading = false;
      if (response.code == 200) {
        this.$message.success('上传成功');
        this.refreshTable()
      }
    },
    selectEnumByCategory() {
      this.$axios.post(this.$api.enums.selectEnumByCategory, {
        category: "文件类别"
      }).then(res => {
        this.fileType = res.data
        this.componentData.tagField.type.select = this.fileType
        this.componentData.selectField.type.select = this.fileType
      })
      this.$axios.post(this.$api.enums.selectEnumByCategory, {
        category: "文件状态"
      }).then(res => {
        this.fileState = res.data
        this.componentData.tagField.state.select = res.data
        this.componentData.selectField.state.select = res.data
      })
    },
    async uploadPDF(pdfBlob) {
      const formData = new FormData();
      formData.append('file', pdfBlob, this.fileName+'.pdf'); // 文件字段
      formData.append('id', this.currentInfo.id); // 文件名字段
 
      let res = await this.$axios.post(this.$api.manageDocumentList.uploadFileManageDocumentList, formData,{
        headers: {
            'Content-Type': 'multipart/form-data;'
        },
        noQs: true
      })
      this.addLoading = false
      if(res.code==200){
        this.$message({ message: '上传成功', type: 'success' });
        this.addDialogVisible = false;
        this.refreshTable()
        return true
      }else{
        this.$message({ message: '上传失败', type: 'error' });
        return false
      }
    }
  }
}
</script>
 
<style scoped>
.title {
    height: 60px;
    line-height: 60px;
  }
  .search {
    background-color: #fff;
    height: 40px;
    display: flex;
    align-items: center;
    position: relative;
  }
 
  .search_thing {
    width: 350px;
    display: flex;
    align-items: center;
  }
 
  .search_label {
    width: 110px;
    font-size: 14px;
    text-align: right;
  }
 
  .search_input {
    width: calc(100% - 110px);
  }
 
  .table {
    background-color: #fff;
    width: calc(100% - 40px);
    height: calc(100% - 60px - 80px);
    padding: 20px;
  }
  .btns{
    position: absolute;
    right: 20px;
    top: 5px;
  }
</style>