2024-07-14 22:25:26 +08:00
|
|
|
|
<!-- 算子管理 -->
|
2024-06-17 23:13:49 +08:00
|
|
|
|
<template>
|
2024-06-21 00:50:41 +08:00
|
|
|
|
<div class="app-container model-detail">
|
2024-07-14 22:25:26 +08:00
|
|
|
|
<!-- 算子新增表单 -->
|
2024-07-12 02:23:19 +08:00
|
|
|
|
<el-card v-loading="loading">
|
2024-08-17 23:06:31 +08:00
|
|
|
|
<template #header><svg-icon icon-class="pause" style="width: 20px; height: 20px" /> 算子基本信息
|
2024-07-10 02:00:20 +08:00
|
|
|
|
</template>
|
2024-06-17 23:13:49 +08:00
|
|
|
|
<el-row>
|
|
|
|
|
<el-col :lg="12" :xs="24">
|
2024-07-14 22:25:26 +08:00
|
|
|
|
<el-form ref="formRef" :model="formData" :rules="rules" label-width="80px">
|
2024-07-10 02:00:20 +08:00
|
|
|
|
<el-form-item label="算子名称" prop="operator_name">
|
2024-08-17 23:06:31 +08:00
|
|
|
|
<el-input v-model="formData.operator_name" maxlength="64" show-word-limit placeholder="请输入算子名称" />
|
2024-06-17 23:13:49 +08:00
|
|
|
|
</el-form-item>
|
2024-07-10 02:00:20 +08:00
|
|
|
|
<el-form-item label="算子类型" prop="oper_sub_type">
|
|
|
|
|
<el-row style="width: 100%">
|
2024-06-17 23:13:49 +08:00
|
|
|
|
<el-col :span="12">
|
2024-08-17 23:06:31 +08:00
|
|
|
|
<el-select v-model="formData.oper_main_type" placeholder="请选择算子主类型" style="width: 100%"
|
|
|
|
|
@change="handleChange">
|
|
|
|
|
<el-option v-for="item in listOpt.operTypeList" :key="item.oper_main_type"
|
|
|
|
|
:label="item.oper_main_type_name" :value="item.oper_main_type" />
|
2024-06-17 23:13:49 +08:00
|
|
|
|
</el-select>
|
|
|
|
|
</el-col>
|
|
|
|
|
<el-col :span="12">
|
2024-08-17 23:06:31 +08:00
|
|
|
|
<el-select v-model="formData.oper_sub_type" placeholder="请选择算子子类型" style="width: 100%"
|
|
|
|
|
@change="handleChangeRules">
|
|
|
|
|
<el-option v-for="item in listOpt.operSubTypeList" :key="item.oper_sub_type"
|
|
|
|
|
:label="item.oper_sub_type_name" :value="item.oper_sub_type" />
|
2024-06-17 23:13:49 +08:00
|
|
|
|
</el-select>
|
|
|
|
|
</el-col>
|
|
|
|
|
</el-row>
|
|
|
|
|
</el-form-item>
|
2024-07-10 02:00:20 +08:00
|
|
|
|
<el-form-item label="算子说明" prop="operator_desc">
|
2024-08-17 23:06:31 +08:00
|
|
|
|
<el-input v-model="formData.operator_desc" :rows="2" type="textarea" placeholder="请输入算子说明"
|
|
|
|
|
maxlength="1024" />
|
2024-06-17 23:13:49 +08:00
|
|
|
|
</el-form-item>
|
2024-07-11 01:27:21 +08:00
|
|
|
|
<el-form-item label="算子文件" prop="parameters">
|
2024-08-17 23:06:31 +08:00
|
|
|
|
<el-upload ref="uploadRef" class="upload-demo" :on-change="handleFileChange" :on-remove="handleFileRemove"
|
|
|
|
|
:on-exceed="handleFileExceed" :auto-upload="false" :limit="1" accept="application/json">
|
|
|
|
|
<el-button type="primary"><el-icon class="el-icon--upload"> <i-ep-upload-filled />
|
|
|
|
|
</el-icon>选择文件</el-button>
|
2024-06-17 23:13:49 +08:00
|
|
|
|
<template #tip>
|
2024-07-10 02:00:20 +08:00
|
|
|
|
<div class="el-upload__tip">
|
|
|
|
|
请上传大小不超过 <strong style="color: red">10M</strong>,格式为
|
|
|
|
|
<strong style="color: red">json</strong> 的文件
|
|
|
|
|
</div>
|
2024-06-17 23:13:49 +08:00
|
|
|
|
</template>
|
|
|
|
|
</el-upload>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
</el-form>
|
|
|
|
|
</el-col>
|
|
|
|
|
<el-col :lg="12" :xs="24">
|
2024-07-12 02:23:19 +08:00
|
|
|
|
<div style="padding-left: 35px" v-if="fileStatus">
|
2024-07-14 22:25:26 +08:00
|
|
|
|
<el-form label-width="100px" size="small">
|
2024-08-17 23:06:31 +08:00
|
|
|
|
<el-divider content-position="left"><strong style="color: #409eff">算子文件预览</strong></el-divider>
|
|
|
|
|
<json-viewer :value="toJson(codeHtml)" copyable boxed sort theme="my-json-view jv-light" />
|
|
|
|
|
<!--
|
|
|
|
|
<el-input v-model="codeHtml" placeholder="请输入算子文件JSON" :rows="10" disabled type="textarea" />
|
|
|
|
|
-->
|
2024-07-12 02:23:19 +08:00
|
|
|
|
</el-form>
|
|
|
|
|
</div>
|
2024-06-17 23:13:49 +08:00
|
|
|
|
</el-col>
|
|
|
|
|
</el-row>
|
|
|
|
|
</el-card>
|
2024-06-21 00:50:41 +08:00
|
|
|
|
<el-card class="card-footer">
|
2024-07-10 02:00:20 +08:00
|
|
|
|
<el-button type="primary" @click="handleSubmit"><i-ep-check />确 定</el-button>
|
|
|
|
|
<el-button @click="closeBack"><i-ep-close />取 消</el-button>
|
2024-06-17 23:13:49 +08:00
|
|
|
|
</el-card>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
2024-09-16 10:36:17 +08:00
|
|
|
|
<script setup>
|
2024-07-10 02:00:20 +08:00
|
|
|
|
import ConstApi from "@/api/const";
|
2024-07-11 01:27:21 +08:00
|
|
|
|
import OperatorApi from "@/api/operator";
|
2024-08-17 23:06:31 +08:00
|
|
|
|
import { toJson } from '@/utils/'
|
2024-06-17 23:13:49 +08:00
|
|
|
|
const router = useRouter();
|
2024-07-12 02:23:19 +08:00
|
|
|
|
const formRef = ref(ElForm); // 表单
|
2024-06-17 23:13:49 +08:00
|
|
|
|
const loading = ref(false); // 加载状态
|
2024-07-10 02:00:20 +08:00
|
|
|
|
const fileStatus = ref(false); // 文件状态
|
2024-07-11 01:27:21 +08:00
|
|
|
|
const codeHtml = ref(""); // 文件信息
|
2024-07-10 02:00:20 +08:00
|
|
|
|
|
2024-07-11 01:27:21 +08:00
|
|
|
|
// 上传组件
|
2024-09-16 10:36:17 +08:00
|
|
|
|
const uploadRef = ref();
|
2024-07-14 22:25:26 +08:00
|
|
|
|
// 表单数据
|
2024-07-11 01:27:21 +08:00
|
|
|
|
const formData = reactive({
|
2024-06-17 23:13:49 +08:00
|
|
|
|
status: 1,
|
|
|
|
|
});
|
2024-07-11 01:27:21 +08:00
|
|
|
|
|
2024-07-10 02:00:20 +08:00
|
|
|
|
// 基础数据列表
|
|
|
|
|
let listOpt = reactive({
|
|
|
|
|
operTypeList: [],
|
|
|
|
|
operSubTypeList: [],
|
|
|
|
|
});
|
|
|
|
|
|
2024-06-17 23:13:49 +08:00
|
|
|
|
// 校验规则
|
|
|
|
|
const rules = reactive({
|
2024-07-11 01:27:21 +08:00
|
|
|
|
operator_name: [{ required: true, message: "算子名称不能为空", trigger: "blur" }],
|
2024-07-23 16:29:35 +08:00
|
|
|
|
oper_main_type: [{ required: true, message: "算子类型不能为空", trigger: "change" }],
|
|
|
|
|
oper_sub_type: [{ required: true, message: "算子类型不能为空", trigger: "change" }],
|
|
|
|
|
operator_desc: [{ required: false, message: "算子说明不能为空", trigger: "blur" }],
|
2024-07-11 01:27:21 +08:00
|
|
|
|
parameters: [{ required: true, message: "算子文件不能为空", trigger: "blur" }],
|
2024-06-17 23:13:49 +08:00
|
|
|
|
});
|
|
|
|
|
|
2024-07-11 01:27:21 +08:00
|
|
|
|
// 主动验证
|
2024-07-14 22:25:26 +08:00
|
|
|
|
function handleChangeRules() {
|
|
|
|
|
formRef.value.validateField("oper_main_type");
|
|
|
|
|
formRef.value.validateField("oper_sub_type");
|
2024-07-11 01:27:21 +08:00
|
|
|
|
}
|
2024-06-17 23:13:49 +08:00
|
|
|
|
|
|
|
|
|
/** 表单提交 */
|
|
|
|
|
const handleSubmit = useThrottleFn(() => {
|
2024-09-16 10:36:17 +08:00
|
|
|
|
formRef.value.validate((valid) => {
|
2024-07-11 01:27:21 +08:00
|
|
|
|
if (valid) {
|
|
|
|
|
loading.value = true;
|
2024-07-14 22:25:26 +08:00
|
|
|
|
OperatorApi.add(formData)
|
|
|
|
|
.then((res) => {
|
|
|
|
|
if (res.data.code == 0) {
|
|
|
|
|
ElMessage.success("保存成功");
|
|
|
|
|
closeBack();
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.finally(() => {
|
2024-07-11 01:27:21 +08:00
|
|
|
|
loading.value = false;
|
2024-07-14 22:25:26 +08:00
|
|
|
|
});
|
2024-07-11 01:27:21 +08:00
|
|
|
|
}
|
|
|
|
|
});
|
2024-06-17 23:13:49 +08:00
|
|
|
|
}, 3000);
|
|
|
|
|
|
|
|
|
|
/** 返回默认页面 */
|
|
|
|
|
function closeBack() {
|
2024-07-14 22:48:26 +08:00
|
|
|
|
router.push({ path: "/operatorLibrary/calculate" });
|
2024-06-17 23:13:49 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-07-10 02:00:20 +08:00
|
|
|
|
/** 算子主类型改变 */
|
|
|
|
|
function handleChange() {
|
2024-07-23 16:29:35 +08:00
|
|
|
|
listOpt.operTypeList.forEach((item) => {
|
2024-07-10 02:00:20 +08:00
|
|
|
|
if (item.oper_main_type == formData.oper_main_type) {
|
2024-07-11 01:27:21 +08:00
|
|
|
|
listOpt.operSubTypeList = item.oper_sub_type_list;
|
2024-07-10 02:00:20 +08:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 文件上传
|
|
|
|
|
function handleFileChange(file) {
|
|
|
|
|
//先创建一个读文件的对象 FileReader
|
|
|
|
|
let reader = new FileReader();
|
|
|
|
|
//判断浏览器是否支持 FileReader
|
|
|
|
|
if (typeof FileReader === "undefined") {
|
|
|
|
|
this.$message({
|
|
|
|
|
type: "info",
|
|
|
|
|
message: "您的浏览器不支持文件读取。",
|
|
|
|
|
});
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
uploadFile(file).then((res) => {
|
2024-07-11 01:27:21 +08:00
|
|
|
|
if (isJSON(res)) {
|
2024-07-22 16:46:27 +08:00
|
|
|
|
formData.parameters = JSON.parse(res);
|
2024-07-14 22:25:26 +08:00
|
|
|
|
formRef.value.validateField("parameters");
|
2024-07-22 01:17:38 +08:00
|
|
|
|
codeHtml.value = res;
|
2024-07-11 01:27:21 +08:00
|
|
|
|
fileStatus.value = true;
|
|
|
|
|
}
|
2024-07-10 02:00:20 +08:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-11 01:27:21 +08:00
|
|
|
|
/** 解析json */
|
|
|
|
|
function isJSON(str) {
|
|
|
|
|
try {
|
|
|
|
|
// 尝试解析输入的字符串
|
|
|
|
|
JSON.parse(str);
|
|
|
|
|
ElMessage.success("JSON文件解析成功");
|
|
|
|
|
return true;
|
|
|
|
|
// 成功解析
|
|
|
|
|
} catch (error) {
|
|
|
|
|
// 解析失败
|
|
|
|
|
ElMessage.error("JSON文件解析失败");
|
|
|
|
|
uploadRef.value.clearFiles();
|
|
|
|
|
fileStatus.value = false;
|
|
|
|
|
formData.parameters = "";
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-10 02:00:20 +08:00
|
|
|
|
// 文件读取
|
|
|
|
|
function uploadFile(file) {
|
|
|
|
|
return new Promise(function (resolve, reject) {
|
|
|
|
|
let reader = new FileReader();
|
|
|
|
|
reader.readAsArrayBuffer(file.raw);
|
|
|
|
|
reader.onload = function (e) {
|
|
|
|
|
var ints = new Uint8Array(e.target.result); //要使用读取的内容,所以将读取内容转化成Uint8Array
|
|
|
|
|
let snippets = new TextDecoder("UTF-8").decode(ints); //二进制缓存区内容转化成中文(即也就是读取到的内容)
|
|
|
|
|
resolve(snippets);
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 文件删除
|
|
|
|
|
function handleFileRemove() {
|
2024-07-11 01:27:21 +08:00
|
|
|
|
formData.parameters = "";
|
2024-07-22 01:17:38 +08:00
|
|
|
|
codeHtml.value = "";
|
2024-07-10 02:00:20 +08:00
|
|
|
|
fileStatus.value = false;
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-11 01:27:21 +08:00
|
|
|
|
// 超出限制,清空文件列表
|
|
|
|
|
function handleFileExceed() {
|
|
|
|
|
uploadRef.value.clearFiles();
|
|
|
|
|
ElMessage.warning("已清空文件列表,请重新上传!");
|
|
|
|
|
handleFileRemove();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 核心算法
|
|
|
|
|
function highlightJSON(json) {
|
|
|
|
|
// 匹配key
|
|
|
|
|
let keyReg = new RegExp('"(.*)"(?=:)', "g");
|
|
|
|
|
// 匹配value
|
|
|
|
|
let valueReg = new RegExp('(?<=: )("(.*)"|\\d+)', "g");
|
|
|
|
|
if (typeof json === "object" && json !== null) {
|
|
|
|
|
json = JSON.stringify(json, this, 5);
|
|
|
|
|
}
|
|
|
|
|
// 颜色替换
|
|
|
|
|
let res = json
|
|
|
|
|
.replace(keyReg, (match) => {
|
|
|
|
|
return `<span class="green">${match}</span>`;
|
|
|
|
|
})
|
|
|
|
|
.replace(valueReg, (match) => {
|
|
|
|
|
if (/\d/.test(match)) {
|
|
|
|
|
return `<span class="blue">${match}</span>`;
|
|
|
|
|
}
|
|
|
|
|
return `<span class="black">${match}</span>`;
|
|
|
|
|
});
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-10 02:00:20 +08:00
|
|
|
|
// 初始化选项列表
|
|
|
|
|
const initData = () => {
|
2024-07-11 01:27:21 +08:00
|
|
|
|
ConstApi.operMainType().then((res) => {
|
|
|
|
|
listOpt.operTypeList = res.data.data.oper_main_type_list || [];
|
2024-07-10 02:00:20 +08:00
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2024-06-17 23:13:49 +08:00
|
|
|
|
onMounted(() => {
|
2024-07-10 02:00:20 +08:00
|
|
|
|
initData();
|
2024-06-17 23:13:49 +08:00
|
|
|
|
});
|
|
|
|
|
</script>
|
2024-07-10 02:00:20 +08:00
|
|
|
|
<style scoped lang="scss">
|
|
|
|
|
.model-detail {
|
|
|
|
|
:deep(.el-card__header) {
|
|
|
|
|
padding: 8px 4px;
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
}
|
2024-06-21 00:50:41 +08:00
|
|
|
|
}
|
2024-08-17 23:06:31 +08:00
|
|
|
|
|
2024-07-10 02:00:20 +08:00
|
|
|
|
.sp-file {
|
|
|
|
|
color: #29d;
|
2024-06-21 00:50:41 +08:00
|
|
|
|
}
|
2024-08-17 23:06:31 +08:00
|
|
|
|
|
2024-07-10 02:00:20 +08:00
|
|
|
|
.tb-base-info {
|
|
|
|
|
line-height: 30px;
|
2024-06-21 00:50:41 +08:00
|
|
|
|
}
|
2024-08-17 23:06:31 +08:00
|
|
|
|
|
2024-07-10 02:00:20 +08:00
|
|
|
|
:deep(.svg-icon) {
|
|
|
|
|
margin-right: 8px;
|
2024-06-21 00:50:41 +08:00
|
|
|
|
}
|
2024-08-17 23:06:31 +08:00
|
|
|
|
|
2024-07-10 02:00:20 +08:00
|
|
|
|
.card-footer {
|
2024-06-17 23:13:49 +08:00
|
|
|
|
position: fixed;
|
2024-06-21 00:50:41 +08:00
|
|
|
|
width: calc(100% - 215px);
|
2024-06-17 23:13:49 +08:00
|
|
|
|
bottom: 0px;
|
2024-08-17 23:06:31 +08:00
|
|
|
|
|
2024-07-10 02:00:20 +08:00
|
|
|
|
:deep(.el-card__body) {
|
|
|
|
|
padding: 10px;
|
2024-08-17 23:06:31 +08:00
|
|
|
|
|
2024-07-10 02:00:20 +08:00
|
|
|
|
.el-pagination {
|
2024-06-21 00:50:41 +08:00
|
|
|
|
justify-content: end;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-06-17 23:13:49 +08:00
|
|
|
|
}
|
|
|
|
|
</style>
|
2024-07-11 01:27:21 +08:00
|
|
|
|
<style lang="scss" scope>
|
|
|
|
|
#codeHtml {
|
|
|
|
|
font-size: 16px;
|
|
|
|
|
color: #e36209;
|
|
|
|
|
font-family: "Courier New", Courier, monospace;
|
|
|
|
|
background: #f5f5f5;
|
2024-08-17 23:06:31 +08:00
|
|
|
|
|
2024-07-11 01:27:21 +08:00
|
|
|
|
.green {
|
|
|
|
|
color: #22863a;
|
|
|
|
|
}
|
2024-08-17 23:06:31 +08:00
|
|
|
|
|
2024-07-11 01:27:21 +08:00
|
|
|
|
.blue {
|
|
|
|
|
color: #005cc5;
|
|
|
|
|
}
|
2024-08-17 23:06:31 +08:00
|
|
|
|
|
2024-07-11 01:27:21 +08:00
|
|
|
|
.black {
|
|
|
|
|
color: #032f62;
|
|
|
|
|
}
|
2024-07-10 02:00:20 +08:00
|
|
|
|
}
|
2024-07-11 01:27:21 +08:00
|
|
|
|
</style>
|