index.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <template>
  2. <div>
  3. <Card :bordered="false" dis-hover class="ivu-mt">
  4. <Form ref="formValidate" :model="formValidate" :rules="ruleValidate" :label-width="160" label-position="right">
  5. <FormItem label="头像">
  6. <div class="avatar" @click="avatarMoadl = true">
  7. <img v-if="formValidate.head_pic" :src="formValidate.head_pic" alt="" />
  8. <img v-else src="../../../assets/images/f.png" alt="" />
  9. </div>
  10. </FormItem>
  11. <FormItem label="账号" prop="">
  12. <Input type="text" v-model="account" :disabled="true" class="input"></Input>
  13. </FormItem>
  14. <FormItem label="姓名" prop="real_name">
  15. <Input type="text" v-model="formValidate.real_name" class="input"></Input>
  16. </FormItem>
  17. <FormItem label="原始密码" prop="pwd">
  18. <Input type="password" v-model="formValidate.pwd" class="input"></Input>
  19. </FormItem>
  20. <FormItem label="新密码" prop="new_pwd">
  21. <Input type="password" v-model="formValidate.new_pwd" class="input"></Input>
  22. </FormItem>
  23. <FormItem label="确认新密码" prop="conf_pwd">
  24. <Input type="password" v-model="formValidate.conf_pwd" class="input"></Input>
  25. </FormItem>
  26. <FormItem>
  27. <Button type="primary" @click="handleSubmit('formValidate')">提交</Button>
  28. </FormItem>
  29. </Form>
  30. </Card>
  31. <Modal v-model="avatarMoadl" title="头像上传" width="700">
  32. <CropperImg v-if="avatarMoadl" @uploadImgSuccess="uploadImgSuccess"></CropperImg>
  33. </Modal>
  34. </div>
  35. </template>
  36. <script>
  37. import { updtaeAdmin } from '@/api/user';
  38. import { mapState } from 'vuex';
  39. import CropperImg from '@/components/cropperImg';
  40. export default {
  41. name: 'setting_user',
  42. components: { CropperImg },
  43. computed: {
  44. ...mapState('media', ['isMobile']),
  45. ...mapState('userLevel', ['categoryId']),
  46. labelWidth() {
  47. return this.isMobile ? undefined : 75;
  48. },
  49. labelPosition() {
  50. return this.isMobile ? 'top' : 'left';
  51. },
  52. },
  53. data() {
  54. return {
  55. account: '',
  56. avatarMoadl: false,
  57. formValidate: {
  58. avatar: '',
  59. real_name: '',
  60. pwd: '',
  61. new_pwd: '',
  62. conf_pwd: '',
  63. },
  64. ruleValidate: {
  65. real_name: [{ required: true, message: '您的姓名不能为空', trigger: 'blur' }],
  66. pwd: [{ required: true, message: '请输入您的原始密码', trigger: 'blur' }],
  67. new_pwd: [{ required: true, message: '请输入您的新密码', trigger: 'blur' }],
  68. conf_pwd: [{ required: true, message: '请确认您的新密码', trigger: 'blur' }],
  69. },
  70. };
  71. },
  72. mounted() {
  73. this.account = this.$store.state.userInfo.userInfo.account;
  74. this.formValidate.head_pic = this.$store.state.userInfo.userInfo.head_pic;
  75. this.formValidate.real_name = this.$store.state.userInfo.userInfo.real_name;
  76. },
  77. methods: {
  78. uploadImgSuccess(data) {
  79. this.avatarMoadl = false;
  80. this.formValidate.head_pic = data.src;
  81. },
  82. handleSubmit(name) {
  83. this.$refs[name].validate((valid) => {
  84. if (valid) {
  85. updtaeAdmin(this.formValidate)
  86. .then((res) => {
  87. this.$store.commit('userInfo/userRealName', this.formValidate.real_name);
  88. this.$store.commit('userInfo/userRealHeadPic', this.formValidate.head_pic);
  89. this.$Message.success(res.msg);
  90. })
  91. .catch((res) => {
  92. this.$Message.error(res.msg);
  93. });
  94. } else {
  95. if (this.formValidate.new_pwd !== this.formValidate.conf_pwd) {
  96. this.$Message.error('您输入的新密码与旧密码不一致');
  97. }
  98. }
  99. });
  100. },
  101. },
  102. };
  103. </script>
  104. <style lang="scss" scoped>
  105. .input {
  106. width: 400px;
  107. }
  108. .avatar {
  109. width: 80px;
  110. height: 80px;
  111. img {
  112. width: 100%;
  113. height: 100%;
  114. border-radius: 50%;
  115. border: 1px solid #f2f2f2;
  116. }
  117. }
  118. </style>