Elysia Tools

在一个清晰的工作台里浏览工具、案例、可视化和主题指南。

热门分类

专题

语言
ZHESPTRUFRDEEN

Elysia Tools

导航

移动开发

Apache Cordova移动开发示例

Apache Cordova混合移动应用开发示例,包括插件使用、设备API、跨平台部署和遗留系统集成

案例

这个案例集合中的条目

代码text简单

Cordova核心插件实现

实现基本Cordova核心插件以支持设备功能,包括相机、地理位置、通知、文件系统和设备信息

text
// config.xml
<?xml version='1.0' encoding='utf-8'?>
<widget id="com.example.cordovaapp" version="1.0.0" xmlns="http://www.w3.org/ns/widgets">
    <name>CordovaDemo</name>
    <description>Apache Cordova Application</description>
    <author email="[email protected]" href="http://example.com">
        Example Developer
    </author>
    <content src="index.html" />
    <access origin="*" />
    <allow-intent href="http://*/*" />
    <allow-intent href="https://*/*" />
    <allow-intent href="tel:*" />
    <allow-intent href="sms:*" />
    <allow-intent href="mailto:*" />
    <allow-intent href="geo:*" />

    <!-- Core Plugins -->
    <plugin name="cordova-plugin-camera" spec="^6.0.0" />
    <plugin name="cordova-plugin-geolocation" spec="^4.1.0" />
    <plugin name="cordova-plugin-device" spec="^2.1.0" />
    <plugin name="cordova-plugin-file" spec="^6.0.2" />
    <plugin name="cordova-plugin-file-transfer" spec="^1.7.1" />
    <plugin name="cordova-plugin-dialogs" spec="^2.0.2" />
    <plugin name="cordova-plugin-vibration" spec="^3.1.1" />
    <plugin name="cordova-plugin-network-information" spec="^2.0.2" />
    <plugin name="cordova-plugin-inappbrowser" spec="^3.2.0" />
    <plugin name="cordova-plugin-media-capture" spec="^3.0.3" />
    <plugin name="cordova-plugin-splashscreen" spec="^5.0.4" />
    <plugin name="cordova-plugin-statusbar" spec="^2.4.3" />
    <plugin name="cordova-plugin-whitelist" spec="^1.3.4" />

    <!-- Platform-specific preferences -->
    <platform name="android">
        <preference name="android-minSdkVersion" value="22" />
        <preference name="android-targetSdkVersion" value="30" />
        <preference name="SplashMaintainAspectRatio" value="true" />
        <preference name="SplashShowOnlyFirstTime" value="false" />
        <preference name="SplashScreenDelay" value="3000" />
        <preference name="StatusBarOverlaysWebView" value="false" />
        <preference name="StatusBarBackgroundColor" value="#000000" />
        <preference name="StatusBarStyle" value="lightcontent" />
    </platform>

    <platform name="ios">
        <preference name="SplashMaintainAspectRatio" value="true" />
        <preference name="SplashScreenDelay" value="3000" />
        <preference name="StatusBarOverlaysWebView" value="false" />
        <preference name="StatusBarBackgroundColor" value="#000000" />
        <preference name="StatusBarStyle" value="lightcontent" />
        <preference name="BackupWebStorage" value="none" />
    </platform>
</widget>

// js/services/CordovaDeviceService.js
class CordovaDeviceService {
    constructor() {
        this.isDeviceReady = false;
        this.initializeCordova();
    }

    initializeCordova() {
        document.addEventListener('deviceready', () => {
            console.log('Device is ready!');
            this.isDeviceReady = true;
            this.onDeviceReady();
        }, false);
    }

    onDeviceReady() {
        // Hide splash screen
        if (navigator.splashscreen) {
            navigator.splashscreen.hide();
        }

        // Setup status bar
        if (window.StatusBar) {
            StatusBar.backgroundColorByHexString("#000000");
            StatusBar.styleLightContent();
        }

        // Setup network monitoring
        this.setupNetworkMonitoring();
    }

    // Device Information
    getDeviceInfo() {
        if (!this.isDeviceReady) {
            console.warn('Device not ready');
            return null;
        }

        return {
            platform: device.platform,
            version: device.version,
            model: device.model,
            manufacturer: device.manufacturer,
            uuid: device.uuid,
            serial: device.serial,
            isVirtual: device.isVirtual
        };
    }

    // Camera Operations
    takePhoto(options = {}) {
        return new Promise((resolve, reject) => {
            if (!this.isDeviceReady || !navigator.camera) {
                reject(new Error('Camera not available'));
                return;
            }

            const defaultOptions = {
                quality: 80,
                destinationType: Camera.DestinationType.FILE_URI,
                sourceType: Camera.PictureSourceType.CAMERA,
                encodingType: Camera.EncodingType.JPEG,
                mediaType: Camera.MediaType.PICTURE,
                allowEdit: false,
                correctOrientation: true,
                saveToPhotoAlbum: false
            };

            const cameraOptions = { ...defaultOptions, ...options };

            navigator.camera.getPicture(
                (imageUri) => {
                    resolve({
                        success: true,
                        imageUri: imageUri,
                        message: 'Photo captured successfully'
                    });
                },
                (error) => {
                    reject(new Error(`Camera error: ${error}`));
                },
                cameraOptions
            );
        });
    }

    getPhotoFromGallery(options = {}) {
        return new Promise((resolve, reject) => {
            if (!this.isDeviceReady || !navigator.camera) {
                reject(new Error('Camera not available'));
                return;
            }

            const defaultOptions = {
                quality: 80,
                destinationType: Camera.DestinationType.FILE_URI,
                sourceType: Camera.PictureSourceType.PHOTOLIBRARY,
                encodingType: Camera.EncodingType.JPEG,
                mediaType: Camera.MediaType.PICTURE
            };

            const cameraOptions = { ...defaultOptions, ...options };

            navigator.camera.getPicture(
                (imageUri) => {
                    resolve({
                        success: true,
                        imageUri: imageUri,
                        message: 'Photo selected successfully'
                    });
                },
                (error) => {
                    reject(new Error(`Gallery error: ${error}`));
                },
                cameraOptions
            );
        });
    }

