OrganizationWorkspace.vue 15.4 KB
Newer Older
1 2 3
<template>
  <div>
    <el-card v-loading="result.loading">
C
chenjianxing 已提交
4
      <template v-slot:header>
S
shiziyuan9527 已提交
5
        <ms-table-header :condition.sync="condition" @search="list" @create="create"
C
Captain.B 已提交
6
                         :create-tip="btnTips" :title="$t('commons.workspace')"/>
C
chenjianxing 已提交
7
      </template>
8
      <el-table :data="items" style="width: 100%">
S
shiziyuan9527 已提交
9 10
        <el-table-column prop="name" :label="$t('commons.name')"/>
        <el-table-column prop="description" :label="$t('commons.description')"/>
11
        <el-table-column :label="$t('commons.member')">
C
v-slot  
Captain.B 已提交
12
          <template v-slot:default="scope">
C
Captain.B 已提交
13 14
            <el-button type="text" class="member-size" @click="cellClick(scope.row)">{{scope.row.memberSize}}
            </el-button>
15 16
          </template>
        </el-table-column>
17
        <el-table-column>
C
v-slot  
Captain.B 已提交
18
          <template v-slot:default="scope">
S
shiziyuan9527 已提交
19
            <ms-table-operator @editClick="edit(scope.row)" @deleteClick="del(scope.row)"/>
20 21 22
          </template>
        </el-table-column>
      </el-table>
S
shiziyuan9527 已提交
23 24
      <ms-table-pagination :change="list" :current-page.sync="currentPage" :page-size.sync="pageSize"
                           :total="total"/>
25 26
    </el-card>

S
shiziyuan9527 已提交
27
    <el-dialog :title="$t('workspace.create')" :visible.sync="dialogWsAddVisible" width="30%">
28
      <el-form :model="form" :rules="rules" ref="form" label-position="right" label-width="100px" size="small">
S
shiziyuan9527 已提交
29
        <el-form-item :label="$t('commons.name')" prop="name">
30 31
          <el-input v-model="form.name" autocomplete="off"/>
        </el-form-item>
S
shiziyuan9527 已提交
32
        <el-form-item :label="$t('commons.description')">
33 34 35
          <el-input type="textarea" v-model="form.description"></el-input>
        </el-form-item>
      </el-form>
C
chenjianxing 已提交
36
      <template v-slot:footer>
S
shiziyuan9527 已提交
37 38 39
        <ms-dialog-footer
          @cancel="dialogWsAddVisible = false"
          @confirm="submit('form')"/>
C
chenjianxing 已提交
40
      </template>
41
    </el-dialog>
42 43

    <!-- dialog of workspace member -->
S
shiziyuan9527 已提交
44
    <el-dialog :visible.sync="dialogWsMemberVisible" width="70%" :destroy-on-close="true" @close="closeMemberFunc">
S
shiziyuan9527 已提交
45
      <ms-table-header :condition.sync="dialogCondition" @create="addMember" @search="dialogSearch"
S
shiziyuan9527 已提交
46
                       :create-tip="dialogBtnTips" :title="$t('commons.member')"/>
47
      <!-- organization member table -->
S
shiziyuan9527 已提交
48
      <el-table :data="memberLineData" style="width: 100%;margin-top: 5px;">
49 50 51 52
        <el-table-column prop="name" :label="$t('commons.username')"/>
        <el-table-column prop="email" :label="$t('commons.email')"/>
        <el-table-column prop="phone" :label="$t('commons.phone')"/>
        <el-table-column :label="$t('commons.role')" width="120">
C
v-slot  
Captain.B 已提交
53
          <template v-slot:default="scope">
S
shiziyuan9527 已提交
54
            <ms-roles-tag :roles="scope.row.roles" type="success"/>
55 56 57
          </template>
        </el-table-column>
        <el-table-column :label="$t('commons.operating')">
C
v-slot  
Captain.B 已提交
58
          <template v-slot:default="scope">
