// 更新跨表属性 var crossuserid; var crossrefid; var crossoptnum;

if(this.cross){ // 获取本地存储中的状态列名和状态列值 var statusColumnName = uni.getStorageSync('statusColumnName'); var statusColumnValue = uni.getStorageSync('statusColumnValue'); // 如果状态列名不为空 if(statusColumnName!='') { // 获取本地存储中的跨表对象 var obj = uni.getStorageSync('crossObj'); // 如果状态列名是单个属性名,则直接更新跨表对象中对应属性的值 if(!statusColumnName.startsWith("[")) { for (var o in obj){ if(o==statusColumnName){ obj[o] = statusColumnValue; } } // 更新跨表对象 var table = uni.getStorageSync('crossTable'); await this.$api.update(${table}, obj); } else { // 否则,需要进行跨表计算,记录跨表用户ID、引用ID和操作数 crossuserid=Number(uni.getStorageSync('userid')); crossrefid=obj['id']; crossoptnum=uni.getStorageSync('statusColumnName'); crossoptnum=crossoptnum.replace(/[/,'').replace(/]/,''); } } }

// 如果存在跨表用户ID和引用ID if(crossrefid && crossuserid) { // 将跨表用户ID和引用ID添加到表单中 this.ruleForm.crossuserid=crossuserid; this.ruleForm.crossrefid=crossrefid; // 查询相关表中是否已经存在足够数量的数据 let params = { page: 1, limit:10, crossuserid:crossuserid, crossrefid:crossrefid, } let res = await this.$api.list(dancifenlei, params); // 如果存在,则给出提示并返回 if (res.data.total >= crossoptnum) { this.$utils.msg(uni.getStorageSync('tips')); return false; } else { // 否则进行跨表计算并更新数据 if(this.ruleForm.id){ await this.$api.update(dancifenlei, this.ruleForm); }else{ await this.$api.add(dancifenlei, this.ruleForm); } this.$utils.msgBack('提交成功'); } } else { // 如果不存在需要更新的跨表属性 // 直接进行添加或更新操作 if(this.ruleForm.id){ await this.$api.update(dancifenlei, this.ruleForm); }else{ await this.$api.add(dancifenlei, this.ruleForm); } this.$utils.msgBack('提交成功'); } },

跨表属性更新及数据验证 - 单词本分类

原文地址: https://www.cveoy.top/t/topic/gM4x 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录