    // Geolocation Operations
    getCurrentPosition(options = {}) {
        return new Promise((resolve, reject) => {
            if (!this.isDeviceReady || !navigator.geolocation) {
                reject(new Error('Geolocation not available'));
                return;
            }

            const defaultOptions = {
                maximumAge: 3000,
                timeout: 5000,
                enableHighAccuracy: true
            };

            const geolocationOptions = { ...defaultOptions, ...options };

            navigator.geolocation.getCurrentPosition(
                (position) => {
                    resolve({
                        success: true,
                        latitude: position.coords.latitude,
                        longitude: position.coords.longitude,
                        accuracy: position.coords.accuracy,
                        altitude: position.coords.altitude,
                        altitudeAccuracy: position.coords.altitudeAccuracy,
                        heading: position.coords.heading,
                        speed: position.coords.speed,
                        timestamp: position.timestamp
                    });
                },
                (error) => {
                    reject(new Error(`Geolocation error: ${error.message}`));
                },
                geolocationOptions
            );
        });
    }

    watchPosition(callback, options = {}) {
        if (!this.isDeviceReady || !navigator.geolocation) {
            throw new Error('Geolocation not available');
        }

        const defaultOptions = {
            maximumAge: 3000,
            timeout: 5000,
            enableHighAccuracy: true
        };

        const geolocationOptions = { ...defaultOptions, ...options };

        return navigator.geolocation.watchPosition(
            (position) => {
                callback({
                    success: true,
                    latitude: position.coords.latitude,
                    longitude: position.coords.longitude,
                    accuracy: position.coords.accuracy,
                    timestamp: position.timestamp
                });
            },
            (error) => {
                callback({
                    success: false,
                    error: error.message
                });
            },
            geolocationOptions
        );
    }

    // File System Operations
    readFile(path, options = {}) {
        return new Promise((resolve, reject) => {
            if (!this.isDeviceReady || !window.resolveLocalFileSystemURL) {
                reject(new Error('File system not available'));
                return;
            }

            window.resolveLocalFileSystemURL(
                path,
                (fileEntry) => {
                    fileEntry.file(
                        (file) => {
                            const reader = new FileReader();

                            reader.onloadend = function() {
                                resolve({
                                    success: true,
                                    data: this.result,
                                    name: file.name,
                                    size: file.size,
                                    type: file.type,
                                    lastModified: file.lastModified
                                });
                            };

                            reader.onerror = function() {
                                reject(new Error('Failed to read file'));
                            };

                            // Read based on options
                            if (options.asText) {
                                reader.readAsText(file);
                            } else if (options.asDataURL) {
                                reader.readAsDataURL(file);
                            } else {
                                reader.readAsArrayBuffer(file);
                            }
                        },
                        (error) => {
                            reject(new Error(`File error: ${error.code}`));
                        }
                    );
                },
                (error) => {
                    reject(new Error(`File system error: ${error.code}`));
                }
            );
        });
    }

    writeFile(path, data, options = {}) {
        return new Promise((resolve, reject) => {
            if (!this.isDeviceReady || !window.resolveLocalFileSystemURL) {
                reject(new Error('File system not available'));
                return;
            }

            const defaultOptions = {
                create: true,
                exclusive: false
            };

            const fileOptions = { ...defaultOptions, ...options };

            window.resolveLocalFileSystemURL(
                path.substring(0, path.lastIndexOf('/')),
                (directoryEntry) => {
                    directoryEntry.getFile(
                        path.substring(path.lastIndexOf('/') + 1),
                        fileOptions,
                        (fileEntry) => {
                            fileEntry.createWriter(
                                (writer) => {
                                    writer.onwriteend = () => {
                                        resolve({
                                            success: true,
                                            path: fileEntry.toURL(),
                                            message: 'File written successfully'
                                        });
                                    };

                                    writer.onerror = (error) => {
                                        reject(new Error(`Write error: ${error}`));
                                    };

                                    if (typeof data === 'string') {
                                        writer.write(data);
                                    } else if (data instanceof Blob) {
                                        writer.write(data);
                                    } else {
                                        const blob = new Blob([JSON.stringify(data)], { type: 'application/json' });
                                        writer.write(blob);
                                    }
                                },
                                (error) => {
                                    reject(new Error(`Writer error: ${error.code}`));
                                }
                            );
                        },
                        (error) => {
                            reject(new Error(`File creation error: ${error.code}`));
                        }
                    );
                },
                (error) => {
                    reject(new Error(`Directory error: ${error.code}`));
                }
            );
        });
    }

    // Dialog Operations
    showAlert(message, title = 'Alert', buttonName = 'OK') {
        return new Promise((resolve) => {
            if (!this.isDeviceReady || !navigator.notification) {
                // Fallback to browser alert
                alert(message);
                resolve();
                return;
            }

            navigator.notification.alert(
                message,
                () => resolve(),
                title,
                buttonName
            );
        });
    }

    showConfirm(message, title = 'Confirm', buttonLabels = ['OK', 'Cancel']) {
        return new Promise((resolve) => {
            if (!this.isDeviceReady || !navigator.notification) {
                // Fallback to browser confirm
                const result = confirm(message);
                resolve(result ? 1 : 2);
                return;
            }

            navigator.notification.confirm(
                message,
                (buttonIndex) => resolve(buttonIndex),
                title,
                buttonLabels
            );
        });
    }

    showPrompt(message, title = 'Prompt', buttonLabels = ['OK', 'Cancel'], defaultText = '') {
        return new Promise((resolve) => {
            if (!this.isDeviceReady || !navigator.notification) {
                // Fallback to browser prompt
                const result = prompt(message, defaultText);
                resolve(result ? { input1: result } : false);
                return;
            }

            navigator.notification.prompt(
                message,
                (results) => resolve(results),
                title,
                buttonLabels,
                defaultText
            );
        });
    }

    // Vibration
    vibrate(pattern) {
        if (!this.isDeviceReady || !navigator.notification || !navigator.vibrate) {
            console.warn('Vibration not available');
            return;
        }

        if (Array.isArray(pattern)) {
            navigator.notification.vibrateWithPattern(pattern);
        } else {
            navigator.vibrate(pattern || 1000);
        }
    }

    // Network Information
    setupNetworkMonitoring() {
        if (!this.isDeviceReady || !navigator.connection) {
            console.warn('Network information not available');
            return;
        }

        document.addEventListener('online', () => {
            console.log('Network connection established');
            this.onNetworkChange(true);
        });

        document.addEventListener('offline', () => {
            console.log('Network connection lost');
            this.onNetworkChange(false);
        });
    }

    onNetworkChange(isOnline) {
        // Override this method to handle network changes
        console.log(`Network status changed: ${isOnline ? 'online' : 'offline'}`);
    }

