前端uniapp提交表单调用接口方法最新

源码1

<template>
	<view class="my-add-bank-card">
		<!-- name="bank_name"  form表单提交的input里面一定要加name绑定要传的参数 name="bank_name" type="text" v-model="address.bank_name"  一定要name和 v-model参数保持一致!!!-->
		<form @submit="formSubmit" @reset="formReset">
			<view class="my-add-bank-card-box">
				<view class="add-card-tit">
					添加银行卡信息
				</view>
				<view class="add-card-list1">
					<view class="add-card-list-name1">
						开户人姓名
					</view>
					<view class="add-card-list1-ipt">
						<input class="popup-input-field" name="bank_user_name" type="text"
							v-model="address.bank_user_name" placeholder="请填写银行卡开户人姓名" />
					</view>
				</view>
				<view class="add-card-list">
					<view class="add-card-list-name1">
						所属银行
					</view>
					<view class="add-card-list1-ipt">
						<input class="popup-input-field" name="bank_name" type="text" v-model="address.bank_name"
							placeholder="请填写所属银行" />
					</view>
				</view>
				<view class="add-card-list">
					<view class="add-card-list-name1">
						开户支行
					</view>
					<view class="add-card-list1-ipt">
						<input class="popup-input-field" name="bank_account" type="number"
							v-model="address.bank_account" placeholder="请填写开户支行" />
					</view>
				</view>
				<view class="add-card-list">
					<view class="add-card-list-name1">
						银行卡号
					</view>
					<view class="add-card-list1-ipt">
						<input class="popup-input-field" name="bank_card" type="number" v-model="address.bank_card"
							placeholder="请填写正确的银行卡号" />
					</view>
				</view>
			</view>
			<view class="bankCardSub">
				<button form-type="submit">提交银行卡信息</button>
			</view>
		</form>
		<!-- 弹窗地址传参数 -->
		<!-- <mpvue-city-picker v-if="is_load" ref="mpvueCityPicker" :province="province" :city="city" :area="area" :pickerValueDefault="cityPickerValueDefault" @onConfirm="onConfirm"></mpvue-city-picker> -->
	</view>
</template>

<script>
	export default {
		data() {
			return {
				address: {},
			}
		},
		methods: {
			formSubmit(e) {
				let self = this;
				var formdata = e.detail.value;
				// formdata.province_id = self.province_id;//有特殊表单的单独加参数

				// console.log(e, 'formdata');

				// 校验里面formdata就是赋值给formdata对象里面了,然后传参就可以传了

				if (formdata.bank_user_name == '') {
					uni.showToast({
						title: '请输入开户人姓名',
						duration: 1000,
						icon: 'none'
					});
					return false;
				}

				if (formdata.bank_name == '') {
					uni.showToast({
						title: '请输入所属银行',
						duration: 1000,
						icon: 'none'
					});
					return false;
				}

				if (formdata.bank_account == '') {
					uni.showToast({
						title: '请输入开户支行',
						duration: 1000,
						icon: 'none'
					});
					return false;
				}

				if (formdata.bank_card == '') {
					uni.showToast({
						title: '请输入银行卡号',
						duration: 1000,
						icon: 'none'
					});
					return false;
				}


				// if (formdata.phone == '') {
				// 	uni.showToast({
				// 		title: '请输入手机号码',
				// 		duration: 1000,
				// 		icon: 'none'
				// 	});
				// 	return false;
				// }

				// if (formdata.province_id == 0 || formdata.city_id == 0 || formdata.region_id) {
				// 	if (formdata.detail == '') {
				// 		uni.showToast({
				// 			title: '请选择完整省市区',
				// 			duration: 1000,
				// 			icon: 'none'
				// 		});
				// 		return false;
				// 	}
				// }

				self._post('user.user/bindUserBankData', formdata, function(res) {

					// self.showSuccess(res.msg, function() {
					// console.log(self.delta);
					// #ifdef  H5
					// uni.navigateBack({
					// 	delta: parseInt(self.delta)
					// });
					//#endif
					// #ifndef  H5
					// uni.navigateBack({
					// 	delta: 1
					// });
					//#endif
					// });
					
					// console.log(res, '添加成功');
					// 跳到添加成功
					if (res.msg == '添加成功') {
						uni.navigateTo({
							url: '/pages/user/my-bank-card/my-successfully-added-bank-card/my-successfully-added-bank-card'
						})
					} else {
						uni.showToast({
							title: '添加失败',
							duration: 1000,
							icon: 'none'
						});
					}
				});
			},
			/*清空数据*/
			formReset: function(e) {
				console.log('清空数据');
			},
		}
	}
