gaoshp
2024-01-05 b5db49ce1e4c678ce4a7120928811a9621128b8e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
<template>
    <div>
      <el-dialog  title="用户详情" :visible.sync="isShow" custom-class="custom-dialog" @close='cancelDialog()'>
        <div class="mdc-table">
           <div class="mdc-row ">
             <div class="mdc-col mdc-content-v-center mdc-col-30">用户名</div>
             <div class="mdc-col mdc-content-v-center mdc-col-20">{{user.user}}</div>
             <div class="mdc-col mdc-content-v-center mdc-col-15">密码</div>
             <div class="mdc-col">
               <div class="mdc-content-v-center" style="position: relative;height: 100%;" v-if="!isLargeAltering">
                 <span>*******</span>
                 <i class="el-icon-edit password-reset-btn" @click="showEditPw()"></i>
               </div>
               <el-form  v-else label-position="right" :model="pwObj"  :rules="myRules" size="small" ref="rpw">
                 <el-form-item  prop="newPw">
                   <el-input auto-complete="off" v-model="pwObj.newPw"><el-button slot="append" @click="resetPw()">重置</el-button></el-input>
                 </el-form-item>
               </el-form>
             </div>
             <el-dialog
               custom-class="custom-dialog"
               title="密码重置"
               :visible.sync="showEditPwDialog"
               append-to-body>
               <el-form label-position="right" :model="pwObj"  :rules="myRules" size="small" ref="rpw">
                 <el-form-item  prop="newPw">
                   <el-input auto-complete="off" v-model="pwObj.newPw"><el-button slot="append" @click="resetPw()">重置</el-button></el-input>
                 </el-form-item>
               </el-form>
             </el-dialog>
           </div>
          <div class="mdc-row">
            <div class="mdc-col mdc-content-v-center mdc-col-30">真实姓名</div>
            <div class="mdc-col mdc-content-v-center mdc-col-20">{{user.name}}</div>
            <div class="mdc-col mdc-content-v-center mdc-col-15">电话</div>
            <div class="mdc-col mdc-content-v-center">{{user.phone}}</div>
          </div>
          <div class="mdc-row">
            <div class="mdc-col mdc-content-v-center mdc-col-30">账户创建时间</div>
            <div class="mdc-col mdc-content-v-center">{{user.ctime}}</div>
          </div>
          <div class="mdc-row">
            <div class="mdc-col mdc-content-v-center mdc-col-30">最近登录时间</div>
            <div class="mdc-col mdc-content-v-center">{{user.ltime}}</div>
          </div>
        </div>
      </el-dialog>
    </div>
</template>
 
<script>
    import { resetPw } from '@/api/MdcApi'
    import { isValidPassword } from '@/utils/validate'
    export default {
      name: 'userDetailDialog',
      props: {
        isVisible: {
          type: Boolean,
          default: false
        },
        user: {
          type: Object,
          default: {}
        }
      },
      watch: {
        isVisible(val) {
          this.isShow = val
          if (!val) {
            this.$refs.rpw.resetFields()
          }
          this.isLargeAltering = false
        }
      },
      data() {
        // 密码自定义规则
        const rulesPass = (rule, value, callback) => {
          if (!isValidPassword(value)) {
            callback(new Error(`可用字母、数字,长度不低于6位`))
          } else if (value.length < 6) {
            callback(new Error(`密码不能低于6位`))
          } else {
            callback()
          }
        }
        return {
          isShow: this.isVisible,
          showEditPwDialog: false, // 密码重置弹框
          isLargeAltering: false,
          newPw: '', // 新密码
          isNewPwPosting: false, // 提交新密码
          pwObj: {
            newPw: ''
          },
          myRules: {
            newPw: [
              { required: true, message: '密码不能为空', trigger: ['blur', 'change'] },
              // 自定义规则
              { validator: rulesPass, trigger: ['blur', 'change'] }
            ]
          }
        }
      },
      methods: {
        /**
         * 取消/关闭对话框
         */
        cancelDialog() {
          this.$emit('submit', { action: 'cancel' })
        },
        showEditPw() {
          if (window.innerWidth > 720) {
            this.isLargeAltering = true
          } else {
            this.showEditPwDialog = true
          }
        },
        resetPw() {
          // todo 重置密码操作
          this.$refs.rpw.validate((valid) => {
            if (valid && !this.isNewPwPosting) {
              this.isNewPwPosting = true
              resetPw(this.user.user, this.pwObj.newPw).then(res => {
                // console.log(res)
                if (res.result === 'SUCCESS') {
                  this.$emit('submit', { action: 'confirm' })
                  this.showEditPwDialog = false
                  this.isNewPwPosting = false
                  this.isLargeAltering = false
                  this.$message({
                    message: '密码重置成功',
                    type: 'success'
                  })
                } else {
                  this.$message({
                    message: '密码重置失败,请重试',
                    type: 'error'
                  })
                }
              })
            } else {
              return false
            }
          })
        }
      }
    }
</script>
 
<style scoped>
  >>>.el-dialog__body{
    padding:20px 5px;
  }
  .mdc-table{}
  .mdc-row{
    display: flex;
    padding: 5px;
    width: 100%;
  }
  .mdc-row + .mdc-row {
    margin-top: -5px;
    padding-top: 0;
  }
  .mdc-col{
    flex: 1;
    display: block;
    padding: 5px;
    width: 100%;
    border: 1px solid #e5e5e5;
    box-sizing: border-box;
  }
  .mdc-content-v-center{
    display: flex;
    align-items: center;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .mdc-col-15 {
    flex: 0 0 15%;
    max-width: 15%; }
  .mdc-col-30 {
    flex: 0 0 30%;
    max-width: 30%; }
  .mdc-col-20 {
    flex: 0 0 20%;
    max-width: 20%; }
  .mdc-col + .mdc-col {
    border-left: none;
  }
  .mdc-row:nth-child(n) .mdc-col{
    border-top: none;
  }
  .mdc-row:first-child .mdc-col {
    border-top: 1px solid #e5e5e5;
  }
  .mdc-col:nth-child(2n+1){
    background-color: #e7f1fd;
  }
  .password-reset-btn{
    position: absolute;right:10px;color:#f56c6c;font-size: 18px;
  }
  .password-reset-btn:hover,.password-reset-btn:active{
     color:#67C23A;
  }
</style>