15815213711
2025-07-29 7eaff7d5d5170bb99237c4eec64a84087ea8a2de
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
 
<template>
  <basicContainer>
    <avue-crud
        :option="option"
        :table-loading="pageF.loading"
        :data="tableData"
        :page="page"
        :permission="permissionList"
        :before-open="beforeOpen"
        v-model="form"
        ref="crudRef"
        @row-update="rowUpdate"
        @row-save="rowSave"
        @row-del="rowDel"
        @search-change="searchChange"
        @search-reset="searchReset"
        @selection-change="selectionChange"
        @current-change="currentChange"
        @size-change="sizeChange"
        @on-load="onLoad"
    >
      <template #menu-left>
        <avue-input-table :props="props" multiple v-show="false"
                          :children="childrenOptions"
                          :on-load="onUserLoad" ref="inputTableRef"
                          v-model="form"
                          placeholder="请选择数据"></avue-input-table>
      <el-button
          type="primary"
          plain
          icon="Plus"
          v-hasPermi="['system:role:add']"
          @click="openSelectUser">添加用户
      </el-button>
      <el-button
          type="danger"
          plain
          icon="CircleClose"
          :disabled="pageF.multiple"
          @click="cancelAuthUserAll"
          v-hasPermi="['system:role:remove']"
      >批量取消授权</el-button>
      <el-button
          type="warning"
          plain
          icon="Close"
          @click="handleClose"
      >关闭</el-button>
    </template>
      <template #menu="scope">
      <el-link
          type="primary"
          icon="CircleClose" :underline="false"
          v-hasPermi="['system:role:remove']"
          @click="cancelAuthUser(scope.row)"> <span style="padding-left:5px">取消授权</span>
      </el-link>
    </template>
    </avue-crud>
  </basicContainer>
</template>
 
<script setup name="type" lang="ts">
import {TypeI,addType, delType, exportType, getType, listType, updateType,refreshCache} from "@/api/system/dict/type";
import useCurrentInstance from "@/utils/useCurrentInstance";
import {computed,reactive, ref, toRefs} from "vue";
import {PagesInterface, PageQueryInterface} from "@/utils/globalInterface";
import {usePagePlus} from "@/hooks/usePagePlus";
import {hasPermission} from "@/utils/permissionUtils";
import {
  allocatedUserList,
  authUserCancel,
  authUserCancelAll,
  authUserSelectAll,
  unallocatedUserList
} from "@/api/system/role";
import {useRoute} from "vue-router";
import {UserI} from "@/api/system/user";
 
const { proxy } = useCurrentInstance();
const crudRef = ref();
const route = useRoute();
 
const permissionList = computed(()=>{
  return {
    addBtn: hasPermission(["system:type:add"]),
    delBtn: hasPermission(["system:type:remove"]),
    editBtn: hasPermission(["system:type:edit"]),
    viewBtn: hasPermission(["system:type:query"]),
  }
})
 
const data = reactive({
  form:<TypeI>{},
  queryParams:<TypeI&PageQueryInterface>{
    roleId:<any> route.params.roleId,
  },
  page: <PagesInterface>{
    pageSize: 10,
    total: 0,
    currentPage: 1,
 
  },
  selectionList:[],
  roleId:<any> route.params.roleId,
})
const {queryParams,form,page,selectionList,roleId} = toRefs(data);
 
 
const { tableData,pageF,rowSave,rowUpdate,rowDel,beforeOpen,searchChange,
  searchReset,selectionChange,onLoad,currentChange,sizeChange,handleDelete,handleExport,handleUpdate} = usePagePlus({
  form:form,
  queryParams:queryParams,
  idKey:'userId',
  page:page.value,
  getListApi:allocatedUserList,
  getDetailApi:getType,
  exportApi:exportType,
  deleteApi:delType,
  addApi:addType,
  updateApi:updateType,
  handleUpdateFunc:()=>{
    crudRef.value.rowEdit(selectionList.value[0]);
  },
  handleSelectionChangeFunc:(selection:any)=>{
    selectionList.value = selection;
  }
})
 
const option = ref({
  rowKey: 'userId',
  addBtn:false,
  viewBtn:false,
  editBtn:false,
  delBtn:false,
  column: {
    userName: {
      label: '用户名称',addDisplay:false,editDisplay:false,
    },
    nickName: {
      label: '用户昵称',search:true,
    },
    email: {
      label: '邮箱',search:true,
    },
    phonenumber: {
      label: '手机',search:true,
    },
    status: {
      label: '状态',search:true,value:'0',
      type: 'radio', dicUrl: '/system/dict/data/type/sys_normal_disable',
      rules:[{required: true, message: "请选择状态", trigger: "change"}]
    },
    createTime: {
      label: '创建时间',addDisplay:false,editDisplay:false,
    },
 
  }
})
const props = ref({
  label: 'userName',
  value: 'userId'
})
 
/** 刷新缓存按钮操作 */
function handleRefreshCache() {
  refreshCache().then(() => {
    proxy.$modal.msgSuccess("刷新成功");
  });
}
// 返回按钮
function handleClose() {
  const obj = { path: "/system/role" };
  proxy.$tab.closeOpenPage(obj);
}
/** 取消授权按钮操作 */
function cancelAuthUser(row?:UserI) {
  proxy.$modal.confirm('确认要取消该用户"' + row?.userName + '"角色吗?').then(function () {
    return authUserCancel({ userId: row?.userId, roleId: roleId.value });
  }).then(() => {
    onLoad(page.value);
    proxy.$modal.msgSuccess("取消授权成功");
  }).catch(() => {});
}
 
/** 批量取消授权按钮操作 */
function cancelAuthUserAll() {
  const uIds =  pageF.ids!.join(",");
  proxy.$modal.confirm("是否取消选中用户授权数据项?").then(function () {
    return authUserCancelAll({ roleId: roleId.value, userIds: uIds });
  }).then(() => {
    onLoad(page.value);
    proxy.$modal.msgSuccess("取消授权成功");
  }).catch(() => {});
}
const childrenOptions = ref({
  border: true,
  rowKey: 'userId',
  column:{
    userName:{
      label: '用户名称',search:true,
    },
    nickName: {
      label: '用户昵称'
    },
    email:{
      label: '邮箱'
    },
    phonenumber:{
      label: '手机',search:true,
    },
    status:{
      label: '状态',
      dicUrl: '/system/dict/data/type/sys_normal_disable',
    },
    createTime:{
      label: '创建时间'
    }
  }
})
const inputTableRef = ref();
 
const openSelectUser = () => {
  inputTableRef.value.handleShow();
}
const onUserLoad = ({ page, value, data }:any, callback:any) =>{
  console.log(page,value,data)
  if (value){
    if (Array.isArray(value) && value.length === 0) {
      proxy.$modal.msgError("请选择要分配的用户");
      return;
    }
    authUserSelectAll({ roleId: roleId.value, userIds: value.join(",") }).then(res => {
      proxy.$modal.msgSuccess(res.msg);
      onLoad({currentPage:1,pageSize:10});
      callback(value);
    });
  }
  if (page){
    unallocatedUserList({pageNum:page.currentPage,pageSize:page.pageSize,roleId:roleId.value,...data}).then(res => {
      callback({
        total: res.total || 0,
        data:res.rows||[]
      })
    });
  }
 
}
 
</script>