index.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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" v-if="!form._id">
  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') form.value = res.data
  111. };
  112. // 开始验证
  113. const formSubmit = () => {
  114. if (agree.value) {
  115. if (openid.value) {
  116. uForm.value.validate().then(async res => {
  117. if (!form.value._id) {
  118. uni.getUserProfile({
  119. desc: '用于展示',
  120. success: async function (res) {
  121. let parmas = {
  122. openid: openid.value,
  123. nickname: res.userInfo.nickName + moment().valueOf()
  124. }
  125. const arr = await $api(`user`, 'POST', { ...form.value, ...parmas });
  126. if (arr.errcode == '0') {
  127. uni.setStorageSync('user', arr.data);
  128. uni.navigateBack({
  129. delta: 1
  130. })
  131. } else {
  132. uni.showToast({
  133. title: arr.errmsg,
  134. icon: 'error'
  135. });
  136. }
  137. },
  138. fail: function (err) {
  139. console.log(err);
  140. }
  141. })
  142. } else {
  143. uni.setStorageSync('user', form.value);
  144. uni.navigateBack({
  145. delta: 1
  146. })
  147. }
  148. }).catch(err => {
  149. console.log(err, '校验失败');
  150. })
  151. } else {
  152. uni.showToast({
  153. title: '系统更新中,请稍后再试!',
  154. icon: 'none'
  155. })
  156. }
  157. } else {
  158. uni.showToast({
  159. title: '请阅读并同意用户协议和隐私政策',
  160. icon: 'none'
  161. })
  162. }
  163. };
  164. // 查看隐私协议
  165. const toAgree = () => {
  166. uni.navigateTo({
  167. url: `/pagesHome/agree/index`
  168. })
  169. };
  170. // 同意隐私协议
  171. const changeAgree = () => {
  172. agree.value = !agree.value;
  173. };
  174. </script>
  175. <style lang="scss" scoped>
  176. .content {
  177. display: flex;
  178. flex-direction: column;
  179. width: 100vw;
  180. height: 100vh;
  181. .info {
  182. position: relative;
  183. flex-grow: 1;
  184. .wx {
  185. .wx_1 {
  186. text-align: center;
  187. padding: 10vw;
  188. .image {
  189. width: 35vw;
  190. height: 27vw;
  191. }
  192. }
  193. .wx_2 {
  194. text-align: center;
  195. .textOne {
  196. font-size: var(--font16Size);
  197. }
  198. .textTwo {
  199. font-size: var(--font14Size);
  200. margin: 2vw 0 0 0;
  201. color: var(--f85Color);
  202. }
  203. }
  204. .wx_3 {
  205. margin: 5vw;
  206. }
  207. .wx_4 {
  208. position: absolute;
  209. bottom: 10px;
  210. padding: 2vw;
  211. text-align: center;
  212. font-size: var(--font12Size);
  213. }
  214. }
  215. }
  216. .foot {
  217. padding: 2vw;
  218. .btn {
  219. font-size: var(--font14Size);
  220. color: var(--mainColor);
  221. background-color: var(--fFFColor);
  222. }
  223. }
  224. }
  225. .scroll-view {
  226. position: absolute;
  227. top: 0;
  228. left: 0;
  229. right: 0;
  230. bottom: 0;
  231. .list-scroll-view {
  232. display: flex;
  233. flex-direction: column;
  234. }
  235. }
  236. </style>