switch.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <template>
  2. <view class="h-max d-flex flex-col">
  3. <view class="title p-md m-t-lg fn-center color-light">{{status?$t('safe.d7'):$t('safe.d8')}}{{name}}{{$t('safe.d9')}}</view>
  4. <view class="flex-fill">
  5. <view class="form-item border-b p-md" v-if="user.phone_status==1">
  6. <view class="label m-b-xs">{{$t('safe.c4')}}</view>
  7. <view class="input color-light">
  8. <v-input v-model="form.sms_code" :placeholder="$t('safe.a6')">
  9. <template #right>
  10. <v-code url="/user/getCode" :data="{type:1}" />
  11. </template>
  12. </v-input>
  13. </view>
  14. </view>
  15. <view class="form-item border-b p-md" v-if="user.email_status==1">
  16. <view class="label m-b-xs">{{$t('safe.a5')}}</view>
  17. <view class="input color-light">
  18. <v-input v-model="form.email_code" :placeholder="$t('safe.a6')">
  19. <template #right>
  20. <v-code url="/user/getCode" :data="{type:2}" />
  21. </template>
  22. </v-input>
  23. </view>
  24. </view>
  25. <view class="form-item border-b p-md" v-if="user.google_status==1">
  26. <view class="label m-b-xs">{{$t('safe.c5')}}</view>
  27. <view class="input color-light">
  28. <v-input v-model="form.google_code" :placeholder="$t('safe.a6')"></v-input>
  29. </view>
  30. </view>
  31. </view>
  32. <view class="p-md">
  33. <v-button class="w-max" block type="theme" @click="changeSwitch" ref="btn">{{status?$t('safe.d7'):$t('safe.d8')}}</v-button>
  34. </view>
  35. <van-toast id="van-toast" />
  36. </view>
  37. </template>
  38. <script>
  39. import { mapState, mapActions } from "vuex";
  40. import Setting from "@/api/setting";
  41. export default {
  42. props: ["type"],
  43. data() {
  44. return {
  45. form: {
  46. sms_code: "",
  47. email_code: "",
  48. google_code: "",
  49. type: "",
  50. },
  51. };
  52. },
  53. computed: {
  54. ...mapState({
  55. user: "user",
  56. }),
  57. name() {
  58. let name = "";
  59. switch (this.type) {
  60. case 1:
  61. name = this.$t('safe.e0');
  62. break;
  63. case 2:
  64. name = this.$t('safe.a2');
  65. break;
  66. case 3:
  67. name = "Google";
  68. break;
  69. }
  70. return name;
  71. },
  72. status() {
  73. let open = true;
  74. switch (this.type) {
  75. case 1:
  76. open = this.user.phone_status == 1;
  77. break;
  78. case 2:
  79. open = this.user.email_status == 1;
  80. break;
  81. case 3:
  82. open = this.user.google_status == 1;
  83. break;
  84. }
  85. return open;
  86. },
  87. },
  88. methods: {
  89. ...mapActions({
  90. setUserInfo: "setUserInfo",
  91. }),
  92. changeSwitch() {
  93. let data = this.form;
  94. data.type = this.type;
  95. let enable = Setting.enableSmsEmailGoogle(data, { btn: this.$refs.btn });
  96. if (this.status)
  97. enable = Setting.disableSmsEmailGoogle(data, { btn: this.$refs.btn });
  98. enable
  99. .then(() => {
  100. this.$emit("close");
  101. this.$toast(this.status ? this.$t('safe.e1') : this.$t('safe.e2'));
  102. this.setUserInfo();
  103. })
  104. .catch(() => {});
  105. },
  106. },
  107. mounted() {},
  108. };
  109. </script>