diff --git a/components-diy/diy-form.vue b/components-diy/diy-form.vue index 97c0ca8..b6b8f3f 100644 --- a/components-diy/diy-form.vue +++ b/components-diy/diy-form.vue @@ -277,7 +277,13 @@ export default { return; } - // 转为 { index: val } 提交格式(后端 /form/api/form/create 期望的紧凑结构) + // 若父级监听了 @submit,则把提交控制权交给父级(用于父级有自定义提交字段/反馈逻辑的页面,如 formdata.vue 传 uniacid) + if (this.$listeners && this.$listeners.submit) { + this.$emit('submit', this.getFormData()); + return; + } + + // 默认内置提交:装饰组件场景下使用,submitData 为 { index: val } 形式 var submitData = {}; this.getFormData().forEach(function(item, index) { submitData[index] = item.val; diff --git a/pages_tool/form/formdata.vue b/pages_tool/form/formdata.vue index b44bea7..0949e94 100644 --- a/pages_tool/form/formdata.vue +++ b/pages_tool/form/formdata.vue @@ -2,22 +2,15 @@ - - - - - {{ formTip }} - - + - @@ -54,24 +47,21 @@ export default { } }, computed: { - formBanner() { - const bannerImg = this.detail?.form_banner - return bannerImg ? bannerImg : 'public/uniapp/form/banner.png' - }, - formTip() { - const tip = this.detail?.form_tip - return tip ? tip : '请填写表单所需信息' - }, // 构造 diy-form raw 模式期望的 value 形态: // - jsonData:透传给 ns-newform(已是 ns-newform 期望的 [{ controller, value, val }]) // - formConfig:后端返回 camelCase(如 formPaddingX / formBgColor / labelFontSize), // diy-form 内部 mergedFormConfig 同时兼容 snake_case 后再交给 ns-newform - // - 不传 show_banner / show_tip:让 diy-form 自带的 banner/tip 不渲染(页面已自渲染) + // - show_banner / form_banner:交给 diy-form 渲染 banner,样式走 form_config.bannerPaddingX;form_banner 给保底图 + // - show_tip / form_tip:交给 diy-form 渲染 tip,样式走 form_config;form_tip 给保底文案 // 注:本 computed 只在 内被消费,无需 null 守卫 diyValue() { return { jsonData: this.detail.json_data, - formConfig: this.detail.form_config + formConfig: this.detail.form_config, + show_banner: this.detail.show_banner, + form_banner: this.detail.form_banner || 'public/uniapp/form/banner.png', + show_tip: this.detail.show_tip, + form_tip: this.detail.form_tip || '请填写表单所需信息' } } }, @@ -157,10 +147,8 @@ export default { // #endif uni.setNavigationBarTitle({ title: formName }); }, - create() { - // 校验(ns-newform 校验失败时会内部 toast;返回 false 表示失败) - if (!this.$refs.form.verify()) return - + // 由 diy-form 内置提交按钮触发:diy-form 已先做 verify(),仅在通过时才 emit('submit', formData) + create(formData) { if (this.isRepeat) return this.isRepeat = true @@ -168,7 +156,7 @@ export default { url: '/form/api/form/create', data: { form_id: this.id, - form_data: JSON.stringify(this.$refs.form.getFormData()), + form_data: JSON.stringify(formData), uniacid: this.uniacid }, success: res => { @@ -197,50 +185,9 @@ page { background: #fff; } -.form-banner { - width: 100vw; - line-height: 1; -} - -.form-banner image { - width: 100%; - line-height: 1; -} - -.form-tip { - text-align: center; -} - -.system-form-tip { - line-height: 120rpx; - font-weight: 600; - font-size: 30rpx; -} - .system-form-wrap { - border-radius: 32rpx; overflow: hidden; margin: 0 0 60rpx 0; - padding: 0 12rpx; - padding-top: 40rpx; - transform: translateY(-40rpx); -} - -.system-form-wrap .button { - height: 80rpx; - line-height: 80rpx !important; - margin-top: 30rpx !important; - width: 84%; - margin-left: 28rpx !important; - border-radius: 80rpx; - background: #f4391c; - color: #fff; -} - -.system-form-wrap .form-wrap { - background: #fff; - padding: 30rpx; - border-radius: 32rpx; } // 穿透 diy-form 包装层:消除其自带的 10rpx 圆角与白色背景,