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
| vm = new Vue({ el:"#app", data() { return { editdate: '', filename: '', size: '', username:"", tableData:{}, multipleSelection: [], fileList: [] } }, methods: { download(){ if (this.multipleSelection.length !== 1){ alert("请只选择一个文件进行操作>_<"); return; } let fileName = this.multipleSelection[0].name; if (fileName.indexOf(".") !== -1){ let url = "/fileDownloadServlet?fileName=" + fileName; window.location.href = encodeURI(url); }else { this.$message.error('不可下载文件夹!'); }
},
backFolder(){ axios.get("https://192.168.1.220:8080/backSuperFolderServlet") .then(resp => { var obj = resp.data; if (obj == null){ this.$message.error('已为根目录!'); return; } this.tableData = Array(obj.length);
for (let i = 0; i < obj.length; i++){ let f = obj[i]; let rawDate = new Date(f.editTime); let size = f.filesize > 0 ? f.filesize : "-"; if (size > 1024*1024 && size < 1024*1024*1024){ size = Number(size / (1024 * 1024)).toFixed(2) + "M"; }else if (size > 1024*1024*1024){ size = Number(size / (1024 * 1024 * 1024)).toFixed(2) + "G"; }else if (size < 1024*1024){ size = Number(size / 1024).toFixed(2) + "K"; }else { } d = dateFormat("YYYY-mm-dd HH:MM", rawDate); this.tableData.push({ name: f.fileName, date: d, size: size }) } }); }, openFolder(){ if (this.multipleSelection.length !== 1){ alert("请只选择一个文件进行操作>_<"); return; } let folderName = this.multipleSelection[0].name; if (this.multipleSelection[0].size !== '-'){ let url = "/" + folderName; window.location.href = encodeURI(url); return; } axios.get("https://192.168.1.220:8080/getSubFilesServlet?indexName=" + folderName) .then(resp => { const obj = resp.data; this.tableData = Array(obj.length); let d; for (let i = 0; i < obj.length; i++) { let f = obj[i]; let rawDate = new Date(f.editTime); let size = f.filesize > 0 ? f.filesize : "-"; if (size > 1024 * 1024 && size < 1024 * 1024 * 1024) { size = Number(size / (1024 * 1024)).toFixed(2) + "M"; } else if (size > 1024 * 1024 * 1024) { size = Number(size / (1024 * 1024 * 1024)).toFixed(2) + "G"; } else if (size < 1024 * 1024) { size = Number(size / 1024).toFixed(2) + "K"; } else { } d = dateFormat("YYYY-mm-dd HH:MM", rawDate); this.tableData.push({ name: f.fileName, date: d, size: size }) } }); },
deleteConfirm() { if (this.multipleSelection.length < 1){ alert("请选择文件>_<"); return; } this.$confirm('此操作将永久删除该文件, 是否继续?', '警告', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' }).then(() => { this.deleteFile(); }).catch(e => { console.log(e); this.$message({ type: 'info', message: '已取消删除' }); }); }, deleteFile(){ for(let i = 0; i < this.multipleSelection.length; i++) { let url = "https://192.168.1.220:8080/deleteFileServlet?indexName=" + this.multipleSelection[i].name; axios.get(encodeURI(url)) .then(resp => { if(resp.data === true){ this.$message({ type: 'success', message: '删除成功!' }); }else { this.$message.error('删除失败!不可删除非空文件夹!'); } }) .catch(error => { console.log(error); this.deleteFlag = false; }) } }, toggleSelection(rows) { if (rows) { rows.forEach(row => { this.$refs.multipleTable.toggleRowSelection(row); }); } else { this.$refs.multipleTable.clearSelection(); } }, handleSelectionChange(val) { this.multipleSelection = val; }, handleCommand(command){ if (command === "b"){ axios.get("https://192.168.1.220:8080/destroySessionServlet") .then(resp => { alert("注销成功!"); window.location.href='/login.html'; }) .catch(e =>{ alert("注销失败!请重试!"); }); }else{ this.$prompt('请输入修改后的密码', '提示', { confirmButtonText: '确定', cancelButtonText: '取消', inputPattern: /^\w+$/, inputErrorMessage: '密码格式不正确,密码只能由数字字母和下划线' }).then(({ value }) => { if (value.length > 20){ this.$message({ type: 'error', message: '新密码过长' }); return; } axios({ method : "POST", url : "https://192.168.1.220:8080/changePasswordServlet", data : "password=" + value }) .then(resp=>{ this.$message({ type: 'success', message: '密码修改成功' }); }) .catch(error=>{ console.log(error); this.$message.error('出错了!请重试'); }) }).catch(() => { this.$message({ type: 'info', message: '取消输入' }); }); } }, getFileInfo(){ axios.get("https://192.168.1.220:8080/fileInfoServlet") .then(resp=>{ console.log(resp.data); var obj = resp.data; this.tableData = Array(obj.length); for (let i = 0; i < obj.length; i++){ let f = obj[i]; let size = f.filesize > 0 ? f.filesize : "-"; if (size > 1024*1024 && size < 1024*1024*1024){ size = Number(size / (1024*1024)).toFixed(2) + "M"; }else if (size > 1024*1024*1024){ size = Number(size / (1024 * 1024 * 1024)).toFixed(2) + "G"; }else if (size < 1024*1024){ size = Number(size / 1024).toFixed(2) + "K"; }else { } let rawDate = new Date(f.editTime); d = dateFormat("YYYY-mm-dd HH:MM", rawDate); this.tableData.push({ name: f.fileName, date: d, size: size }) } }); },
getUserName() { axios.get("https://192.168.1.220:8080/userInfo") .then(response=>{ this.username = response.data; }) .catch(error=>{ console.log(error); alert('网络错误!'); }) }, open() { this.$prompt('请输入文件夹名', '提示', { confirmButtonText: '确定', cancelButtonText: '取消' }).then(({ value }) => { if (value.length > 64){ this.$message({ type: 'error', message: '文件名过长' }); return; } let url = "https://192.168.1.220:8080/createIndexServlet?indexName=" + value; axios.get(encodeURI(url)) .then(resp=>{ this.$message({ type: 'success', message: '新建文件夹名为: ' + value }); }) .catch(error=>{ console.log(error); this.$message.error('出错了!请检查文件名!'); }) }).catch(() => { this.$message({ type: 'info', message: '取消输入' }); }); }, upload() { this.$alert('<template><el-upload\n' + ' class="upload-demo"\n' + ' drag\n' + ' action="https://192.168.1.220:8080/fileUploadServlet"\n' + ' multiple>\n' + ' <i class="el-icon-upload"></i>\n' + ' <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>\n' + ' <div class="el-upload__tip" slot="tip">只能上传jpg/png文件,且不超过500kb</div>\n' + '</el-upload></template>', 'HTML 片段', { dangerouslyUseHTMLString: true }) this.$message({ type: 'success', message: '已上传' }); } }, mounted(){ axios.defaults.withCredentials = true; this.getUserName(); this.getFileInfo(); } }); function dateFormat(fmt, date) { let ret; const opt = { "Y+": date.getFullYear().toString(), "m+": (date.getMonth() + 1).toString(), "d+": date.getDate().toString(), "H+": date.getHours().toString(), "M+": date.getMinutes().toString(), "S+": date.getSeconds().toString() }; for (let k in opt) { ret = new RegExp("(" + k + ")").exec(fmt); if (ret) { fmt = fmt.replace(ret[1], (ret[1].length === 1) ? (opt[k]) : (opt[k].padStart(ret[1].length, "0"))) } } return fmt; }
|