小小儁爺
2025-03-06 e9a02d180b91ee7a383d25d5e19853630026b4b1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
<template>
  <div>
    <div class="body" :style="{height:mainHeight+'px'}">
      <div class="bodyTopButtonGroup" style="justify-content: space-between">
        <el-button v-waves type="primary" icon="el-icon-circle-plus-outline" @click="add('add')">新增</el-button>
        <el-button v-waves type="success" icon="el-icon-download" @click="$router.push('./../systemSetting/dataImport?fileCode=4')">导入</el-button>
      </div>
 
      <div class="bodyTopFormGroup">
        <el-form
          ref="form"
          :model="form"
          label-width="100px"
          inline
          style="display: flex;"
        >
          <div class="elForm">
            <el-form-item label="角色编码" style=" display: flex;">
              <el-input v-model="form.role_code" placeholder="请输入" style="width: 200px" />
            </el-form-item>
            <el-form-item label="角色名称" style=" display: flex;">
              <el-input v-model="form.role_name" placeholder="请输入" style="width: 200px" />
            </el-form-item>
          </div>
          <div
            class="bodySearchReset"
            :style="{marginLeft:$store.state.app.sidebar.opened? $store.state.settings.menuIsHorizontal?'15%':'3%':'10%'}"
          >
            <el-button v-waves type="primary" icon="el-icon-search" @click="getRoleData">查询</el-button>
            <el-button v-waves type="info" icon="el-icon-refresh" @click="reset">重置</el-button>
          </div>
        </el-form>
        <div
          class="bodyTopFormExpand"
          style="height:5px"
        >
          <!--          <svg-icon-->
          <!--            v-show="mouseHoverType==='mouseout'"-->
          <!--            style="cursor: pointer"-->
          <!--            :icon-class="!isExpandForm?'doubleDown3':'doubleUp3'"-->
          <!--            @mouseenter="mouseHoverType=$event.type"-->
          <!--          />-->
          <!--          <svg-icon-->
          <!--            v-show="mouseHoverType==='mouseenter'"-->
          <!--            style="cursor: pointer"-->
          <!--            :icon-class="!isExpandForm?'doubleDown':'doubleUp'"-->
          <!--            @click="isExpandForm=!isExpandForm"-->
          <!--            @mouseout="mouseHoverType=$event.type"-->
          <!--          />-->
        </div>
      </div>
 
      <div class="elTableDiv">
        <el-table
          ref="tableDataRef"
          class="tableFixed"
          :data="tableData"
          :height="tableHeight+'px'"
          border
          row-class-name="custom-row"
          :style="{width: 100+'%',height:tableHeight+'px',}"
          highlight-current-row
          :header-cell-style="this.$headerCellStyle"
          :cell-style="this.$cellStyle"
          @sort-change="sortChange"
        >
          <el-table-column
            prop="rowNum"
            width="120"
            fixed
            label="序号"
          />
          <el-table-column
            prop="rolecode"
            label="角色编码"
            sortable="custom"
          />
          <el-table-column
            prop="rolename"
            label="角色名称"
            sortable="custom"
          />
          <el-table-column
            prop="status"
            label="状态"
            sortable="custom"
          >
            <template slot-scope="{row}">
              <el-tag v-if="row.status==='Y'" size="small" type="success">正常</el-tag>
              <el-tag v-if="row.status==='N'" size="small" type="danger">停用</el-tag>
            </template>
          </el-table-column>
          <!--          <el-table-column-->
          <!--            prop="dataname"-->
          <!--            label="权限范围"-->
          <!--            sortable="custom"-->
          <!--          />-->
          <el-table-column
            prop="description"
            label="备注"
            sortable="custom"
          >
            <template slot-scope="{row}">
              {{ row.description?row.description:'/' }}
            </template>
          </el-table-column>
          <el-table-column
            prop="username"
            label="创建人员"
            sortable="custom"
          />
          <el-table-column
            prop="lm_date"
            label="创建时间"
            width="160"
            sortable="custom"
          />
          <el-table-column
            label="操作"
            width="160"
            fixed="right"
          >
            <template slot-scope="{row}">
              <div class="operationClass">
                <el-tooltip class="item" effect="dark" content="编辑" placement="top">
                  <i
                    class="el-icon-edit-outline"
                    :style="{color:$store.state.settings.theme}"
                    @click="edit('edit',row)"
                  />
                </el-tooltip>
                <el-tooltip v-del-tab-index class="item" effect="dark" content="删除" placement="top">
                  <i
                    class="el-icon-delete"
                    :style="{color:$store.state.settings.theme}"
                    @click="del(row)"
                  />
                </el-tooltip>
 
                <el-dropdown placement="bottom" @command="command=>handleCommand(command,row)">
                  <div
                    class="el-dropdown-link"
                    style="display: flex;align-content: center;
                    justify-content: center;
                    cursor: pointer;"
                    :style="{color:$store.state.settings.theme}"
                  >
                    <div>更多</div>
                    <div>
                      <i class="el-icon-arrow-down el-icon--right" />
                    </div>
                  </div>
                  <el-dropdown-menu slot="dropdown">
                    <el-dropdown-item icon="el-icon-circle-check" command="menuPower">菜单权限</el-dropdown-item>
                    <el-dropdown-item icon="el-icon-user" command="divideUser">分配用户</el-dropdown-item>
                    <!--                    <el-dropdown-item icon="el-icon-download" command="downloadMenu">导出菜单</el-dropdown-item>-->
                  </el-dropdown-menu>
                </el-dropdown>
              </div>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <!--分页-->
      <pagination
        :total="total"
        :page.sync="form.page"
        :limit.sync="form.rows"
        align="right"
        layout="total,prev, pager, next,sizes,jumper"
        popper-class="select_bottom"
        @pagination="getRoleData"
      />
    </div>
 
    <el-dialog
      v-el-drag-dialog
      :title="operation==='add'?'新增':'编辑'"
      :visible.sync="dialogVisible"
      width="800px"
      :close-on-click-modal="false"
      top="15vh"
      @closed="handleClose"
      @close="handleClose"
    >
      <el-form ref="dialogForm" inline :rules="dialogFormRules" :model="dialogForm" label-width="80px">
        <!--        <el-form-item label="角色编码" prop="rolecode">-->
        <!--          <el-input v-model="dialogForm.rolecode" :disabled="operation!=='add'" style="width: 200px" />-->
        <!--        </el-form-item>-->
        <el-form-item label="角色名称" prop="rolename">
          <el-input v-model="dialogForm.rolename" style="width: 200px" />
        </el-form-item>
 
        <!--        <el-form-item required label="数据范围">-->
        <!--          <el-select-->
        <!--            v-model="dialogForm.datacode"-->
        <!--            style="width:200px"-->
        <!--            placeholder="请选择"-->
        <!--            :popper-append-to-body="false"-->
        <!--          >-->
        <!--            <el-option-->
        <!--              v-for="item in datacodeArr"-->
        <!--              :key="item.datacode"-->
        <!--              :label="item.dataname"-->
        <!--              :value="item.datacode"-->
        <!--            />-->
        <!--          </el-select>-->
        <!--        </el-form-item>-->
        <el-form-item required label="状态">
          <el-radio-group v-model="dialogForm.status" style="width: 200px">
            <el-radio label="Y">正常</el-radio>
            <el-radio label="N">停用</el-radio>
          </el-radio-group>
        </el-form-item>
        <!--        <el-form-item v-if="dialogForm.datacode==='CUSTOM'" label="数据权限" style="margin: 0">-->
        <!--          <el-checkbox-group v-model="checkboxGroupSelected" @change="checkboxGroupChange">-->
        <!--            <el-checkbox v-for="item in checkboxGroup" :key="item" :label="item">-->
        <!--              {{ item }}-->
        <!--              <el-tooltip class="item" effect="dark" content="勾选父节点是否同时选中子节点" placement="top">-->
        <!--                <i v-if="item==='父子联动'" class="el-icon-question" />-->
        <!--              </el-tooltip>-->
        <!--            </el-checkbox>-->
        <!--          </el-checkbox-group>-->
        <!--        </el-form-item>-->
        <!--        <el-card-->
        <!--          v-if="dialogForm.datacode==='CUSTOM'"-->
        <!--          class="box-card"-->
        <!--          shadow="never"-->
        <!--          style="margin-bottom: 30px;width: 78%;margin-left: 12%;"-->
        <!--        >-->
 
        <!--          <el-tree-->
        <!--            ref="tree"-->
        <!--            :key="checkboxGroupSelected.toString()"-->
        <!--            :data="treeData"-->
        <!--            show-checkbox-->
        <!--            :check-strictly="!checkboxGroupSelected.includes('父子联动')"-->
        <!--            :default-expand-all="checkboxGroupSelected.includes('展开/折叠')"-->
        <!--            node-key="torg_code"-->
        <!--            :props="defaultProps"-->
        <!--          />-->
        <!--        </el-card>-->
 
        <el-form-item label="备注">
          <el-input v-model="dialogForm.description" type="textarea" style="width:500px" />
        </el-form-item>
 
      </el-form>
      <span slot="footer" class="dialog-footer">
        <div class="footerButton">
          <el-button v-waves @click="dialogVisibleCancel">取 消</el-button>
          <el-button
            v-waves
            type="primary"
            :loading="$store.state.app.buttonIsDisabled"
            :disabled="$store.state.app.buttonIsDisabled"
            @click="dialogVisibleConfirm"
          >确 定</el-button>
        </div>
      </span>
    </el-dialog>
 
  </div>
