index.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. <template>
  2. <div class="pageWrap">
  3. <div class="content-warp flex-column-page-wrap">
  4. <!-- 公用搜索组件 -->
  5. <LeSearchForm ref="searchForm" v-model:searchData="searchData" :forms="forms" :loading="tableOpts.options.loading"> </LeSearchForm>
  6. <!-- LeTable 组件使用 -->
  7. <LeTable
  8. ref="tableRef"
  9. v-model:searchParams="tableOpts.searchParams"
  10. v-bind="tableOpts"
  11. v-model:curRow="tableOpts.curRow"
  12. v-model:checked-options="checkedColumns"
  13. :columns="activeColumns"
  14. >
  15. <template #toolLeft>
  16. <el-button type="primary" @click="addHandler">
  17. <el-icon class="btn-icon">
  18. <Plus />
  19. </el-icon>
  20. </el-button>
  21. <el-button type="danger" @click="batch_del" :disabled="curSelectionRows.length === 0">
  22. <el-icon class="btn-icon">
  23. <Delete />
  24. </el-icon>
  25. </el-button>
  26. <el-button type="primary" plain :disabled="!curSelectionRows.length || curSelectionRows.length !== 1" @click="visiblePermission = true"
  27. >权限设置</el-button
  28. >
  29. </template>
  30. <template #statusSlot="scope">
  31. <status-indicator v-if="scope.row.status === 1" pulse type="success"></status-indicator>
  32. <status-indicator v-else pulse type="danger"></status-indicator>
  33. </template>
  34. <template #actionSlot="scope">
  35. <el-tooltip content="编辑" placement="bottom" effect="light">
  36. <el-icon class="ibt0" @click="table_edit(scope.row)">
  37. <Edit />
  38. </el-icon>
  39. </el-tooltip>
  40. <el-divider direction="vertical"></el-divider>
  41. <el-popconfirm title="确定删除吗?" @confirm="table_del(scope.row)">
  42. <template #reference>
  43. <el-icon class="ibt0">
  44. <Delete />
  45. </el-icon>
  46. </template>
  47. </el-popconfirm>
  48. </template>
  49. </LeTable>
  50. </div>
  51. <LeFormConfigDialog
  52. v-if="visible"
  53. ref="dialogUserRef"
  54. v-model="visible"
  55. :title="`${isCreate ? '新增' : '编辑'}角色`"
  56. width="600px"
  57. :form-data="activeData"
  58. :form-options="formOptions"
  59. @submit="submitHandler"
  60. />
  61. <!-- 权限设置 -->
  62. <Permission
  63. v-if="visiblePermission"
  64. :role-id="curSelectionRows.map(item => item.id).join(',')"
  65. v-model="visiblePermission"
  66. @closed="visiblePermission = false"
  67. />
  68. </div>
  69. </template>
  70. <script lang="tsx" setup>
  71. import role from '@/api/system/role'
  72. import { computed, nextTick, ref, watch } from 'vue'
  73. import { ElMessage, ElTree } from 'element-plus'
  74. import { useTablePage } from '@/hooks/useTablePage'
  75. import { Plus, Delete } from '@element-plus/icons-vue'
  76. import StatusIndicator from '@/components/StatusIndicator'
  77. import Permission from './permission.vue'
  78. const visible = ref(false) // 弹窗显示隐藏
  79. const isCreate = ref(true)
  80. const visiblePermission = ref(false) // 权限设置弹窗显示隐藏
  81. const activeData = ref({})
  82. const formsDialog = [
  83. {
  84. prop: 'name',
  85. label: '角色名称',
  86. itemType: 'input',
  87. rules: [{ required: true, message: '请输入角色名称', trigger: 'blur' }]
  88. },
  89. {
  90. prop: 'alias',
  91. label: '角色别名',
  92. itemType: 'input',
  93. rules: [{ required: true, message: '请输入角色别名', trigger: 'blur' }]
  94. },
  95. {
  96. prop: 'sort',
  97. label: '排序',
  98. itemType: 'inputNumber',
  99. rules: [{ required: true, message: '请输入排序', trigger: 'blur' }]
  100. },
  101. {
  102. prop: 'status',
  103. label: '状态',
  104. itemType: 'switch',
  105. activeText: '是',
  106. inactiveText: '否'
  107. },
  108. {
  109. prop: 'remark',
  110. label: '备注',
  111. itemType: 'input'
  112. }
  113. ]
  114. // 新增的表单 和 编辑的表单
  115. const formOptions = computed(() => {
  116. return {
  117. forms: formsDialog,
  118. labelWidth: 120,
  119. span: 30,
  120. showResetBtn: true,
  121. formConfig: {
  122. submitLoading: false
  123. }
  124. }
  125. })
  126. const groupFilterText = ref('')
  127. const treeRef = ref<InstanceType<typeof ElTree>>()
  128. // 表格搜索条件
  129. const forms = ref([
  130. {
  131. prop: 'keyword',
  132. label: '角色名称:',
  133. itemType: 'input',
  134. placeholder: '请输入角色名称'
  135. }
  136. ])
  137. // table列表数据请求
  138. const queryList = async () => {
  139. const { options, searchParams } = tableOpts
  140. options.loading = true
  141. try {
  142. const { records: list, total } = await role.rolePageApi(searchParams)
  143. tableOpts.total = total
  144. tableOpts.list = list
  145. } catch {
  146. console.log('获取列表数据失败')
  147. tableOpts.total = 0
  148. tableOpts.list = []
  149. options.loading = false // 更改加载中的 loading值
  150. } finally {
  151. options.loading = false
  152. }
  153. }
  154. // table 参数
  155. const columns = [
  156. {
  157. prop: 'name',
  158. label: '角色名称',
  159. minWidth: 80
  160. },
  161. {
  162. prop: 'status',
  163. label: '状态',
  164. minWidth: 50,
  165. slots: {
  166. default: 'statusSlot'
  167. }
  168. },
  169. {
  170. prop: 'alias',
  171. label: '别名',
  172. minWidth: 100
  173. },
  174. {
  175. prop: 'remark',
  176. label: '备注',
  177. minWidth: 100
  178. },
  179. {
  180. prop: 'sort',
  181. label: '排序',
  182. minWidth: 80
  183. },
  184. {
  185. prop: 'updateBy',
  186. label: '修改人',
  187. minWidth: 100
  188. },
  189. {
  190. prop: 'updateTime',
  191. label: '修改时间',
  192. minWidth: 126
  193. },
  194. {
  195. prop: 'createBy',
  196. label: '创建人',
  197. minWidth: 100
  198. },
  199. {
  200. prop: 'createTime',
  201. label: '创建时间',
  202. minWidth: 126
  203. },
  204. {
  205. prop: 'action',
  206. label: '操作',
  207. width: 100,
  208. fixed: 'right',
  209. slots: {
  210. default: 'actionSlot'
  211. }
  212. }
  213. ]
  214. const { searchData, tableOpts, checkedColumns, activeColumns, curSelectionRows, updateParams } = useTablePage(
  215. {
  216. options: {
  217. showIndex: false
  218. },
  219. // 需要展示的列
  220. columns,
  221. // 控制列配置
  222. columnsConfig: {
  223. columns
  224. }
  225. },
  226. {
  227. queryList,
  228. fetchImmediate: false
  229. }
  230. )
  231. // 删除
  232. const deleteItem = async ids => {
  233. try {
  234. await role.roleDeleteApi(ids)
  235. updateParams()
  236. } catch (e) {
  237. console.log('删除失败')
  238. ElMessage.error(`删除失败~`)
  239. }
  240. }
  241. // 单个删除
  242. const table_del = row => {
  243. deleteItem([row.id])
  244. }
  245. //批量删除
  246. const batch_del = () => {
  247. const ids = curSelectionRows.value.map(item => item.id) // 多选数据
  248. deleteItem(ids)
  249. }
  250. const table_edit = async row => {
  251. isCreate.value = false
  252. activeData.value = { ...row, status: row.status ? true : false }
  253. visible.value = true
  254. }
  255. // 弹窗事件
  256. const submitHandler = async params => {
  257. formOptions.value.formConfig.submitLoading = true
  258. try {
  259. params.status = params.status ? 1 : 0
  260. params.id = activeData.value.id ? activeData.value.id : null
  261. await role.roleSaveApi(params)
  262. ElMessage.success(`${isCreate.value ? '新增' : '修改'}成功~`)
  263. visible.value = false
  264. updateParams()
  265. formOptions.value.formConfig.submitLoading = false
  266. } catch (e) {
  267. console.log(e)
  268. formOptions.value.formConfig.submitLoading = false
  269. }
  270. }
  271. const addHandler = () => {
  272. isCreate.value = true
  273. activeData.value = {}
  274. visible.value = true
  275. }
  276. nextTick(() => {
  277. queryList()
  278. })
  279. watch(groupFilterText, val => {
  280. treeRef.value!.filter(val)
  281. })
  282. </script>
  283. <style scoped lang="scss">
  284. .pageWrap {
  285. flex: 1;
  286. display: flex;
  287. height: 100%;
  288. //background: #fff;
  289. }
  290. .content-warp {
  291. flex: 1;
  292. //width: calc(100% - 250px);
  293. width: calc(100% - 210px);
  294. }
  295. // 单独自己写的
  296. /*:deep(.box-card) {
  297. height: 100%;
  298. .el-card__body {
  299. padding: 0;
  300. }
  301. }*/
  302. // 角色的树结构样式
  303. :deep(.menu-tree) {
  304. .el-tree-node__content {
  305. height: 36px;
  306. }
  307. .el-tree-node__content .el-tree-node__label .icon {
  308. margin-right: 5px;
  309. }
  310. }
  311. .nopadding {
  312. padding: 0px;
  313. }
  314. </style>