hookehuyr

✨ feat(实名认证页面): 接口预联调

...@@ -5,14 +5,19 @@ ...@@ -5,14 +5,19 @@
5 <van-config-provider :theme-vars="themeVars"> 5 <van-config-provider :theme-vars="themeVars">
6 <van-form ref="form" @submit="onSubmit"> 6 <van-form ref="form" @submit="onSubmit">
7 <div class="van-hairline--bottom"> 7 <div class="van-hairline--bottom">
8 - <van-field v-model="parent" label="家长姓名" placeholder="请输入你真实的姓名" :rules="[{ required: true, message: '请填写家长姓名' }]" /> 8 + <van-field v-model="user_name" label="家长姓名" placeholder="请输入你真实的姓名"
9 + :rules="[{ required: true, message: '请填写家长姓名' }]" />
9 </div> 10 </div>
10 <div class="van-hairline--bottom"> 11 <div class="van-hairline--bottom">
11 - <van-field v-if="use_widget" v-model="phone" name="phone" label="手机号" placeholder="手机号" readonly clickable @touchstart.stop="showKeyboard" /> 12 + <van-field v-if="use_widget" v-model="phone" name="phone" label="手机号" placeholder="手机号" readonly clickable
12 - <van-field v-else v-model="phone" name="phone" label="手机号" placeholder="手机号" :rules="[{ validator, message: '请输入正确手机号' }]" /> 13 + :rules="[{ validator, message: '请输入正确手机号' }]"
14 + @touchstart.stop="showKeyboard" />
15 + <van-field v-else v-model="phone" name="phone" label="手机号" placeholder="手机号"
16 + :rules="[{ validator, message: '请输入正确手机号' }]" />
13 </div> 17 </div>
14 <div class="van-hairline--bottom"> 18 <div class="van-hairline--bottom">
15 - <van-field v-model="code" center clearable name="code" label="短信验证码" placeholder="请输入短信验证码" :formatter="formatter" :rules="[{ required: true, message: '请填写验证码' }]" > 19 + <van-field v-model="pin" center clearable name="pin" label="短信验证码" placeholder="请输入短信验证码"
20 + :formatter="formatter" :rules="[{ required: true, message: '请填写验证码' }]">
16 <template #button> 21 <template #button>
17 <van-button @click="sendCode" size="small" type="primary" :disabled="disabled"> 22 <van-button @click="sendCode" size="small" type="primary" :disabled="disabled">
18 <span v-if="countDown === 60">发送验证码</span> 23 <span v-if="countDown === 60">发送验证码</span>
...@@ -30,25 +35,19 @@ ...@@ -30,25 +35,19 @@
30 <my-button @on-click="submit" type="primary">保存</my-button> 35 <my-button @on-click="submit" type="primary">保存</my-button>
31 </div> 36 </div>
32 37
33 - <van-number-keyboard 38 + <van-number-keyboard v-model="phone" :show="keyboard_show" :maxlength="11" @blur="onBlur" />
34 - v-model="phone"
35 - :show="keyboard_show"
36 - :maxlength="11"
37 - @blur="onBlur"
38 - />
39 </template> 39 </template>
40 40
41 <script setup> 41 <script setup>
42 import MyButton from '@/components/MyButton/index.vue' 42 import MyButton from '@/components/MyButton/index.vue'
43 43
44 import { wxInfo } from '@/utils/tools'; 44 import { wxInfo } from '@/utils/tools';
45 -import qs from 'Qs' 45 +
46 -import { ref, reactive, onMounted } from 'vue' 46 +import { ref, onMounted, nextTick } from 'vue'
47 -import { useRoute, useRouter } from 'vue-router' 47 +import { useRouter } from 'vue-router'
48 import axios from '@/utils/axios'; 48 import axios from '@/utils/axios';
49 -import $ from 'jquery'
50 import { Toast } from 'vant'; 49 import { Toast } from 'vant';
51 -const $route = useRoute(); 50 +
52 const $router = useRouter(); 51 const $router = useRouter();
53 52
54 const themeVars = { 53 const themeVars = {
...@@ -57,54 +56,35 @@ const themeVars = { ...@@ -57,54 +56,35 @@ const themeVars = {
57 buttonPrimaryColor: '#713610', 56 buttonPrimaryColor: '#713610',
58 }; 57 };
59 58
60 -const parent = ref('') 59 +/******************** 输入框控件 START ********************/
61 60
62 -// 判断是否显示控件
63 -let use_widget = ref(true);
64 /** 61 /**
65 - * 手机号码校验 62 + * 判断微信环境看是否弹出控件框
66 - * 函数返回 true 表示校验通过,false 表示不通过 63 + * 桌面微信直接输入
67 - * @param {*} val 64 + * 其他环境弹出输入框
68 */ 65 */
69 -const validator = (val) => { 66 +let use_widget = ref(true);
70 - let flag = false; 67 +if (wxInfo().isiOS || wxInfo().isAndroid) {
71 - // 简单判断手机号位数 68 + use_widget.value = true;
72 - if (/1\d{10}/.test(val) && phone.value.length === 11) { 69 +} else {
73 - disabled.value = false; 70 + use_widget.value = false;
74 - flag = true; 71 +}
75 - } else {
76 - disabled.value = true;
77 - flag = false;
78 - }
79 - return flag
80 -};
81 -
82 - onMounted(() => {
83 - /**
84 - * 判断微信环境看是否弹出控件框
85 - * 桌面微信直接输入
86 - * 其他环境弹出输入框
87 - */
88 - if (wxInfo().isiOS || wxInfo().isAndroid) {
89 - use_widget.value = true;
90 - } else {
91 - use_widget.value = false;
92 - }
93 - })
94 72
95 -// 手机号输入控件控制 73 +// 手机号输入控件
96 const keyboard_show = ref(false); 74 const keyboard_show = ref(false);
97 const showKeyboard = () => { // 弹出数字弹框 75 const showKeyboard = () => { // 弹出数字弹框
98 keyboard_show.value = true; 76 keyboard_show.value = true;
99 }; 77 };
100 const onBlur = () => { // 数字键盘失焦回调 78 const onBlur = () => { // 数字键盘失焦回调
101 keyboard_show.value = false; 79 keyboard_show.value = false;
102 - if (phone.value.length === 11) { 80 + if (phone.value.length === 11) { // 手机号码位数正确时可以发送验证码
103 disabled.value = false; 81 disabled.value = false;
104 } 82 }
105 }; 83 };
106 84
107 -// 设置发送短信倒计时 85 +/******************** 发送验证码模块 START ********************/
86 +
87 +// TODO:发送验证码接口待调,验证码写默认8888
108 const countDown = ref(60); 88 const countDown = ref(60);
109 const countDownHandle = () => { 89 const countDownHandle = () => {
110 // 倒计时 90 // 倒计时
...@@ -119,14 +99,84 @@ const countDownHandle = () => { ...@@ -119,14 +99,84 @@ const countDownHandle = () => {
119 } 99 }
120 const sendCode = () => { // 发送验证码 100 const sendCode = () => { // 发送验证码
121 if (countDown.value === 60) { 101 if (countDown.value === 60) {
122 - axios.post('/srv/?f=shzl_comment&a=bind_phone&t=get_code', 102 + axios.post('/srv/?a=bind_phone&t=get_code', {
123 - qs.stringify({
124 phone: phone.value 103 phone: phone.value
125 - })) 104 + })
105 + .then(res => {
106 + if (res.data.code === 1) {
107 + Toast.success('发送成功');
108 + countDownHandle()
109 + } else {
110 + console.warn(res.data);
111 + Toast({
112 + message: res.data.msg,
113 + icon: 'close',
114 + });
115 + }
116 + })
117 + .catch(err => {
118 + console.error(err);
119 + })
120 + }
121 +};
122 +
123 +/******************** 表单业务逻辑 START ********************/
124 +
125 +const user_name = ref('')
126 +const phone = ref('');
127 +const pin = ref('');
128 +const disabled = ref(true);
129 +
130 +// 表单填写验证
131 +const form = ref(null);
132 +let valid = null;
133 +let submit = () => {
134 + valid = form.value.validate();
135 + valid
136 + .then(() => {
137 + form.value.submit();
138 + })
139 + .catch(error => {
140 + console.error(error);
141 + Toast({
142 + message: '请检查后再次提交',
143 + icon: 'cross',
144 + });
145 + })
146 +};
147 +
148 +/**
149 + * 手机号码校验
150 + * 函数返回 true 表示校验通过,false 表示不通过
151 + * @param {*} val
152 + */
153 +const validator = (val) => {
154 + let flag = false;
155 + // 简单判断手机号位数
156 + if (/1\d{10}/.test(val) && phone.value.length === 11) {
157 + disabled.value = false;
158 + flag = true;
159 + } else {
160 + disabled.value = true;
161 + flag = false;
162 + }
163 + return flag
164 +};
165 +
166 +// 过滤输入的验证码 只能四位
167 +const formatter = (value) => value.substring(0, 4);
168 +
169 +// 保存用户信息
170 +const onSubmit = (values) => {
171 + axios.post('/srv/?a=c_auth', {
172 + user_name: values.user_name,
173 + phone: values.phone,
174 + pin: values.pin,
175 + })
126 .then(res => { 176 .then(res => {
127 if (res.data.code === 1) { 177 if (res.data.code === 1) {
128 - Toast.success('发送成功'); 178 + Toast.success('录入成功')
129 - countDownHandle() 179 + $router.go(-1);
130 } else { 180 } else {
131 console.warn(res.data); 181 console.warn(res.data);
132 Toast({ 182 Toast({
...@@ -136,41 +186,12 @@ const sendCode = () => { // 发送验证码 ...@@ -136,41 +186,12 @@ const sendCode = () => { // 发送验证码
136 } 186 }
137 }) 187 })
138 .catch(err => { 188 .catch(err => {
139 - console.error(err); 189 + console.error(err);
140 }) 190 })
141 - }
142 }; 191 };
143 192
144 -const phone = ref(''); 193 +/****************************************/
145 -const code = ref('');
146 -const disabled = ref(true);
147 -// 过滤输入的数字 只能四位
148 -const formatter = (value) => value.substring(0, 4);
149 194
150 -// 保存用户信息
151 -const onSubmit = (values) => {
152 - axios.post('/srv/?f=shzl_comment&a=bind_phone&t=bind',
153 - qs.stringify({
154 - phone: values.phone,
155 - code: values.code,
156 - }))
157 - .then(res => {
158 - if (res.data.code === 1) {
159 - $router.push({
160 - path: '/'
161 - });
162 - } else {
163 - console.warn(res.data);
164 - Toast({
165 - message: res.data.msg,
166 - icon: 'close',
167 - });
168 - }
169 - })
170 - .catch(err => {
171 - console.error(err);
172 - })
173 -};
174 </script> 195 </script>
175 196
176 <script> 197 <script>
...@@ -178,29 +199,15 @@ import mixin from 'common/mixin'; ...@@ -178,29 +199,15 @@ import mixin from 'common/mixin';
178 199
179 export default { 200 export default {
180 mixins: [mixin.init], 201 mixins: [mixin.init],
181 - data () { 202 + data() {
182 return { 203 return {
183 204
184 } 205 }
185 }, 206 },
186 - mounted () { 207 + mounted() {
187 208
188 }, 209 },
189 methods: { 210 methods: {
190 - submit () {
191 - let valid = this.$refs.form.validate();
192 - valid
193 - .then(() => {
194 - this.$refs.form.submit();
195 - })
196 - .catch(error => {
197 - console.error(error);
198 - this.$toast({
199 - message: '请检查后再次提交',
200 - icon: 'cross',
201 - });
202 - })
203 - }
204 } 211 }
205 } 212 }
206 </script> 213 </script>
......