Commit a03d5cff authored by rockyl's avatar rockyl

图集打包上传改为并行,加快速度

parent cf25f3fb
......@@ -24,13 +24,13 @@ class ApiError extends Error {
}
}
export async function fetchApi(uri, {host = '', params, method = 'get', auth = true, judgeSuccess = true, contentType = 'json', dataField = 'data', errMessage} = {}) {
export async function fetchApi(uri, {host = '', params, method = 'get', auth = true, credentials = 'include', judgeSuccess = true, contentType = 'json', dataField = 'data', errMessage} = {}) {
let url = host + (uri.startsWith('http') || uri.startsWith('//') ? uri : API_HOST + uri);
const options = {
method,
headers: {},
credentials: 'include',
credentials,
};
if (auth) {
//options.headers.authorization = 'Bearer ' + window['zeroing_token'];
......
......@@ -19,7 +19,3 @@ export async function getSkins(projectId, env) {
export async function sendDingTalk() {
return await fetchApi(`/polaris/sendMessage`, { method: 'post' })
}
export async function getDevPersons(){
return await fetchApi('/api/editor/devPersons', { method: 'get' });
}
\ No newline at end of file
......@@ -64,11 +64,12 @@ export async function deleteOne(id) {
/**
* 获取一个项目
* @param id
* @param withData 是否携带data
* @return {Promise<*|any>}
*/
export async function fetchOne(id) {
export async function fetchOne(id, withData = true) {
return await fetchApi('/api/project/query/data', {
params: { id },
params: { id, withData },
method: 'get',
errMessage: 'Failed to fetch project',
})
......@@ -83,6 +84,7 @@ export async function fetchOneFromDataUrl(dataUrl) {
return await fetchApi(dataUrl, {
auth: false,
judgeSuccess: false,
credentials: 'same-origin',
errMessage: 'Failed to fetch project',
})
}
......
......@@ -243,6 +243,7 @@
"Accept Both": "兼并",
"Previous Conflict": "上一个冲突",
"Next Conflict": "下一个冲突",
"To Verify": "去验证",
"eventGroup": {
"in": "接收",
"out": "派发"
......
......@@ -101,7 +101,7 @@ export const projectStore = {
state.name = name;
state.creator = creator;
state.operator = operator;
state.operators = operators;
state.operators = operators || creator; //兼容未保存的本地存储
state.update_time = update_time;
const localData = state.data;
......@@ -479,7 +479,7 @@ export const projectStore = {
project(state) {
const {id, name, creator, data, update_time, operator, operators,} = state;
let newData = clonePureObj(data);
delete newData['dependencies'];
//delete newData['dependencies'];
deleteDesignConfig(newData.processes);
deleteAssetsDepConfig(newData);
return {
......@@ -640,6 +640,7 @@ export const projectStore = {
},
async loadFromDataUrl({commit, dispatch}, {project, dataUrl}) {
await dispatch('loadPackageInfos');
project = await projectApi.fetchOne(project.id, false);
const projectData = await projectApi.fetchOneFromDataUrl(dataUrl);
if (projectData) {
project.data = projectData;
......@@ -918,7 +919,9 @@ async function packAssets(assets) {
let newAssets = assets.concat();
await packImages(newAssets, {getSheetUrlByUUID});
for (let asset of newAssets) {
await Promise.all(newAssets.map(asset=>{
return new Promise(async (resolve, reject)=>{
try {
if (asset.file) {
const {url} = await editorApi.uploadFile(asset.file, true).catch(e => {
failedList.push(asset);
......@@ -940,7 +943,37 @@ async function packAssets(assets) {
delete asset.frames;
delete asset.sheetUUID;
}
resolve();
}catch (e) {
reject(e);
}
})
}));
/*for (let asset of newAssets) {
if (asset.file) {
const {url} = await editorApi.uploadFile(asset.file, true).catch(e => {
failedList.push(asset);
});
let sheetConfig = {
file: url,
type: 'sheet',
frames: asset.frames,
};
let sheetConfigFile = new File([JSON.stringify(sheetConfig)], 'sheet.json', {type: 'plain/text'});
const {url: sheetConfigUrl} = await editorApi.uploadFile(sheetConfigFile, false, asset.sheetUUID).catch(e => {
failedList.push(asset)
});
asset.url = sheetConfigUrl;
asset.uuid = generateUUID();
delete asset.file;
delete asset.frames;
delete asset.sheetUUID;
}
}*/
return newAssets;
}
......
......@@ -158,7 +158,7 @@ export default {
lineSpacing: {
alias: '行间距',
type: 'number',
default: 14
default: 0
},
textAlign: {
alias: '文本对齐',
......
......@@ -11,14 +11,14 @@ const packExts = ['.png']; //, '.jpg', '.jpeg', '.bmp'
let canvas = document.createElement('canvas');
export async function packImages(asssts, options = {}) {
export async function packImages(assets, options = {}) {
const padding = options.padding || 1;
const maxSize = options.maxSize || 2048;
const mode = options.mode || 0;
const {getSheetUrlByUUID} = options;
const images = await preProcessing(asssts);
const images = await preProcessing(assets);
let rects = [], singles = [];
for (let item of images) {
......@@ -38,7 +38,7 @@ export async function packImages(asssts, options = {}) {
offY: 0,
})
} else {
asssts.push({
assets.push({
name: assets[0].name,
ext: assets[0].ext,
url: assets[0].url,
......@@ -53,6 +53,7 @@ export async function packImages(asssts, options = {}) {
let remainRects = rects.concat();
let index = 0;
let sheetPacks = [];
while (remainRects.length > 0) {
let name = 'sheet' + index;
......@@ -95,7 +96,7 @@ export async function packImages(asssts, options = {}) {
}
}
const sheetUUID = sha256(urls.sort().join()).toString();
/*const sheetUUID = sha256(urls.sort().join()).toString();
let url;
if (getSheetUrlByUUID) {
......@@ -103,22 +104,52 @@ export async function packImages(asssts, options = {}) {
}
if(url){
asssts.push({
assets.push({
ext: '.sht',
url,
uuid: generateUUID(),
});
}else{
asssts.push({
assets.push({
ext: '.sht',
file: new File([blob], name + '.png'),
frames,
sheetUUID,
});
}
}*/
sheetPacks.push([urls, name, blob, frames]);
index++;
}
await Promise.all(sheetPacks.map(([urls, name, blob, frames]) => {
return deal(assets, urls, getSheetUrlByUUID, name, blob, frames);
}))
}
async function deal(assets, urls, getSheetUrlByUUID, name, blob, frames) {
const sheetUUID = sha256(urls.sort().join()).toString();
let url;
if (getSheetUrlByUUID) {
url = await getSheetUrlByUUID(sheetUUID);
}
if (url) {
assets.push({
ext: '.sht',
url,
uuid: generateUUID(),
});
} else {
assets.push({
ext: '.sht',
file: new File([blob], name + '.png'),
frames,
sheetUUID,
});
}
}
function loadImage(url, assets) {
......
......@@ -56,10 +56,9 @@
import {
getSkins,
saveSkin,
sendDingTalk,
getDevPersons
} from "../../../../src/api/polaris";
import {pxHostMapping} from "../../../utils";
import {getDevPersons} from "../../../api/editor";
export default {
name: "PublishView",
......@@ -112,8 +111,6 @@
const {pxEnv} = this.options;
const pxPid = this.pxPid = pxEnv[env];
console.log("getDevPersons",getDevPersons())
this.QAList=await getDevPersons()
this.QAList=this.QAList.filter((item)=>{
return item.level==1
......@@ -175,7 +172,10 @@
const {env} = this;
this.pxProjectName = '';
this.skins = [];
await this.$alert(this.$t('SSO is invalid'));
await this.$confirm(this.$t('SSO is invalid'), this.$t('Alert'), {
confirmButtonText: this.$t('To Verify'),
cancelButtonText: this.$t('Close'),
});
window.open('/sso/login?env=' + env, '_blank');
},
hasIndex() {
......
......@@ -89,10 +89,11 @@
import EnabledSetter from "../components/EnabledSetter";
import MonacoEditor from "vue-monaco";
import PxConfigPopover from "../components/PxConfigPopover";
import {getSkins, saveSkin,getDevPersons} from "../../../api/polaris";
import {getSkins, saveSkin,} from "../../../api/polaris";
import {playWaiting, pxHostMapping} from "../../../utils";
import copy from "copy-to-clipboard";
import PxSkinEditor from "./PxSkinEditor";
import {getDevPersons} from "../../../api/editor";
export default {
name: "PxSkinEditorDialog",
......@@ -178,8 +179,6 @@
const {pxEnv} = this.options;
const pxPid = this.pxPid = pxEnv[env];
console.log("getDevPersons",getDevPersons())
this.QAList=await getDevPersons()
this.QAList=this.QAList.filter((item)=>{
return item.level==1
......@@ -207,7 +206,10 @@
const {env} = this;
this.pxProjectName = '';
this.skins = [];
await this.$alert(this.$t('SSO is invalid'));
await this.$confirm(this.$t('SSO is invalid'), this.$t('Alert'), {
confirmButtonText: this.$t('To Verify'),
cancelButtonText: this.$t('Close'),
});
window.open('/sso/login?env=' + env, '_blank');
},
async saveSkin(skin, operate) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment