Files
lucky_shop/pages_tool/form/formdata.vue
ZF sun 800cdbc805 fix(formdata): 修复H5端导航栏隐藏选择器失效的问题
将原先通过类名选择uni-page-head改为直接选择uni-page-head组件,适配框架组件渲染变化
2026-05-28 16:56:06 +08:00

212 lines
4.3 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<template>
<view :style="themeColor">
<block v-if="detail">
<view class="page">
<view class="form-banner" v-if="detail.show_banner > 0">
<image :src="$util.img(formBanner)" mode="widthFix"></image>
</view>
<view class="form-tip">
<view class="system-form-tip" v-if="detail.show_tip > 0">{{ formTip }}</view>
</view>
<view class="system-form-wrap">
<ns-newform ref="form" :data="detail.json_data" @submit="create"></ns-newform>
<button class="button mini" style="font-size:32rpx;" type="primary" size="mini"
@click="create">提交</button>
</view>
</view>
</block>
<block v-else>
<ns-empty :text="complete ? '提交成功' : '未获取到表单信息'" :isIndex="false"></ns-empty>
</block>
<loading-cover ref="loadingCover"></loading-cover>
<ns-login ref="login"></ns-login>
</view>
</template>
<script>
import nsNewform from '../_components/ns-newform/ns-newform.vue';
export default {
components: {
nsNewform
},
data() {
return {
id: 0,
detail: null,
isRepeat: false,
complete: false,
scroll: true,
uniacid: 0,
isFromMpWebView: false, // 是否是从微信小程序的WebView跳转过来的
}
},
computed: {
formBanner() {
const bannerImg = this.detail?.form_banner
return bannerImg ? bannerImg : 'public/uniapp/form/banner.png'
},
formTip() {
const tip = this.detail?.form_tip
console.log('formTip computed, tip value:', tip, 'truthy:', !!tip)
return tip ? tip : '请填写表单所需信息'
}
},
onLoad(options) {
if (!options.uniacid) {
uni.showModal({
title: '提示',
content: '参数错误',
showCancel: false,
success: () => { }
})
return false
}
uni.setStorageSync('skipPrivacyCheck', true);
this.uniacid = options.uniacid
this.id = options.id || 0
this.isFromMpWebView = options.from === 'mp-webview';
if (options.scene) {
const scene = decodeURIComponent(options.scene)
const params = scene.split('&')
params.length && params.forEach(item => {
if (item.indexOf('id') != -1) {
this.id = item.split('-')[1]
}
})
}
// #ifdef H5
if (this.isFromMpWebView) {
this.$nextTick(() => {
const navbar = document.querySelector('uni-page-head')
if (navbar) navbar.style.display = 'none'
})
}
// #endif
this.getData()
},
watch: {
storeToken(newVal, oldVal) {
newVal && this.getData()
}
},
methods: {
getData() {
this.$api.sendRequest({
url: '/form/api/form/info',
data: {
form_id: this.id,
uniacid: this.uniacid
},
success: res => {
if (res.code == 0 && res.data) {
this.detail = res.data
console.log(`form data =>`, this.detail)
// 非H5的情况下,设置标题
if (!this.isFromMpWebView) {
uni.setNavigationBarTitle({
title: res.data.form_name
})
}
}
this.$refs.loadingCover && this.$refs.loadingCover.hide()
},
fail: () => {
this.$refs.loadingCover && this.$refs.loadingCover.hide()
}
})
},
create() {
if (!this.$refs.form.verify()) return
if (this.isRepeat) return
this.isRepeat = true
this.$api.sendRequest({
url: '/form/api/form/create',
data: {
form_id: this.id,
form_data: JSON.stringify(this.$refs.form.formData),
uniacid: this.uniacid
},
success: res => {
if (res.code == 0) {
uni.showModal({
title: '提示',
content: '提交成功',
showCancel: false,
success: () => { }
})
} else {
this.isRepeat = false
this.$util.showToast({
title: res.message
})
}
}
})
}
}
}
</script>
<style lang="scss" scoped>
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;
}
</style>