yanjinhui
10 天以前 c5de0d98241f8c8349fa38851b77efcfc61e4d26
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
<script setup>
import { reactive, ref, unref, onMounted, toRef } from 'vue'
import { GetPageDataApi } from '@/api/department'
import { AddRoleApi, UpdateRoleApi, StatusChangeApiApi, SaveRoleApi,DeleteRoleApi} from '@/api/role'
import { ElMessage, ElMessageBox } from 'element-plus'
import { ContentWrap } from '@/components/ContentWrap'
import { formatTime } from '@/utils/index'
const obj = {
  selectName: '',
 
  selectTime: [], // 时间范围
  selectType: '',
  selectInput: ''
}
 
const grideData = ref([])
const userInfo = ref('')
//分组
const groupOptions = ref([])
 
//用户角色新建
const dialogVisible2 = ref(false)
const rolekey = ref([
  { value: 1, label: '一级' },
  { value: 0, label: '二级' }
])
const pageTotal = ref(0)
const formRoleRef = ref()
const roleRules = reactive({
  roleName: {
    required: true,
    message: '请输入角色名称',
    trigger: 'blur'
  },
  description: {
    required: true,
    message: '请输入角色描述',
    trigger: 'blur'
  }
})
const formRole = ref({
  roleName: '',
  description: '',
  createDate: formatTime(new Date()), //创建时间
  creater: JSON.parse(localStorage.getItem('user')).userName, //创建人
  isLeader: 0 //组员类型
})
const roles = ref(
  '[{"id":10,"actions":[{"text":"查询","value":"Search"},{"text":"新建","value":"Add"},{"text":"删除","value":"Delete"},{"text":"编辑","value":"Update"},{"text":"导入","value":"Import"},{"text":"导出","value":"Export"}]},{"id":12,"actions":[{"text":"查询","value":"Search"},{"text":"新建","value":"Add"},{"text":"删除","value":"Delete"},{"text":"编辑","value":"Update"},{"text":"导入","value":"Import"},{"text":"导出","value":"Export"}]},{"id":17,"actions":[{"text":"查询","value":"Search"},{"text":"新建","value":"Add"},{"text":"删除","value":"Delete"},{"text":"编辑","value":"Update"},{"text":"导入","value":"Import"},{"text":"导出","value":"Export"}]},{"id":1,"actions":[{"text":"查询","value":"Search"},{"text":"新建","value":"Add"},{"text":"删除","value":"Delete"},{"text":"编辑","value":"Update"},{"text":"导入","value":"Import"},{"text":"导出","value":"Export"}]},{"id":2,"actions":[{"text":"查询","value":"Search"},{"text":"新建","value":"Add"},{"text":"删除","value":"Delete"},{"text":"编辑","value":"Update"},{"text":"导入","value":"Import"},{"text":"导出","value":"Export"}]},{"id":3,"actions":[{"text":"查询","value":"Search"},{"text":"新建","value":"Add"},{"text":"删除","value":"Delete"},{"text":"编辑","value":"Update"},{"text":"导入","value":"Import"},{"text":"导出","value":"Export"}]},{"id":4,"actions":[{"text":"查询","value":"Search"},{"text":"新建","value":"Add"},{"text":"删除","value":"Delete"},{"text":"编辑","value":"Update"},{"text":"导入","value":"Import"},{"text":"导出","value":"Export"}]},{"id":18,"actions":[{"text":"查询","value":"Search"},{"text":"新建","value":"Add"},{"text":"删除","value":"Delete"},{"text":"编辑","value":"Update"},{"text":"查看全部路由","value":"ViewAllRouter"},{"text":"路由配置","value":"AddRouters"},{"text":"导入","value":"Import"},{"text":"导出","value":"Export"}]},{"id":13,"actions":[{"text":"查询","value":"Search"},{"text":"新建","value":"Add"},{"text":"回滚到上一步","value":"Previous"},{"text":"跳转到下一步","value":"Next"},{"text":"删除","value":"Delete"},{"text":"编辑","value":"Update"},{"text":"导入","value":"Import"},{"text":"导出","value":"Export"}]},{"id":11,"actions":[{"text":"查询","value":"Search"},{"text":"新建","value":"Add"},{"text":"删除","value":"Delete"},{"text":"编辑","value":"Update"},{"text":"导入","value":"Import"},{"text":"导出","value":"Export"}]},{"id":14,"actions":[{"text":"查询","value":"Search"},{"text":"新建","value":"Add"},{"text":"删除","value":"Delete"},{"text":"编辑","value":"Update"},{"text":"导入","value":"Import"},{"text":"导出","value":"Export"}]},{"id":15,"actions":[{"text":"查询","value":"Search"},{"text":"新建","value":"Add"},{"text":"删除","value":"Delete"},{"text":"编辑","value":"Update"},{"text":"导入","value":"Import"},{"text":"导出","value":"Export"}]},{"id":16,"actions":[{"text":"查询","value":"Search"},{"text":"新建","value":"Add"},{"text":"删除","value":"Delete"},{"text":"编辑","value":"Update"},{"text":"导入","value":"Import"},{"text":"导出","value":"Export"}]},{"id":8,"actions":[{"text":"查询","value":"Search"},{"text":"新建","value":"Add"},{"text":"删除","value":"Delete"},{"text":"编辑","value":"Update"},{"text":"导入","value":"Import"},{"text":"导出","value":"Export"}]},{"id":6,"actions":[{"text":"查询","value":"Search"},{"text":"新建","value":"Add"},{"text":"删除","value":"Delete"},{"text":"编辑","value":"Update"},{"text":"导入","value":"Import"},{"text":"导出","value":"Export"}]},{"id":7,"actions":[{"text":"查询","value":"Search"},{"text":"新建","value":"Add"},{"text":"删除","value":"Delete"},{"text":"编辑","value":"Update"},{"text":"导入","value":"Import"},{"text":"导出","value":"Export"}]},{"id":9,"actions":[{"text":"查询","value":"Search"},{"text":"新建","value":"Add"},{"text":"删除","value":"Delete"},{"text":"编辑","value":"Update"},{"text":"导入","value":"Import"},{"text":"导出","value":"Export"}]},{"id":5,"actions":[{"text":"查询","value":"Search"},{"text":"新建","value":"Add"},{"text":"删除","value":"Delete"},{"text":"编辑","value":"Update"},{"text":"导入","value":"Import"},{"text":"导出","value":"Export"}]}]'
)
//新建角色
const AddRole = () => {
  Roletype.value = '新建'
  dialogVisible2.value = true
}
const Roletype = ref('新建')
//保存角色
const saveRole = async (formEl) => {
  if (!formEl) return
  await formEl.validate((valid, fields) => {
    if (valid) {
      if (Roletype.value == '修改') {
        UpdateRoleApi(formRole.value).then((res) => {
          ElMessage({ message: '修改成功', type: 'success' })
          dialogVisible2.value = false
          getRole()
        })
      } else {
        AddRoleApi(formRole.value).then((res) => {
          ElMessage({ message: '添加成功', type: 'success' })
          dialogVisible2.value = false
          getRole()
        })
      }
    } else {
      console.log('error submit!', fields)
    }
  })
}
//编辑角色
const EditRole = (val) => {
  Roletype.value = '修改'
  const obj = Object.assign({}, val)
  formRole.value = obj
  dialogVisible2.value = true
}
//获取角色
const getRole = () => {
  GetPageDataApi({
    page: 1,
    rows: 100,
    total: 0,
    tableName: 'string',
    sort: 'string',
    order: 'string',
    wheres: 'string',
    export: true,
    value: 'string',
    filter: [
      {
        name: 'string',
        value: 'string',
        displayType: 'string'
      }
    ]
  }).then((res) => {
    grideData.value = res.rows
    pageTotal.value = res.total
    groupOptions.value = res.rows
  })
}
const resetForm1 = (formEl) => {
  if (!formEl) return
  formEl.resetFields()
  formRole.value = {
    roleName: '',
    description: '',
    isLeader: 0 //组员类型
  }
}
const dialogVisible = ref(false)
// 用户角色是否启用
const changeRoleSwitch = (val) => {
  const data = Object.assign({}, val)
  StatusChangeApiApi(data).then((res) => {
    ElMessage({ message: '修改成功', type: 'success' })
    dialogVisible.value = false
    getRole()
  })
  SaveRoleApi(val.roleId, JSON.parse(roles.value))
}
//批量删除
const ids = ref([])
const UserSelectionChange = (val) => {
  ids.value = []
  ids.value = val.map((item) => item.user_Id)
  console.log(val, ids.value)
}
const RoleSelectionChange = (val) => {
  ids.value = []
  ids.value = val.map((item) => item.roleId)
}
 
