index.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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:seckill-config: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 #sliderPicUrls="{ row }">
  32. <el-image
  33. v-for="(item, index) in row.sliderPicUrls"
  34. :key="index"
  35. :src="item"
  36. class="w-60px h-60px mr-10px"
  37. @click="imagePreview(row.sliderPicUrls)"
  38. />
  39. </template>
  40. <template #status="{ row }">
  41. <el-switch
  42. v-model="row.status"
  43. :active-value="0"
  44. :inactive-value="1"
  45. @change="handleStatusChange(row)"
  46. />
  47. </template>
  48. <template #action="{ row }">
  49. <el-button
  50. v-hasPermi="['promotion:seckill-config:update']"
  51. link
  52. type="primary"
  53. @click="openForm('update', row.id)"
  54. >
  55. 编辑
  56. </el-button>
  57. <el-button
  58. v-hasPermi="['promotion:seckill-config:delete']"
  59. link
  60. type="danger"
  61. @click="handleDelete(row.id)"
  62. >
  63. 删除
  64. </el-button>
  65. </template>
  66. </Table>
  67. </ContentWrap>
  68. <!-- 表单弹窗:添加/修改 -->
  69. <SeckillConfigForm ref="formRef" @success="getList" />
  70. </template>
  71. <script lang="ts" name="PromotionSeckillConfig" setup>
  72. import { allSchemas } from './seckillConfig.data'
  73. import * as SeckillConfigApi from '@/api/mall/promotion/seckill/seckillConfig'
  74. import SeckillConfigForm from './SeckillConfigForm.vue'
  75. import { createImageViewer } from '@/components/ImageViewer'
  76. import { CommonStatusEnum } from '@/utils/constants'
  77. import { isArray } from '@/utils/is'
  78. const message = useMessage() // 消息弹窗
  79. // tableObject:表格的属性对象,可获得分页大小、条数等属性
  80. // tableMethods:表格的操作对象,可进行获得分页、删除记录等操作
  81. // 详细可见:https://doc.iocoder.cn/vue3/crud-schema/
  82. const { tableObject, tableMethods } = useTable({
  83. getListApi: SeckillConfigApi.getSeckillConfigPage, // 分页接口
  84. delListApi: SeckillConfigApi.deleteSeckillConfig // 删除接口
  85. })
  86. // 获得表格的各种操作
  87. const { getList, setSearchParams } = tableMethods
  88. /** 轮播图预览预览 */
  89. const imagePreview = (args) => {
  90. const urlList = []
  91. if (isArray(args)) {
  92. args.forEach((item) => {
  93. urlList.push(item)
  94. })
  95. } else {
  96. urlList.push(args)
  97. }
  98. createImageViewer({
  99. urlList
  100. })
  101. }
  102. /** 添加/修改操作 */
  103. const formRef = ref()
  104. const openForm = (type: string, id?: number) => {
  105. formRef.value.open(type, id)
  106. }
  107. /** 删除按钮操作 */
  108. const handleDelete = (id: number) => {
  109. tableMethods.delList(id, false)
  110. }
  111. /** 修改用户状态 */
  112. const handleStatusChange = async (row: SeckillConfigApi.SeckillConfigVO) => {
  113. try {
  114. // 修改状态的二次确认
  115. const text = row.status === CommonStatusEnum.ENABLE ? '启用' : '停用'
  116. await message.confirm('确认要"' + text + '""' + row.name + '?')
  117. // 发起修改状态
  118. await SeckillConfigApi.updateSeckillConfigStatus(row.id, row.status)
  119. // 刷新列表
  120. await getList()
  121. } catch {
  122. // 取消后,进行恢复按钮
  123. row.status =
  124. row.status === CommonStatusEnum.ENABLE ? CommonStatusEnum.DISABLE : CommonStatusEnum.ENABLE
  125. }
  126. }
  127. /** 初始化 **/
  128. onMounted(() => {
  129. getList()
  130. })
  131. </script>