Index.vue 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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, i18n } from '@/stores'
  24. import { useNavigation } from '@mobile/router/navigation'
  25. import { fullloading } from '@/utils/vant'
  26. import { decryptAES } from '@/services/websocket/package/crypto'
  27. const { global: { t } } = i18n
  28. // formRef
  29. const formRef = shallowRef<FormInstance>()
  30. // loginStore
  31. const loginStore = useLoginStore()
  32. // userStore
  33. const userStore = useUserStore()
  34. // router
  35. const { router } = useNavigation()
  36. const formData = reactive<Model.UserInfoWechatAndEmailReq>({
  37. userid: loginStore.userId, // 用户ID
  38. wechat: decryptAES(userStore.userInfo.wechat), // 微信
  39. })
  40. // 表单验证规则
  41. const formRules: { [key: string]: FieldRule[] } = {
  42. wechat: [{
  43. message: t('mine.profile.tips1'),
  44. validator: () => {
  45. return !!formData.wechat
  46. }
  47. }],
  48. }
  49. const onSubmit = () => {
  50. fullloading((hideLoading) => {
  51. updateUserInfoWechatAndEmail({
  52. data: formData
  53. }).then(() => {
  54. hideLoading()
  55. router.back()
  56. }).catch((err) => {
  57. showFailToast(err)
  58. })
  59. })
  60. }
  61. </script>