OrganizationWorkspace.vue 15.9 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 20 21 22
            <el-button @click="edit(scope.row)" @keydown.enter.native.prevent type="primary" icon="el-icon-edit"
                       size="mini" circle/>
            <el-button @click="del(scope.row)" @keydown.enter.native.prevent type="danger" icon="el-icon-delete"
                       size="mini" circle/>
23 24 25
          </template>
        </el-table-column>
      </el-table>
S
shiziyuan9527 已提交
26 27
      <ms-table-pagination :change="list" :current-page.sync="currentPage" :page-size.sync="pageSize"
                           :total="total"/>
28 29
    </el-card>

S
shiziyuan9527 已提交
30
    <el-dialog :title="$t('workspace.create')" :visible.sync="dialogWsAddVisible" width="30%">
31
      <el-form :model="form" :rules="rules" ref="form" label-position="right" label-width="100px" size="small">
S
shiziyuan9527 已提交
32
        <el-form-item :label="$t('commons.name')" prop="name">
33 34
          <el-input v-model="form.name" autocomplete="off"/>
        </el-form-item>
S
shiziyuan9527 已提交
35
        <el-form-item :label="$t('commons.description')">
36 37 38
          <el-input type="textarea" v-model="form.description"></el-input>
        </el-form-item>
      </el-form>
C
chenjianxing 已提交
39 40
      <template v-slot:footer>
        <span class="dialog-footer">
S
shiziyuan9527 已提交
41 42 43
          <el-button @click="submit('form')" @keydown.enter.native.prevent type="primary"
                     size="medium">{{$t('commons.save')}}
          </el-button>
C
chenjianxing 已提交
44 45
        </span>
      </template>
46
    </el-dialog>
47 48

    <!-- dialog of workspace member -->
S
shiziyuan9527 已提交
49
    <el-dialog :visible.sync="dialogWsMemberVisible" width="70%" :destroy-on-close="true" @close="closeMemberFunc">
S
shiziyuan9527 已提交
50
      <ms-table-header :condition.sync="dialogCondition" @create="addMember" @search="dialogSearch"
S
shiziyuan9527 已提交
51
                       :create-tip="dialogBtnTips" :title="$t('commons.member')"/>
52
      <!-- organization member table -->
S
shiziyuan9527 已提交
53
      <el-table :data="memberLineData" style="width: 100%;margin-top: 5px;">
54 55 56 57
        <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 已提交
58
          <template v-slot:default="scope">
S
shiziyuan9527 已提交
59
            <ms-roles-tag :roles="scope.row.roles" type="success"/>
60 61 62
          </template>
        </el-table-column>
        <el-table-column :label="$t('commons.operating')">
C
v-slot  
Captain.B 已提交
63
          <template v-slot:default="scope">
S
shiziyuan9527 已提交
64
            <el-button @click="editMember(scope.row)" @keydown.enter.native.prevent type="primary" icon="el-icon-edit"
C
Captain.B 已提交
65
                       size="mini" circle/>
S
shiziyuan9527 已提交
66
            <el-button @click="delMember(scope.row)" @keydown.enter.native.prevent type="danger" icon="el-icon-delete"
C
Captain.B 已提交
67
                       size="mini" circle/>
68 69 70
          </template>
        </el-table-column>
      </el-table>
S
shiziyuan9527 已提交
71 72
      <ms-table-pagination :change="dialogSearch" :current-page.sync="dialogCurrentPage"
                           :page-size.sync="dialogPageSize"
S
shiziyuan9527 已提交
73
                           :total="dialogTotal"/>
74 75 76
    </el-dialog>

    <!-- add workspace member dialog -->
S
shiziyuan9527 已提交
77 78
    <el-dialog :title="$t('member.create')" :visible.sync="dialogWsMemberAddVisible" width="30%"
               :destroy-on-close="true"
C
Captain.B 已提交
79 80 81
               @close="closeFunc">
      <el-form :model="memberForm" ref="form" :rules="wsMemberRule" label-position="right" label-width="100px"
               size="small">
82
        <el-form-item :label="$t('commons.member')" prop="userIds">
C
Captain.B 已提交
83 84
          <el-select v-model="memberForm.userIds" multiple :placeholder="$t('member.please_choose_member')"
                     class="select-width">
85 86 87 88 89 90 91 92 93 94 95
            <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 已提交
96 97
          <el-select v-model="memberForm.roleIds" multiple :placeholder="$t('role.please_choose_role')"
                     class="select-width">
98 99 100 101 102 103 104 105 106
            <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 已提交
107 108
      <template v-slot:footer>
        <span class="dialog-footer">
