delete event in list
This commit is contained in:
@@ -38,6 +38,14 @@
|
|||||||
<span v-else>未配置</span>
|
<span v-else>未配置</span>
|
||||||
</template>
|
</template>
|
||||||
</t-cell>
|
</t-cell>
|
||||||
|
<t-cell
|
||||||
|
v-if="canReadEventRecord"
|
||||||
|
title="登记记录"
|
||||||
|
note="查看该事件登记记录"
|
||||||
|
arrow
|
||||||
|
:hover="true"
|
||||||
|
@click="toEventRecordList"
|
||||||
|
/>
|
||||||
</t-cell-group>
|
</t-cell-group>
|
||||||
<t-cell-group v-entrance-transition="140" v-if="event" title="登记配置" theme="card">
|
<t-cell-group v-entrance-transition="140" v-if="event" title="登记配置" theme="card">
|
||||||
<t-cell title="数值类型" :note="getValueTypeText(event.valueType)" />
|
<t-cell title="数值类型" :note="getValueTypeText(event.valueType)" />
|
||||||
@@ -121,6 +129,7 @@ const defaultColor = "#2f88ff";
|
|||||||
|
|
||||||
const canUpdate = computed(() => userStore.hasPermissions(permissionCodes.event.update));
|
const canUpdate = computed(() => userStore.hasPermissions(permissionCodes.event.update));
|
||||||
const canDeleteEvent = computed(() => userStore.hasPermissions(permissionCodes.event.delete));
|
const canDeleteEvent = computed(() => userStore.hasPermissions(permissionCodes.event.delete));
|
||||||
|
const canReadEventRecord = computed(() => userStore.hasPermissions(permissionCodes.eventRecord.read));
|
||||||
const isGlobalManager = computed(() => userStore.hasRoles(gaoRoleCodes.globalManager));
|
const isGlobalManager = computed(() => userStore.hasRoles(gaoRoleCodes.globalManager));
|
||||||
const storeName = computed(() => {
|
const storeName = computed(() => {
|
||||||
const storeId = event.value?.storeId;
|
const storeId = event.value?.storeId;
|
||||||
@@ -295,6 +304,31 @@ async function removeEvent(eventId: string): Promise<void> {
|
|||||||
|
|
||||||
// ---------- 导航 ----------
|
// ---------- 导航 ----------
|
||||||
|
|
||||||
|
async function toEventRecordList(): Promise<void> {
|
||||||
|
const eventId = event.value?.id || String(route.params.id || "");
|
||||||
|
if (!eventId || !canReadEventRecord.value) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await router.push({
|
||||||
|
name: "EventRecordList",
|
||||||
|
query: {
|
||||||
|
eventIds: eventId,
|
||||||
|
transitionDepth: String(getCurrentRouteDepth() + 1)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function getCurrentRouteDepth(): number {
|
||||||
|
const transitionDepth = Array.isArray(route.query.transitionDepth)
|
||||||
|
? route.query.transitionDepth[0]
|
||||||
|
: route.query.transitionDepth;
|
||||||
|
const depth = Number(transitionDepth);
|
||||||
|
if (transitionDepth && Number.isInteger(depth) && 0 <= depth && depth <= 20) {
|
||||||
|
return depth;
|
||||||
|
}
|
||||||
|
return Number(route.meta.depth ?? 0);
|
||||||
|
}
|
||||||
|
|
||||||
async function toEdit(): Promise<void> {
|
async function toEdit(): Promise<void> {
|
||||||
const eventId = String(route.params.id || "");
|
const eventId = String(route.params.id || "");
|
||||||
if (!canUpdate.value || !eventId) {
|
if (!canUpdate.value || !eventId) {
|
||||||
|
|||||||
@@ -10,11 +10,14 @@
|
|||||||
@scrolltolower="fetch"
|
@scrolltolower="fetch"
|
||||||
>
|
>
|
||||||
<t-cell-group theme="card">
|
<t-cell-group theme="card">
|
||||||
<t-cell
|
<t-swipe-cell
|
||||||
v-entrance-transition="index * 30"
|
v-entrance-transition="index * 30"
|
||||||
v-for="(item, index) in visibleEventList"
|
v-for="(item, index) in visibleEventList"
|
||||||
:key="item.id"
|
:key="item.id"
|
||||||
class="item"
|
class="item"
|
||||||
|
>
|
||||||
|
<t-cell
|
||||||
|
class="cell"
|
||||||
:arrow="!!item.id"
|
:arrow="!!item.id"
|
||||||
:hover="!!item.id"
|
:hover="!!item.id"
|
||||||
@click="toEventItem(item)"
|
@click="toEventItem(item)"
|
||||||
@@ -51,6 +54,17 @@
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</t-cell>
|
</t-cell>
|
||||||
|
<template v-if="canDeleteEvent" #right>
|
||||||
|
<t-button
|
||||||
|
class="delete"
|
||||||
|
theme="danger"
|
||||||
|
:loading="isRemoving && removingEventId === item.id"
|
||||||
|
@click.stop="openRemoveDialog(item)"
|
||||||
|
>
|
||||||
|
删除
|
||||||
|
</t-button>
|
||||||
|
</template>
|
||||||
|
</t-swipe-cell>
|
||||||
</t-cell-group>
|
</t-cell-group>
|
||||||
<div v-if="!visibleEventList.length" class="empty-block" v-text="emptyText" />
|
<div v-if="!visibleEventList.length" class="empty-block" v-text="emptyText" />
|
||||||
<div v-if="visibleEventList.length" class="load-state" v-text="isNoMore ? '已经到底了' : '上拉加载更多'" />
|
<div v-if="visibleEventList.length" class="load-state" v-text="isNoMore ? '已经到底了' : '上拉加载更多'" />
|
||||||
@@ -60,6 +74,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
import { DialogPlugin } from "tdesign-mobile-vue";
|
||||||
import { Message } from "@/utils/message";
|
import { Message } from "@/utils/message";
|
||||||
import { type Page, type PageResult, type Role, useUserStore } from "timi-web-api";
|
import { type Page, type PageResult, type Role, useUserStore } from "timi-web-api";
|
||||||
import EventAPI from "@/api/EventAPI";
|
import EventAPI from "@/api/EventAPI";
|
||||||
@@ -84,6 +99,7 @@ const isGlobalManager = computed(() => userStore.hasRoles(gaoRoleCodes.globalMan
|
|||||||
const eventListOptions = computed(() => ({ storeId: currentStoreStore.currentStoreId }));
|
const eventListOptions = computed(() => ({ storeId: currentStoreStore.currentStoreId }));
|
||||||
const canCreateEvent = computed(() => userStore.hasPermissions(permissionCodes.event.create));
|
const canCreateEvent = computed(() => userStore.hasPermissions(permissionCodes.event.create));
|
||||||
const canUpdateEventItem = computed(() => userStore.hasPermissions(permissionCodes.event.update));
|
const canUpdateEventItem = computed(() => userStore.hasPermissions(permissionCodes.event.update));
|
||||||
|
const canDeleteEvent = computed(() => userStore.hasPermissions(permissionCodes.event.delete));
|
||||||
const canShowActionMenu = computed(() => canCreateEvent.value || canUpdateEventItem.value);
|
const canShowActionMenu = computed(() => canCreateEvent.value || canUpdateEventItem.value);
|
||||||
|
|
||||||
const actionList = computed<NavBarAction[]>(() => {
|
const actionList = computed<NavBarAction[]>(() => {
|
||||||
@@ -115,6 +131,8 @@ const roleOptions = ref<Role[]>([]);
|
|||||||
const isRefreshing = ref(false);
|
const isRefreshing = ref(false);
|
||||||
const isLoading = ref(false);
|
const isLoading = ref(false);
|
||||||
const isNoMore = ref(false);
|
const isNoMore = ref(false);
|
||||||
|
const isRemoving = ref(false);
|
||||||
|
const removingEventId = ref("");
|
||||||
const page = reactive<Page<EventItem>>({
|
const page = reactive<Page<EventItem>>({
|
||||||
index: 0,
|
index: 0,
|
||||||
size: 15,
|
size: 15,
|
||||||
@@ -156,6 +174,51 @@ async function toEventItem(item: EventItem): Promise<void> {
|
|||||||
await router.push(`/management/registration-events/${item.id}`);
|
await router.push(`/management/registration-events/${item.id}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------- 删除 ----------
|
||||||
|
|
||||||
|
function openRemoveDialog(eventItem: EventItem): void {
|
||||||
|
const eventId = eventItem.id;
|
||||||
|
if (!eventId || isRemoving.value) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const eventName = eventItem.name || "未命名事件";
|
||||||
|
const dialog = DialogPlugin.confirm({
|
||||||
|
title: "删除登记事件",
|
||||||
|
content: `确定删除登记事件 ${eventName} 吗?删除后无法恢复。`,
|
||||||
|
cancelBtn: "取消",
|
||||||
|
confirmBtn: "删除",
|
||||||
|
onCancel() {
|
||||||
|
dialog.destroy();
|
||||||
|
},
|
||||||
|
async onConfirm() {
|
||||||
|
dialog.destroy();
|
||||||
|
await removeEvent(eventId);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function removeEvent(eventId: string): Promise<void> {
|
||||||
|
if (isRemoving.value) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
isRemoving.value = true;
|
||||||
|
removingEventId.value = eventId;
|
||||||
|
try {
|
||||||
|
await EventAPI.remove(eventId);
|
||||||
|
pageResult.list = pageResult.list.filter(item => item.id !== eventId);
|
||||||
|
pageResult.total = Math.max(0, pageResult.total - 1);
|
||||||
|
isNoMore.value = pageResult.list.length >= pageResult.total;
|
||||||
|
Message.success("登记事件已删除");
|
||||||
|
} catch {
|
||||||
|
Message.error("登记事件删除失败");
|
||||||
|
} finally {
|
||||||
|
isRemoving.value = false;
|
||||||
|
removingEventId.value = "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ---------- 展示文案 ----------
|
// ---------- 展示文案 ----------
|
||||||
|
|
||||||
function getStatusTag(item: EventItem): StatusTag {
|
function getStatusTag(item: EventItem): StatusTag {
|
||||||
@@ -293,6 +356,12 @@ onUnmounted(() => {
|
|||||||
|
|
||||||
.item {
|
.item {
|
||||||
|
|
||||||
|
.delete {
|
||||||
|
height: 100%;
|
||||||
|
padding: 0 1rem;
|
||||||
|
border-radius: 0;
|
||||||
|
}
|
||||||
|
|
||||||
.header {
|
.header {
|
||||||
gap: .5rem;
|
gap: .5rem;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
|||||||
Reference in New Issue
Block a user