email.vue 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <template>
  2. <v-page>
  3. <v-header :title="`${user.email?$t('safe.a0'):$t('safe.a1')} ${$t('safe.a2')}`"></v-header>
  4. <main class="layout-main bg-panel-4 m-t-md">
  5. <view class="form-item border-b p-md" v-if="!user.email">
  6. <view class="label m-b-xs">{{$t('safe.a3')}}</view>
  7. <view class="input color-light">
  8. <v-input v-model="form.email" :placeholder="$t('safe.a4')"></v-input>
  9. </view>
  10. </view>
  11. <view class="form-item border-b p-md">
  12. <view class="label m-b-xs">{{$t('safe.a5')}}</view>
  13. <view class="input color-light">
  14. <v-input v-model="form.email_code" :placeholder="$t('safe.a6')">
  15. <template #right>
  16. <v-code url="/user/getCode" v-if="user.email" :data="{type:2}" />
  17. <v-code url="/user/sendBindEmailCode" v-else :data="{email:form.email}" />
  18. </template>
  19. </v-input>
  20. </view>
  21. </view>
  22. <view class="form-item border-b p-md" v-if="user.phone_status==1">
  23. <view class="label m-b-xs">SMS{{$t('safe.a7')}}</view>
  24. <view class="input color-light">
  25. <v-input v-model="form.sms_code" :placeholder="$t('safe.a6')">
  26. <template #right>
  27. <v-code url="/user/getCode" :data="{type:1}" />
  28. </template>
  29. </v-input>
  30. </view>
  31. </view>
  32. <view class="form-item border-b p-md" v-if="user.google_status==1">
  33. <view class="label m-b-xs">google{{$t('safe.a7')}}</view>
  34. <view class="input color-light">
  35. <v-input v-model="form.google_code" :placeholder="$t('safe.a6')"></v-input>
  36. </view>
  37. </view>
  38. </main>
  39. <view class="p-md bg-panel-4">
  40. <v-button block class="w-max" type="theme" ref="btn" @click="chnageEmail">{{user.email?$t('safe.a0'):$t('safe.a1')}}</v-button>
  41. </view>
  42. <van-toast id="van-toast" />
  43. </v-page>
  44. </template>
  45. <script>
  46. import Setting from "@/api/setting";
  47. import { mapState, mapActions } from "vuex";
  48. export default {
  49. data() {
  50. return {
  51. form: {
  52. email: "",
  53. email_code: "",
  54. sms_code: "",
  55. google_code: "",
  56. },
  57. };
  58. },
  59. computed: {
  60. ...mapState({
  61. user: "user",
  62. }),
  63. },
  64. methods: {
  65. ...mapActions({
  66. setUserInfo: "setUserInfo",
  67. }),
  68. chnageEmail() {
  69. let data = this.form;
  70. let changeEmail = this.user.email
  71. ? Setting.unbindEmail(data, { btn: this.$refs.btn })
  72. : Setting.bindEmail(data, { btn: this.$refs.btn });
  73. changeEmail
  74. .then(() => {
  75. this.$toast.success(this.user.email ? this.$t('safe.a8') : this.$t('safe.a9'));
  76. this.$back();
  77. this.setUserInfo();
  78. })
  79. .catch(() => {});
  80. },
  81. },
  82. };
  83. </script>
  84. <style lang="scss" scoped>
  85. </style>