    getNetworkInfo() {
        if (!this.isDeviceReady || !navigator.connection) {
            return {
                online: navigator.onLine,
                type: 'unknown'
            };
        }

        const connection = navigator.connection;
        return {
            online: navigator.onLine,
            type: connection.type,
            effectiveType: connection.effectiveType,
            downlink: connection.downlink,
            rtt: connection.rtt
        };
    }

    // In App Browser
    openInAppBrowser(url, options = {}) {
        if (!this.isDeviceReady || !cordova.InAppBrowser) {
            // Fallback to opening in same window
            window.open(url, '_blank');
            return null;
        }

        const defaultOptions = {
            location: 'yes',
            clearcache: 'yes',
            toolbar: 'yes',
            closebuttoncaption: 'Close'
        };

        const browserOptions = { ...defaultOptions, ...options };
        const target = options.target || '_blank';

        return cordova.InAppBrowser.open(url, target, browserOptions);
    }

    // Media Capture
    captureAudio(options = {}) {
        return new Promise((resolve, reject) => {
            if (!this.isDeviceReady || !navigator.device.capture) {
                reject(new Error('Media capture not available'));
                return;
            }

            const defaultOptions = {
                limit: 1,
                duration: 30
            };

            const captureOptions = { ...defaultOptions, ...options };

            navigator.device.capture.captureAudio(
                (mediaFiles) => {
                    resolve({
                        success: true,
                        files: mediaFiles.map(file => ({
                            name: file.name,
                            fullPath: file.fullPath,
                            type: file.type,
                            lastModifiedDate: file.lastModifiedDate,
                            size: file.size
                        }))
                    });
                },
                (error) => {
                    reject(new Error(`Audio capture error: ${error.code}`));
                },
                captureOptions
            );
        });
    }

    captureImage(options = {}) {
        return new Promise((resolve, reject) => {
            if (!this.isDeviceReady || !navigator.device.capture) {
                reject(new Error('Media capture not available'));
                return;
            }

            const defaultOptions = {
                limit: 1
            };

            const captureOptions = { ...defaultOptions, ...options };

            navigator.device.capture.captureImage(
                (mediaFiles) => {
                    resolve({
                        success: true,
                        files: mediaFiles.map(file => ({
                            name: file.name,
                            fullPath: file.fullPath,
                            type: file.type,
                            lastModifiedDate: file.lastModifiedDate,
                            size: file.size
                        }))
                    });
                },
                (error) => {
                    reject(new Error(`Image capture error: ${error.code}`));
                },
                captureOptions
            );
        });
    }
}

// Export for use in other modules
if (typeof module !== 'undefined' && module.exports) {
    module.exports = CordovaDeviceService;
}

// js/app.js (Main Application)
const deviceService = new CordovaDeviceService();

// Example usage in your app
class AppController {
    constructor() {
        this.initializeEventListeners();
    }

    initializeEventListeners() {
        document.addEventListener('DOMContentLoaded', () => {
            this.setupUI();
        });

        // Wait for device ready
        if (deviceService.isDeviceReady) {
            this.onDeviceReady();
        } else {
            document.addEventListener('deviceready', () => {
                this.onDeviceReady();
            });
        }
    }

    onDeviceReady() {
        console.log('App is ready!');
        this.displayDeviceInfo();
        this.checkNetworkStatus();
    }

    async displayDeviceInfo() {
        const deviceInfo = deviceService.getDeviceInfo();
        if (deviceInfo) {
            const infoElement = document.getElementById('device-info');
            if (infoElement) {
                infoElement.innerHTML = `
                    <p><strong>Platform:</strong> ${deviceInfo.platform}</p>
                    <p><strong>Version:</strong> ${deviceInfo.version}</p>
                    <p><strong>Model:</strong> ${deviceInfo.model}</p>
                    <p><strong>UUID:</strong> ${deviceInfo.uuid}</p>
                `;
            }
        }
    }

    checkNetworkStatus() {
        const networkInfo = deviceService.getNetworkInfo();
        const statusElement = document.getElementById('network-status');
        if (statusElement) {
            statusElement.innerHTML = `
                <p><strong>Status:</strong> ${networkInfo.online ? 'Online' : 'Offline'}</p>
                <p><strong>Type:</strong> ${networkInfo.type}</p>
            `;
            statusElement.className = networkInfo.online ? 'online' : 'offline';
        }
    }

    async takePicture() {
        try {
            const result = await deviceService.takePhoto({
                quality: 90,
                saveToPhotoAlbum: true
            });

            if (result.success) {
                const imageElement = document.getElementById('captured-image');
                if (imageElement) {
                    imageElement.src = result.imageUri;
                    imageElement.style.display = 'block';
                }

                await deviceService.showAlert(
                    'Photo captured successfully!',
                    'Success',
                    'OK'
                );
            }
        } catch (error) {
            console.error('Camera error:', error);
            await deviceService.showAlert(
                'Failed to capture photo: ' + error.message,
                'Error',
                'OK'
            );
        }
    }

    async getCurrentLocation() {
        try {
            const position = await deviceService.getCurrentPosition();

            if (position.success) {
                const locationElement = document.getElementById('location');
                if (locationElement) {
                    locationElement.innerHTML = `
                        <p><strong>Latitude:</strong> ${position.latitude}</p>
                        <p><strong>Longitude:</strong> ${position.longitude}</p>
                        <p><strong>Accuracy:</strong> ${position.accuracy}m</p>
                    `;
                }
            }
        } catch (error) {
            console.error('Geolocation error:', error);
            await deviceService.showAlert(
                'Failed to get location: ' + error.message,
                'Error',
                'OK'
            );
        }
    }

    async showConfirmation() {
        const result = await deviceService.showConfirm(
            'Do you want to continue?',
            'Confirmation',
            ['Yes', 'No']
        );

        if (result === 1) {
            await deviceService.showAlert('You chose Yes!', 'Result', 'OK');
        } else {
            await deviceService.showAlert('You chose No!', 'Result', 'OK');
        }
    }
}

// Initialize the app
const app = new AppController();
代码text中等

Cordova自定义插件开发

创建自定义Cordova插件,使用原生代码实现iOS (Objective-C/Swift) 和 Android (Java/Kotlin) 功能

text
// Plugin Creation Command
// cordova plugin create cordova-plugin-myplugin --name "My Plugin" --plugin_id cordova-plugin-myplugin --plugin_version 1.0.0

// www/myplugin.js (JavaScript Interface)
var exec = require('cordova/exec');

