User.vue 22.2 KB
Newer Older
1
<template>
S
shiziyuan9527 已提交
2
  <div v-loading="result.loading">
S
shiziyuan9527 已提交
3

S
shiziyuan9527 已提交
4
    <el-card class="table-card">
C
chenjianxing 已提交
5
      <template v-slot:header>
C
Captain.B 已提交
6
        <ms-table-header :condition.sync="condition" @search="search" @create="create"
王振 已提交
7
                         :create-tip="$t('user.create')" :title="$t('commons.user')"/>
C
chenjianxing 已提交
8
      </template>
W
wenyann 已提交
9

10 11
      <el-table :data="tableData" style="width: 100%">
        <el-table-column prop="id" label="ID"/>
W
名称  
wenyann 已提交
12
        <el-table-column prop="name" :label="$t('commons.name')" width="200"/>
S
shiziyuan9527 已提交
13 14 15 16 17
        <el-table-column :label="$t('commons.role')" width="120">
          <template v-slot:default="scope">
            <ms-roles-tag :roles="scope.row.roles"/>
          </template>
        </el-table-column>
S
shiziyuan9527 已提交
18
        <el-table-column prop="email" :label="$t('commons.email')"/>
19
        <el-table-column prop="status" :label="$t('commons.status')" width="120">
C
v-slot  
Captain.B 已提交
20
          <template v-slot:default="scope">
S
shiziyuan9527 已提交
21 22 23 24 25 26 27 28 29
            <el-switch v-model="scope.row.status"
                       active-color="#13ce66"
                       inactive-color="#ff4949"
                       active-value="1"
                       inactive-value="0"
                       @change="changeSwitch(scope.row)"
            />
          </template>
        </el-table-column>
S
shiziyuan9527 已提交
30
        <el-table-column prop="createTime" :label="$t('commons.create_time')">
C
v-slot  
Captain.B 已提交
31
          <template v-slot:default="scope">
32 33 34
            <span>{{ scope.row.createTime | timestampFormatDate }}</span>
          </template>
        </el-table-column>
S
shiziyuan9527 已提交
35
        <el-table-column :label="$t('commons.operating')">
C
v-slot  
Captain.B 已提交
36
          <template v-slot:default="scope">
C
样式  
Captain.B 已提交
37 38 39
            <ms-table-operator @editClick="edit(scope.row)" @deleteClick="del(scope.row)">
              <template v-slot:behind>
                <ms-table-operator-button :tip="$t('member.edit_password')" icon="el-icon-s-tools"
40
                                          type="success" @exec="editPassword(scope.row)" v-if="!scope.row.isLdapUser"/>
C
样式  
Captain.B 已提交
41 42
              </template>
            </ms-table-operator>
43 44 45
          </template>
        </el-table-column>
      </el-table>
46

S
shiziyuan9527 已提交
47 48
      <ms-table-pagination :change="search" :current-page.sync="currentPage" :page-size.sync="pageSize"
                           :total="total"/>
49
    </el-card>
S
shiziyuan9527 已提交
50

W
wenyann 已提交
51
    <!--Create user-->
52
    <el-dialog :title="$t('user.create')" :visible.sync="createVisible" width="35%" @closed="handleClose"
S
shiziyuan9527 已提交
53
               :destroy-on-close="true">
54
      <el-form :model="form" label-position="right" label-width="120px" size="small" :rules="rule" ref="createUserForm">
55
        <el-form-item label="ID" prop="id">
S
i18n  
shiziyuan9527 已提交
56
          <el-input v-model="form.id" autocomplete="off" :placeholder="$t('user.input_id_placeholder')"/>
57
        </el-form-item>
S
shiziyuan9527 已提交
58
        <el-form-item :label="$t('commons.username')" prop="name">
S
i18n  
shiziyuan9527 已提交
59
          <el-input v-model="form.name" autocomplete="off" :placeholder="$t('user.input_name')"/>
60
        </el-form-item>
S
shiziyuan9527 已提交
61
        <el-form-item :label="$t('commons.email')" prop="email">
