xiangpei
2024-06-04 c87c4fe5aa3987d61b10d57208232a94eec83d7c
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
<template>
  <div class="c">
    <div class="bg">
      <div class="main">
        <!-- <div class="main-title">
          <p>班级管理</p>
        </div> -->
        <div class="main-title">
          <p>个人基本信息</p>
          <div
            class="back"
            @click="goBack"
          ><svg
              t="1651823534392"
              class="icon"
              viewBox="0 0 1024 1024"
              version="1.1"
              content-inquire
              xmlns="http://www.w3.org/2000/svg"
              p-id="1892"
              width="20"
              height="20"
            >
              <path
                d="M896 544H250.4l242.4 242.4L448 832 173.6 557.6 128 512l45.6-45.6L448 192l45.6 45.6L250.4 480H896v64z"
                p-id="1893"
                fill="#515151"
              ></path>
            </svg></div>
        </div>
        <div class="main-1">
          <el-row>
            <el-form
              ref="form"
              label-width="80px"
              v-loading="loading"
            >
              <el-form-item
                label="头像:"
                style="margin-bottom:0"
              >
                <el-upload
                  class="
                  avatar-uploader"
                  action="https://jsonplaceholder.typicode.com/posts/"
                  :show-file-list="false"
                  :on-success="handleAvatarSuccess"
                  :before-upload="beforeAvatarUpload"
                >
                  <img
                    v-if="state.avatar"
                    :src="state.avatar"
                    class="avatar"
                  >
                  <i
                    v-else
                    class="el-icon-plus avatar-uploader-icon"
                  ></i>
                </el-upload>
              </el-form-item>
              <el-col :span="12">
 
                <el-form-item label="用户名:">
                  <el-input
                    class="input-style"
                    v-model="state.username"
                    :readonly='true'
                  ></el-input>
                </el-form-item>
                <el-form-item label="年龄">
                  <el-input
                    class="input-style"
                    v-model.number="state.age"
                  ></el-input>
                </el-form-item>
                <el-form-item label="部门">
                  <el-input
                    class="input-style"
                    v-model="state.deptId"
                  ></el-input>
                </el-form-item>
                <el-form-item
                  label="性别"
                  prop="resource"
                >
                  <el-radio-group v-model="state.sex">
                    <el-radio label="1">男</el-radio>
                    <el-radio label="2">女</el-radio>
                  </el-radio-group>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="电话号码:">
                  <el-input
                    class="input-style"
                    v-model="state.phone"
                  ></el-input>
                </el-form-item>
                <el-form-item label="兴趣爱好:">
                  <el-input class="input-style"></el-input>
                </el-form-item>
                <el-form-item label="个人简介:">
                  <el-input
                    class="input-style"
                    type="textarea"
                    :rows="4"
                    placeholder="请输入内容"
                    v-model="state.description"
                  >
                  </el-input>
                </el-form-item>
              </el-col>
              <el-col :span="24">
                <el-form-item size="large">
                  <el-button
                    style="margin-left: 360px;"
                    type="primary"
                    @click="onSubmit"
                  >保存修改</el-button>
                </el-form-item>
              </el-col>
            </el-form>
          </el-row>
 
        </div>
      </div>
 
    </div>
  </div>
</template>
 
<script>
import { mapGetters } from "vuex";
export default {
  data() {
    return {
      // 修改的数据
      state: {},
      loading: false,
    };
  },
  methods: {
    // 返回上一个页面
    goBack() {
      this.$router.back();
    },
 
    // 头像修改
    handleAvatarSuccess(res, file) {
      this.state.avatar = URL.createObjectURL(file.raw);
    },
    beforeAvatarUpload(file) {
      const isJPG = file.type;
      const isLt2M = file.size / 1024 / 1024 < 2;
 
      //   if (!isJPG) {
      //     this.$message.error("上传头像图片只能是 JPG 格式!");
      //   }
      if (!isLt2M) {
        this.$message.error("上传头像图片大小不能超过 2MB!");
      }
      return isJPG && isLt2M;
    },
 
    // 修改提交
    // async onSubmit() {
    //   this.loading = true;
    //   // 提交
    //   let data = await putObj(this.state);
    //   if (data.status === 200) {
    //     this.$message({
    //       message: "修改成功",
    //       type: "success",
    //     });
    //   } else {
    //     this.$message({
    //       message: "修改失败",
    //       type: "error",
    //     });
    //   }
    //   this.loading = false;
    // },
 
    // 赋默认值
    getState() {
      this.state = {
        ...this.userInfo,
        // 设置头像
        avatar: this.state.avatar
          ? this.state.avatar
          : require("../../assets/img/avatarIcon.png"),
      };
    },
  },
  computed: {
    ...mapGetters({
      userInfo: "userInfo",
    }),
  },
  mounted() {
    this.getState();
  },
};
</script>
 
<style scoped lang="scss">
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}
.avatar {
  width: 80px;
  height: 80px;
  display: block;
  border-radius: 50%;
}
 
.flex {
  display: flex;
}
.mian-1-top {
  margin: 10px 0;
  align-items: center;
  & input {
    height: 30px;
    width: 200px;
    margin-right: 20px;
  }
}
.main {
  &-title {
    border-left: 5px solid rgb(16, 71, 247);
    padding-left: 10px;
    margin: 30px 0;
    & p {
      font-weight: 700;
    }
  }
  &-1 {
    width: 1227px;
    // height: 784px;
    background: white;
    box-shadow: 1px 1px 1px 1px rgba(0, 0, 0, 0.1);
    border-radius: 10px;
    padding: 60px 100px 0 100px;
  }
  &-btn {
    padding-bottom: 10px;
    border-bottom: 3px solid rgb(16, 71, 247);
  }
}
.deepBlue {
  background: rgb(16, 71, 247);
  color: white;
  border: none;
  &:hover {
    background-color: rgb(45, 92, 248);
  }
}
.input-style {
  max-width: 220px;
}
.el-form-item {
  margin-bottom: 30px !important;
}
</style>