研发图纸文件管理系统-前端项目
he wei
2023-12-22 198defdf3fbc30bbf5d394dfbe7510251b0e578d
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
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
<template>
  <div class="">
    <a-table
      ref="aTable"
      size="small"
      :scroll="{ y }"
      bordered
      :columns="columns"
      :data-source="dataSource"
      :pagination="false"
      :rowKey="(record, index) => index"
      :rowClassName="(record) => (1 == record.lockFlag ? 'is-lock' : '')"
    >
      <template slot="action" slot-scope="text, record">
        <div v-if="record.url">
          <a
            v-if="
              !record.lockFlag &&
              ((record.fileType == 'dwg' && canViewDoc) ||
                (record.fileType != 'dwg' && canViewOther))
            "
            @click="view(record)"
            >预览</a
          >
          <template
            v-if="
              ((record.fileType == 'dwg' && canDownloadDoc) ||
                (record.fileType != 'dwg' && canDownloadOther)) &&
              !record.lockFlag
            "
          >
            <a-divider type="vertical"></a-divider>
            <a @click="downloadReason(record)">下载</a>
          </template>
          <template v-if="canLockOther && (id || productId)">
            <a-divider v-if="!record.lockFlag" type="vertical"></a-divider>
            <a @click="lock(record)">{{ record.lockFlag ? "解锁" : "锁定" }}</a>
          </template>
          <template v-if="isOwnerDwg(record)">
            <a-divider type="vertical"></a-divider>
            <a @click="history(record)">历史</a>
          </template>
        </div>
      </template>
    </a-table>
    <a-modal
      :width="600"
      :visible="previewVisible"
      :footer="null"
      @cancel="handleCancel"
    >
      <img alt="example" style="width: 100%" :src="imgUrl" />
    </a-modal>
    <a-modal
      :width="400"
      :visible="reasonVisible"
      title="操作原因"
      :destroyOnClose="true"
      :maskClosable="false"
      @cancel="reasonCancel"
      @ok="reasonOk"
    >
      <a-form-model-item ref="name" label="操作原因">
        <a-input
          type="textarea"
          v-model="reason"
          placeHolder="请输入操作原因"
        />
      </a-form-model-item>
    </a-modal>
    <download-reason
      :reason-visible.sync="downloadReasonVisible"
      v-if="downloadReasonVisible"
      @ok="downloadReasonOk"
    ></download-reason>
    <a-modal
      :visible="dwgHisVisible"
      title="物料图纸历史"
      :width="860"
      :destroyOnClose="true"
      @cancel="dwgHisClose"
    >
      <a-table
        ref="table"
        :columns="dwgColumns"
        :dataSource="dwgDataSource"
        :scroll="{ x: 400, y1 }"
        :row-key="(record, index) => index"
        :pagination="{
          current: pageCurr,
          pageSize: pageSize,
          total: total,
          showSizeChanger: true,
          showLessItems: true,
          showQuickJumper: true,
          pageSizeOptions: ['10', '20', '50', '100'],
          showTotal: (total, range) =>
            `第 ${range[0]}-${range[1]} 条,总计 ${total} 条`,
          onChange: onPageChange,
          onShowSizeChange: onSizeChange,
        }"
      >
        <template slot="action" slot-scope="text, record">
          <a @click="dwgReview(record.url)">预览</a>
        </template>
      </a-table>
      <template v-slot:footer>
        <a-button @click="dwgHisClose">关闭</a-button>
      </template>
    </a-modal>
  </div>
</template>
 
