更新记录

1.2.5(2025-11-15) 下载此版本

pdf识别 文档解析 docx文档 excel文档 文档识别 功能demo上传


平台兼容性

uni-app(4.25)

Vue2 Vue3 Chrome Safari app-vue app-nvue Android iOS 鸿蒙
微信小程序 支付宝小程序 抖音小程序 百度小程序 快手小程序 京东小程序 鸿蒙元服务 QQ小程序 飞书小程序 快应用-华为 快应用-联盟

介绍

本功能基于轻语API 轻语API提供一键生成二维码、OCR文字识别、通用文档内容识别(pdf/excel/docx/doc等文档格式解析)、文字转语音、随机图库、智能Ai助手、地理编码获取(逆地理编码,从内容中获取地址信息(含经纬度),从经纬度获取地址信息)等等API

<template>
    <view class="container">
        <!-- 文件上传区域(H5端) -->
        <view class="upload-section">
            <view class="section-title">方式一:选择本地文件上传</view>
            <view class="upload-area" @click="chooseFile">
                <view v-if="selectedFile" class="file-display">
                    <text class="file-icon">📄</text>
                    <view class="file-details">
                        <text class="file-name-display">{{ selectedFile.tempFiles[0].name }}</text>
                        <text class="file-size">{{ formatFileSize(selectedFile.tempFiles[0].size) }}</text>
                        <text class="file-type">文件类型:{{ selectedFile.tempFiles[0].type || '未知' }}</text>
                    </view>
                </view>
                <view v-else class="upload-placeholder">
                    <text class="upload-icon">📁</text>
                    <text class="upload-text">点击选择文件</text>
                    <text class="upload-hint">支持各种文档格式(PDF、Word、Excel、CSV、TXT等)</text>
                </view>
            </view>
            <view v-if="selectedFile" class="remove-file-btn" @click.stop="removeFile">
                <text>✕ 移除文件</text>
            </view>
        </view>

        <!-- 文件URL输入区域 -->
        <view class="url-input-section">
            <view class="section-title">方式二:输入文件网络链接</view>
            <view class="tip-text">文件上传和URL二选一,如果都填写则优先使用文件上传</view>

            <view class="section-title">输入文件网络链接:</view>
            <view class="tip-text">uniapp App端没有提供选择文件的api,使用文件URL方式测验</view>
            <view class="test-urls">
                <view class="test-url-title">测试文档URL:</view>
                <text class="test-url-item" @click="selectTestUrl('http://file.luanqing.net/doc/测试的PDF文档.pdf')">
                    测试PDF文档
                </text>
                <text class="test-url-item" @click="selectTestUrl('http://file.luanqing.net/doc/测试的Word文档.docx')">
                    测试Word文档
                </text>
            </view>

            <input v-model="fileUrl" class="input" placeholder="请输入文件URL地址" />
        </view>

        <!-- API Key -->
        <view class="apikey-section">
            <view class="section-title">API Key:</view>
            <view class="apikey-tip">共用测试Key,当日额度用尽后次日重置,上线请用正式key</view>
            <input v-model="apikey" class="input" placeholder="test_app_key_5555api.com" />
        </view>

        <!-- 操作按钮 -->
        <view class="button-section">
            <view class="btn btn-clear" @click="onClear">清空</view>

            <!-- 等待进度条 -->
            <view v-if="status==='loading'">
                <image src="/static/icon_spinner.png" style="width: 68rpx;height: 68rpx;" class="rotating-element"></image>
            </view>
            <navigator v-else url="/pages/index/index" class="link-text">查看其他API</navigator>

            <view class="btn btn-query" @click="onParseFile">开始解析文件</view>
        </view>

        <!-- 请求URL展示 -->
        <view v-if="requestUrl" class="url-section">
            <view class="section-title">请求接口(长按可复制):</view>
            <view class="url-content" @longpress="copyUrl">{{ requestUrl }}</view>
        </view>

        <!-- 结果展示 -->
        <view v-if="resultText" class="result-section">
            <view class="section-title">解析结果(长按可复制):</view>
            <view class="result-content" @longpress="copyResult">{{ resultText }}</view>
        </view>
    </view>
