编辑代码


/*
*名称:fnOnMsg
*功能:1.执行原有的消息机制
        2.视情况执行对应的函数
*参数:msg.data
*返回:无
*问题:是否需要增加函数执行后的响应- done
*/
function fnOnMsg(msg) {

    //if(!msg.data.bIfContinue)
    if (!msg.data.bIfContinue) {
        alert(msg.strErrorDescription);
        window.onmessage = window.fnOldOnmessage;
        window.sessionStorage.removeItem('aryStrTaskName');
        window.fnOldOnmessage = null;
        window.objGlobalParam = null;
    }
    else if (msg.data.strName.match('') ||
        msg.data.strName.match('') ||
        msg.data.strName.match('') ||
        msg.data.strName.match('') ||
        msg.data.strName.match('') ||
        msg.data.strName.match('') ||
        msg.data.strName.match('') ||
        msg.data.strName.match('start') 
        ) {
        let aryStrTaskName = window.sessionStorage.getItem('aryStrTaskName').split(',');

        switch (aryStrTaskName.pop())
        /*
            "End,"+
            "fnCheckOut,"+
            "fnCreateInvoice,"+
            "fnAutoReceipt,"+
            "fnCancelInvoiceNumber,"+
            "fnGetInoiceNumber,"+
            "fnGetAccountBalance," +            1
            "fnGetReservationDetails,"+
            "fnParseFromRmNum2ResNum,"+
            "fnGetInhouseReservationList") */ {
            case "End":
                window.onmessage = window.fnOldMainOnmessage;
                window.sessionStorage.removeItem('aryStrTaskName');
                window.fnOldMainOnmessage = null;
                objParam = null;
                objMsg = null;
                window.objGlobalParam= null;
                break;
            case "fnGetInhouseReservationList":
                fnGetInhouseReservationList(msg.data);
                window.sessionStorage.setItem('aryStrTaskName', aryStrTaskName);
                break;
            case "fnParseFromRmNum2ResNum":
                msg.data.name = "fnCallBackParseFromRmNum2ResNum"

                fnParseFromRmNum2ResNum(parseInt(prompt("请输入房间号", "")), window.objGlobalParam.objAryInOutData);
                window.sessionStorage.setItem('aryStrTaskName', aryStrTaskName);
                window.postMessage(msg.data);
                break;
        }
    }
    //old onmessage
    else if (window.fnOldMainOnmessage != null)
        window.fnOldMainOnmessage(msg);



}

//fnMain-->fnOnMsg<==>fnFuntionN
//1.set the string array of task queue name into sessionStorage 
//2.set param if necessary
//3.run the fnMain

//include initialization
function fnMain() {
    //initialization
    window.fnOldMainOnmessage = window.onmessage;
    window.onmessage = fnOnMsg;

    //set tasks
    window.sessionStorage.setItem('aryStrTaskName',
        "End," +
        "," +
        "," +
        "," +
        "," +
        "," +
        "," +
        "," +
        "," +
        "");
    //let nRoomNumber = parseInt(prompt("请输入房间号",""))
    let objMainMsg = {
        "objParam": '',
        "bIfContinue": 1,
        "strErrorDescription": '',
        "strName": 'start'
    }
    objMainMsg.objParam.nParam = 0;
    window.objGlobalParam = new Object();

    //Entrance
    window.postMessage(objMainMsg);

}

fnMain();

//# sourceURL=my-script.js