10.10综合交易所原始源码-管理后台
admin
2026-01-06 a3cc41349752d6fb067df2a58e4e4b723a915f21
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
<template>
  <div>
    <p>笔记附件列表({{ files.length }})</p>
    <div class="annex-box lum-scrollbar">
      <input ref="uploads" type="file" @change="uploadAnnex" />
      <div class="annex-main">
        <p v-show="files.length == 0" class="empty-text">
          暂无附件
        </p>
 
        <div v-for="(file, i) in files" :key="file.id" class="file-item">
          <div class="suffix">{{ file.suffix }}</div>
          <div class="content">
            <div class="filename">{{ file.original_name }}</div>
            <div class="filetool">
              <span>{{ formateTime(file.created_at) }}</span>
              <span class="size">
                {{ formateSize(file.size) }}
              </span>
              <div class="tools">
                <i class="el-icon-download" @click="downloadAnnex(file.id)" />
                <i class="el-icon-delete" @click="deleteAnnex(file.id, i)" />
              </div>
            </div>
          </div>
        </div>
      </div>
 
      <div class="annex-footer">
        <p class="notice-text">最多可支持上传{{ maxNum }}个附件</p>
        <el-button
          type="primary"
          size="small"
          icon="el-icon-upload"
          :disabled="files.length >= maxNum"
          :loading="loadStatus"
          @click="$refs.uploads.click()"
          >{{ loadStatus ? '上传中...' : '上传附件' }}
        </el-button>
      </div>
    </div>
  </div>
</template>
 
<script>
import {
  ServeDeleteArticleAnnex,
  ServeDownloadAnnex as downloadAnnex,
  ServeUploadArticleAnnex,
} from '@/api/article'
import { formateSize, formateTime, parseTime } from '@/utils/functions'
 
export default {
  name: 'NoteAnnexBox',
  props: {
    id: {
      type: Number,
      default: 0,
    },
    files: {
      type: Array,
      default() {
        return []
      },
    },
  },
  data() {
    return {
      loadStatus: false,
      disabled: false,
      maxNum: 10,
    }
  },
  methods: {
    // 格式化文件大小
    formateSize,
 
    // 格式化时间显示格式
    formateTime,
 
    // 下载笔记附件
    downloadAnnex,
 
    // 删除笔记附件
    deleteAnnex(annex_id, index) {
      ServeDeleteArticleAnnex({
        annex_id,
      }).then(({ code }) => {
        if (code == 200) {
          this.$delete(this.files, index)
        }
      })
    },
 
    // 上传笔记附件文件
    uploadAnnex(e) {
      if (e.target.files.length == 0) {
        return false
      }
 
      let file = e.target.files[0]
      if (file.size / (1024 * 1024) > 5) {
        this.$message('笔记附件不能大于5M!')
        return false
      }
 
      let fileData = new FormData()
      fileData.append('annex', file)
      fileData.append('article_id', this.id)
 
      this.loadStatus = true
      ServeUploadArticleAnnex(fileData)
        .then(({ code, data }) => {
          if (code == 200) {
            this.files.push({
              id: data.id,
              original_name: data.original_name,
              created_at: parseTime(new Date()),
              size: data.size,
              suffix: data.suffix,
            })
          }
        })
        .finally(() => {
          this.loadStatus = false
        })
    },
  },
}
</script>
<style lang="less" scoped>
/* 文件管理弹出层 */
.annex-box {
  width: 300px;
  min-height: 50px;
  max-height: 675px;
  background-color: white;
  overflow-y: auto;
 
  .annex-main {
    min-height: 30px;
    border-bottom: 1px solid rgb(239, 233, 233);
    margin-bottom: 8px;
    padding: 5px 0;
 
    .empty-text {
      color: #969292;
      font-size: 12px;
      margin-top: 10px;
    }
 
    .file-item {
      height: 50px;
      margin-bottom: 5px;
      margin-top: 10px;
 
      .suffix {
        width: 50px;
        height: 100%;
        background-color: #ffcc80;
        border-radius: 3px;
        float: left;
        line-height: 50px;
        text-align: center;
        color: white;
      }
 
      .content {
        float: left;
        width: 247px;
        height: 100%;
 
        .filename {
          padding-left: 5px;
          color: #172b4d;
          font-size: 14px;
          font-weight: 400;
          line-height: 1.6;
          white-space: nowrap;
          overflow: hidden;
          text-overflow: ellipsis;
        }
 
        .filetool {
          color: #505f79;
          font-size: 12px;
          font-weight: 400;
          line-height: 1.6;
          padding-left: 5px;
          margin-top: 9px;
          position: relative;
 
          span {
            margin: 0 3px;
            &.size {
              color: #3a8ee6;
            }
          }
        }
 
        .tools {
          position: absolute;
          top: -5px;
          right: 5px;
          width: 55px;
          height: 24px;
          text-align: right;
          line-height: 28px;
 
          i {
            font-size: 16px;
            cursor: pointer;
            margin-right: 5px;
          }
 
          .el-icon-download {
            color: #66b1ff;
          }
 
          .el-icon-delete {
            color: red;
          }
        }
      }
    }
  }
 
  input {
    display: none;
  }
 
  .annex-footer {
    .notice-text {
      font-size: 12px;
      color: #ccc;
      text-align: left;
      float: left;
      padding-top: 10px;
    }
 
    button {
      float: right;
    }
  }
}
</style>