研发图纸文件管理系统-前端项目
he wei
2022-08-31 e22836691999f9983d9fc4ff32e2d2d69d860607
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
<template>
  <div class="main">
    <div class="inner" ref="wraper">
      <a-spin class="" :spinning="spinning" tip="拼命加载中...">
        <a-card>
          <advance-table
            ref="table"
            class="doc-center-table"
            :data-source="dataSource"
            :columns="columns"
            title=""
            row-key="parentModel"
            @search="onSearch"
            @refresh="onRefresh"
            @reset="onReset"
            :format-conditions="true"
            :scroll="{ x: 400, y }"
            :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="title">
              <span class="title">软件中心</span>
            </template>
            <template slot="action" slot-scope="{ record }">
              <template v-if="downloadFlag">
                <a @click="download(record)">下载</a>
              </template>
            </template>
          </advance-table>
        </a-card>
      </a-spin>
    </div>
  </div>
</template>
 
<script>
import AdvanceTable from "@/components/table/advance/AdvanceTable";
 
import { getList, downLoadSoftware } from "./apis";
import { mapGetters } from "vuex";
 
export default {
  name: "",
  data() {
    return {
      spinning: false,
      loading: false,
      pageCurr: 1,
      pageSize: 10,
      total: 0,
      y: 400,
      update: -1,
      conditions: {},
      columns: [
        {
          title: "关联产品母料型号",
          dataIndex: "parentModel",
          key: "parentModel",
          align: "center",
          width: 180,
          searchAble: true,
        },
        {
          title: "软件名称",
          dataIndex: "softwareName",
          key: "softwareName",
          align: "center",
          noSearch: true,
          width: 160,
        },
        {
          title: "操作",
          dataIndex: "operation",
          key: "operation",
          align: "center",
          width: 168,
          fixed: "right",
          scopedSlots: { customRender: "action" },
        },
      ],
      dataSource: [],
    };
  },
  components: {
    AdvanceTable,
  },
  methods: {
    onSearch(conditions, searchOptions) {
      // console.log(conditions);
      // console.log(searchOptions);
      this.pageCurr = 1;
      this.conditions = conditions;
      this.searchData();
    },
    onPageChange(page, pageSize) {
      this.pageCurr = page;
      this.pageSize = pageSize;
      this.searchData();
    },
    onSizeChange(current, size) {
      this.pageCurr = 1;
      this.pageSize = size;
      this.searchData();
    },
    onRefresh(conditions) {
      this.conditions = conditions;
      this.searchData();
    },
    onReset(conditions) {
      this.conditions = conditions;
      this.searchData();
    },
    searchData() {
      const { pageCurr, pageSize, conditions } = this;
      let params = {};
      Object.keys(conditions).forEach((v) => {
        params[v] = conditions[v];
      });
      let data = {
        pageSize,
        pageCurr,
        ...params,
      };
      getList(pageCurr, pageSize, params).then((res) => {
        res = res.data;
        console.log(res);
        let data = [];
        let total = 0;
        if (res.code && res.data) {
          data = res.data2.list;
          total = res.data2.total;
        }
        this.dataSource = data;
        this.total = total;
        if (-1 == this.update) {
          this.update = Math.random();
        }
      });
    },
    download(obj) {
      const { parentModel, softwareName } = obj;
      downLoadSoftware(softwareName).then((res) => {
        console.log(res, "===========");
        let { headers, data, status } = res;
        if (200 == status && data) {
          let url = window.URL.createObjectURL(data);
          const matchRes = /filename=(.*)/.exec(headers["content-disposition"]);
          const fileName = matchRes ? decodeURI(matchRes[1].trim()) : "未知文件名.zip";
          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);
        } else {
          this.$message.error("操作失败");
        }
      });
    },
    resize() {
      setTimeout(() => {
        this.update = Math.random();
      }, 200);
    },
  },
  watch: {
    update(n) {
      if (-1 != n) {
        // this.$nextTick(() => {
        //   const table = this.$refs.table;
        //   const header = document.querySelectorAll(
        //     ".doc-center-table .ant-table-header"
        //   )[0].clientHeight;
        //   const bar = document.querySelectorAll(".header-bar")[0].clientHeight;
        //   if (table.fullScreen) {
        //     this.y = table.$el.clientHeight - bar - header - 64;
        //   } else {
        //     const wraper = this.$refs.wraper.clientHeight;
        //     const card = document.querySelectorAll(".ant-card-body")[0];
        //     const { paddingBottom, paddingTop } = getComputedStyle(card, null);
        //     const h =
        //       wraper -
        //       header -
        //       64 -
        //       bar -
        //       parseInt(paddingBottom) -
        //       parseInt(paddingTop);
        //     // console.log(h, "h",wraper, header, bar );
        //     this.y = h;
        //   }
        // });
      }
    },
  },
  computed: {
    ...mapGetters("account", ["downloadFlag"]),
  },
  mounted() {
    this.searchData();
    window.addEventListener("resize", this.resize);
  },
  destroyed() {
    window.removeEventListener("resize", this.resize);
  },
};
</script>
 
<style scoped lang="less">
.main {
  height: 100%;
  position: relative;
  .inner {
    position: absolute;
    left: 0;
    top: 0;
    right: 0;
    bottom: 0;
  }
}
/deep/table {
  table-layout: fixed;
}
</style>