S
i18n  
shiziyuan9527 已提交
62
          <el-input v-model="form.email" autocomplete="off" :placeholder="$t('user.input_email')"/>
63
        </el-form-item>
S
shiziyuan9527 已提交
64
        <el-form-item :label="$t('commons.phone')" prop="phone">
S
i18n  
shiziyuan9527 已提交
65
          <el-input v-model="form.phone" autocomplete="off" :placeholder="$t('user.input_phone')"/>
66
        </el-form-item>
W
wenyann 已提交
67 68 69
        <el-form-item :label="$t('commons.password')" prop="password" style="margin-bottom: 29px">
          <el-input v-model="form.password" autocomplete="new-password" show-password
                    :placeholder="$t('user.input_password')"/>
W
wenyann 已提交
70
        </el-form-item>
71
        <div v-for="(role, index) in form.roles" :key="index">
S
i18n  
shiziyuan9527 已提交
72
          <el-form-item :label="$t('commons.role')+index"
73
                        :prop="'roles.' + index + '.id'"
S
i18n  
shiziyuan9527 已提交
74
                        :rules="{required: true, message: $t('role.please_choose_role'), trigger: 'change'}"
75
          >
S
i18n  
shiziyuan9527 已提交
76
            <el-select v-model="role.id" :placeholder="$t('role.please_choose_role')">
77
              <el-option
78
                v-for="item in activeRole(role)"
79
                :key="item.id"
S
i18n  
shiziyuan9527 已提交
80
                :label="$t('role.' + item.id)"
81 82
                :value="item.id"
              >
S
i18n  
shiziyuan9527 已提交
83
                {{$t('role.' + item.id)}}
84 85
              </el-option>
            </el-select>
S
i18n  
shiziyuan9527 已提交
86
            <el-button @click.prevent="removeRole(role)" style="margin-left: 20px;" v-if="form.roles.length > 1">{{$t('commons.delete')}}
87 88 89
            </el-button>
          </el-form-item>
          <div v-if="role.id === 'org_admin'">
S
i18n  
shiziyuan9527 已提交
90
            <el-form-item :label="$t('organization.select_organization')"
91
                          :prop="'roles.' + index + '.ids'"
S
i18n  
shiziyuan9527 已提交
92
                          :rules="{required: true, message: $t('organization.select_organization'), trigger: 'change'}"
93
            >
S
i18n  
shiziyuan9527 已提交
94
              <el-select v-model="role.ids" :placeholder="$t('organization.select_organization')" multiple>
95 96 97 98 99 100 101 102 103 104
                <el-option
                  v-for="item in form.orgList"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
          </div>
          <div v-if="role.id === 'test_manager'">
S
i18n  
shiziyuan9527 已提交
105
            <el-form-item :label="$t('workspace.select')"
106
                          :prop="'roles.' + index + '.ids'"
S
i18n  
shiziyuan9527 已提交
107
                          :rules="{required: true, message: $t('workspace.select'), trigger: 'change'}"
108
            >
S
i18n  
shiziyuan9527 已提交
109
              <el-select v-model="role.ids" :placeholder="$t('workspace.select')" multiple>
110 111 112 113 114 115 116 117 118 119
                <el-option
                  v-for="item in form.wsList"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
          </div>
          <div v-if="role.id ==='test_user'">
S
i18n  
shiziyuan9527 已提交
120
            <el-form-item :label="$t('workspace.select')"
121
                          :prop="'roles.' + index + '.ids'"
S
i18n  
shiziyuan9527 已提交
122
                          :rules="{required: true, message: $t('workspace.select'), trigger: 'change'}"
123
            >
S
i18n  
shiziyuan9527 已提交
124
              <el-select v-model="role.ids" :placeholder="$t('workspace.select')" multiple>
125 126 127 128 129 130 131 132 133 134
                <el-option
                  v-for="item in form.wsList"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
          </div>
          <div v-if="role.id ==='test_viewer'">
S
i18n  
shiziyuan9527 已提交
135
            <el-form-item :label="$t('workspace.select')"
136
                          :prop="'roles.' + index + '.ids'"
