将项目筛选并入搜索框下方的 van-dropdown 行,与协议状态样式一致;科研捐赠 Tab 同步展示两项筛选,并修复捐赠列表按 protocolStatus 过滤 donation_status。 Co-authored-by: Cursor <cursoragent@cursor.com>
696 lines
22 KiB
Vue
696 lines
22 KiB
Vue
<template>
|
||
<router-view v-if="childActive" />
|
||
<MarketPageShell
|
||
v-else
|
||
:title="`${roleTitle} · ${moduleTitle}`"
|
||
:show-header="false"
|
||
>
|
||
<div class="market-list__filters">
|
||
<div
|
||
v-if="listFilterTabs.length"
|
||
class="market-source-tabs"
|
||
role="tablist"
|
||
aria-label="业务来源"
|
||
>
|
||
<div class="market-source-tabs__list">
|
||
<button
|
||
v-for="tab in listFilterTabs"
|
||
:key="tab.value"
|
||
type="button"
|
||
role="tab"
|
||
class="market-source-tabs__btn"
|
||
:class="{ 'is-active': listStatus === tab.value }"
|
||
:aria-selected="listStatus === tab.value"
|
||
@click="switchListStatus(tab.value)"
|
||
>
|
||
{{ tab.text }}
|
||
</button>
|
||
</div>
|
||
<button
|
||
v-if="batchDeleteAvailable && !batchSelectionMode"
|
||
type="button"
|
||
class="market-source-tabs__more"
|
||
aria-label="更多操作"
|
||
@click="toggleBatchSelectionMode"
|
||
>
|
||
<van-icon name="ellipsis" />
|
||
</button>
|
||
</div>
|
||
<div class="market-list__search-row">
|
||
<van-search
|
||
v-model="keyword"
|
||
shape="round"
|
||
clearable
|
||
:placeholder="searchPlaceholder"
|
||
@update:model-value="queueSearch"
|
||
@search="search"
|
||
@clear="search"
|
||
/>
|
||
<button
|
||
v-if="sheetFilterFields.length"
|
||
type="button"
|
||
class="market-list__filter-button"
|
||
aria-label="打开筛选"
|
||
@click="filterSheetVisible = true"
|
||
>
|
||
<span>筛选</span>
|
||
<span v-if="activeFilters" class="market-list__filter-count">{{ activeFilters }}</span>
|
||
</button>
|
||
</div>
|
||
<div
|
||
v-if="inlineDropdownFilters.length || showProtocolProjectFilter"
|
||
class="market-list__filter-row"
|
||
>
|
||
<van-dropdown-menu active-color="#0a9f6d">
|
||
<van-dropdown-item
|
||
v-for="field in inlineDropdownFilters"
|
||
:key="`${field.source || 'all'}:${field.key}`"
|
||
:model-value="listFilters[field.key]"
|
||
:options="inlineFilterOptionsByKey[field.key] || []"
|
||
@change="(value) => onInlineFilterChange(field.key, value)"
|
||
/>
|
||
<van-dropdown-item
|
||
v-if="showProtocolProjectFilter"
|
||
:model-value="listFilters.projectId || ''"
|
||
:options="protocolProjectFilterOptions"
|
||
@change="(value) => onInlineFilterChange('projectId', value)"
|
||
/>
|
||
</van-dropdown-menu>
|
||
</div>
|
||
</div>
|
||
|
||
<div v-if="loading && !items.length" class="market-state">
|
||
<van-loading color="#0a9f6d">加载中…</van-loading>
|
||
</div>
|
||
<div v-else-if="errorMessage && !items.length" class="market-state">
|
||
<van-empty image="error" :description="errorMessage">
|
||
<van-button type="primary" round @click="loadPage(true)">重新加载</van-button>
|
||
</van-empty>
|
||
</div>
|
||
<van-empty v-else-if="!items.length" description="暂无相关数据" />
|
||
<van-list
|
||
v-if="items.length"
|
||
class="market-list"
|
||
:class="{ 'market-list--batch-selecting': batchSelectionMode }"
|
||
:loading="loadingMore"
|
||
:finished="!hasMore || Boolean(errorMessage)"
|
||
finished-text="没有更多了"
|
||
loading-text="正在加载…"
|
||
@load="loadPage(false)"
|
||
>
|
||
<div v-if="errorMessage" class="market-list__error" role="alert">
|
||
<span>{{ errorMessage }}</span>
|
||
<button type="button" @click="loadPage(false)">重试</button>
|
||
</div>
|
||
<MarketListCard
|
||
v-for="(item, index) in items"
|
||
:key="item.id || item.code || index"
|
||
:item="item"
|
||
:index="index"
|
||
:module="context.module"
|
||
:role="context.marketRole"
|
||
:selectable="batchSelectionMode && canDeleteProtocol(item)"
|
||
:selected="selectedRecordIds.includes(String(item.id || ''))"
|
||
:selection-mode="batchSelectionMode"
|
||
@action="handleCardAction"
|
||
@toggle-select="toggleRecordSelection"
|
||
/>
|
||
</van-list>
|
||
|
||
<div
|
||
v-if="batchSelectionMode"
|
||
class="market-list__batch-bar"
|
||
role="toolbar"
|
||
aria-label="批量操作"
|
||
>
|
||
<button type="button" class="market-list__batch-bar-side" @click="toggleSelectAll">
|
||
{{ allDeletableSelected ? '取消全选' : '全选' }}
|
||
</button>
|
||
<button
|
||
type="button"
|
||
class="market-list__batch-bar-main is-danger"
|
||
:disabled="!selectedRecordIds.length || batchDeleting"
|
||
@click="deleteSelectedProtocols"
|
||
>
|
||
批量删除{{ selectedRecordIds.length ? `(${selectedRecordIds.length})` : '' }}
|
||
</button>
|
||
<button type="button" class="market-list__batch-bar-side" @click="cancelBatchSelection">
|
||
取消
|
||
</button>
|
||
</div>
|
||
|
||
<button
|
||
v-if="canCreate && !batchSelectionMode"
|
||
type="button"
|
||
class="market-list__fab"
|
||
:aria-label="`新增${moduleTitle}`"
|
||
@click="openCreate"
|
||
>
|
||
<van-icon name="plus" />
|
||
</button>
|
||
<MarketFilterSheet
|
||
v-if="sheetFilterFields.length"
|
||
v-model:show="filterSheetVisible"
|
||
v-model="listFilters"
|
||
:fields="sheetFilterFields"
|
||
:options="filterOptions"
|
||
@apply="applyListFilters"
|
||
@reset="resetListFilters"
|
||
/>
|
||
</MarketPageShell>
|
||
</template>
|
||
|
||
<script setup>
|
||
import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue'
|
||
import { showConfirmDialog, showSuccessToast, showToast } from 'vant'
|
||
import { useRoute, useRouter } from 'vue-router'
|
||
import {
|
||
fetchMarketFormOptions,
|
||
fetchMarketList,
|
||
fetchProjectOptions,
|
||
performMarketAction
|
||
} from '../../api/market.js'
|
||
import { intersectAllowedActions } from '../../market/action-policy.js'
|
||
import { deleteMarketItemsSequentially } from '../../market/batch-delete.js'
|
||
import {
|
||
activeFilterCount,
|
||
buildListParams,
|
||
createListFilters
|
||
} from '../../market/list-filters.js'
|
||
import { marketSearchPlaceholder } from '../../market/list-presenter.js'
|
||
import { marketErrorMessage } from '../../market/market-error.js'
|
||
import { getMarketModule } from '../../market/module-registry.js'
|
||
import { projectOptions } from '../../market/project-assignment.js'
|
||
import {
|
||
getMarketRouteContext,
|
||
MARKET_MODULE_TITLES,
|
||
MARKET_ROLE_TITLES,
|
||
marketRecordNavigationQuery,
|
||
pickMarketNavigationQuery,
|
||
resolvePaymentChaseView,
|
||
shouldLoadMarketListAfterDetail
|
||
} from '../../market/routes.js'
|
||
import { resetMarketWindowScroll } from '../../market/page-scroll.js'
|
||
import {
|
||
createMarketListState,
|
||
failMarketListRequest,
|
||
finishMarketListRequest,
|
||
invalidateMarketRequestState,
|
||
startMarketListRequest
|
||
} from '../../market/request-state.js'
|
||
import MarketListCard from '../../market/components/MarketListCard.vue'
|
||
import MarketFilterSheet from '../../market/components/MarketFilterSheet.vue'
|
||
import MarketPageShell from '../../market/components/MarketPageShell.vue'
|
||
|
||
const PAGE_SIZE = 10
|
||
const route = useRoute()
|
||
const router = useRouter()
|
||
const SOURCE_TAB_VALUES = ['cell_storage', 'research_donation']
|
||
|
||
function usesSourceTabs(module) {
|
||
return module === 'protocol'
|
||
}
|
||
|
||
function resolveSourceListStatus(query) {
|
||
const raw = String(query?.tab || query?.source || '').trim()
|
||
return SOURCE_TAB_VALUES.includes(raw) ? raw : 'cell_storage'
|
||
}
|
||
|
||
function clearStalePointerLocks() {
|
||
if (typeof document === 'undefined') return
|
||
// Vant Toast forbidClick 会给 body 挂 van-toast--unclickable,泄漏时整页 pointer-events:none
|
||
document.body.classList.remove('van-toast--unclickable')
|
||
document.querySelectorAll('.van-overlay').forEach((node) => {
|
||
const style = window.getComputedStyle(node)
|
||
if (style.display === 'none' || style.visibility === 'hidden' || Number(style.opacity) === 0) {
|
||
node.style.pointerEvents = 'none'
|
||
}
|
||
})
|
||
}
|
||
|
||
const context = computed(() => getMarketRouteContext(route))
|
||
const moduleTitle = computed(() => MARKET_MODULE_TITLES[context.value.module])
|
||
const roleTitle = computed(() => MARKET_ROLE_TITLES[context.value.marketRole])
|
||
const detailId = computed(() => String(route.params.id || '').trim())
|
||
const childActive = computed(() => Boolean(detailId.value || route.meta.formMode))
|
||
const moduleContract = computed(() => getMarketModule(context.value.module))
|
||
const listFilterTabs = computed(() =>
|
||
usesSourceTabs(context.value.module) ? (moduleContract.value.statusOptions || []) : []
|
||
)
|
||
const listStatus = ref(
|
||
usesSourceTabs(context.value.module) ? resolveSourceListStatus(route.query) : ''
|
||
)
|
||
const searchPlaceholder = computed(() =>
|
||
marketSearchPlaceholder(context.value.module, listStatus.value)
|
||
)
|
||
const keyword = ref('')
|
||
const filterSheetVisible = ref(false)
|
||
const listFilters = ref(createListFilters(context.value.module, listStatus.value))
|
||
const filterOptions = ref({})
|
||
const sheetFilterFields = computed(() =>
|
||
(moduleContract.value.filterFields || []).filter((field) =>
|
||
!field.source || field.source === listFilters.value.source
|
||
)
|
||
)
|
||
const inlineDropdownFilters = computed(() => {
|
||
const rows = Array.isArray(moduleContract.value.inlineDropdownFilters)
|
||
? moduleContract.value.inlineDropdownFilters
|
||
: []
|
||
const source = listFilters.value.source || listStatus.value
|
||
return rows.filter((field) => !field.source || field.source === source)
|
||
})
|
||
const showProtocolProjectFilter = computed(() => context.value.module === 'protocol')
|
||
const protocolProjectOptions = ref([])
|
||
const protocolProjectFilterOptions = computed(() => [
|
||
{ text: '全部项目', value: '' },
|
||
...protocolProjectOptions.value
|
||
])
|
||
const activeFilters = computed(() =>
|
||
activeFilterCount(context.value.module, listFilters.value)
|
||
)
|
||
|
||
function normalizeDropdownOption(item) {
|
||
return {
|
||
text: String(item?.text ?? item?.label ?? item?.name ?? item?.value ?? ''),
|
||
value: String(item?.value ?? item?.id ?? item?.code ?? '')
|
||
}
|
||
}
|
||
|
||
/** 稳定 options 引用,避免模板每次 render 新建数组触发 van-dropdown 死循环白屏 */
|
||
const inlineFilterOptionsByKey = computed(() => {
|
||
const result = {}
|
||
for (const field of inlineDropdownFilters.value) {
|
||
const rows = field.optionKey
|
||
? (filterOptions.value[field.optionKey] || [])
|
||
: (field.options || [])
|
||
result[field.key] = [
|
||
{ text: field.allText || '全部', value: '' },
|
||
...(Array.isArray(rows) ? rows : []).map(normalizeDropdownOption)
|
||
]
|
||
}
|
||
return result
|
||
})
|
||
const collectionActions = ref([])
|
||
const batchSelectionMode = ref(false)
|
||
const batchDeleting = ref(false)
|
||
const selectedRecordIds = ref([])
|
||
const listState = ref(createMarketListState())
|
||
const items = computed(() => listState.value.items)
|
||
const total = computed(() => listState.value.total)
|
||
const loading = computed(() => listState.value.loading)
|
||
const loadingMore = computed(() => listState.value.loadingMore)
|
||
const errorMessage = computed(() => listState.value.errorMessage)
|
||
const hasMore = computed(() => items.value.length < total.value)
|
||
const canCreate = computed(() => intersectAllowedActions(
|
||
context.value.module,
|
||
context.value.marketRole,
|
||
collectionActions.value
|
||
).includes('create'))
|
||
const deletableItems = computed(() => items.value.filter(canDeleteProtocol))
|
||
const batchDeleteAvailable = computed(() =>
|
||
context.value.module === 'protocol' && deletableItems.value.length > 0
|
||
)
|
||
const allDeletableSelected = computed(() =>
|
||
deletableItems.value.length > 0 && deletableItems.value.every((item) =>
|
||
selectedRecordIds.value.includes(String(item.id || ''))
|
||
)
|
||
)
|
||
let requestSequence = 0
|
||
let abortController = null
|
||
let projectOptionsController = null
|
||
let searchTimer = null
|
||
|
||
function normalizeList(result) {
|
||
const rows = result?.list || result?.items || result?.rows || []
|
||
return {
|
||
rows: Array.isArray(rows) ? rows : [],
|
||
total: Number(result?.total ?? rows.length) || 0,
|
||
allowedActions: Array.isArray(result?.allowedActions) ? result.allowedActions : []
|
||
}
|
||
}
|
||
|
||
async function loadPage(reset) {
|
||
if (!reset && (!hasMore.value || listState.value.loading || listState.value.loadingMore)) return
|
||
if (reset) {
|
||
collectionActions.value = []
|
||
batchSelectionMode.value = false
|
||
selectedRecordIds.value = []
|
||
}
|
||
const requestId = ++requestSequence
|
||
abortController?.abort()
|
||
abortController = new AbortController()
|
||
const started = startMarketListRequest(listState.value, { requestId, reset })
|
||
listState.value = started.state
|
||
const requestContext = { ...context.value }
|
||
const listParams = buildListParams(context.value.module, listFilters.value)
|
||
try {
|
||
const result = normalizeList(await fetchMarketList(
|
||
requestContext,
|
||
{
|
||
keyword: keyword.value.trim(),
|
||
...listParams,
|
||
page: started.page,
|
||
pageSize: PAGE_SIZE
|
||
},
|
||
{ signal: abortController.signal }
|
||
))
|
||
const nextState = finishMarketListRequest(listState.value, {
|
||
requestId, page: started.page, reset, rows: result.rows, total: result.total
|
||
})
|
||
if (listState.value.requestId === requestId) collectionActions.value = result.allowedActions
|
||
listState.value = nextState
|
||
} catch (error) {
|
||
if (error?.name === 'AbortError') return
|
||
listState.value = failMarketListRequest(listState.value, {
|
||
requestId,
|
||
message: marketErrorMessage(error, '数据加载失败')
|
||
})
|
||
if (!reset && listState.value.requestId === requestId) showToast(listState.value.errorMessage)
|
||
}
|
||
}
|
||
|
||
function search() {
|
||
window.clearTimeout(searchTimer)
|
||
loadPage(true)
|
||
}
|
||
|
||
function queueSearch() {
|
||
window.clearTimeout(searchTimer)
|
||
searchTimer = window.setTimeout(search, 350)
|
||
}
|
||
|
||
async function loadProtocolProjectOptions() {
|
||
projectOptionsController?.abort()
|
||
if (!showProtocolProjectFilter.value) {
|
||
protocolProjectOptions.value = []
|
||
return
|
||
}
|
||
const current = new AbortController()
|
||
projectOptionsController = current
|
||
const bizType = listFilters.value.source || listStatus.value || 'cell_storage'
|
||
try {
|
||
const data = await fetchProjectOptions(bizType, {
|
||
signal: current.signal,
|
||
filter: true,
|
||
context: context.value
|
||
})
|
||
if (projectOptionsController !== current) return
|
||
protocolProjectOptions.value = projectOptions(data)
|
||
} catch (error) {
|
||
if (projectOptionsController === current && error?.name !== 'AbortError') {
|
||
protocolProjectOptions.value = []
|
||
}
|
||
}
|
||
}
|
||
|
||
async function loadListFilterOptions() {
|
||
await loadProtocolProjectOptions()
|
||
const optionKeys = [
|
||
...sheetFilterFields.value.map((field) => field.optionKey),
|
||
...inlineDropdownFilters.value.map((field) => field.optionKey)
|
||
].filter(Boolean)
|
||
if (!optionKeys.length) {
|
||
filterOptions.value = {}
|
||
return
|
||
}
|
||
try {
|
||
const result = await fetchMarketFormOptions(context.value, {})
|
||
filterOptions.value = Object.fromEntries(
|
||
optionKeys.map((key) => [key, Array.isArray(result?.[key]) ? result[key] : []])
|
||
)
|
||
} catch {
|
||
filterOptions.value = {}
|
||
}
|
||
}
|
||
|
||
function applyListFilters(value) {
|
||
listFilters.value = value
|
||
loadPage(true)
|
||
}
|
||
|
||
function resetListFilters(value) {
|
||
listFilters.value = value
|
||
loadPage(true)
|
||
}
|
||
|
||
function onInlineFilterChange(key, value) {
|
||
const nextKey = String(key || '').trim()
|
||
if (!nextKey) return
|
||
listFilters.value = {
|
||
...listFilters.value,
|
||
[nextKey]: value == null ? '' : String(value)
|
||
}
|
||
loadPage(true)
|
||
}
|
||
|
||
function openDetail(item, extraQuery = {}) {
|
||
const target = moduleContract.value.detailTarget?.(item)
|
||
const targetModule = target?.module || context.value.module
|
||
const id = String(target?.id || item?.id || '').trim()
|
||
if (!id) {
|
||
showToast('该记录缺少详情标识')
|
||
return
|
||
}
|
||
router.push({
|
||
name: `market-${context.value.marketRole}-${targetModule}-detail`,
|
||
params: { id },
|
||
query: {
|
||
...marketRecordNavigationQuery(context.value.module, item, route.query),
|
||
...(target?.query || {}),
|
||
...extraQuery
|
||
}
|
||
})
|
||
}
|
||
|
||
function openProtocol(item) {
|
||
const id = String(item.protocolId || item.collectionProtocolId || item.parentId || '').trim()
|
||
if (!id) {
|
||
showToast('该记录缺少关联协议标识')
|
||
return
|
||
}
|
||
router.push({
|
||
name: `market-${context.value.marketRole}-protocol-detail`,
|
||
params: { id },
|
||
query: {
|
||
...pickMarketNavigationQuery(route.query),
|
||
source: item.source || 'cell_storage',
|
||
...(context.value.module === 'payment' ? { from: 'payment' } : {})
|
||
}
|
||
})
|
||
}
|
||
|
||
function openForm(item, action) {
|
||
const query = {
|
||
...marketRecordNavigationQuery(context.value.module, item, route.query),
|
||
action
|
||
}
|
||
if (action === 'register-transfer') {
|
||
query.scheduleId = String((item.schedules || []).find((row) => row.allowedActions?.includes('register-transfer'))?.id || '')
|
||
}
|
||
router.push({
|
||
name: `market-${context.value.marketRole}-${context.value.module}-edit`,
|
||
params: { id: item.id },
|
||
query
|
||
})
|
||
}
|
||
|
||
async function deleteProtocol(item) {
|
||
try {
|
||
const name = String(item.motherName || item.code || '').trim()
|
||
await showConfirmDialog({
|
||
title: '删除协议单',
|
||
message: name ? `确认删除 ${name} 吗?` : '确认删除该协议单吗?'
|
||
})
|
||
} catch {
|
||
return
|
||
}
|
||
try {
|
||
await performMarketAction(context.value, 'delete', {
|
||
id: item.id,
|
||
data: { source: item.source }
|
||
})
|
||
showSuccessToast('删除成功')
|
||
await loadPage(true)
|
||
} catch (error) {
|
||
if (error) showToast(marketErrorMessage(error))
|
||
}
|
||
}
|
||
|
||
async function deleteFreight(item) {
|
||
const linked = Number(item.visibleItemCount ?? item.items?.length ?? 0)
|
||
const linkHint =
|
||
linked > 0 ? `将解除其全部关联样本,并删除该运费单。` : '将删除该运费单。'
|
||
try {
|
||
await showConfirmDialog({
|
||
title: '删除运费单',
|
||
message: `确认删除 ${item.freightNo || item.code || '该运费单'} 吗?${linkHint}`
|
||
})
|
||
} catch {
|
||
return
|
||
}
|
||
try {
|
||
await performMarketAction(context.value, 'delete', { id: item.id })
|
||
showSuccessToast('删除成功')
|
||
await loadPage(true)
|
||
} catch (error) {
|
||
if (error) showToast(marketErrorMessage(error))
|
||
}
|
||
}
|
||
|
||
function canDeleteProtocol(item) {
|
||
return context.value.module === 'protocol' && intersectAllowedActions(
|
||
'protocol',
|
||
context.value.marketRole,
|
||
item?.allowedActions
|
||
).includes('delete')
|
||
}
|
||
|
||
function toggleRecordSelection(item) {
|
||
if (!canDeleteProtocol(item)) return
|
||
const id = String(item?.id || '')
|
||
if (!id) return
|
||
selectedRecordIds.value = selectedRecordIds.value.includes(id)
|
||
? selectedRecordIds.value.filter((value) => value !== id)
|
||
: [...selectedRecordIds.value, id]
|
||
}
|
||
|
||
function toggleSelectAll() {
|
||
selectedRecordIds.value = allDeletableSelected.value
|
||
? []
|
||
: deletableItems.value.map((item) => String(item.id))
|
||
}
|
||
|
||
function cancelBatchSelection() {
|
||
batchSelectionMode.value = false
|
||
selectedRecordIds.value = []
|
||
}
|
||
|
||
function toggleBatchSelectionMode() {
|
||
batchSelectionMode.value = true
|
||
selectedRecordIds.value = []
|
||
}
|
||
|
||
async function deleteSelectedProtocols() {
|
||
if (!selectedRecordIds.value.length || batchDeleting.value) return
|
||
const selected = selectedRecordIds.value
|
||
.map((id) => items.value.find((item) => String(item.id || '') === id))
|
||
.filter(Boolean)
|
||
try {
|
||
await showConfirmDialog({
|
||
title: '批量删除协议单',
|
||
message: `确认删除已选的 ${selected.length} 条协议单吗?`
|
||
})
|
||
} catch {
|
||
return
|
||
}
|
||
batchDeleting.value = true
|
||
const result = await deleteMarketItemsSequentially(selected, (item) =>
|
||
performMarketAction(context.value, 'delete', {
|
||
id: item.id,
|
||
data: { source: item.source }
|
||
})
|
||
)
|
||
batchDeleting.value = false
|
||
if (result.failed) {
|
||
showToast(
|
||
`已删除 ${result.succeeded} 条,失败 ${result.failed} 条,未处理 ${result.unprocessed} 条:${marketErrorMessage(result.error)}`
|
||
)
|
||
} else {
|
||
showSuccessToast(`已删除 ${result.succeeded} 条`)
|
||
}
|
||
await loadPage(true)
|
||
}
|
||
|
||
function handleCardAction(action, item) {
|
||
const chaseView = context.value.module === 'payment-chase'
|
||
? resolvePaymentChaseView(action)
|
||
: ''
|
||
if (chaseView) return openDetail(item, { view: chaseView })
|
||
if (action === 'view' || action === 'view-payment' || action === 'view-payment-detail') return openDetail(item)
|
||
if (action === 'view-storage-qc') return openDetail(item, { focus: 'storage-qc' })
|
||
if (action === 'view-protocol') return openProtocol(item)
|
||
if (action === 'delete' && context.value.module === 'protocol') return deleteProtocol(item)
|
||
if (action === 'delete' && context.value.module === 'freight') return deleteFreight(item)
|
||
if (['edit', 'register-transfer', 'link', 'unlink'].includes(action)) {
|
||
return openForm(item, action)
|
||
}
|
||
}
|
||
|
||
function openCreate() {
|
||
router.push({
|
||
name: `market-${context.value.marketRole}-${context.value.module}-new`,
|
||
query: {
|
||
...pickMarketNavigationQuery(route.query),
|
||
...(context.value.module === 'protocol' ? { source: listStatus.value } : {})
|
||
}
|
||
})
|
||
}
|
||
|
||
function switchListStatus(value) {
|
||
const next = String(value || '').trim()
|
||
if (!SOURCE_TAB_VALUES.includes(next) || next === listStatus.value) return
|
||
listStatus.value = next
|
||
listFilters.value = createListFilters('protocol', next)
|
||
keyword.value = ''
|
||
collectionActions.value = []
|
||
cancelBatchSelection()
|
||
const nextQuery = {
|
||
...pickMarketNavigationQuery(route.query),
|
||
source: next,
|
||
tab: next
|
||
}
|
||
router.replace({ query: nextQuery }).catch(() => {})
|
||
loadProtocolProjectOptions()
|
||
loadPage(true)
|
||
}
|
||
|
||
watch(
|
||
() => `${route.meta.marketRole}:${route.meta.module}`,
|
||
() => {
|
||
keyword.value = ''
|
||
collectionActions.value = []
|
||
cancelBatchSelection()
|
||
listStatus.value = usesSourceTabs(context.value.module)
|
||
? resolveSourceListStatus(route.query)
|
||
: ''
|
||
listFilters.value = createListFilters(context.value.module, listStatus.value)
|
||
filterSheetVisible.value = false
|
||
clearStalePointerLocks()
|
||
if (!childActive.value) {
|
||
loadListFilterOptions()
|
||
loadPage(true)
|
||
}
|
||
}
|
||
)
|
||
|
||
watch(detailId, (currentDetailId, previousDetailId) => {
|
||
if (shouldLoadMarketListAfterDetail({ previousDetailId, detailId: currentDetailId })) {
|
||
clearStalePointerLocks()
|
||
loadPage(true)
|
||
}
|
||
})
|
||
|
||
watch(childActive, (active, wasActive) => {
|
||
if (wasActive && !active) {
|
||
resetMarketWindowScroll()
|
||
clearStalePointerLocks()
|
||
}
|
||
})
|
||
|
||
onMounted(() => {
|
||
clearStalePointerLocks()
|
||
if (!childActive.value) {
|
||
loadListFilterOptions()
|
||
loadPage(true)
|
||
}
|
||
})
|
||
|
||
onBeforeUnmount(() => {
|
||
const requestId = ++requestSequence
|
||
listState.value = invalidateMarketRequestState(listState.value, requestId)
|
||
abortController?.abort()
|
||
projectOptionsController?.abort()
|
||
window.clearTimeout(searchTimer)
|
||
})
|
||
</script>
|