This commit is contained in:
linfeng 2022-12-19 10:55:47 +08:00
parent 8c3b88e27e
commit f720ccea0f

View File

@ -2,8 +2,15 @@
<el-dialog
:title="!dataForm.id ? '新增' : '修改'"
:close-on-click-modal="false"
:visible.sync="visible">
<el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
:visible.sync="visible"
>
<el-form
:model="dataForm"
:rules="dataRule"
ref="dataForm"
@keyup.enter.native="dataFormSubmit()"
label-width="80px"
>
<el-form-item label="标题" prop="title">
<el-input v-model="dataForm.title" placeholder="标题"></el-input>
</el-form-item>
@ -14,11 +21,7 @@
:show-file-list="false"
:on-success="handleIconSuccess"
>
<img
v-if="dataForm.img"
:src="dataForm.img"
class="avatar"
/>
<img v-if="dataForm.img" :src="dataForm.img" class="avatar" />
<i v-else class="el-icon-plus avatar-uploader-icon" />
</el-upload>
<p class="formInfo">建议尺寸500*250像素jpgpng图片类型</p>
@ -32,103 +35,99 @@
</template>
<script>
export default {
data () {
export default {
data() {
return {
url: "",
visible: false,
dataForm: {
id: 0,
title: '',
url: '',
img: '',
type: '',
createTime: ''
title: "",
url: "",
img: "",
type: "",
createTime: "",
},
dataRule: {
title: [
{ required: true, message: '标题不能为空', trigger: 'blur' }
],
url: [
{ required: true, message: '路径不能为空', trigger: 'blur' }
],
img: [
{ required: true, message: '图片不能为空', trigger: 'blur' }
],
title: [{ required: true, message: "标题不能为空", trigger: "blur" }],
url: [{ required: true, message: "路径不能为空", trigger: "blur" }],
img: [{ required: true, message: "图片不能为空", trigger: "blur" }],
type: [
{ required: true, message: '3圈子页轮播图不能为空', trigger: 'blur' }
{ required: true, message: "3圈子页轮播图不能为空", trigger: "blur" },
],
createTime: [
{ required: true, message: '创建时间不能为空', trigger: 'blur' }
]
}
}
{ required: true, message: "创建时间不能为空", trigger: "blur" },
],
},
};
},
methods: {
init (id) {
this.dataForm.id = id || 0
init(id) {
this.dataForm.id = id || 0;
this.url = this.$http.adornUrl(
`/sys/oss/upload?token=${this.$cookie.get("token")}`
);
this.visible = true
this.visible = true;
this.$nextTick(() => {
this.$refs['dataForm'].resetFields()
this.$refs["dataForm"].resetFields();
if (this.dataForm.id) {
this.$http({
url: this.$http.adornUrl(`/admin/link/info/${this.dataForm.id}`),
method: 'get',
params: this.$http.adornParams()
}).then(({data}) => {
method: "get",
params: this.$http.adornParams(),
}).then(({ data }) => {
if (data && data.code === 0) {
this.dataForm.title = data.link.title
this.dataForm.url = data.link.url
this.dataForm.img = data.link.img
this.dataForm.type = data.link.type
this.dataForm.createTime = data.link.createTime
this.dataForm.title = data.link.title;
this.dataForm.url = data.link.url;
this.dataForm.img = data.link.img;
this.dataForm.type = data.link.type;
this.dataForm.createTime = data.link.createTime;
}
})
});
}
})
});
},
//
dataFormSubmit () {
this.$refs['dataForm'].validate((valid) => {
dataFormSubmit() {
this.$refs["dataForm"].validate((valid) => {
if (valid) {
this.$http({
url: this.$http.adornUrl(`/admin/link/${!this.dataForm.id ? 'save' : 'update'}`),
method: 'post',
url: this.$http.adornUrl(
`/admin/link/${!this.dataForm.id ? "save" : "update"}`
),
method: "post",
data: this.$http.adornData({
'id': this.dataForm.id || undefined,
'title': this.dataForm.title,
'url': this.dataForm.url,
'img': this.dataForm.img,
'type': this.dataForm.type,
'createTime': this.dataForm.createTime
})
}).then(({data}) => {
id: this.dataForm.id || undefined,
title: this.dataForm.title,
url: this.dataForm.url,
img: this.dataForm.img,
type: this.dataForm.type,
createTime: this.dataForm.createTime,
}),
}).then(({ data }) => {
if (data && data.code === 0) {
this.$message({
message: '操作成功',
type: 'success',
message: "操作成功",
type: "success",
duration: 1500,
onClose: () => {
this.visible = false
this.$emit('refreshDataList')
}
})
this.visible = false;
this.$emit("refreshDataList");
},
});
} else {
this.$message.error(data.msg)
this.$message.error(data.msg);
}
})
});
}
})
});
},
handleIconSuccess(response) {
this.dataForm.img = response.url;
this.$forceUpdate();
},
}
}
},
};
</script>
<style lang="scss">
.formInfo {