S
shiziyuan9527 已提交
59
            <ms-table-operator @editClick="editMember(scope.row)" @deleteClick="delMember(scope.row)"/>
60 61 62
          </template>
        </el-table-column>
      </el-table>
S
shiziyuan9527 已提交
63 64
      <ms-table-pagination :change="dialogSearch" :current-page.sync="dialogCurrentPage"
                           :page-size.sync="dialogPageSize"
S
shiziyuan9527 已提交
65
                           :total="dialogTotal"/>
66 67 68
    </el-dialog>

    <!-- add workspace member dialog -->
S
shiziyuan9527 已提交
69 70
    <el-dialog :title="$t('member.create')" :visible.sync="dialogWsMemberAddVisible" width="30%"
               :destroy-on-close="true"
C
Captain.B 已提交
71 72 73
               @close="closeFunc">
      <el-form :model="memberForm" ref="form" :rules="wsMemberRule" label-position="right" label-width="100px"
               size="small">
74
        <el-form-item :label="$t('commons.member')" prop="userIds">
C
Captain.B 已提交
75 76
          <el-select v-model="memberForm.userIds" multiple :placeholder="$t('member.please_choose_member')"
                     class="select-width">
77 78 79 80 81 82 83 84 85 86 87
            <el-option
              v-for="item in memberForm.userList"
              :key="item.id"
              :label="item.name"
              :value="item.id">
              <span class="ws-member-name">{{ item.name }}</span>
              <span class="ws-member-email">{{ item.email }}</span>
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item :label="$t('commons.role')" prop="roleIds">
C
Captain.B 已提交
88 89
          <el-select v-model="memberForm.roleIds" multiple :placeholder="$t('role.please_choose_role')"
                     class="select-width">
90 91 92 93 94 95 96 97 98
            <el-option
              v-for="item in memberForm.roles"
              :key="item.id"
              :label="item.name"
              :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
C
chenjianxing 已提交
99
      <template v-slot:footer>
S
shiziyuan9527 已提交
100 101 102
        <ms-dialog-footer
          @cancel="dialogWsMemberAddVisible = false"
          @confirm="submitForm('form')"/>
C
chenjianxing 已提交
103
      </template>
104 105 106
    </el-dialog>

    <!-- update workspace member dialog -->
S
shiziyuan9527 已提交
107 108
    <el-dialog :title="$t('member.modify')" :visible.sync="dialogWsMemberUpdateVisible" width="30%"
               :destroy-on-close="true"
C
Captain.B 已提交
109
               @close="closeFunc">
110
      <el-form :model="memberForm" label-position="right" label-width="100px" size="small" ref="updateUserForm">
111 112 113 114 115 116 117 118 119 120 121 122 123
        <el-form-item label="ID" prop="id">
          <el-input v-model="memberForm.id" autocomplete="off" :disabled="true"/>
        </el-form-item>
        <el-form-item :label="$t('commons.username')" prop="name">
          <el-input v-model="memberForm.name" autocomplete="off"/>
        </el-form-item>
        <el-form-item :label="$t('commons.email')" prop="email">
          <el-input v-model="memberForm.email" autocomplete="off"/>
        </el-form-item>
        <el-form-item :label="$t('commons.phone')" prop="phone">
          <el-input v-model="memberForm.phone" autocomplete="off"/>
        </el-form-item>
        <el-form-item :label="$t('commons.role')" prop="roleIds">
C
Captain.B 已提交
124 125
          <el-select v-model="memberForm.roleIds" multiple :placeholder="$t('role.please_choose_role')"
                     class="select-width">
126 127 128 129 130 131 132 133 134
            <el-option
              v-for="item in memberForm.allroles"
              :key="item.id"
              :label="item.name"
              :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
C
chenjianxing 已提交
135
      <template v-slot:footer>
