
//plus控件自绘聊天框 - chatBox
import win.ui;
import inet.http;
import fsys.dlg;
import fsys;
import fsys.info;
import fsys.file;
import process;
import web.json;
/*DSG{{*/
var winform = win.form(text="aardio 聊天框示例";right=463;bottom=631;clipch=1;composited=1)
winform.add(
btnFileA={cls="button";text="+";left=144;top=576;right=192;bottom=616;db=1;dl=1;z=6};
btnFileB={cls="button";text="+";left=392;top=576;right=440;bottom=616;db=1;dr=1;z=5};
btnUserA={cls="button";text="用户A发送";left=24;top=576;right=136;bottom=617;db=1;dl=1;z=3};
btnUserB={cls="button";text="用户B发送";left=272;top=576;right=384;bottom=617;db=1;dr=1;z=4};
editMsg={cls="edit";left=24;top=536;right=440;bottom=570;db=1;dl=1;dr=1;edge=1;multiline=1;z=2};
plusChat={cls="plus";left=24;top=16;right=440;bottom=528;bgcolor=0xFFFFFF;db=1;dl=1;dr=1;dt=1;edge=1;notify=1;z=1}
)
/*}}*/
var imgObjA = gdip.bitmap("https://img3-tc.tapimg.com/avatars/etag/Fqs8Pm-QS6gtg9OnWtZLyFfMaWi6.png");
var imgObjB = gdip.bitmap("https://img3-tc.tapimg.com/default_avatars/fa4f0232b0237ea362cad0e74c9dd998.jpg");
var code = inet.http.get("https://aar.chengxu.online/attach-download-477.htm");
var classObject = loadcodex(code);
var chatbox = classObject(winform.plusChat);
//初始化user1、user2的信息
chatBox.setUser1( {id = "userA"; name = "我"; bubbleColor=0xFFA0FF70; avatar =imgObjA } );
chatBox.setUser2( {id = "userB"; name = "你"; bubbleColor=0xFFF3FF3F; avatar =imgObjB } );
chatBox.user1isRight = false; //用户1是否显示在右侧
chatBox.showGifAnimation(true); //是否显示gif动画
//chatBox.avatarRound = false; //头像是否为圆角
winform.btnUserA.oncommand = function(id,event){
var txt = winform.editMsg.text;
if(!#txt)return;
chatBox.showMsg("userA", txt, 1, time()) ;
winform.editMsg.text = "";
}
winform.btnUserB.oncommand = function(id,event){
var txt = winform.editMsg.text;
if(!#txt)return;
chatBox.showMsg("userB", txt, 1, time()) ;
winform.editMsg.text = "";
}
winform.btnFileA.oncommand = function(id,event){
var filepath = fsys.dlg.open()
if(filepath){
chatBox.showMsg("userA", filepath, 2, time()) ;
}
}
winform.btnFileB.oncommand = function(id,event){
var filepath = fsys.dlg.open()
if(filepath){
chatBox.showMsg("userB", filepath, 2, time()) ;
}
}
winform.onDestroy = function(){
//程序关闭时,保存聊天内容
chatBox.save();
}
winform.show();
//( 必须放在winform.show()后,contentHeight才能计算正确)
chatBox.load();
win.loopMessage();