index.vue 6.5 KB

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