set_nickname.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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 = wx.getStorageSync('userInfo');
  51. _student.userName = that.nickname;
  52. wx.setStorageSync('userInfo', _student);
  53. uni.navigateTo({
  54. url: `/pages/user/setUp`
  55. })
  56. }
  57. })
  58. .catch(res => {
  59. uni.showToast({
  60. title: res.errmsg,
  61. icon: 'none',
  62. duration: 2000
  63. })
  64. });
  65. } else if (res.cancel) {
  66. // console.log('用户点击取消');
  67. }
  68. },
  69. })
  70. },
  71. }
  72. }
  73. </script>
  74. <style>
  75. .container {
  76. padding: 10px 0px;
  77. background-color: #F5F6FA;
  78. }
  79. .explain {
  80. margin-left: 16px;
  81. font-size: 16px;
  82. color: #6D6D72;
  83. margin-top: 20px;
  84. }
  85. .editText {
  86. width: 100%;
  87. height: 50px;
  88. background-color: #FFFFFF;
  89. line-height: 50px;
  90. padding-left: 20px;
  91. margin-top: 10px;
  92. padding-top: 12px;
  93. }
  94. .texts {
  95. line-height: 50px;
  96. color: #C6C6C8;
  97. font-size: 16px;
  98. /* placeholder-style="font-size:18px" */
  99. }
  100. .btn {
  101. width: 100%;
  102. height: 50px;
  103. background-color: #FFFFFF;
  104. text-align: center;
  105. color: #22C572;
  106. font-size: 20px;
  107. margin-top: 16px;
  108. border-radius: 20px;
  109. line-height: 50px;
  110. font-weight: 500;
  111. }
  112. </style>