index.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <script setup lang="ts">
  2. import RegularPage from '@/components/RegularPage.vue'
  3. import { onMounted, ref, reactive } from 'vue'
  4. import type { BaseTableColumns } from 'tdesign-vue-next'
  5. import CarousalDialog from '@/pages/carousal/components/CarousalDialog.vue'
  6. import { activeCarousal, deleteCarousal, getCarousalList, inactiveCarousal } from '@/api/carousal'
  7. import { BrowseIcon } from 'tdesign-icons-vue-next'
  8. const columns: BaseTableColumns = [
  9. {
  10. title: 'ID',
  11. colKey: 'id',
  12. width: 100,
  13. },
  14. {
  15. title: '轮播图',
  16. colKey: 'imageUrl',
  17. width: 100,
  18. },
  19. {
  20. title: '显示状态',
  21. colKey: 'status',
  22. width: 100,
  23. },
  24. {
  25. title: '操作',
  26. colKey: 'operation',
  27. width: 100,
  28. }
  29. ]
  30. const loading = ref(false)
  31. const data = ref([])
  32. const pagination = reactive({
  33. page: 1,
  34. size: 10,
  35. total:0
  36. })
  37. const query = reactive({
  38. page:1,
  39. size:10,
  40. })
  41. const carousalDialogVisible = ref(false)
  42. const isEdit = ref(false)
  43. const currentTableData = ref<{}>({})
  44. const fetchSaveCarousalData = async () => {
  45. /* TODO: 获取轮播图表格数据 */
  46. query.page = pagination.page
  47. query.size = pagination.size
  48. const getCarousalListApi = await getCarousalList(query)
  49. data.value = getCarousalListApi.data
  50. pagination.total = getCarousalListApi.pagination.total
  51. }
  52. onMounted(fetchSaveCarousalData)
  53. const editClick = (row:object) => {
  54. isEdit.value = true
  55. currentTableData.value = Object.assign({}, row)
  56. carousalDialogVisible.value = true
  57. }
  58. const showClick = async (res:object) => {
  59. if (res.status === 'active'){
  60. await inactiveCarousal(res.id)
  61. } else {
  62. await activeCarousal(res.id)
  63. }
  64. await fetchSaveCarousalData()
  65. }
  66. const delClick = async (row:object) => {
  67. console.log(row,'删除')
  68. await deleteCarousal(row.id)
  69. await fetchSaveCarousalData()
  70. }
  71. const handleCreateCarousal = () => {
  72. isEdit.value = false
  73. carousalDialogVisible.value = true
  74. currentTableData.value = {}
  75. }
  76. const onPageChange = () => {
  77. /* TODO: 分页切换 */
  78. }
  79. const handleSuccessDialog = async () => {
  80. await fetchSaveCarousalData()
  81. carousalDialogVisible.value = false
  82. }
  83. </script>
  84. <template>
  85. <RegularPage title="轮播图管理">
  86. <template #right-area>
  87. <TButton @click="handleCreateCarousal">创建轮播图</TButton>
  88. </template>
  89. <TTable
  90. class="w-full h-full"
  91. row-key="id"
  92. height="92%"
  93. table-layout="auto"
  94. :data="data"
  95. :loading="loading"
  96. :columns="columns"
  97. cell-empty-content="-"
  98. :paginationAffixedBottom="true"
  99. :pagination="{
  100. total: pagination.total,
  101. current: pagination.page,
  102. pageSize: pagination.size,
  103. onChange: onPageChange
  104. }"
  105. >
  106. <template #imageUrl="{row}">
  107. <div class="tdesign-demo-image-viewer__base">
  108. <t-image-viewer :images="[row.imageUrl]">
  109. <template #trigger="{ open }">
  110. <div class="tdesign-demo-image-viewer__ui-image">
  111. <img alt="test" :src="row.imageUrl" class="tdesign-demo-image-viewer__ui-image--img" />
  112. <div class="tdesign-demo-image-viewer__ui-image--hover" @click="open">
  113. <span><BrowseIcon size="1.4em" /> 预览</span>
  114. </div>
  115. </div>
  116. </template>
  117. </t-image-viewer>
  118. </div>
  119. </template>
  120. <template #status="{row}">
  121. <TSpace>
  122. <TTag :theme="row.status === 'active' ? 'success' : 'danger'" variant="light">{{row.status === 'active' ? '显示中' : '已关闭'}}</TTag>
  123. </TSpace>
  124. </template>
  125. <template #roles="{ row }">
  126. <TSpace>
  127. <TTag v-for="role in row.roles" :key="role.id" theme="success" variant="light">{{
  128. role.label
  129. }}</TTag>
  130. </TSpace>
  131. </template>
  132. <template #operation="{ row }">
  133. <TButton variant="text" size="small" theme="primary" @click="editClick(row)">编辑</TButton>
  134. <TButton variant="text" size="small" theme="primary" @click="showClick(row)">{{ row.status === 'active' ? '关闭显示' : '开启显示'}}</TButton>
  135. <TButton variant="text" size="small" theme="danger" @click="delClick(row)">删除</TButton>
  136. </template>
  137. </TTable>
  138. <CarousalDialog
  139. :carousal="currentTableData"
  140. v-model:visible="carousalDialogVisible"
  141. :isEdit="isEdit"
  142. @success="handleSuccessDialog"
  143. headerTitle="轮播图"
  144. ></CarousalDialog>
  145. </RegularPage>
  146. </template>
  147. <style scoped>
  148. :deep(.t-card__body) {
  149. flex: 1;
  150. min-height: 0;
  151. }
  152. .tdesign-demo-image-viewer__ui-image {
  153. width: 100%;
  154. height: 100%;
  155. display: inline-flex;
  156. position: relative;
  157. justify-content: center;
  158. align-items: center;
  159. border-radius: var(--td-radius-small);
  160. overflow: hidden;
  161. }
  162. .tdesign-demo-image-viewer__ui-image--hover {
  163. width: 100%;
  164. height: 100%;
  165. display: flex;
  166. justify-content: center;
  167. align-items: center;
  168. position: absolute;
  169. left: 0;
  170. top: 0;
  171. opacity: 0;
  172. background-color: rgba(0, 0, 0, 0.6);
  173. color: var(--td-text-color-anti);
  174. line-height: 22px;
  175. transition: 0.2s;
  176. }
  177. .tdesign-demo-image-viewer__ui-image:hover .tdesign-demo-image-viewer__ui-image--hover {
  178. opacity: 1;
  179. cursor: pointer;
  180. }
  181. .tdesign-demo-image-viewer__ui-image--img {
  182. width: auto;
  183. height: auto;
  184. max-width: 100%;
  185. max-height: 100%;
  186. cursor: pointer;
  187. position: absolute;
  188. }
  189. .tdesign-demo-image-viewer__ui-image--icons .tdesign-demo-icon {
  190. cursor: pointer;
  191. }
  192. .tdesign-demo-image-viewer__base {
  193. width: 100px;
  194. height: 100px;
  195. border: 4px solid var(--td-bg-color-secondarycontainer);
  196. border-radius: var(--td-radius-medium);
  197. }
  198. </style>