index.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  1. <template>
  2. <div class="pageWrap">
  3. <el-aside style="background: #fff; margin-right: 10px" width="200px">
  4. <el-container>
  5. <el-header>
  6. <el-input v-model="groupFilterText" placeholder="输入关键字进行过滤" clearable style="margin-top: 10px" />
  7. </el-header>
  8. <el-main class="nopadding">
  9. <el-tree
  10. ref="treeRef"
  11. class="menu-tree"
  12. :data="treeData"
  13. node-key="id"
  14. :current-node-key="''"
  15. :highlight-current="true"
  16. :expand-on-click-node="false"
  17. :props="defaultProps"
  18. default-expand-all
  19. :filter-node-method="filterNode"
  20. @node-click="roleClick"
  21. />
  22. </el-main>
  23. </el-container>
  24. </el-aside>
  25. <!-- <el-divider direction="vertical" style="height: 100%" />-->
  26. <div class="content-warp flex-column-page-wrap">
  27. <!-- 公用搜索组件 -->
  28. <LeSearchForm ref="searchForm" v-model:searchData="searchData" :forms="forms" :loading="tableOpts.options.loading"> </LeSearchForm>
  29. <!-- LeTable 组件使用 -->
  30. <LeTable
  31. ref="tableRef"
  32. v-model:searchParams="tableOpts.searchParams"
  33. v-bind="tableOpts"
  34. v-model:checked-options="checkedColumns"
  35. :columns="activeColumns"
  36. >
  37. <template #toolLeft>
  38. <el-button type="primary" @click="addHandler">
  39. <el-icon class="btn-icon">
  40. <Plus />
  41. </el-icon>
  42. </el-button>
  43. <el-button type="danger">
  44. <el-icon class="btn-icon">
  45. <Delete />
  46. </el-icon>
  47. </el-button>
  48. <el-button plain> 分配角色 </el-button>
  49. <el-button plain> 密码重置 </el-button>
  50. </template>
  51. <template #filterAvatarSlot="scope">
  52. <el-avatar :src="scope.row.avatar" size="small"></el-avatar>
  53. </template>
  54. <template #statusSlot="scope">
  55. <status-indicator v-if="scope.row.status === 1" pulse type="success"></status-indicator>
  56. <status-indicator v-else pulse type="danger"></status-indicator>
  57. </template>
  58. <template #actionSlot="">
  59. <el-tooltip content="编辑" placement="bottom" effect="light">
  60. <el-icon class="ibt0">
  61. <Edit />
  62. </el-icon>
  63. </el-tooltip>
  64. <el-divider direction="vertical"></el-divider>
  65. <el-popconfirm title="确定删除吗?" @confirm="table_del(scope.row)">
  66. <template #reference>
  67. <el-icon class="ibt0">
  68. <Delete />
  69. </el-icon>
  70. </template>
  71. </el-popconfirm>
  72. </template>
  73. </LeTable>
  74. </div>
  75. <LeFormConfigDialog
  76. v-if="visible"
  77. ref="dialogUserRef"
  78. v-model="visible"
  79. :title="`${isCreate ? '新增' : '编辑'}用户`"
  80. width="600px"
  81. :form-data="activeData"
  82. :form-options="formOptions"
  83. @submit="submitHandler"
  84. />
  85. </div>
  86. </template>
  87. <script lang="tsx" setup>
  88. import role from '@/api/system/role'
  89. import user from '@/api/system/user'
  90. import { nextTick, ref, watch } from 'vue'
  91. import { ElMessage, ElTree } from 'element-plus'
  92. import { useTablePage } from '@/hooks/useTablePage'
  93. import { Plus, Delete } from '@element-plus/icons-vue'
  94. import StatusIndicator from '@/components/StatusIndicator'
  95. const visible = ref(false) // 弹窗显示隐藏
  96. const isCreate = ref(true)
  97. const activeData = ref({})
  98. const formOptions = ref({
  99. forms: [
  100. {
  101. prop: 'custName',
  102. label: '登录账号',
  103. itemType: 'input',
  104. placeholder: '用于登录系统',
  105. rules: [{ required: true, message: '请输入登录账号', trigger: 'blur' }]
  106. },
  107. {
  108. prop: 'custName1',
  109. label: '登录密码',
  110. itemType: 'input',
  111. rules: [{ required: true, message: '请输入登录密码', trigger: 'blur' }]
  112. },
  113. {
  114. prop: 'custName2',
  115. label: '确认密码',
  116. itemType: 'input',
  117. rules: [{ required: true, message: '请再次输入密码', trigger: 'blur' }]
  118. },
  119. {
  120. prop: 'custName3',
  121. label: '昵称',
  122. itemType: 'input'
  123. },
  124. {
  125. prop: 'custName4',
  126. label: '姓名',
  127. itemType: 'input'
  128. },
  129. {
  130. prop: 'custName5',
  131. label: '性别',
  132. itemType: 'radio',
  133. options: [
  134. { value: '0', label: '男' },
  135. { value: '1', label: '女' }
  136. ]
  137. },
  138. {
  139. prop: 'switch',
  140. // label: '状态',
  141. t_label: '状态',
  142. itemType: 'switch',
  143. slots: {
  144. label: 'slot_label_test'
  145. },
  146. activeText: '是',
  147. inactiveText: '否',
  148. change(value, options, params) {
  149. console.warn('dataType change value, options, params', value, options, params)
  150. }
  151. },
  152. {
  153. prop: 'select多选',
  154. label: '所属角色',
  155. itemType: 'select',
  156. multiple: true,
  157. collapseTags: true,
  158. maxCollapseTags: 1,
  159. filterable: true,
  160. itemWidth: '200px',
  161. options: [
  162. { value: '类型one', label: '类型一' },
  163. { value: '类型two', label: '类型二' },
  164. { value: '类型three', label: '类型三' }
  165. ]
  166. }
  167. ],
  168. labelWidth: 120,
  169. span: 30,
  170. showResetBtn: true,
  171. formConfig: {
  172. submitLoading: false
  173. }
  174. })
  175. const showGroupLoading = ref(false)
  176. const groupFilterText = ref('')
  177. const treeRef = ref<InstanceType<typeof ElTree>>()
  178. const defaultProps = {
  179. children: 'children',
  180. label: 'label'
  181. }
  182. const filterNode = (value: string, data: Tree) => {
  183. if (!value) return true
  184. return data.label.includes(value)
  185. }
  186. const treeData = ref([])
  187. // 获取左侧菜单数据
  188. const getGroup = async () => {
  189. showGroupLoading.value = true
  190. let data = await role.roleListTreeApi()
  191. showGroupLoading.value = false
  192. data.unshift({ id: '', label: '所有' })
  193. treeData.value = data // console.log('获取左侧菜单数据')
  194. }
  195. // 左侧菜单点击
  196. const roleClick = data => {
  197. console.log(data.id, 'data.id')
  198. // 修改search参数 watch 变更 自动刷新 列表
  199. searchData.value = { ...searchData.value, data: { roleId: data.id ? data.id : null } }
  200. // queryList()
  201. // 刷新右侧的表格
  202. }
  203. // 搜索条件
  204. const forms = ref([
  205. {
  206. prop: 'name',
  207. label: '账号/姓名:',
  208. itemType: 'input',
  209. placeholder: '请输入登录账号 / 姓名'
  210. }
  211. ])
  212. // table列表数据请求
  213. const queryList = async () => {
  214. const { options, searchParams } = tableOpts
  215. options.loading = true
  216. console.log('搜索参数: ', JSON.stringify(tableOpts.searchParams))
  217. try {
  218. const { records: list, total } = await user.userPageApi(searchParams)
  219. tableOpts.total = total
  220. tableOpts.list = list
  221. } catch {
  222. console.log('获取列表数据失败')
  223. tableOpts.total = 0
  224. tableOpts.list = []
  225. options.loading = false // 更改加载中的 loading值
  226. } finally {
  227. options.loading = false
  228. }
  229. }
  230. // table 参数
  231. const columns = [
  232. {
  233. prop: 'filterAvatar',
  234. label: '头像',
  235. minWidth: 80,
  236. slots: {
  237. default: 'filterAvatarSlot'
  238. }
  239. },
  240. {
  241. prop: 'username',
  242. label: '登录账号',
  243. minWidth: 100
  244. },
  245. {
  246. prop: 'status',
  247. label: '状态',
  248. minWidth: 50,
  249. slots: {
  250. default: 'statusSlot'
  251. }
  252. },
  253. {
  254. prop: 'nickName',
  255. label: '昵称',
  256. minWidth: 100
  257. },
  258. {
  259. prop: 'realName',
  260. label: '姓名',
  261. minWidth: 100
  262. },
  263. {
  264. prop: 'sex',
  265. label: '性别',
  266. minWidth: 80
  267. },
  268. {
  269. prop: 'updateBy',
  270. label: '修改人',
  271. minWidth: 100
  272. },
  273. {
  274. prop: 'updateTime',
  275. label: '修改时间',
  276. minWidth: 126
  277. },
  278. {
  279. prop: 'createBy',
  280. label: '创建人',
  281. minWidth: 100
  282. },
  283. {
  284. prop: 'createTime',
  285. label: '创建时间',
  286. minWidth: 126
  287. },
  288. {
  289. prop: 'action',
  290. label: '操作',
  291. width: 100,
  292. fixed: 'right',
  293. slots: {
  294. default: 'actionSlot'
  295. }
  296. }
  297. ]
  298. const { searchData, tableOpts, checkedColumns, activeColumns } = useTablePage(
  299. {
  300. options: {
  301. showIndex: false
  302. },
  303. // searchParams: {
  304. // // page: 1,
  305. // // size: 10,
  306. // test: 1
  307. // },
  308. // 需要展示的列
  309. columns,
  310. // 控制列配置
  311. columnsConfig: {
  312. columns
  313. }
  314. },
  315. {
  316. queryList,
  317. fetchImmediate: false
  318. }
  319. )
  320. // // 列接口请求后 进行赋值
  321. // checkedColumns.value = columns
  322. // 删除
  323. const table_del = row => {
  324. // 删除
  325. }
  326. //批量删除
  327. const batch_del = () => {}
  328. // 弹窗事件
  329. const submitHandler = params => {
  330. ElMessage.success(`${isCreate.value ? '新增' : '修改'}成功~`)
  331. }
  332. const addHandler = () => {
  333. isCreate.value = true
  334. activeData.value = {}
  335. visible.value = true
  336. }
  337. nextTick(() => {
  338. getGroup()
  339. queryList()
  340. })
  341. watch(groupFilterText, val => {
  342. treeRef.value!.filter(val)
  343. })
  344. </script>
  345. <style scoped lang="scss">
  346. .pageWrap {
  347. flex: 1;
  348. display: flex;
  349. height: 100%;
  350. //background: #fff;
  351. }
  352. .content-warp {
  353. flex: 1;
  354. //width: calc(100% - 250px);
  355. width: calc(100% - 210px);
  356. }
  357. // 单独自己写的
  358. /*:deep(.box-card) {
  359. height: 100%;
  360. .el-card__body {
  361. padding: 0;
  362. }
  363. }*/
  364. // 角色的树结构样式
  365. :deep(.menu-tree) {
  366. .el-tree-node__content {
  367. height: 36px;
  368. }
  369. .el-tree-node__content .el-tree-node__label .icon {
  370. margin-right: 5px;
  371. }
  372. }
  373. .nopadding {
  374. padding: 0px;
  375. }
  376. </style>