!2378 批量下载图纸功能,导出的文件名增加文件的最后更新日期时间

pull/2376/MERGE
黄诗津 1 year ago committed by ChenX
parent b31eb8fb75
commit c32985126b

@ -295,30 +295,64 @@ export class FileServer extends Singleton
async Download(fid: string)
{
let fileInfo = await this.GetFileInfo(fid);
const store = TopPanelStore.GetInstance();
let file = deflate(fileInfo.file);
if (file)
FS.WriteFile(fileInfo.name + ".json", btoa(JSON.stringify({ file, id: store.shopId })));
while (true)
{
const data = await PostJson(FileUrls.detail, { file_id: fid });
const fileInfo = data.files;
let file = "";
let fileName = "";
if (data.err_code === RequestStatus.Ok && fileInfo)
{
const parts = (fileInfo.update_date ?? fileInfo.create_date).split(/[- :]/);
const time = "-" + parts[0].slice(2) + parts[1] + parts[2] + "_" + parts[3] + parts[4];
fileName = `${fileInfo.name + time}.json`;
file = deflate(inflateBase64(fileInfo.file));
}
if (file && fileName)
{
const store = TopPanelStore.GetInstance();
FS.WriteFile(fileName, btoa(JSON.stringify({ file, id: store.shopId })));
break;
}
else
{
let isContinue = confirm("当前文件下载失败,是否重试?");
if (!isContinue) break;
}
}
}
async DownloadTemplate(fid: string)
{
let data = await PostJson(TemplateUrls.detail, { module_id: fid });
let templateInfo: IFileInfo;
if (data.err_code === RequestStatus.Ok && data.modules)
while (true)
{
templateInfo = {
name: data.modules.name,
file: data.modules.file,
logo: data.modules.logo,
props: data.modules.props,
};
let data = await PostJson(TemplateUrls.detail, { module_id: fid });
let templateInfo: IFileInfo = {};
if (data.err_code === RequestStatus.Ok && data.modules)
{
templateInfo = {
name: data.modules.name,
file: data.modules.file,
logo: data.modules.logo,
props: data.modules.props,
};
}
let { file, logo, props } = templateInfo;
if (file && logo && props)
{
const store = TopPanelStore.GetInstance();
FS.WriteFile(templateInfo.name + ".json", btoa(JSON.stringify({ file, id: store.shopId, logo, props, type: "template" })));
break;
}
else
{
let isContinue = confirm("当前文件下载失败,是否重试?");
if (!isContinue) break;
}
}
const store = TopPanelStore.GetInstance();
let { file, logo, props } = templateInfo;
if (file && logo && props)
FS.WriteFile(templateInfo.name + ".json", btoa(JSON.stringify({ file, id: store.shopId, logo, props, type: "template" })));
}
private SaveCurrentFileInfo(fileInfo: IFileInfo)
{

@ -73,9 +73,15 @@ export class ImportFile extends React.Component<{ commonPanel: CommonPanel, type
else
{
let fserver = FileServer.GetInstance();
let fileName = f.name.replace(".json", "");
//如果名称字数大于30就自动去掉日期
if (fileName.length > 30)
{
fileName = fileName.replace(/-\d{6}_\d{4}$/, "");
}
await fserver.UploadFile({
dir_id,
name: f.name.replace(".json", ""),
name: fileName,
file: file
});
}

Loading…
Cancel
Save