Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ellipsis): 修复taro端文本省略失效 #2791

Merged
merged 1 commit into from
Dec 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions src/packages/__VUE/ellipsis/index.taro.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<view>
<view :id="'root' + refRandomId" ref="root" class="nut-ellipsis ell" @click="handleClick">
<view :id="rootId" class="nut-ellipsis ell" @click="handleClick">
<view v-if="!exceeded" class="nut-ellipsis__wordbreak">{{ content }}</view>

<view v-if="exceeded && !expanded" class="nut-ellipsis__wordbreak">
Expand Down Expand Up @@ -28,7 +28,7 @@
</template>

<script lang="ts">
import { ref, reactive, toRefs, computed, onMounted, PropType, unref } from 'vue';
import { ref, reactive, toRefs, computed, onMounted, PropType } from 'vue';
import { createComponent } from '@/packages/utils/create';
import { useTaroRect } from '@/packages/utils/useTaroRect';
import Taro from '@tarojs/taro';
Expand Down Expand Up @@ -74,7 +74,6 @@ export default create({
emits: ['click', 'change'],

setup(props, { emit }) {
const root = ref(null);
const rootContain = ref(null);
const symbolContain = ref(null);
let contantCopy = ref(props.content);
Expand All @@ -83,6 +82,7 @@ export default create({
let originHeight = 0; // 原始高度
const ellipsis = reactive<EllipsisedValue>({});
const refRandomId = Math.random().toString(36).slice(-8);
const rootId = ref('root' + refRandomId);
let widthRef = ref('auto');
const state = reactive({
exceeded: false, //是否超出
Expand Down Expand Up @@ -120,12 +120,10 @@ export default create({
};

const getReference = async () => {
let element = unref(root);

const query = Taro.createSelectorQuery();
query.select(`#${(element as any).id}`) &&
query.select(`#${rootId.value}`) &&
query
.select(`#${(element as any).id}`)
.select(`#${rootId.value}`)
.fields(
{
computedStyle: ['width', 'height', 'lineHeight', 'paddingTop', 'paddingBottom', 'fontSize']
Expand Down Expand Up @@ -287,7 +285,7 @@ export default create({

return {
...toRefs(state),
root,
rootId,
rootContain,
symbolContain,
ellipsis,
Expand Down