</script>

<style scoped>
	page {
		background: #F8F9FA;
	}

	.my-add-bank-card {
		display: flex;
		flex-direction: column;
	}

	.my-add-bank-card-box {
		width: 686rpx;
		background: #FFFFFF;
		border-radius: 16rpx 16rpx 16rpx 16rpx;
		opacity: 1;
		margin: 20rpx 32rpx 80rpx 32rpx;
		padding: 24rpx 30rpx 0rpx 30rpx;
		box-sizing: border-box;
	}

	.add-card-tit {
		font-size: 36rpx;
		font-family: Source Han Sans-Medium, Source Han Sans;
		font-weight: 500;
		color: #333333;
		line-height: 50rpx;
		font-weight: bold;
	}

	.add-card-list1 {
		padding-top: 12rpx;
		padding-bottom: 30rpx;
		box-sizing: border-box;
		display: flex;
		align-items: center;
	}

	.add-card-list-name1 {
		font-size: 32rpx;
		font-family: Source Han Sans-Regular, Source Han Sans;
		font-weight: 400;
		color: #3D3D3D;
		line-height: 52rpx;
	}

	.add-card-list1-ipt {
		margin-left: 24rpx;
	}

	.add-card-list {
		padding-bottom: 30rpx;
		box-sizing: border-box;
		display: flex;
		align-items: center;
	}

	.bankCardSub {
		width: 554rpx;
		height: 84rpx;
		background: #891F50;
		border-radius: 137rpx 137rpx 137rpx 137rpx;
		opacity: 1;
		margin: 0 auto;
		display: flex;
		justify-content: center;
		align-items: center;
		font-size: 36rpx;
		font-family: Source Han Sans-Regular, Source Han Sans;
		font-weight: 400;
		color: #FFFFFF;
		line-height: 36rpx;
	}

	.bankCardSub button {
		width: 554rpx;
		height: 84rpx;
		background: #891F50;
		border-radius: 137rpx 137rpx 137rpx 137rpx;
		opacity: 1;
		margin: 0 auto;
		display: flex;
		justify-content: center;
		align-items: center;
		font-size: 36rpx;
		font-family: Source Han Sans-Regular, Source Han Sans;
		font-weight: 400;
		color: #FFFFFF;
		line-height: 36rpx;
	}
</style>

源码2

<template>
	<view class="my-add-bank-card">
		<!-- name="bank_name"  form表单提交的input里面一定要加name绑定要传的参数 name="bank_name" type="text" v-model="address.bank_name"  一定要name和 v-model参数保持一致!!!-->
		<form @submit="formSubmit" @reset="formReset">
			<view class="my-add-bank-card-box">
				<view class="add-card-tit">
					编辑银行卡信息
				</view>
				<view class="add-card-list1">
					<view class="add-card-list-name1">
						开户人姓名
					</view>
					<view class="add-card-list1-ipt">
						<input class="popup-input-field" name="bank_user_name" type="text"
							v-model="address.bank_user_name" placeholder="请填写银行卡开户人姓名" />
					</view>
				</view>
				<view class="add-card-list">
					<view class="add-card-list-name1">
						所属银行
					</view>
					<view class="add-card-list1-ipt">
						<input class="popup-input-field" name="bank_name" type="text" v-model="address.bank_name"
							placeholder="请填写所属银行" />
					</view>
				</view>
				<view class="add-card-list">
					<view class="add-card-list-name1">
						开户支行
					</view>
					<view class="add-card-list1-ipt">
						<input class="popup-input-field" name="bank_account" type="number"
							v-model="address.bank_account" placeholder="请填写开户支行" />
					</view>
				</view>
				<view class="add-card-list">
					<view class="add-card-list-name1">
						银行卡号
					</view>
					<view class="add-card-list1-ipt">
						<input class="popup-input-field" name="bank_card" type="number" v-model="address.bank_card"
							placeholder="请填写正确的银行卡号" />
					</view>
				</view>
			</view>
			<view class="bankCardSub">
				<button form-type="submit">提交银行卡信息</button>
			</view>
		</form>
		<!-- 弹窗地址传参数 -->
		<!-- <mpvue-city-picker v-if="is_load" ref="mpvueCityPicker" :province="province" :city="city" :area="area" :pickerValueDefault="cityPickerValueDefault" @onConfirm="onConfirm"></mpvue-city-picker> -->
	</view>
</template>