S
shiziyuan9527 已提交
136 137 138
        <ms-dialog-footer
          @cancel="dialogWsMemberUpdateVisible = false"
          @confirm="updateOrgMember('updateUserForm')"/>
C
chenjianxing 已提交
139
      </template>
140 141
    </el-dialog>

142 143 144 145
  </div>
</template>

<script>
S
shiziyuan9527 已提交
146
  import MsCreateBox from "../CreateBox";
147
  import {Message} from "element-ui";
C
Captain.B 已提交
148
  import {TokenKey} from "../../../../common/js/constants";
S
shiziyuan9527 已提交
149
  import MsTablePagination from "../../common/pagination/TablePagination";
C
Captain.B 已提交
150
  import MsTableHeader from "../../common/components/MsTableHeader";
S
shiziyuan9527 已提交
151
  import MsRolesTag from "../../common/components/MsRolesTag";
S
shiziyuan9527 已提交
152
  import MsTableOperator from "../../common/components/MsTableOperator";
S
shiziyuan9527 已提交
153
  import MsDialogFooter from "../../common/components/MsDialogFooter";
154 155

  export default {
S
shiziyuan9527 已提交
156
    name: "MsOrganizationWorkspace",
S
shiziyuan9527 已提交
157
    components: {MsCreateBox, MsTablePagination, MsTableHeader, MsRolesTag, MsTableOperator, MsDialogFooter},
158 159 160
    mounted() {
      this.list();
    },
161 162
    computed: {
      currentUser: () => {
C
Captain.B 已提交
163
        let user = localStorage.getItem(TokenKey);
164 165 166
        return JSON.parse(user);
      }
    },
167 168
    methods: {
      create() {
S
shiziyuan9527 已提交
169
        this.dialogWsAddVisible = true;
170 171 172 173 174 175 176 177 178 179
        this.form = {};
      },
      submit(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            let saveType = 'add';
            if (this.form.id) {
              saveType = 'update'
            }
            this.$post("/workspace/" + saveType, this.form, () => {
S
shiziyuan9527 已提交
180
              this.dialogWsAddVisible = false;
181
              this.list();
S
shiziyuan9527 已提交
182
              Message.success(this.$t('commons.save_success'));
183 184 185 186 187 188 189
            });
          } else {
            return false;
          }
        });
      },
      edit(row) {
S
shiziyuan9527 已提交
190
        this.dialogWsAddVisible = true;
S
shiziyuan9527 已提交
191
        this.form = Object.assign({}, row);
192 193
      },
      del(row) {
S
shiziyuan9527 已提交
194 195 196
        this.$confirm(this.$t('workspace.delete_confirm'), '', {
          confirmButtonText: this.$t('commons.confirm'),
          cancelButtonText: this.$t('commons.cancel'),
197 198 199
          type: 'warning'
        }).then(() => {
          this.$get('/workspace/delete/' + row.id, () => {
S
shiziyuan9527 已提交
200
            this.$success(this.$t('commons.delete_success'));
201 202 203 204 205 206 207 208
            this.list();
          });
        }).catch(() => {

        });
      },
      list() {
        let url = '/workspace/list/' + this.currentPage + '/' + this.pageSize;
209 210 211 212
        let lastOrganizationId = this.currentUser.lastOrganizationId;
        let userRole = this.currentUser.userRoles.filter(r => r.sourceId === lastOrganizationId);
        if (userRole.length > 0) {
          if (userRole[0].roleId === "org_admin") {
C
Captain.B 已提交
213
            this.result = this.$post(url, this.condition, response => {
214 215
              let data = response.data;
              this.items = data.listObject;
216 217 218 219 220
              for (let i = 0; i < this.items.length; i++) {
                let param = {
                  name: '',
                  workspaceId: this.items[i].id
                }
S
shiziyuan9527 已提交
221
                let path = "user/ws/member/list/all";
222 223 224 225 226
                this.$post(path, param, res => {
                  let member = res.data;
                  this.$set(this.items[i], "memberSize", member.length);
                })
              }
227 228 229 230 231 232 233 234
              this.total = data.itemCount;
            });
          } else {
            this.items = [];
            this.total = 0;
          }
        }

235
      },
