研发图纸文件管理系统-前端项目
he wei
2023-09-20 c0e36244c61614b5fd21eb73be1ceca09b2f7afb
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
<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>
        </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>
  </div>
</template>
 
<script>
import getWebUrl from "@/assets/js/tools/getWebUrl";
import { dwgReview } from "@/pages/workplace/apis";
// import { downloadLog } from "@/pages/system/logs/apis";
import { downLoadFileByFilePath } 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;
      },
    },
    // 类型 产品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: 140,
        scopedSlots: { customRender: "action" },
      },
    ];
    return {
      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;
    },
    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("操作失败");
        }
      });
    },
  },
  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>