S
i18n  
shiziyuan9527 已提交
137
                          :rules="{required: true, message: $t('workspace.select'), trigger: 'change'}"
138
            >
S
i18n  
shiziyuan9527 已提交
139
              <el-select v-model="role.ids" :placeholder="$t('workspace.select')" multiple>
140 141 142 143 144 145 146 147 148 149 150 151 152
                <el-option
                  v-for="item in form.wsList"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
          </div>
        </div>

        <el-form-item>
          <template>
S
i18n  
shiziyuan9527 已提交
153
            <el-button type="success" style="width: 100%;" @click="addRole('createUserForm')" :disabled="btnAddRole">{{$t('role.add')}}</el-button>
154 155
          </template>
        </el-form-item>
156
      </el-form>
C
chenjianxing 已提交
157
      <template v-slot:footer>
S
shiziyuan9527 已提交
158 159 160
        <ms-dialog-footer
          @cancel="createVisible = false"
          @confirm="createUser('createUserForm')"/>
C
chenjianxing 已提交
161
      </template>
S
shiziyuan9527 已提交
162 163
    </el-dialog>

W
wenyann 已提交
164
    <!--Modify user information in system settings-->
165
    <el-dialog :title="$t('user.modify')" :visible.sync="updateVisible" width="35%" :destroy-on-close="true"
S
shiziyuan9527 已提交
166
               @close="handleClose">
167
      <el-form :model="form" label-position="right" label-width="120px" size="small" :rules="rule" ref="updateUserForm">
S
shiziyuan9527 已提交
168
        <el-form-item label="ID" prop="id">
169
          <el-input v-model="form.id" autocomplete="off" :disabled="true"/>
S
shiziyuan9527 已提交
170
        </el-form-item>
S
shiziyuan9527 已提交
171
        <el-form-item :label="$t('commons.username')" prop="name">
S
shiziyuan9527 已提交
172 173
          <el-input v-model="form.name" autocomplete="off"/>
        </el-form-item>
S
shiziyuan9527 已提交
174
        <el-form-item :label="$t('commons.email')" prop="email">
S
shiziyuan9527 已提交
175 176
          <el-input v-model="form.email" autocomplete="off"/>
        </el-form-item>
S
shiziyuan9527 已提交
177
        <el-form-item :label="$t('commons.phone')" prop="phone">
S
shiziyuan9527 已提交
178 179
          <el-input v-model="form.phone" autocomplete="off"/>
        </el-form-item>
180
        <div v-for="(role, index) in form.roles" :key="index">
S
i18n  
shiziyuan9527 已提交
181
          <el-form-item :label="$t('commons.role')+index"
182
                        :prop="'roles.' + index + '.id'"
S
i18n  
shiziyuan9527 已提交
183
                        :rules="{required: true, message: $t('role.please_choose_role'), trigger: 'change'}"
184
          >
S
i18n  
shiziyuan9527 已提交
185
            <el-select v-model="role.id" :placeholder="$t('role.please_choose_role')" :disabled="!!role.id">
186
              <el-option
S
bug fix  
shiziyuan9527 已提交
187
                v-for="item in activeRole(role)"
188
                :key="item.id"
S
i18n  
shiziyuan9527 已提交
189
                :label="$t('role.' + item.id)"
190 191 192
                :value="item.id">
              </el-option>
            </el-select>
S
i18n  
shiziyuan9527 已提交
193
            <el-button @click.prevent="removeRole(role)" style="margin-left: 20px;" v-if="form.roles.length > 1">{{$t('commons.delete')}}
194 195 196
            </el-button>
          </el-form-item>
          <div v-if="role.id === 'org_admin'">
S
i18n  
shiziyuan9527 已提交
197
            <el-form-item :label="$t('organization.select_organization')"
198
                          :prop="'roles.' + index + '.ids'"
S
i18n  
shiziyuan9527 已提交
199
                          :rules="{required: true, message: $t('organization.select_organization'), trigger: 'change'}"
200
            >
S
i18n  
shiziyuan9527 已提交
201
              <el-select v-model="role.ids" :placeholder="$t('organization.select_organization')" multiple>