const deleteAll = () => {
  if (ids.value.includes(1)) {
    ElMessage({ message: '超级管理员不能删除', type: 'error' })
    return
  }
  if (ids.value.length == 0) {
    ElMessage({ message: '请选择要删除的数据', type: 'error' })
    return
  }
  DeleteRoleApi(ids.value).then((res) => {
    ElMessage({ message: '删除成功', type: 'success' })
    getRole()
  })
}
onMounted(() => {
  getRole()
  userInfo.value = JSON.parse(localStorage.getItem('user')).userInfo
})
</script>
 
<template>
  <ContentWrap>
    <div class="box" style="display: flex; align-items: center">
    <!-- <Search :schema="searchSchema" @reset="setSearchParams" @search="setSearchParams" /> -->
    <div class="mb-10px">
      <el-button
        type="primary"
        size="small"
        @click="AddRole"
        style="width: 5.5rem; height: 2rem; font-size: 0.88rem; display: flex; align-items: center"
        >新建</el-button
      > 
    </div>
   <div class="mb-10px">
        <div style="width: 5.5rem; height: 2rem; font-size: 0.88rem;display: flex; align-items: center ;margin-left: 40px;">
          <el-button
            type="danger"
            size="small"
            style="width: 5.5rem; height: 2rem; font-size: 0.88rem;"
            class="text_btn"
            @click="deleteAll"
            >批量删除</el-button
          >
          </div>
        </div>
        </div>
    <el-table
      empty-text="暂无数据"
      height="800"
      :data="grideData"
      style="width: 100%"
      :header-cell-style="{
        background: 'rgba(250,250,250,1)',
        color: '#101010',
        fontSize: '0.88rem',
        height: '3rem',
        border: 'none'
      }"
      :row-style="{
        color: '#101010',
        fontSize: '0.88rem',
        height: '3rem'
      }"
      @selection-change="RoleSelectionChange"
    >
      <el-table-column type="selection" align="center" />
      <el-table-column prop="roleName" label="角色名称" align="center" />
      <el-table-column prop="isLeader" label="用户类型" align="center">
        <template #default="scope">
          <span v-if="scope.row.isLeader == 0">二级</span>
          <span v-else-if="scope.row.isLeader == 1">一级</span>
        </template>
      </el-table-column>
      <!-- <el-table-column prop="deptName" label="备注" align="center" /> -->
      <el-table-column label="是否启用" align="center">
        <template #default="scope">
          <el-switch
            :disabled="!(userInfo.userName == 'admin' || userInfo.roleId == '1')"
            v-model="scope.row.enable"
            :active-value="1"
            :inactive-value="0"
            @change="changeRoleSwitch(scope.row)"
          />
        </template>
      </el-table-column>
      <el-table-column prop="createDate" label="创建日期" align="center" />
      <el-table-column label="操作" align="center">
        <template #default="scope">
          <span
            v-if="
              !(userInfo.userName == 'admin' || userInfo.roleId == '1'
                ? scope.row.userName == 'admin' || scope.row.user_Id == '1'
                : scope.row.userName == 'admin' ||
                  scope.row.user_Id == '1' ||
                  scope.row.userName != userInfo.userName)
            "
            style="color: blue; font-size: 0.88rem; cursor: pointer"
            @click="EditRole(scope.row)"
            >编辑</span
          >
          <span style="color:blue; font-size: 0.88rem; padding-left: 30px; cursor: pointer" @click="deleteAll">删除</span>
        </template></el-table-column
      >
    </el-table>
  </ContentWrap>
 
  <!-- 用户角色新建 -->
  <el-dialog
    v-model="dialogVisible2"
    title=""
    width="30%"
    :show-close="false"
    :align-center="true"
    @close="resetForm1(formRoleRef)"
  >
    <template #title>
      <div style="height: 3.63rem; display: flex; border-bottom: 1px solid #e6e6e6">
        <span style="color: rgb(16, 16, 16); font-size: 1rem; font-weight: bold">用户角色</span>
      </div>
    </template>
    <el-form
      :model="formRole"
      label-width="auto"
      label-position="top"
      ref="formRoleRef"
      :rules="roleRules"
      :hide-required-asterisk="true"
    >
      <el-form-item prop="roleName">
        <template #label>
          <div style="display: flex; align-items: flex-end">
            <span style="color: red; margin-right: 0.2rem">*</span>
            <span style="font-size: 0.88rem; color: black; font-weight: bold">角色名称</span>
          </div>
        </template>
        <el-input
          style="height: 2rem"
          size="small"
          v-model="formRole.roleName"
          placeholder="请输入"
        />
      </el-form-item>
      <el-form-item prop="isLeader">
        <template #label>
          <div style="display: flex; align-items: flex-end">
            <span
              :style="{
                color: 'red',
                marginRight: '0.2rem',
                fontSize: '0.88rem'
              }"
              >*</span
            >
            <span
              :style="{
                fontSize: '0.88rem',
                color: 'black',
                fontWeight: 'bold'
              }"
              >用户类型</span
            >
          </div>
        </template>
        <el-select v-model="formRole.isLeader" placeholder="请选择" size="small">
          <el-option
            v-for="item in rolekey"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <!-- <el-form-item>
        <template #label>
          <div style="display: flex; align-items: flex-end">
            <span style="font-size: 0.88rem; color: black; font-weight: bold">备注</span>
          </div>
        </template>
        <el-input
          style="height: 2rem"
          size="small"
          v-model="formRole.description"
          placeholder="请输入"
        />
      </el-form-item> -->
    </el-form>
    <template #footer>
      <div class="dialog-footer" style="text-align: center">
        <el-button
          size="small"
          @click="dialogVisible2 = false"
          style="height: 2rem; font-size: 0.88rem"
          >取消</el-button
        >
 
        <el-button
          size="small"
          type="primary"
          @click="saveRole(formRoleRef)"
          style="height: 2rem; font-size: 0.88rem"
        >
          保存
        </el-button>
      </div>
    </template>
  </el-dialog>
</template>