弹窗/或者点击按钮-路由跳转以后-再回来时要回显的问题

本文介绍在Vue.js中如何通过路由参数实现页面间的数据传递,并在返回原页面时利用mounted钩子处理数据,触发弹窗或其他业务逻辑。通过具体示例,展示了如何在点击事件中设置路由跳转并携带query数据,以及如何在目标页面接收并处理这些数据。
  • 原本路由 http://localhost:9528/#/example/careerman

  • 点击跳转到新路由 http://localhost:9528/#/example/application?employeeId=11823&type=1
    在这里插入图片描述

  • 点击按钮 x 要让老页面的弹窗展示
    在这里插入图片描述

  • 思路是在返回老页面时路由里面传值, 在老页面mounted是监听路由的值,让弹窗显示

clickGoBack() {
      // 点击事件 路由跳转,并且带上 query 数据
        this.$router.push({ path: '/example/careerman', query: { employeeId: this.employeeId }})
    }

点击 x 以后的路由

  • http://localhost:9528/#/example/careerman?employeeId=11823
mounted() {
    // 在mounted 事件中 对路由里面的数据处理 打开弹窗或者其他处理
    if (this.$route.query.employeeId) {
      if (typeof (this.$route.query.employeeId) === 'number') {
        this.$refs.personalData.openDialog(Number(this.$route.query.employeeId))
      }
    }
  },
