Browse Source

fix: 暂时注释File文件管理

pull/89/head 6.0.1.1
王军 3 years ago
parent
commit
04b747e7e5
  1. 72
      vben28/src/views/admin/files/File.ts
  2. 4
      vben28/src/views/admin/files/File.vue
  3. 122
      vben28/src/views/admin/files/UploadOss.ts

72
vben28/src/views/admin/files/File.ts

@ -1,40 +1,40 @@
import { FormSchema } from "/@/components/Table"; // import { FormSchema } from "/@/components/Table";
import { BasicColumn } from "/@/components/Table"; // import { BasicColumn } from "/@/components/Table";
import { formatToDateTime } from '/@/utils/dateUtil'; // import { formatToDateTime } from '/@/utils/dateUtil';
import { FilesServiceProxy, PagingFileInput } from "/@/services/ServiceProxies"; // import { FilesServiceProxy, PagingFileInput } from "/@/services/ServiceProxies";
import { useI18n } from "/@/hooks/web/useI18n"; // import { useI18n } from "/@/hooks/web/useI18n";
const { t } = useI18n(); // const { t } = useI18n();
export const searchFormSchema: FormSchema[] = [ // export const searchFormSchema: FormSchema[] = [
{ // {
field: "filter", // field: "filter",
label: t("routes.admin.fileName"), // label: t("routes.admin.fileName"),
component: "Input", // component: "Input",
colProps: { span: 8 } // colProps: { span: 8 }
} // }
]; // ];
export const tableColumns: BasicColumn[] = [ // export const tableColumns: BasicColumn[] = [
{ // {
title: t("routes.admin.fileName"), // title: t("routes.admin.fileName"),
dataIndex: "fileName" // dataIndex: "fileName"
}, // },
{ // {
title: t("routes.admin.userManagement_createTime"), // title: t("routes.admin.userManagement_createTime"),
dataIndex: "creationTime", // dataIndex: "creationTime",
customRender: ({ text }) => { // customRender: ({ text }) => {
return formatToDateTime(text); // return formatToDateTime(text);
} // }
} // }
]; // ];
/** // /**
* // * 分页列表
* @param params // * @param params
* @returns // * @returns
*/ // */
export async function getTableListAsync(params: PagingFileInput) { // export async function getTableListAsync(params: PagingFileInput) {
const _filesServiceProxy = new FilesServiceProxy(); // const _filesServiceProxy = new FilesServiceProxy();
return _filesServiceProxy.page(params); // return _filesServiceProxy.page(params);
} // }

4
vben28/src/views/admin/files/File.vue

@ -1,4 +1,4 @@
<template> <!-- <template>
<div> <div>
<BasicTable @register="registerTable" size="small"> <BasicTable @register="registerTable" size="small">
<template #toolbar> <template #toolbar>
@ -111,4 +111,4 @@ export default defineComponent({
}); });
</script> </script>
<style lang="less" scoped></style> <style lang="less" scoped></style> -->

122
vben28/src/views/admin/files/UploadOss.ts

@ -1,66 +1,66 @@
import { FilesServiceProxy, FileTokenOutput } from "/@/services/ServiceProxies"; // import { FilesServiceProxy, FileTokenOutput } from "/@/services/ServiceProxies";
import OSS from "ali-oss"; // import OSS from "ali-oss";
import { dateUtil } from '/@/utils/dateUtil'; // import { dateUtil } from '/@/utils/dateUtil';
export async function importFileAsync({ request }) { // export async function importFileAsync({ request }) {
const _filesServiceProxy = new FilesServiceProxy(); // const _filesServiceProxy = new FilesServiceProxy();
await _filesServiceProxy.create(request); // await _filesServiceProxy.create(request);
} // }
async function getFileTokenAsync() { // async function getFileTokenAsync() {
const _filesServiceProxy = new FilesServiceProxy(); // const _filesServiceProxy = new FilesServiceProxy();
const result = await _filesServiceProxy.getFileToken(); // const result = await _filesServiceProxy.getFileToken();
sessionStorage.setItem("oss", JSON.stringify(result)); // sessionStorage.setItem("oss", JSON.stringify(result));
return result; // return result;
} // }
export async function getOSSClient(): Promise<OSS> { // export async function getOSSClient(): Promise<OSS> {
let fileToken = new FileTokenOutput(); // let fileToken = new FileTokenOutput();
try { // try {
let oss = sessionStorage.getItem("oss"); // let oss = sessionStorage.getItem("oss");
if (!oss) { // if (!oss) {
fileToken = await getFileTokenAsync(); // fileToken = await getFileTokenAsync();
} else { // } else {
fileToken = JSON.parse(oss); // fileToken = JSON.parse(oss);
let expiration = dateUtil(fileToken.expiration).format("YYYY-MM-DD HH:mm:ss"); // let expiration = dateUtil(fileToken.expiration).format("YYYY-MM-DD HH:mm:ss");
if (expiration < formatDate(dateUtil())) { // if (expiration < formatDate(dateUtil())) {
fileToken = await getFileTokenAsync(); // fileToken = await getFileTokenAsync();
} // }
} // }
let request = { // let request = {
region: fileToken.region, // region: fileToken.region,
accessKeyId: fileToken.accessKeyId, // accessKeyId: fileToken.accessKeyId,
accessKeySecret: fileToken.accessKeySecret, // accessKeySecret: fileToken.accessKeySecret,
bucket: fileToken.bucket, // bucket: fileToken.bucket,
stsToken: fileToken.token as string // stsToken: fileToken.token as string
}; // };
return Promise.resolve<OSS>(new OSS(request)); // return Promise.resolve<OSS>(new OSS(request));
} catch (error) { // } catch (error) {
console.error("获取oss Client失败"); // console.error("获取oss Client失败");
} // }
} // }
export async function downLoadFile(fileName) { // export async function downLoadFile(fileName) {
let oss = await getOSSClient(); // let oss = await getOSSClient();
const response = { // const response = {
"content-disposition": `attachment; filename=${encodeURIComponent(fileName)}` // "content-disposition": `attachment; filename=${encodeURIComponent(fileName)}`
}; // };
const url = (oss as OSS).signatureUrl(fileName, { response }); // const url = (oss as OSS).signatureUrl(fileName, { response });
let link = document.createElement("a"); //创建a标签 // let link = document.createElement("a"); //创建a标签
link.style.display = "none"; //使其隐藏 // link.style.display = "none"; //使其隐藏
link.href = url; //赋予文件下载地址 // link.href = url; //赋予文件下载地址
link.setAttribute("download", fileName); //设置下载属性 以及文件名 // link.setAttribute("download", fileName); //设置下载属性 以及文件名
document.body.appendChild(link); //a标签插至页面中 // document.body.appendChild(link); //a标签插至页面中
link.click(); //强制触发a标签事件 // link.click(); //强制触发a标签事件
} // }
function formatDate(dateTime) { // function formatDate(dateTime) {
const date = new Date(dateTime); // const date = new Date(dateTime);
const YY = date.getFullYear() + "-"; // const YY = date.getFullYear() + "-";
const MM = (date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1) + "-"; // const MM = (date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1) + "-";
const DD = date.getDate() < 10 ? "0" + date.getDate() : date.getDate(); // const DD = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
const hh = date.getHours() + ":"; // const hh = date.getHours() + ":";
const mm = date.getMinutes() + ":"; // const mm = date.getMinutes() + ":";
const ss = date.getSeconds(); // const ss = date.getSeconds();
return YY + MM + DD + " " + hh + mm + ss; // return YY + MM + DD + " " + hh + mm + ss;
} // }

Loading…
Cancel
Save