var MyPlugin = {
    /**
     * Perform a custom operation
     * @param {Function} successCallback - Success callback
     * @param {Function} errorCallback - Error callback
     * @param {Object} options - Options object
     */
    customOperation: function(successCallback, errorCallback, options) {
        var defaultOptions = {
            value: '',
            mode: 'normal'
        };

        var mergedOptions = Object.assign(defaultOptions, options || {});

        exec(
            successCallback,
            errorCallback,
            'MyPlugin',
            'customOperation',
            [mergedOptions]
        );
    },

    /**
     * Get device specific information
     * @param {Function} successCallback - Success callback
     * @param {Function} errorCallback - Error callback
     */
    getDeviceInfo: function(successCallback, errorCallback) {
        exec(
            successCallback,
            errorCallback,
            'MyPlugin',
            'getDeviceInfo',
            []
        );
    },

    /**
     * Start monitoring a custom event
     * @param {Function} callback - Event callback
     */
    startMonitoring: function(callback) {
        exec(
            callback,
            callback,
            'MyPlugin',
            'startMonitoring',
            []
        );
    },

    /**
     * Stop monitoring custom events
     */
    stopMonitoring: function() {
        exec(
            function() {},
            function() {},
            'MyPlugin',
            'stopMonitoring',
            []
        );
    }
};

module.exports = MyPlugin;

// src/ios/MyPlugin.m (Objective-C Implementation)
#import <Cordova/CDV.h>
#import "MyPlugin.h"

@implementation MyPlugin

- (void)customOperation:(CDVInvokedUrlCommand*)command {
    CDVPluginResult* pluginResult = nil;
    NSString* value = nil;
    NSString* mode = @"normal";

    @try {
        // Get parameters
        NSDictionary* options = [command.arguments objectAtIndex:0];

        if (options) {
            value = [options objectForKey:@"value"];
            mode = [options objectForKey:@"mode"];

            if (!mode) {
                mode = @"normal";
            }
        }

        if (!value) {
            pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Missing required parameter: value"];
        } else {
            // Process the operation
            NSString* processedValue = [NSString stringWithFormat:@"%@: %@",
                                      [mode isEqualToString:@"advanced"] ? @"ADVANCED" : @"NORMAL",
                                      value];

            // Create response dictionary
            NSDictionary* result = @{
                @"success": @YES,
                @"processedValue": processedValue,
                @"timestamp": @([[NSDate date] timeIntervalSince1970] * 1000),
                @"platform": @"iOS"
            };

            pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:result];
        }
    } @catch (NSException* exception) {
        pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:[exception reason]];
    }

    [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}

- (void)getDeviceInfo:(CDVInvokedUrlCommand*)command {
    CDVPluginResult* pluginResult = nil;

    @try {
        UIDevice* device = [UIDevice currentDevice];

        NSDictionary* deviceInfo = @{
            @"platform": @"iOS",
            @"systemVersion": device.systemVersion,
            @"model": device.model,
            @"name": device.name,
            @"customProperty": @"ios-specific-value",
            @"batteryLevel": @(device.batteryLevel),
            @"batteryState": @(device.batteryState)
        };

        pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:deviceInfo];
    } @catch (NSException* exception) {
        pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:[exception reason]];
    }

    [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}

- (void)startMonitoring:(CDVInvokedUrlCommand*)command {
    // Start monitoring custom events
    self.monitoringCallbackId = command.callbackId;

    // Example: Monitor battery changes
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(batteryLevelDidChange:)
                                                 name:UIDeviceBatteryLevelDidChangeNotification
                                               object:nil];

    // Enable battery monitoring
    [[UIDevice currentDevice] setBatteryMonitoringEnabled:YES];

    // Keep the command alive for monitoring
    CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
    [pluginResult setKeepCallbackAsBool:YES];
    [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}

- (void)stopMonitoring:(CDVInvokedUrlCommand*)command {
    // Stop monitoring
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    [[UIDevice currentDevice] setBatteryMonitoringEnabled:NO];

    self.monitoringCallbackId = nil;

    CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
    [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}

- (void)batteryLevelDidChange:(NSNotification*)notification {
    if (self.monitoringCallbackId) {
        UIDevice* device = [UIDevice currentDevice];

        NSDictionary* batteryInfo = @{
            @"eventType": @"batteryChange",
            @"level": @(device.batteryLevel),
            @"state": @(device.batteryState),
            @"timestamp": @([[NSDate date] timeIntervalSince1970] * 1000)
        };

        CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:batteryInfo];
        [pluginResult setKeepCallbackAsBool:YES];
        [self.commandDelegate sendPluginResult:pluginResult callbackId:self.monitoringCallbackId];
    }
}

- (void)dispose {
    [self stopMonitoring:nil];
    [super dispose];
}

@end

// src/android/MyPlugin.java (Android Implementation)
package com.example.myplugin;

import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.PluginResult;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.BatteryManager;
import android.util.Log;

public class MyPlugin extends CordovaPlugin {
    private static final String TAG = "MyPlugin";
    private CallbackContext monitoringCallback;