</template>
 
<script>
import Pagination from '@/components/Pagination'
import {
  AddUpdateGroup,
  DeleteGroup, RoleAddUpdateSava,
  RoleData, RoleDeleteSava
} from '@/api/basicSettings'
import { validateCode } from '@/utils/global'
import elDragDialog from '@/directive/el-drag-dialog'
import waves from '@/directive/waves'
import { DataPermissions, PrentOrganization } from '@/api/GeneralBasicData'
import arrayToTree from 'array-to-tree'
 
export default {
  name: 'RoleList',
  components: {
    Pagination
  },
  directives: { elDragDialog, waves },
  data() {
    return {
      mainHeight: 0,
      tableHeight: 0,
      form: {
        role_code: '',
        role_name: '',
        prop: 'lm_date', // 排序字段
        order: 'desc', // 排序字段
        page: 1, // 第几页
        rows: 20 // 每页多少条
      },
      total: 10,
      tableData: [],
      dialogVisible: false,
      dialogForm: {
        rolecode: '', //
        rolename: '', //
        datacode: 'ALL',
        description: '',
        datapermissions: '', // 数据权限
        status: 'Y'// 状态
      },
      datacodeArr: [],
      checkboxGroupSelected: ['展开/折叠', '父子联动'],
      checkboxGroup: ['展开/折叠', '全选/全不选', '父子联动'],
      operation: '',
      dialogFormRules: {
        rolecode: [
          { required: true, validator: validateCode, trigger: ['blur', 'change'] }
        ],
        rolename: [
          { required: true, message: '请输入组织名称', trigger: ['blur', 'change'] }
        ]
      },
      defaultProps: {
        children: 'children',
        label: 'torg_name'
      },
      treeData: []
 
    }
  },
  activated() {   window.addEventListener('resize', this.getHeight)   this.getHeight() }, created() {
    this.getRoleData()
  },
  mounted() {
    window.addEventListener('resize', this.getHeight)
    this.getHeight()
 
    this.getPrentOrganization()
    this.getDataPermissions()
  },
  methods: {
    async getRoleData() {
      const res = await RoleData(this.form)
      this.tableData = res.data
      this.total = res.count
    },
    async getDataPermissions() {
      const { data: res } = await DataPermissions()
      this.datacodeArr = res
    },
    // 组织架构级联选择器
    async getPrentOrganization() {
      const { data: res } = await PrentOrganization()
      this.treeData = arrayToTree(res, {
        parentProperty: 'parent_id',
        customID: 'torg_code',
        childrenProperty: 'children'
      })
    },
    // 排序改变时
    sortChange({ column, prop, order }) {
      if (order === 'descending') {
        order = 'desc'
      } else if (order === 'ascending') {
        order = 'asc'
      } else {
        order = 'desc'
      }
      this.form.order = order
      this.form.prop = prop
      this.getRoleData()
    },
    // 重置
    reset() {
      this.form.role_code = ''
      this.form.role_name = ''
      this.getRoleData()
    },
    // 新增按钮
    add(operation) {
      this.operation = operation
      this.dialogVisible = true
      this.dialogForm.OperType = 'Add'
    },
    // 修改按钮
    async edit(operation, row) {
      this.operation = operation
      this.dialogVisible = true
      this.dialogForm.OperType = 'Update'
      this.$nextTick(() => {
        this.dialogForm.rolecode = row.rolecode
        this.dialogForm.rolename = row.rolename
        this.dialogForm.datacode = row.datacode
        this.dialogForm.status = row.status
        this.dialogForm.description = row.description
        if (this.dialogForm.datacode === 'CUSTOM') {
          setTimeout(() => {
            this.$refs.tree.setCheckedKeys(row.datapermissionscode.split(','))
          })
        }
      })
    },
    // 删除按钮
    async del(row) {
      this.$confirm('是否确认删除?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        RoleDeleteSava({ rolecode: row.rolecode }).then(res => {
          if (res.code === '200') {
            this.$notify.success('删除成功!')
            if (this.form.page > 1 && this.tableData.length === 1) {
              this.form.page--
            }
            this.getRoleData()
          }
        })
      }).catch(() => {
        this.$notify.info('已取消删除')
      })
    },
    checkboxGroupChange(val) {
      if (val.includes('全选/全不选')) {
        this.$refs.tree.setCheckedKeys([this.treeData[0].torg_code])
      }
    },
    // 对话框关闭事件
    handleClose() {
      this.dialogForm.rolecode = ''
      this.dialogForm.rolename = ''
      this.dialogForm.description = ''
      this.dialogForm.datapermissions = ''
      this.dialogForm.datacode = 'ALL'
      this.dialogForm.status = 'Y'
      this.$refs.dialogForm.clearValidate()
    },
    // 对话框取消
    dialogVisibleCancel() {
      this.dialogVisible = false
    },
    // 对话框确认
    dialogVisibleConfirm() {
      this.$refs.dialogForm.validate(valid => {
        if (valid) {
          this.$store.state.app.buttonIsDisabled = true
          if (this.$refs.tree) {
            this.dialogForm.datapermissions = this.$refs.tree.getCheckedKeys().join(',')
          }
          RoleAddUpdateSava(this.dialogForm).then(res => {
            if (res.code === '200') {
              this.$notify.success(this.operation === 'add' ? '添加成功!' : '修改成功!')
              this.dialogVisible = false
              this.$store.state.app.buttonIsDisabled = false
              this.getRoleData()
            } else {
              this.$store.state.app.buttonIsDisabled = false
              this.$notify.error(this.operation === 'add' ? '添加失败!' : '修改失败!')
            }
          })
        }
      })
    },
    handleCommand(command, row) {
      console.log(command, row)
      if (command === 'menuPower') {
        this.$router.push('./powerDivider?rolecode=' + row.rolecode)
      }
      if (command === 'divideUser') {
        this.$router.push('./roleDivider?rolecode=' + row.rolecode)
      }
    },
    // 获取页面高度
    getHeight() {
      this.$nextTick(() => {
        this.mainHeight = window.innerHeight - 85
        this.tableHeight = this.mainHeight - 200
        this.$refs.tableDataRef.doLayout()
      })
    }
  }
}
</script>