User.vue 22.0 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"/>
S
shiziyuan9527 已提交
12 13 14 15 16 17
        <el-table-column prop="name" :label="$t('commons.username')" width="200"/>
        <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 40 41 42
            <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"
                                          type="success" @exec="editPassword(scope.row)"/>
              </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-->
S
shiziyuan9527 已提交
165
    <el-dialog :title="$t('user.modify')" :visible.sync="updateVisible" width="30%" :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
    <el-dialog :title="$t('member.edit_password')" :visible.sync="editPasswordVisible" width="30%" left>
C
Captain.B 已提交
271
      <el-form :model="ruleForm" label-position="right" label-width="120px" size="small" :rules="rule"
S
shiziyuan9527 已提交
272
               ref="editPasswordForm" class="demo-ruleForm">
W
wenyann 已提交
273 274 275
        <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 已提交
276
        <el-form-item>
W
wenyann 已提交
277
          <el-input v-model="ruleForm.id" autocomplete="off" :disabled="true" style="display:none"/>
W
demo  
wenyann 已提交
278 279 280
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
W
wenyann 已提交
281 282 283
        <ms-dialog-footer
          @cancel="editPasswordVisible = false"
          @confirm="editUserPassword('editPasswordForm')"/>
W
demo  
wenyann 已提交
284
      </span>
W
wenyann 已提交
285
    </el-dialog>
S
shiziyuan9527 已提交
286

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

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

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

<style scoped>
</style>