</template>

<script>
    export default {
        data() {
            return {
                selectedFile: null,
                fileUrl: '', // 文件URL地址
                apikey: 'test_app_key_5555api.com', // 测试用的共享apikey,每日有限额,上线请在https://5555api.com注册正式apikey
                resultText: '',
                requestUrl: '',
                status: ''
            }
        },
        methods: {
            // 选择文件(仅H5端使用)
            chooseFile() {
                let that = this;
                // #ifdef H5
                uni.chooseFile({
                    count: 1,
                    success(res) {
                        console.log("选择文件成功", res);
                        that.selectedFile = res;
                        uni.showToast({
                            title: '文件已选择',
                            icon: 'success'
                        });
                    },
                    fail(err) {
                        console.error("选择文件失败", err);
                        uni.showToast({
                            title: '选择文件失败',
                            icon: 'none'
                        });
                    }
                })

                // #endif
            },

            // 选择测试URL(App端使用)
            selectTestUrl(url) {
                this.fileUrl = url;
                uni.showToast({
                    title: '已选择测试文档',
                    icon: 'success'
                });
            },

            // 移除文件
            removeFile() {
                this.selectedFile = null;
                uni.showToast({
                    title: '已移除文件',
                    icon: 'success'
                });
            },

            // 格式化文件大小
            formatFileSize(bytes) {
                if (!bytes) return '0 B';
                const k = 1024;
                const sizes = ['B', 'KB', 'MB', 'GB'];
                const i = Math.floor(Math.log(bytes) / Math.log(k));
                return (bytes / Math.pow(k, i)).toFixed(2) + ' ' + sizes[i];
            },

            // 清空内容
            onClear() {
                this.selectedFile = null;
                this.fileUrl = '';
                this.resultText = '';
                this.requestUrl = '';
                uni.showToast({
                    title: '已清空',
                    icon: 'success'
                });
            },

            // 长按复制URL
            copyUrl() {
                if(this.requestUrl) {
                    uni.setClipboardData({
                        data: this.requestUrl,
                        success: () => {
                            uni.showToast({
                                title: 'URL已复制',
                                icon: 'success'
                            });
                        },
                        fail: () => {
                            uni.showToast({
                                title: '复制失败',
                                icon: 'none'
                            });
                        }
                    });
                }
            },

            // 长按复制结果
            copyResult() {
                if(this.resultText) {
                    uni.setClipboardData({
                        data: this.resultText,
                        success: () => {
                            uni.showToast({
                                title: '结果已复制',
                                icon: 'success'
                            });
                        },
                        fail: () => {
                            uni.showToast({
                                title: '复制失败',
                                icon: 'none'
                            });
                        }
                    });
                }
            },

            // 解析文件
            onParseFile() {
                let that = this;

                // 验证输入:至少要有文件或URL
                if(!that.selectedFile && !that.fileUrl) {
                    uni.showToast({
                        title: '请选择文件或输入文件URL',
                        icon: 'none'
                    });
                    return;
                }

                if(!that.apikey) {
                    uni.showToast({
                        title: '请输入API Key',
                        icon: 'none'
                    });
                    return;
                }

                that.status = 'loading';
                that.resultText = '';

                // const baseUrl = 'http://192.168.2.134:9093/data/api/parseFile';
                const baseUrl = 'https://5555api.com/data/api/parseFile';

                // #ifdef H5
                // H5端:优先使用文件上传,如果没有文件则使用URL
                if(that.selectedFile) {
                    // 生成请求URL(文件上传时显示参数)
                    that.requestUrl = `${baseUrl}?apikey=${that.apikey}`;

                    uni.uploadFile({
                        url: that.requestUrl,
                        name: 'file',
                        filePath: that.selectedFile.tempFilePaths[0],
                        timeout: 180000,
                        success(res) {
                            that.status = '';
                            console.log('上传成功:', res.data);
                            try {
                                let data;
                                if(typeof res.data === 'string') {
                                    data = JSON.parse(res.data);
                                } else {
                                    data = res.data;
                                }
                                that.resultText = JSON.stringify(data, null, 2);
                            } catch(e) {
                                that.resultText = res.data || '解析成功';
                            }
                        },
                        fail(err) {
                            that.status = '';
                            console.error('上传失败:', err);
                            that.resultText = "上传失败:" + (err.errMsg || '网络请求失败');
                            uni.showToast({
                                title: '上传失败',
                                icon: 'none'
                            });
                        }
                    });

                } else {
                    // 使用URL方式
                    that.requestUrl = `${baseUrl}?url=${encodeURIComponent(that.fileUrl)}&apikey=${that.apikey}`;

                    uni.request({
                        url: that.requestUrl,
                        method: 'POST',
                        header: {
                            'content-type': 'application/x-www-form-urlencoded'
                        },
                        timeout: 180000,
                        success(res) {
                            that.status = '';
                            console.log('请求成功:', res);
                            if(res.data) {
                                that.resultText = JSON.stringify(res.data, null, 2);
                            } else {
                                that.resultText = "解析成功,但未返回数据";
                            }
                        },
                        fail(err) {
                            that.status = '';
                            console.error('请求失败:', err);
                            that.resultText = "服务异常:" + (err.errMsg || '网络请求失败');
                            uni.showToast({
                                title: '请求失败',
                                icon: 'none'
                            });
                        }
                    });
                }
                // #endif

                // #ifndef H5
                // App端:只支持URL方式
                that.requestUrl = `${baseUrl}?url=${encodeURIComponent(that.fileUrl)}&apikey=${that.apikey}`;
                console.error("app端", that.requestUrl);
                uni.request({
                    url: that.requestUrl,
                    method: 'POST',
                    header: {
                        'content-type': 'application/x-www-form-urlencoded'
                    },
                    timeout: 180000,
                    success(res) {
                        that.status = '';
                        console.log('请求成功:', res);
                        try {
                            if(typeof res.data === 'string') {
                                const data = JSON.parse(res.data);
                                that.resultText = JSON.stringify(data, null, 2);
                            } else {
                                that.resultText = JSON.stringify(res.data, null, 2);
                            }
                        } catch(e) {
                            that.resultText = res.data;
                        }
                    },
                    fail(err) {
                        that.status = '';
                        console.error('请求失败:', err);
                        that.resultText = "服务异常:" + (err.errMsg || '网络请求失败');
                        uni.showToast({
                            title: '请求失败',
                            icon: 'none'
                        });
                    }
                });
                // #endif
            }
        }
    }