<script>
	export default {
		data() {
			return {
				address: {
					bank_user_name: '',
					bank_name: '',
					bank_account: '',
					bank_card: '',
					bank_id: ''
				},
			}
		},
		onLoad(onptions) {
			// console.log(onptions.bank_user_name, '接受bank_user_name');
			// console.log(onptions.bank_name, '接受bank_name');
			// console.log(onptions.bank_account, '接受bank_account');
			// console.log(onptions.bank_card, '接受bank_card');
			this.address.bank_user_name = onptions.bank_user_name;
			this.address.bank_name = onptions.bank_name;
			this.address.bank_account = onptions.bank_account;
			this.address.bank_card = onptions.bank_card;
			this.bank_id = onptions.bank_id;
		},
		methods: {
			formSubmit(e) {
				let self = this;
				var formdata = e.detail.value;
				// formdata.province_id = self.province_id;//有特殊表单的单独加参数

				// console.log(e, 'formdata');

				// 校验里面formdata就是赋值给formdata对象里面了,然后传参就可以传了

				this.bank_id = onptions.bank_id;
				
				formdata.bank_id = self.bank_id;	// 这个就是特殊的上一个页面传过来的参数id

				if (formdata.bank_user_name == '') {
					uni.showToast({
						title: '请输入开户人姓名',
						duration: 1000,
						icon: 'none'
					});
					return false;
				}

				if (formdata.bank_name == '') {
					uni.showToast({
						title: '请输入所属银行',
						duration: 1000,
						icon: 'none'
					});
					return false;
				}

				if (formdata.bank_account == '') {
					uni.showToast({
						title: '请输入开户支行',
						duration: 1000,
						icon: 'none'
					});
					return false;
				}

				if (formdata.bank_card == '') {
					uni.showToast({
						title: '请输入银行卡号',
						duration: 1000,
						icon: 'none'
					});
					return false;
				}


				// if (formdata.phone == '') {
				// 	uni.showToast({
				// 		title: '请输入手机号码',
				// 		duration: 1000,
				// 		icon: 'none'
				// 	});
				// 	return false;
				// }

				// if (formdata.province_id == 0 || formdata.city_id == 0 || formdata.region_id) {
				// 	if (formdata.detail == '') {
				// 		uni.showToast({
				// 			title: '请选择完整省市区',
				// 			duration: 1000,
				// 			icon: 'none'
				// 		});
				// 		return false;
				// 	}
				// }

				self._post('user.user/editBankData', formdata, function(res) {

					// self.showSuccess(res.msg, function() {
					// console.log(self.delta);
					// #ifdef  H5
					// uni.navigateBack({
					// 	delta: parseInt(self.delta)
					// });
					//#endif
					// #ifndef  H5
					// uni.navigateBack({
					// 	delta: 1
					// });
					//#endif
					// });

					// console.log(res, '添加成功');
					// 跳到添加成功
					if (res.msg == '添加成功') {
						uni.navigateTo({
							url: '/pages/user/my-bank-card/my-successfully-edit-bank-card/my-successfully-edit-bank-card'
						})
					} else {
						uni.showToast({
							title: '添加失败',
							duration: 1000,
							icon: 'none'
						});
					}
				});
			},
			/*清空数据*/
			formReset: function(e) {
				console.log('清空数据');
			},
		}
	}
</script>

<style scoped>
	page {
		background: #F8F9FA;
	}

	.my-add-bank-card {
		display: flex;
		flex-direction: column;
	}

	.my-add-bank-card-box {
		width: 686rpx;
		background: #FFFFFF;
		border-radius: 16rpx 16rpx 16rpx 16rpx;
		opacity: 1;
		margin: 20rpx 32rpx 80rpx 32rpx;
		padding: 24rpx 30rpx 0rpx 30rpx;
		box-sizing: border-box;
	}

	.add-card-tit {
		font-size: 36rpx;
		font-family: Source Han Sans-Medium, Source Han Sans;
		font-weight: 500;
		color: #333333;
		line-height: 50rpx;
		font-weight: bold;
	}

	.add-card-list1 {
		padding-top: 12rpx;
		padding-bottom: 30rpx;
		box-sizing: border-box;
		display: flex;
		align-items: center;
	}

	.add-card-list-name1 {
		font-size: 32rpx;
		font-family: Source Han Sans-Regular, Source Han Sans;
		font-weight: 400;
		color: #3D3D3D;
		line-height: 52rpx;
	}

	.add-card-list1-ipt {
		margin-left: 24rpx;
	}

	.add-card-list {
		padding-bottom: 30rpx;
		box-sizing: border-box;
		display: flex;
		align-items: center;
	}

	.bankCardSub {
		width: 554rpx;
		height: 84rpx;
		background: #891F50;
		border-radius: 137rpx 137rpx 137rpx 137rpx;
		opacity: 1;
		margin: 0 auto;
		display: flex;
		justify-content: center;
		align-items: center;
		font-size: 36rpx;
		font-family: Source Han Sans-Regular, Source Han Sans;
		font-weight: 400;
		color: #FFFFFF;
		line-height: 36rpx;
	}

	.bankCardSub button {
		width: 554rpx;
		height: 84rpx;
		background: #891F50;
		border-radius: 137rpx 137rpx 137rpx 137rpx;
		opacity: 1;
		margin: 0 auto;
		display: flex;
		justify-content: center;
		align-items: center;
		font-size: 36rpx;
		font-family: Source Han Sans-Regular, Source Han Sans;
		font-weight: 400;
		color: #FFFFFF;
		line-height: 36rpx;
	}