下面代码修改页面的数据不能返回到提货地址的下拉框里面:<template> <div class="container"> <el-tabs type="border-card"> <el-tab-pane :label="title"> <el-form ref="form" :model="form" :rules="rules" label-width="120px"> <el-form-item label="介绍图片:" prop="cover"> <div style="display: flex;"> <div class="flex-row"> <el-upload class="avatar-uploader" action :http-request="selectPicUpload" :show-file-list="false" :before-upload="beforeAvatarUpload" :on-change="handleAvatarChange"> <img v-if="form.cover" :src="form.cover" class="avatar"> <i v-else class="el-icon-plus avatar-uploader-icon"></i> </el-upload> </div> </div> </el-form-item> <el-row> <el-col :span="12"> <el-form-item label="团购名称:" prop="name"> <el-input class="input" v-model="form.name" placeholder="请输入团购名称" /> </el-form-item> </el-col> <el-col :span="12"> <el-form-item label="自动截止:" prop="isAutoEnd"> <el-switch v-model="form.isAutoEnd" :active-value="true" :inactive-value="false" /> </el-form-item> </el-col> <el-col :span="12"> <el-form-item label="团购内容:" prop="detailInfo"> <el-input class="input" v-model="form.detailInfo" placeholder="请输入团购内容" /> <!-- <Tinymce v-model="form.detailInfo" :disabled="allDisabled"></Tinymce> --> </el-form-item> </el-col> <el-col :span="12"> <el-form-item label="开始间:" prop="startTime"> <el-date-picker clearable v-model="form.startTime" type="datetime" default-time="12:00:00" value-format="yyyy-MM-dd HH:mm:ss" placeholder="请选择活动开始间"> </el-date-picker> </el-form-item> </el-col> <el-col :span="12"> <el-form-item label="截止间:" prop="endTime"> <el-date-picker clearable v-model="form.endTime" type="datetime" default-time="12:00:00" value-format="yyyy-MM-dd HH:mm:ss" placeholder="请选择活动截止间"> </el-date-picker> </el-form-item> </el-col> <el-col :span="12"> <el-form-item label="最大接龙人数" prop="maxJoinNum"> <el-input class="input" v-model="form.maxJoinNum" placeholder="请输入" /> </el-form-item> </el-col> <el-col :span="12"> <el-form-item label="最小成交金额" > <el-input class="input" v-model="form.minAmount" placeholder="请输入" /> </el-form-item> </el-col> <el-col :span="12"> <el-form-item label="提货地址:" prop="addressIds"> <el-select v-model="form.addressIds" filterable placeholder="请选择" multiple> <el-option v-for="item in addressoptions" :key="item.id" :label="item.addressName" :value="item.id"> </el-option> </el-select> </el-form-item> </el-col> </el-row> <el-form-item label="其它信息:"> <el-checkbox-group v-model="form.selectedItemsOther"> <el-checkbox label="isGetRealName">真实姓名</el-checkbox> <el-checkbox label="isGetPhone">手机号码</el-checkbox> </el-checkbox-group> </el-form-item> <el-form-item label="功能选择:"> <el-checkbox-group v-model="form.selectedItemsFunction"> <el-checkbox label="isHideList">发布最新接龙列表</el-checkbox> <el-checkbox label="isHideOrderAmount">接龙金额仅创建人可见</el-checkbox> <el-checkbox label="canCancel">禁止用户取消订单</el-checkbox> </el-checkbox-group> </el-form-item> <div> <el-form-item label="商品信息:" prop="products"> <el-table :data="form.products" @selection-change="handleSelectionChange"> <el-table-column type="selection" width="55" align="center" /> <el-table-column label="商品名称" align="center" prop="product.name"> <template slot-scope="{row,$index}"> <el-input v-model="row.name" placeholder="请输入名称"></el-input> </template>" </el-table-column> <el-table-column label="商品价格" align="center" prop="products.price"> <template slot-scope="{row,$index}"> <el-input v-model="row.price" placeholder="请输入名称"></el-input> </template>" </el-table-column> <el-table-column label="商品数量" align="center" prop="products.soldNum"> <template slot-scope="{row,$index}"> <el-input v-model="row.soldNum" placeholder="请输入名称"><el-button icon="el-icon-remove-outline" @click="addmount()"></el-button></el-input> </template> </el-table-column> <el-table-column label="每单限制购买量" align="center" prop="products.limitNum" width="180"> <template slot-scope="{row,$index}"> <el-input v-model="row.limitNum" placeholder="请输入名称"></el-input> </template> </el-table-column> <el-table-column label="商品图片" align="center" prop="image" width="100"> <template slot-scope="{row,$index}"> <el-upload class="avatar-uploader" action :http-request="(fileObj) => selectProductUpload(fileObj, $index)" :show-file-list="false" :before-upload="beforeAvatarUpload"> <img v-if="row.image" :src="row.image" class="avatar"> <i v-else class="el-icon-plus avatar-uploader-icon"></i> </el-upload> </template> </el-table-column> <el-table-column label="操作" align="center" class-name="small-padding fixed-width"> <template slot-scope="scope"> <!-- <el-button size="mini" type="text" v-if="scope.row.status != '4'" icon="el-icon-edit" @click="openApproval(scope.row)" v-hasPermi="['solitaire:list:order']">添加 </el-button > --> <el-button @click="addproduct()"> 添加</el-button> <el-button type="danger" icon="el-icon-delete" :disabled="form.products.length <= 1" @click="removeRow(scope.$index)">删除</el-button> </template> </el-table-column> </el-table> </el-form-item> </div> </el-form> <!-- 修改/新增 --> <div class="dialog-footer"> <el-button type="primary" @click="submitForm">确 定</el-button> <el-button @click="handleBack">取 消</el-button> </div> </el-tab-pane> </el-tabs> </div> </template> <script> import { imgUrl } from '@/utils/request' import { getISOTime, checkLongitudeValidator, checkPointIsNumber } from '@/utils/parsing' import { checkPhone } from '@/utils/validate' import mapView from '@/components/MapContainer/index.vue' import { addGroupShop, editGroupBuy, getGroupBuyAddressPage, getGroupBuyDetail } from '@/api/solitaire/solitaire' import { uploadPic } from '@/api/activity/activity' import { onMounted, beforeDestroy } from 'vue' import { reset } from 'echarts/lib/visual/seriesColor' export default { components: { mapView }, onMounted() { }, watch: { '$route.query'(newVal) { if (!newVal.id) { this.title = "新增接龙"; this.resetForm(); // 重置表单方法 } } }, data() { return { addressoptions: [], addressList: [], currentTime: new Date().toLocaleTimeString(), timer: null, // 第一个复选框组绑定值 // 第二个复选框组绑定值 selectedItemsFunction: [], checkList: ['选中且禁用', '复选框 A'], checked: true, // 单个复选框的绑定 dataList: [], title: "新增接龙", // 封面图片 selectImgUrl: '', queryParams: {}, currentImgIndex: 0, // 封面图片类型选择 imgDialogVisible: false, // 表单数据 form: { selectedItemsOther: [], selectedItemsFunction: [], ids: null, // addressIds: ['1'], addressIds: [], canCancel: 0, cover: '', detailInfo: null, endTime: null, id: 0, isAutoEnd: 0, isHideList: false, isHideOrderAmount: false, isJoin: 0, maxJoinNum: 0, minAmount:null, name: "", products: [ { id: 0, image: imgUrl, limitNum: 0, name: "", parentId: 0, price: 0, soldNum: 0, totalNum: 0 } ], realEndTime: "", startTime: "", status: 0, }, // 表单校验 rules: { products: [ { validator: (rule, value, callback) => { // 自定义校验逻辑 if (!value || value.length === 0) { callback(new Error('至少需要添加一个商品')); return; } const isValid = value.every(item => item.name && item.price !== undefined && item.price !== null && item.image && item.image !== imgUrl // 确保不是默认图片 ); if (!isValid) { callback(new Error('请完善所有商品信息(名称、价格和图片必填)')); } else { callback(); } }, trigger: 'change' // 可以根据需要改为'blur'或保持'change' } ], addressIds: [ { required: true, message: '请选择提货地址', trigger: ['change', 'blur'] } ], cover: [ { required: true, message: '请选择活动图片', trigger: ['change', 'blur'] } ], name: [ { required: true, message: '请输入团购名称', trigger: 'change' } ], othermessage: [ { type: 'array', required: true, message: '请选择其它信息', trigger: 'change' } ], selectability: [ { type: 'array', required: true, message: '请选择功能', trigger: 'change' }, ], shopmessage: [ { required: true, message: '请输入商品信息', trigger: 'change' }, ], detailInfo: [ { required: true, message: '请输入团购内容', trigger: 'change' } ], maxJoinNum: [ { required: true, message: '最大人数不能为空', trigger: 'change' } ], minAmount: [ { required: true, message: '最小成交金额不能为空', trigger: 'change' } ], endTime: [ { required: true, message: '结束间必须选择', trigger: 'change' } ], startTime: [ { required: true, message: '开始间不能为空', trigger: 'change' } ], description: [ { required: true, message: '活动开始内容不能为空', trigger: 'change' } ], address: [ { required: true, message: '地点不能为空', trigger: 'change' } ], conditionRequire: [ { required: true, message: '请输入条件说明', trigger: 'change' } ], // signStartDatetime: [ // { required: true, message: '报名开始间必须选择', trigger: 'change' } // ], signEndDatetime: [ { required: true, message: '活动截止间必须选择', trigger: 'change' } ], jobUserVOLists: [ { type: 'array', required: true, message: '请添加岗位需求', trigger: 'change' } ], }, // 图片前缀 cover: imgUrl, // //分页 column: { pageSize: null, pageNum: null }, // 队伍列表 // 岗位表单校验 jobRules: { jobName: [ { required: true, message: '请输入岗位名称', trigger: 'change' } ], jobCount: [ { required: true, message: '请输入岗位人数', trigger: 'change' } ], workHour: [ { required: true, message: '请输入工', trigger: 'change' } ], pointPercent: [ { required: true, message: '请输入积分(每人每小)', trigger: 'change' }, { validator: checkPointIsNumber, message: '积分必须为数字' } ], checkInTime: [ { required: true, message: '请输入签到间', trigger: 'change' } ], checkOutTime: [ { required: true, message: '请输入签退间', trigger: 'change' } ], checkLocation: [ { required: true, message: '请选择签到地点', trigger: 'change' } ] }, } }, created() { this.getAddressList() if (!this.$route.query.id) { this.$router.replace({ ...this.$route, query: {} }); } else { this.queryParams = this.$route.query; console.log(this.queryParams.id, '888') if (this.queryParams.id) { // 编辑 this.title = '修改接龙' getGroupBuyDetail(this.queryParams.id).then(res => { const boolConvert = val => val === 1; console.log(res, '---') const { cover, id } = res; console.log(res.isGetRealName) this.form = { ...res, isAutoEnd: res.isAutoEnd = 1 ? true : false, id, cover, addressIds:res.addressIds || [], selectedItemsOther: [], selectedItemsFunction: [], products:res.products || [{ image:imgUrl }] } if (res.isGetRealName === 1) { this.form.selectedItemsOther.push('isGetRealName') } if (res.isGetPhone === 1) { this.form.selectedItemsOther.push('isGetPhone') } if (res.isHideList === 1) { this.form.selectedItemsFunction.push('isHideList') } if (res.isHideOrderAmount === 1) { this.form.selectedItemsFunction.push('isHideOrderAmount') } if (res.canCancel === 1) { this.form.selectedItemsFunction.push('canCancel') } }) }} }, methods: { onMounted() { }, getAddressList() { getGroupBuyAddressPage().then(res => { this.addressoptions = res.pageData }) }, beforeDestroy() { clearInterval(this.timer); }, addproduct() { this.form.products.push({ /* 初始化新商品 */ }); this.$nextTick(() => { this.$refs.form.validateField('products'); // 触发products字段校验 }); }, removeRow(index) { // 添加长度检查 if (this.form.products.length <= 1) { this.$message.warning('至少需要保留一个商品'); return; } this.form.products.splice(index, 1); this.$nextTick(() => { this.$refs.form.validateField('products'); }); }, // 在图片上传成功后的回调中也触发校验 selectProductUpload(obj, index) { uploadPic().then(res => { this.$set(this.form.products, index, { ...this.form.products[index], image: res}) this.$nextTick(() => { this.$refs.form.validateField('products'); }); }); }, handleProductAvatarChange(file) { if (!file || !file.raw) return; const reader = new FileReader(); reader.onload = (e) => { const img = new Image(); img.onload = () => { // 限制最大尺寸(合理值:800×600) const MAX_SIZE = 800; let width = img.width; let height = img.height; // 按比例缩放到最大尺寸 if (width > MAX_SIZE || height > MAX_SIZE) { const scale = Math.min(MAX_SIZE / width, MAX_SIZE / height); width *= scale; height *= scale; } // 画布压缩处理 const canvas = document.createElement('canvas'); const ctx = canvas.getContext('2d'); canvas.width = width; canvas.height = height; ctx.drawImage(img, 0, 0, width, height); // 关键优化:降低质量生成更短Data URL this.form.products.image = canvas.toDataURL(file.type, 0.01); // 压缩质量65% }; img.src = e.target.result; }; reader.readAsDataURL(file.raw); }, handleAvatarChange(file) { if (!file || !file.raw) return; const reader = new FileReader(); reader.onload = (e) => { const img = new Image(); img.onload = () => { // 限制最大尺寸(合理值:800×600) const MAX_SIZE = 800; let width = img.width; let height = img.height; // 按比例缩放到最大尺寸 if (width > MAX_SIZE || height > MAX_SIZE) { const scale = Math.min(MAX_SIZE / width, MAX_SIZE / height); width *= scale; height *= scale; } // 画布压缩处理 const canvas = document.createElement('canvas'); const ctx = canvas.getContext('2d'); canvas.width = width; canvas.height = height; ctx.drawImage(img, 0, 0, width, height); // 关键优化:降低质量生成更短Data URL this.form.cover = canvas.toDataURL(file.type, 0.01); // 压缩质量65% }; img.src = e.target.result; }; reader.readAsDataURL(file.raw); }, beforeAvatarUpload(file) { const validTypes = ['image/jpeg', 'image/png', 'image/webp']; // 移除GIF减小潜在数据量 const MAX_SIZE_MB = 1.2; // 更严格的大小限制 const isImage = validTypes.includes(file.type); const isSizeValid = file.size / 1024 / 1024 < MAX_SIZE_MB; if (!isImage) { this.$message.error('仅支持 JPG/PNG/WEBP 格式'); return false; } if (!isSizeValid) { this.$message.error(`图片大小不能超过 ${MAX_SIZE_MB}MB`); return false; } return true; }, // updateOtherInfo() { // this.form.isGetRealName = this.selectedItemsOther.includes('真实姓名'); // this.form.isGetPhone = this.selectedItemsOther.includes('手机号码'); // }, // 更新"功能选择"表单值 updateFunctionSelection() { this.form.isHideList = this.selectedItemsFunction.includes('发布最新接龙列表'); this.form.isHideOrderAmount = this.selectedItemsFunction.includes('接龙金额仅创建人可见'); // "禁止用户取消订单"需要特殊处理:选中canCancel=false this.form.canCancel = !this.selectedItemsFunction.includes('禁止用户取消订单'); }, // 获取活动详情 // getDetail(status) { // getGroupBuyDetail(this.queryParams.id, status).then(response => { // this.queryParams.id, status // this.form = response // console.log(response, '789') // }) // }, // 表单重置 reset() { this.form = { addressIds: [], cover: null, canCancel: 0, ids: null, detailInfo: null, endTime: null, id: 0, isAutoEnd: 0, isGetPhone: 0, isGetRealName: 0, isHideList: 0, isHideOrderAmount: 0, isJoin: 0, maxJoinNum: 0, minAmount: 0, name: "", products: [ { id: 0, image: imgUrl, limitNum: 0, name: "", parentId: 0, price: 0, soldNum: 0, totalNum: 0 } ], realEndTime: "", startTime: "", status: 0, } }, selectPicUpload(obj) { let fd = new FormData() //参数的格式是formData格式的 fd.append('file', obj.file) //参数 uploadPic(fd, { modularName: 'ACTIVITY' }).then(res => { this.form.cover = res }) }, selectProductUpload(obj, index) { let fd = new FormData(); fd.append('file', obj.file); uploadPic(fd, { modularName: 'ACTIVITY' }).then(res => { // 直接更新对应索引位置的图片URL this.$set(this.form.products, index, { ...this.form.products[index], image: res }); }).catch(error => { console.error('商品图片上传失败:', error); this.$message.error('商品图片上传失败'); }); }, // // 取消关闭弹窗 // closeDialog() { // this.currentImgIndex = 0 // this.selectImgUrl = '' // this.imgDialogVisible = false // }, // // 确认默认图片关闭弹窗 // submitPic() { // this.form.cover = this.selectImgUrl // this.imgDialogVisible = false // }, hasCommonValue(arr) { let seen = new Set(); // 用于存储已经遇到的值 for (let obj of arr) { for (let value of obj.jobUsers) { // 如果值已经存在于 set 中,返回 true if (seen.has(value.userId)) { return true; } // 将当前值加入 set seen.add(value.userId); } } return false; // 如果没有重复的值,返回 false }, /** 提交按钮 */ submitForm() { console.log(this.form.products.image, '000') let newForm = { ids: this.form.ids, addressIds: this.form.addressIds, canCancel: this.form.selectedItemsFunction.includes('canCancel') ? 1 : 0, cover: this.form.cover, detailInfo: this.form.detailInfo, endTime: this.form.endTime, id: this.form.id, isAutoEnd: this.form.isAutoEnd == true ? 1 : 0, isGetPhone: this.form.selectedItemsOther.includes('isGetPhone') ? 1 : 0, isGetRealName: this.form.selectedItemsOther.includes('isGetRealName') ? 1 : 0, isHideList: this.form.selectedItemsFunction.includes('isHideList') ? 0 : 1, isHideOrderAmount: this.selectedItemsFunction.includes('isHideOrderAmount') ? 1 : 0, isJoin: this.form.isJoin, maxJoinNum: this.form.maxJoinNum, minAmount: this.form.minAmount, name: this.form.name, // 遍历数组中的每个对象 products: this.form.products.map(item => ({ id: item.id, image: item.image, limitNum: item.limitNum, name: item.name, parentId: item.parentId, price: item.price, soldNum: item.soldNum, totalNum: item.totalNum })), realEndTime: this.form.realEndTime, startTime: this.form.startTime, status: this.form.status, // 修正为this.form.status }; console.log(newForm, this.form.id) //判断每个间段是否有岗位 // let isJobEmpty = this.form.jobUserVOLists.some(item => item.jobList.length == 0) this.$refs['form'].validate(valid => { if (valid) { if (this.form.id) { editGroupBuy(newForm).then(response => { console.log(response, '00') this.$modal.msgSuccess('修改成功') this.$router.back(-1) }) } else { if (this.form.name != '' && this.form.cover != '') { addGroupShop(newForm).then(response => { console.log(response) this.$modal.msgSuccess('新增成功') this.$router.back(-1) }) } else { console.log(this.form.ids, '09') this.$modal.msgError('请完善信息') } } } }) }, handleBack() { this.$router.back(-1) }, // handleSelectionChange(selection) { this.ids = selection.map(item => item.pkId) this.single = selection.length !== 1 this.multiple = !selection.length }, // 新增间段 changeStatus() { if (this.currentTime) { this.timer = setInterval(() => { this.currentTime = new Date().toLocaleTimeString(); console.log(this.currentTime, '90') }, 1000); } }, // 改变间段的初始间 changeStartTime(value, timeIndex) { console.log(this.form.jobUserVOLists[timeIndex].jobList) if (this.form.jobUserVOLists[timeIndex].jobList) { this.form.jobUserVOLists[timeIndex].jobList.forEach(item => { item.checkInTime = value if (item.checkOutTime && item.checkInTime) { item.workHour = getISOTime(item.checkInTime, item.checkOutTime) if (item.jobUsers) { item.jobUsers.forEach(itemson => { itemson.workHour = item.workHour itemson.point = parseInt(item.pointPercent) * item.workHour }) } } }) } }, // 改变间段的初始间 changeEndTime(value, timeIndex) { if (this.form.jobUserVOLists[timeIndex].jobList) { this.form.jobUserVOLists[timeIndex].jobList.forEach(item => { item.checkOutTime = value if (item.checkOutTime && item.checkInTime) { item.workHour = getISOTime(item.checkInTime, item.checkOutTime) if (item.jobUsers) { item.jobUsers.forEach(itemson => { itemson.workHour = item.workHour itemson.point = parseInt(item.pointPercent) * item.workHour }) } } }) } }, // 改变间段的签到纬度 changeLatitude(value, timeIndex) { if (this.form.jobUserVOLists[timeIndex].jobList) { this.form.jobUserVOLists[timeIndex].jobList.forEach(item => { item.checkLatitude = value }) } }, // 改变间段的签到经度 changeLongitude(value, timeIndex) { if (this.form.jobUserVOLists[timeIndex].jobList) { this.form.jobUserVOLists[timeIndex].jobList.forEach(item => { item.checkLongitude = value }) } }, // 跳转 toPrck() { window.open('https://lbs.amap.com/tools/picker') }, // 删除间段 deleteTime(timeIndex) { this.$modal.confirm('是否确认该间段?').then(function () { }).then(() => { this.form.jobUserVOLists.splice(timeIndex, 1) this.changeNumber() }).catch(() => { }) }, // 删除岗位按钮 // 活动最大人数改变 changeNumber() { this.form.maxCount = 0 this.form.jobUserVOLists.forEach(item => { item.jobList.forEach(itemson => { this.form.maxCount += itemson.jobUsers.length }) }) }, // 岗位人数改变 //岗位志愿者选择 } } </script> <style scoped> .container { background-color: #f5f5f5; padding: 1%; } .title_type { font-size: 24px; font-weight: 700; margin-bottom: 20px; } .dialog-footer { display: flex; flex-direction: row; justify-content: center; align-items: center; padding-bottom: 30px; } .avatar-uploader .el-upload { border: 1px solid #f8f3f3; border-radius: 6px; cursor: pointer; position: relative; overflow: hidden; } .avatar-uploader .el-upload:hover { border-color: #409EFF; } .avatar-uploader-icon { font-size: 28px; color: #8c939d; width: 120px; height: 120px; line-height: 120px; text-align: center; } .coverImage { width: 214px; height: 129px; border-radius: 6px; cursor: pointer; } .select_mask { position: absolute; z-index: 2; background-color: rgba(127, 125, 121, 0.5); text-align: center; top: 0; bottom: 0; left: 0; right: 0; width: 214px; height: 129px; display: flex; justify-content: center; align-items: center; } .avatar { width: 50px; height: 50px; display: block; } .margin-right-10 { margin-right: 10px; } .job_box { /* border: 1px solid #ccc; */ background-color: #F8F8F8; padding: 46px 10px 10px; margin-bottom: 10px; margin-left: 50px; border-radius: 10px; } </style>
最新发布
11-01
<template> <div class="sendEmail || page"> <vue-form ref="myForm" v-loading="loading" v-model="formData" :ui-schema="uiSchema" :schema="schema" :error-schema="errorSchema" v-hasPermi="['biz:mail:sendExpress']" @on-submit="sendMail()" @on-cancel="cancel()" > <div slot-scope="{ formRefFn }"> <p style="float: right; margin-bottom: 30px"> <el-button @click="cancel(formRefFn)">取消</el-button> <el-button @click="saveBtn(formRefFn)" type="primary" v-hasPermi="['biz:mail:sendExpress']" >保存</el-button > </p> </div> </vue-form> <el-dialog title="邮件保存" :visible.sync="saveLog" :close-on-click-modal="false" width="500px" > <span style="font-size: 18px">确定保存吗?</span> <el-form :model="mailSaveData"> </el-form> <div slot="footer" class="dialog-footer"> <el-button @click="cancelSave()">取 消</el-button> <el-button type="primary" @click="saveLogBtn()">确 定</el-button> </div> </el-dialog> </div> </template> <script> //这里可以导入其他文件(比如:组件,工具js,第三方插件js,json文件,图片文件等等) //例如:import 《组件名称》 from '《组件路径》'; import upload from "@c/Upload/upload"; import colorSelector from "@c/ColorSelector/colorSelector"; import { sendExpress, saveExpress } from "@/api/portal/otd"; import { listTemplate, getTemplate } from "@/api/portal/template"; import { listReceiver, getReceiver } from "@/api/portal/receiver"; import { listEmailTemplateLog, getEmailTemplateLog, addEmailTemplateLog, } from "@/api/emailTemplateLog/emailTemplateLog"; import { getOtdhtml, updateOtdhtml } from "@/api/portal/otdhtml"; export default { name: "sendExpress", //import引入的组件需要注入到对象中才能使用 components: { upload, colorSelector, }, data() { //这里存放数据 return { loading: false, headTitleSizeEn: "13.0", headTitleSizeZh: "11.0", sectionTitleSizeEn: "13.0", sectionTitleSizeZh: "15.0", contentSizeEn: "10.0", contentSizeZh: "10.0", imageUrl: "", formData: {}, emailData: { templateJson: "", }, mailSaveData: { remark: "", }, optType: "", mailData: [], //分页 total: 0, type: 1, queryParams: { pageNum: 1, pageSize: 10, remark: null, templateJson: null, createTime: null, optType: null, webPic: null, appPic: null, }, saveLog: false, schema: { type: "object", required: [ "title", "bannerPicture", "AppbannerPicture", "expressNo", "otdNo", ], properties: { // emailTitle: { // title: "邮件主题", // type: "string", // }, title: { title: "标题", type: "string", }, expressNo: { title: "期号", type: "string", default: "ISSUE 202207", }, bannerPicture: { "ui:widget": upload, title: "WEB主图片", type: "string", default: "", }, AppBannerPicture: { "ui:widget": upload, title: "APP主图片", type: "string", default: "", }, expressSection: { title: "内容部分", type: "array", items: { type: "object", required: [ "colorInfoOutside", "colorInfoInside", "btnImg", "sectionTitleZh", "sectionTitleEn", ], properties: { colorInfoOutside: { "ui:widget": colorSelector, title: "外边框颜色", type: "string", default: "", }, colorInfoInside: { "ui:widget": colorSelector, title: "内边框颜色", type: "string", default: "", }, btnImg: { title: "按钮图片", type: "string", }, sectionTitleZh: { title: "一级标题(中文)", type: "string", }, sectionTitleEn: { title: "一级标题(英文)", type: "string", }, subSection: { title: "一级内容部分", type: "array", items: { type: "object", required: [ "subTitleZh", "subTitleEn", "imgUrlList", "expressSubContent", ], properties: { subTitleZh: { title: "二级标题(中文)", type: "string", }, subTitleEn: { title: "二级标题(英文)", type: "string", }, imgUrlList: { title: "二级内容图片", type: "array", minItems: 1, maxItems: 2, items: { type: "string", }, }, expressSubContent: { title: "二级段落部分", type: "array", items: { type: "object", required: ["contentZh", "contentEn"], properties: { contentZh: { title: "段落内容(中文)", type: "string", }, contentEn: { title: "段落内容(英文)", type: "string", }, }, }, }, }, }, }, }, }, }, }, }, uiSchema: { bannerPicture: { "ui:widget": upload, "ui:prop": "imageUrl", }, AppBannerPicture: { "ui:widget": upload, "ui:prop": "imageUrl", }, expressSection: { items: { btnImg: { "ui:widget": upload, }, subSection: { items: { imgUrlList: { items: { "ui:widget": upload, }, }, }, }, }, }, }, errorSchema: { title: { "err:options": { required: "标题不能为空", }, }, expressNo: { "err:options": { required: "显示期号不能为空", }, }, bannerPicture: { "err:options": { required: "请输入WEB主图片", }, }, AppBannerPicture: { "err:options": { required: "请输入APP主图片", }, }, expressSection: { items: { colorInfoInside: { "err:options": { required: "请选择一个内边框颜色", }, }, colorInfoInside: { "err:options": { required: "请选择一个外边框颜色", }, }, btnImg: { "err:options": { required: "请添加按钮图片", }, }, sectionTitleZh: { "err:options": { required: "内容不能为空", }, }, sectionTitleEn: { "err:options": { required: "内容不能为空", }, }, subSection: { items: { subTitleZh: { "err:options": { required: "内容不能为空", }, }, subTitleEn: { "err:options": { required: "内容不能为空", }, }, imgUrlList: { items: { "err:options": { required: "请添加内容图片", }, }, }, expressSubContent: { items: { contentZh: { "err:options": { required: "内容不能为空", }, }, contentEn: { "err:options": { required: "内容不能为空", }, }, }, }, }, }, }, }, }, }; }, //监听属性 类似于data概念 computed: {}, //如果页面有keep-alive缓存功能,这个函数会触发 activated() {}, //方法集合 methods: { //保存弹窗 saveBtn() { this.$ refs.myForm.$$uiFormRef.validate((valid) => { if (valid) { this.saveLog = true; return; } this.saveLog = false; }); }, //保存草稿 saveLogBtn() { if (this.saveId != null) { let data = {}; data.id = this.saveId; this.templateJson = { formData: this.formData, }; data.templateJson = JSON.stringify(this.templateJson); data.webPic = this.formData.bannerPicture; data.appPic = this.formData.AppBannerPicture; updateOtdhtml(data).then((response) => { this.msgSuccess("修改成功"); this.$ router.replace({ path: "/otdPreview/otdPreview", }); }); } else { saveExpress({ formData: this.formData, }).then((response) => { this.msgSuccess("保存成功"); this.$ router.replace({ path: "/otdPreview/otdPreview", }); }); } this.saveLog = false; }, // getPreview(id) { if (id !== undefined) { getOtdhtml(id).then((response) => { console.log(response); this.templateJson = JSON.parse(response.data.templateJson); this.formData = this.templateJson.formData; this.formData.AppBannerPicture = response.data.appPic; console.log("this.formData(回显)", this.formData); }); } }, cancel() { this.formData = {}; }, cancelSave() { this.mailSaveData.remark = ""; this.saveLog = false; }, }, //生命周期 - 创建完成(可以访问当前this实例) created() { this.saveId = this.$ route.params.id; this.getPreview(this.saveId); }, //生命周期 - 挂载完成(可以访问DOM元素) mounted() {}, //监控data中的数据变化 watch: {}, }; </script> <style rel="stylesheet/scss" lang="scss" scoped> .sendEmail { margin: 20px auto; width: 80%; } /deep/ .fieldGroupWrap_title { line-height: inherit !important; margin-bottom: 0px !important; } /deep/ .el-form-item { margin-bottom: 8px !important; } /deep/.formItemErrorBox { padding-top: 0px !important; } /deep/.fieldGroupWrap_title { height: 28px !important; } /deep/.arrayField:not(.genFormItem) { margin-bottom: 0px; } .mailHistory { float: right; font-weight: bold; &:hover { color: #0077ff; } } .templateJson_1 { // 3行文本超长换行 overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; line-clamp: 3; box-orient: vertical; cursor: pointer; &:hover { color: #0077ff; } } .typeface { float: right; width: 50%; } </style> 换成vue3 setup写法
07-11
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值