lyn7568 2 anos atrás
pai
commit
563460afc6

+ 19 - 13
src/router/index.js

@ -60,7 +60,7 @@ export const constantRoutes = [
60 60
    component: Layout,
61 61
    redirect: '/example/table',
62 62
    name: 'Example',
63
    meta: { title: 'Example', icon: 'el-icon-s-help' },
63
    meta: { title: '系统管理', icon: 'el-icon-s-help' },
64 64
    children: [
65 65
      {
66 66
        path: 'table',
@ -73,6 +73,12 @@ export const constantRoutes = [
73 73
        name: 'Tree',
74 74
        component: () => import('@/views/tree/index'),
75 75
        meta: { title: 'Tree', icon: 'tree' }
76
      },
77
      {
78
        path: 'user',
79
        name: 'User',
80
        component: () => import('@/views/user/index'),
81
        meta: { title: '用户管理', icon: 'form' }
76 82
      }
77 83
    ]
78 84
  },
@ -89,18 +95,18 @@ export const constantRoutes = [
89 95
      }
90 96
    ]
91 97
  },
92
  {
93
    path: '/user',
94
    component: Layout,
95
    children: [
96
      {
97
        path: 'user',
98
        name: 'User',
99
        component: () => import('@/views/user/user.vue'),
100
        meta: { title: 'User', icon: 'form' }
101
      }
102
    ]
103
  },
98
  // {
99
  //   path: '/user',
100
  //   component: Layout,
101
  //   children: [
102
  //     {
103
  //       path: 'user',
104
  //       name: 'User',
105
  //       component: () => import('@/views/user/index'),
106
  //       meta: { title: '用户管理', icon: 'form' }
107
  //     }
108
  //   ]
109
  // },