S
shiziyuan9527 已提交
109 110 111
          <el-button @click="submitForm('form')" @keydown.enter.native.prevent type="primary"
                     size="medium">{{$t('commons.save')}}
          </el-button>
C
chenjianxing 已提交
112 113
        </span>
      </template>
114 115 116
    </el-dialog>

    <!-- update workspace member dialog -->
S
shiziyuan9527 已提交
117 118
    <el-dialog :title="$t('member.modify')" :visible.sync="dialogWsMemberUpdateVisible" width="30%"
               :destroy-on-close="true"
C
Captain.B 已提交
119
               @close="closeFunc">
120
      <el-form :model="memberForm" label-position="right" label-width="100px" size="small" ref="updateUserForm">
121 122 123 124 125 126 127 128 129 130 131 132 133
        <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 已提交
134 135
          <el-select v-model="memberForm.roleIds" multiple :placeholder="$t('role.please_choose_role')"
                     class="select-width">
136 137 138 139 140 141 142 143 144
            <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 已提交
145 146
      <template v-slot:footer>
        <span class="dialog-footer">
S
shiziyuan9527 已提交
147 148 149
          <el-button @click="updateOrgMember('updateUserForm')" @keydown.enter.native.prevent type="primary"
                     size="medium">{{$t('commons.save')}}
          </el-button>
C
chenjianxing 已提交
150 151
        </span>
      </template>
152 153
    </el-dialog>

154 155 156 157
  </div>
</template>

<script>
S
shiziyuan9527 已提交
158
  import MsCreateBox from "../CreateBox";
159
  import {Message} from "element-ui";
C
Captain.B 已提交
160
  import {TokenKey} from "../../../../common/js/constants";
S
shiziyuan9527 已提交
161
  import MsTablePagination from "../../common/pagination/TablePagination";
C
Captain.B 已提交
162
  import MsTableHeader from "../../common/components/MsTableHeader";
S
shiziyuan9527 已提交
163
  import MsRolesTag from "../../common/components/MsRolesTag";
164 165

  export default {
S
shiziyuan9527 已提交
166
    name: "MsOrganizationWorkspace",
S
shiziyuan9527 已提交
167
    components: {MsCreateBox, MsTablePagination, MsTableHeader, MsRolesTag},
168 169 170
    mounted() {
      this.list();
    },
171 172
    computed: {
      currentUser: () => {
C
Captain.B 已提交
173
        let user = localStorage.getItem(TokenKey);
174 175 176
        return JSON.parse(user);
      }
    },
177 178
    methods: {
      create() {
S
shiziyuan9527 已提交
179
        this.dialogWsAddVisible = true;
180 181 182 183 184 185 186 187 188 189
        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 已提交
190
              this.dialogWsAddVisible = false;
191
              this.list();
S
shiziyuan9527 已提交
192
              Message.success(this.$t('commons.save_success'));
193 194 195 196 197 198 199
            });
          } else {
            return false;
          }
        });
      },
      edit(row) {
S
shiziyuan9527 已提交
200
        this.dialogWsAddVisible = true;
201 202 203
        this.form = row;
      },
      del(row) {
S
shiziyuan9527 已提交
204 205 206
        this.$confirm(this.$t('workspace.delete_confirm'), '', {
          confirmButtonText: this.$t('commons.confirm'),
          cancelButtonText: this.$t('commons.cancel'),
207 208 209
          type: 'warning'
        }).then(() => {
          this.$get('/workspace/delete/' + row.id, () => {
S
shiziyuan9527 已提交
210
            this.$success(this.$t('commons.delete_success'));
211 212 213 214 215 216 217 218
            this.list();
          });
        }).catch(() => {

        });
      },
      list() {
        let url = '/workspace/list/' + this.currentPage + '/' + this.pageSize;
219 220 221 222
        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 已提交
223
            this.result = this.$post(url, this.condition, response => {
224 225
              let data = response.data;
              this.items = data.listObject;
226 227 228 229 230
              for (let i = 0; i < this.items.length; i++) {
                let param = {
                  name: '',
                  workspaceId: this.items[i].id
                }
S
shiziyuan9527 已提交
231
                let path = "user/ws/member/list/all";
232 233 234 235 236
                this.$post(path, param, res => {
                  let member = res.data;
                  this.$set(this.items[i], "memberSize", member.length);
                })
              }
237 238 239 240 241 242 243 244
              this.total = data.itemCount;
            });
          } else {
            this.items = [];
            this.total = 0;
          }
        }

245
      },