236
      addMember() {
S
shiziyuan9527 已提交
237
        this.dialogWsMemberAddVisible = true;
238 239 240 241 242 243 244 245
        this.memberForm = {};
        this.result = this.$get('/user/list/', response => {
          this.$set(this.memberForm, "userList", response.data);
        });
        this.result = this.$get('/role/list/test', response => {
          this.$set(this.memberForm, "roles", response.data);
        })
      },
C
Captain.B 已提交
246
      cellClick(row) {
247 248
        // 保存当前点击的组织信息到currentRow
        this.currentWorkspaceRow = row;
S
shiziyuan9527 已提交
249
        this.dialogWsMemberVisible = true;
250 251 252 253
        let param = {
          name: '',
          workspaceId: row.id
        };
S
shiziyuan9527 已提交
254
        let path = "/user/ws/member/list";
255 256 257 258 259 260 261 262 263 264 265
        this.result = this.$post(this.buildPagePath(path), param, res => {
          let data = res.data;
          this.memberLineData = data.listObject;
          let url = "/userrole/list/ws/" + row.id;
          // 填充角色信息
          for (let i = 0; i < this.memberLineData.length; i++) {
            this.$get(url + "/" + this.memberLineData[i].id, response => {
              let roles = response.data;
              this.$set(this.memberLineData[i], "roles", roles);
            })
          }
S
shiziyuan9527 已提交
266
          this.dialogTotal = data.itemCount;
267 268
        });
      },
S
shiziyuan9527 已提交
269
      dialogSearch() {
S
shiziyuan9527 已提交
270
        let row = this.currentWorkspaceRow;
S
shiziyuan9527 已提交
271
        this.dialogWsMemberVisible = true;
S
shiziyuan9527 已提交
272 273
        let param = this.dialogCondition;
        this.$set(param, 'workspaceId', row.id);
S
shiziyuan9527 已提交
274 275 276 277 278 279 280 281 282 283 284 285
        let path = "/user/ws/member/list";
        this.result = this.$post(this.buildPagePath(path), param, res => {
          let data = res.data;
          this.memberLineData = data.listObject;
          let url = "/userrole/list/ws/" + row.id;
          // 填充角色信息
          for (let i = 0; i < this.memberLineData.length; i++) {
            this.$get(url + "/" + this.memberLineData[i].id, response => {
              let roles = response.data;
              this.$set(this.memberLineData[i], "roles", roles);
            })
          }
S
shiziyuan9527 已提交
286
          this.dialogTotal = data.itemCount;
S
shiziyuan9527 已提交
287 288
        });
      },
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303
      closeFunc() {
        this.form = {};
      },
      closeMemberFunc() {
        this.memberLineData = [];
        this.list();
      },
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            let param = {
              userIds: this.memberForm.userIds,
              roleIds: this.memberForm.roleIds,
              workspaceId: this.currentWorkspaceRow.id
            };
