index.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. <template>
  2. <view class="content">
  3. <view class="info">
  4. <scroll-view scroll-y="true" class="scroll-view">
  5. <view class="list-scroll-view">
  6. <view class="wx">
  7. <view class="wx_1">
  8. <image class="image" src="/static/login.png">
  9. </image>
  10. </view>
  11. <view class="wx_2">
  12. <view class="textOne">当前业务需要人脸识别验证</view>
  13. <view class="textTwo">信息将用于公证业务办理,并与当前微信绑定</view>
  14. </view>
  15. <view class="wx_3">
  16. <u--form class="form" :model="form" ref="uForm" :rules="rules" labelWidth="70"
  17. label-position="top">
  18. <u-form-item label="证件号码" prop="card">
  19. <input class="input" v-model="form.card" placeholder="填写证件号码" />
  20. </u-form-item>
  21. <u-form-item label="姓名" prop="name">
  22. <input class="input" v-model="form.name" placeholder="填写姓名" />
  23. </u-form-item>
  24. <u-form-item label="手机号" prop="phone">
  25. <input class="input" v-model="form.phone" placeholder="填写常用手机号" />
  26. </u-form-item>
  27. </u--form>
  28. </view>
  29. <view class="wx_4">
  30. <checkbox-group @change="changeAgree">
  31. <label>
  32. <checkbox color="#2979ff" :checked="agree" />
  33. <text @tap.stop="toAgree()">我同意使用我所提交的信息用于身份验证及公证业务办理,阅读<text
  34. style="color: #2979ff;">《用户服务协议》</text>和 <text
  35. style="color: #2979ff;">《隐私策略》</text></text>
  36. </label>
  37. </checkbox-group>
  38. </view>
  39. </view>
  40. </view>
  41. </scroll-view>
  42. </view>
  43. <view class="foot">
  44. <button class="btn" @tap="formSubmit">开始验证</button>
  45. </view>
  46. </view>
  47. </template>
  48. <script setup lang="ts">
  49. import moment from 'moment';
  50. import { getCurrentInstance, computed, ref } from 'vue';
  51. //该依赖已内置不需要单独安装
  52. import { onShow, onPullDownRefresh } from "@dcloudio/uni-app";
  53. // 请求接口
  54. const $api = getCurrentInstance()?.appContext.config.globalProperties.$api;
  55. // openid
  56. const openid = computed(() => {
  57. return uni.getStorageSync('openid');
  58. })
  59. // 用户协议
  60. const agree = ref(false);
  61. const form = ref({ name: '', card: '', phone: '' });
  62. const rules = {
  63. 'card': [{
  64. required: true,
  65. message: '请填写身份证号',
  66. },
  67. {
  68. validator: function (rule, value, data, callback) {
  69. if (value.indexOf('**') > -1) {
  70. callback()
  71. return
  72. }
  73. let idCard = (
  74. /^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/
  75. ); //
  76. return idCard.test(value)
  77. },
  78. message: '身份证格式不正确,请重新填写'
  79. }
  80. ],
  81. 'name': {
  82. type: 'string',
  83. required: true,
  84. message: '请输入姓名',
  85. trigger: ['blur', 'change'],
  86. },
  87. 'phone': [
  88. {
  89. required: true,
  90. message: '请输入手机号',
  91. trigger: ['change', 'blur'],
  92. },
  93. {
  94. // 自定义验证函数,见上说明
  95. validator: (rule, value, callback) => {
  96. return uni.$u.test.mobile(value);
  97. },
  98. message: '手机号码不正确',
  99. trigger: ['change', 'blur'],
  100. }
  101. ]
  102. }
  103. const uForm = ref(null);
  104. onShow(() => {
  105. if (openid.value) search();
  106. })
  107. // 查询
  108. const search = async () => {
  109. const res = await $api(`login/wxapp/${openid.value}`, 'POST', {});
  110. if (res.errcode == '0') {
  111. form.value = res.data
  112. uni.setStorageSync('user', res.data);
  113. }
  114. };
  115. // 开始验证
  116. const formSubmit = () => {
  117. if (agree.value) {
  118. if (openid.value) {
  119. uForm.value.validate().then(async res => {
  120. uni.getUserProfile({
  121. desc: '用于展示',
  122. success: async function (res) {
  123. let parmas = {
  124. openid: openid.value,
  125. nickname: res.userInfo.nickName + moment().valueOf()
  126. }
  127. const arr = await $api(`user`, 'POST', { ...form.value, ...parmas });
  128. if (arr.errcode == '0') {
  129. uni.setStorageSync('user', arr.data);
  130. uni.navigateBack({
  131. delta: 1
  132. })
  133. } else {
  134. uni.showToast({
  135. title: arr.errmsg,
  136. icon: 'error'
  137. });
  138. }
  139. },
  140. fail: function (err) {
  141. console.log(err);
  142. }
  143. })
  144. }).catch(err => {
  145. console.log(err, '校验失败');
  146. })
  147. } else {
  148. uni.showToast({
  149. title: '系统更新中,请稍后再试!',
  150. icon: 'none'
  151. })
  152. }
  153. } else {
  154. uni.showToast({
  155. title: '请阅读并同意用户协议和隐私政策',
  156. icon: 'none'
  157. })
  158. }
  159. };
  160. // 查看隐私协议
  161. const toAgree = () => {
  162. uni.navigateTo({
  163. url: `/pagesHome/agree/index`
  164. })
  165. };
  166. // 同意隐私协议
  167. const changeAgree = () => {
  168. agree.value = !agree.value;
  169. };
  170. </script>
  171. <style lang="scss" scoped>
  172. .content {
  173. display: flex;
  174. flex-direction: column;
  175. width: 100vw;
  176. height: 100vh;
  177. .info {
  178. position: relative;
  179. flex-grow: 1;
  180. .wx {
  181. .wx_1 {
  182. text-align: center;
  183. padding: 10vw;
  184. .image {
  185. width: 35vw;
  186. height: 27vw;
  187. }
  188. }
  189. .wx_2 {
  190. text-align: center;
  191. .textOne {
  192. font-size: var(--font16Size);
  193. }
  194. .textTwo {
  195. font-size: var(--font14Size);
  196. margin: 2vw 0 0 0;
  197. color: var(--f85Color);
  198. }
  199. }
  200. .wx_3 {
  201. margin: 5vw;
  202. }
  203. .wx_4 {
  204. padding: 2vw;
  205. text-align: center;
  206. font-size: var(--font12Size);
  207. }
  208. }
  209. }
  210. .foot {
  211. padding: 2vw;
  212. .btn {
  213. font-size: var(--font14Size);
  214. color: var(--mainColor);
  215. background-color: var(--fFFColor);
  216. }
  217. }
  218. }
  219. .scroll-view {
  220. position: absolute;
  221. top: 0;
  222. left: 0;
  223. right: 0;
  224. bottom: 0;
  225. .list-scroll-view {
  226. display: flex;
  227. flex-direction: column;
  228. }
  229. }
  230. </style>