@@ -1,12 +1,16 @@
< template >
< view :style = "themeColor" >
<!-- 返回主页按钮 : 左上角固定 , 始终可见 -- >
< view class = "home-btn" @click ="goHome" >
< text class = "home-btn-text" > { { $lang ( 'form.formdata.backHome' ) } } < / text >
< / view >
< block v-if = "detail" >
< view class = "page" >
< view class = "system-form-wrap" >
<!-- 复用 diy - form : banner / tip / 表单字段 / 提交按钮 全部由其内部渲染 , 样式 ( bannerPaddingX / tipColor / submitBgColor 等 ) 由 form _config 控制 。
: onSubmit 接管提交逻辑 ( 带 uniacid + showModal ) ; 跨 H5 / MP 一致 , 不依赖 $listeners 。
注意 : create 重度依赖本组件 this ( id / uniacid / memberInfo / $api 等 ) , 必须在 created 阶段 bind this ,
否则 diy - form 通过 this . onSubmit ( formData ) 调用时 this 会漂移到子组件实例 -- >
: onSubmit 接管提交逻辑 ( 带 uniacid + showModal ) ; 跨 H5 / MP 一致 , 不依赖 $listeners 。
注意 : create 重度依赖本组件 this ( id / uniacid / memberInfo / $api 等 ) , 必须在 created 阶段 bind this ,
否则 diy - form 通过 this . onSubmit ( formData ) 调用时 this 会漂移到子组件实例 -- >
< diy-form ref = "form" :value = "diyValue" dataMode = "raw" :onSubmit = "handleSubmit" / >
< / view >
< / view >
@@ -174,6 +178,18 @@ export default {
// #endif
uni . setNavigationBarTitle ( { title : formName } ) ;
} ,
// 返回主页(用 reLaunch 避免返回后还能 navigateBack 回到已提交的表单页)
goHome ( ) {
this . $util . redirectTo ( this . $util . INDEX _PAGE _URL , { } , 'reLaunch' ) ;
} ,
// 清空表单数据:通过 diy-form 的 ref 拿到 ns-newform 实例,调用 setFormData 重置
resetForm ( ) {
try {
if ( this . $refs . form && this . $refs . form . $refs . nsNewform && this . $refs . form . $refs . nsNewform . setFormData ) {
this . $refs . form . $refs . nsNewform . setFormData ( ) ;
}
} catch ( e ) { }
} ,
// 由 diy-form 内置提交按钮触发: diy-form handleSubmit 已先做 verify(),
// 仅在通过时才通过 :onSubmit 函数 prop 调用本方法(跨 H5 / MP 一致,不走 $emit / $listeners) 。
// 注意:本方法通过 created 中 this.handleSubmit = this.create.bind(this) 预绑定 this,
@@ -193,15 +209,18 @@ export default {
member _id : this . memberInfo ? this . memberInfo . id : 0
} ,
success : res => {
if ( res . code == 0 ) {
this . complete = true
uni . showModal ( {
title : this . $lang ( 'form.formdata.tip' ) ,
content : this . $lang ( 'form.formdata.submitSuccess' ) ,
showCancel : false ,
success : ( ) => { }
} )
} e lse {
if ( res . code == 0 ) {
this . complete = true
// 提交成功后清空表单
this . resetForm ( )
this . isRepeat = false
uni . showModal ( {
title : this . $lang ( 'form.formdata.tip' ) ,
content : this . $lang ( 'form.formdata.submitSuccess' ) ,
showCancel : fa lse ,
success : ( ) => { }
} )
} else {
this . isRepeat = false
this . $util . showToast ( {
title : res . message
@@ -235,6 +254,35 @@ page {
border - radius : 0 ;
}
// 左上角返回主页按钮
. home - btn {
position : fixed ;
left : 30 rpx ;
// #ifdef MP-WEIXIN || MP-ALIPAY || MP-BAIDU || MP-TOUTIAO || MP-QQ || MP-LARK
// 小程序端需避开右上角胶囊按钮,下移到状态栏 + 胶囊高度之下
top : calc ( var ( -- status - bar - height , 20 px ) + 10 rpx ) ;
// #endif
// #ifdef H5
top : 20 rpx ;
// #endif
z - index : 999 ;
padding : 12 rpx 28 rpx ;
background - color : rgba ( 0 , 0 , 0 , 0.5 ) ;
border - radius : 40 rpx ;
display : flex ;
align - items : center ;
. home - btn - text {
color : # ffffff ;
font - size : 26 rpx ;
line - height : 1 ;
}
& : active {
opacity : 0.8 ;
}
}
: : v - deep . mescroll - totop {
/* #ifdef H5 */
right : 27 rpx ! important ;