Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…yUI-Studio into develop
  • Loading branch information
SHAO committed Feb 21, 2024
2 parents 86f7e85 + 068c5f9 commit 3f8d3dc
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 25 deletions.
16 changes: 14 additions & 2 deletions loader/components/home/classification/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,20 @@ export default {
this.$emit("changeSearchParameter", { key: "", tags: this.tags });
},
// Select a single tag
selectClassify(index) {
selectClassify(event, index) {
const existIndex = this.selectedList.findIndex((x) => x === index);
if (event.ctrlKey) {
if (existIndex != -1) {
this.selectedList.splice(existIndex, 1);
const tagIndex = this.tags.findIndex((x) => x === this.list[index].name);
this.tags.splice(tagIndex, 1);
} else {
this.selectedList.push(index);
this.tags.push(this.list[index].name);
}
this.$emit("changeSearchParameter", { key: "", tags: this.tags });
return;
}
// 无ctrl: 单选, 当已存在时取消所有, 若当前已选多项时单击先取消所有再选择当前
if (this.tags.length > 1 || existIndex == -1) {
this.selectedList = [index];
Expand Down Expand Up @@ -89,7 +101,7 @@ export default {
template: `<div ref="classification" class="classification" :class="{classification_expand:isExpand}">
<div class="item all" :class="{selected_classify: selectedList.length === 0}" @click="selectAll">ALL</div>
<div class="block"></div>
<div v-for="(item,index) in list" :key="index" ref="item" class="item" :class="{selected_classify: selectedList.includes(index)}" @click="selectClassify(index)" @contextmenu.prevent="handleContextMenu($event, index)" @selectstart.prevent="handleSelectStart" >
<div v-for="(item,index) in list" :key="index" ref="item" class="item" :class="{selected_classify: selectedList.includes(index)}" @click="selectClassify($event, index)" @contextmenu.prevent="handleContextMenu($event, index)" @selectstart.prevent="handleSelectStart" >
{{item.name}}
</div>
<div class="expand_icon" :class="{rotate_em:isExpand}" @click="expandClassify"><em class="iconfont icon-double-arrow-bottom"></em></div>
Expand Down
13 changes: 13 additions & 0 deletions loader/components/home/model/detail/basicInf/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ export default {
//Timestamp conversion
timestampConversion(timeStamp) {
const date = new Date(Number(timeStamp));
return date.toLocaleString([], {
year: "numeric",
month: "2-digit",
day: "2-digit",
hour: "2-digit",
minute: "2-digit",
});
return date.getFullYear() + "/" + (date.getMonth() + 1) + "/" + date.getDate() + " " + date.getHours() + ": " + date.getMinutes();
},
// Delete tag
Expand Down Expand Up @@ -73,6 +80,12 @@ export default {
return true;
},
},
filters: {
// 保留小数位数->str
numberRound(num, decimal = 2) {
return Math.round(num * Math.pow(10, decimal)) / Math.pow(10, decimal);
},
},
template: `<div class="basic_inf">
<div class="model_inf">
<div class="size inf_item">
Expand Down
6 changes: 0 additions & 6 deletions loader/components/home/model/detail/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,6 @@ export default {
this.menuIndex = index;
},
},
filters: {
// 保留小数位数->str
numberRound(num, decimal = 2) {
return Math.round(num * Math.pow(10, decimal)) / Math.pow(10, decimal);
},
},
template: `
<div v-if="model" class="model_detail">
<div class="img_container">
Expand Down
62 changes: 45 additions & 17 deletions loader/components/home/model/detail/workflow/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,39 +56,40 @@ export default {
saveWorkflow(name) {
// 随机生成
if (!name) name = `wk-${Math.random().toString(36).substring(2, 10)}`;
var node = this.node;
var data = window.parent.app.graph.serialize();
var request = new XMLHttpRequest();
request.timeout = 500; // 超时
// request.timeout = 500; // 超时
request.open("post", "/cs/save_workflow", true);
request.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
request.onload = () => {
if (request.status != 200) return;
var resp = JSON.parse(request.responseText);
if (resp?.saved) {
this.node.CSupdateModelConfig(this.model.name);
node.CSupdateModelConfig(this.model.name);
this.$message(name + " " + this.$t("home.modelDetail.workflow.saveSuccess"));
} else {
this.$message(name + " " + this.$t("home.modelDetail.workflow.saveFail"));
}
};
request.ontimeout = () => {
this.$message(name + " " + this.$t("home.modelDetail.workflow.saveTimeout"));
};
let mtype = this.node.CSgetModelWidgetType();
// request.ontimeout = () => {
// this.$message(name + " " + this.$t("home.modelDetail.workflow.saveTimeout"));
// };
let mtype = node.CSgetModelWidgetType();
let body = { mtype: mtype, mname: this.model?.name, data, name };
request.send(JSON.stringify(body));
},
// Copy workflow
async copyText(item) {
copyWorkflow(item) {
var request = new XMLHttpRequest();
request.timeout = 500; // 超时
request.open("post", "/cs/fetch_workflow", true);
request.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
request.onload = () => {
request.onload = async () => {
if (request.status != 200) return;
var resp = JSON.parse(request.responseText);
if (resp) {
navigator.clipboard.writeText(request.responseText);
await navigator.clipboard.writeText(request.responseText);
this.$message(item.name + " " + this.$t("home.modelDetail.workflow.copySuccess"));
} else {
this.$message(item.name + " " + this.$t("home.modelDetail.workflow.copyFail"));
Expand All @@ -102,9 +103,10 @@ export default {
request.send(JSON.stringify(body));
},
// Delete workflow
deleteItem(index, item) {
deleteWorkflow(index, item) {
// 异步, 且取消超时等待
var request = new XMLHttpRequest();
request.timeout = 500; // 超时
// request.timeout = 500; // 超时
request.open("post", "/cs/remove_workflow", true);
request.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
request.onload = () => {
Expand All @@ -117,15 +119,41 @@ export default {
this.$message(item.name + " " + this.$t("home.modelDetail.workflow.deleteFail"));
}
};
// request.ontimeout = () => {
// this.$message(item.name + " " + this.$t("home.modelDetail.workflow.deleteTimeout"));
// };
let mtype = this.node.CSgetModelWidgetType();
let body = { mtype: mtype, mname: this.model?.name, workflow: item.workflow, name: item.name };
request.send(JSON.stringify(body));
},
// Import
importWorkflow(item) {
var request = new XMLHttpRequest();
request.timeout = 500; // 超时
request.open("post", "/cs/fetch_workflow", true);
request.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
request.onload = async () => {
if (request.status != 200) return;
var resp = JSON.parse(request.responseText);
if (resp) {
try {
if (resp.hasOwnProperty("workflow")) resp = resp.workflow;
await window.parent.app.loadGraphData(resp);
this.$message(item.name + " " + this.$t("home.modelDetail.workflow.importSuccess"));
} catch (e) {
this.$message(item.name + " " + this.$t("home.modelDetail.workflow.importFail") + `: ${e}`);
}
} else {
this.$message(item.name + " " + this.$t("home.modelDetail.workflow.importFail"));
}
};
request.ontimeout = () => {
this.$message(item.name + " " + this.$t("home.modelDetail.workflow.deleteTimeout"));
this.$message(item.name + " " + this.$t("home.modelDetail.workflow.importTimeout"));
};
let mtype = this.node.CSgetModelWidgetType();
let body = { mtype: mtype, mname: this.model?.name, workflow: item.workflow, name: item.name };
request.send(JSON.stringify(body));
},
// Import
import(item) {},
},
template: `<div class="workflow">
<div class="workflow_content">
Expand All @@ -143,9 +171,9 @@ export default {
<div v-for="(item,index) in filterList" :key="index" class="workflow_item">
<span class="name">{{item.name}}</span>
<div class="option">
<em class="iconfont icon-import" @click="import(item)" :title="$t('home.modelDetail.workflow.importText')"></em>
<em class="iconfont icon-copy" @click="copyText(item)" :title="$t('home.modelDetail.workflow.copyText')"></em>
<em class="iconfont icon-delete" @click="deleteItem(index,item)" :title="$t('home.modelDetail.workflow.delete')"></em>
<em class="iconfont icon-import" @click="importWorkflow(item)" :title="$t('home.modelDetail.workflow.importText')"></em>
<em class="iconfont icon-copy" @click="copyWorkflow(item)" :title="$t('home.modelDetail.workflow.copyText')"></em>
<em class="iconfont icon-delete" @click="deleteWorkflow(index,item)" :title="$t('home.modelDetail.workflow.delete')"></em>
</div>
</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions loader/enterLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ function message(event) {
if (event.data.type === "close_loader_page") {
let page = getPage();
page.style.display = "none";
window.CSvm.node = null; // reset node
// document.body.removeChild(document.getElementById("loader_iframe"));
}
}
Expand Down
9 changes: 9 additions & 0 deletions loader/static/js/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ const message = {
deleteSuccess: "删除成功",
deleteFail: "删除失败",
deleteTimeout: "删除超时",
importSuccess: "导入成功",
importFail: "导入失败",
importTimeout: "导入超时",
},
useButtonText: "使用此模型",
},
Expand Down Expand Up @@ -317,6 +320,9 @@ const message = {
deleteSuccess: "Delete success",
deleteFail: "Delete failed",
deleteTimeout: "Delete timeout",
importSuccess: "Import success",
importFail: "Import failed",
importTimeout: "Import timeout",
},
useButtonText: "Use model",
},
Expand Down Expand Up @@ -493,6 +499,9 @@ const message = {
deleteSuccess: "刪除成功",
deleteFail: "刪除失敗",
deleteTimeout: "刪除超时",
importSuccess: "導入成功",
importFail: "導入失敗",
importTimeout: "導入超時",
},
useButtonText: "使用此模型",
},
Expand Down

0 comments on commit 3f8d3dc

Please sign in to comment.