From 946f4e9e2beadbe2fd8436d690ed42df5aa1a191 Mon Sep 17 00:00:00 2001
From: wupengfei <834520024@qq.com>
Date: 星期三, 12 二月 2025 15:04:55 +0800
Subject: [PATCH] feat: mine
---
/dev/null | 72 ------------------------------------
1 files changed, 0 insertions(+), 72 deletions(-)
diff --git a/apps/cMiniApp/src/components/Input/ChooseInput.vue b/apps/cMiniApp/src/components/Input/ChooseInput.vue
deleted file mode 100644
index 6486c46..0000000
--- a/apps/cMiniApp/src/components/Input/ChooseInput.vue
+++ /dev/null
@@ -1,37 +0,0 @@
-<template>
- <nut-input
- class="nut-input-text bole-input-text"
- type="text"
- readonly
- alwaysEmbed
- v-bind="$attrs"
- >
- <template #clear>
- <slot name="clear"></slot>
- </template>
- <template #right>
- <slot name="right">
- <RectRight :size="12" class="common-choose-input-icon" />
- </slot>
- </template>
- </nut-input>
-</template>
-
-<script setup lang="ts">
-import { RectRight } from '@nutui/icons-vue-taro';
-
-defineOptions({
- name: 'ChooseInput',
-});
-</script>
-
-<style lang="scss">
-@import '@/styles/common.scss';
-
-.common-choose-input-icon {
- // width: 13px;
- // height: 23px;
- margin-left: 18px;
- color: boleGetCssVar('text-color', 'primary');
-}
-</style>
diff --git a/apps/cMiniApp/src/components/Input/ChooseInputWithAreaPicker.vue b/apps/cMiniApp/src/components/Input/ChooseInputWithAreaPicker.vue
deleted file mode 100644
index b7eaec8..0000000
--- a/apps/cMiniApp/src/components/Input/ChooseInputWithAreaPicker.vue
+++ /dev/null
@@ -1,76 +0,0 @@
-<template>
- <ChooseInput :modelValue="inputValue" @click="handleOpen()"></ChooseInput>
-</template>
-
-<script setup lang="ts">
-import { useAllAreaList } from '@/hooks';
-import Portal from '../Portal';
-import ChooseInput from './ChooseInput.vue';
-import { Popup, Picker } from '@nutui/nutui-taro';
-
-defineOptions({
- name: 'ChooseInputWithAreaPicker',
-});
-
-const { findAreaNameFromCode } = useAllAreaList();
-
-type Props = {
- fieldNames?: object;
- columns: API.AreaTreeNode[];
- modelValue: Array<string | number>;
- title?: string;
-};
-
-const props = withDefaults(defineProps<Props>(), {
- title: '閫夋嫨鍦板潃',
- fieldNames: () => ({
- text: 'areaName',
- value: 'areaCode',
- children: 'children',
- }),
-});
-const inputValue = computed(() =>
- props.modelValue.map((x) => findAreaNameFromCode(Number(x))).join(',')
-);
-
-const emit = defineEmits<{
- (e: 'update:modelValue', val: Array<string | number>): void;
-}>();
-
-function handleOpen() {
- Portal.add((key) => {
- return h(
- Portal.Container,
- { keyNumber: key, delayOpen: true },
- {
- default: ({ open, onClose }) =>
- h(
- Popup,
- {
- visible: open.value,
- 'onUpdate:visible': (value) => !value && onClose(),
- position: 'bottom',
- },
- {
- default: () =>
- h(Picker, {
- modelValue: props.modelValue,
- columns: props.columns,
- fieldNames: props.fieldNames,
- title: props.title,
- onCancel: onClose,
- onConfirm: ({ selectedValue, selectedOptions }) => {
- emit(
- 'update:modelValue',
- selectedOptions.map((x) => x.areaCode)
- );
- onClose();
- },
- }),
- }
- ),
- }
- );
- });
-}
-</script>
diff --git a/apps/cMiniApp/src/components/Input/ChooseInputWithPicker.vue b/apps/cMiniApp/src/components/Input/ChooseInputWithPicker.vue
deleted file mode 100644
index 572583a..0000000
--- a/apps/cMiniApp/src/components/Input/ChooseInputWithPicker.vue
+++ /dev/null
@@ -1,72 +0,0 @@
-<template>
- <ChooseInput :modelValue="inputValue" @click="handleOpen()"></ChooseInput>
-</template>
-
-<script setup lang="ts">
-import Portal from '../Portal';
-import ChooseInput from './ChooseInput.vue';
-import { Popup, Picker } from '@nutui/nutui-taro';
-import { convertOptions, ValueEnum } from './input';
-
-defineOptions({
- name: 'ChooseInputWithPicker',
-});
-
-type Props = {
- enumLabelKey?: string;
- enumValueKey?: string;
- valueEnum?: ValueEnum;
- modelValue: string | number;
-};
-
-const props = withDefaults(defineProps<Props>(), {
- enumLabelKey: 'name',
- enumValueKey: 'id',
-});
-
-const emit = defineEmits<{
- (e: 'update:modelValue', val: string | number): void;
-}>();
-
-const options = computed(() =>
- convertOptions(props.valueEnum, props.enumLabelKey, props.enumValueKey)
-);
-
-const inputValue = computed(
- () => options.value?.find((x) => x.value === props.modelValue)?.text ?? ''
-);
-
-function handleOpen() {
- const _modelValue = [props.modelValue];
- Portal.add((key) => {
- return h(
- Portal.Container,
- { keyNumber: key, delayOpen: true },
- {
- default: ({ open, onClose }) =>
- h(
- Popup,
- {
- visible: open.value,
- 'onUpdate:visible': (value) => !value && onClose(),
- position: 'bottom',
- },
- {
- default: () =>
- h(Picker, {
- modelValue: _modelValue,
- columns: options.value,
- onCancel: onClose,
- onConfirm: ({ selectedValue, selectedOptions }) => {
- console.log('selectedValue: ', selectedValue, selectedOptions);
- emit('update:modelValue', selectedOptions[0].value);
- onClose();
- },
- }),
- }
- ),
- }
- );
- });
-}
-</script>
diff --git a/apps/cMiniApp/src/components/Input/NumberInput.vue b/apps/cMiniApp/src/components/Input/NumberInput.vue
deleted file mode 100644
index 05ba733..0000000
--- a/apps/cMiniApp/src/components/Input/NumberInput.vue
+++ /dev/null
@@ -1,55 +0,0 @@
-<template>
- <nut-input type="number" :formatter="formatter" formatTrigger="onBlur">
- <template #right>
- <slot name="right"></slot>
- </template>
- </nut-input>
-</template>
-
-<script setup lang="ts">
-defineOptions({
- name: 'NumberInput',
-});
-
-type Props = {
- min?: number;
- max?: number;
- precision?: number;
-};
-
-const props = withDefaults(defineProps<Props>(), {
- max: Math.pow(2, 53) - 1,
-});
-
-function formatter(value: string): string {
- const newVal = value !== '' ? Number.parseFloat(value) : '';
- if (Number.isNaN(newVal)) {
- return '';
- }
- if (newVal && newVal > props.max) {
- return `${toPrecision(props.max)}`;
- }
- if (props.min !== undefined && newVal && newVal < props.min) {
- return `${toPrecision(props.min)}`;
- }
- return newVal !== '' ? `${toPrecision(newVal)}` : newVal;
-}
-
-function toPrecision(num: number) {
- if (props.precision) {
- if (props.precision === 0) return Math.round(num);
- let snum = String(num);
- const pointPos = snum.indexOf('.');
- if (pointPos === -1) return num;
- const nums = snum.replace('.', '').split('');
- const datum = nums[pointPos + props.precision];
- if (!datum) return num;
- const length = snum.length;
- if (snum.charAt(length - 1) === '5') {
- snum = `${snum.slice(0, Math.max(0, length - 1))}6`;
- }
- return Number(snum).toFixed(props.precision);
- }
- return String(num);
-}
-</script>
diff --git a/apps/cMiniApp/src/components/Input/input.ts b/apps/cMiniApp/src/components/Input/input.ts
deleted file mode 100644
index d1a5309..0000000
--- a/apps/cMiniApp/src/components/Input/input.ts
+++ /dev/null
@@ -1,31 +0,0 @@
-import _ from 'lodash';
-
-export type ValueEnumItem = { [key: string]: any };
-export type ValueEnum = ValueEnumItem[] | Record<string | number, string>;
-export type OptionItem = {
- text: string;
- value: string | number;
- [key: string]: any;
-};
-
-export function convertOptions(
- valueEnum: ValueEnum,
- enumLabelKey: string,
- enumValueKey: string
-): OptionItem[] {
- return _.isArray(valueEnum)
- ? valueEnum.map((x) => ({
- ...x,
- text: x[enumLabelKey],
- value: _.isNaN(Number(x[enumValueKey])) ? x[enumValueKey] : Number(x[enumValueKey]),
- }))
- : Object.keys(valueEnum).map((x) => ({
- value: _.isNaN(Number(x)) ? x : Number(x),
- text: valueEnum[x],
- }));
-}
-
-export type ChooseCheckBoxOptionItem = {
- text: string;
- value: string | number;
-};
diff --git a/apps/cMiniApp/src/components/Portal/Portal.vue b/apps/cMiniApp/src/components/Portal/Portal.vue
deleted file mode 100644
index 06d5c1a..0000000
--- a/apps/cMiniApp/src/components/Portal/Portal.vue
+++ /dev/null
@@ -1,19 +0,0 @@
-<template>
- <PortalConsumer :manager="portalContext">
- <template #default>
- <slot />
- </template>
- </PortalConsumer>
-</template>
-
-<script setup lang="ts">
-import PortalConsumer from './portal-consumer.vue';
-// import PortalContainer from './portal-container';
-import { portal, usePortalContext } from './portal';
-
-defineOptions({
- name: 'Portal',
-});
-
-const portalContext = usePortalContext();
-</script>
diff --git a/apps/cMiniApp/src/components/Portal/PortalManager.vue b/apps/cMiniApp/src/components/Portal/PortalManager.vue
deleted file mode 100644
index 4f0a6cd..0000000
--- a/apps/cMiniApp/src/components/Portal/PortalManager.vue
+++ /dev/null
@@ -1,44 +0,0 @@
-<script lang="ts">
-import { State, PortalNode } from './portal';
-
-export default defineComponent({
- name: 'PortalManager',
- setup(props, { expose }) {
- const state = reactive<State>({
- portals: [],
- });
-
- const mount = (key: number, children: PortalNode) => {
- state.portals.push({ key, children });
- };
- const update = (key: number, children: PortalNode) => {
- state.portals = state.portals.map((item) => {
- if (item.key === key) {
- return { ...item, children };
- }
- return item;
- });
- };
-
- const unmount = (key: number) => {
- state.portals = state.portals.filter((item) => item.key !== key);
- };
-
- expose({
- mount,
- update,
- unmount,
- });
-
- return () => {
- return h(
- 'div',
- null,
- state.portals.map((item) => {
- return h('div', { key: item.key }, [item.children]);
- })
- );
- };
- },
-});
-</script>
diff --git a/apps/cMiniApp/src/components/Portal/index.ts b/apps/cMiniApp/src/components/Portal/index.ts
deleted file mode 100644
index 29fbcf8..0000000
--- a/apps/cMiniApp/src/components/Portal/index.ts
+++ /dev/null
@@ -1,12 +0,0 @@
-import PortalContainer from './portal-container.vue';
-import PortalHost from './portal-host.vue';
-import { portal } from './portal';
-import Portal from './Portal.vue';
-
-export default {
- Host: PortalHost,
- add: portal.add,
- remove: portal.remove,
- Portal: Portal,
- Container: PortalContainer,
-};
diff --git a/apps/cMiniApp/src/components/Portal/portal-consumer.vue b/apps/cMiniApp/src/components/Portal/portal-consumer.vue
deleted file mode 100644
index ba1a582..0000000
--- a/apps/cMiniApp/src/components/Portal/portal-consumer.vue
+++ /dev/null
@@ -1,37 +0,0 @@
-<script lang="ts">
-import { PortalMethods } from './portal';
-
-export default defineComponent({
- name: 'PortalConsumer',
- props: {
- manager: {
- type: Object as PropType<PortalMethods>,
- },
- },
- setup(props) {
- const _key = ref<number>();
-
- const slots = useSlots();
-
- onMounted(() => {
- if (!props.manager) {
- throw new Error('forgot');
- }
- const defaultSlot = slots.default();
- props.manager.update(_key.value, defaultSlot);
- _key.value = props.manager.mount(defaultSlot);
- });
-
- onUpdated(() => {
- const defaultSlot = slots.default();
- props.manager.update(_key.value, defaultSlot);
- });
-
- onUnmounted(() => {
- props.manager.unmount(_key.value);
- });
-
- return () => null;
- },
-});
-</script>
diff --git a/apps/cMiniApp/src/components/Portal/portal-container.vue b/apps/cMiniApp/src/components/Portal/portal-container.vue
deleted file mode 100644
index 7c12a7e..0000000
--- a/apps/cMiniApp/src/components/Portal/portal-container.vue
+++ /dev/null
@@ -1,50 +0,0 @@
-<script lang="ts">
-import { VNode } from 'vue';
-import { portal } from './portal';
-
-export default defineComponent({
- name: 'portal-container',
- props: {
- render: {
- type: Function as PropType<(open: Ref<boolean>, onClose?: () => any) => VNode>,
- },
- keyNumber: {
- type: Number,
- },
- /**
- * 鏄惁寤惰繜璁剧疆open涓簍rue
- */
- delayOpen: {
- type: Boolean,
- },
- },
- setup(props, { slots }) {
- const open = ref(!props.delayOpen);
-
- function onClose() {
- open.value = false;
- }
-
- onMounted(() => {
- if (props.delayOpen) {
- setTimeout(() => {
- open.value = true;
- }, 30);
- }
- });
-
- watch(open, (open, preOpen) => {
- if (preOpen && !open) {
- setTimeout(() => {
- portal.remove(props.keyNumber);
- }, 300);
- }
- });
-
- return () => {
- // const childrenNode = props.render(open, onClose);
- return slots.default?.({ open, onClose });
- };
- },
-});
-</script>
diff --git a/apps/cMiniApp/src/components/Portal/portal-host.vue b/apps/cMiniApp/src/components/Portal/portal-host.vue
deleted file mode 100644
index 05068a7..0000000
--- a/apps/cMiniApp/src/components/Portal/portal-host.vue
+++ /dev/null
@@ -1,104 +0,0 @@
-<template>
- <slot></slot>
- <PortalManager ref="_manager" />
-</template>
-
-<script lang="ts">
-defineComponent({
- name: 'portal-host',
- inheritAttrs: false,
-});
-</script>
-
-<script setup lang="ts">
-import {
- PortalContextKey,
- Operation,
- getUniqueKey,
- addType,
- removeType,
- TopViewEventEmitter,
- PortalNode,
- PortalManagerInstance,
-} from './portal';
-import PortalManager from './PortalManager.vue';
-
-const _nextKey = ref(0);
-const _queue = ref<Operation[]>([]);
-const _manager = ref<PortalManagerInstance>();
-
-onMounted(() => {
- TopViewEventEmitter.on(getUniqueKey(addType), _mount);
- TopViewEventEmitter.on(getUniqueKey(removeType), _unmount);
-
- while (_queue.value.length && _manager.value) {
- const action = _queue.value.pop();
- if (!action) {
- continue;
- }
-
- switch (action.type) {
- case 'mount':
- _manager.value.mount(action.key, action.children);
- break;
- case 'update':
- _manager.value.update(action.key, action.children);
- break;
- case 'unmount':
- _manager.value.unmount(action.key);
- break;
- }
- }
-});
-
-onUnmounted(() => {
- TopViewEventEmitter.off(getUniqueKey(addType), _mount);
- TopViewEventEmitter.off(getUniqueKey(removeType), _unmount);
-});
-
-const _setManager = (manager?: any) => {
- _manager.value = manager;
-};
-
-const _mount = (children: PortalNode, _key?: number) => {
- const key = _key || _nextKey.value++;
- if (_manager.value) {
- _manager.value.mount(key, children);
- } else {
- _queue.value.push({ type: 'mount', key, children });
- }
-
- return key;
-};
-
-const _update = (key: number, children: PortalNode) => {
- if (_manager.value) {
- _manager.value.update(key, children);
- } else {
- const op: Operation = { type: 'mount', key, children };
- const index = _queue.value.findIndex(
- (o) => o.type === 'mount' || (o.type === 'update' && o.key === key)
- );
-
- if (index > -1) {
- _queue.value[index] = op;
- } else {
- _queue.value.push(op);
- }
- }
-};
-
-const _unmount = (key: number) => {
- if (_manager.value) {
- _manager.value.unmount(key);
- } else {
- _queue.value.push({ type: 'unmount', key });
- }
-};
-
-provide(PortalContextKey, {
- mount: _mount,
- update: _update,
- unmount: _unmount,
-});
-</script>
diff --git a/apps/cMiniApp/src/components/Portal/portal.ts b/apps/cMiniApp/src/components/Portal/portal.ts
deleted file mode 100644
index 38b8216..0000000
--- a/apps/cMiniApp/src/components/Portal/portal.ts
+++ /dev/null
@@ -1,72 +0,0 @@
-import type { VNode } from 'vue';
-import Taro from '@tarojs/taro';
-
-export type PortalNode = VNode | VNode[];
-
-export type State = {
- portals: Array<{
- key: number;
- children: PortalNode;
- }>;
-};
-export type PortalManagerState = {
- portals: Array<{
- key: number;
- children: PortalNode;
- }>;
-};
-
-export type PortalMethods = {
- mount: (children: PortalNode) => number;
- update: (key: number, children: PortalNode) => void;
- unmount: (key: number) => void;
-};
-
-export type Operation =
- | { type: 'mount'; key: number; children: PortalNode }
- | { type: 'update'; key: number; children: PortalNode }
- | { type: 'unmount'; key: number };
-
-export const PortalContextKey: InjectionKey<PortalMethods> = Symbol('PortalContextKey');
-
-export function usePortalContext() {
- return inject(PortalContextKey);
-}
-
-export function getUniqueKey(key: string) {
- const router = Taro.getCurrentInstance().router;
- const prefix = router.path;
- return `${prefix}_${key}`;
-}
-
-// events
-export const addType = 'ADD_PORTAL';
-export const removeType = 'REMOVE_PORTAL';
-
-export const TopViewEventEmitter = new Taro.Events();
-
-class PortalGuard {
- private nextKey = 10000;
- add = (render: (_key: number) => PortalNode) => {
- const key = this.nextKey++;
- const node = render(key);
- TopViewEventEmitter.trigger(getUniqueKey(addType), node, key);
- return key;
- };
- remove = (key: number) => {
- TopViewEventEmitter.trigger(getUniqueKey(removeType), key);
- };
-}
-/**
- * portal
- */
-export const portal = new PortalGuard();
-
-export type PortalManagerInstance = {
- mount: (key: number, children: PortalNode) => void;
- update: (key: number, children: PortalNode) => void;
- unmount: (key: number) => {
- key: number;
- children: PortalNode;
- }[];
-};
--
Gitblit v1.10.0