index.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <template>
  2. <ContentWrap>
  3. <el-tabs v-model="tab" @tab-click="tabClick">
  4. <el-tab-pane v-for="(k, i) in tabList" :key="i" :label="k.label" :name="k.value"/>
  5. </el-tabs>
  6. <div style="text-align: end;">
  7. <el-button @click="getList"><Icon icon="ep:refresh" class="mr-5px" /> 刷 新</el-button>
  8. <el-button type="primary" @click="handleAdd"><Icon icon="ep:plus" class="mr-5px" />新 增</el-button>
  9. </div>
  10. <el-table v-loading="loading" :data="info[tabList[tab].key]" :stripe="true">
  11. <!-- <el-table-column label="排序" align="center" prop="sort" /> -->
  12. <el-table-column label="标题" align="center" prop="title" />
  13. <el-table-column label="图片" align="center" prop="img">
  14. <template #default="scope">
  15. <el-image v-if="scope.row.img" class="h-150px w-200px" :src="scope.row.img" lazy preview-teleported :preview-src-list="info[tabList[tab].key].map(e => e.img)" fit="scale-down" />
  16. </template>
  17. </el-table-column>
  18. <el-table-column label="点击跳转链接" align="center" prop="link">
  19. <template #default="scope">
  20. <el-link v-if="scope.row.link" :href="scope.row.link" type="primary" target="_blank">点击查看</el-link>
  21. </template>
  22. </el-table-column>
  23. <el-table-column label="操作" align="center" fixed="right" min-width="220">
  24. <template #default="scope">
  25. <el-button link type="primary" @click="handleEdit(scope.row.mark)">编辑</el-button>
  26. <el-button link type="danger" @click="handleDelete(scope.row.mark)">删除</el-button>
  27. </template>
  28. </el-table-column>
  29. </el-table>
  30. </ContentWrap>
  31. <!-- 表单弹窗:添加/修改 -->
  32. <WebContentForm ref="formRef" @success="getList" />
  33. </template>
  34. <script setup lang="ts">
  35. import { WebContentApi } from '@/api/menduner/system/web'
  36. import WebContentForm from './WebContentForm.vue'
  37. /** 页面内容 列表 */
  38. defineOptions({ name: 'WebContent' })
  39. const message = useMessage() // 消息弹窗
  40. const { t } = useI18n() // 国际化
  41. const loading = ref(false)
  42. const tab = ref(2)
  43. let info = reactive({})
  44. const tabList = [
  45. { label: 'PC首页左侧广告图', value: 0, key: 'pcLeft' },
  46. { label: 'PC首页弹窗广告图', value: 1, key: 'pcAdvertisement' },
  47. { label: 'PC首页轮播图', value: 2, key: 'pcHomeCarousel' },
  48. { label: 'PC登录页轮播图', value: 3, key: 'pcLoginCarousel' },
  49. { label: '小程序首页轮播图', value: 4, key: 'appHomeCarousel' },
  50. { label: '小程序首页弹窗广告图', value: 5, key: 'appAdvertisement' },
  51. ]
  52. /** 查询列表 */
  53. const getList = async () => {
  54. loading.value = true
  55. try {
  56. const data = await WebContentApi.getWebContent(1)
  57. info = data
  58. } finally {
  59. loading.value = false
  60. }
  61. }
  62. const tabClick = (val) => {
  63. tab.value = val.paneName
  64. getList()
  65. }
  66. const handleAdd = () => {
  67. formRef.value.open('add', tabList[tab.value].key, tabList[tab.value].label)
  68. }
  69. const formRef = ref()
  70. const handleEdit = (mark: string) => {
  71. formRef.value.open('edit', tabList[tab.value].key, tabList[tab.value].label, mark)
  72. }
  73. /** 删除按钮操作 */
  74. const handleDelete = async (mark: string) => {
  75. const index = info[tabList[tab.value].key].findIndex((item) => item.mark === mark)
  76. if (index === -1) return message.warning('图片不存在')
  77. try {
  78. // 删除的二次确认
  79. await message.delConfirm()
  80. // 发起删除
  81. info[tabList[tab.value].key].splice(index, 1)
  82. await WebContentApi.updateWebContent(info)
  83. message.success(t('common.delSuccess'))
  84. // 刷新列表
  85. await getList()
  86. } catch {}
  87. }
  88. /** 初始化 **/
  89. onMounted(() => {
  90. getList()
  91. })
  92. </script>