1.1.0 • Published 4 years ago

cdm-plugin v1.1.0

Weekly downloads
34
License
ISC
Repository
-
Last release
4 years ago

cdm-plugin

Table of Contents generated with DocToc

install:

    npm install cdm-plugin --save

use:

    import {Http, WebSocketClient, FileUtil, 
    BaseUtil, BaseDBUtil, Business, 
    LOGLEVEL, MODE_TYPE, FILE_TYPE, Log} from 'cdm-plugin';

Http:

method
methoddescriptionparamsparams detail
ajaxPromiseajax with promise{Object}{url, data, async, type} default: type='get', async=true,data = ''
ajaxPromiseUploadupload file{Object}{url, formData}
use
    // post
    let data = await Http.ajaxPromise({url: `www.xxx.com/entity?id=1`}); // get
    let data = await Http.ajaxPromise({
        url: `www.xxx.com/entity`,
        type: 'post',
        data: data,
    });
    // upload file
    const export_blob = new Blob([data]);
    const file = new File([export_blob], fileName);
    const formData = new FormData();
    formData.append("file", file);
    Http.ajaxPromiseUpload({
        url,
        formData,
    });

WebSocketClient:

method
methoddescriptionparams
constructorinit with ip, portip, port
addEventListener-type, callback
removeEventListener-type
removeAllEventListener--
waitConnect--
send-data
close--
use
    let client = new WebSocketClient(ip, port);
    client.addEventListener('devicelist', (e) => {
        console.log(e.data);
    });
    await client.waitConnect();
    client.removeEventListener('devicelist');
    client.removeAllEventListener();
    client.send(JSON.stringify(data));
    client.close();

FileUtil:

method
methoddescriptionparamsparams detail
XMLtoString-xmlElement-
toFilegenerate filefileName, fileText-
getZipFilesget a zip package all filesfile-
saveZipgenerate zip filefileName, content-
uploadFiles-url, files-
use
    const str = FileUtil.XMLtoString(xmlElement);
    cosnt file1 = FileUtil.toFile(str);
    cosnt file2 = FileUtil.toFile(str);
    const [logics, modes, zip] = await FileUtil.getZipFiles(file);
    const files = [file1, file2];
    FileUtil.uploadFiles(url, files);
    let zip = new JSZip();
    let logic = zip.folder('lua');
    cosnt file1 = FileUtil.toFile(str);
    logic.file(`${fileName}.${fileType}`, file1);
    const content = await zip.generateAsync({type: 'blob'});
    FileUtil.saveZip(`fileName.zip`, content);

BaseUtil:

method
methoddescriptionparamsparams detail
notEmptyArray-Arrayreturn boolean
notEmptyObject-{Object}return boolean
fileNameFormat-Stringreturn String
fileExtFormat-Stringreturn String
use
    let array1;// false
    let array2 = [];// false
    let array3 = [0];// true
    BaseUtil.notEmptyArray(array1);
    
    let object1;// false
    let object2 = {};// false
    let object3 = {'key': 'value'};// true
    BaseUtil.notEmptyObject(object1);
    const fileName = 'index.json';
    BaseUtil.fileNameFormat(fileName);// index
    BaseUtil.fileExtFormat(fileName);// json

BaseDBUtil:

method
methoddescriptionparamsparams detail
setConfig------Arrayreturn boolean
setTimeout------numberreturn boolean
getTimeout-------return number
getInstance-------return number
save2Idb------tableName, data-
findDataByCondition------tableName, conditionreturn Array
deleteData------tableName, condition-
customOperation------tableName, operationcallback return instance
use
import dbc from '@/js/db_config';

    const baseDBUtil = new BaseDBUtil();
    baseDBUtil.setConfig(dbc);
    baseDBUtil.setTimeout(5000);
    await baseDBUtil.getInstance();
    await baseDBUtil.save2Idb(tableName,{'key':'value'});
    const data = await baseDBUtil.findDataByCondition(tableName, (item) => {
        return item.programName === name
            && item.programType === type;
    });
    const data2 = await baseDBUtil.findAll(tableName);
    await baseDBUtil.deleteData(tableName, (item) => {
        return item.name === key && item.type === FILE_TYPE.JSON;
    });
    await baseDBUtil.customOperation(tableName, (instance) => {
        instance.query({
            tableName,
            condition,
        });
    });
    await baseDBUtil.clearIdbTable(tableName);
reference

when you use customOperation, you can get idb-js instance

db_config file reference idb-js

idb-js doc url: https://github.com/verybigorange/idb-js

Business:

method
methoddescriptionparamsparams detail
getZipDatazip to dataFilereturn Array
generateZipContentdata to zipdatareturn content
uploadAllFiles-config, logicFiles, modeFilesconfig = {fileServer, params}
deleteAllFiles-config, logicFiles, modeFilesconfig = {fileServer, params}
use
    const rows = Business.getZipData(file);
    rows.forEach((item) => {
        baseDBUtil.save2Idb(tableName, item);
    });
    
    const content = Business.generateZipContent(rows);
    FileUtil.saveZip(fname, content);
    const config = {
        fileServer: 'www.xxx.com/entity', 
        params: '?id=1',
    };
    await Business.uploadAllFiles(config, logicFiles, modeFiles);
    await Business.deleteAllFiles(config, logicFiles, modeFiles);

Log:

method
methoddescriptionparamsparams detail
init-logLevelnumber0-4
setLevel-logLevelnumber0-4
use
    Log.init(LOG_LEVEL.WARN);
    Log.setLevel(LOG_LEVEL.INFO);

DICT:

define
objectkeyvalue
LOG_LEVELTRACE0
LOG_LEVELLOG1
LOG_LEVELINFO2
LOG_LEVELWARN3
LOG_LEVELERROR4
MODE_TYPELOGIC'logic'
MODE_TYPEMODE'mode'
FILE_TYPEJSON'json'
FILE_TYPEJSON'lua'
FILE_TYPEJSON'xml'
use
    Log.init(LOG_LEVEL.WARN);
1.1.0

4 years ago

1.0.31

4 years ago

1.0.30

4 years ago

1.0.29

4 years ago

1.0.28

4 years ago

1.0.26

4 years ago

1.0.27

4 years ago

1.0.25

4 years ago

1.0.24

4 years ago

1.0.23

4 years ago

1.0.22

4 years ago

1.0.21

4 years ago

1.0.20

4 years ago

1.0.19

4 years ago

1.0.18

4 years ago

1.0.17

4 years ago

1.0.16

4 years ago

1.0.15

4 years ago

1.0.14

4 years ago

1.0.13

4 years ago

1.0.12

4 years ago

1.0.11

4 years ago

1.0.10

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.3

4 years ago

1.0.0

4 years ago