<script>
import escapeRegExp from '@/assets/js/tools/escapeRegExp';
import getWebUrl from "@/assets/js/tools/getWebUrl";
import { dwgReview } from "@/pages/workplace/apis";
// import { downloadLog } from "@/pages/system/logs/apis";
import { downLoadFileByFilePath, getDwgHisById } from "@/assets/js/apis";
import { updateAttachLock } from "@/pages/resourceManage/materialsCenter/apis";
import { updateProductLock } from "@/pages/resourceManage/product/details/apis";
import checkPermit from "@/assets/js/tools/checkPermit";
import DownloadReason from "@/pages/components/downloadReason";
import PERMITS from "@/assets/js/const/const_permits";
import { mapGetters } from "vuex";
export default {
  name: "",
  components: {
    DownloadReason,
  },
  props: {
    list: {
      type: Array,
      default() {
        return [];
      },
    },
    info: {
      type: Object,
      default() {
        return null;
      },
    },
    subModel: {
      type: String,
      default: "",
    },
    // 类型 产品12 物料13
    type: {
      type: Number,
      required: true,
    },
    oprateVersion: {
      type: Number,
      default: 0,
    },
  },
  data() {
    const columns = [
      {
        title: "文件名称",
        dataIndex: "fileName",
        align: "center",
        width: 200,
      },
      {
        title: "文件类型",
        dataIndex: "fileType",
        align: "center",
        width: 100,
      },
      {
        title: "操作原因",
        dataIndex: "localReason",
        align: "center",
      },
      {
        title: "操作",
        dataIndex: "operation",
        key: "operation",
        align: "center",
        width: 200,
        scopedSlots: { customRender: "action" },
      },
    ];
    const dwgColumns = [
      {
        title: "文件名称",
        dataIndex: "fileName",
        align: "center",
        width: 200,
      },
      {
        title: "操作",
        dataIndex: "operation",
        key: "operation",
        align: "center",
        width: 140,
        scopedSlots: { customRender: "action" },
      },
    ];
    return {
      dwgHisVisible: false,
      dwgColumns,
      dwgDataSource: [],
      pageCurr: 1,
      pageSize: 10,
      total: 0,
      y1: 400,
      downloadUrl: "",
      downloadReasonVisible: false,
      reason: "",
      reasonVisible: false,
      currObj: null,
      columns,
      y: 500,
      imgUrl: "",
      previewVisible: false,
      webUrl: getWebUrl(),
    };
  },
  methods: {
    handleClick() {
      this.$emit("success", this.list);
    },
    view(obj) {
      switch (obj.fileType) {
        // 图片
        case "bmp":
        case "jpg":
        case "jpeg":
        case "png":
          this.imgUrl = this.webUrl + obj.url;
          this.previewVisible = true;
          break;
        case "pdf":
          window.open(this.webUrl + obj.url);
          break;
        case "doc":
        case "docx":
        case "dwg":
          this.dwgReview(obj.url);
          break;
        default:
          this.$message.warn("该类型文件暂不支持预览");
          break;
      }
    },
    handleCancel() {
      this.previewVisible = false;
    },
    dwgHisClose() {
      this.dwgHisVisible = false;
    },
    dwgReview(url) {
      let loading = this.$layer.loading();
      dwgReview(url)
        .then((res) => {
          let { code, data, msg } = res.data;
          if (code && data) {
            window.open(this.webUrl + data);
          } else {
            this.$message.error(msg);
          }
          this.$layer.close(loading);
        })
        .catch((error) => {
          console.log(error);
          this.$layer.close(loading);
        });
    },
    downloadReason(record) {
      this.downloadUrl = record.url;
      this.downloadReasonVisible = true;
    },
    downloadReasonOk(data) {
      this.downloadLog(this.downloadUrl, data);
    },
    downloadLog(url, reason) {
      let reg = /(.*\\+)*(.*)$/;
      let fileName = url.match(reg)[2];
      downLoadFileByFilePath(
        url,
        reason,
        this.info.oprateInfo,
        this.oprateVersion,
        this.type
      ).then((res) => {
        let { data, status } = res;
        if (200 == status && data) {
          let url = window.URL.createObjectURL(data);
          let link = document.createElement("a");
          link.style.display = "none";
          link.href = url;
          link.download = fileName;
          document.body.appendChild(link);
          link.click();
          document.body.removeChild(link);
          window.URL.revokeObjectURL(url);
          // downloadLog(parentModel, subModel);
        } else {
          this.$message.error("下载失败");
        }
      });
    },
    lock(obj) {
      this.currObj = obj;
      this.reason = "";
      this.reasonVisible = true;
    },
    reasonCancel() {
      this.reasonVisible = false;
    },
    reasonOk() {
      if (!this.id && !this.productId) {
        this.$message.error("无效的ID");
        return false;
      }
      let obj = this.currObj;
      let lockFlag = !obj.lockFlag * 1;
      let isProd = !!this.productId;
      let params = {
        attachName: obj.fileName,
        localReason: this.reason,
        lockFlag,
        materialId: this.id ? this.id : undefined,
        productId: this.productId ? this.productId : undefined,
      };
      let update = isProd ? updateProductLock : updateAttachLock;
      update([params]).then((res) => {
        const { code, data, msg } = res.data;
        if (code && data) {
          this.$message.success("操作成功");
          obj.lockFlag = lockFlag;
          obj.localReason = this.reason;
          this.reasonVisible = false;
        } else {
          this.$message.error("操作失败");
        }
      });
    },
    isOwnerDwg(record) {
      if (!this.subModel) {
        return false;
      }
      let reg = new RegExp("^" + escapeRegExp(this.subModel), "i");
      return reg.test(record.fileName) && record.fileType == "dwg";
    },
    history(record) {
      this.getList();
      this.dwgHisVisible = true;
    },
    getList() {
      getDwgHisById(this.id, this.pageCurr, this.pageSize)
        .then((res) => {
          let { code, data, data2 } = res.data;
          let list = [];
          let total = 0;
          if (code && data) {
            // console.log(data);
            let reg = /(.*\\+)*(.*)$/;
            list = data2.list.map((item) => {
              let url = item.dwgUrl;
              let fileName = url.match(reg)[2];
              return {
                fileName,
                url,
              };
            });
            total = data2.total;
          }
          this.dwgDataSource = list;
          this.total = total;
        })
        .catch((err) => {
          console.log(err);
        });
    },
    onPageChange(page, pageSize) {
      this.pageCurr = page;
      this.pageSize = pageSize;
      this.getList();
    },
    onSizeChange(current, size) {
      this.pageCurr = 1;
      this.pageSize = size;
      this.getList();
    },
  },
  computed: {
    dataSource() {
      let attachLocks = this.attachLocks;
      let reg = /(.*\\+)*(.*)$/;
      return this.list.map((item) => {
        let fileName = item.match(reg)[2];
        let arr = fileName.split(".");
        let fileType = arr.length ? arr[arr.length - 1].toLowerCase() : "";
        let localReason = "";
        let lockFlag = 0;
        attachLocks.forEach((v) => {
          if (v.attachName == fileName) {
            localReason = v.localReason;
            lockFlag = v.lockFlag;
          }
        });
        return {
          fileName,
          fileType,
          url: item,
          localReason,
          lockFlag,
        };
      });
    },
    id() {
      return this.info ? this.info.id : 0;
    },
    productId() {
      return this.info ? this.info.productId : 0;
    },
    attachLocks() {
      return this.info ? this.info.attachLocks : [];
    },
    ...mapGetters("account", ["permits"]),
    canDownloadOther() {
      return checkPermit(PERMITS.downloadOther, this.permits);
    },
    canDownloadDoc() {
      return checkPermit(PERMITS.downloadDoc, this.permits);
    },
    canLockOther() {
      return checkPermit(PERMITS.lockOther, this.permits);
    },
    canViewOther() {
      return checkPermit(PERMITS.viewOther, this.permits);
    },
    canViewDoc() {
      return checkPermit(PERMITS.viewDoc, this.permits);
    },
  },
  mounted() {},
};
</script>
 
<style lang="less" scoped>
/deep/.is-lock td {
  background: #ddd;
}
</style>