202 203 204 205 206 207 208 209 210 211
                <el-option
                  v-for="item in form.orgList"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
          </div>
          <div v-if="role.id === 'test_manager'">
S
i18n  
shiziyuan9527 已提交
212
            <el-form-item :label="$t('workspace.select')"
213
                          :prop="'roles.' + index + '.ids'"
S
i18n  
shiziyuan9527 已提交
214
                          :rules="{required: true, message: $t('workspace.select'), trigger: 'change'}"
215
            >
S
i18n  
shiziyuan9527 已提交
216
              <el-select v-model="role.ids" :placeholder="$t('workspace.select')" multiple>
217 218 219 220 221 222 223 224 225 226
                <el-option
                  v-for="item in form.wsList"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
          </div>
          <div v-if="role.id ==='test_user'">
S
i18n  
shiziyuan9527 已提交
227
            <el-form-item :label="$t('workspace.select')"
228
                          :prop="'roles.' + index + '.ids'"
S
i18n  
shiziyuan9527 已提交
229
                          :rules="{required: true, message: $t('workspace.select'), trigger: 'change'}"
230
            >
S
i18n  
shiziyuan9527 已提交
231
              <el-select v-model="role.ids" :placeholder="$t('workspace.select')" multiple>
232 233 234 235 236 237 238 239 240 241
                <el-option
                  v-for="item in form.wsList"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
          </div>
          <div v-if="role.id ==='test_viewer'">
S
i18n  
shiziyuan9527 已提交
242
            <el-form-item :label="$t('workspace.select')"
243
                          :prop="'roles.' + index + '.ids'"
S
i18n  
shiziyuan9527 已提交
244
                          :rules="{required: true, message: $t('workspace.select'), trigger: 'change'}"
245
            >
S
i18n  
shiziyuan9527 已提交
246
              <el-select v-model="role.ids" :placeholder="$t('workspace.select')" multiple>
247 248 249 250 251 252 253 254 255 256 257 258
                <el-option
                  v-for="item in form.wsList"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
          </div>
        </div>
        <el-form-item>
          <template>
S
i18n  
shiziyuan9527 已提交
259
            <el-button type="success" style="width: 100%;" @click="addRole('updateUserForm')" :disabled="btnAddRole">{{$t('role.add')}}</el-button>
260 261
          </template>
        </el-form-item>
S
shiziyuan9527 已提交
262
      </el-form>
C
chenjianxing 已提交
263
      <template v-slot:footer>
S
shiziyuan9527 已提交
264 265 266
        <ms-dialog-footer
          @cancel="updateVisible = false"
          @confirm="updateUser('updateUserForm')"/>
C
chenjianxing 已提交
267
      </template>
268
    </el-dialog>
S
shiziyuan9527 已提交
269
    <!--Changing user password in system settings-->
W
wenyann 已提交
270 271
    <el-dialog :title="$t('member.edit_password')" :visible.sync="editPasswordVisible" width="30%"
               :destroy-on-close="true" @close="handleClose" left>
C
Captain.B 已提交
272
      <el-form :model="ruleForm" label-position="right" label-width="120px" size="small" :rules="rule"
S
shiziyuan9527 已提交
273
               ref="editPasswordForm" class="demo-ruleForm">
W
wenyann 已提交
274 275 276
        <el-form-item :label="$t('member.new_password')" prop="newpassword">
          <el-input type="password" v-model="ruleForm.newpassword" autocomplete="off" show-password></el-input>
        </el-form-item>
S
shiziyuan9527 已提交
277
        <el-form-item>
W
wenyann 已提交
278
          <el-input v-model="ruleForm.id" autocomplete="off" :disabled="true" style="display:none"/>
W
demo  
wenyann 已提交
279 280 281
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
W
wenyann 已提交
282 283 284
        <ms-dialog-footer
          @cancel="editPasswordVisible = false"
          @confirm="editUserPassword('editPasswordForm')"/>
W
demo  
wenyann 已提交
285
      </span>
W
wenyann 已提交
286
    </el-dialog>
S
shiziyuan9527 已提交
287

