update Tag style

This commit is contained in:
Timi
2026-10-21 21:02:54 +08:00
parent c870bcdd39
commit 3fc295acb2
4 changed files with 248 additions and 277 deletions
@@ -38,7 +38,7 @@ const emit = defineEmits<{
edit: [];
}>();
const maxRowCount = 3;
const maxRowCount = 2;
const tagRowList = computed(() => {
const rowCount = Math.min(maxRowCount, props.tagList.length);
const rowList = Array.from({ length: rowCount }, () => [] as Tag[]);
+200 -69
View File
@@ -6,7 +6,19 @@
title="标签详情"
left-arrow
@left-click="$router.back()"
/>
>
<template #right>
<t-button
v-if="canDeleteTag && tag"
theme="danger"
variant="text"
size="small"
:disabled="isDeletingTag"
content="删除"
@click="openDeleteDialog"
/>
</template>
</t-navbar>
<main v-can="corePermissionCodes.tag.read" class="page-content scroll list">
<t-pull-down-refresh
class="pull-refresh"
@@ -15,78 +27,80 @@
@refresh="refresh"
@scrolltolower="loadMore"
>
<section v-if="tag" class="tag-card">
<div class="field">
<span class="label">标签名称</span>
<t-input
v-model.trim="tagName"
class="name-input"
borderless
:readonly="!canUpdateTag"
placeholder="请输入标签名称"
/>
<t-button
v-if="canUpdateTag"
class="save"
theme="primary"
size="small"
:loading="isSaving"
:disabled="!isNameChanged || isSaving"
@click="saveTag"
>
保存
</t-button>
</div>
<div class="usage" v-text="tagUsageText" />
</section>
<center-tips v-else :content="isTagLoading ? '正在加载标签' : '标签不存在或无权查看'" />
<section v-if="canReadCustomer" class="customer-section">
<div class="head">
<h2 class="title" v-text="`使用客户(${tag?.useCount ?? 0})`" />
<t-button
v-if="canManageTagCustomers"
size="small"
theme="primary"
:disabled="!tagId || isApplyingTag"
@click="customerSelectorVisible = true"
>
添加客户
</t-button>
</div>
<div class="filters glass" v-entrance-transition>
<t-input
v-model.trim="keyword"
class="search"
borderless
clearable
placeholder="搜索编码、姓名(拼音)、电话"
/>
<t-cell-group v-if="customerList.length" class="customers" theme="card">
<t-cell
v-for="item in customerList"
:key="item.id"
:title="getCustomerName(item)"
:note="item.code || ''"
hover
@click="openCustomer(item)"
>
<template #description>
<telephone-link :value="item.telephone" placeholder="未填写电话" />
</template>
<template v-if="canManageTagCustomers" #rightIcon>
<t-button theme="danger" size="extra-small" @click.stop="confirmRemoveCustomer(item)">
移除
</t-button>
</template>
</t-cell>
</t-cell-group>
<center-tips v-else :content="customerEmptyText" />
<center-tips
v-if="customerList.length"
:content="isLoadingCustomers ? '正在加载更多' : isNoMore ? '已经到底了' : '上拉加载更多'"
/>
</section>
<center-tips v-else content="暂无客户查看权限" />
>
<template #suffix>
<t-button
v-if="canManageTagCustomers"
size="extra-small"
theme="primary"
:disabled="!tagId || isApplyingTag"
@click="customerSelectorVisible = true"
>
添加客户
</t-button>
</template>
</t-input>
</div>
<div class="list-wrap">
<t-form v-if="tag" class="form card" v-entrance-transition>
<t-form-item label="标签名称">
<t-input
v-model.trim="tagName"
class="name-input"
borderless
:readonly="!canUpdateTag"
placeholder="请输入标签名称"
/>
</t-form-item>
<t-form-item :label="`客户数量:${customerTotal}`" content-align="right">
<t-button
v-if="canUpdateTag"
class="save"
theme="primary"
size="extra-small"
:loading="isSaving"
:disabled="!isNameChanged || isSaving"
content="保存"
@click="saveTag"
/>
</t-form-item>
</t-form>
<center-tips v-else :content="isTagLoading ? '正在加载标签' : '标签不存在或无权查看'" />
<template v-if="canReadCustomer">
<t-cell-group v-if="customerList.length" class="customers fix-last-cell-line" theme="card">
<t-swipe-cell
class="item"
v-for="item in customerList"
:key="item.id"
v-entrance-transition="{ step: 30 }"
>
<customer-cell :customer="item" hover @click="openCustomer(item)">
<template #description>
<telephone-link :value="item.telephone" placeholder="未填写电话" />
</template>
</customer-cell>
<template v-if="canManageTagCustomers" #right>
<t-button theme="danger" @click.stop="confirmRemoveCustomer(item)">
移除
</t-button>
</template>
</t-swipe-cell>
</t-cell-group>
<center-tips v-else :content="customerEmptyText" />
<center-tips
v-if="customerList.length"
:content="isLoadingCustomers ? '正在加载更多' : isNoMore ? '已经到底了' : '上拉加载更多'"
/>
</template>
<center-tips v-else content="暂无客户查看权限" />
</div>
</t-pull-down-refresh>
<customer-selector
v-if="canManageTagCustomers"
@@ -97,6 +111,46 @@
@change="addCustomer"
/>
</main>
<t-dialog
v-model:visible="deleteDialogVisible"
title="删除标签"
:close-on-overlay-click="!isDeletingTag"
>
<div v-if="tag" class="delete-dialog-content">
<div class="hint">
请输入标签名
<span class="name" v-text="getTagName(tag)" />
以确认删除
</div>
<t-input
v-model.trim="deleteConfirmName"
class="confirm-input"
size="small"
borderless
clearable
placeholder="请输入标签名"
/>
</div>
<template #cancelBtn>
<t-button
theme="default"
content="取消"
block
:disabled="isDeletingTag"
@click="closeDeleteDialog"
/>
</template>
<template #confirmBtn>
<t-button
theme="danger"
content="确认删除"
block
:loading="isDeletingTag"
:disabled="!canConfirmTagDeletion"
@click="removeTag"
/>
</template>
</t-dialog>
</div>
</template>
@@ -126,14 +180,21 @@ const tag = ref<Tag>();
const tagName = ref("");
const isTagLoading = ref(false);
const isSaving = ref(false);
const isDeletingTag = ref(false);
const deleteDialogVisible = ref(false);
const deleteConfirmName = ref("");
let tagRequestToken = 0;
const canUpdateTag = computed(() => userStore.hasPermissions(corePermissionCodes.tag.update));
const canDeleteTag = computed(() => userStore.hasPermissions(corePermissionCodes.tag.delete));
const canApplyTag = computed(() => userStore.hasPermissions(corePermissionCodes.tag.apply));
const canReadCustomer = computed(() => userStore.hasPermissions(permissionCodes.customer.read));
const canManageTagCustomers = computed(() => canApplyTag.value && canReadCustomer.value);
const isNameChanged = computed(() => !!tag.value && !!tagName.value.trim() && tagName.value.trim() !== getTagName(tag.value));
const tagUsageText = computed(() => `共 ${tag.value?.useCount ?? 0} 位客户使用`);
const canConfirmTagDeletion = computed(() => {
const currentTag = tag.value;
return canDeleteTag.value && !!currentTag?.id && deleteConfirmName.value === getTagName(currentTag) && !isDeletingTag.value;
});
function getTagName(value: Tag): string {
return value.name || value.zhCN || "未命名标签";
@@ -190,6 +251,49 @@ async function saveTag(): Promise<void> {
}
}
function openDeleteDialog(): void {
if (!canDeleteTag.value || !tag.value?.id || isDeletingTag.value) {
return;
}
deleteConfirmName.value = "";
deleteDialogVisible.value = true;
}
function closeDeleteDialog(): void {
if (isDeletingTag.value) {
return;
}
deleteDialogVisible.value = false;
deleteConfirmName.value = "";
}
async function removeTag(): Promise<void> {
const id = tagId.value;
if (!id || !canConfirmTagDeletion.value || isDeletingTag.value) {
return;
}
isDeletingTag.value = true;
try {
await TagAPI.remove(id);
} catch {
Message.error("标签删除失败");
return;
} finally {
isDeletingTag.value = false;
}
deleteDialogVisible.value = false;
Message.success("标签已删除");
await router.replace({ name: "TagList" });
}
watch(deleteDialogVisible, visible => {
if (!visible) {
deleteConfirmName.value = "";
}
});
// ---------- 客户列表 ----------
const pageSize = 20;
@@ -283,7 +387,11 @@ async function openCustomer(customer: Customer): Promise<void> {
if (!customer.id) {
return;
}
await router.push({ name: "CustomerDetail", params: { id: customer.id } });
await router.push({
name: "CustomerDetail",
params: { id: customer.id },
query: { transitionDepth: String(Number(route.meta.depth ?? 0) + 1) }
});
}
// ---------- 客户标签维护 ----------
@@ -396,6 +504,12 @@ onUnmounted(() => {
.tag-detail {
padding: var(--app-nav-height) 0 1rem;
.list-wrap {
gap: 1rem;
display: flex;
flex-direction: column;
}
.tag-card,
.customer-section {
margin: 0 1rem 1rem;
@@ -462,4 +576,21 @@ onUnmounted(() => {
}
}
}
.delete-dialog-content {
.hint {
color: var(--td-text-color-secondary);
margin-bottom: .5rem;
}
.name {
color: var(--td-error-color);
font-weight: 600;
}
.confirm-input {
border: 1px solid var(--td-component-border);
border-radius: .75rem;
}
}
</style>
+45 -206
View File
@@ -8,41 +8,14 @@
@left-click="$router.back()"
>
<template #right>
<div
v-if="pageNavBarRight.icon || pageNavBarRight.text"
class="nav-right-slot"
>
<t-badge
v-if="pageNavBarRight.icon && pageNavBarRight.badge !== undefined"
class="badge"
:count="pageNavBarRight.badge"
:max-count="99"
:show-zero="false"
>
<button class="button" type="button" :disabled="pageNavBarRight.disabled" @click="handlePageNavBarRightAction">
<t-icon :name="pageNavBarRight.icon" size="1.25rem" />
</button>
</t-badge>
<button
v-else-if="pageNavBarRight.icon"
class="button"
type="button"
:disabled="pageNavBarRight.disabled"
@click="handlePageNavBarRightAction"
>
<t-icon :name="pageNavBarRight.icon" size="1.25rem" />
</button>
<button
v-else
class="nav-text"
type="button"
:disabled="pageNavBarRight.disabled"
:style="{ color: pageNavBarRight.disabled ? 'var(--td-text-color-disabled)' : pageNavBarRight.textColor || 'var(--td-text-color-primary, #333)' }"
:class="{ clickable: !!pageNavBarRight.action, disabled: pageNavBarRight.disabled }"
@click="handlePageNavBarRightAction"
v-text="pageNavBarRight.text"
/>
</div>
<t-button
v-if="canCreateTag"
theme="primary"
variant="text"
size="small"
content="新增"
@click="openCreateDialog"
/>
</template>
</t-navbar>
<main v-can="corePermissionCodes.tag.read" class="page-content scroll list">
@@ -59,30 +32,30 @@
class="search"
type="search"
borderless
placeholder="搜索标签"
placeholder="搜索标签名称(拼音)"
/>
</div>
<div class="tag-panel">
<div
v-entrance-transition="{ step: 30 }"
class="item bg-white"
v-for="item in tagList"
:key="item.id"
@click="openDetail(item)"
>
<span class="name" v-text="`${getTagName(item)}(${item.useCount ?? 0})`" />
<button
v-if="canDeleteTag"
type="button"
class="close"
@click="confirmRemoveTag(item, $event)"
<div class="list-wrap">
<t-cell-group theme="card">
<t-cell title="标签总数" :note="Text.display(total)" />
</t-cell-group>
<t-cell-group v-if="tagList.length" class="tag-group" theme="card">
<t-cell
v-for="item in tagList"
:key="item.id"
v-entrance-transition="{ step: 30 }"
arrow
:note="Text.display(item.useCount ?? 0)"
@click="openDetail(item)"
>
<t-icon name="close" size="1rem" />
</button>
</div>
<template #title>
<span class="title" :style="getTagStyle(item)" v-text="getTagName(item)" />
</template>
</t-cell>
</t-cell-group>
<center-tips v-if="!tagList.length" :content="emptyText" />
<center-tips v-if="tagList.length" :content="isLoading ? '正在加载更多' : isNoMore ? '已经到底了' : '上拉加载更多'" />
</div>
<center-tips v-if="!tagList.length" :content="emptyText" />
<center-tips v-if="tagList.length" :content="isLoading ? '正在加载更多' : isNoMore ? '已经到底了' : '上拉加载更多'" />
</t-pull-down-refresh>
</main>
<t-dialog
@@ -107,44 +80,13 @@
</template>
<script setup lang="ts">
import { DialogPlugin } from "tdesign-mobile-vue";
import { type Page, useUserStore } from "timi-web-api";
import TagAPI from "@/api/TagAPI";
import { corePermissionCodes } from "@/utils/permission";
import { Message } from "@/utils/message.ts";
const pageNavBarRight = reactive({
icon: "",
badge: undefined as number | undefined,
text: "",
textColor: "",
disabled: false,
action: undefined as (() => void | Promise<void>) | undefined
});
function setPageNavBarRightText(value?: string, color?: string, action?: () => void | Promise<void>): void {
pageNavBarRight.text = value || "";
pageNavBarRight.textColor = color || "";
pageNavBarRight.disabled = false;
pageNavBarRight.action = action;
if (value) {
pageNavBarRight.badge = undefined;
pageNavBarRight.icon = "";
}
}
function clearPageNavBarRight(): void {
Object.assign(pageNavBarRight, { icon: "", badge: undefined, text: "", textColor: "", disabled: false, action: undefined });
}
async function handlePageNavBarRightAction(): Promise<void> {
if (pageNavBarRight.disabled || !pageNavBarRight.action) {
return;
}
await pageNavBarRight.action();
}
import type { Tag } from "@/types/Tag";
import { Text } from "timi-web";
defineOptions({
name: "TagList"
@@ -152,8 +94,9 @@ defineOptions({
const userStore = useUserStore();
const router = useRouter();
const canCreateTag = computed(() => userStore.hasPermissions(corePermissionCodes.tag.create));
const pageSize = 100;
const pageSize = 16;
const keyword = ref("");
const tagList = ref<Tag[]>([]);
const isLoading = ref(false);
@@ -172,7 +115,7 @@ const formModel = reactive({
name: ""
});
const canDeleteTag = computed(() => userStore.hasPermissions(corePermissionCodes.tag.delete));
const maxUseCount = computed(() => Math.max(0, tagList.value[0]?.useCount ?? 0));
const emptyText = computed(() => {
if (isLoading.value) {
return "正在加载标签";
@@ -184,6 +127,14 @@ function getTagName(tag: Tag): string {
return tag.name || tag.zhCN || "未命名标签";
}
function getTagStyle(tag: Tag): Record<string, string> {
const max = maxUseCount.value;
const useCount = Math.max(0, tag.useCount ?? 0);
const percentage = max ? Math.min(100, useCount / max * 100) : 0;
const hue = (210 - percentage * 1.85).toFixed(1);
return { "--tag-hue": `${hue}deg` };
}
async function fetch(reset = false): Promise<void> {
if (!reset && (isLoading.value || isNoMore.value)) {
return;
@@ -283,45 +234,7 @@ async function saveTag(): Promise<void> {
}
}
function confirmRemoveTag(tag: Tag, event?: MouseEvent): void {
event?.preventDefault();
event?.stopPropagation();
if (!tag.id) {
return;
}
const dialog = DialogPlugin.confirm({
title: "删除标签",
content: `确定删除标签 ${getTagName(tag)} 吗?`,
cancelBtn: "取消",
confirmBtn: "删除",
onCancel() {
dialog.destroy();
},
async onConfirm() {
dialog.destroy();
await removeTag(tag.id || "");
}
});
}
async function removeTag(id: string): Promise<void> {
if (!id) {
return;
}
try {
await TagAPI.remove(id);
await reload();
Message.success("标签已删除");
} catch {
Message.error("标签删除失败");
}
}
onMounted(async () => {
clearPageNavBarRight();
if (userStore.hasPermissions(corePermissionCodes.tag.create)) {
setPageNavBarRightText("新增", "var(--td-brand-color)", openCreateDialog);
}
await reload();
});
@@ -333,7 +246,6 @@ watch(keyword, () => {
});
onUnmounted(() => {
clearPageNavBarRight();
window.clearTimeout(keywordTimer);
});
</script>
@@ -342,46 +254,13 @@ onUnmounted(() => {
.tag-list {
padding: var(--app-nav-height) 0 1rem 0;
.tag-panel {
gap: .75rem;
.list-wrap {
gap: 1rem;
display: flex;
padding: 0 1rem 1rem 1rem;
flex-wrap: wrap;
align-items: flex-start;
flex-direction: column;
.item {
flex: 1 1 auto;
color: var(--td-brand-color);
width: fit-content;
border: 1px solid var(--td-brand-color);
cursor: pointer;
margin: 0;
display: flex;
padding: .25rem .5rem;
min-width: 0;
font-size: 1rem;
align-items: center;
border-radius: .5rem;
justify-content: center;
.name {
flex: 1;
min-width: 0;
line-height: 1;
text-align: center;
overflow-wrap: anywhere;
}
.close {
color: inherit;
flex: 0 0 auto;
border: 0;
padding: 0;
display: flex;
background: transparent;
margin-left: .5rem;
align-items: center;
}
.title {
color: color-mix(in srgb, hsl(var(--tag-hue), 72%, 44%) 68%, var(--td-text-color-primary));
}
}
}
@@ -397,44 +276,4 @@ onUnmounted(() => {
}
}
.nav-right-slot {
width: 6rem;
height: 100%;
display: flex;
align-items: center;
justify-content: flex-end;
.badge {
:deep(.t-badge__content) {
display: flex;
align-items: center;
}
}
.button,
.nav-text {
color: var(--td-text-color-primary, #333);
border: none;
padding: 0;
display: inline-flex;
background: transparent;
align-items: center;
justify-content: center;
}
.button {
&:disabled {
color: var(--td-text-color-disabled);
cursor: not-allowed;
}
}
.nav-text {
font: inherit;
cursor: default;
&.clickable { cursor: pointer; }
&.disabled { cursor: not-allowed; }
}
}
</style>