refactor: 重构录播图管理页面、图片预览组件抽离、useSearchable 组合式函数使用
This commit is contained in:
1 parent
f8fc42dfec
commit
0558261ba7
6 files changed
+77
-121
No files matched your search
Vendored
+2
@@ -8,6 +8,7 @@ export {}
|
|||||||
declare module 'vue' {
|
declare module 'vue' {
|
||||||
export interface GlobalComponents {
|
export interface GlobalComponents {
|
||||||
Copyright: typeof import('./src/components/Copyright.vue')['default']
|
Copyright: typeof import('./src/components/Copyright.vue')['default']
|
||||||
|
ImagePreviewer: typeof import('./src/components/ImagePreviewer.vue')['default']
|
||||||
ImageUpload: typeof import('./src/components/ImageUpload.vue')['default']
|
ImageUpload: typeof import('./src/components/ImageUpload.vue')['default']
|
||||||
RegularPage: typeof import('./src/components/RegularPage.vue')['default']
|
RegularPage: typeof import('./src/components/RegularPage.vue')['default']
|
||||||
RouterLink: typeof import('vue-router')['RouterLink']
|
RouterLink: typeof import('vue-router')['RouterLink']
|
||||||
@@ -22,6 +23,7 @@ declare module 'vue' {
|
|||||||
TFormItem: typeof import('tdesign-vue-next')['FormItem']
|
TFormItem: typeof import('tdesign-vue-next')['FormItem']
|
||||||
THeader: typeof import('tdesign-vue-next')['Header']
|
THeader: typeof import('tdesign-vue-next')['Header']
|
||||||
TIcon: typeof import('tdesign-vue-next')['Icon']
|
TIcon: typeof import('tdesign-vue-next')['Icon']
|
||||||
|
TImage: typeof import('tdesign-vue-next')['Image']
|
||||||
TImageViewer: typeof import('tdesign-vue-next')['ImageViewer']
|
TImageViewer: typeof import('tdesign-vue-next')['ImageViewer']
|
||||||
TInput: typeof import('tdesign-vue-next')['Input']
|
TInput: typeof import('tdesign-vue-next')['Input']
|
||||||
TInputNumber: typeof import('tdesign-vue-next')['InputNumber']
|
TInputNumber: typeof import('tdesign-vue-next')['InputNumber']
|
||||||
|
|||||||
+4
-4
@@ -1,13 +1,13 @@
|
|||||||
import httpClient from './httpClient'
|
import httpClient from './httpClient'
|
||||||
import type { CarousalResult, CreateCarousalsRequest, GetCarousalsRequest } from '@/model/carousals'
|
import type { CarousalResult, CreateCarousalsRequest, SearchCarousalsFilter } from '@/model/carousals'
|
||||||
import type { PageResult } from '@/model/base'
|
import type { PageResult } from '@/model/base'
|
||||||
|
|
||||||
export const createCarousal = (createCarousalsRequest: CreateCarousalsRequest) => {
|
export const createCarousal = (createCarousalsRequest: CreateCarousalsRequest) => {
|
||||||
return httpClient.post<PageResult<CarousalResult>>('/carousals', createCarousalsRequest)
|
return httpClient.post<PageResult<CarousalResult>>('/carousals', createCarousalsRequest)
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getCarousalList = (getCarousalsRequest:GetCarousalsRequest) => {
|
export const searchCarousals = (searchCarousalsFilter: SearchCarousalsFilter) => {
|
||||||
return httpClient.get<PageResult<CarousalResult>>('/carousals',getCarousalsRequest)
|
return httpClient.get<PageResult<CarousalResult>>('/carousals',searchCarousalsFilter)
|
||||||
}
|
}
|
||||||
export const getCarousalItem = (id:string) => {
|
export const getCarousalItem = (id:string) => {
|
||||||
return httpClient.get<CarousalResult>(`/carousals/${id}`)
|
return httpClient.get<CarousalResult>(`/carousals/${id}`)
|
||||||
@@ -27,4 +27,4 @@ export const activeCarousal = (id: string | number) => {
|
|||||||
|
|
||||||
export const inactiveCarousal = (id: string | number ) => {
|
export const inactiveCarousal = (id: string | number ) => {
|
||||||
return httpClient.put<CarousalResult>(`/carousals/${id}/inactive`)
|
return httpClient.put<CarousalResult>(`/carousals/${id}/inactive`)
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
<template>
|
||||||
|
<TImageViewer :images="[url]">
|
||||||
|
<template #trigger="{ open }">
|
||||||
|
<div class="w-[100px] h-[100px] relative flex justify-center items-center rounded overflow-hidden">
|
||||||
|
<img alt="test" :src="url" class="w-full h-full object-contain" />
|
||||||
|
<div class="transition-all hover:opacity-100 opacity-0 w-full h-full absolute top-0 left-0 bg-[#00000099] text-white flex items-center justify-center" @click="open">
|
||||||
|
<span><BrowseIcon size="1.4em" /> 预览</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</TImageViewer>
|
||||||
|
</template>
|
||||||
|
<script setup lang="ts">
|
||||||
|
|
||||||
|
import { BrowseIcon } from 'tdesign-icons-vue-next'
|
||||||
|
|
||||||
|
defineProps<{
|
||||||
|
url: string,
|
||||||
|
}>()
|
||||||
|
|
||||||
|
|
||||||
|
</script>
|
||||||
|
<style scoped>
|
||||||
|
|
||||||
|
</style>
|
||||||
@@ -42,4 +42,9 @@ const slots = defineSlots<{
|
|||||||
</TCard>
|
</TCard>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style scoped></style>
|
<style scoped>
|
||||||
|
:deep(.t-card__body) {
|
||||||
|
flex: 1;
|
||||||
|
min-height: 0;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -6,7 +6,7 @@ export interface CreateCarousalsRequest {
|
|||||||
targetUrl?:string,
|
targetUrl?:string,
|
||||||
targetId?:string
|
targetId?:string
|
||||||
}
|
}
|
||||||
export interface GetCarousalsRequest {
|
export interface SearchCarousalsFilter {
|
||||||
page:number,
|
page:number,
|
||||||
size:number,
|
size:number,
|
||||||
order?:[string]
|
order?:[string]
|
||||||
|
|||||||
+39
-115
@@ -1,84 +1,70 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import RegularPage from '@/components/RegularPage.vue'
|
import RegularPage from '@/components/RegularPage.vue'
|
||||||
import { onMounted, ref, reactive } from 'vue'
|
import { onMounted, ref } from 'vue'
|
||||||
import type { BaseTableColumns } from 'tdesign-vue-next'
|
import type { BaseTableColumns } from 'tdesign-vue-next'
|
||||||
import CarousalDialog from '@/pages/carousal/components/CarousalDialog.vue'
|
import CarousalDialog from '@/pages/carousal/components/CarousalDialog.vue'
|
||||||
import { activeCarousal, deleteCarousal, getCarousalList, inactiveCarousal } from '@/api/carousal'
|
import { activeCarousal, deleteCarousal, searchCarousals, inactiveCarousal } from '@/api/carousal'
|
||||||
import { BrowseIcon } from 'tdesign-icons-vue-next'
|
import type { CarousalResult, SearchCarousalsFilter } from '@/model/carousals'
|
||||||
import type { CarousalResult } from '@/model/carousals'
|
import ImagePreviewer from '@/components/ImagePreviewer.vue'
|
||||||
|
import { useSearchable } from '@/composables/useSearchable'
|
||||||
|
|
||||||
const columns: BaseTableColumns = [
|
const columns: BaseTableColumns = [
|
||||||
{
|
{
|
||||||
title: 'ID',
|
title: 'ID',
|
||||||
colKey: 'id',
|
colKey: 'id',
|
||||||
width: 100,
|
width: 100
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: '轮播图',
|
title: '轮播图',
|
||||||
colKey: 'imageUrl',
|
colKey: 'imageUrl',
|
||||||
width: 100,
|
width: 100
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: '显示状态',
|
title: '显示状态',
|
||||||
colKey: 'status',
|
colKey: 'status',
|
||||||
width: 100,
|
width: 100
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: '操作',
|
title: '操作',
|
||||||
colKey: 'operation',
|
colKey: 'operation',
|
||||||
width: 100,
|
width: 100
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
const loading = ref<boolean>(false)
|
|
||||||
const data = ref<CarousalResult[]>([])
|
const { loading, data, pagination, fetchData, onPageChange } = useSearchable<CarousalResult, SearchCarousalsFilter>(searchCarousals)
|
||||||
const pagination = reactive<{page:number,size:number,total:number}>({
|
onMounted(fetchData)
|
||||||
page: 1,
|
|
||||||
size: 10,
|
|
||||||
total:0
|
|
||||||
})
|
|
||||||
const query = reactive<{page:number,size:number}>({
|
|
||||||
page:1,
|
|
||||||
size:10,
|
|
||||||
})
|
|
||||||
const carousalDialogVisible = ref<boolean>(false)
|
const carousalDialogVisible = ref<boolean>(false)
|
||||||
const isEdit = ref<boolean>(false)
|
const isEdit = ref<boolean>(false)
|
||||||
const currentTableData = ref<CarousalResult | {}>({})
|
const currentTableData = ref<CarousalResult | null>(null)
|
||||||
const fetchSaveCarousalData = async () :Promise<void> => {
|
|
||||||
/* TODO: 获取轮播图表格数据 */
|
|
||||||
query.page = pagination.page
|
const editClick = (row: object): void => {
|
||||||
query.size = pagination.size
|
|
||||||
const getCarousalListApi = await getCarousalList(query)
|
|
||||||
data.value = getCarousalListApi.data
|
|
||||||
pagination.total = getCarousalListApi.pagination.total
|
|
||||||
}
|
|
||||||
onMounted(fetchSaveCarousalData)
|
|
||||||
const editClick = (row:object):void => {
|
|
||||||
isEdit.value = true
|
isEdit.value = true
|
||||||
currentTableData.value = Object.assign({}, row)
|
currentTableData.value = Object.assign({}, row)
|
||||||
carousalDialogVisible.value = true
|
carousalDialogVisible.value = true
|
||||||
}
|
}
|
||||||
const showClick = async (res:CarousalResult):Promise<void> => {
|
const showClick = async (res: CarousalResult): Promise<void> => {
|
||||||
if (res.status === 'active'){
|
if (res.status === 'active') {
|
||||||
await inactiveCarousal(res.id)
|
await inactiveCarousal(res.id)
|
||||||
} else {
|
} else {
|
||||||
await activeCarousal(res.id)
|
await activeCarousal(res.id)
|
||||||
}
|
}
|
||||||
await fetchSaveCarousalData()
|
await fetchData()
|
||||||
}
|
}
|
||||||
const delClick = async (row:CarousalResult) :Promise<void>=> {
|
const delClick = async (row: CarousalResult): Promise<void> => {
|
||||||
await deleteCarousal(row.id)
|
await deleteCarousal(row.id)
|
||||||
await fetchSaveCarousalData()
|
await fetchData()
|
||||||
}
|
}
|
||||||
const handleCreateCarousal = () :void => {
|
const handleCreateCarousal = (): void => {
|
||||||
isEdit.value = false
|
isEdit.value = false
|
||||||
carousalDialogVisible.value = true
|
carousalDialogVisible.value = true
|
||||||
currentTableData.value = {}
|
currentTableData.value = {}
|
||||||
}
|
}
|
||||||
const onPageChange = ():void => {
|
|
||||||
/* TODO: 分页切换 */
|
const handleSuccessDialog = async (): Promise<void> => {
|
||||||
}
|
await fetchData()
|
||||||
const handleSuccessDialog = async () :Promise<void> => {
|
|
||||||
await fetchSaveCarousalData()
|
|
||||||
carousalDialogVisible.value = false
|
carousalDialogVisible.value = false
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
@@ -91,8 +77,8 @@ const handleSuccessDialog = async () :Promise<void> => {
|
|||||||
<TTable
|
<TTable
|
||||||
class="w-full h-full"
|
class="w-full h-full"
|
||||||
row-key="id"
|
row-key="id"
|
||||||
height="92%"
|
|
||||||
table-layout="auto"
|
table-layout="auto"
|
||||||
|
height="92%"
|
||||||
:data="data"
|
:data="data"
|
||||||
:loading="loading"
|
:loading="loading"
|
||||||
:columns="columns"
|
:columns="columns"
|
||||||
@@ -105,35 +91,28 @@ const handleSuccessDialog = async () :Promise<void> => {
|
|||||||
onChange: onPageChange
|
onChange: onPageChange
|
||||||
}"
|
}"
|
||||||
>
|
>
|
||||||
<template #imageUrl="{row}">
|
<template #imageUrl="{ row }">
|
||||||
<div class="tdesign-demo-image-viewer__base">
|
<ImagePreviewer :url="row.imageUrl"/>
|
||||||
<t-image-viewer :images="[row.imageUrl]">
|
|
||||||
<template #trigger="{ open }">
|
|
||||||
<div class="tdesign-demo-image-viewer__ui-image">
|
|
||||||
<img alt="test" :src="row.imageUrl" class="tdesign-demo-image-viewer__ui-image--img" />
|
|
||||||
<div class="tdesign-demo-image-viewer__ui-image--hover" @click="open">
|
|
||||||
<span><BrowseIcon size="1.4em" /> 预览</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
</t-image-viewer>
|
|
||||||
</div>
|
|
||||||
</template>
|
</template>
|
||||||
<template #status="{row}">
|
<template #status="{ row }">
|
||||||
<TSpace>
|
<TSpace>
|
||||||
<TTag :theme="row.status === 'active' ? 'success' : 'danger'" variant="light">{{row.status === 'active' ? '显示中' : '已关闭'}}</TTag>
|
<TTag :theme="row.status === 'active' ? 'success' : 'danger'" variant="light">{{
|
||||||
|
row.status === 'active' ? '显示中' : '已关闭'
|
||||||
|
}}</TTag>
|
||||||
</TSpace>
|
</TSpace>
|
||||||
</template>
|
</template>
|
||||||
<template #roles="{ row }">
|
<template #roles="{ row }">
|
||||||
<TSpace>
|
<TSpace>
|
||||||
<TTag v-for="role in row.roles" :key="role.id" theme="success" variant="light">{{
|
<TTag v-for="role in row.roles" :key="role.id" theme="success" variant="light">{{
|
||||||
role.label
|
role.label
|
||||||
}}</TTag>
|
}}</TTag>
|
||||||
</TSpace>
|
</TSpace>
|
||||||
</template>
|
</template>
|
||||||
<template #operation="{ row }">
|
<template #operation="{ row }">
|
||||||
<TButton variant="text" size="small" theme="primary" @click="editClick(row)">编辑</TButton>
|
<TButton variant="text" size="small" theme="primary" @click="editClick(row)">编辑</TButton>
|
||||||
<TButton variant="text" size="small" theme="primary" @click="showClick(row)">{{ row.status === 'active' ? '关闭显示' : '开启显示'}}</TButton>
|
<TButton variant="text" size="small" theme="primary" @click="showClick(row)">{{
|
||||||
|
row.status === 'active' ? '关闭显示' : '开启显示'
|
||||||
|
}}</TButton>
|
||||||
<TButton variant="text" size="small" theme="danger" @click="delClick(row)">删除</TButton>
|
<TButton variant="text" size="small" theme="danger" @click="delClick(row)">删除</TButton>
|
||||||
</template>
|
</template>
|
||||||
</TTable>
|
</TTable>
|
||||||
@@ -148,60 +127,5 @@ const handleSuccessDialog = async () :Promise<void> => {
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
:deep(.t-card__body) {
|
|
||||||
flex: 1;
|
|
||||||
min-height: 0;
|
|
||||||
}
|
|
||||||
.tdesign-demo-image-viewer__ui-image {
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
display: inline-flex;
|
|
||||||
position: relative;
|
|
||||||
justify-content: center;
|
|
||||||
align-items: center;
|
|
||||||
border-radius: var(--td-radius-small);
|
|
||||||
overflow: hidden;
|
|
||||||
}
|
|
||||||
|
|
||||||
.tdesign-demo-image-viewer__ui-image--hover {
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
display: flex;
|
|
||||||
justify-content: center;
|
|
||||||
align-items: center;
|
|
||||||
position: absolute;
|
|
||||||
left: 0;
|
|
||||||
top: 0;
|
|
||||||
opacity: 0;
|
|
||||||
background-color: rgba(0, 0, 0, 0.6);
|
|
||||||
color: var(--td-text-color-anti);
|
|
||||||
line-height: 22px;
|
|
||||||
transition: 0.2s;
|
|
||||||
}
|
|
||||||
|
|
||||||
.tdesign-demo-image-viewer__ui-image:hover .tdesign-demo-image-viewer__ui-image--hover {
|
|
||||||
opacity: 1;
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
|
|
||||||
.tdesign-demo-image-viewer__ui-image--img {
|
|
||||||
width: auto;
|
|
||||||
height: auto;
|
|
||||||
max-width: 100%;
|
|
||||||
max-height: 100%;
|
|
||||||
cursor: pointer;
|
|
||||||
position: absolute;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
.tdesign-demo-image-viewer__ui-image--icons .tdesign-demo-icon {
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
|
|
||||||
.tdesign-demo-image-viewer__base {
|
|
||||||
width: 100px;
|
|
||||||
height: 100px;
|
|
||||||
border: 4px solid var(--td-bg-color-secondarycontainer);
|
|
||||||
border-radius: var(--td-radius-medium);
|
|
||||||
}
|
|
||||||
</style>
|
</style>
|
||||||
Reference in new issue
Block a user