|
@@ -1,11 +1,7 @@
|
|
|
<template>
|
|
<template>
|
|
|
<view :class="classes">
|
|
<view :class="classes">
|
|
|
<view
|
|
<view
|
|
|
- :class="[
|
|
|
|
|
- 'collapse-item',
|
|
|
|
|
- { 'item-expanded': openExpanded },
|
|
|
|
|
- { 'nut-collapse-item-disabled': disabled }
|
|
|
|
|
- ]"
|
|
|
|
|
|
|
+ :class="['collapse-item', { 'item-expanded': openExpanded }, { 'nut-collapse-item-disabled': disabled }]"
|
|
|
@click="toggleOpen"
|
|
@click="toggleOpen"
|
|
|
>
|
|
>
|
|
|
<view class="collapse-title">
|
|
<view class="collapse-title">
|
|
@@ -16,10 +12,7 @@
|
|
|
:name="titleIcon"
|
|
:name="titleIcon"
|
|
|
:size="titleIconSize"
|
|
:size="titleIconSize"
|
|
|
:color="titleIconColor"
|
|
:color="titleIconColor"
|
|
|
- :class="[
|
|
|
|
|
- 'collapse-title-icon',
|
|
|
|
|
- titleIconPosition == 'left' ? 'titleIconLeft' : 'titleIconRight'
|
|
|
|
|
- ]"
|
|
|
|
|
|
|
+ :class="['collapse-title-icon', titleIconPosition == 'left' ? 'titleIconLeft' : 'titleIconRight']"
|
|
|
></nut-icon>
|
|
></nut-icon>
|
|
|
<template v-if="$slots.mTitle">
|
|
<template v-if="$slots.mTitle">
|
|
|
<slot name="mTitle"></slot>
|
|
<slot name="mTitle"></slot>
|
|
@@ -51,11 +44,7 @@
|
|
|
:name="icon"
|
|
:name="icon"
|
|
|
:size="iconSize"
|
|
:size="iconSize"
|
|
|
:color="iconColor"
|
|
:color="iconColor"
|
|
|
- :class="[
|
|
|
|
|
- 'collapse-icon',
|
|
|
|
|
- { 'col-expanded': openExpanded },
|
|
|
|
|
- { 'collapse-icon-disabled': disabled }
|
|
|
|
|
- ]"
|
|
|
|
|
|
|
+ :class="['collapse-icon', { 'col-expanded': openExpanded }, { 'collapse-icon-disabled': disabled }]"
|
|
|
:style="iconStyle"
|
|
:style="iconStyle"
|
|
|
></nut-icon>
|
|
></nut-icon>
|
|
|
</view>
|
|
</view>
|
|
@@ -76,18 +65,18 @@ import {
|
|
|
inject,
|
|
inject,
|
|
|
toRefs,
|
|
toRefs,
|
|
|
onMounted,
|
|
onMounted,
|
|
|
|
|
+ Ref,
|
|
|
ref,
|
|
ref,
|
|
|
|
|
+ unref,
|
|
|
nextTick,
|
|
nextTick,
|
|
|
computed,
|
|
computed,
|
|
|
watch,
|
|
watch,
|
|
|
getCurrentInstance,
|
|
getCurrentInstance,
|
|
|
ComponentInternalInstance
|
|
ComponentInternalInstance
|
|
|
} from 'vue';
|
|
} from 'vue';
|
|
|
-import Taro, {
|
|
|
|
|
- eventCenter,
|
|
|
|
|
- getCurrentInstance as getCurrentInstanceTaro
|
|
|
|
|
-} from '@tarojs/taro';
|
|
|
|
|
|
|
+import Taro, { eventCenter, getCurrentInstance as getCurrentInstanceTaro } from '@tarojs/taro';
|
|
|
import { createComponent } from '../../utils/create';
|
|
import { createComponent } from '../../utils/create';
|
|
|
|
|
+import { useTaroRect } from '../../utils/useTaroRect';
|
|
|
const { create, componentName } = createComponent('collapse-item');
|
|
const { create, componentName } = createComponent('collapse-item');
|
|
|
|
|
|
|
|
export default create({
|
|
export default create({
|
|
@@ -140,9 +129,7 @@ export default create({
|
|
|
// classDirection: 'right',
|
|
// classDirection: 'right',
|
|
|
iconStyle: {
|
|
iconStyle: {
|
|
|
transform: 'rotate(0deg)',
|
|
transform: 'rotate(0deg)',
|
|
|
- marginTop: parent.props.iconHeght
|
|
|
|
|
- ? '-' + parent.props.iconHeght / 2 + 'px'
|
|
|
|
|
- : '-10px'
|
|
|
|
|
|
|
+ marginTop: parent.props.iconHeght ? '-' + parent.props.iconHeght / 2 + 'px' : '-10px'
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
|
|
|
|
@@ -180,8 +167,7 @@ export default create({
|
|
|
if (parent.props.icon && !proxyData.openExpanded) {
|
|
if (parent.props.icon && !proxyData.openExpanded) {
|
|
|
proxyData.iconStyle['transform'] = 'rotate(0deg)';
|
|
proxyData.iconStyle['transform'] = 'rotate(0deg)';
|
|
|
} else {
|
|
} else {
|
|
|
- proxyData.iconStyle['transform'] =
|
|
|
|
|
- 'rotate(' + parent.props.rotate + 'deg)';
|
|
|
|
|
|
|
+ proxyData.iconStyle['transform'] = 'rotate(' + parent.props.rotate + 'deg)';
|
|
|
}
|
|
}
|
|
|
nextTick(() => {
|
|
nextTick(() => {
|
|
|
const query = Taro.createSelectorQuery();
|
|
const query = Taro.createSelectorQuery();
|
|
@@ -203,8 +189,7 @@ export default create({
|
|
|
const defaultOpen = () => {
|
|
const defaultOpen = () => {
|
|
|
open();
|
|
open();
|
|
|
if (parent.props.icon) {
|
|
if (parent.props.icon) {
|
|
|
- proxyData['iconStyle']['transform'] =
|
|
|
|
|
- 'rotate(' + parent.props.rotate + 'deg)';
|
|
|
|
|
|
|
+ proxyData['iconStyle']['transform'] = 'rotate(' + parent.props.rotate + 'deg)';
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
|
|
|
|
@@ -255,41 +240,48 @@ export default create({
|
|
|
let h = tm[0]['height'];
|
|
let h = tm[0]['height'];
|
|
|
item1.conHeight = h;
|
|
item1.conHeight = h;
|
|
|
}
|
|
}
|
|
|
- // ary.forEach((item2: any, index2: number) => {
|
|
|
|
|
- // let ary2 = Array.from(item2.children);
|
|
|
|
|
- // ary2.length > 0 &&
|
|
|
|
|
- // ary2.forEach((item3: any, index3: number) => {
|
|
|
|
|
- // if (domID.includes(item3.uid)) {
|
|
|
|
|
- // const h = list.filter((item4: any) => item4.id == item3.uid)[0]
|
|
|
|
|
- // ?.height;
|
|
|
|
|
- // item1.conHeight = h;
|
|
|
|
|
- // }
|
|
|
|
|
- // });
|
|
|
|
|
- // });
|
|
|
|
|
});
|
|
});
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- // let list: any = [],
|
|
|
|
|
- // domID: any = [];
|
|
|
|
|
|
|
+ const getH5 = () => {
|
|
|
|
|
+ parent.children.forEach((item1: any, index1: number) => {
|
|
|
|
|
+ let ary: any = Array.from(item1.$el.children);
|
|
|
|
|
+ let h = ary[1].children[0]['offsetHeight'];
|
|
|
|
|
+ item1.conHeight = h;
|
|
|
|
|
+ });
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ const getRefHeight = () => {
|
|
|
|
|
+ const query = Taro.createSelectorQuery();
|
|
|
|
|
+ query.selectAll('.collapse-content').boundingClientRect();
|
|
|
|
|
+ query.exec((res) => {
|
|
|
|
|
+ if (Taro.getEnv() === 'WEB') {
|
|
|
|
|
+ getH5();
|
|
|
|
|
+ } else {
|
|
|
|
|
+ getH(res[0]);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
onMounted(() => {
|
|
onMounted(() => {
|
|
|
const { name } = props;
|
|
const { name } = props;
|
|
|
const active = parent && parent.props.active;
|
|
const active = parent && parent.props.active;
|
|
|
// 获取 DOM 元素
|
|
// 获取 DOM 元素
|
|
|
- eventCenter.once((getCurrentInstanceTaro() as any).router.onReady, () => {
|
|
|
|
|
- const query = Taro.createSelectorQuery();
|
|
|
|
|
- query.selectAll('.collapse-content').boundingClientRect();
|
|
|
|
|
- query.exec((res) => {
|
|
|
|
|
- // list = res[0];
|
|
|
|
|
- // list.forEach((item: any) => {
|
|
|
|
|
- // domID.push(item.id);
|
|
|
|
|
- // });
|
|
|
|
|
- getH(res[0]);
|
|
|
|
|
- // parent.activeIndex().forEach((item:any) => {
|
|
|
|
|
- // const h = list[item]?.height;
|
|
|
|
|
- // parent.children[item].conHeight = h;
|
|
|
|
|
- // });
|
|
|
|
|
|
|
+ if (Taro.getEnv() === 'WEB') {
|
|
|
|
|
+ getRefHeight();
|
|
|
|
|
+ } else {
|
|
|
|
|
+ eventCenter.once((getCurrentInstanceTaro() as any).router.onReady, () => {
|
|
|
|
|
+ getRefHeight();
|
|
|
});
|
|
});
|
|
|
- });
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // const query = Taro.createSelectorQuery();
|
|
|
|
|
+ // query.selectAll('.collapse-content').boundingClientRect();
|
|
|
|
|
+ // query.exec((res) => {
|
|
|
|
|
+ // console.log(res[0]);
|
|
|
|
|
+ // getH(res[0]);
|
|
|
|
|
+ // });
|
|
|
|
|
+
|
|
|
if (typeof active == 'number' || typeof active == 'string') {
|
|
if (typeof active == 'number' || typeof active == 'string') {
|
|
|
if (name == active) {
|
|
if (name == active) {
|
|
|
defaultOpen();
|
|
defaultOpen();
|