246
      addMember() {
S
shiziyuan9527 已提交
247
        this.dialogWsMemberAddVisible = true;
248 249 250 251 252 253 254 255
        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 已提交
256
      cellClick(row) {
257 258
        // 保存当前点击的组织信息到currentRow
        this.currentWorkspaceRow = row;
S
shiziyuan9527 已提交
259
        this.dialogWsMemberVisible = true;
260 261 262 263
        let param = {
          name: '',
          workspaceId: row.id
        };
S
shiziyuan9527 已提交
264
        let path = "/user/ws/member/list";
265 266 267 268 269 270 271 272 273 274 275
        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 已提交
276
          this.dialogTotal = data.itemCount;
277 278
        });
      },
S
shiziyuan9527 已提交
279
      dialogSearch() {
S
shiziyuan9527 已提交
280
        let row = this.currentWorkspaceRow;
S
shiziyuan9527 已提交
281
        this.dialogWsMemberVisible = true;
S
shiziyuan9527 已提交
282 283
        let param = this.dialogCondition;
        this.$set(param, 'workspaceId', row.id);
S
shiziyuan9527 已提交
284 285 286 287 288 289 290 291 292 293 294 295
        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 已提交
296
          this.dialogTotal = data.itemCount;
S
shiziyuan9527 已提交
297 298
        });
      },
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313
      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 已提交
314
            this.result = this.$post("user/ws/member/add", param, () => {
315
              this.cellClick(this.currentWorkspaceRow);
S
shiziyuan9527 已提交
316
              this.dialogWsMemberAddVisible = false;
317 318 319 320 321 322 323
            })
          } else {
            return false;
          }
        });
      },
      editMember(row) {
S
shiziyuan9527 已提交
324
        this.dialogWsMemberUpdateVisible = true;
325 326 327 328 329 330 331 332 333 334 335 336 337 338
        this.memberForm = row;
        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 已提交
339
          this.result = this.$get('/user/ws/member/delete/' + this.currentWorkspaceRow.id + '/' + row.id, () => {
S
shiziyuan9527 已提交
340
            this.$success(this.$t('commons.delete_success'));
341 342 343
            this.cellClick(this.currentWorkspaceRow);
          });
        }).catch(() => {
S
shiziyuan9527 已提交
344
          this.$info(this.$t('commons.delete_cancel'));
345 346 347 348 349 350 351 352 353 354 355
        });
      },
      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 已提交
356
        this.result = this.$post("/workspace/member/update", param, () => {
S
shiziyuan9527 已提交
357
          this.$success(this.$t('commons.modify_success'));
S
shiziyuan9527 已提交
358
          this.dialogWsMemberUpdateVisible = false;
359 360 361 362
          this.cellClick(this.currentWorkspaceRow);
        });
      },
      buildPagePath(path) {
S
shiziyuan9527 已提交
363
        return path + "/" + this.dialogCurrentPage + "/" + this.dialogPageSize;
364
      },
365 366 367 368
    },
    data() {
      return {
        result: {},
S
shiziyuan9527 已提交
369 370 371 372
        dialogWsAddVisible: false,
        dialogWsMemberVisible: false,
        dialogWsMemberAddVisible: false,
        dialogWsMemberUpdateVisible: false,
S
shiziyuan9527 已提交
373 374
        btnTips: this.$t('workspace.create'),
        dialogBtnTips: this.$t('member.create'),
375
        addTips: this.$t('member.create'),
C
Captain.B 已提交
376
        condition: {},
S
shiziyuan9527 已提交
377
        dialogCondition: {},
378 379 380 381
        items: [],
        currentPage: 1,
        pageSize: 5,
        total: 0,
S
shiziyuan9527 已提交
382 383 384
        dialogCurrentPage: 1,
        dialogPageSize: 5,
        dialogTotal: 0,
385 386
        memberLineData: [],
        memberForm: {},
387 388 389 390 391 392
        form: {
          // name: "",
          // description: ""
        },
        rules: {
          name: [
S
shiziyuan9527 已提交
393 394
            {required: true, message: this.$t('workspace.input_name'), trigger: 'blur'},
            {min: 2, max: 50, message: this.$t('commons.input_limit', [2, 50]), trigger: 'blur'}
395 396
          ]
        },
397 398 399 400 401 402 403 404 405
        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: {},
406 407 408 409 410 411 412 413 414 415 416
      }
    }
  }
</script>

<style scoped>

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

417
  .member-size {
C
Captain.B 已提交
418 419
    text-decoration: underline;
    cursor: pointer;
420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435
  }

  .select-width {
    width: 100%;
  }

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

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

436 437
</style>