WebApp【公共组件库】@前端(For Git Submodule)
2 files modified
92 ■■■■■ changed files
bases/Pilot.js 61 ●●●●● patch | view | raw | blame | history
forms/textarea/CTextArea.vue 31 ●●●●● patch | view | raw | blame | history
bases/Pilot.js
@@ -8,9 +8,7 @@
import project from '@project';
export class Pilot {
    constructor() {
    }
    constructor() {}
    $data() {
        return {};
@@ -68,9 +66,11 @@
            created() {
                const instance = getCurrentInstance();
                instance.page.$component = this;
                // 绑定方法到页面实例
                // 跨页消息发送
                this.$poster = Pilot.createPoster(this);
                // 跨页接收消息
                this.$onMessage = onMessage || (() => null);
                // 跨端接收消息
                this.$onBridge = onBridge || (() => null);
                // 实际生命周期回调
                created && created.call(this);
@@ -96,11 +96,11 @@
    // 创建页面通讯器
    static createPoster($vm) {
        return (pageType, action, data) => {
            // 解除引用关系
            // 解除原引用关系、移除非数据内容
            const nextData = JSON.parse(JSON.stringify(data || {}));
            // 下一页
            // 传递消息到下一页
            if (pageType === 'nextPage') {
                // 持续 3 秒,检测下一页是否存在
                // 持续 3 秒,检测下一页是否存在,如果 3 秒内未创建下一页,忽略
                let count = 0;
                const timer = setInterval(() => {
                    if (++count > 60) {
@@ -111,20 +111,44 @@
                    const nextPage = currentPages[pageIndex + 1];
                    if (nextPage) {
                        clearInterval(timer);
                        nextPage.$component?.$onMessage(action, nextData);
                        setTimeout(() => {
                            nextPage.$component?.$onMessage(action, nextData);
                        }, 0);
                    }
                }, 50);
            } else if (pageType === 'prevPage') {
            }
            // 传递消息到上一页,上一页的上一页,依次直到首页
            else if (pageType === 'prevPage') {
                const currentPages = getCurrentPages();
                let pageIndex = currentPages.findIndex(page => page.$component === $vm);
                while (pageIndex - 1 >= 0) {
                    const prevPage = currentPages[pageIndex - 1];
                    if (prevPage) {
                        prevPage.$component?.$onMessage(action, nextData);
                    }
                    pageIndex--;
                }
            }
            // 传递消息到原地新页(redirectTo原地新开页面)
            else if (pageType === 'sitePage') {
                const currentPages = getCurrentPages();
                const pageIndex = currentPages.findIndex(page => page.$component === $vm);
                const prevPage = currentPages[pageIndex - 1];
                if (prevPage) {
                    prevPage.$component?.$onMessage(action, nextData);
                }
            } else if (pageType === 'rootPage') {
                const currentPages = getCurrentPages();
                const rootPage = currentPages[0];
                rootPage.$component?.$onMessage(action, nextData);
                const pagePath = currentPages[pageIndex].$taroPath
                // 持续 3 秒,检查当前页是否新开,如果 3 秒内没有新开,忽略
                let count = 0;
                const timer = setInterval(() => {
                    if (++count > 60) {
                        clearInterval(timer);
                    }
                    const currentPages = getCurrentPages();
                    const sitePage = currentPages[pageIndex];
                    if (sitePage.$component !== $vm || sitePage.$taroPath !== pagePath) {
                        clearInterval(timer);
                        setTimeout(() => {
                            sitePage.$component?.$onMessage(action, nextData);
                        }, 0);
                    }
                }, 50);
            }
        };
    }
@@ -154,5 +178,4 @@
        });
        return assets2;
    }
}
}
forms/textarea/CTextArea.vue
@@ -1,13 +1,16 @@
/**
 * CTextArea
 * 多行文本输入组件,用于在表单中收集用户的多行文本输入
 * 支持设置输入区域高度,可以通过字数、行数或像素值来控制
 * 支持设置输入区域高度,可以通过行数或像素值来控制
 * 支持只读模式和自动增高功能
 * @author Tevin
 */
<template>
    <view class="c-textarea" :class="readOnly ? 'read-only' : ''">
    <view
        class="c-textarea"
        :class="readOnly?'read-only':''"
    >
        <AtInput
            ref="input"
            :name="itemRes.name"
@@ -19,16 +22,13 @@
        <textarea
            ref="textarea"
            class="textarea"
            :style="{
                minHeight: minHeight,
                maxHeight: maxHeight,
            }"
            :style="{minHeight: areaHeight, height: areaHeight}"
            :placeholder="placeholder"
            :value="itemRes.formData[itemRes.name]"
            :maxlength="maxLength"
            :autoFocus="false"
            :autoHeight="true"
            @input="evt => itemRes.onChange(evt.detail.value)"
            @input="evt=>itemRes.onChange(evt.detail.value)"
        />
    </view>
</template>
@@ -68,21 +68,10 @@
        return {};
    },
    computed: {
        minHeight() {
            // 默认最小高度为2行
            const defaultRows = 2;
            return Taro.pxTransform(defaultRows * 40, 750);
        },
        maxHeight() {
            if (this.maxLength > 0) {
                // maxLength 优先级最高
                const estimatedRows = Math.ceil(this.maxLength / 25);
                return Taro.pxTransform(estimatedRows * 40, 750);
            } else if (this.rows) {
                // 其次是 rows
        areaHeight() {
            if (this.rows) {
                return Taro.pxTransform(this.rows * 40, 750);
            } else {
                // 最后是 height
                return Taro.pxTransform(this.height, 750);
            }
        },