tangweijie 5099f2e87e Initial commit: Vue3 + TypeScript 前端项目
- Vue 3 + TypeScript + Element Plus 前端界面
- Pinia 状态管理
- Vue Router 4 路由管理
- Axios HTTP 客户端
- MSW (Mock Service Worker) 开发环境模拟
- 账户管理界面 (列表、详情、三科目余额展示)
- 交易管理界面 (列表、详情)
- 对账管理界面 (三账校验)
- 完善的 API 客户端封装
- Docker 容器化配置
- Nginx 配置用于生产环境
2026-01-05 17:57:11 +08:00

68 lines
2.2 KiB
JavaScript

import { ref, provide, inject, onMounted, unref, onBeforeUnmount } from 'vue';
import Collection from './collection2.mjs';
import CollectionItem from './collection-item.mjs';
const COLLECTION_ITEM_SIGN = `data-el-collection-item`;
const createCollectionWithScope = (name) => {
const COLLECTION_NAME = `El${name}Collection`;
const COLLECTION_ITEM_NAME = `${COLLECTION_NAME}Item`;
const COLLECTION_INJECTION_KEY = Symbol(COLLECTION_NAME);
const COLLECTION_ITEM_INJECTION_KEY = Symbol(COLLECTION_ITEM_NAME);
const ElCollection = Object.assign({}, Collection, {
name: COLLECTION_NAME,
setup() {
const collectionRef = ref();
const itemMap = /* @__PURE__ */ new Map();
const getItems = () => {
const collectionEl = unref(collectionRef);
if (!collectionEl)
return [];
const orderedNodes = Array.from(
collectionEl.querySelectorAll(`[${COLLECTION_ITEM_SIGN}]`)
);
const items = [...itemMap.values()];
return items.sort(
(a, b) => orderedNodes.indexOf(a.ref) - orderedNodes.indexOf(b.ref)
);
};
provide(COLLECTION_INJECTION_KEY, {
itemMap,
getItems,
collectionRef
});
}
});
const ElCollectionItem = Object.assign({}, CollectionItem, {
name: COLLECTION_ITEM_NAME,
setup(_, { attrs }) {
const collectionItemRef = ref();
const collectionInjection = inject(COLLECTION_INJECTION_KEY, void 0);
provide(COLLECTION_ITEM_INJECTION_KEY, {
collectionItemRef
});
onMounted(() => {
const collectionItemEl = unref(collectionItemRef);
if (collectionItemEl) {
collectionInjection.itemMap.set(collectionItemEl, {
ref: collectionItemEl,
...attrs
});
}
});
onBeforeUnmount(() => {
const collectionItemEl = unref(collectionItemRef);
collectionInjection.itemMap.delete(collectionItemEl);
});
}
});
return {
COLLECTION_INJECTION_KEY,
COLLECTION_ITEM_INJECTION_KEY,
ElCollection,
ElCollectionItem
};
};
export { COLLECTION_ITEM_SIGN, createCollectionWithScope };
//# sourceMappingURL=collection.mjs.map