update Tag style
This commit is contained in:
@@ -105,7 +105,8 @@ html.theme-dark body {
|
|||||||
--td-button-border-radius: 99rem;
|
--td-button-border-radius: 99rem;
|
||||||
|
|
||||||
border: 1px solid var(--td-component-border);
|
border: 1px solid var(--td-component-border);
|
||||||
padding: .25rem .25rem .25rem .5rem;
|
height: 2.25rem;
|
||||||
|
padding: .25rem .25rem .25rem .75rem;
|
||||||
z-index: 2;
|
z-index: 2;
|
||||||
position: relative;
|
position: relative;
|
||||||
border-radius: 1rem;
|
border-radius: 1rem;
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ const emit = defineEmits<{
|
|||||||
edit: [];
|
edit: [];
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
const maxRowCount = 3;
|
const maxRowCount = 2;
|
||||||
const tagRowList = computed(() => {
|
const tagRowList = computed(() => {
|
||||||
const rowCount = Math.min(maxRowCount, props.tagList.length);
|
const rowCount = Math.min(maxRowCount, props.tagList.length);
|
||||||
const rowList = Array.from({ length: rowCount }, () => [] as Tag[]);
|
const rowList = Array.from({ length: rowCount }, () => [] as Tag[]);
|
||||||
|
|||||||
+200
-69
@@ -6,7 +6,19 @@
|
|||||||
title="标签详情"
|
title="标签详情"
|
||||||
left-arrow
|
left-arrow
|
||||||
@left-click="$router.back()"
|
@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">
|
<main v-can="corePermissionCodes.tag.read" class="page-content scroll list">
|
||||||
<t-pull-down-refresh
|
<t-pull-down-refresh
|
||||||
class="pull-refresh"
|
class="pull-refresh"
|
||||||
@@ -15,78 +27,80 @@
|
|||||||
@refresh="refresh"
|
@refresh="refresh"
|
||||||
@scrolltolower="loadMore"
|
@scrolltolower="loadMore"
|
||||||
>
|
>
|
||||||
<section v-if="tag" class="tag-card">
|
<div class="filters glass" v-entrance-transition>
|
||||||
<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>
|
|
||||||
<t-input
|
<t-input
|
||||||
v-model.trim="keyword"
|
v-model.trim="keyword"
|
||||||
class="search"
|
class="search"
|
||||||
borderless
|
borderless
|
||||||
clearable
|
clearable
|
||||||
placeholder="搜索编码、姓名(拼音)、电话"
|
placeholder="搜索编码、姓名(拼音)、电话"
|
||||||
/>
|
>
|
||||||
<t-cell-group v-if="customerList.length" class="customers" theme="card">
|
<template #suffix>
|
||||||
<t-cell
|
<t-button
|
||||||
v-for="item in customerList"
|
v-if="canManageTagCustomers"
|
||||||
:key="item.id"
|
size="extra-small"
|
||||||
:title="getCustomerName(item)"
|
theme="primary"
|
||||||
:note="item.code || ''"
|
:disabled="!tagId || isApplyingTag"
|
||||||
hover
|
@click="customerSelectorVisible = true"
|
||||||
@click="openCustomer(item)"
|
>
|
||||||
>
|
添加客户
|
||||||
<template #description>
|
</t-button>
|
||||||
<telephone-link :value="item.telephone" placeholder="未填写电话" />
|
</template>
|
||||||
</template>
|
</t-input>
|
||||||
<template v-if="canManageTagCustomers" #rightIcon>
|
</div>
|
||||||
<t-button theme="danger" size="extra-small" @click.stop="confirmRemoveCustomer(item)">
|
<div class="list-wrap">
|
||||||
移除
|
<t-form v-if="tag" class="form card" v-entrance-transition>
|
||||||
</t-button>
|
<t-form-item label="标签名称">
|
||||||
</template>
|
<t-input
|
||||||
</t-cell>
|
v-model.trim="tagName"
|
||||||
</t-cell-group>
|
class="name-input"
|
||||||
<center-tips v-else :content="customerEmptyText" />
|
borderless
|
||||||
<center-tips
|
:readonly="!canUpdateTag"
|
||||||
v-if="customerList.length"
|
placeholder="请输入标签名称"
|
||||||
:content="isLoadingCustomers ? '正在加载更多' : isNoMore ? '已经到底了' : '上拉加载更多'"
|
/>
|
||||||
/>
|
</t-form-item>
|
||||||
</section>
|
<t-form-item :label="`客户数量:${customerTotal}`" content-align="right">
|
||||||
<center-tips v-else content="暂无客户查看权限" />
|
<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>
|
</t-pull-down-refresh>
|
||||||
<customer-selector
|
<customer-selector
|
||||||
v-if="canManageTagCustomers"
|
v-if="canManageTagCustomers"
|
||||||
@@ -97,6 +111,46 @@
|
|||||||
@change="addCustomer"
|
@change="addCustomer"
|
||||||
/>
|
/>
|
||||||
</main>
|
</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>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -126,14 +180,21 @@ const tag = ref<Tag>();
|
|||||||
const tagName = ref("");
|
const tagName = ref("");
|
||||||
const isTagLoading = ref(false);
|
const isTagLoading = ref(false);
|
||||||
const isSaving = ref(false);
|
const isSaving = ref(false);
|
||||||
|
const isDeletingTag = ref(false);
|
||||||
|
const deleteDialogVisible = ref(false);
|
||||||
|
const deleteConfirmName = ref("");
|
||||||
let tagRequestToken = 0;
|
let tagRequestToken = 0;
|
||||||
|
|
||||||
const canUpdateTag = computed(() => userStore.hasPermissions(corePermissionCodes.tag.update));
|
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 canApplyTag = computed(() => userStore.hasPermissions(corePermissionCodes.tag.apply));
|
||||||
const canReadCustomer = computed(() => userStore.hasPermissions(permissionCodes.customer.read));
|
const canReadCustomer = computed(() => userStore.hasPermissions(permissionCodes.customer.read));
|
||||||
const canManageTagCustomers = computed(() => canApplyTag.value && canReadCustomer.value);
|
const canManageTagCustomers = computed(() => canApplyTag.value && canReadCustomer.value);
|
||||||
const isNameChanged = computed(() => !!tag.value && !!tagName.value.trim() && tagName.value.trim() !== getTagName(tag.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 {
|
function getTagName(value: Tag): string {
|
||||||
return value.name || value.zhCN || "未命名标签";
|
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;
|
const pageSize = 20;
|
||||||
@@ -283,7 +387,11 @@ async function openCustomer(customer: Customer): Promise<void> {
|
|||||||
if (!customer.id) {
|
if (!customer.id) {
|
||||||
return;
|
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 {
|
.tag-detail {
|
||||||
padding: var(--app-nav-height) 0 1rem;
|
padding: var(--app-nav-height) 0 1rem;
|
||||||
|
|
||||||
|
.list-wrap {
|
||||||
|
gap: 1rem;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
.tag-card,
|
.tag-card,
|
||||||
.customer-section {
|
.customer-section {
|
||||||
margin: 0 1rem 1rem;
|
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>
|
</style>
|
||||||
|
|||||||
+45
-206
@@ -8,41 +8,14 @@
|
|||||||
@left-click="$router.back()"
|
@left-click="$router.back()"
|
||||||
>
|
>
|
||||||
<template #right>
|
<template #right>
|
||||||
<div
|
<t-button
|
||||||
v-if="pageNavBarRight.icon || pageNavBarRight.text"
|
v-if="canCreateTag"
|
||||||
class="nav-right-slot"
|
theme="primary"
|
||||||
>
|
variant="text"
|
||||||
<t-badge
|
size="small"
|
||||||
v-if="pageNavBarRight.icon && pageNavBarRight.badge !== undefined"
|
content="新增"
|
||||||
class="badge"
|
@click="openCreateDialog"
|
||||||
: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>
|
|
||||||
</template>
|
</template>
|
||||||
</t-navbar>
|
</t-navbar>
|
||||||
<main v-can="corePermissionCodes.tag.read" class="page-content scroll list">
|
<main v-can="corePermissionCodes.tag.read" class="page-content scroll list">
|
||||||
@@ -59,30 +32,30 @@
|
|||||||
class="search"
|
class="search"
|
||||||
type="search"
|
type="search"
|
||||||
borderless
|
borderless
|
||||||
placeholder="搜索标签"
|
placeholder="搜索标签名称(拼音)"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div class="tag-panel">
|
<div class="list-wrap">
|
||||||
<div
|
<t-cell-group theme="card">
|
||||||
v-entrance-transition="{ step: 30 }"
|
<t-cell title="标签总数" :note="Text.display(total)" />
|
||||||
class="item bg-white"
|
</t-cell-group>
|
||||||
v-for="item in tagList"
|
<t-cell-group v-if="tagList.length" class="tag-group" theme="card">
|
||||||
:key="item.id"
|
<t-cell
|
||||||
@click="openDetail(item)"
|
v-for="item in tagList"
|
||||||
>
|
:key="item.id"
|
||||||
<span class="name" v-text="`${getTagName(item)}(${item.useCount ?? 0})`" />
|
v-entrance-transition="{ step: 30 }"
|
||||||
<button
|
arrow
|
||||||
v-if="canDeleteTag"
|
:note="Text.display(item.useCount ?? 0)"
|
||||||
type="button"
|
@click="openDetail(item)"
|
||||||
class="close"
|
|
||||||
@click="confirmRemoveTag(item, $event)"
|
|
||||||
>
|
>
|
||||||
<t-icon name="close" size="1rem" />
|
<template #title>
|
||||||
</button>
|
<span class="title" :style="getTagStyle(item)" v-text="getTagName(item)" />
|
||||||
</div>
|
</template>
|
||||||
|
</t-cell>
|
||||||
|
</t-cell-group>
|
||||||
|
<center-tips v-if="!tagList.length" :content="emptyText" />
|
||||||
|
<center-tips v-if="tagList.length" :content="isLoading ? '正在加载更多' : isNoMore ? '已经到底了' : '上拉加载更多'" />
|
||||||
</div>
|
</div>
|
||||||
<center-tips v-if="!tagList.length" :content="emptyText" />
|
|
||||||
<center-tips v-if="tagList.length" :content="isLoading ? '正在加载更多' : isNoMore ? '已经到底了' : '上拉加载更多'" />
|
|
||||||
</t-pull-down-refresh>
|
</t-pull-down-refresh>
|
||||||
</main>
|
</main>
|
||||||
<t-dialog
|
<t-dialog
|
||||||
@@ -107,44 +80,13 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { DialogPlugin } from "tdesign-mobile-vue";
|
|
||||||
import { type Page, useUserStore } from "timi-web-api";
|
import { type Page, useUserStore } from "timi-web-api";
|
||||||
import TagAPI from "@/api/TagAPI";
|
import TagAPI from "@/api/TagAPI";
|
||||||
import { corePermissionCodes } from "@/utils/permission";
|
import { corePermissionCodes } from "@/utils/permission";
|
||||||
import { Message } from "@/utils/message.ts";
|
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 type { Tag } from "@/types/Tag";
|
||||||
|
import { Text } from "timi-web";
|
||||||
|
|
||||||
defineOptions({
|
defineOptions({
|
||||||
name: "TagList"
|
name: "TagList"
|
||||||
@@ -152,8 +94,9 @@ defineOptions({
|
|||||||
|
|
||||||
const userStore = useUserStore();
|
const userStore = useUserStore();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
const canCreateTag = computed(() => userStore.hasPermissions(corePermissionCodes.tag.create));
|
||||||
|
|
||||||
const pageSize = 100;
|
const pageSize = 16;
|
||||||
const keyword = ref("");
|
const keyword = ref("");
|
||||||
const tagList = ref<Tag[]>([]);
|
const tagList = ref<Tag[]>([]);
|
||||||
const isLoading = ref(false);
|
const isLoading = ref(false);
|
||||||
@@ -172,7 +115,7 @@ const formModel = reactive({
|
|||||||
name: ""
|
name: ""
|
||||||
});
|
});
|
||||||
|
|
||||||
const canDeleteTag = computed(() => userStore.hasPermissions(corePermissionCodes.tag.delete));
|
const maxUseCount = computed(() => Math.max(0, tagList.value[0]?.useCount ?? 0));
|
||||||
const emptyText = computed(() => {
|
const emptyText = computed(() => {
|
||||||
if (isLoading.value) {
|
if (isLoading.value) {
|
||||||
return "正在加载标签";
|
return "正在加载标签";
|
||||||
@@ -184,6 +127,14 @@ function getTagName(tag: Tag): string {
|
|||||||
return tag.name || tag.zhCN || "未命名标签";
|
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> {
|
async function fetch(reset = false): Promise<void> {
|
||||||
if (!reset && (isLoading.value || isNoMore.value)) {
|
if (!reset && (isLoading.value || isNoMore.value)) {
|
||||||
return;
|
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 () => {
|
onMounted(async () => {
|
||||||
clearPageNavBarRight();
|
|
||||||
if (userStore.hasPermissions(corePermissionCodes.tag.create)) {
|
|
||||||
setPageNavBarRightText("新增", "var(--td-brand-color)", openCreateDialog);
|
|
||||||
}
|
|
||||||
await reload();
|
await reload();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -333,7 +246,6 @@ watch(keyword, () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
onUnmounted(() => {
|
onUnmounted(() => {
|
||||||
clearPageNavBarRight();
|
|
||||||
window.clearTimeout(keywordTimer);
|
window.clearTimeout(keywordTimer);
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
@@ -342,46 +254,13 @@ onUnmounted(() => {
|
|||||||
.tag-list {
|
.tag-list {
|
||||||
padding: var(--app-nav-height) 0 1rem 0;
|
padding: var(--app-nav-height) 0 1rem 0;
|
||||||
|
|
||||||
.tag-panel {
|
.list-wrap {
|
||||||
gap: .75rem;
|
gap: 1rem;
|
||||||
display: flex;
|
display: flex;
|
||||||
padding: 0 1rem 1rem 1rem;
|
flex-direction: column;
|
||||||
flex-wrap: wrap;
|
|
||||||
align-items: flex-start;
|
|
||||||
|
|
||||||
.item {
|
.title {
|
||||||
flex: 1 1 auto;
|
color: color-mix(in srgb, hsl(var(--tag-hue), 72%, 44%) 68%, var(--td-text-color-primary));
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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>
|
</style>
|
||||||
|
|||||||
Reference in New Issue
Block a user