index.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <template>
  2. <!-- 搜索工作栏 -->
  3. <ContentWrap>
  4. <Search :schema="allSchemas.searchSchema" @reset="setSearchParams" @search="setSearchParams">
  5. <!-- 新增等操作按钮 -->
  6. <template #actionMore>
  7. <el-button
  8. v-hasPermi="['promotion:combination-activity:create']"
  9. plain
  10. type="primary"
  11. @click="openForm('create')"
  12. >
  13. <Icon class="mr-5px" icon="ep:plus" />
  14. 新增
  15. </el-button>
  16. </template>
  17. </Search>
  18. </ContentWrap>
  19. <!-- 列表 -->
  20. <ContentWrap>
  21. <Table
  22. v-model:currentPage="tableObject.currentPage"
  23. v-model:pageSize="tableObject.pageSize"
  24. :columns="allSchemas.tableColumns"
  25. :data="tableObject.tableList"
  26. :loading="tableObject.loading"
  27. :pagination="{
  28. total: tableObject.total
  29. }"
  30. >
  31. <template #spuId="{ row }">
  32. <el-image
  33. :src="row.picUrl"
  34. class="w-30px h-30px align-middle mr-5px"
  35. @click="imagePreview(row.picUrl)"
  36. />
  37. <span class="align-middle">{{ row.spuName }}</span>
  38. </template>
  39. <template #action="{ row }">
  40. <el-button
  41. v-hasPermi="['promotion:combination-activity:update']"
  42. link
  43. type="primary"
  44. @click="openForm('update', row.id)"
  45. >
  46. 编辑
  47. </el-button>
  48. <el-button
  49. v-hasPermi="['promotion:combination-activity:delete']"
  50. link
  51. type="danger"
  52. @click="handleDelete(row.id)"
  53. >
  54. 删除
  55. </el-button>
  56. </template>
  57. </Table>
  58. </ContentWrap>
  59. <!-- 表单弹窗:添加/修改 -->
  60. <CombinationActivityForm ref="formRef" @success="getList" />
  61. </template>
  62. <script lang="ts" setup>
  63. import { allSchemas } from './combinationActivity.data'
  64. import * as CombinationActivityApi from '@/api/mall/promotion/combination/combinationactivity'
  65. import CombinationActivityForm from './CombinationActivityForm.vue'
  66. import { cloneDeep } from 'lodash-es'
  67. import { createImageViewer } from '@/components/ImageViewer'
  68. defineOptions({ name: 'PromotionCombinationActivity' })
  69. // tableObject:表格的属性对象,可获得分页大小、条数等属性
  70. // tableMethods:表格的操作对象,可进行获得分页、删除记录等操作
  71. // 详细可见:https://doc.iocoder.cn/vue3/crud-schema/
  72. const { tableObject, tableMethods } = useTable({
  73. getListApi: CombinationActivityApi.getCombinationActivityPage, // 分页接口
  74. delListApi: CombinationActivityApi.deleteCombinationActivity // 删除接口
  75. })
  76. // 获得表格的各种操作
  77. const { getList, setSearchParams } = tableMethods
  78. /** 商品图预览 */
  79. const imagePreview = (imgUrl: string) => {
  80. createImageViewer({
  81. urlList: [imgUrl]
  82. })
  83. }
  84. /** 添加/修改操作 */
  85. const formRef = ref()
  86. const openForm = (type: string, id?: number) => {
  87. formRef.value.open(type, id)
  88. }
  89. /** 删除按钮操作 */
  90. const handleDelete = (id: number) => {
  91. tableMethods.delList(id, false)
  92. }
  93. // TODO @puhui999:要不还是使用原生的 element plus 做。感觉 crud schema 复杂界面,做起来麻烦
  94. /** 初始化 **/
  95. onMounted(() => {
  96. /**
  97. TODO
  98. 后面准备封装成一个函数来操作 tableColumns 重新排列:比如说需求是表单上商品选择是在后面的而列表展示的时候需要调到位置。
  99. 封装效果支持批量操作,给出 field 和需要插入的位置,例:[{field:'spuId',index: 1}] 效果为把 field 为 spuId 的 column 移动到第一个位置
  100. */
  101. // 处理一下表格列让商品往前
  102. const index = allSchemas.tableColumns.findIndex((item) => item.field === 'spuId')
  103. const column = cloneDeep(allSchemas.tableColumns[index])
  104. allSchemas.tableColumns.splice(index, 1)
  105. // 添加到开头
  106. allSchemas.tableColumns.unshift(column)
  107. getList()
  108. })
  109. </script>