MrShi
2024-02-22 8d7bb4ac830444afde480a588e99952105ea8ede
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
<template>
  <!-- 新建/修改 -->
  <GlobalWindow
    :title="title"
    :visible.sync="visible"
    :confirm-working="isWorking"
    @confirm="confirm"
  >
    <el-form :model="form" ref="form" :rules="rules">
      <el-form-item label="账号" prop="username" required>
        <el-input v-model="form.username" placeholder="请输入" v-trim maxlength="50"/>
      </el-form-item>
      <el-form-item label="名称" prop="realname" required>
        <el-input v-model="form.realname" placeholder="请输入" v-trim maxlength="50"/>
      </el-form-item>
      <el-form-item label="联系方式" prop="mobile">
        <el-input v-model="form.mobile" placeholder="请输入" v-trim maxlength="11"/>
      </el-form-item>
      <el-form-item label="验证码" prop="captcha">
        <div style="width: 100%; display: flex; align-items: center;">
          <el-input v-model="form.captcha" maxlength="11" type="number" style="flex: 1;" placeholder="请输入" v-trim/>
          <el-button type="primary" style="flex-shrink: 0; margin-left: 15px;" @click="send" v-if="num === 0">发送验证码</el-button>
          <el-button type="primary" style="flex-shrink: 0; margin-left: 15px;" v-else>{{num}}s</el-button>
        </div>
      </el-form-item>
      <el-form-item label="抄送文件邮箱" prop="email">
        <el-input v-model="form.email" placeholder="请输入" v-trim />
      </el-form-item>
    </el-form>
  </GlobalWindow>
</template>
 
<script>
import BaseOpera from '@/components/base/BaseOpera'
import GlobalWindow from '@/components/common/GlobalWindow'
import DepartmentSelect from '@/components/common/DepartmentSelect'
import PositionSelect from '@/components/common/PositionSelect'
import { checkMobile, checkEmail } from '@/utils/form'
import { sendSms } from '@/api/business/smsEmail'
 
export default {
  name: 'OperaUserWindow',
  extends: BaseOpera,
  components: { PositionSelect, DepartmentSelect, GlobalWindow },
  data () {
    return {
      // 表单数据
      form: {
        id: null,
        username: '', // 用户名
        realname: '', // 姓名
        mobile: '', // 手机号码
        email: '',
        captcha: ''
      },
      num: 0,
      timer: null,
      // 验证规则
      rules: {
        username: [
          { required: true, message: '请输入用户名' }
        ],
        realname: [
          { required: true, message: '请输入姓名' }
        ],
        mobile: [
          { required: true, validator: checkMobile }
        ],
        email: [
          { required: true, message: '请输入邮箱' }
        ]
      }
    }
  },
  methods: {
    send() {
      if (!this.form.mobile) {
        this.$message.warning('请输入手机号')
        return
      }
      sendSms({ phone: this.form.mobile })
        .then(res => {
          this.num = 60
          this.setTime()
        })
    },
    setTime() {
      this.timer = setInterval(() => {
        this.num -= 1
        if (this.num === 0) {
          clearInterval(this.timer)
          this.num = 0
        }
      }, 1000)
    },
    /**
     * @title 窗口标题
     * @target 编辑的用户对象
     */
    open (title, target) {
      this.title = title
      this.visible = true
      clearInterval(this.timer)
      this.num = 0
      // 新建
      if (target == null) {
        this.$nextTick(() => {
          this.$refs.form.resetFields()
          this.form.id = null
          this.form.departmentId = null
          this.form.positionIds = []
        })
        return
      }
      // 编辑
      this.$nextTick(() => {
        for (const key in this.form) {
          this.form[key] = target[key]
        }
        this.form.departmentId = target.department == null ? null : target.department.id
        this.form.positionIds = target.positions == null ? [] : target.positions.map(p => p.id)
      })
    }
  },
  created () {
    this.config({
      api: '/system/user'
    })
  }
}
</script>
 
<style lang="scss" scoped>
.global-window {
  /deep/ .el-date-editor {
    width: 100%;
  }
  // 表单头像处理
  /deep/ .form-item-avatar {
    .el-radio.is-bordered {
      height: auto;
      padding: 6px;
      margin: 0 10px 0 0;
      .el-radio__input {
        display: none;
      }
      .el-radio__label {
        padding: 0;
        width: 48px;
        display: block;
        img {
          width: 100%;
        }
      }
    }
  }
}
</style>