</script>

<style scoped>
    .container {
        padding: 40rpx;
    }

    /* 上传区域 */
    .upload-section {
        margin-bottom: 30rpx;
    }

    .upload-area {
        width: 100%;
        min-height: 300rpx;
        border: 2rpx dashed #12c212;
        border-radius: 10rpx;
        display: flex;
        align-items: center;
        justify-content: center;
        background-color: #f9f9f9;
        padding: 30rpx;
        box-sizing: border-box;
        cursor: pointer;
    }

    .upload-placeholder {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        text-align: center;
    }

    .upload-icon {
        font-size: 80rpx;
        margin-bottom: 20rpx;
    }

    .upload-text {
        font-size: 28rpx;
        color: #333;
        margin-bottom: 10rpx;
    }

    .upload-hint {
        font-size: 24rpx;
        color: #999;
    }

    /* 文件显示区域 */
    .file-display {
        width: 100%;
        display: flex;
        align-items: center;
        gap: 30rpx;
    }

    .file-icon {
        font-size: 80rpx;
        flex-shrink: 0;
    }

    .file-details {
        flex: 1;
        display: flex;
        flex-direction: column;
        gap: 10rpx;
    }

    .file-name-display {
        font-size: 28rpx;
        color: #333;
        font-weight: bold;
        word-break: break-all;
    }

    .file-size {
        font-size: 24rpx;
        color: #666;
    }

    .file-type {
        font-size: 24rpx;
        color: #12c212;
    }

    .remove-file-btn {
        margin-top: 15rpx;
        padding: 15rpx 30rpx;
        background-color: #f44336;
        color: #fff;
        border-radius: 10rpx;
        text-align: center;
        font-size: 26rpx;
        cursor: pointer;
    }

    .section-title {
        font-size: 28rpx;
        color: #666;
        margin-bottom: 15rpx;
        font-weight: bold;
    }

    .tip-text {
        font-size: 24rpx;
        color: #ff9800;
        margin-bottom: 15rpx;
        line-height: 1.5;
    }

    .apikey-tip {
        font-size: 24rpx;
        color: #2196f3;
        margin-bottom: 15rpx;
        line-height: 1.5;
    }

    .input {
        width: 100%;
        height: 70rpx;
        padding: 0 20rpx;
        border: 2rpx solid #12c212;
        border-radius: 10rpx;
        font-size: 28rpx;
        box-sizing: border-box;
    }

    /* URL输入区域 */
    .url-input-section {
        margin-bottom: 30rpx;
    }

    /* 测试链接区域 */
    .test-urls {
        margin-bottom: 15rpx;
        padding: 20rpx;
        background-color: #e3f2fd;
        border-radius: 10rpx;
    }

    .test-url-title {
        font-size: 26rpx;
        color: #1976d2;
        margin-bottom: 15rpx;
        font-weight: bold;
    }

    .test-url-item {
        display: inline-block;
        margin-right: 20rpx;
        margin-bottom: 10rpx;
        padding: 10rpx 20rpx;
        background-color: #2196f3;
        color: #fff;
        border-radius: 8rpx;
        font-size: 24rpx;
        cursor: pointer;
    }

    /* API Key区域 */
    .apikey-section {
        margin-bottom: 30rpx;
    }

    /* 按钮区域 */
    .button-section {
        display: flex;
        align-items: center;
        justify-content: space-around;
        margin-bottom: 40rpx;
    }

    .btn {
        color: #fff;
        border-radius: 12rpx;
        font-size: 30rpx;
        padding: 15rpx 40rpx;
    }

    .btn-clear {
        background-color: #999;
    }

    .btn-query {
        background-color: cornflowerblue;
    }

    .link-text {
        font-size: 26rpx;
        color: #999999;
        text-align: center;
    }

    /* URL展示区域 */
    .url-section {
        margin-top: 20rpx;
    }

    .url-content {
        padding: 20rpx;
        background-color: #fff8e1;
        border: 2rpx solid #ffa726;
        border-radius: 10rpx;
        font-size: 22rpx;
        color: #e65100;
        word-break: break-all;
        line-height: 1.5;
    }

    /* 结果展示区域 */
    .result-section {
        margin-top: 20rpx;
    }

    .result-content {
        padding: 20rpx;
        background-color: #f9f9f9;
        border: 2rpx solid #12c212;
        border-radius: 10rpx;
        font-size: 24rpx;
        color: #333;
        white-space: pre-wrap;
        word-break: break-all;
        max-height: 600rpx;
        overflow-y: auto;
    }

    /* 加载动画 */
    .rotating-element {
        animation: rotateAnimation 2s linear infinite;
    }

    @keyframes rotateAnimation {
        from {
            transform: rotate(0deg);
        }
        to {
            transform: rotate(360deg);
        }
    }
</style>

隐私、权限声明

1. 本插件需要申请的系统权限列表:

2. 本插件采集的数据、发送的服务器地址、以及数据用途说明:

插件不采集任何数据

3. 本插件是否包含广告,如包含需详细说明广告表达方式、展示频率:

许可协议

MIT协议

暂无用户评论。