index.vue 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <template>
  2. <view class="register-bg">
  3. <auth-wrap class="register-container" ref="authWrap">
  4. <view class="form-content" slot="content">
  5. <RegistForm v-if="rules" :rules="rules" ref="registForm" @onSubmitHandle="onFormSubmit"></RegistForm>
  6. </view>
  7. </auth-wrap>
  8. </view>
  9. </template>
  10. <script>
  11. import { fetchUsrInfo, formCfg, putUsrRegist } from '@/common/api';
  12. import { ICON_CFG, MEETING_TYPE, USR_TYPE_LIST } from '@/common/EnumConst';
  13. import AuthWrap from '@/components/AuthComp/index.vue';
  14. import RegistForm from '@/components/RegistForm';
  15. import SingleDropList from '@/components/SingleDropList/index.vue';
  16. import { getUserInfo, setUserInfo } from '@/util';
  17. const staticRules = {
  18. 'userInfo.email': {
  19. pattern: /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/,
  20. },
  21. };
  22. export default {
  23. name: 'login',
  24. components: {
  25. RegistForm,
  26. AuthWrap,
  27. SingleDropList,
  28. },
  29. props: {},
  30. data() {
  31. return {
  32. ICON_CFG,
  33. USR_TYPE_LIST,
  34. showEnterprise: false,
  35. loading: false,
  36. model1: {
  37. userInfo: {
  38. usrName: '',
  39. conferenceFlag: '1',
  40. },
  41. },
  42. rules: null,
  43. };
  44. },
  45. created() {
  46. },
  47. async onLoad() {
  48. const { msg } = await formCfg('meet_form_cfg');
  49. if (msg) {
  50. const cfgJson = JSON.parse(msg);
  51. Object.keys(staticRules).forEach(item => {
  52. if (!cfgJson[item]) {
  53. Object.assign(cfgJson[item], staticRules[item]);
  54. }
  55. });
  56. this.rules = cfgJson;
  57. }
  58. //如果需要兼容微信小程序,并且校验规则中含有方法等,只能通过setRules方法设置规则。
  59. this.$refs.authWrap.reloadPage();
  60. this.$refs.registForm?.setFormRules();
  61. },
  62. onReady() {
  63. },
  64. methods: {
  65. hideKeyboard() {
  66. uni.hideKeyboard();
  67. },
  68. async onFormSubmit(userInfo) {
  69. const { code } = await putUsrRegist(userInfo, MEETING_TYPE.meeting.value);
  70. if (code !== 200) {
  71. return;
  72. }
  73. uni.showToast({
  74. mask: true,
  75. title: '报名完成',
  76. icon: 'success',
  77. success: async () => {
  78. const user = getUserInfo();
  79. const newUsr = await fetchUsrInfo(user.id);
  80. if (newUsr.code === 200) {
  81. setUserInfo(newUsr.data);
  82. }
  83. uni.navigateBack({
  84. delta: 1,
  85. });
  86. },
  87. });
  88. },
  89. },
  90. };
  91. </script>
  92. <style lang="scss" src="./index.scss" />;