C
Captain.B 已提交
304
            this.result = this.$post("user/ws/member/add", param, () => {
305
              this.cellClick(this.currentWorkspaceRow);
S
shiziyuan9527 已提交
306
              this.dialogWsMemberAddVisible = false;
307 308 309 310 311 312 313
            })
          } else {
            return false;
          }
        });
      },
      editMember(row) {
S
shiziyuan9527 已提交
314
        this.dialogWsMemberUpdateVisible = true;
S
shiziyuan9527 已提交
315
        this.memberForm = Object.assign({}, row);
316 317 318 319 320 321 322 323 324 325 326 327 328
        let roleIds = this.memberForm.roles.map(r => r.id);
        this.result = this.$get('/role/list/test', response => {
          this.$set(this.memberForm, "allroles", response.data);
        })
        // 编辑时填充角色信息
        this.$set(this.memberForm, 'roleIds', roleIds);
      },
      delMember(row) {
        this.$confirm(this.$t('member.delete_confirm'), '', {
          confirmButtonText: this.$t('commons.confirm'),
          cancelButtonText: this.$t('commons.cancel'),
          type: 'warning'
        }).then(() => {
S
shiziyuan9527 已提交
329
          this.result = this.$get('/user/ws/member/delete/' + this.currentWorkspaceRow.id + '/' + row.id, () => {
S
shiziyuan9527 已提交
330
            this.$success(this.$t('commons.delete_success'));
331 332 333
            this.cellClick(this.currentWorkspaceRow);
          });
        }).catch(() => {
S
shiziyuan9527 已提交
334
          this.$info(this.$t('commons.delete_cancel'));
335 336 337 338 339 340 341 342 343 344 345
        });
      },
      updateOrgMember() {
        let param = {
          id: this.memberForm.id,
          name: this.memberForm.name,
          email: this.memberForm.email,
          phone: this.memberForm.phone,
          roleIds: this.memberForm.roleIds,
          workspaceId: this.currentWorkspaceRow.id
        }
C
Captain.B 已提交
346
        this.result = this.$post("/workspace/member/update", param, () => {
S
shiziyuan9527 已提交
347
          this.$success(this.$t('commons.modify_success'));
S
shiziyuan9527 已提交
348
          this.dialogWsMemberUpdateVisible = false;
349 350 351 352
          this.cellClick(this.currentWorkspaceRow);
        });
      },
      buildPagePath(path) {
S
shiziyuan9527 已提交
353
        return path + "/" + this.dialogCurrentPage + "/" + this.dialogPageSize;
354
      },
355 356 357 358
    },
    data() {
      return {
        result: {},
S
shiziyuan9527 已提交
359 360 361 362
        dialogWsAddVisible: false,
        dialogWsMemberVisible: false,
        dialogWsMemberAddVisible: false,
        dialogWsMemberUpdateVisible: false,
S
shiziyuan9527 已提交
363 364
        btnTips: this.$t('workspace.create'),
        dialogBtnTips: this.$t('member.create'),
365
        addTips: this.$t('member.create'),
C
Captain.B 已提交
366
        condition: {},
S
shiziyuan9527 已提交
367
        dialogCondition: {},
368 369 370 371
        items: [],
        currentPage: 1,
        pageSize: 5,
        total: 0,
S
shiziyuan9527 已提交
372 373 374
        dialogCurrentPage: 1,
        dialogPageSize: 5,
        dialogTotal: 0,
375 376
        memberLineData: [],
        memberForm: {},
377 378 379 380 381 382
        form: {
          // name: "",
          // description: ""
        },
        rules: {
          name: [
S
shiziyuan9527 已提交
383 384
            {required: true, message: this.$t('workspace.input_name'), trigger: 'blur'},
            {min: 2, max: 50, message: this.$t('commons.input_limit', [2, 50]), trigger: 'blur'}
385 386
          ]
        },
387 388 389 390 391 392 393 394 395
        wsMemberRule: {
          userIds: [
            {required: true, message: this.$t('member.please_choose_member'), trigger: ['blur']}
          ],
          roleIds: [
            {required: true, message: this.$t('role.please_choose_role'), trigger: ['blur']}
          ]
        },
        currentWorkspaceRow: {},
396 397 398 399 400 401 402 403 404 405 406
      }
    }
  }
</script>

<style scoped>

  .el-table__row:hover .edit {
    opacity: 1;
  }

407
  .member-size {
C
Captain.B 已提交
408 409
    text-decoration: underline;
    cursor: pointer;
410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425
  }

  .select-width {
    width: 100%;
  }

  .ws-member-name {
    float: left;
  }

  .ws-member-email {
    float: right;
    color: #8492a6;
    font-size: 13px;
  }

426 427
</style>