    @Override
    public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
        if ("customOperation".equals(action)) {
            this.customOperation(args, callbackContext);
            return true;
        } else if ("getDeviceInfo".equals(action)) {
            this.getDeviceInfo(callbackContext);
            return true;
        } else if ("startMonitoring".equals(action)) {
            this.startMonitoring(callbackContext);
            return true;
        } else if ("stopMonitoring".equals(action)) {
            this.stopMonitoring(callbackContext);
            return true;
        } else {
            callbackContext.error("Invalid action: " + action);
            return false;
        }
    }

    private void customOperation(JSONArray args, CallbackContext callbackContext) {
        try {
            if (args.length() < 1) {
                callbackContext.error("Missing options parameter");
                return;
            }

            JSONObject options = args.getJSONObject(0);
            String value = options.optString("value", "");
            String mode = options.optString("mode", "normal");

            if (value.isEmpty()) {
                callbackContext.error("Missing required parameter: value");
                return;
            }

            // Process the operation
            String processedValue = "advanced".equals(mode)
                ? "ADVANCED: " + value
                : "NORMAL: " + value;

            // Create response
            JSONObject result = new JSONObject();
            result.put("success", true);
            result.put("processedValue", processedValue);
            result.put("timestamp", System.currentTimeMillis());
            result.put("platform", "Android");

            callbackContext.success(result);
        } catch (JSONException e) {
            Log.e(TAG, "JSON Exception", e);
            callbackContext.error("JSON Exception: " + e.getMessage());
        }
    }

    private void getDeviceInfo(CallbackContext callbackContext) {
        try {
            Context context = cordova.getActivity().getApplicationContext();

            JSONObject deviceInfo = new JSONObject();
            deviceInfo.put("platform", "Android");
            deviceInfo.put("version", android.os.Build.VERSION.RELEASE);
            deviceInfo.put("model", android.os.Build.MODEL);
            deviceInfo.put("manufacturer", android.os.Build.MANUFACTURER);
            deviceInfo.put("customProperty", "android-specific-value");

            // Battery information
            IntentFilter ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
            Intent batteryStatus = context.registerReceiver(null, ifilter);

            if (batteryStatus != null) {
                int level = batteryStatus.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
                int scale = batteryStatus.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
                float batteryPct = level / (float) scale;
                int status = batteryStatus.getIntExtra(BatteryManager.EXTRA_STATUS, -1);

                deviceInfo.put("batteryLevel", batteryPct);
                deviceInfo.put("batteryStatus", status);
            }

            callbackContext.success(deviceInfo);
        } catch (JSONException e) {
            Log.e(TAG, "JSON Exception", e);
            callbackContext.error("JSON Exception: " + e.getMessage());
        }
    }

    private void startMonitoring(CallbackContext callbackContext) {
        this.monitoringCallback = callbackContext;

        // Create a result that stays alive for monitoring
        PluginResult result = new PluginResult(PluginResult.Status.OK);
        result.setKeepCallback(true);
        callbackContext.sendPluginResult(result);

        // Start a background thread for monitoring
        startBackgroundMonitoring();
    }

    private void stopMonitoring(CallbackContext callbackContext) {
        this.monitoringCallback = null;
        stopBackgroundMonitoring();

        callbackContext.success();
    }

    private void startBackgroundMonitoring() {
        cordova.getThreadPool().execute(new Runnable() {
            @Override
            public void run() {
                while (monitoringCallback != null) {
                    try {
                        // Example: Monitor battery every 5 seconds
                        Thread.sleep(5000);

                        if (monitoringCallback != null) {
                            Context context = cordova.getActivity().getApplicationContext();
                            IntentFilter ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
                            Intent batteryStatus = context.registerReceiver(null, ifilter);

                            if (batteryStatus != null) {
                                int level = batteryStatus.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
                                int scale = batteryStatus.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
                                float batteryPct = level / (float) scale;

                                JSONObject batteryInfo = new JSONObject();
                                try {
                                    batteryInfo.put("eventType", "batteryChange");
                                    batteryInfo.put("level", batteryPct);
                                    batteryInfo.put("timestamp", System.currentTimeMillis());

                                    PluginResult result = new PluginResult(PluginResult.Status.OK, batteryInfo);
                                    result.setKeepCallback(true);
                                    monitoringCallback.sendPluginResult(result);
                                } catch (JSONException e) {
                                    Log.e(TAG, "JSON Exception", e);
                                }
                            }
                        }
                    } catch (InterruptedException e) {
                        Log.d(TAG, "Monitoring interrupted", e);
                        break;
                    }
                }
            }
        });
    }

    private void stopBackgroundMonitoring() {
        // Cleanup background monitoring
        // This would typically involve stopping any background threads
    }

    @Override
    public void onDestroy() {
        stopMonitoring(null);
        super.onDestroy();
    }
}

// src/android/MyPlugin.gradle (Gradle Build File)
dependencies {
    implementation 'org.apache.cordova:framework:9.0.0'
}

// package.json (Plugin Package Configuration)
{
  "name": "cordova-plugin-myplugin",
  "version": "1.0.0",
  "description": "My Custom Cordova Plugin",
  "cordova": {
    "id": "cordova-plugin-myplugin",
    "platforms": [
      "android",
      "ios"
    ]
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/example/cordova-plugin-myplugin.git"
  },
  "keywords": [
    "cordova",
    "plugin",
    "ecosystem:cordova",
    "cordova-android",
    "cordova-ios"
  ],
  "author": "Example Developer",
  "license": "MIT",
  "bugs": {
    "url": "https://github.com/example/cordova-plugin-myplugin/issues"
  },
  "homepage": "https://github.com/example/cordova-plugin-myplugin#readme"
}

// Usage in Cordova App
// js/app.js
document.addEventListener('deviceready', function() {
    // Use the custom plugin
    MyPlugin.customOperation(
        function(result) {
            console.log('Success:', result);
        },
        function(error) {
            console.error('Error:', error);
        },
        {
            value: 'Hello World',
            mode: 'advanced'
        }
    );

    // Get device info
    MyPlugin.getDeviceInfo(
        function(deviceInfo) {
            console.log('Device Info:', deviceInfo);
        },
        function(error) {
            console.error('Error:', error);
        }
    );

    // Start monitoring
    MyPlugin.startMonitoring(function(event) {
        console.log('Event received:', event);
    });

    // Stop monitoring when done
    // MyPlugin.stopMonitoring();
});
代码text复杂

Cordova企业级部署与安全

配置企业级Cordova应用程序,包含安全最佳实践、证书固定、加密和企业部署策略

