middleground_code_v2/src/views/applicationList/applicationAdd.vue

442 lines
12 KiB
Vue
Raw Normal View History

2024-03-26 11:18:19 +08:00
<script src="configData.js"></script>
<template>
<div class="wrap">
<div class="btn">
<div class="chunk">
2024-07-02 09:03:23 +08:00
<el-button
icon="el-icon-back"
@click="
2024-03-26 11:18:19 +08:00
$router.replace({ path: '/applicationList/applicationListAdmin' })
"
2024-07-02 09:03:23 +08:00
>返回
</el-button>
2024-03-26 11:18:19 +08:00
</div>
<div class="chunk">
2024-07-02 09:03:23 +08:00
<el-button
icon="el-icon-first-aid-kit"
type="primary"
@click="saveHandle"
>保存</el-button
>
2024-03-26 11:18:19 +08:00
</div>
</div>
<div class="main">
2024-03-26 11:18:19 +08:00
<div class="upload">
<div class="title">应用信息</div>
<div class="uploadMain">
<div class="left">
<div class="title">应用logo</div>
2024-07-02 09:03:23 +08:00
<el-upload
class="avatar-uploader"
ref="upload"
action="https://jsonplaceholder.typicode.com/posts/"
:on-preview="handlePreview"
:on-progress="handleProgress"
:before-upload="beforeUpload"
list-type="picture"
:limit="1"
:disabled="lookFlag"
:on-success="handleAvatarSuccess"
:show-file-list="false"
>
2024-03-26 11:18:19 +08:00
<div class="line">
<div class="left">
2024-07-02 09:03:23 +08:00
<img
v-if="imgUrl"
:src="imgUrl"
class="avatar"
@error="handleImageError"
/>
2024-03-26 11:18:19 +08:00
<!-- <el-image style="width: 64px; height: 64px" :src="iconBase64" fit="cover" alt="点击上传">
<template v-slot:error>
<div style="line-height: 64px; font-size: 12px">
logo上传
</div>
</template>
</el-image> -->
</div>
<div class="right" v-if="!lookFlag">
2024-07-02 09:03:23 +08:00
<el-button size="small" type="primary" v-if="!loading"
>点击上传</el-button
>
<el-button
size="small"
type="primary"
:loading="loading"
v-else
>上传中</el-button
>
2024-03-26 11:18:19 +08:00
</div>
</div>
<div slot="tip" class="el-upload__tip" v-if="!lookFlag">
只能上传jpg/png文件且不超过2MB
</div>
</el-upload>
</div>
<div class="right">
2024-07-02 09:03:23 +08:00
<el-switch
active-value="1"
inactive-value="2"
v-model="appStatus"
active-text="启用"
active-color="#60c958"
:disabled="lookFlag"
>
2024-03-26 11:18:19 +08:00
</el-switch>
</div>
</div>
</div>
<div class="form">
2024-07-02 09:03:23 +08:00
<baseNewForm
ref="mainForm"
:spanNumber="24"
:isFunBtn="false"
:lookFlag="lookFlag"
:formRule="!lookFlag"
:formRow="formRow"
:ruleForm="ruleForm"
@onSubmit="onSubmit"
></baseNewForm>
2024-03-26 11:18:19 +08:00
</div>
</div>
</div>
</template>
<script>
2024-07-02 09:03:23 +08:00
import { getApiModuleApi } from "@/api/apiChunks/index.js";
import { uploadLogo } from "@/api/apis/logo.js";
import configData from "./configData";
import baseNewForm from "@/views/intergrationTask/compoments/baseNewForm";
import request from "@/utils/request";
2024-03-26 11:18:19 +08:00
export default {
data() {
return {
fileList: [],
2024-07-02 09:03:23 +08:00
iconBase64: "",
imgUrl: "",
2024-03-26 11:18:19 +08:00
loading: false,
2024-07-02 09:03:23 +08:00
appLogo: "",
2024-03-26 11:18:19 +08:00
appStatus: 1,
ruleForm: {
2024-07-02 09:03:23 +08:00
accessMode: [],
2024-03-26 11:18:19 +08:00
},
lookFlag: false,
2024-07-02 09:03:23 +08:00
formRow: configData.addForm,
};
2024-03-26 11:18:19 +08:00
},
methods: {
handleImageError(row) {
2024-07-02 09:03:23 +08:00
this.imgUrl = require("./images/1.png");
},
2024-03-26 11:18:19 +08:00
// 文件上传相关时间
handleProgress(file, fileList) {
2024-07-02 09:03:23 +08:00
this.loading = true;
this.handleAvatarSuccess({}, fileList).then((res) => {
this.loading = false;
});
2024-03-26 11:18:19 +08:00
},
2024-07-02 09:03:23 +08:00
handlePreview(file) {},
2024-03-26 11:18:19 +08:00
async handleAvatarSuccess(res, file) {
2024-07-02 09:03:23 +08:00
file.raw.type;
if (
2024-07-02 09:03:23 +08:00
file.raw.type.split("/")[1] != "jpeg" &&
file.raw.type.split("/")[1] != "png"
) {
2024-07-02 09:03:23 +08:00
return false;
} else if (file.size >= 2000000) {
2024-07-02 09:03:23 +08:00
return false;
}
2024-07-02 09:03:23 +08:00
this.$refs.upload.clearFiles(); //清理文件上传状态
2024-03-26 11:18:19 +08:00
2024-07-02 09:03:23 +08:00
this.imgUrl = URL.createObjectURL(file.raw);
let formData = new FormData();
formData.append("file", file.raw);
formData.append("fileFlag", true);
formData.append("businessType", "application");
2024-03-26 11:18:19 +08:00
// console.log(formData);
// const el = await uploadLogo(formData)
// if (el.status === '200') {
// this.$vmNews("上传成功", "success")
// this.appLogo = el.id
// }
return request({
2024-07-02 09:03:23 +08:00
url: "/kangarooDataCenterV3/entranceController/fileUpload",
method: "post",
data: formData,
2024-03-26 11:18:19 +08:00
}).then((res) => {
2024-07-02 09:03:23 +08:00
if (res.status === "200") {
this.$vmNews("上传成功", "success");
this.appLogo = res.attribute.id;
2024-03-26 11:18:19 +08:00
}
2024-07-02 09:03:23 +08:00
return true;
2024-03-26 11:18:19 +08:00
// this.loading = false
2024-07-02 09:03:23 +08:00
});
},
2024-03-26 11:18:19 +08:00
async beforeUpload(file) {
if (
2024-07-02 09:03:23 +08:00
file.type.split("/")[1] != "jpeg" &&
file.type.split("/")[1] != "png"
2024-03-26 11:18:19 +08:00
) {
this.$message({
2024-07-02 09:03:23 +08:00
type: "warning",
message: "只能上传jpg/png文件",
});
return false;
2024-03-26 11:18:19 +08:00
} else {
if (file.size >= 2000000) {
this.$message({
2024-07-02 09:03:23 +08:00
type: "warning",
message: "文件大小不超过2MB",
});
return false;
2024-03-26 11:18:19 +08:00
}
// let reader = new FileReader();
// let that = this;
// reader.onloadend = function () {
// // 将文件转换成base64字符串
// var base64String = reader.result;
// that.iconBase64 = base64String;
// };
// reader.readAsDataURL(file);
// return false;
}
2024-07-02 09:03:23 +08:00
},
2024-03-26 11:18:19 +08:00
// 保存按钮、列表验证
saveHandle() {
2024-07-02 09:03:23 +08:00
this.$refs.mainForm.submitForm();
},
2024-03-26 11:18:19 +08:00
//验证成功准备上传
async onSubmit() {
2024-07-02 09:03:23 +08:00
if (this.$route.query.flag === "add") {
const res = await getApiModuleApi(
{
tl: "sysApplicationService",
as: "application",
dj: "saveApp",
},
{ ...this.ruleForm, appStatus: this.appStatus, appLogo: this.appLogo }
);
if (res.status === "200") {
this.$vmNews("保存成功", "success");
this.$router.replace({
path: "/applicationList/applicationListAdmin",
});
2024-03-26 11:18:19 +08:00
}
2024-07-02 09:03:23 +08:00
} else if (this.$route.query.flag === "copy") {
const res = await getApiModuleApi(
{
tl: "sysApplicationService",
as: "application",
dj: "copyApp",
},
{ ...this.ruleForm, appStatus: this.appStatus, appLogo: this.appLogo }
);
if (res.status === "200") {
this.$vmNews("复制成功", "success");
this.$router.replace({
path: "/applicationList/applicationListAdmin",
});
2024-03-26 11:18:19 +08:00
}
2024-07-02 09:03:23 +08:00
} else if (this.$route.query.flag === "setting") {
const res = await getApiModuleApi(
{
tl: "sysApplicationService",
as: "application",
dj: "updateApp",
},
{
updateType: 1,
...this.ruleForm,
appStatus: this.appStatus,
appLogo: this.appLogo,
}
);
if (res.status === "200") {
this.$vmNews("保存成功", "success");
this.initEditFormData();
this.getLogoUrl();
this.$emit("saveSuccess");
2024-03-26 11:18:19 +08:00
}
}
2024-07-02 09:03:23 +08:00
},
2024-03-26 11:18:19 +08:00
// 获取下拉数据
async initSelectOptions() {
let params = {
2024-07-02 09:03:23 +08:00
tab_name: "sys_product",
column_name: "classify",
};
const res = await getApiModuleApi(
{
tl: "generalServiceImpl",
as: "dictionaryshop",
dj: "selectDictionaryshop",
},
params
);
this.formRow[3].elCol[0].options = [];
2024-03-26 11:18:19 +08:00
res.attribute.forEach((item) => {
this.formRow[3].elCol[0].options.push({
label: item.column_content,
2024-07-02 09:03:23 +08:00
id: item.column_value,
});
});
},
2024-03-26 11:18:19 +08:00
// 复制-获取表单数据
async initCopyFormData() {
2024-07-02 09:03:23 +08:00
const res = await getApiModuleApi(
{
tl: "sysApplicationService",
as: "application",
dj: "getCopyApp",
},
{ id: this.$route.query.id }
);
this.ruleForm = res.attribute;
this.ruleForm.accessMode = JSON.parse(res.attribute.accessMode);
this.appStatus = res.attribute.appStatus;
},
2024-03-26 11:18:19 +08:00
async initEditFormData() {
2024-07-02 09:03:23 +08:00
const res = await getApiModuleApi(
{
tl: "sysApplicationService",
as: "application",
dj: "getApp",
},
{ id: this.$route.query.id }
);
this.ruleForm = res.attribute;
this.ruleForm.accessMode = JSON.parse(res.attribute.accessMode);
this.appStatus = res.attribute.appStatus;
},
2024-03-26 11:18:19 +08:00
//下载logo
getLogoUrl() {
2024-07-02 09:03:23 +08:00
let id = this.appLogo ? this.appLogo : this.$route.query.appLogo;
2024-03-26 11:18:19 +08:00
return request({
2024-07-02 09:03:23 +08:00
url:
"/kangarooDataCenterV3/entranceController/fileDownloadNew?id=" + id,
method: "get",
responseType: "arraybuffer",
2024-03-26 11:18:19 +08:00
}).then((res) => {
this.imgUrl =
2024-07-02 09:03:23 +08:00
"data:image/png/jpg;base64," +
btoa(
new Uint8Array(res).reduce(
(data, byte) => data + String.fromCharCode(byte),
""
)
);
});
},
2024-03-26 11:18:19 +08:00
},
components: {
2024-07-02 09:03:23 +08:00
baseNewForm,
2024-03-26 11:18:19 +08:00
},
created() {
// 请求下拉options
2024-07-02 09:03:23 +08:00
this.initSelectOptions();
2024-03-26 11:18:19 +08:00
// 判断是什么类型进来的
2024-07-02 09:03:23 +08:00
if (this.$route.query.flag === "setting") {
this.formRow[0].elCol[0].disabled = false;
2024-03-26 11:18:19 +08:00
} else {
2024-07-02 09:03:23 +08:00
this.formRow[0].elCol[0].disabled = false;
2024-03-26 11:18:19 +08:00
}
2024-07-02 09:03:23 +08:00
if (this.$route.query.flag === "copy") {
this.initCopyFormData();
this.getLogoUrl();
} else if (this.$route.query.flag === "setting") {
this.initEditFormData();
this.getLogoUrl();
2024-03-26 11:18:19 +08:00
}
2024-07-02 09:03:23 +08:00
},
};
2024-03-26 11:18:19 +08:00
</script>
<style scoped lang="scss">
::v-deep .el-button {
border-radius: 4px;
2024-03-26 11:18:19 +08:00
}
2024-03-26 11:18:19 +08:00
::v-deep .el-form-item {
display: block !important;
}
2024-03-26 11:18:19 +08:00
.wrap {
background-color: #fbfbfb;
width: 100%;
overflow: auto;
2024-03-26 11:18:19 +08:00
> .btn {
display: flex;
justify-content: flex-end;
2024-03-26 11:18:19 +08:00
> .chunk {
margin-left: 10px;
}
}
2024-03-26 11:18:19 +08:00
> .main {
margin-top: 10px;
2024-03-26 11:18:19 +08:00
> .upload {
background-color: #fff;
border-radius: 16px;
padding: 24px 30px;
2024-03-26 11:18:19 +08:00
> .title {
font-size: 18px;
font-weight: 600;
}
2024-03-26 11:18:19 +08:00
> .uploadMain {
margin-top: 20px;
display: flex;
align-items: center;
justify-content: space-between;
2024-03-26 11:18:19 +08:00
> .left {
> .title {
font-size: 18px;
color: #999999;
margin-bottom: 10px;
}
2024-03-26 11:18:19 +08:00
.line {
display: flex;
align-items: center;
2024-03-26 11:18:19 +08:00
.left {
border: 1px dashed #999999;
width: 64px;
height: 64px;
display: flex;
justify-content: center;
align-items: center;
2024-03-26 11:18:19 +08:00
> img {
width: 100%;
// height: 100%;
2024-03-26 11:18:19 +08:00
}
}
2024-03-26 11:18:19 +08:00
.right {
margin-left: 15px;
}
}
}
}
}
2024-03-26 11:18:19 +08:00
> .form {
overflow: auto;
margin-top: 10px;
background-color: #fff;
border-radius: 16px;
width: 100%;
padding: 10px 20px;
}
}
}
</style>