</style>

最后

感觉文章好的话记得点个心心和关注和收藏,有错的地方麻烦指正一下,如果需要转载,请标明出处,多谢!!!

### UniApp 前端集成 Captcha 验证实现方案 在 UniApp 中接入 Captcha 验证功能可以通过自定义组件的方式完成。以下是详细的实现方法: #### 1. 创建 Captcha 组件 创建一个新的 Vue 组件 `Captcha.vue`,用于封装腾讯验证码逻辑。 ```vue <template> <view class="captcha-container"> <!-- 容器 --> <div ref="captchaContainer"></div> </view> </template> <script> export default { name: 'Captcha', props: ['appId', 'callback'], // 接收 appId 和回调函数作为参数 mounted() { this.initCaptcha(); }, methods: { initCaptcha() { const container = this.$refs.captchaContainer; if (!container) return; new TencentCaptcha(container, this.appId, (res) => { // 调用父组件传递的回调函数处理结果 if (typeof this.callback === 'function') { this.callback(res); } }, { type: 'embed' }).show(); // 使用嵌入式模式 } } }; </script> <style scoped> .captcha-container { width: 100%; height: auto; } </style> ``` 此部分代码实现了通过传入 `appId` 和回调函数来初始化并显示验证码的功能[^1]。 --- #### 2. 在父组件中引入并使用 Captcha 组件 修改父组件以加载和调用 Captcha 功能。 ```vue <template> <view> <!-- 验证码 --> <Captcha :appId="captchaAppId" @callback="handleCaptchaResponse" /> <button @click="submit">提交</button> </view> </template> <script> import Captcha from '@/components/Captcha'; export default { components: { Captcha, }, data() { return { captchaAppId: 'your-captcha-app-id-here', // 替换为实际 App ID captchaResult: null, }; }, methods: { handleCaptchaResponse(response) { console.log('Captcha Response:', response); this.captchaResult = response.ticket; // 存储 ticket 数据以便后续使用 }, submit() { if (!this.captchaResult) { alert('请先完成验证码验证'); return; } // 提交表单或其他操作... console.log('Submit with Captcha Ticket:', this.captchaResult); }, }, }; </script> ``` 在此代码片段中,父组件负责接收子组件返回的结果并通过按钮触发进一步的操作。 --- #### 3. 初始化腾讯验证码 SDK 为了使上述代码正常工作,需确保已在项目中正确配置腾讯验证码 SDK。可以按照以下步骤操作: - 下载腾讯验证码 JS 文件或将 CDN 地址加入 HTML 页面头部。 - 如果使用 NPM 或 Yarn,则可通过安装依赖包完成导入。 示例: ```javascript // main.js 或其他入口文件 import '@tencent/captcha'; // 确保路径正确或替换为 CDN 引入方式 ``` 或者直接在页面中添加脚本标签: ```html <script src="https://ssl.captcha.qq.com/TCaptcha.js"></script> ``` 以上步骤基于官方文档说明[^2]^。 --- #### 4. 测试与优化 测试时注意检查以下几点: - 是否成功渲染验证码; - 用户交互完成后是否能正确获取到票券数据 (`ticket`) 并回传给服务器; - 不同设备上的兼容性和样式调整。 更多细节可参考 [AnJi Plus 的 Captcha 文档](https://captcha.anji-plus.com/#/),其中提供了丰富的跨平台解决方案[^3]。 --- ### 注意事项 - **安全性**:始终将最终校验逻辑放置于服务端执行,防止伪造请求。 - **用户体验**:合理控制验证码出现频率以免影响正常使用体验。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值