submit.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <template>
  2. <CommonRoot>
  3. <FlexCol :gap="20" :padding="30">
  4. <!--注册-->
  5. <FlexCol v-if="step === 'register'">
  6. <DynamicForm
  7. ref="registerFormRef"
  8. :model="registerFormModel"
  9. :options="registerFormDefine"
  10. />
  11. <Height :height="20" />
  12. <Button block type="primary" @click="registerSubmit" :loading="registerFormLoading">提交</Button>
  13. </FlexCol>
  14. <!--注册完成-->
  15. <Result
  16. v-else-if="step === 'finished'"
  17. status="success"
  18. title="注册志愿者成功"
  19. description="请等待管理员审核,在此期间,可以在社区中先逛逛,学习如何采编村社文化资源信息吧"
  20. >
  21. <Height :size="20" />
  22. <Button type="primary" @click="back()">进入首页</Button>
  23. </Result>
  24. <!--错误-->
  25. <Result
  26. v-else-if="step === 'error'"
  27. status="error"
  28. title="分享链接参数有误"
  29. description="请联系管理员,或稍后重试"
  30. />
  31. <!--登录-->
  32. <FlexCol v-else center :height="400">
  33. <Icon icon="smile-filling" color="primary" :size="156" />
  34. <Height :height="20" />
  35. <Text :fontSize="26" color="primary" text="欢迎注册,加入志愿者队伍,点亮村落" />
  36. <Height :size="40" />
  37. <!-- #ifdef MP-WEIXIN -->
  38. <Button type="primary" block text="微信登录" @click="loginWechat" />
  39. <Height :size="20" />
  40. <!-- #endif -->
  41. <!-- #ifndef MP-WEIXIN -->
  42. <Result status="warning" title="提示" desc="当前环境不支持微信登录" />
  43. <!-- #endif -->
  44. </FlexCol>
  45. </FlexCol>
  46. </CommonRoot>
  47. </template>
  48. <script setup lang="ts">
  49. import Button from '@/components/basic/Button.vue';
  50. import Result from '@/components/feedback/Result.vue';
  51. import FlexCol from '@/components/layout/FlexCol.vue';
  52. import Height from '@/components/layout/space/Height.vue';
  53. import Icon from '@/components/basic/Icon.vue';
  54. import Text from '@/components/basic/Text.vue';
  55. import CommonRoot from '@/components/dialog/CommonRoot.vue';
  56. import DynamicForm from '@/components/dynamic/DynamicForm.vue';
  57. import { useAppInit } from '@/common/composeabe/AppInit';
  58. import { UserApi } from '@/api/auth/UserApi';
  59. import { useAuthStore } from '@/store/auth';
  60. import { back } from '@/components/utils/PageAction';
  61. import { closeToast, toast } from '@/components/dialog/CommonRoot';
  62. import { showError } from '@/common/composeabe/ErrorDisplay';
  63. import { useLoadQuerys } from '@/components/composeabe/LoadQuerys';
  64. import { onMounted, ref } from 'vue';
  65. import VillageApi, { VolunteerInfo } from '@/api/inhert/VillageApi';
  66. import type { IDynamicFormOptions, IDynamicFormRef } from '@/components/dynamic';
  67. import { waitTimeOut } from '@imengyu/imengyu-utils';
  68. import { getVolunteerForm } from './form/volunteer';
  69. /**
  70. * 点亮村社页面
  71. */
  72. const authStore = useAuthStore();
  73. const { init } = useAppInit();
  74. const { querys } = useLoadQuerys({
  75. villageId: 0,
  76. regionId: 0,
  77. unit: '',
  78. });
  79. const step = ref<'register' |'add'|'finished'|'error'>('register');
  80. onMounted(async () => {
  81. if (!querys.value.villageId) {
  82. step.value = 'error';
  83. return;
  84. }
  85. //如果已登录,则尝试获取志愿者信息,有注册志愿者,则显示认领当前村落表单
  86. /* if (authStore.isLogged) {
  87. try {
  88. const volunteerInfo = await VillageApi.getVolunteerInfo();
  89. if (volunteerInfo) {
  90. step.value = 'add';
  91. return;
  92. }
  93. } catch {
  94. }
  95. } */
  96. await waitTimeOut(1000);
  97. registerFormDefine.value = getVolunteerForm({
  98. canSetCatalog: false,
  99. villageId: querys.value.villageId,
  100. onlyPassword: false,
  101. isNew: ref(true),
  102. formRef: registerFormRef,
  103. });
  104. registerFormModel.value.regionId = querys.value.regionId;
  105. registerFormModel.value.unit = querys.value.unit;
  106. });
  107. async function loginWechat() {
  108. toast({
  109. type: 'loading',
  110. content: '登录中...',
  111. })
  112. try {
  113. const res = await Promise.all([
  114. uni.login({ provider: 'weixin' }),
  115. uni.getUserProfile({ desc: '用于完善会员资料' }),
  116. ]);
  117. await authStore.loginWechart(res[0].code, res[1]);
  118. toast({
  119. type: 'success',
  120. content: '登录成功',
  121. });
  122. step.value = 'register';
  123. } catch(e) {
  124. showError(e);
  125. } finally {
  126. closeToast();
  127. }
  128. }
  129. const registerFormLoading = ref(false);
  130. const registerFormRef = ref<IDynamicFormRef>();
  131. const registerFormModel = ref<VolunteerInfo>(new VolunteerInfo());
  132. const registerFormDefine = ref<IDynamicFormOptions>();
  133. async function registerSubmit() {
  134. if (!registerFormRef.value || !registerFormModel.value)
  135. return;
  136. try {
  137. await registerFormRef.value.validate();
  138. } catch (e) {
  139. toast({ content: '有必填项未填写,请检查' });
  140. return;
  141. }
  142. try {
  143. registerFormLoading.value = true;
  144. registerFormModel.value!.villageId = querys.value.villageId;
  145. const loginRes = await VillageApi.shareAddVolunteer(registerFormModel.value as VolunteerInfo);
  146. await authStore.loginResultHandle(loginRes, UserApi.LOGIN_TYPE_USER);
  147. await init();
  148. toast({ content: '注册成功' });
  149. step.value = 'finished';
  150. } catch (e) {
  151. showError(e);
  152. } finally {
  153. registerFormLoading.value = false;
  154. }
  155. }
  156. </script>