set_nickname.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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(
  48. res => {
  49. if (res.data.code == 200) {
  50. uni.showToast({
  51. title: '修改成功!',
  52. icon: 'success',
  53. duration: 2000,
  54. success() {
  55. setTimeout(()=>{
  56. var _student = uni.getStorageSync('userInfo');
  57. _student.userName = that.nickname;
  58. uni.setStorageSync('userInfo', _student);
  59. var name = 'userInfo';
  60. var value = _student;
  61. that.$store.commit('$uStore', {
  62. name,
  63. value
  64. });
  65. uni.navigateBack()
  66. },2000)
  67. }
  68. })
  69. }
  70. })
  71. .catch(res => {
  72. if(res.errmsg){
  73. uni.showToast({
  74. title: res.errmsg,
  75. icon: 'none',
  76. duration: 2000
  77. })
  78. }
  79. else{
  80. uni.showToast({
  81. title: "系统异常,请联系管理员",
  82. icon: 'none',
  83. duration: 2000
  84. })
  85. }
  86. });
  87. } else if (res.cancel) {
  88. // console.log('用户点击取消');
  89. }
  90. },
  91. })
  92. },
  93. }
  94. }
  95. </script>
  96. <style>
  97. .container {
  98. padding: 10px 0px;
  99. background-color: #F5F6FA;
  100. }
  101. .explain {
  102. margin-left: 16px;
  103. font-size: 16px;
  104. color: #6D6D72;
  105. margin-top: 20px;
  106. }
  107. .editText {
  108. width: 100%;
  109. height: 50px;
  110. background-color: #FFFFFF;
  111. line-height: 50px;
  112. padding-left: 20px;
  113. margin-top: 10px;
  114. padding-top: 12px;
  115. }
  116. .texts {
  117. line-height: 50px;
  118. color: #C6C6C8;
  119. font-size: 16px;
  120. /* placeholder-style="font-size:18px" */
  121. }
  122. .btn {
  123. width: 100%;
  124. height: 50px;
  125. background-color: #FFFFFF;
  126. text-align: center;
  127. color: #22C572;
  128. font-size: 20px;
  129. margin-top: 16px;
  130. border-radius: 20px;
  131. line-height: 50px;
  132. font-weight: 500;
  133. }
  134. </style>