text
// config-security.xml (Security Configuration)
<?xml version='1.0' encoding='utf-8'?>
<widget id="com.enterprise.cordovaapp" version="2.0.0" xmlns="http://www.w3.org/ns/widgets">
    <name>EnterpriseApp</name>
    <description>Enterprise Cordova Application</description>
    <author email="[email protected]" href="https://enterprise.example.com">
        Enterprise Team
    </author>
    <content src="index.html" />

    <!-- Security Settings -->
    <access origin="https://api.enterprise.com" />
    <access origin="https://auth.enterprise.com" />
    <access origin="https://cdn.enterprise.com" />
    <allow-navigation href="https://*.enterprise.com/*" />
    <allow-intent href="https://*.enterprise.com/*" />
    <feature name="Whitelist">
        <param name="allowed-intents" value="https://*.enterprise.com/*" />
    </feature>

    <!-- Security Plugins -->
    <plugin name="cordova-plugin-advanced-http" spec="^3.2.2" />
    <plugin name="cordova-plugin-certificate-observer" spec="^1.0.0" />
    <plugin name="cordova-plugin-secure-storage" spec="^4.0.2" />
    <plugin name="cordova-plugin-screen-orientation" spec="^3.0.4" />
    <plugin name="cordova-plugin-app-version" spec="^0.1.9" />
    <plugin name="cordova-plugin-ios-security" spec="^2.0.0" />
    <plugin name="cordova-android-security" spec="^1.0.0" />

    <!-- Enterprise Platform Preferences -->
    <platform name="android">
        <preference name="android-minSdkVersion" value="23" />
        <preference name="android-targetSdkVersion" value="30" />
        <preference name="android:usesCleartextTraffic" value="false" />
        <preference name="android:networkSecurityConfig" value="res/xml/network_security_config.xml" />
        <preference name="android:allowBackup" value="false" />
        <preference name="android:fullBackupContent" value="false" />
        <preference name="AndroidInsecureFileModeEnabled" value="false" />

        <!-- Certificate Pinning -->
        <config-file target="AndroidManifest.xml" parent="/manifest/application">
            <meta-data android:name="io.intercom.certificate-pin" android:value="sha256/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=" />
        </config-file>
    </platform>

    <platform name="ios">
        <preference name="deployment-target" value="12.0" />
        <preference name="BackupWebStorage" value="none" />
        <preference name="DisallowOverscroll" value="true" />

        <!-- iOS Security Configuration -->
        <config-file target="*-Info.plist" parent="ITSAppUsesNonExemptEncryption">
            <true/>
        </config-file>

        <!-- App Transport Security -->
        <config-file target="*-Info.plist" parent="NSAppTransportSecurity">
            <dict>
                <key>NSAllowsArbitraryLoads</key>
                <false/>
                <key>NSExceptionDomains</key>
                <dict>
                    <key>api.enterprise.com</key>
                    <dict>
                        <key>NSExceptionRequiresForwardSecrecy</key>
                        <false/>
                        <key>NSExceptionMinimumTLSVersion</key>
                        <string>TLSv1.2</string>
                        <key>NSIncludesSubdomains</key>
                        <true/>
                    </dict>
                </dict>
            </dict>
        </config-file>
    </platform>
</widget>

// js/services/SecurityService.js
class SecurityService {
    constructor() {
        this.secureStorage = null;
        this.initializeSecurity();
    }

    async initializeSecurity() {
        try {
            // Initialize secure storage
            if (window.cordova && window.cordova.plugins.SecureStorage) {
                this.secureStorage = cordova.plugins.SecureStorage;
                await this.initializeSecureStorage();
            }

            // Setup certificate pinning
            await this.setupCertificatePinning();

            // Initialize encryption
            await this.initializeEncryption();
        } catch (error) {
            console.error('Security initialization failed:', error);
        }
    }

    async initializeSecureStorage() {
        return new Promise((resolve, reject) => {
            this.secureStorage.init(
                () => {
                    console.log('Secure storage initialized');
                    resolve();
                },
                (error) => {
                    console.error('Secure storage initialization failed:', error);
                    reject(error);
                },
                'enterprise_secure_storage'
            );
        });
    }

    async setupCertificatePinning() {
        if (!window.cordova || !window.cordova.plugins.CertificatePinning) {
            console.warn('Certificate pinning plugin not available');
            return;
        }

        return new Promise((resolve, reject) => {
            const certificates = [
                'sha256/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=', // Primary certificate
                'sha256/BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB=' // Backup certificate
            ];

            cordova.plugins.CertificatePinning.pinCertificates(
                certificates,
                () => {
                    console.log('Certificate pinning configured');
                    resolve();
                },
                (error) => {
                    console.error('Certificate pinning failed:', error);
                    reject(error);
                }
            );
        });
    }

    async initializeEncryption() {
        // Initialize AES encryption key
        this.encryptionKey = await this.getOrCreateEncryptionKey();
    }

    async getOrCreateEncryptionKey() {
        try {
            const existingKey = await this.getSecureItem('encryption_key');
            if (existingKey) {
                return existingKey;
            }

            // Generate new encryption key
            const key = this.generateEncryptionKey();
            await this.setSecureItem('encryption_key', key);
            return key;
        } catch (error) {
            console.error('Encryption key setup failed:', error);
            throw error;
        }
    }

    generateEncryptionKey() {
        // Generate a random 256-bit key
        const array = new Uint8Array(32);
        crypto.getRandomValues(array);
        return Array.from(array, byte => byte.toString(16).padStart(2, '0')).join('');
    }

    // Secure Storage Operations
    async setSecureItem(key, value) {
        if (!this.secureStorage) {
            throw new Error('Secure storage not available');
        }

        return new Promise((resolve, reject) => {
            this.secureStorage.set(
                () => resolve(),
                (error) => reject(error),
                key,
                value
            );
        });
    }

    async getSecureItem(key) {
        if (!this.secureStorage) {
            throw new Error('Secure storage not available');
        }

        return new Promise((resolve, reject) => {
            this.secureStorage.get(
                (value) => resolve(value),
                (error) => reject(error),
                key
            );
        });
    }

    async removeSecureItem(key) {
        if (!this.secureStorage) {
            throw new Error('Secure storage not available');
        }

        return new Promise((resolve, reject) => {
            this.secureStorage.remove(
                () => resolve(),
                (error) => reject(error),
                key
            );
        });
    }

    // Encryption/Decryption
    async encryptData(data) {
        try {
            const encoder = new TextEncoder();
            const dataBuffer = encoder.encode(JSON.stringify(data));

            // Import encryption key
            const key = await crypto.subtle.importKey(
                'raw',
                new TextEncoder().encode(this.encryptionKey).slice(0, 32),
                { name: 'AES-CBC' },
                false,
                ['encrypt']
            );

            // Generate random IV
            const iv = crypto.getRandomValues(new Uint8Array(16));

            // Encrypt data
            const encryptedData = await crypto.subtle.encrypt(
                {
                    name: 'AES-CBC',
                    iv: iv
                },
                key,
                dataBuffer
            );

            // Combine IV and encrypted data
            const combined = new Uint8Array(iv.length + encryptedData.byteLength);
            combined.set(iv);
            combined.set(new Uint8Array(encryptedData), iv.length);

            return btoa(String.fromCharCode.apply(null, combined));
        } catch (error) {
            console.error('Encryption failed:', error);
            throw error;
        }
    }