104 110
105 111
  {
106 112
    path: '/nested',

+ 31 - 0
src/utils/validate.js

@ -18,3 +18,34 @@ export function validUsername(str) {
18 18
  const valid_map = ['admin', 'editor']
19 19
  return valid_map.indexOf(str.trim()) >= 0
20 20
}
21
/**
22
 * 邮箱
23
 * @param {*} s
24
 */
25
 export function isEmail (s) {
26
  return /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((.[a-zA-Z0-9_-]{2,3}){1,2})$/.test(s)
27
}
28
29
/**
30
 * 手机号码
31
 * @param {*} s
32
 */
33
 export function isMobile (s) {
34
  return /^1[0-9]{10}$/.test(s)
35
}
36
37
/**
38
 * 电话号码
39
 * @param {*} s
40
 */
41
export function isPhone (s) {
42
  return /^([0-9]{3,4}-)?[0-9]{7,8}$/.test(s)
43
}
44
45
/**
46
 * URL地址
47
 * @param {*} s
48
 */
49
export function isURL (s) {
50
  return /^http[s]?:\/\/.*/.test(s)
51
}

+ 1 - 1
src/views/login/index.vue

@ -146,7 +146,7 @@ export default {
146 146
    //验证码
147 147
    getCaptcha() {
148 148
      let uuid = Math.random();
149
      this.vercodePath = `/sys/Login/captcha?${uuid}`;
149
      this.vercodePath = `http://192.168.0.2:9528/sys/Login/captcha?${uuid}`;
150 150
    },
151 151
152 152
    showPwd() {

+ 30 - 10
src/views/user/user.vue

@ -35,6 +35,18 @@
35 35
        align="center"
36 36
        label="用户名">
37 37
      </el-table-column>
38
      <el-table-column
39
        prop="rolename"
40
        header-align="center"
41
        align="center"
42
        label="角色">
43
      </el-table-column>
44
      <el-table-column
45
        prop="nickname"
46
        header-align="center"
47
        align="center"
48
        label="昵称">
49
      </el-table-column>
38 50
      <el-table-column
39 51
        prop="email"
40 52
        header-align="center"
@ -42,10 +54,18 @@
42 54
        label="邮箱">
43 55
      </el-table-column>
44 56
      <el-table-column
45
        prop="rolename"
57
        prop="per_time"
58
        header-align="center"
59
        align="center"
60
        width="180"
61
        label="最后登录时间">
62
      </el-table-column>
63
      <el-table-column
64
        prop="per_ip"
46 65
        header-align="center"
47 66
        align="center"
48
        label="用户组">
67
        width="180"
68
        label="最后登录IP">
49 69
      </el-table-column>
50 70
      <el-table-column
51 71
        prop="status"
@ -71,8 +91,8 @@
71 91
        width="150"
72 92
        label="操作">
73 93
        <template slot-scope="scope">
74
          <el-button type="text" size="small" @click="addOrUpdateHandle(scope.row.userId)">修改</el-button>
75
          <el-button type="text" size="small" @click="deleteHandle(scope.row.userId)">删除</el-button>
94
          <el-button type="text" size="small" @click="addOrUpdateHandle(scope.row.userid)">修改</el-button>
95
          <el-button type="text" size="small" @click="deleteHandle(scope.row.userid)">删除</el-button>
76 96
        </template>
77 97
      </el-table-column>
78 98
    </el-table>
@ -117,7 +137,7 @@
117 137
      // 获取数据列表
118 138
      getDataList () {
119 139
        this.dataListLoading = true
120
        console.log(1);
140
        // console.log(1);
121 141
        this.$http({
122 142
          url: this.$http.adornUrl('/sys/user/index'),
123 143
          method: 'get',
@ -127,7 +147,7 @@
127 147
            'username': this.dataForm.userName
128 148
          })
129 149
        }).then(({data}) => {
130
         console.log(data);
150
        //  console.log(data);
131 151
          if (data && data.code === 0) {
132 152
            this.dataList = data.data.data
133 153
            this.totalPage = data.data.total
@ -162,10 +182,10 @@
162 182
      },
163 183
      // 删除
164 184
      deleteHandle (id) {
165
        var userIds = id ? [id] : this.dataListSelections.map(item => {
166
          return item.userId
185
        var userids = id ? [id] : this.dataListSelections.map(item => {
186
          return item.userid
167 187
        })
168
        this.$confirm(`确定对[id=${userIds.join(',')}]进行[${id ? '删除' : '批量删除'}]操作?`, '提示', {
188
        this.$confirm(`确定对[id=${userids.join(',')}]进行[${id ? '删除' : '批量删除'}]操作?`, '提示', {
169 189
          confirmButtonText: '确定',
170 190
          cancelButtonText: '取消',
171 191
          type: 'warning'
@ -173,7 +193,7 @@
173 193
          this.$http({
174 194
            url: this.$http.adornUrl('/sys/user/delete'),
175 195
            method: 'post',
176
            data: this.$http.adornData(userIds, false)
196
            data: this.$http.adornData(userids, false)
177 197
          }).then(({data}) => {
178 198
            if (data && data.code === 0) {
179 199
              this.$message({

+ 152 - 124
src/views/user/user-add-or-update.vue

@ -1,6 +1,6 @@
1 1
<template>
2 2
  <el-dialog
3
    :title="!dataForm.id ? '新增' : '修改'"
3
    :title="!dataForm.id ? '新增管理员' : '修改管理员'"
4 4
    :close-on-click-modal="false"
5 5
    :visible.sync="visible"
6 6
  >
@ -11,8 +11,8 @@
11 11
      @keyup.enter.native="dataFormSubmit()"
12 12
      label-width="80px"
13 13
    >
14
      <el-form-item label="用户名" prop="userName">
15
        <el-input v-model="dataForm.userName" placeholder="登录帐号"></el-input>
14
      <el-form-item label="用户名" prop="username">
15
        <el-input v-model="dataForm.username" placeholder="登录帐号"></el-input>
16 16
      </el-form-item>
17 17
      <el-form-item
18 18
        label="密码"
@ -36,55 +36,46 @@
36 36
          placeholder="确认密码"
37 37
        ></el-input>
38 38
      </el-form-item>
39
      <el-form-item label="昵称" prop="nickname">
40
        <el-input v-model="dataForm.nickname" placeholder="昵称"></el-input>
41
      </el-form-item>
42
      <el-form-item label="姓名" prop="truename">
43
        <el-input v-model="dataForm.truename" placeholder="姓名"></el-input>
44
      </el-form-item>
39 45
      <el-form-item label="邮箱" prop="email">
40 46
        <el-input v-model="dataForm.email" placeholder="邮箱"></el-input>
41 47
      </el-form-item>
42
      <el-form-item label="手机号" prop="mobile">
43
        <el-input v-model="dataForm.mobile" placeholder="手机号"></el-input>
44
      </el-form-item>
45
      <!-- <el-form-item label="部门" prop="departmentList">
48
      <el-form-item label="部门" prop="departmentname">
46 49
        <el-select
47
          v-model="dataForm.departmentList"
48
          placeholder="部门"
49
          allow-create
50
          filterable
51
          @change="getClientName"
50
          v-model="dataForm.departmentname"
51
          size="medium"
52
          placeholder="请选择部门"
53
          @change="changedepartmentName"
52 54
        >
53
          <el-tree
55
          <el-option
54 56
            v-for="item in departmentList"
55
            :label="item.departmentName"
56
            :value="item.departmentId"
57
            :key="item.departmentId"
58
          ></el-tree>
57
            :key="item.departmentid"
58
            :value="item.departmentid"
59
            :label="item.departmentname"
60
          >
61
          </el-option>
59 62
        </el-select>
60
      </el-form-item> -->
61
      <el-form-item label="部门" prop="departmentName">
62
        <el-popover
63
          ref="menuListPopover"
64
          placement="bottom-start"
65
          trigger="click">
66
          <el-tree
67
            :data="departmentList"
68
            :props="menuListTreeProps"
69
            node-key="departmentId"
70
            ref="departmentListTree"
71
            @current-change="departmentListTreeCurrentChangeHandle"
72
            :default-expand-all="true"
73
            :highlight-current="true"
74
            :expand-on-click-node="true">
75
          </el-tree>
76
        </el-popover>
77
        <el-input v-model="dataForm.departmentName" v-popover:menuListPopover :readonly="true" placeholder="点击选择部门" class="menu-list__input"></el-input>
78 63
      </el-form-item>
79
      <el-form-item label="角色" size="mini" prop="roleIdList">
80
        <el-checkbox-group v-model="dataForm.roleIdList">
81
          <el-checkbox
82
            v-for="role in roleList"
83
            :key="role.roleId"
84
            :label="role.roleId"
85
            >{{ role.roleName }}</el-checkbox
64
      <el-form-item label="角色" size="mini" prop="roleList">
65
        <el-select
66
          v-model="dataForm.rolename"
67
          size="medium"
68
          placeholder="请选择角色"
69
          @change="changeRole"
70
        >
71
          <el-option
72
            v-for="item in roleList"
73
            :key="item.roleid"
74
            :value="item.roleid"
75
            :label="item.name"
86 76
          >
87
        </el-checkbox-group>
77
          </el-option>
78
        </el-select>
88 79
      </el-form-item>
89 80
      <el-form-item label="状态" size="mini" prop="status">
90 81
        <el-radio-group v-model="dataForm.status">
@ -118,7 +109,7 @@
118 109
119 110
<script>
120 111
import { isEmail, isMobile } from "@/utils/validate";
121
import { treeDataTranslate } from '@/utils'
112
import { treeDataTranslate } from "@/utils";
122 113
export default {
123 114
  data() {
124 115
    var validatePassword = (rule, value, callback) => {
@ -144,38 +135,44 @@ export default {
144 135
        callback();
145 136
      }
146 137
    };
147
    var validateMobile = (rule, value, callback) => {
148
      if (!isMobile(value)) {
149
        callback(new Error("手机号格式错误"));
150
      } else {
151
        callback();
152
      }
153
    };
138
    // var validateMobile = (rule, value, callback) => {
139
    //   if (!isMobile(value)) {
140
    //     callback(new Error("手机号格式错误"));
141
    //   } else {
142
    //     callback();
143
    //   }
144
    // };
154 145
    return {
155
      visible: false,
146
      visible: false,//加载控制样式
156 147
      dialogImageUrl: "",
157
      roleList: [],
148
      roleList: [],//角色列表
158 149
      dataForm: {
159 150
        id: 0,
160
        userName: "",
161
        password: "",
162
        comfirmPassword: "",
163
        salt: "",
164
        email: "",
165
        mobile: "",
166
        roleIdList: [],
167
        status: 1,
168
        avatar: "",
169
        departmentId:"",
170
        departmentName:"",
151
        username: "",//用户名
152
        userid: "",//用户id
153
        nickname: "",//昵称
154
        rolename:"",//角色名
155
        roleid:"",//角色id
156
        truename: "",//姓名
157
        password: "",//密码
158
        comfirmPassword: "",//二次确认密码
159
        // salt: "",
160
        email: "",//邮箱
161
        // mobile: "",
162
        // roleIdList: [],//角色
163
        status: 1,//状态
164
        avatar: "",//头像
165
        departmentid: "",//部门id
166
        departmentname: "",//部门名称
167
        remark: "",//备注
171 168
      },
172
      departmentList: [],
173
        menuListTreeProps: {
174
          label: 'departmentName',
175
          children: 'children'
176
        },
169
      departmentList: [],//部门列表
170
      // menuListTreeProps: {
171
      //   label: "departmentName",
172
      //   children: "children",
173
      // },
177 174
      dataRule: {
178
        userName: [
175
        username: [
179 176
          { required: true, message: "用户名不能为空", trigger: "blur" },
180 177
        ],
181 178
        password: [{ validator: validatePassword, trigger: "blur" }],
@ -183,40 +180,35 @@ export default {
183 180
          { validator: validateComfirmPassword, trigger: "blur" },
184 181
        ],
185 182
        email: [
186
          { required: true, message: "邮箱不能为空", trigger: "blur" },
183
          // { required: true, message: "邮箱不能为空", trigger: "blur" },
187 184
          { validator: validateEmail, trigger: "blur" },
188 185
        ],
189
        mobile: [
190
          { required: true, message: "手机号不能为空", trigger: "blur" },
191
          { validator: validateMobile, trigger: "blur" },
192
        ],
186
        // mobile: [
187
        //   { required: true, message: "手机号不能为空", trigger: "blur" },
188
        //   { validator: validateMobile, trigger: "blur" },
189
        // ],
193 190
      },
194 191
    };
195 192
  },
196 193
  methods: {
197 194
    // 上传成功
198 195
    handlePictureCardPreview(response, file) {
199
      console.log(response);
196
      // console.log(response);
200 197
      this.dataForm.avatar = response.url;
201 198
    },
202
    getClientName(e) {
203
      console.log(e);
204
      let obj = {};
205
      obj = this.departmentList.find((item) => {
206
        return item.departmentId === e;
207
      });
208
      console.log(obj);
209
      console.log(obj.name);
210
      this.dataForm.departmentId = e;
211
    },
199
   
212 200
    init(id) {
213 201
      this.dataForm.id = id || 0;
214 202
      this.$http({
215
        url: this.$http.adornUrl("/sys/user/index"),
203
        url: this.$http.adornUrl("/sys/Department/index"),
216 204
        method: "get",
217 205
        params: this.$http.adornParams(),
218 206
      }).then(({ data }) => {
219
          this.departmentList = treeDataTranslate(data.list, 'departmentId')
207
        console.log(data);
208
          this.departmentList = data.data
209
        console.log(this.departmentList);
210
          
211
220 212
      }).then(() => {
221 213
          this.visible = true
222 214
          this.$nextTick(() => {
@ -224,12 +216,14 @@ export default {
224 216
          })
225 217
        })
226 218
      this.$http({
227
        url: this.$http.adornUrl("/sys/user/index"),
219
        url: this.$http.adornUrl("/sys/Role/index"),
228 220
        method: "get",
229 221
        params: this.$http.adornParams(),
230 222
      })
231 223
        .then(({ data }) => {
232
          this.roleList = data && data.code === 0 ? data.list : [];
224
          // console.log(data);
225
          this.roleList = data && data.code === 0 ? data.data : [];
226
          // console.log(this.roleList);
233 227
        })
234 228
        .then(() => {
235 229
          this.visible = true;
@ -238,65 +232,99 @@ export default {
238 232
          });
239 233
        })
240 234
        .then(() => {
241
          if (this.dataForm.id) {
235
          // if (this.dataForm.id) {
242 236
            this.$http({
243
              url: this.$http.adornUrl(`/sys/user/info/${this.dataForm.id}`),
237
              url: this.$http.adornUrl(`/sys/user/info/id/${this.dataForm.id}`),
244 238
              method: "get",
245 239
              params: this.$http.adornParams(),
246 240
            }).then(({ data }) => {
241
              // console.log(data);
247 242
              if (data && data.code === 0) {
248
                this.dataForm.userName = data.user.username;
249
                this.dataForm.salt = data.user.salt;
250
                this.dataForm.email = data.user.email;
251
                this.dataForm.mobile = data.user.mobile;
252
                this.dataForm.roleIdList = data.user.roleIdList;
253
                this.dataForm.status = data.user.status;
254
                this.dataForm.avatar = data.user.avatar;
255
                this.dataForm.departmentId = data.user.departmentId;
256
                this.dataForm.departmentName = data.user.departmentName;
257
                this.menuListTreeSetCurrentNode()
243
                this.visible = true;
244
                this.dataForm.username = data.data.username;
245
                this.dataForm.nickname = data.data.nickname;
246
                this.dataForm.truename = data.data.truename;
247
                this.dataForm.rolename = data.data.rolename;
248
                this.dataForm.departmentid = data.data.departmentid;
249
                this.dataForm.userid = data.data.userid;
250
                this.dataForm.roleid = data.data.roleid;
251
252
                // this.dataForm.salt = data.data.salt;
253
                this.dataForm.email = data.data.email;
254
                // this.dataForm.mobile = data.data.mobile;
255
                // this.dataForm.roleIdList = data.data.roleIdList;
256
                this.dataForm.status = data.data.status;
257
                this.dataForm.avatar = data.data.avatar;
258
                // this.dataForm.departmentId = data.data.departmentId;
259
                this.dataForm.departmentname = data.data.departmentname;
260
                // this.menuListTreeSetCurrentNode();
258 261
              }
259 262
            });
260
          }else{
261
            this.menuListTreeSetCurrentNode()
262
          }
263
          // } else {
264
          //   this.menuListTreeSetCurrentNode();
265
          // }
263 266
        });
267
268
        // 头像 
269
264 270
      // this.dialogImageUrl = this.$http.adornUrl(
265 271
      //   `/sys/oss/uploadimg?token=${this.$cookie.get("token")}`
266 272
      // );
267 273
      // console.log(this.dialogImageUrl);
268 274
    },
269
    // 菜单树选中
270
      departmentListTreeCurrentChangeHandle (data, node) {
271
        this.dataForm.departmentId = data.departmentId
272
        this.dataForm.departmentName = data.departmentName
273
      },
274
      // 菜单树设置当前选中节点
275
      menuListTreeSetCurrentNode () {
276
        this.$refs.departmentListTree.setCurrentKey(this.dataForm.departmentId)
277
        this.dataForm.departmentName = (this.$refs.departmentListTree.getCurrentNode() || {})['departmentName']
278
      },
275
    //选择角色
276
    changeRole(e) {
277
      // console.log(e);
278
      // this.dataForm.roleid = e
279
      let obj = {};
280
      obj = this.roleList.find((item) => {
281
        return item.roleid === e;
282
      });
283
      // console.log(obj);
284
      // console.log(obj.name);
285
      this.dataForm.roleid = e;
286
      this.dataForm.rolename = obj.name;
287
      // console.log(this.dataForm.rolename);
288
      // console.log(this.dataForm.roleid);
289
    },
290
    //选择部门
291
     changedepartmentName(e) {
292
      // console.log(e);
293
      let obj = {};
294
      obj = this.departmentList.find((item) => {
295
        return item.departmentid === e;
296
      });
297
      // console.log(this.departmentList);
298
      // console.log(obj);
299
      // console.log(obj.name);
300
      this.dataForm.departmentid = e;
301
      this.dataForm.departmentname = obj.departmentname;
302
    },
303
304
279 305
    // 表单提交
280 306
    dataFormSubmit() {
281 307
      this.$refs["dataForm"].validate((valid) => {
282 308
        if (valid) {
283 309
          this.$http({
284 310
            url: this.$http.adornUrl(
285
              `/sys/user/${!this.dataForm.id ? "save" : "update"}`
311
              `/sys/User/save`
286 312
            ),
287 313
            method: "post",
288
            data: this.$http.adornData({
289
              userId: this.dataForm.id || undefined,
290
              username: this.dataForm.userName,
314
            data: {
315
              userid: this.dataForm.userid || 0,
316
              username: this.dataForm.username,
317
              nickname: this.dataForm.nickname,
318
              truename: this.dataForm.truename,
319
              roleid: this.dataForm.roleid,
291 320
              password: this.dataForm.password,
292
              salt: this.dataForm.salt,
321
              repassword: this.dataForm.comfirmPassword,
293 322
              email: this.dataForm.email,
294
              mobile: this.dataForm.mobile,
295 323
              status: this.dataForm.status,
296
              roleIdList: this.dataForm.roleIdList,
297
              departmentId: this.dataForm.departmentId,
324
              departmentid: this.dataForm.departmentid,
298 325
              avatar: this.dataForm.avatar,
299
            }),
326
              remark: this.dataForm.remark,
327
            },
300 328
          }).then(({ data }) => {
301 329
            if (data && data.code === 0) {
302 330
              this.$message({