|
|
<template>
|
|
|
<!-- 添加/编辑页面容器 -->
|
|
|
<div class="addEdit-block">
|
|
|
<!-- 表单组件 -->
|
|
|
<el-form
|
|
|
class="detail-form-content"
|
|
|
ref="ruleForm"
|
|
|
:model="ruleForm"
|
|
|
:rules="rules"
|
|
|
label-width="80px"
|
|
|
:style="{backgroundColor:addEditForm.addEditBoxColor}" <!-- 设置表单背景颜色 -->
|
|
|
>
|
|
|
<el-row> <!-- 表单布局行 -->
|
|
|
<el-col :span="12"> <!-- 左侧列,宽度为12 -->
|
|
|
<el-form-item class="input" v-if="type!='info'" label="收藏id" prop="refid"> <!-- 收藏id输入框 -->
|
|
|
<el-input v-model="ruleForm.refid"
|
|
|
placeholder="收藏id" clearable :readonly="ro.refid"></el-input>
|
|
|
</el-form-item>
|
|
|
<div v-else> <!-- 如果是查看模式,显示只读输入框 -->
|
|
|
<el-form-item class="input" label="收藏id" prop="refid">
|
|
|
<el-input v-model="ruleForm.refid"
|
|
|
placeholder="收藏id" readonly></el-input>
|
|
|
</el-form-item>
|
|
|
</div>
|
|
|
</el-col>
|
|
|
<el-col :span="12"> <!-- 右侧列,宽度为12 -->
|
|
|
<el-form-item class="input" v-if="type!='info'" label="表名" prop="tablename"> <!-- 表名输入框 -->
|
|
|
<el-input v-model="ruleForm.tablename"
|
|
|
placeholder="表名" clearable :readonly="ro.tablename"></el-input>
|
|
|
</el-form-item>
|
|
|
<div v-else> <!-- 如果是查看模式,显示只读输入框 -->
|
|
|
<el-form-item class="input" label="表名" prop="tablename">
|
|
|
<el-input v-model="ruleForm.tablename"
|
|
|
placeholder="表名" readonly></el-input>
|
|
|
</el-form-item>
|
|
|
</div>
|
|
|
</el-col>
|
|
|
<el-col :span="12"> <!-- 左侧列,宽度为12 -->
|
|
|
<el-form-item class="input" v-if="type!='info'" label="收藏名称" prop="name"> <!-- 收藏名称输入框 -->
|
|
|
<el-input v-model="ruleForm.name"
|
|
|
placeholder="收藏名称" clearable :readonly="ro.name"></el-input>
|
|
|
</el-form-item>
|
|
|
<div v-else> <!-- 如果是查看模式,显示只读输入框 -->
|
|
|
<el-form-item class="input" label="收藏名称" prop="name">
|
|
|
<el-input v-model="ruleForm.name"
|
|
|
placeholder="收藏名称" readonly></el-input>
|
|
|
</el-form-item>
|
|
|
</div>
|
|
|
</el-col>
|
|
|
<el-col :span="24"> <!-- 占满整行 -->
|
|
|
<el-form-item class="upload" v-if="type!='info' && !ro.picture" label="收藏图片" prop="picture"> <!-- 图片上传组件 -->
|
|
|
<file-upload
|
|
|
tip="点击上传收藏图片"
|
|
|
action="file/upload"
|
|
|
:limit="3"
|
|
|
:multiple="true"
|
|
|
:fileUrls="ruleForm.picture?ruleForm.picture:''"
|
|
|
@change="pictureUploadChange"
|
|
|
></file-upload>
|
|
|
</el-form-item>
|
|
|
<div v-else> <!-- 如果是查看模式或只读,显示图片 -->
|
|
|
<el-form-item v-if="ruleForm.picture" label="收藏图片" prop="picture">
|
|
|
<img style="margin-right:20px;" v-bind:key="index" v-for="(item,index) in ruleForm.picture.split(',')" :src="item" width="100" height="100">
|
|
|
</el-form-item>
|
|
|
</div>
|
|
|
</el-col>
|
|
|
</el-row>
|
|
|
<el-form-item class="btn"> <!-- 按钮容器 -->
|
|
|
<el-button v-if="type!='info'" type="primary" class="btn-success" @click="onSubmit">提交</el-button> <!-- 提交按钮 -->
|
|
|
<el-button v-if="type!='info'" class="btn-close" @click="back()">取消</el-button> <!-- 取消按钮 -->
|
|
|
<el-button v-if="type=='info'" class="btn-close" @click="back()">返回</el-button> <!-- 返回按钮 -->
|
|
|
</el-form-item>
|
|
|
</el-form>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
// 引入验证工具函数
|
|
|
import { isNumber,isIntNumer,isEmail,isPhone, isMobile,isURL,checkIdCard } from "@/utils/validate";
|
|
|
|
|
|
export default {
|
|
|
data() {
|
|
|
let self = this
|
|
|
// 定义身份证验证规则
|
|
|
var validateIdCard = (rule, value, callback) => {
|
|
|
if(!value){
|
|
|
callback();
|
|
|
} else if (!checkIdCard(value)) {
|
|
|
callback(new Error("请输入正确的身份证号码"));
|
|
|
} else {
|
|
|
callback();
|
|
|
}
|
|
|
};
|
|
|
// 定义URL验证规则
|
|
|
var validateUrl = (rule, value, callback) => {
|
|
|
if(!value){
|
|
|
callback();
|
|
|
} else if (!isURL(value)) {
|
|
|
callback(new Error("请输入正确的URL地址"));
|
|
|
} else {
|
|
|
callback();
|
|
|
}
|
|
|
};
|
|
|
// 定义手机号验证规则
|
|
|
var validateMobile = (rule, value, callback) => {
|
|
|
if(!value){
|
|
|
callback();
|
|
|
} else if (!isMobile(value)) {
|
|
|
callback(new Error("请输入正确的手机号码"));
|
|
|
} else {
|
|
|
callback();
|
|
|
}
|
|
|
};
|
|
|
// 定义电话号验证规则
|
|
|
var validatePhone = (rule, value, callback) => {
|
|
|
if(!value){
|
|
|
callback();
|
|
|
} else if (!isPhone(value)) {
|
|
|
callback(new Error("请输入正确的电话号码"));
|
|
|
} else {
|
|
|
callback();
|
|
|
}
|
|
|
};
|
|
|
// 定义邮箱验证规则
|
|
|
var validateEmail = (rule, value, callback) => {
|
|
|
if(!value){
|
|
|
callback();
|
|
|
} else if (!isEmail(value)) {
|
|
|
callback(new Error("请输入正确的邮箱地址"));
|
|
|
} else {
|
|
|
callback();
|
|
|
}
|
|
|
};
|
|
|
// 定义数字验证规则
|
|
|
var validateNumber = (rule, value, callback) => {
|
|
|
if(!value){
|
|
|
callback();
|
|
|
} else if (!isNumber(value)) {
|
|
|
callback(new Error("请输入数字"));
|
|
|
} else {
|
|
|
callback();
|
|
|
}
|
|
|
};
|
|
|
// 定义整数验证规则
|
|
|
var validateIntNumber = (rule, value, callback) => {
|
|
|
if(!value){
|
|
|
callback();
|
|
|
} else if (!isIntNumer(value)) {
|
|
|
callback(new Error("请输入整数"));
|
|
|
} else {
|
|
|
callback();
|
|
|
}
|
|
|
};
|
|
|
return {
|
|
|
// 表单样式配置
|
|
|
addEditForm: { /* 样式配置参数 */ },
|
|
|
id: '',
|
|
|
type: '',
|
|
|
ro:{
|
|
|
// 各字段只读状态配置
|
|
|
userid : false,
|
|
|
refid : false,
|
|
|
tablename : false,
|
|
|
name : false,
|
|
|
picture : false,
|
|
|
},
|
|
|
// 表单数据模型
|
|
|
ruleForm: {
|
|
|
userid: '',
|
|
|
refid: '',
|
|
|
tablename: '',
|
|
|
name: '',
|
|
|
picture: '',
|
|
|
},
|
|
|
// 表单验证规则
|
|
|
rules: {
|
|
|
userid: [
|
|
|
{ required: true, message: '用户id不能为空', trigger: 'blur' }, // 必填验证
|
|
|
],
|
|
|
refid: [
|
|
|
],
|
|
|
tablename: [
|
|
|
],
|
|
|
name: [
|
|
|
{ required: true, message: '收藏名称不能为空', trigger: 'blur' }, // 必填验证
|
|
|
],
|
|
|
picture: [
|
|
|
{ required: true, message: '收藏图片不能为空', trigger: 'blur' }, // 必填验证
|
|
|
],
|
|
|
}
|
|
|
};
|
|
|
},
|
|
|
props: ["parent"], // 定义父组件传入的属性
|
|
|
computed: {
|
|
|
},
|
|
|
created() {
|
|
|
this.addEditStyleChange() // 调用样式更新方法
|
|
|
this.addEditUploadStyleChange() // 调用上传组件样式更新方法
|
|
|
},
|
|
|
methods: {
|
|
|
// 下载文件方法
|
|
|
download(file){
|
|
|
window.open(`${file}`)
|
|
|
},
|
|
|
// 初始化方法
|
|
|
init(id,type) {
|
|
|
if (id) {
|
|
|
this.id = id; // 设置当前ID
|
|
|
this.type = type; // 设置当前类型
|
|
|
}
|
|
|
if(this.type=='info'||this.type=='else'){ // 如果是查看或编辑模式
|
|
|
this.info(id); // 获取详细信息
|
|
|
}else if(this.type=='cross'){ // 如果是关联模式
|
|
|
var obj = this.$storage.getObj('crossObj'); // 获取关联对象
|
|
|
for (var o in obj){ // 遍历关联对象属性
|
|
|
if(o=='userid'){
|
|
|
this.ruleForm.userid = obj[o]; // 设置用户id
|
|
|
this.ro.userid = true; // 设置为只读
|
|
|
continue;
|
|
|
}
|
|
|
if(o=='refid'){
|
|
|
this.ruleForm.refid = obj[o]; // 设置收藏id
|
|
|
this.ro.refid = true; // 设置为只读
|
|
|
continue;
|
|
|
}
|
|
|
if(o=='tablename'){
|
|
|
this.ruleForm.tablename = obj[o]; // 设置表名
|
|
|
this.ro.tablename = true; // 设置为只读
|
|
|
continue;
|
|
|
}
|
|
|
if(o=='name'){
|
|
|
this.ruleForm.name = obj[o]; // 设置收藏名称
|
|
|
this.ro.name = true; // 设置为只读
|
|
|
continue;
|
|
|
}
|
|
|
if(o=='picture'){
|
|
|
this.ruleForm.picture = obj[o]; // 设置收藏图片
|
|
|
this.ro.picture = true; // 设置为只读
|
|
|
continue;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
// 获取详细信息方法
|
|
|
info(id) {
|
|
|
this.$http({
|
|
|
url: `storeup/info/${id}`,
|
|
|
method: "get"
|
|
|
}).then(({ data }) => {
|
|
|
if (data && data.code === 0) {
|
|
|
this.ruleForm = data.data; // 更新表单数据
|
|
|
} else {
|
|
|
this.$message.error(data.msg);
|
|
|
}
|
|
|
});
|
|
|
},
|
|
|
// 提交表单方法
|
|
|
onSubmit() {
|
|
|
// 表单验证并提交
|
|
|
this.$refs["ruleForm"].validate(valid => {
|
|
|
if (valid) {
|
|
|
this.$http({
|
|
|
url: `storeup/${!this.ruleForm.id ? "save" : "update"}`, // 请求保存或更新接口
|
|
|
method: "post",
|
|
|
data: this.ruleForm
|
|
|
}).then(({ data }) => {
|
|
|
if (data && data.code === 0) {
|
|
|
this.$message({
|
|
|
message: "操作成功", // 显示成功消息
|
|
|
type: "success",
|
|
|
duration: 1500,
|
|
|
onClose: () => {
|
|
|
this.parent.showFlag = true; // 显示列表页
|
|
|
this.parent.addOrUpdateFlag = false; // 隐藏表单页
|
|
|
this.parent.storeupCrossAddOrUpdateFlag = false; // 隐藏关联表单页
|
|
|
this.parent.search(); // 刷新列表
|
|
|
this.parent.contentStyleChange(); // 更新列表样式
|
|
|
}
|
|
|
});
|
|
|
} else {
|
|
|
this.$message.error(data.msg); // 显示错误消息
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
});
|
|
|
},
|
|
|
// 获取唯一标识符方法
|
|
|
getUUID () {
|
|
|
return new Date().getTime();
|
|
|
},
|
|
|
// 返回方法
|
|
|
back() {
|
|
|
this.parent.showFlag = true; // 显示列表页
|
|
|
this.parent.addOrUpdateFlag = false; // 隐藏表单页
|
|
|
this.parent.storeupCrossAddOrUpdateFlag = false; // 隐藏关联表单页
|
|
|
this.parent.contentStyleChange(); // 更新列表样式
|
|
|
},
|
|
|
// 图片上传变更方法
|
|
|
pictureUploadChange(fileUrls) {
|
|
|
this.ruleForm.picture = fileUrls; // 更新图片数据
|
|
|
this.addEditUploadStyleChange(); // 更新上传组件样式
|
|
|
},
|
|
|
addEditStyleChange() { // 更新表单样式方法
|
|
|
this.$nextTick(()=>{ // 在DOM更新后执行
|
|
|
// 更新input样式
|
|
|
document.querySelectorAll('.addEdit-block .input .el-input__inner').forEach(el=>{
|
|
|
el.style.height = this.addEditForm.inputHeight;
|
|
|
el.style.color = this.addEditForm.inputFontColor;
|
|
|
el.style.fontSize = this.addEditForm.inputFontSize;
|
|
|
el.style.borderWidth = this.addEditForm.inputBorderWidth;
|
|
|
el.style.borderStyle = this.addEditForm.inputBorderStyle;
|
|
|
el.style.borderColor = this.addEditForm.inputBorderColor;
|
|
|
el.style.borderRadius = this.addEditForm.inputBorderRadius;
|
|
|
el.style.backgroundColor = this.addEditForm.inputBgColor;
|
|
|
});
|
|
|
document.querySelectorAll('.addEdit-block .input .el-form-item__label').forEach(el=>{
|
|
|
el.style.lineHeight = this.addEditForm.inputHeight;
|
|
|
el.style.color = this.addEditForm.inputLableColor;
|
|
|
el.style.fontSize = this.addEditForm.inputLableFontSize;
|
|
|
});
|
|
|
// 更新select样式
|
|
|
document.querySelectorAll('.addEdit-block .select .el-input__inner').forEach(el=>{
|
|
|
el.style.height = this.addEditForm.selectHeight;
|
|
|
el.style.color = this.addEditForm.selectFontColor;
|
|
|
el.style.fontSize = this.addEditForm.selectFontSize;
|
|
|
el.style.borderWidth = this.addEditForm.selectBorderWidth;
|
|
|
el.style.borderStyle = this.addEditForm.selectBorderStyle;
|
|
|
el.style.borderColor = this.addEditForm.selectBorderColor;
|
|
|
el.style.borderRadius = this.addEditForm.selectBorderRadius;
|
|
|
el.style.backgroundColor = this.addEditForm.selectBgColor;
|
|
|
});
|
|
|
document.querySelectorAll('.addEdit-block .select .el-form-item__label').forEach(el=>{
|
|
|
el.style.lineHeight = this.addEditForm.selectHeight;
|
|
|
el.style.color = this.addEditForm.selectLableColor;
|
|
|
el.style.fontSize = this.addEditForm.selectLableFontSize;
|
|
|
});
|
|
|
document.querySelectorAll('.addEdit-block .select .el-select__caret').forEach(el=>{
|
|
|
el.style.color = this.addEditForm.selectIconFontColor;
|
|
|
el.style.fontSize = this.addEditForm.selectIconFontSize;
|
|
|
});
|
|
|
// 更新date样式
|
|
|
document.querySelectorAll('.addEdit-block .date .el-input__inner').forEach(el=>{
|
|
|
el.style.height = this.addEditForm.dateHeight;
|
|
|
el.style.color = this.addEditForm.dateFontColor;
|
|
|
el.style.fontSize = this.addEditForm.dateFontSize;
|
|
|
el.style.borderWidth = this.addEditForm.dateBorderWidth;
|
|
|
el.style.borderStyle = this.addEditForm.dateBorderStyle;
|
|
|
el.style.borderColor = this.addEditForm.dateBorderColor;
|
|
|
el.style.borderRadius = this.addEditForm.dateBorderRadius;
|
|
|
el.style.backgroundColor = this.addEditForm.dateBgColor;
|
|
|
});
|
|
|
document.querySelectorAll('.addEdit-block .date .el-form-item__label').forEach(el=>{
|
|
|
el.style.lineHeight = this.addEditForm.dateHeight;
|
|
|
el.style.color = this.addEditForm.dateLableColor;
|
|
|
el.style.fontSize = this.addEditForm.dateLableFontSize;
|
|
|
});
|
|
|
document.querySelectorAll('.addEdit-block .date .el-input__icon').forEach(el=>{
|
|
|
el.style.color = this.addEditForm.dateIconFontColor;
|
|
|
el.style.fontSize = this.addEditForm.dateIconFontSize;
|
|
|
el.style.lineHeight = this.addEditForm.dateHeight;
|
|
|
});
|
|
|
// 更新upload样式
|
|
|
let iconLineHeight = parseInt(this.addEditForm.uploadHeight) - parseInt(this.addEditForm.uploadBorderWidth) * 2 + 'px';
|
|
|
document.querySelectorAll('.addEdit-block .upload .el-upload--picture-card').forEach(el=>{
|
|
|
el.style.width = this.addEditForm.uploadHeight;
|
|
|
el.style.height = this.addEditForm.uploadHeight;
|
|
|
el.style.borderWidth = this.addEditForm.uploadBorderWidth;
|
|
|
el.style.borderStyle = this.addEditForm.uploadBorderStyle;
|
|
|
el.style.borderColor = this.addEditForm.uploadBorderColor;
|
|
|
el.style.borderRadius = this.addEditForm.uploadBorderRadius;
|
|
|
el.style.backgroundColor = this.addEditForm.uploadBgColor;
|
|
|
});
|
|
|
document.querySelectorAll('.addEdit-block .upload .el-form-item__label').forEach(el=>{
|
|
|
el.style.lineHeight = this.addEditForm.uploadHeight;
|
|
|
el.style.color = this.addEditForm.uploadLableColor;
|
|
|
el.style.fontSize = this.addEditForm.uploadLableFontSize;
|
|
|
});
|
|
|
document.querySelectorAll('.addEdit-block .upload .el-icon-plus').forEach(el=>{
|
|
|
el.style.color = this.addEditForm.uploadIconFontColor;
|
|
|
el.style.fontSize = this.addEditForm.uploadIconFontSize;
|
|
|
el.style.lineHeight = iconLineHeight;
|
|
|
el.style.display = 'block';
|
|
|
});
|
|
|
// 更新textarea样式
|
|
|
document.querySelectorAll('.addEdit-block .textarea .el-textarea__inner').forEach(el=>{
|
|
|
el.style.height = this.addEditForm.textareaHeight;
|
|
|
el.style.color = this.addEditForm.textareaFontColor;
|
|
|
el.style.fontSize = this.addEditForm.textareaFontSize;
|
|
|
el.style.borderWidth = this.addEditForm.textareaBorderWidth;
|
|
|
el.style.borderStyle = this.addEditForm.textareaBorderStyle;
|
|
|
el.style.borderColor = this.addEditForm.textareaBorderColor;
|
|
|
el.style.borderRadius = this.addEditForm.textareaBorderRadius;
|
|
|
el.style.backgroundColor = this.addEditForm.textareaBgColor;
|
|
|
});
|
|
|
document.querySelectorAll('.addEdit-block .textarea .el-form-item__label').forEach(el=>{
|
|
|
// el.style.lineHeight = this.addEditForm.textareaHeight
|
|
|
el.style.color = this.addEditForm.textareaLableColor;
|
|
|
el.style.fontSize = this.addEditForm.textareaLableFontSize;
|
|
|
});
|
|
|
// 更新按钮样式
|
|
|
document.querySelectorAll('.addEdit-block .btn .btn-success').forEach(el=>{
|
|
|
el.style.width = this.addEditForm.btnSaveWidth;
|
|
|
el.style.height = this.addEditForm.btnSaveHeight;
|
|
|
el.style.color = this.addEditForm.btnSaveFontColor;
|
|
|
el.style.fontSize = this.addEditForm.btnSaveFontSize;
|
|
|
el.style.borderWidth = this.addEditForm.btnSaveBorderWidth;
|
|
|
el.style.borderStyle = this.addEditForm.btnSaveBorderStyle;
|
|
|
el.style.borderColor = this.addEditForm.btnSaveBorderColor;
|
|
|
el.style.borderRadius = this.addEditForm.btnSaveBorderRadius;
|
|
|
el.style.backgroundColor = this.addEditForm.btnSaveBgColor;
|
|
|
});
|
|
|
// 更新取消按钮样式
|
|
|
document.querySelectorAll('.addEdit-block .btn .btn-close').forEach(el=>{
|
|
|
el.style.width = this.addEditForm.btnCancelWidth;
|
|
|
el.style.height = this.addEditForm.btnCancelHeight;
|
|
|
el.style.color = this.addEditForm.btnCancelFontColor;
|
|
|
el.style.fontSize = this.addEditForm.btnCancelFontSize;
|
|
|
el.style.borderWidth = this.addEditForm.btnCancelBorderWidth;
|
|
|
el.style.borderStyle = this.addEditForm.btnCancelBorderStyle;
|
|
|
el.style.borderColor = this.addEditForm.btnCancelBorderColor;
|
|
|
el.style.borderRadius = this.addEditForm.btnCancelBorderRadius;
|
|
|
el.style.backgroundColor = this.addEditForm.btnCancelBgColor;
|
|
|
});
|
|
|
});
|
|
|
},
|
|
|
addEditUploadStyleChange() { // 更新上传组件样式方法
|
|
|
this.$nextTick(()=>{ // 在DOM更新后执行
|
|
|
document.querySelectorAll('.addEdit-block .upload .el-upload-list--picture-card .el-upload-list__item').forEach(el=>{
|
|
|
el.style.width = this.addEditForm.uploadHeight;
|
|
|
el.style.height = this.addEditForm.uploadHeight;
|
|
|
el.style.borderWidth = this.addEditForm.uploadBorderWidth;
|
|
|
el.style.borderStyle = this.addEditForm.uploadBorderStyle;
|
|
|
el.style.borderColor = this.addEditForm.uploadBorderColor;
|
|
|
el.style.borderRadius = this.addEditForm.uploadBorderRadius;
|
|
|
el.style.backgroundColor = this.addEditForm.uploadBgColor;
|
|
|
});
|
|
|
});
|
|
|
},
|
|
|
}
|
|
|
};
|
|
|
</script>
|
|
|
|
|
|
<style lang="scss">
|
|
|
.editor{
|
|
|
height: 500px; <!-- 编辑器高度 -->
|
|
|
|
|
|
& /deep/ .ql-container { <!-- 编辑器内容区域 -->
|
|
|
height: 310px; <!-- 设置内容区域高度 -->
|
|
|
}
|
|
|
}
|
|
|
.amap-wrapper { <!-- 地图容器 -->
|
|
|
width: 100%; <!-- 宽度为100% -->
|
|
|
height: 500px; <!-- 高度为500px -->
|
|
|
}
|
|
|
.search-box { <!-- 搜索长度 -->
|
|
|
position: absolute; <!-- 绝对定位 -->
|
|
|
}
|
|
|
.addEdit-block { <!-- 表单容器 -->
|
|
|
margin: -10px; <!-- 外边距 -->
|
|
|
}
|
|
|
.detail-form-content { <!-- 表单内容 -->
|
|
|
padding: 12px; <!-- 内边距 -->
|
|
|
}
|
|
|
.btn .el-button { <!-- 按钮样式 -->
|
|
|
padding: 0; <!-- 无内边距 -->
|
|
|
}
|
|
|
</style> |