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
        <el-form-item :label="$t('commons.password')" prop="password">
S
i18n  
shiziyuan9527 已提交
68
          <el-input v-model="form.password" autocomplete="new-password" show-password :placeholder="$t('user.input_password')"/>
W
wenyann 已提交
69
        </el-form-item>
70
        <div v-for="(role, index) in form.roles" :key="index">
S
i18n  
shiziyuan9527 已提交
71
          <el-form-item :label="$t('commons.role')+index"
72
                        :prop="'roles.' + index + '.id'"
S
i18n  
shiziyuan9527 已提交
73
                        :rules="{required: true, message: $t('role.please_choose_role'), trigger: 'change'}"
74
          >
S
i18n  
shiziyuan9527 已提交
75
            <el-select v-model="role.id" :placeholder="$t('role.please_choose_role')">
76
              <el-option
77
                v-for="item in activeRole(role)"
78
                :key="item.id"
S
i18n  
shiziyuan9527 已提交
79
                :label="$t('role.' + item.id)"
80 81
                :value="item.id"
              >
S
i18n  
shiziyuan9527 已提交
82
                {{$t('role.' + item.id)}}
83 84
              </el-option>
            </el-select>
S
i18n  
shiziyuan9527 已提交
85
            <el-button @click.prevent="removeRole(role)" style="margin-left: 20px;" v-if="form.roles.length > 1">{{$t('commons.delete')}}
86 87 88
            </el-button>
          </el-form-item>
          <div v-if="role.id === 'org_admin'">
S
i18n  
shiziyuan9527 已提交
89
            <el-form-item :label="$t('organization.select_organization')"
90
                          :prop="'roles.' + index + '.ids'"
S
i18n  
shiziyuan9527 已提交
91
                          :rules="{required: true, message: $t('organization.select_organization'), trigger: 'change'}"
92
            >
S
i18n  
shiziyuan9527 已提交
93
              <el-select v-model="role.ids" :placeholder="$t('organization.select_organization')" multiple>
94 95 96 97 98 99 100 101 102 103
                <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 已提交
104
            <el-form-item :label="$t('workspace.select')"
105
                          :prop="'roles.' + index + '.ids'"
S
i18n  
shiziyuan9527 已提交
106
                          :rules="{required: true, message: $t('workspace.select'), trigger: 'change'}"
107
            >
S
i18n  
shiziyuan9527 已提交
108
              <el-select v-model="role.ids" :placeholder="$t('workspace.select')" multiple>
109 110 111 112 113 114 115 116 117 118
                <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 已提交
119
            <el-form-item :label="$t('workspace.select')"
120
                          :prop="'roles.' + index + '.ids'"
S
i18n  
shiziyuan9527 已提交
121
                          :rules="{required: true, message: $t('workspace.select'), trigger: 'change'}"
122
            >
S
i18n  
shiziyuan9527 已提交
123
              <el-select v-model="role.ids" :placeholder="$t('workspace.select')" multiple>
124 125 126 127 128 129 130 131 132 133
                <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 已提交
134
            <el-form-item :label="$t('workspace.select')"
135
                          :prop="'roles.' + index + '.ids'"
S
i18n  
shiziyuan9527 已提交
136
                          :rules="{required: true, message: $t('workspace.select'), trigger: 'change'}"
137
            >
S
i18n  
shiziyuan9527 已提交
138
              <el-select v-model="role.ids" :placeholder="$t('workspace.select')" multiple>
139 140 141 142 143 144 145 146 147 148 149 150 151
                <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 已提交
152
            <el-button type="success" style="width: 100%;" @click="addRole('createUserForm')" :disabled="btnAddRole">{{$t('role.add')}}</el-button>
153 154
          </template>
        </el-form-item>
155
      </el-form>
C
chenjianxing 已提交
156
      <template v-slot:footer>
S
shiziyuan9527 已提交
157 158 159
        <ms-dialog-footer
          @cancel="createVisible = false"
          @confirm="createUser('createUserForm')"/>
C
chenjianxing 已提交
160
      </template>
S
shiziyuan9527 已提交
161 162
    </el-dialog>

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

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

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

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

<style scoped>
</style>