set_nickname.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <template>
  2. <view class="container">
  3. <view class="explain">
  4. 昵称长度限制在2-24个字符内
  5. </view>
  6. <view class="editText">
  7. <input placeholder="请输入昵称" name="input" v-model="nickname" class="texts"></input>
  8. </view>
  9. <view class="btn" @click="commit">
  10. 保存
  11. </view>
  12. </view>
  13. </template>
  14. <script>
  15. import {
  16. mapState
  17. } from 'vuex';
  18. export default {
  19. data() {
  20. return {
  21. nickname: "",
  22. deptListurl: {},
  23. }
  24. },
  25. computed: {
  26. ...mapState(['hasLogin', 'userInfo'])
  27. },
  28. methods: {
  29. commit() {
  30. if (this.nickname == null || this.nickname == "") {
  31. this.$api.msg('请输入昵称!')
  32. return
  33. }
  34. if (this.nickname.length < 2 || this.nickname.length > 24) {
  35. this.$api.msg('请正确输入昵称!')
  36. return
  37. }
  38. var that = this
  39. uni.showModal({
  40. content: "您确定要更改昵称?",
  41. showCancel: true,
  42. confirmText: '确定',
  43. success: function(res) {
  44. if (res.confirm) {
  45. that.deptListurl.userName = that.nickname
  46. that.deptListurl.id = that.userInfo.id
  47. that.$api.doRequest('post', '/commonUser/editUserInfo', that.deptListurl).then(res => {
  48. if (res.data.code == 200) {
  49. // this.$api.msg('修改成功!')
  50. var _student = uni.getStorageSync('userInfo');
  51. _student.userName = that.nickname;
  52. uni.setStorageSync('userInfo', _student);
  53. uni.navigateBack()
  54. }
  55. })
  56. .catch(res => {
  57. uni.showToast({
  58. title: res.errmsg,
  59. icon: 'none',
  60. duration: 2000
  61. })
  62. });
  63. } else if (res.cancel) {
  64. // console.log('用户点击取消');
  65. }
  66. },
  67. })
  68. },
  69. }
  70. }
  71. </script>
  72. <style>
  73. .container {
  74. padding: 10px 0px;
  75. background-color: #F5F6FA;
  76. }
  77. .explain {
  78. margin-left: 16px;
  79. font-size: 16px;
  80. color: #6D6D72;
  81. margin-top: 20px;
  82. }
  83. .editText {
  84. width: 100%;
  85. height: 50px;
  86. background-color: #FFFFFF;
  87. line-height: 50px;
  88. padding-left: 20px;
  89. margin-top: 10px;
  90. padding-top: 12px;
  91. }
  92. .texts {
  93. line-height: 50px;
  94. color: #C6C6C8;
  95. font-size: 16px;
  96. /* placeholder-style="font-size:18px" */
  97. }
  98. .btn {
  99. width: 100%;
  100. height: 50px;
  101. background-color: #FFFFFF;
  102. text-align: center;
  103. color: #22C572;
  104. font-size: 20px;
  105. margin-top: 16px;
  106. border-radius: 20px;
  107. line-height: 50px;
  108. font-weight: 500;
  109. }
  110. </style>