index.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <template>
  2. <doc-alert title="【营销】商城装修" url="https://doc.iocoder.cn/mall/diy/" />
  3. <ContentWrap>
  4. <!-- 搜索工作栏 -->
  5. <el-form
  6. class="-mb-15px"
  7. :model="queryParams"
  8. ref="queryFormRef"
  9. :inline="true"
  10. label-width="68px"
  11. >
  12. <el-form-item label="页面名称" prop="name">
  13. <el-input
  14. v-model="queryParams.name"
  15. placeholder="请输入页面名称"
  16. clearable
  17. @keyup.enter="handleQuery"
  18. class="!w-240px"
  19. />
  20. </el-form-item>
  21. <el-form-item label="创建时间" prop="createTime">
  22. <el-date-picker
  23. v-model="queryParams.createTime"
  24. value-format="YYYY-MM-DD HH:mm:ss"
  25. type="daterange"
  26. start-placeholder="开始日期"
  27. end-placeholder="结束日期"
  28. :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
  29. class="!w-240px"
  30. />
  31. </el-form-item>
  32. <el-form-item>
  33. <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
  34. <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
  35. <el-button
  36. type="primary"
  37. plain
  38. @click="openForm('create')"
  39. v-hasPermi="['promotion:diy-page:create']"
  40. >
  41. <Icon icon="ep:plus" class="mr-5px" /> 新增
  42. </el-button>
  43. </el-form-item>
  44. </el-form>
  45. </ContentWrap>
  46. <!-- 列表 -->
  47. <ContentWrap>
  48. <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
  49. <el-table-column label="编号" align="center" prop="id" />
  50. <el-table-column label="预览图" align="center" prop="previewPicUrls">
  51. <template #default="scope">
  52. <el-image
  53. class="h-40px max-w-40px"
  54. v-for="(url, index) in scope.row.previewPicUrls"
  55. :key="index"
  56. :src="url"
  57. :preview-src-list="scope.row.previewPicUrls"
  58. :initial-index="index"
  59. preview-teleported
  60. />
  61. </template>
  62. </el-table-column>
  63. <el-table-column label="页面名称" align="center" prop="name" />
  64. <el-table-column label="备注" align="center" prop="remark" />
  65. <el-table-column
  66. label="创建时间"
  67. align="center"
  68. prop="createTime"
  69. :formatter="dateFormatter"
  70. width="180px"
  71. />
  72. <el-table-column label="操作" align="center">
  73. <template #default="scope">
  74. <el-button
  75. link
  76. type="primary"
  77. @click="handleDecorate(scope.row.id)"
  78. v-hasPermi="['promotion:diy-page:update']"
  79. >
  80. 装修
  81. </el-button>
  82. <el-button
  83. link
  84. type="primary"
  85. @click="openForm('update', scope.row.id)"
  86. v-hasPermi="['promotion:diy-page:update']"
  87. >
  88. 编辑
  89. </el-button>
  90. <el-button
  91. link
  92. type="danger"
  93. @click="handleDelete(scope.row.id)"
  94. v-hasPermi="['promotion:diy-page:delete']"
  95. >
  96. 删除
  97. </el-button>
  98. </template>
  99. </el-table-column>
  100. </el-table>
  101. <!-- 分页 -->
  102. <Pagination
  103. :total="total"
  104. v-model:page="queryParams.pageNo"
  105. v-model:limit="queryParams.pageSize"
  106. @pagination="getList"
  107. />
  108. </ContentWrap>
  109. <!-- 表单弹窗:添加/修改 -->
  110. <DiyPageForm ref="formRef" @success="getList" />
  111. </template>
  112. <script setup lang="ts">
  113. import { dateFormatter } from '@/utils/formatTime'
  114. import * as DiyPageApi from '@/api/mall/promotion/diy/page'
  115. import DiyPageForm from './DiyPageForm.vue'
  116. /** 装修页面 */
  117. defineOptions({ name: 'DiyPage' })
  118. const message = useMessage() // 消息弹窗
  119. const { t } = useI18n() // 国际化
  120. const loading = ref(true) // 列表的加载中
  121. const total = ref(0) // 列表的总页数
  122. const list = ref([]) // 列表的数据
  123. const queryParams = reactive({
  124. pageNo: 1,
  125. pageSize: 10,
  126. name: null,
  127. createTime: []
  128. })
  129. const queryFormRef = ref() // 搜索的表单
  130. /** 查询列表 */
  131. const getList = async () => {
  132. loading.value = true
  133. try {
  134. const data = await DiyPageApi.getDiyPagePage(queryParams)
  135. list.value = data.list
  136. total.value = data.total
  137. } finally {
  138. loading.value = false
  139. }
  140. }
  141. /** 搜索按钮操作 */
  142. const handleQuery = () => {
  143. queryParams.pageNo = 1
  144. getList()
  145. }
  146. /** 重置按钮操作 */
  147. const resetQuery = () => {
  148. queryFormRef.value.resetFields()
  149. handleQuery()
  150. }
  151. /** 添加/修改操作 */
  152. const formRef = ref()
  153. const openForm = (type: string, id?: number) => {
  154. formRef.value.open(type, id)
  155. }
  156. /** 删除按钮操作 */
  157. const handleDelete = async (id: number) => {
  158. try {
  159. // 删除的二次确认
  160. await message.delConfirm()
  161. // 发起删除
  162. await DiyPageApi.deleteDiyPage(id)
  163. message.success(t('common.delSuccess'))
  164. // 刷新列表
  165. await getList()
  166. } catch {}
  167. }
  168. /** 打开装修页面 */
  169. const { push } = useRouter()
  170. const handleDecorate = (id: number) => {
  171. push({ name: 'DiyPageDecorate', params: { id } })
  172. }
  173. /** 初始化 **/
  174. onMounted(() => {
  175. getList()
  176. })
  177. </script>