Index.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <template>
  2. <app-view class="g-form">
  3. <template #header>
  4. <app-navbar :title="$t('mine.profile.wechat')" />
  5. </template>
  6. <Form ref="formRef" class="g-form__container" @submit="onSubmit">
  7. <CellGroup inset>
  8. <Field :required="true" v-model="formData.wechat" :rules="formRules.wechat" name="email" :label="$t('mine.profile.wechat')"
  9. :placeholder="$t('common.required')" />
  10. </CellGroup>
  11. </Form>
  12. <template #footer>
  13. <div class="g-form__footer inset">
  14. <Button round block type="danger" @click="formRef?.submit">{{ $t('operation.submit') }}</Button>
  15. </div>
  16. </template>
  17. </app-view>
  18. </template>
  19. <script lang="ts" setup>
  20. import { shallowRef, reactive } from 'vue'
  21. import { Form, Field, FormInstance, CellGroup, FieldRule, Button, showFailToast } from 'vant'
  22. import { updateUserInfoWechatAndEmail } from '@/services/api/user'
  23. import { useLoginStore, useUserStore } from '@/stores'
  24. import { useNavigation } from '@mobile/router/navigation'
  25. import { fullloading } from '@/utils/vant'
  26. import { decryptAES } from '@/services/websocket/package/crypto'
  27. // formRef
  28. const formRef = shallowRef<FormInstance>()
  29. // loginStore
  30. const loginStore = useLoginStore()
  31. // userStore
  32. const userStore = useUserStore()
  33. // router
  34. const { router } = useNavigation()
  35. const formData = reactive<Model.UserInfoWechatAndEmailReq>({
  36. userid: loginStore.userId, // 用户ID
  37. wechat: decryptAES(userStore.userInfo.wechat), // 微信
  38. })
  39. // 表单验证规则
  40. const formRules: { [key in keyof Model.UserInfoWechatAndEmailReq]?: FieldRule[] } = {
  41. wechat: [{
  42. message: '请输入微信号',
  43. validator: () => {
  44. return !!formData.wechat
  45. }
  46. }],
  47. }
  48. const onSubmit = () => {
  49. fullloading((hideLoading) => {
  50. updateUserInfoWechatAndEmail({
  51. data: formData
  52. }).then(() => {
  53. hideLoading()
  54. router.back()
  55. }).catch((err) => {
  56. showFailToast(err)
  57. })
  58. })
  59. }
  60. </script>