    async decryptData(encryptedData) {
        try {
            const combined = new Uint8Array(
                atob(encryptedData).split('').map(char => char.charCodeAt(0))
            );

            // Extract IV
            const iv = combined.slice(0, 16);
            const data = combined.slice(16);

            // Import encryption key
            const key = await crypto.subtle.importKey(
                'raw',
                new TextEncoder().encode(this.encryptionKey).slice(0, 32),
                { name: 'AES-CBC' },
                false,
                ['decrypt']
            );

            // Decrypt data
            const decryptedData = await crypto.subtle.decrypt(
                {
                    name: 'AES-CBC',
                    iv: iv
                },
                key,
                data
            );

            const decoder = new TextDecoder();
            return JSON.parse(decoder.decode(decryptedData));
        } catch (error) {
            console.error('Decryption failed:', error);
            throw error;
        }
    }

    // API Security
    async makeSecureRequest(url, options = {}) {
        const defaultOptions = {
            method: 'GET',
            headers: {
                'Content-Type': 'application/json',
                'X-App-Version': await this.getAppVersion(),
                'X-Device-ID': await this.getDeviceId()
            },
            timeout: 30000
        };

        const requestOptions = { ...defaultOptions, ...options };

        try {
            // Add authentication token if available
            const authToken = await this.getSecureItem('auth_token');
            if (authToken) {
                requestOptions.headers['Authorization'] = `Bearer ${authToken}`;
            }

            // Make request with certificate pinning
            const response = await this.httpRequestWithPinning(url, requestOptions);
            return response;
        } catch (error) {
            console.error('Secure request failed:', error);
            throw error;
        }
    }

    async httpRequestWithPinning(url, options) {
        if (window.cordova && window.cordova.plugin.http) {
            // Use Cordova HTTP plugin with certificate pinning
            return new Promise((resolve, reject) => {
                cordova.plugin.http.setRequestSerializer('json');
                cordova.plugin.http.setResponseSerializer('json');

                const success = (response) => {
                    resolve({
                        status: response.status,
                        data: response.data,
                        headers: response.headers
                    });
                };

                const failure = (error) => {
                    reject(new Error(`HTTP Error: ${error.error}`));
                };

                if (options.method === 'GET') {
                    cordova.plugin.http.get(url, options.params || {}, options.headers, success, failure);
                } else if (options.method === 'POST') {
                    cordova.plugin.http.post(url, options.data || {}, options.headers, success, failure);
                } else if (options.method === 'PUT') {
                    cordova.plugin.http.put(url, options.data || {}, options.headers, success, failure);
                } else if (options.method === 'DELETE') {
                    cordova.plugin.http.delete(url, options.params || {}, options.headers, success, failure);
                }
            });
        } else {
            // Fallback to standard fetch with security considerations
            const response = await fetch(url, options);

            if (!response.ok) {
                throw new Error(`HTTP ${response.status}: ${response.statusText}`);
            }

            return {
                status: response.status,
                data: await response.json(),
                headers: response.headers
            };
        }
    }

    async getAppVersion() {
        return new Promise((resolve, reject) => {
            if (window.cordova && window.cordova.getVersionCode) {
                window.cordova.getVersionCode(
                    (version) => resolve(version),
                    (error) => reject(error)
                );
            } else {
                resolve('1.0.0'); // Fallback version
            }
        });
    }

    async getDeviceId() {
        try {
            let deviceId = await this.getSecureItem('device_id');
            if (!deviceId) {
                deviceId = this.generateDeviceId();
                await this.setSecureItem('device_id', deviceId);
            }
            return deviceId;
        } catch (error) {
            console.error('Failed to get device ID:', error);
            return 'unknown';
        }
    }

    generateDeviceId() {
        return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
            const r = Math.random() * 16 | 0;
            const v = c === 'x' ? r : (r & 0x3 | 0x8);
            return v.toString(16);
        });
    }

    // Session Management
    async createSession(userCredentials) {
        try {
            // Authenticate with backend
            const authResponse = await this.makeSecureRequest(
                'https://api.enterprise.com/auth/login',
                {
                    method: 'POST',
                    data: userCredentials
                }
            );

            if (authResponse.status === 200 && authResponse.data.token) {
                // Securely store authentication tokens
                await this.setSecureItem('auth_token', authResponse.data.token);
                await this.setSecureItem('refresh_token', authResponse.data.refreshToken);

                // Encrypt and store user session data
                const encryptedSession = await this.encryptData({
                    user: authResponse.data.user,
                    permissions: authResponse.data.permissions,
                    expiresAt: Date.now() + (authResponse.data.expiresIn * 1000)
                });

                await this.setSecureItem('user_session', encryptedSession);

                return authResponse.data;
            } else {
                throw new Error('Authentication failed');
            }
        } catch (error) {
            console.error('Session creation failed:', error);
            throw error;
        }
    }

    async validateSession() {
        try {
            const encryptedSession = await this.getSecureItem('user_session');
            if (!encryptedSession) {
                return false;
            }

            const session = await this.decryptData(encryptedSession);

            // Check if session is expired
            if (session.expiresAt < Date.now()) {
                await this.clearSession();
                return false;
            }

            // Validate token with backend
            const validationResponse = await this.makeSecureRequest(
                'https://api.enterprise.com/auth/validate',
                {
                    method: 'POST',
                    data: { token: await this.getSecureItem('auth_token') }
                }
            );

            return validationResponse.status === 200;
        } catch (error) {
            console.error('Session validation failed:', error);
            await this.clearSession();
            return false;
        }
    }

    async clearSession() {
        try {
            await this.removeSecureItem('auth_token');
            await this.removeSecureItem('refresh_token');
            await this.removeSecureItem('user_session');
            await this.removeSecureItem('device_id');
        } catch (error) {
            console.error('Session cleanup failed:', error);
        }
    }

    // Audit Logging
    async logSecurityEvent(eventType, details) {
        try {
            const auditLog = {
                timestamp: new Date().toISOString(),
                eventType: eventType,
                details: details,
                deviceId: await this.getDeviceId(),
                appVersion: await this.getAppVersion()
            };

            // Encrypt audit log
            const encryptedLog = await this.encryptData(auditLog);

            // Send to secure logging endpoint
            await this.makeSecureRequest(
                'https://api.enterprise.com/audit/log',
                {
                    method: 'POST',
                    data: { log: encryptedLog }
                }
            );
        } catch (error) {
            console.error('Security event logging failed:', error);
        }
    }
}

// Export for use in other modules
if (typeof module !== 'undefined' && module.exports) {
    module.exports = SecurityService;
}

// js/EnterpriseApp.js (Main Application)
class EnterpriseApp {
    constructor() {
        this.securityService = new SecurityService();
        this.isAuthenticated = false;
    }

