change-username.vue 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <!-- 修改用户名 changeUsername -->
  2. <template>
  3. <view>
  4. <!-- 标题栏 -->
  5. <view class="head-box ss-m-b-60">
  6. <view class="head-title ss-m-b-20">修改用户名</view>
  7. <view class="head-subtitle">用户名仅限修改一次</view>
  8. </view>
  9. <!-- 表单项 -->
  10. <uni-forms
  11. ref="formRef"
  12. v-model="state.model"
  13. :rules="state.rules"
  14. validateTrigger="bind"
  15. labelWidth="140"
  16. labelAlign="center"
  17. >
  18. <uni-forms-item name="username" label="用户名">
  19. <uni-easyinput
  20. placeholder="请输入用户名"
  21. v-model="state.model.username"
  22. :inputBorder="false"
  23. ></uni-easyinput>
  24. </uni-forms-item>
  25. <view class="editPwd-btn-box ss-m-t-80">
  26. <button class="ss-reset-button save-btn ui-Shadow-Main" @tap="changeUsernameSubmit">
  27. 保存
  28. </button>
  29. </view>
  30. </uni-forms>
  31. </view>
  32. </template>
  33. <script setup>
  34. import { computed, watch, ref, reactive, unref } from 'vue';
  35. import sheep from '@/sheep';
  36. import { username } from '@/sheep/validate/form';
  37. import { showAuthModal, closeAuthModal } from '@/sheep/hooks/useModal';
  38. const formRef = ref(null);
  39. // 数据
  40. const state = reactive({
  41. model: {
  42. username: '',
  43. },
  44. rules: {
  45. username,
  46. },
  47. });
  48. // 7.修改用户名
  49. async function changeUsernameSubmit() {
  50. const validate = await unref(formRef)
  51. .validate()
  52. .catch((error) => {
  53. console.log('error: ', error);
  54. });
  55. if (!validate) return;
  56. sheep.$api.user.changeUsername(state.model).then((res) => {
  57. if (res.error === 0) {
  58. sheep.$store('user').getInfo();
  59. closeAuthModal();
  60. }
  61. });
  62. }
  63. </script>
  64. <style lang="scss" scoped>
  65. @import '../index.scss';
  66. </style>