UserInfoView.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <template>
  2. <!-- <el-popover
  3. ref="userInfoView"
  4. placement="right"
  5. trigger="click" style="padding:0px"> -->
  6. <div class="userInfoViewCom" style="width: 100%;">
  7. <div class="userImg" style="margin-left:43%">
  8. <div style="height:4.6vw;width:4.6vw;border-radius: 50%; border: 2px solid #00c1de;">
  9. <img :src="userInfo.imagePath" style="width: 100%;height: 100%;border-radius: 50%">
  10. </div>
  11. <el-upload
  12. class="upload-demo"
  13. ref="upload"
  14. :action="$dao.sysDao.uploadUserImg()"
  15. :http-request="httpRequest"
  16. :show-file-list="false"
  17. :with-credentials="true"
  18. :auto-upload="true">
  19. <el-button slot="trigger" size="small" type="primary">更换头像</el-button>
  20. </el-upload>
  21. <div class="userInfoTitle">
  22. <!-- <span style="color:#00c1de;font-size:16px">更换头像</span> -->
  23. <span style="color:#eeeeee">|</span>
  24. <i class="iconfont icon-bianji1" @click="editUserInfo"></i>
  25. </div>
  26. </div>
  27. <hr style="margin:20px -12px 10px -12px;border: solid 1px #eeeeee;">
  28. <div class="userInfoView">
  29. <el-form ref="userInfo" :model="userInfo" label-width="60px" size="mini" label-position="left">
  30. <i class="iconfont icon-dengluming"></i>
  31. <el-form-item label="登陆名">
  32. <el-input readonly v-model="userInfo.loginName"></el-input>
  33. </el-form-item>
  34. <i class="iconfont icon-xingming"></i>
  35. <el-form-item label="姓名">
  36. <el-input readonly v-model="userInfo.name"></el-input>
  37. </el-form-item>
  38. <i class="iconfont icon-youxiang"></i>
  39. <el-form-item label="邮箱">
  40. <el-input @blur="userInfo.email=userInfo.email.trim()" :class="{editUserInput: isUserInfoEdit === false}" :readonly="isUserInfoEdit"
  41. v-model="userInfo.email"></el-input>
  42. </el-form-item>
  43. <i class="iconfont icon-dianhua"></i>
  44. <el-form-item label="手机号">
  45. <el-input @blur="userInfo.phone=userInfo.phone.trim()" :class="{editUserInput: isUserInfoEdit === false}" :readonly="isUserInfoEdit"
  46. v-model="userInfo.phone"></el-input>
  47. </el-form-item>
  48. </el-form>
  49. </div>
  50. <div v-if="isUserInfoEdit===false">
  51. <hr style="margin: -10px -12px 0px -12px;border: solid 1px #eeeeee;">
  52. <div style="text-align:right;margin:10px 0px;">
  53. <el-button @click="cancelEditUserInfo" size="small">取消</el-button>
  54. <el-button @click="saveUserInfo" type="primary" size="small">保存</el-button>
  55. </div>
  56. </div>
  57. <hr style="margin: 0px -12px 20px -12px;border: solid 1px #eeeeee;">
  58. <!-- <i class="iconfont icon-tuichu"></i> -->
  59. <div @click="handleCommand('logDown')" class="iconfont icon-tuichu" style="display: inline;cursor:pointer;padding-left: 15px;">
  60. <span style="margin-left:10px">退出登录</span>
  61. </div>
  62. </div>
  63. <!-- </el-popover> -->
  64. </template>
  65. <script>
  66. import { mapGetters, mapActions } from "vuex";
  67. export default {
  68. name: "model",
  69. props: {
  70. handleCommand: Function
  71. },
  72. data() {
  73. return {
  74. isUserInfoEdit: true,
  75. userInfo: {
  76. loginName: "",
  77. name: "",
  78. email: "",
  79. phone: "",
  80. imagePath: ""
  81. }
  82. };
  83. },
  84. watch: {},
  85. computed: {
  86. ...mapGetters(["getUser"])
  87. },
  88. methods: {
  89. ...mapActions(["setUser"]),
  90. // 编辑
  91. editUserInfo() {
  92. this.isUserInfoEdit = false;
  93. },
  94. // 取消
  95. cancelEditUserInfo() {
  96. this.isUserInfoEdit = true;
  97. },
  98. // 保存
  99. async saveUserInfo() {
  100. let self = this;
  101. let { success } = await self.$dao.sysDao.userInfoEdit(this.userInfo);
  102. if (success) {
  103. self.$util.messageMethod("success", "保存用户信息成功!");
  104. let u = self.getUser;
  105. u.email = self.userInfo.email;
  106. u.phone = self.userInfo.phone;
  107. self.setUser(u);
  108. this.$nextTick(() => {
  109. self.isUserInfoEdit = true;
  110. });
  111. }
  112. },
  113. httpRequest(file) {
  114. let self = this;
  115. // var fileObj = document.getElementByIdx_x_x("file").files[0]
  116. var FileController = file.action;
  117. // FormData 对象
  118. var form = new FormData();
  119. // form.append("__sid", this.$dao.getCookie('session.id'))
  120. form.append("file", file.file);
  121. // XMLHttpRequest 对象
  122. var xhr = new XMLHttpRequest();
  123. xhr.open("post", FileController, true);
  124. xhr.setRequestHeader(this.$dao.getHeadName(), this.$dao.getHeadValue());
  125. xhr.send(form);
  126. xhr.onreadystatechange = function() {
  127. if (xhr.readyState === 4 && xhr.status === 200) {
  128. // console.log('5555555')
  129. self.uploadSuccess(xhr.responseText);
  130. }
  131. };
  132. },
  133. uploadSuccess(data) {
  134. data = JSON.parse(data);
  135. // data = data.parseJSON()
  136. this.userInfo.imagePath = data.imagePath;
  137. console.log(this.userInfo.imagePath);
  138. let u = this.getUser;
  139. u.imagePath = this.userInfo.imagePath;
  140. this.setUser(u);
  141. // this.$emit('click', {
  142. // img: this.userInfo.imagePath
  143. // })
  144. }
  145. },
  146. mounted() {
  147. this.userInfo.loginName = this.getUser.loginName;
  148. this.userInfo.name = this.getUser.name;
  149. this.userInfo.email = this.getUser.email;
  150. this.userInfo.phone = this.getUser.phone;
  151. this.userInfo.imagePath = this.getUser.imagePath;
  152. this.userInfo.id = this.getUser.id;
  153. }
  154. };
  155. </script>
  156. <!-- Add "scoped" attribute to limit CSS to this component only -->
  157. <style scoped>
  158. .userInfoTitle {
  159. /* margin-left: 43%; */
  160. margin-top: 10px;
  161. display: inline-block;
  162. }
  163. .userInfoTitle span {
  164. margin: 0px 30px;
  165. }
  166. .userInfoTitle i {
  167. font-size: 16px;
  168. color: #00c1de;
  169. cursor: pointer;
  170. }
  171. .userInfoView {
  172. padding: 0px 15px;
  173. }
  174. .userInfoView i {
  175. position: absolute;
  176. }
  177. .el-popover {
  178. padding: 0px;
  179. }
  180. </style>