    async initialize() {
        try {
            // Validate existing session
            this.isAuthenticated = await this.securityService.validateSession();

            if (this.isAuthenticated) {
                await this.loadUserData();
                await this.showMainInterface();
            } else {
                await this.showLoginInterface();
            }

            // Log app initialization
            await this.securityService.logSecurityEvent('APP_INITIALIZED', {
                timestamp: Date.now(),
                existingSession: this.isAuthenticated
            });

        } catch (error) {
            console.error('App initialization failed:', error);
            await this.handleInitializationError(error);
        }
    }

    async login(username, password) {
        try {
            const credentials = {
                username: username,
                password: password,
                deviceId: await this.securityService.getDeviceId(),
                timestamp: Date.now()
            };

            const session = await this.securityService.createSession(credentials);
            this.isAuthenticated = true;

            await this.securityService.logSecurityEvent('USER_LOGIN', {
                username: username,
                success: true
            });

            await this.loadUserData();
            await this.showMainInterface();

            return session;
        } catch (error) {
            await this.securityService.logSecurityEvent('LOGIN_FAILED', {
                username: username,
                error: error.message
            });

            throw error;
        }
    }

    async logout() {
        try {
            await this.securityService.logSecurityEvent('USER_LOGOUT', {
                timestamp: Date.now()
            });

            await this.securityService.clearSession();
            this.isAuthenticated = false;

            await this.showLoginInterface();
        } catch (error) {
            console.error('Logout failed:', error);
        }
    }

    async loadUserData() {
        // Load user-specific data securely
    }

    async showMainInterface() {
        // Show main application interface
    }

    async showLoginInterface() {
        // Show login interface
    }

    async handleInitializationError(error) {
        // Handle initialization errors
        console.error('Initialization error:', error);
        await this.securityService.logSecurityEvent('INIT_ERROR', {
            error: error.message
        });
    }
}

// Initialize the enterprise app
document.addEventListener('deviceready', () => {
    const app = new EnterpriseApp();
    app.initialize();
});

工具

经常与该案例搭配使用的工具

相关内容

相关案例集合

相关内容

相关专题

专题

界面截图结构化、人工校对与开发交付

把一张获授权的界面截图整理为经人工校对的组件树、结构 JSON 与开发说明,记录坐标来源、识别遗漏和修改依据,不把视觉推断当成原始代码。

专题

药代动力学教学模型与结果核查

用于教学或 QA 的药代公式、模型假设和结果一致性核查,不提供用药剂量、诊断或临床建议。

专题

自托管抽奖组件配置复核、嵌入测试与上线交付

复核转盘、刮刮卡或盲盒的配置与商家接口样例,检查可读性和移动端布局,交付版本明确的组件文件及真实浏览器验收记录。

专题

经典与现代密码工具

在安全的教学或 CTF 场景中比较可逆的经典变换与现代加密,并明确玩具密码不等于安全防护。

首页
工具3206
案例593
可视化468
文件查看器103
专题236
标签333
图像、音频与视频657

图像、音频、视频处理、转换与优化工具

数学、日期与金融645

计算器、数值计算、日期逻辑、统计与金融工具

设计与颜色298

颜色、版式、图形、视觉样式与设计辅助工具

文本与写作209

写作、清洗、格式化、提取与文本分析工具

开发与 Web193

开发者工具、网络处理、Web 调试与自动化辅助工具

转换与编码175

格式、文件、压缩包、单位与编码转换工具

长文改编 X 串文与 LinkedIn 帖子的事实复核与交付
Markdown 互动课件审校、离线演示与交付
小房间家具布局复核与搬入方案交付
FLAC/WAV 无损音源疑点筛查与证据交付
自托管抽奖组件配置复核、嵌入测试与上线交付

© 2026 Elysia Tools. 保留所有权利。

文档价格关于我们服务条款隐私政策Cookie 政策联系我们

Data Processing

日志解析器 - Apache/Nginx访问日志解析

使用正则表达式解析Apache/Nginx访问日志并提取结构化数据

Health

APACHE II 危重病评分计算器

计算 APACHE II 危重病评分:急性生理评分 APS(12 项生理变量,每项 0-4 分,取入 ICU 24h 内最差值)+ 年龄分(0-6)+ 慢性健康分(0/2/5),总分 0-71,越高预后越差。氧合:FiO₂≥0.5 用 A-a 梯度,否则用 PaO₂;急性肾衰时肌酐分翻倍;GCS 计 15−GCS。同时给出基础死亡风险预测(logit=−3.517+0.146×分,不含诊断类别权重)。来源 Knaus 1985 Crit Care Med、SFAR 评分表。不能替代临床判断。不构成医疗建议。

Health

胎儿发育时间线

按孕周(末次月经起算)展示胎儿发育里程碑,分三个孕期,标注当前孕周对应的胎儿大小、身长、体重及当周发育要点。

Health

握力测力计与发力率(RFD)解析教练

解读 Jamar/Camry/EH101 握力读数:按年龄性别对比 Massy-Westropp 2011 人群常模(Z 分数/百分位/常模百分比),筛查少肌症无力阈值(EWGSOP2、AWGS、Fried),检测 10% 左右不对称;从力-时间曲线计算发力率 RFD(0-50 至 0-250ms 时间窗、峰值 RFD、冲量、峰值时间,方法学遵循 Maffiuletti 2016);重复测试计算疲劳指数。

Development

注释文档提取器

从JavaScript/TypeScript、Python和Java源代码中提取和解析文档

Text Processing

手机号提取器

从混合文本中提取电话号码,支持多个国家和格式

Development

API 文档生成器

从 OpenAPI 或注释生成美观的 API 文档

Development

JavaScript反混淆器

反混淆和分析混淆的JavaScript代码,提高可读性和理解性

移动开发

React Native 示例

React Native 跨平台移动开发示例,包括组件、导航、状态管理和原生集成

文本处理

手机号提取器示例

包含来自多个国家的电话号码的混合文本集合,用于提取测试

区块链

Hardhat 开发框架示例

Hardhat 以太坊开发环境示例,包括智能合约、测试、部署、脚本、插件和开发工作流

区块链

Truffle 开发套件示例

Truffle 以太坊开发框架示例,包括智能合约、测试、部署、迁移、调试和开发工作流

移动开发

Capacitor混合应用开发示例

Capacitor混合应用开发示例,包括原生设备API、插件、跨平台部署和渐进式Web应用功能

移动开发

Ionic 示例

Ionic 混合移动应用框架示例,包括组件、导航、状态管理和原生集成