index.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. <template>
  2. <div class="pageWrap bgc">
  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" :disabled="curSelectionRows.length === 0" @click="batch_del">
  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, ElMessageBox, 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. showCancelBtn: true,
  110. submitLoading: false
  111. }
  112. }
  113. })
  114. const groupFilterText = ref('')
  115. const treeRef = ref<InstanceType<typeof ElTree>>()
  116. // 表格搜索条件
  117. const forms = ref([
  118. {
  119. prop: 'keyword',
  120. label: '岗位名称:',
  121. itemType: 'input',
  122. placeholder: '请输入岗位名称'
  123. },
  124. {
  125. prop: 'code',
  126. label: '编码:',
  127. itemType: 'input',
  128. placeholder: '请输入编码'
  129. },
  130. {
  131. prop: 'status',
  132. label: '状态:',
  133. itemType: 'select',
  134. placeholder: '请选择状态',
  135. options: [
  136. {
  137. label: '禁用',
  138. value: 0
  139. },
  140. {
  141. label: '正常',
  142. value: 1
  143. }
  144. ]
  145. }
  146. ])
  147. // table列表数据请求
  148. const queryList = async () => {
  149. const { options, searchParams } = tableOpts
  150. options.loading = true
  151. try {
  152. const { records: list, total } = await post.postPageApi(searchParams)
  153. tableOpts.total = total
  154. tableOpts.list = list
  155. } catch {
  156. console.log('获取列表数据失败')
  157. tableOpts.total = 0
  158. tableOpts.list = []
  159. options.loading = false // 更改加载中的 loading值
  160. } finally {
  161. options.loading = false
  162. }
  163. }
  164. // table 参数
  165. const columns = [
  166. {
  167. prop: 'name',
  168. label: '岗位名称',
  169. minWidth: 80,
  170. slots: {
  171. default: 'filterAvatarSlot'
  172. }
  173. },
  174. {
  175. prop: 'status',
  176. label: '状态',
  177. minWidth: 50,
  178. slots: {
  179. default: 'statusSlot'
  180. }
  181. },
  182. {
  183. prop: 'code',
  184. label: '编码',
  185. minWidth: 100
  186. },
  187. {
  188. prop: 'remark',
  189. label: '备注',
  190. minWidth: 100
  191. },
  192. {
  193. prop: 'sort',
  194. label: '排序',
  195. minWidth: 80
  196. },
  197. {
  198. prop: 'updateBy',
  199. label: '修改人',
  200. minWidth: 100
  201. },
  202. {
  203. prop: 'updateTime',
  204. label: '修改时间',
  205. minWidth: 126
  206. },
  207. {
  208. prop: 'createBy',
  209. label: '创建人',
  210. minWidth: 100
  211. },
  212. {
  213. prop: 'createTime',
  214. label: '创建时间',
  215. minWidth: 126
  216. },
  217. {
  218. prop: 'action',
  219. label: '操作',
  220. width: 100,
  221. fixed: 'right',
  222. slots: {
  223. default: 'actionSlot'
  224. }
  225. }
  226. ]
  227. const { searchData, tableOpts, checkedColumns, activeColumns, curSelectionRows, updateParams } = useTablePage(
  228. {
  229. options: {
  230. showIndex: false
  231. },
  232. // 需要展示的列
  233. columns,
  234. // 控制列配置
  235. columnsConfig: {
  236. columns
  237. }
  238. },
  239. {
  240. queryList,
  241. fetchImmediate: false
  242. }
  243. )
  244. // 删除
  245. const deleteItem = async ids => {
  246. // try {
  247. await post.postDeleteApi(ids)
  248. ElMessage.error(`删除成功~`)
  249. updateParams()
  250. // } catch (e) {
  251. // console.log('删除失败')
  252. // ElMessage.error(`删除失败~`)
  253. // }
  254. }
  255. // 单个删除
  256. const table_del = row => {
  257. deleteItem([row.id])
  258. }
  259. //批量删除
  260. const batch_del = () => {
  261. const ids = curSelectionRows.value.map(item => item.id) // 多选数据
  262. ElMessageBox.confirm('是否删除选中数据?', '提示', {
  263. confirmButtonText: '确认',
  264. cancelButtonText: '取消',
  265. type: 'error',
  266. buttonSize: 'default'
  267. }).then(() => {
  268. deleteItem(ids)
  269. })
  270. }
  271. const table_edit = async row => {
  272. isCreate.value = false
  273. activeData.value = { ...row, status: row.status ? true : false }
  274. visible.value = true
  275. }
  276. // 弹窗事件
  277. const submitHandler = async params => {
  278. formOptions.value.formConfig.submitLoading = true
  279. try {
  280. params.status = params.status ? 1 : 0
  281. params.id = activeData.value.id ? activeData.value.id : null
  282. await post.postAddOrEditSaveApi(params)
  283. ElMessage.success(`${isCreate.value ? '新增' : '修改'}成功~`)
  284. visible.value = false
  285. updateParams()
  286. formOptions.value.formConfig.submitLoading = false
  287. } catch (e) {
  288. console.log(e)
  289. formOptions.value.formConfig.submitLoading = false
  290. }
  291. }
  292. const addHandler = () => {
  293. isCreate.value = true
  294. activeData.value = {}
  295. visible.value = true
  296. }
  297. nextTick(() => {
  298. queryList()
  299. })
  300. watch(groupFilterText, val => {
  301. treeRef.value!.filter(val)
  302. })
  303. </script>