288 289 290 291
  </div>
</template>

<script>
S
shiziyuan9527 已提交
292
  import MsCreateBox from "../CreateBox";
S
shiziyuan9527 已提交
293
  import MsTablePagination from "../../common/pagination/TablePagination";
C
Captain.B 已提交
294
  import MsTableHeader from "../../common/components/MsTableHeader";
S
shiziyuan9527 已提交
295
  import MsTableOperator from "../../common/components/MsTableOperator";
S
shiziyuan9527 已提交
296
  import MsDialogFooter from "../../common/components/MsDialogFooter";
C
样式  
Captain.B 已提交
297
  import MsTableOperatorButton from "../../common/components/MsTableOperatorButton";
S
shiziyuan9527 已提交
298
  import {getCurrentUser} from "../../../../common/js/utils";
S
shiziyuan9527 已提交
299
  import MsRolesTag from "../../common/components/MsRolesTag";
300 301

  export default {
C
Captain.B 已提交
302
    name: "MsUser",
S
shiziyuan9527 已提交
303 304 305 306 307 308 309 310 311
    components: {
      MsCreateBox,
      MsTablePagination,
      MsTableHeader,
      MsTableOperator,
      MsDialogFooter,
      MsTableOperatorButton,
      MsRolesTag
    },
312 313
    data() {
      return {
S
shiziyuan9527 已提交
314 315 316 317
        queryPath: '/user/special/list',
        deletePath: '/user/special/delete/',
        createPath: '/user/special/add',
        updatePath: '/user/special/update',
C
样式  
Captain.B 已提交
318
        editPasswordPath: '/user/special/password',
S
shiziyuan9527 已提交
319
        result: {},
320 321
        createVisible: false,
        updateVisible: false,
S
shiziyuan9527 已提交
322
        editPasswordVisible: false,
323
        btnAddRole: false,
324
        multipleSelection: [],
325
        userRole: [],
326 327 328
        currentPage: 1,
        pageSize: 5,
        total: 0,
C
Captain.B 已提交
329
        condition: {},
330
        tableData: [],
331
        form: {
332 333 334
          roles: [{
            id: ''
          }]
335
        },
S
shiziyuan9527 已提交
336
        checkPasswordForm: {},
W
wenyann 已提交
337
        ruleForm: {},
338 339
        rule: {
          id: [
S
shiziyuan9527 已提交
340
            {required: true, message: this.$t('user.input_id'), trigger: 'blur'},
S
shiziyuan9527 已提交
341 342 343 344 345 346 347
            {min: 2, max: 50, message: this.$t('commons.input_limit', [2, 50]), trigger: 'blur'},
            {
              required: true,
              pattern: /^[a-zA-Z0-9]+$/,
              message: this.$t('user.special_characters_are_not_supported'),
              trigger: 'blur'
            }
348 349
          ],
          name: [
S
shiziyuan9527 已提交
350
            {required: true, message: this.$t('user.input_name'), trigger: 'blur'},
C
Captain.B 已提交
351
            {min: 2, max: 50, message: this.$t('commons.input_limit', [2, 50]), trigger: 'blur'},
352 353 354
            {
              required: true,
              pattern: /^[\u4e00-\u9fa5_a-zA-Z0-9.·-]+$/,
S
shiziyuan9527 已提交
355
              message: this.$t('user.special_characters_are_not_supported'),
356 357 358 359 360 361 362
              trigger: 'blur'
            }
          ],
          phone: [
            {
              required: false,
              pattern: '^1(3|4|5|7|8)\\d{9}$',
S
shiziyuan9527 已提交
363
              message: this.$t('user.mobile_number_format_is_incorrect'),
364 365 366 367
              trigger: 'blur'
            }
          ],
          email: [
S
shiziyuan9527 已提交
368
            {required: true, message: this.$t('user.input_email'), trigger: 'blur'},
369 370
            {
              required: true,
C
Captain.B 已提交
371
              pattern: /^([A-Za-z0-9_\-.])+@([A-Za-z0-9]+\.)+[A-Za-z]{2,6}$/,
S
shiziyuan9527 已提交
372
              message: this.$t('user.email_format_is_incorrect'),
373 374
              trigger: 'blur'
            }
W
wenyann 已提交
375 376 377 378
          ],
          password: [
            {required: true, message: this.$t('user.input_password'), trigger: 'blur'},
            {
S
shiziyuan9527 已提交
379
              required: true,
W
wenyann 已提交
380 381 382 383
              pattern: /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[^]{8,16}$/,
              message: this.$t('member.password_format_is_incorrect'),
              trigger: 'blur'
            }
W
wenyann 已提交
384 385
          ],
          newpassword: [
S
shiziyuan9527 已提交
386 387 388 389 390 391 392
            {required: true, message: this.$t('user.input_password'), trigger: 'blur'},
            {
              required: true,
              pattern: /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[^]{8,16}$/,
              message: this.$t('member.password_format_is_incorrect'),
              trigger: 'blur'
            }
393 394 395 396
          ]
        }
      }
    },
397
    activated() {
S
shiziyuan9527 已提交
398
      this.search();
399
      this.getAllRole();
400 401 402 403
    },
    methods: {
      create() {
        this.createVisible = true;
404 405
        this.getOrgList();
        this.getWsList();
406 407
      },
      edit(row) {
S
shiziyuan9527 已提交
408
        this.updateVisible = true;
S
shiziyuan9527 已提交
409
        this.form = Object.assign({}, row);
410 411 412 413 414 415 416 417 418 419
        this.$get("/organization/list", response => {
          this.$set(this.form, "orgList", response.data);
        });
        this.$get("/workspace/list", response => {
          this.$set(this.form, "wsList", response.data);
        });
        this.$get('/userrole/all/' + row.id, response => {
          let data = response.data;
          this.$set(this.form, "roles", data);
        });
420
      },
S
shiziyuan9527 已提交
421 422
      editPassword(row) {
        this.editPasswordVisible = true;
W
wenyann 已提交
423 424
        this.ruleForm = Object.assign({}, row);
      },
425
      del(row) {
S
shiziyuan9527 已提交
426 427 428
        this.$confirm(this.$t('user.delete_confirm'), '', {
          confirmButtonText: this.$t('commons.confirm'),
          cancelButtonText: this.$t('commons.cancel'),
429 430
          type: 'warning'
        }).then(() => {
S
shiziyuan9527 已提交
431
          this.result = this.$get(this.deletePath + row.id, () => {
S
shiziyuan9527 已提交
432
            this.$success(this.$t('commons.delete_success'));
S
shiziyuan9527 已提交
433
            this.search();
434 435
          });
        }).catch(() => {
S
shiziyuan9527 已提交
436
          this.$info(this.$t('commons.delete_cancel'));
437 438
        });
      },
S
shiziyuan9527 已提交
439
      createUser(createUserForm) {
S
shiziyuan9527 已提交
440 441
        this.$refs[createUserForm].validate(valid => {
          if (valid) {
S
shiziyuan9527 已提交
442
            this.result = this.$post(this.createPath, this.form, () => {
S
shiziyuan9527 已提交
443
              this.$success(this.$t('commons.save_success'));
S
shiziyuan9527 已提交
444
              this.search();
S
shiziyuan9527 已提交
445
              this.createVisible = false;
S
shiziyuan9527 已提交
446
            });
S
shiziyuan9527 已提交
447 448 449 450 451 452
          } else {
            return false;
          }
        })
      },
      updateUser(updateUserForm) {
S
shiziyuan9527 已提交
453 454
        this.$refs[updateUserForm].validate(valid => {
          if (valid) {
S
shiziyuan9527 已提交
455
            this.result = this.$post(this.updatePath, this.form, () => {
S
shiziyuan9527 已提交
456
              this.$success(this.$t('commons.modify_success'));
S
shiziyuan9527 已提交
457
              this.updateVisible = false;
S
shiziyuan9527 已提交
458 459
              this.search();
            });
460 461 462 463 464
          } else {
            return false;
          }
        })
      },
S
shiziyuan9527 已提交
465 466 467
      editUserPassword(editPasswordForm) {
        this.$refs[editPasswordForm].validate(valid => {
          if (valid) {
W
wenyann 已提交
468 469 470
            this.result = this.$post(this.editPasswordPath, this.ruleForm, response => {
              this.$success(this.$t('commons.modify_success'));
              this.editPasswordVisible = false;
S
shiziyuan9527 已提交
471
              this.search();
W
wenyann 已提交
472 473
              window.location.reload();
            });
S
shiziyuan9527 已提交
474
          } else {
W
wenyann 已提交
475 476 477 478
            return false;
          }
        })
      },
S
shiziyuan9527 已提交
479
      search() {
C
Captain.B 已提交
480
        this.result = this.$post(this.buildPagePath(this.queryPath), this.condition, response => {
S
shiziyuan9527 已提交
481 482 483
          let data = response.data;
          this.total = data.itemCount;
          this.tableData = data.listObject;
S
shiziyuan9527 已提交
484 485 486 487 488 489 490
          let url = "/user/special/user/role";
          for (let i = 0; i < this.tableData.length; i++) {
            this.$get(url + '/' + this.tableData[i].id, result => {
              let data = result.data;
              let roles = data.roles;
              // let userRoles = result.userRoles;
              this.$set(this.tableData[i], "roles", roles);
491
              this.$set(this.tableData[i], "isLdapUser", this.tableData[i].source === 'LDAP' ? true : false);
492
            });
S
shiziyuan9527 已提交
493
          }
494
        })
S
shiziyuan9527 已提交
495
      },
S
shiziyuan9527 已提交
496
      handleClose() {
497
        this.form = {roles: [{id: ''}]};
S
bug fix  
shiziyuan9527 已提交
498
        this.btnAddRole = false;
S
shiziyuan9527 已提交
499 500
      },
      changeSwitch(row) {
501
        this.$post('/user/special/update_status', row, () => {
S
shiziyuan9527 已提交
502
          this.$success(this.$t('commons.modify_success'));
S
shiziyuan9527 已提交
503 504
        })
      },
505 506 507 508 509
      buildPagePath(path) {
        return path + "/" + this.currentPage + "/" + this.pageSize;
      },
      handleSelectionChange(val) {
        this.multipleSelection = val;
510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525
      },
      getOrgList() {
        this.$get("/organization/list", response => {
          this.$set(this.form, "orgList", response.data);
        })
      },
      getWsList() {
        this.$get("/workspace/list", response => {
          this.$set(this.form, "wsList", response.data);
        })
      },
      getAllRole() {
        this.$get("/role/all", response => {
          this.userRole = response.data;
        })
      },
S
bug fix  
shiziyuan9527 已提交
526 527
      addRole(validForm) {
        this.$refs[validForm].validate(valid => {
528 529 530 531 532 533 534 535 536 537 538 539 540 541 542
          if (valid) {
            let roleInfo = {};
            roleInfo.selects = [];
            let ids = this.form.roles.map(r => r.id);
            ids.forEach(id => {
              roleInfo.selects.push(id);
            })
            let roles = this.form.roles;
            roles.push(roleInfo);
            if (this.form.roles.length > this.userRole.length - 1) {
              this.btnAddRole = true;
            }
          } else {
            return false;
          }
543
        })
544 545
      },
      removeRole(item) {
546
        let index = this.form.roles.indexOf(item);
547 548 549
        if (index !== -1) {
          this.form.roles.splice(index, 1)
        }
550 551 552
        if (this.form.roles.length < this.userRole.length) {
          this.btnAddRole = false;
        }
553
      },
554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570
      activeRole(roleInfo) {
        return this.userRole.filter(function (role) {
          let value = true;
          if (!roleInfo.selects) {
            return true;
          }
          if (roleInfo.selects.length === 0) {
            value = true;
          }
          for (let i = 0; i < roleInfo.selects.length; i++) {
            if (role.id === roleInfo.selects[i]) {
              value = false;
            }
          }
          return value;
        })
      }
571 572 573 574 575 576
    }
  }
</script>

<style scoped>
</style>