血透系统PC前端

modify_user_info_dialog.vue 9.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. <template>
  2. <div>
  3. <el-dialog title="修改个人信息" modal-append-to-body="false" append-to-body="true" width="50%" :visible.sync="visible" :before-close="_close">
  4. <el-form ref="form" :model="form" :rules="rules" label-width="80px"
  5. v-loading="uploading">
  6. <el-form-item label="账号:">
  7. <span>{{ this.$store.getters.xt_user.user.mobile }}</span>
  8. </el-form-item>
  9. <el-form-item label="姓名:" prop="user_name">
  10. <el-input v-model="form.user_name" style="width: 300px;"></el-input>
  11. </el-form-item>
  12. <el-form-item label="头像:">
  13. <el-upload
  14. style="width:100%;"
  15. :data="qn_upload_data"
  16. :multiple="false"
  17. action="https://upload.qiniup.com"
  18. :show-file-list="false"
  19. :on-error="handleAvatarError"
  20. :on-success="handleAvatarSuccess"
  21. :before-upload="beforeAvatarUpload"
  22. list-type="picture-card">
  23. <!-- <img :src="avatar" style="width: 100px; height: 100px;" />
  24. <span style="display: block; font-size: 11px; color: gray">108*108像素,仅支持JPG/PNG/JPEG, 大小在300K以内</span> -->
  25. <img v-if="form.avatar" :src="form.avatar" class="avatar">
  26. <i v-else class="el-icon-plus"></i>
  27. </el-upload>
  28. <span style="display: block; font-size: 11px; color: gray">仅支持JPG/PNG/JPEG, 大小在300K以内</span>
  29. </el-form-item>
  30. </el-form>
  31. <div slot="footer" class="dialog-footer">
  32. <el-button type="primary" @click="submitAction">保存</el-button>
  33. <el-button type="primary" @click="modifyPwdAction">修改密码</el-button>
  34. </div>
  35. </el-dialog>
  36. <el-dialog title="修改密码" modal-append-to-body="false" append-to-body="true" :visible.sync="pwd_dialog_visible">
  37. <el-form ref="pwd_form" :model="pwd_form" label-width="80px">
  38. <el-form-item label="账号:">
  39. <span>{{ this.$store.getters.xt_user.user.mobile }}</span>
  40. </el-form-item>
  41. <el-form-item label="新密码:" prop="new_password">
  42. <el-input v-model="pwd_form.new_password" style="width: 260px;"></el-input>
  43. </el-form-item>
  44. <el-form-item label="验证码:" prop="code">
  45. <el-input v-model="pwd_form.code" style="width: 135px;"></el-input>
  46. <el-button :type="count_downing ? 'info' : 'primary'" :disabled="count_downing" @click="getCodeAction" style="width: 122px; padding-left: 5px; padding-right: 5px;">{{ code_btn_title }}</el-button>
  47. </el-form-item>
  48. </el-form>
  49. <div slot="footer" class="dialog-footer">
  50. <el-button :loading="modify_pwd_loading" type="primary" @click="submitModifyPwdAction">保存</el-button>
  51. </div>
  52. </el-dialog>
  53. </div>
  54. </template>
  55. <script>
  56. import { getToken } from "@/api/qiniu";
  57. import { getFileExtension } from "@/utils/tools";
  58. import { modifyAdminInfo, getModifyPwdCode, modifyPassword } from "@/api/login/login"
  59. import { hex_md5 } from "@/utils/md5"
  60. export default {
  61. name: "ModifyUserInfoDialog",
  62. data() {
  63. return {
  64. visible: false,
  65. pwd_dialog_visible: false,
  66. form: {
  67. user_name: this.$store.getters.xt_user.user.user_name,
  68. avatar: this.$store.getters.xt_user.user.avatar,
  69. },
  70. qn_upload_data: {
  71. token: "",
  72. key: "",
  73. },
  74. qiniuDomain: "https://images.shengws.com/",
  75. uploading: false,
  76. rules: {
  77. user_name: [
  78. { required: true, message: "请填写姓名", trigger: "blur" }
  79. ]
  80. },
  81. pwd_form: {
  82. new_password: "",
  83. code: "",
  84. },
  85. count_downing: false,
  86. count_down: 0,
  87. modify_pwd_loading: false,
  88. }
  89. },
  90. computed: {
  91. avatar: function() {
  92. return this.form.avatar.length == 0 ? "/src/assets/home/user.png" : this.form.avatar
  93. },
  94. code_btn_title: function() {
  95. if (this.count_down == 0) {
  96. return "获取验证码"
  97. } else {
  98. return this.count_down + "秒后重新获取"
  99. }
  100. }
  101. },
  102. methods: {
  103. _close: function(done) {
  104. this.clear()
  105. done()
  106. },
  107. clear: function() {
  108. this.form.user_name = this.$store.getters.xt_user.user.user_name
  109. this.form.avatar = this.$store.getters.xt_user.user.avatar
  110. },
  111. show() {
  112. this.clear()
  113. this.visible = true
  114. },
  115. hide() {
  116. this.clear()
  117. this.visible = false
  118. },
  119. submitAction() {
  120. this.$refs.form.validate(valid => {
  121. if (valid) {
  122. this.uploading = true
  123. var params = {
  124. name: this.form.user_name,
  125. avatar: this.form.avatar,
  126. }
  127. modifyAdminInfo(params).then(rs => {
  128. this.uploading = false
  129. var resp = rs.data
  130. if (resp.state === 1) {
  131. this.$store.dispatch("ModifyAdminUserInfo", { user_name: this.form.user_name, avatar: this.form.avatar })
  132. this.hide()
  133. } else {
  134. this.$message.error(resp.msg)
  135. }
  136. })
  137. } else {
  138. return false
  139. }
  140. })
  141. },
  142. handleAvatarError(err, file, fileList) {
  143. this.$message.error(err);
  144. this.uploading = false
  145. return false;
  146. },
  147. handleAvatarSuccess(res, file) {
  148. this.form.avatar = this.qiniuDomain + res.url;
  149. this.uploading = false
  150. },
  151. beforeAvatarUpload(file) {
  152. var fileType = file.type
  153. const isJPG = fileType.indexOf("image") > -1
  154. const isLt300K = file.size < 300 * 1024
  155. if (!isJPG) {
  156. this.$message.error("只能上传图片")
  157. return false
  158. }
  159. if (!isLt300K) {
  160. this.$message.error("上传头像图片大小不能超过 300KB!")
  161. return false
  162. }
  163. var date = new Date()
  164. var ext = getFileExtension(file.name)
  165. var key = date.getFullYear() + "/" + (date.getMonth() + 1) + "/" + date.getDate() + "/" + "admin_avatar_" + file.uid + "." + ext
  166. this.uploading = true
  167. return new Promise((resolve, reject) => {
  168. getToken().then(response => {
  169. const token = response.data.data.uptoken
  170. this.qn_upload_data.token = token
  171. this.qn_upload_data.key = key
  172. resolve(true)
  173. })
  174. })
  175. },
  176. modifyPwdAction: function() {
  177. this.pwd_dialog_visible = true
  178. },
  179. getCodeAction: function() {
  180. this.count_downing = true
  181. this.count_down = 11
  182. this.countDown()
  183. getModifyPwdCode()
  184. },
  185. countDown: function() {
  186. this.count_down = this.count_down - 1
  187. if (this.count_down == 0) {
  188. this.count_downing = false
  189. return
  190. }
  191. var t = this
  192. setTimeout(() => {
  193. this.countDown()
  194. }, 1000);
  195. },
  196. submitModifyPwdAction: function() {
  197. if (this.pwd_form.new_password.length == 0) {
  198. this.$message.error("未填写新密码")
  199. return
  200. }
  201. if (this.pwd_form.code.length == 0) {
  202. this.$message.error("未填写验证码")
  203. return
  204. }
  205. this.modify_pwd_loading = true
  206. modifyPassword(hex_md5(this.pwd_form.new_password), this.pwd_form.code).then(rs => {
  207. this.modify_pwd_loading = false
  208. var resp = rs.data
  209. if (resp.state == 1) {
  210. this.$message.success(resp.data.msg)
  211. } else {
  212. this.$message.error(resp.msg)
  213. }
  214. })
  215. }
  216. }
  217. }
  218. </script>
  219. <style scoped>
  220. .avatar-uploader .el-upload {
  221. border: 1px dashed #d9d9d9;
  222. border-radius: 6px;
  223. cursor: pointer;
  224. position: relative;
  225. overflow: hidden;
  226. }
  227. .avatar-uploader .el-upload:hover {
  228. border-color: #409EFF;
  229. }
  230. .avatar-uploader-icon {
  231. font-size: 28px;
  232. color: #8c939d;
  233. width: 148px;
  234. height: 148px;
  235. line-height: 148px;
  236. text-align: center;
  237. }
  238. .avatar {
  239. width: 146px;
  240. height: 146px;
  241. display: block;
  242. }
  243. </style>