support tablet
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
<template>
|
||||
<div class="page-layout navbar product-list">
|
||||
<div class="tui-page-layout tui-navbar product-list">
|
||||
<t-navbar
|
||||
fixed
|
||||
:z-index="20"
|
||||
@@ -18,100 +18,125 @@
|
||||
/>
|
||||
</template>
|
||||
</t-navbar>
|
||||
<main ref="productListRef" v-can="permissionCodes.product.read" class="page-content scroll column list">
|
||||
<t-pull-down-refresh
|
||||
class="pull-refresh"
|
||||
v-model="isRefreshing"
|
||||
:refresh-timeout="30000"
|
||||
@refresh="refresh"
|
||||
@scrolltolower="loadMore"
|
||||
>
|
||||
<div class="filters glass">
|
||||
<t-input
|
||||
v-model="keyword"
|
||||
class="keyword"
|
||||
type="search"
|
||||
borderless
|
||||
placeholder="搜索产品名称(拼音)或编码"
|
||||
/>
|
||||
<t-dropdown-menu class="menus">
|
||||
<t-dropdown-item
|
||||
v-model="status"
|
||||
label="状态"
|
||||
:options="statusOptions"
|
||||
@change="selectStatus"
|
||||
/>
|
||||
<t-dropdown-item
|
||||
v-model="productType"
|
||||
label="类型"
|
||||
:options="productTypeOptions"
|
||||
@change="selectProductType"
|
||||
/>
|
||||
<t-dropdown-item
|
||||
:model-value="categoryIdList"
|
||||
label="分类"
|
||||
:options="categoryOptions"
|
||||
multiple
|
||||
:options-columns="2"
|
||||
@change="selectCategory"
|
||||
@confirm="confirmCategory"
|
||||
@reset="resetCategory"
|
||||
@update:model-value="updateCategory"
|
||||
/>
|
||||
</t-dropdown-menu>
|
||||
</div>
|
||||
<t-cell-group
|
||||
v-if="productList.length"
|
||||
class="list fix-last-cell-line empty-cell-title-margin"
|
||||
theme="card"
|
||||
<master-detail-page
|
||||
ref="productListRef"
|
||||
v-can="permissionCodes.product.read"
|
||||
class="list"
|
||||
:split="isWide"
|
||||
:selected="!!selectedId"
|
||||
:direction="paneDirection"
|
||||
>
|
||||
<template #master>
|
||||
<t-pull-down-refresh
|
||||
class="pull-refresh"
|
||||
v-model="isRefreshing"
|
||||
:refresh-timeout="30000"
|
||||
@refresh="refresh"
|
||||
@scrolltolower="loadMore"
|
||||
>
|
||||
<t-cell v-for="item in productList" :key="item.id" class="item" arrow hover v-entrance-transition="{ step: 30 }" @click="toDetail(item)">
|
||||
<template #leftIcon>
|
||||
<t-image
|
||||
v-if="getProductPhotoURL(item)"
|
||||
:src="getProductPhotoURL(item)"
|
||||
:alt="item.name || '产品图片'"
|
||||
fit="cover"
|
||||
class="avatar"
|
||||
<div class="filters glass">
|
||||
<t-input
|
||||
v-model="keyword"
|
||||
class="keyword"
|
||||
type="search"
|
||||
borderless
|
||||
placeholder="搜索产品名称(拼音)或编码"
|
||||
/>
|
||||
<t-dropdown-menu class="menus">
|
||||
<t-dropdown-item
|
||||
v-model="status"
|
||||
label="状态"
|
||||
:options="statusOptions"
|
||||
@change="selectStatus"
|
||||
/>
|
||||
<div
|
||||
v-else
|
||||
class="avatar fallback"
|
||||
v-text="(item.name || '产').slice(0, 1)"
|
||||
<t-dropdown-item
|
||||
v-model="productType"
|
||||
label="类型"
|
||||
:options="productTypeOptions"
|
||||
@change="selectProductType"
|
||||
/>
|
||||
</template>
|
||||
<template #title>
|
||||
<div class="text-bold" v-text="item.name || '未命名产品'" />
|
||||
</template>
|
||||
<template #note>
|
||||
<t-tag
|
||||
size="small"
|
||||
variant="outline"
|
||||
:theme="getProductStatusTheme(item.status)"
|
||||
:content="getProductStatusText(item.status)"
|
||||
<t-dropdown-item
|
||||
:model-value="categoryIdList"
|
||||
label="分类"
|
||||
:options="categoryOptions"
|
||||
multiple
|
||||
:options-columns="2"
|
||||
@change="selectCategory"
|
||||
@confirm="confirmCategory"
|
||||
@reset="resetCategory"
|
||||
@update:model-value="updateCategory"
|
||||
/>
|
||||
</template>
|
||||
<template #description>
|
||||
<div class="description">
|
||||
</t-dropdown-menu>
|
||||
</div>
|
||||
<t-cell-group
|
||||
v-if="productList.length"
|
||||
class="list fix-last-cell-line empty-cell-title-margin"
|
||||
theme="card"
|
||||
>
|
||||
<t-cell v-for="item in productList" :key="item.id" class="item" arrow hover v-entrance-transition="{ step: 30 }" @click="toDetail(item)">
|
||||
<template #leftIcon>
|
||||
<t-image
|
||||
v-if="getProductPhotoURL(item)"
|
||||
:src="getProductPhotoURL(item)"
|
||||
:alt="item.name || '产品图片'"
|
||||
fit="cover"
|
||||
class="avatar"
|
||||
/>
|
||||
<div
|
||||
v-else
|
||||
class="avatar fallback"
|
||||
v-text="(item.name || '产').slice(0, 1)"
|
||||
/>
|
||||
</template>
|
||||
<template #title>
|
||||
<div class="text-bold" v-text="item.name || '未命名产品'" />
|
||||
</template>
|
||||
<template #note>
|
||||
<t-tag
|
||||
size="small"
|
||||
variant="outline"
|
||||
:content="getProductTypeText(item.productType)"
|
||||
:theme="getProductStatusTheme(item.status)"
|
||||
:content="getProductStatusText(item.status)"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
</t-cell>
|
||||
</t-cell-group>
|
||||
<center-tips v-else :content="emptyText" />
|
||||
<center-tips v-if="productList.length" :content="isLoading ? '正在加载更多' : isNoMore ? '已经到底了' : '上拉加载更多'" />
|
||||
</t-pull-down-refresh>
|
||||
</main>
|
||||
</template>
|
||||
<template #description>
|
||||
<div class="description">
|
||||
<t-tag
|
||||
size="small"
|
||||
variant="outline"
|
||||
:content="getProductTypeText(item.productType)"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
</t-cell>
|
||||
</t-cell-group>
|
||||
<center-tips v-else :content="emptyText" />
|
||||
<center-tips v-if="productList.length" :content="isLoading ? '正在加载更多' : isNoMore ? '已经到底了' : '上拉加载更多'" />
|
||||
</t-pull-down-refresh>
|
||||
</template>
|
||||
<template #detail>
|
||||
<product-edit
|
||||
v-if="editing"
|
||||
:key="`edit-${selectedId}`"
|
||||
:product-id="selectedId"
|
||||
/>
|
||||
<product-detail
|
||||
v-else
|
||||
:key="`detail-${selectedId}-${detailVersion}`"
|
||||
:product-id="selectedId"
|
||||
@edit="openEdit"
|
||||
/>
|
||||
</template>
|
||||
</master-detail-page>
|
||||
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { type DropdownValue } from "tdesign-mobile-vue";
|
||||
import { MasterDetailPage, useMasterDetailPane } from "timi-tdesign-mobile";
|
||||
import ProductDetail from "@/pages/product/ProductDetail.vue";
|
||||
import ProductEdit from "@/pages/product/ProductEdit.vue";
|
||||
import { useUserStore } from "timi-web-api";
|
||||
import { onBeforeRouteLeave } from "vue-router";
|
||||
import ProductAPI from "@/api/ProductAPI";
|
||||
@@ -124,9 +149,18 @@ import { permissionCodes } from "@/utils/permission";
|
||||
|
||||
defineOptions({ name: "ProductList" });
|
||||
|
||||
|
||||
const router = useRouter();
|
||||
const route = useRoute();
|
||||
const productListRef = ref<HTMLElement | null>(null);
|
||||
|
||||
// 选中项、编辑态、切换方向、关闭逻辑、转屏、query 同步都在这里
|
||||
const { selectedId, editing, detailVersion, paneDirection, isWide, openDetail, openEdit } =
|
||||
useMasterDetailPane({
|
||||
path: "/management/products",
|
||||
detail: id => `/management/products/${id}`,
|
||||
edit: id => `/management/products/${id}/edit`
|
||||
});
|
||||
const productListRef = ref<ComponentPublicInstance | null>(null);
|
||||
const userStore = useUserStore();
|
||||
const canCreate = computed(() => userStore.hasPermissions(permissionCodes.product.create));
|
||||
|
||||
@@ -150,7 +184,7 @@ let unregisterProductListEvent: (() => void) | undefined;
|
||||
let isDisposed = false;
|
||||
|
||||
function getProductListPage(): HTMLElement | null {
|
||||
return productListRef.value?.querySelector<HTMLElement>(".pull-refresh") || null;
|
||||
return (productListRef.value?.$el as HTMLElement | undefined)?.querySelector<HTMLElement>(".pull-refresh") || null;
|
||||
}
|
||||
|
||||
function savePageScrollPosition(): void {
|
||||
@@ -383,9 +417,7 @@ async function toCreate(): Promise<void> {
|
||||
}
|
||||
|
||||
async function toDetail(item: Product): Promise<void> {
|
||||
if (item.id) {
|
||||
await router.push(`/management/products/${item.id}`);
|
||||
}
|
||||
openDetail(item.id || "");
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
@@ -435,7 +467,7 @@ onUnmounted(() => {
|
||||
|
||||
<style scoped lang="less">
|
||||
.product-list {
|
||||
padding: var(--app-nav-height) 0 1rem;
|
||||
padding: var(--tui-nav-height) 0 1rem;
|
||||
|
||||
|
||||
.list {
|
||||
|
||||
Reference in New Issue
Block a user