luohairen
2024-12-26 7379f2bcf71fe80d021eb7f2118991525e41ea7e
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
 
<template>
  <div>
    <el-dialog
      :visible.sync="fileDialogVisible"
      ref="formDialogRef"
      width="35%"
      append-to-body
      close-on-click-modal
      @close="closeDialog"
    >
      <template slot="title">
        <span style="padding-bottom: 18px">
          {{ isImportOrExport ? '请按照需求导出目标内容' : '请按照模板样式上传项目文件' }}
        </span>
      </template>
      <template slot="default">
        <div v-if="!isImportOrExport" class="dialog-content">
          <el-upload
            ref="uploadRef"
            class="upload-demo"
            :action="uploadUrl"
            :limit="1"
            :accept="accept"
            :headers="uploadHeaders"
            :disabled="uploadIsUploading"
            :on-progress="handleFileUploadProgress"
            :on-success="handleFileSuccess"
            :auto-upload="false"
            drag
          >
            <i class="el-icon-upload"></i>
            <div class="el-upload__text">请上传<em>Zip</em>文件,大小在<em>100M</em>以内</div>
          </el-upload>
          <span>仅允许导入zip格式文件。</span>
          <el-link type="primary" :underline="false" style="font-size: 12px; vertical-align: baseline" @click="handleDownloadFile">下载模板</el-link>
        </div>
        <div v-else-if="isImportOrExport" class="dialog-content">
          <el-button class="export-button" @click="handleDownloadTargetList">导出目标列表内容</el-button>
          <el-button class="export-button" @click="handleDownloadAllList">导出所有列表内容</el-button>
          <el-button class="export-button" @click="handleDownloadDetailList">导出目标项目详情</el-button>
          <el-button class="export-button" @click="handleDownloadAllList">导出所有项目详情</el-button>
        </div>
      </template>
      <template slot="footer">
        <div v-if="!isImportOrExport" class="dialog-footer">
          <el-button type="primary" @click="submitFileForm">确 定</el-button>
          <el-button @click="closeDialog">取 消</el-button>
        </div>
        <div v-else-if="isImportOrExport"></div>
      </template>
    </el-dialog>
  </div>
</template>
 
<script>
 
export default {
  name: 'FileDialog',
  props: {
    isImportOrExport: {
      type: Boolean,
      default: false
    },
    fileDialogVisible: {
      type: Boolean,
      default: false
    },
    currentColumns: {
      type: Array,
      default: function () {
        return [];
      }
    },
    dataIdList: {
      type: Array,
      default: function () {
        return [];
      }
    },
  },
  data() {
    return {
      queryParams: {},
      uploadRef: null,
      targetColumn: [],
      accept: `.zip`,
      uploadUrl: '/project/import',
      uploadHeaders: {},
      uploadIsUploading: false
    };
  },
  methods: {
    submit() {
      console.log("子组件submit")
    },
    handleFileUploadProgress() {
      this.uploadIsUploading = true;
    },
    handleFileSuccess(response, file) {
      this.uploadIsUploading = false;
      if (this.uploadRef) {
        this.uploadRef.handleRemove(file);
      }
      if (response.code === 200) {
        this.$emit('fileDialogCancel');
        this.$message({
          message: response.msg,
          type: 'success'
        });
      } else {
        this.$message.error(response.msg);
      }
    },
    handleDownloadFile() {
      this.download('/project/info/export/template', {}, `项目文件模板_${new Date().getTime()}.zip`)
    },
    submitFileForm() {
      if (this.uploadRef) {
        this.uploadRef.submit();
      }
    },
    closeDialog() {
      this.$emit('fileDialogCancel');
    },
    handleDownloadTargetList() {
      this.queryParams.fieldList = this.currentColumns.filter(item => item.visible).map(item =>item.id);
      this.queryParams.requireFile = false;
      this.download('project/info/export', {
          ...this.queryParams
        }, `项目库${new Date().getTime()}.xlsx`)
    },
    handleDownloadAllList() {
      this.queryParams.fieldList = this.currentColumns;
      this.queryParams.requireFile = false;
      this.download('project/info/export', {
        ...this.queryParams
      }, `项目库${new Date().getTime()}.xlsx`)
    },
    handleDownloadDetailList() {
      this.queryParams.dataIdList = this.dataIdList
      this.queryParams.requireFile = true;
      this.download('project/info/export', {
        ...this.queryParams
      }, `项目库${new Date().getTime()}.zip`)
    }
  },
  mounted() {
    this.uploadRef = this.$refs.uploadRef;
  },
  created() {
    this.isFileDialogVisible = this.fileDialogVisible;
  }
};
</script>
 
<style scoped lang="scss">
.dialog-content {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  height: 300px;
 
  .export-button {
    margin-left: 0;
    margin-bottom: 10px;
  }
}
.dialog-footer {
  display: flex;
  justify-content: center;
}
.upload-demo {
  width: 100%;
}
::v-deep  .el-upload{
  width: 100%;
}
::v-deep .el-upload .el-upload-dragger{
  width: 100%;
}
</style>