<template>
|
<div class="pageAlg right-main">
|
<div class="bread-crumb">
|
<span class="prev-title">
|
<router-link to="/layout/AppManage">应用列表</router-link>
|
</span>
|
<span class="devide"></span>
|
<span class="cur-title"
|
>{{ appId == "create" ? "创建" : "编辑" }}应用</span
|
>
|
</div>
|
<div style="min-height: calc(100vh - 150px); background: #fff">
|
<el-form
|
:model="appForm"
|
ref="appForm"
|
:rules="rules"
|
label-width="120px"
|
v-loading="formLoading"
|
>
|
<div class="base-info info-block">
|
<div class="info-header">
|
<span class="title">基本信息</span>
|
</div>
|
<div class="info-body">
|
<div class="left">
|
<el-form-item label="应用名称" prop="name">
|
<el-input v-model="appForm.name" size="small"></el-input>
|
</el-form-item>
|
<el-form-item label="应用包名" prop="package">
|
<el-input v-model="appForm.package" size="small"></el-input>
|
</el-form-item>
|
<el-form-item label="加载方式" prop="type">
|
<el-select v-model="appForm.type" size="small">
|
<el-option value="1" label="单独页面">单独页面</el-option>
|
<el-option value="2" label="弹窗">弹窗</el-option>
|
</el-select>
|
</el-form-item>
|
<el-form-item label="应用路径" prop="url">
|
<el-input v-model="appForm.url" size="small"></el-input>
|
</el-form-item>
|
<el-form-item label="应用标题" prop="title">
|
<el-input v-model="appForm.title" size="small"></el-input>
|
</el-form-item>
|
<el-form-item label="应用类型" prop="isDefault">
|
<el-radio v-model="appForm.isDefault" :label="true"
|
>默认应用</el-radio
|
>
|
<el-radio v-model="appForm.isDefault" :label="false"
|
>可选应用</el-radio
|
>
|
</el-form-item>
|
</div>
|
<div class="right">
|
<el-form-item
|
label="应用logo"
|
prop="iconBlob"
|
style="margin-bottom: 16px"
|
>
|
<el-upload
|
class="avatar-uploader"
|
drag
|
action="https://jsonplaceholder.typicode.com/posts/"
|
:show-file-list="false"
|
:http-request="uploadAlgLogo"
|
:on-success="onSuccess"
|
:before-upload="beforeUpload"
|
>
|
<el-image
|
v-if="appForm.iconBlob"
|
:src="
|
appForm.iconBlob.indexOf(',') > 0
|
? appForm.iconBlob
|
: `data:image/png;base64,${appForm.iconBlob}`
|
"
|
style="width: 100%; height: 100%"
|
fit="contain"
|
></el-image>
|
<i v-else class="el-icon-plus avatar-uploader-icon"></i>
|
<div class="el-upload__text">
|
将图片拖到此处,或
|
<em>点击上传</em>
|
</div>
|
</el-upload>
|
<span class="second-icon-desc">其它风格应用logo:</span>
|
<el-upload
|
class="avatar-uploader"
|
drag
|
action="https://jsonplaceholder.typicode.com/posts/"
|
:show-file-list="false"
|
:http-request="uploadAlgLogo2"
|
:on-success="onSuccess"
|
:before-upload="beforeUpload"
|
>
|
<el-image
|
v-if="appForm.iconBlob2"
|
:src="
|
appForm.iconBlob2.indexOf(',') > 0
|
? appForm.iconBlob2
|
: `data:image/png;base64,${appForm.iconBlob2}`
|
"
|
style="width: 100%; height: 100%"
|
fit="contain"
|
></el-image>
|
<i v-else class="el-icon-plus avatar-uploader-icon"></i>
|
<div class="el-upload__text">
|
将图片拖到此处,或
|
<em>点击上传</em>
|
</div>
|
</el-upload>
|
</el-form-item>
|
<el-form-item
|
label="默认宽"
|
prop="width"
|
v-if="appForm.type == '2'"
|
>
|
<el-input v-model.number="appForm.width" size="small">
|
<template slot="append">px</template>
|
</el-input>
|
</el-form-item>
|
<el-form-item
|
label="默认高"
|
prop="height"
|
v-if="appForm.type == '2'"
|
>
|
<el-input v-model.number="appForm.height" size="small">
|
<template slot="append">px</template>
|
</el-input>
|
</el-form-item>
|
</div>
|
</div>
|
<div class="form-end">
|
<el-button size="small" @click="goBack">取消</el-button>
|
<el-button type="primary" size="small" @click="saveForm"
|
>保存</el-button
|
>
|
</div>
|
</div>
|
</el-form>
|
<div class="base-info info-block">
|
<div class="info-header">
|
<span class="title">应用版本</span>
|
<div class="toAdd" @click="toAddVersion">
|
<i class="el-icon-circle-plus-outline"></i>
|
<span>添加</span>
|
</div>
|
</div>
|
<div class="info-body">
|
<el-table :data="versionInfo" style="width: 100%" border>
|
<el-table-column
|
type="index"
|
width="50"
|
label="序号"
|
align="center"
|
></el-table-column>
|
<el-table-column
|
prop="version_show"
|
width="260"
|
label="版本号"
|
align="center"
|
>
|
<template slot-scope="scope">
|
<div>
|
<span>{{ scope.row.version_show }}</span>
|
</div>
|
</template>
|
</el-table-column>
|
<el-table-column
|
prop="content"
|
width="500"
|
label="版本更新内容"
|
header-align="center"
|
>
|
<template slot-scope="scope">
|
<div v-if="isVersionEdit && scope.$index == curEditIndex">
|
<el-input v-model="editData.content" size="mini"></el-input>
|
</div>
|
<div v-else>
|
<span>{{ scope.row.content }}</span>
|
</div>
|
</template>
|
</el-table-column>
|
<el-table-column
|
prop="updateTime"
|
width="290"
|
label="更新时间"
|
align="center"
|
></el-table-column>
|
<el-table-column
|
prop="updateUserName"
|
width="150"
|
label="更新人"
|
align="center"
|
></el-table-column>
|
<el-table-column width="250" label="附件" align="center">
|
<template slot-scope="scope">
|
<div
|
v-if="
|
isVersionEdit &&
|
scope.$index == curEditIndex &&
|
!scope.row.id
|
"
|
>
|
<file-uploader
|
single
|
uploadPlaceholder="上传应用文件"
|
url="/data/api-f/file/upload"
|
@complete="onFileUpload"
|
@file-added="onFileAdded"
|
/>
|
</div>
|
<div v-else>{{ scope.row.component_name }}</div>
|
</template>
|
</el-table-column>
|
<el-table-column label="操作" align="center" width="100">
|
<template slot-scope="scope">
|
<div v-if="isVersionEdit && scope.$index == curEditIndex">
|
<span class="cursor-pointer" @click="cancel(scope)"
|
>取消</span
|
>
|
<span
|
class="cursor-pointer"
|
@click="saveRowVersion(scope.row)"
|
>保存</span
|
>
|
</div>
|
<div class="operation" v-else>
|
<i class="el-icon-edit" @click="editAppVersion(scope)"></i>
|
<i
|
class="el-icon-remove-outline"
|
@click="removeAppVersion(scope)"
|
></i>
|
</div>
|
</template>
|
</el-table-column>
|
</el-table>
|
</div>
|
</div>
|
</div>
|
</div>
|
</template>
|
<script>
|
// import {
|
// saveApp,
|
// showAppDetail,
|
// saveAppVersion,
|
// deleteAppVersion,
|
// } from "@/api/app";
|
import { getFilePath } from "@/api/utils";
|
import FileUploader from "@/components/subComponents/FileUpload/index";
|
export default {
|
components: {
|
FileUploader,
|
},
|
props: ["appId"],
|
data() {
|
return {
|
appForm: {
|
name: "",
|
package: "",
|
type: "",
|
url: "",
|
title: "",
|
iconBlob: "",
|
iconBlob2: "",
|
isDefault: false,
|
},
|
rules: {
|
name: [
|
{ required: true, message: "请输入应用名称", trigger: "blur" },
|
{ min: 1, max: 15, message: "长度在1到15个字符", trigger: "blur" },
|
],
|
iconBlob: [
|
{ required: true, message: "请上传应用logo", trigger: "blur" },
|
],
|
package: [
|
{ required: true, message: "请输入应用包名", trigger: "blur" },
|
{ min: 1, max: 50, message: "长度在1到50个字符", trigger: "blur" },
|
],
|
type: [
|
{ required: true, message: "请选择应用加载方式", trigger: "change" },
|
],
|
title: [
|
{ required: true, message: "请输入应用标题", trigger: "blur" },
|
{ min: 1, max: 15, message: "长度在1到15个字符", trigger: "blur" },
|
],
|
width: [
|
{ required: true, message: "请输入应用默认宽", trigger: "blur" },
|
{
|
type: "number",
|
message: "请输入100到1920之间的整数",
|
trigger: "blur",
|
},
|
// { min: 100, message: '默认宽不能小于100', trigger: 'blur' },
|
// { max: 1920, message: '默认宽不能大于1920', trigger: 'blur' }
|
],
|
height: [
|
{ required: true, message: "请输入应用默认高", trigger: "blur" },
|
{
|
type: "number",
|
message: "请输入100到1200之间的整数",
|
trigger: "blur",
|
},
|
],
|
},
|
versionInfo: [],
|
editData: {},
|
isVersionEdit: false,
|
curEditIndex: 0,
|
curEditRow: {},
|
formLoading: false,
|
// lastComponent_name:'',
|
// lastComponent_path:''
|
};
|
},
|
mounted() {
|
if (this.appId != "create") {
|
this.showDetail();
|
}
|
},
|
methods: {
|
newAppVersion() {
|
return {
|
version: "",
|
content: "",
|
updateTime: "",
|
person: "",
|
component_name: "",
|
component_path: "",
|
};
|
},
|
toAddVersion() {
|
if (this.isVersionEdit) return;
|
this.editData = this.newAppVersion();
|
this.versionInfo.push(this.editData);
|
this.isVersionEdit = true;
|
this.curEditIndex = this.versionInfo.length - 1;
|
},
|
beforeUpload() {},
|
uploadAlgLogo(params) {
|
let file = params.file;
|
let fileReader = new FileReader();
|
if (file) {
|
fileReader.readAsDataURL(file);
|
}
|
fileReader.onload = () => {
|
this.appForm.iconBlob = fileReader.result.substring(
|
fileReader.result.indexOf(",") + 1
|
);
|
};
|
},
|
uploadAlgLogo2(params) {
|
let file = params.file;
|
let fileReader = new FileReader();
|
if (file) {
|
fileReader.readAsDataURL(file);
|
}
|
fileReader.onload = () => {
|
this.appForm.iconBlob2 = fileReader.result.substring(
|
fileReader.result.indexOf(",") + 1
|
);
|
};
|
},
|
onSuccess() {},
|
saveForm() {
|
this.$refs["appForm"].validate((valid) => {
|
if (valid) {
|
this.formLoading = true;
|
let params = {
|
iconBlob: this.appForm.iconBlob,
|
iconBlob2: this.appForm.iconBlob2,
|
id: this.appForm.id,
|
name: this.appForm.name,
|
package: this.appForm.package,
|
title: this.appForm.title,
|
type: this.appForm.type,
|
url: this.appForm.url,
|
width: this.appForm.width,
|
height: this.appForm.height,
|
isDefault: this.appForm.isDefault,
|
};
|
saveApp(params)
|
.then((res) => {
|
if (res.code == 200) {
|
this.$notify({
|
type: "success",
|
message: "保存成功!",
|
duration: 2500,
|
offset: 57,
|
});
|
this.formLoading = false;
|
this.appId = res.data.id;
|
this.showDetail();
|
}
|
})
|
.catch((e) => {
|
if (e && e.status == 401) {
|
return;
|
}
|
this.$notify({
|
type: "error",
|
message: "保存失败,请稍后重试!",
|
duration: 2500,
|
offset: 57,
|
});
|
console.log(e);
|
this.formLoading = false;
|
});
|
} else {
|
return false;
|
}
|
});
|
},
|
showDetail() {
|
showAppDetail({ id: this.appId })
|
.then((res) => {
|
if (res.code == 200) {
|
this.appForm = res.data.appInfo;
|
this.versionInfo = res.data.versions;
|
}
|
})
|
.catch((e) => {
|
console.log(e);
|
});
|
},
|
goBack() {
|
this.$router.go(-1);
|
},
|
removeAppVersion(scope) {
|
this.$confirm("确定删除该项吗?", "提示", {
|
confirmButtonText: "确定",
|
cancelButtonText: "取消",
|
type: "warning",
|
center: true,
|
})
|
.then(() => {
|
deleteAppVersion({ id: scope.row.id }).then((res) => {
|
if (res.code == 200) {
|
this.$message({
|
type: "success",
|
message: "删除成功!",
|
});
|
this.showDetail();
|
}
|
});
|
})
|
.catch((e) => {
|
console.log(e);
|
});
|
},
|
// rowClick (row, column, ev) {
|
// this.curEditRow = JSON.parse(JSON.stringify(row));
|
// },
|
saveRowVersion(row) {
|
let params = {
|
app_id: this.appId,
|
component_name: row.id
|
? row.component_name
|
: this.curEditRow.component_name,
|
component_path: row.id
|
? row.component_path
|
: this.curEditRow.component_path,
|
content: this.editData.content,
|
id: this.editData.id,
|
updateBy: this.editData.updateBy,
|
updateTime: this.editData.updateTime,
|
updateUserName: this.editData.updateUserName,
|
version: this.editData.version,
|
};
|
|
saveAppVersion(params)
|
.then((res) => {
|
if (res.code == 200) {
|
this.$notify({
|
type: "success",
|
message: "保存成功!",
|
position: "bottom-right",
|
duration: 2500,
|
});
|
this.isVersionEdit = false;
|
this.showDetail();
|
}
|
})
|
.catch((e) => {
|
if (e && e.status == 401) {
|
return;
|
}
|
this.$notify({
|
type: "error",
|
message: e.data,
|
position: "bottom-right",
|
duration: 2500,
|
});
|
});
|
},
|
cancel(scope) {
|
this.isVersionEdit = false;
|
if (!scope.row.id) {
|
this.versionInfo.splice(this.versionInfo.length - 1, 1);
|
}
|
},
|
editAppVersion(scope) {
|
this.isVersionEdit = true;
|
this.curEditIndex = scope.$index;
|
this.editData = JSON.parse(JSON.stringify(scope.row));
|
},
|
onFileUpload(params) {
|
this.curEditRow.component_name = params.filename;
|
getFilePath(params).then((res) => {
|
if (res.code == 200) {
|
this.curEditRow.component_path = res.data;
|
}
|
});
|
},
|
onFileAdded() {},
|
},
|
};
|
</script>
|
<style lang="scss">
|
.pageAlg {
|
height: 100%;
|
|
.orderTop {
|
width: calc(100% - 60px);
|
height: 30px;
|
background: #fff;
|
padding: 15px 30px;
|
p {
|
font-family: "PingFangSC-Regular";
|
text-align: left;
|
font-size: 14px;
|
line-height: 30px;
|
}
|
}
|
.orderBody {
|
width: calc(100% - 40px);
|
//height: calc(100% - 100px);
|
padding: 20px;
|
background: #f0f2f5;
|
}
|
}
|
.info-block {
|
background: #fff;
|
padding: 20px;
|
.info-header {
|
border-bottom: 1px solid #eee;
|
display: flex;
|
padding: 10px 5px;
|
margin-bottom: 10px;
|
.title {
|
font-size: 15px;
|
font-weight: bold;
|
margin-right: 16px;
|
}
|
}
|
.info-body {
|
display: flex;
|
width: 100%;
|
margin-bottom: 20px;
|
.left,
|
.right {
|
width: 50%;
|
text-align: left;
|
.el-input-group__append {
|
color: #999;
|
}
|
.el-select {
|
width: 100%;
|
}
|
.el-upload {
|
width: 100px;
|
height: 100px;
|
line-height: 100px;
|
}
|
|
.des {
|
position: absolute;
|
top: 110px;
|
left: 175px;
|
font-size: 12px;
|
}
|
}
|
.el-table {
|
overflow: hidden;
|
}
|
.el-table th {
|
background: rgb(248, 248, 248);
|
color: rgb(34, 34, 34);
|
}
|
.operation {
|
font-size: 20px;
|
cursor: pointer;
|
.el-icon-top {
|
color: #409eff;
|
margin-right: 10px;
|
}
|
.el-icon-remove-outline {
|
color: red;
|
}
|
.el-icon-edit {
|
margin-right: 10px;
|
}
|
}
|
}
|
.form-end {
|
padding-top: 20px;
|
}
|
}
|
.toAdd {
|
font-size: 13px;
|
color: #3d68e1;
|
cursor: pointer;
|
i {
|
font-size: 15px;
|
margin-right: 2px;
|
}
|
}
|
.avatar-uploader {
|
float: left;
|
}
|
.second-icon-desc {
|
float: left;
|
margin-left: 50px;
|
}
|
.avatar-uploader .el-upload {
|
border-radius: 6px;
|
cursor: pointer;
|
position: relative;
|
overflow: hidden;
|
}
|
.avatar-uploader .el-upload-dragger {
|
width: 100px;
|
height: 100px;
|
}
|
.avatar-uploader .el-upload:hover {
|
border-color: #409eff;
|
}
|
.avatar-uploader-icon {
|
font-size: 28px;
|
color: #8c939d;
|
}
|
.avatar {
|
width: 178px;
|
height: 178px;
|
display: block;
|
}
|
</style>
|