善小而为_ 发表于 2024-2-21 09:43:40

通用代码:baidu翻译接口

import win.ui;
/*DSG{{*/
var winform = win.form(text="aardio form";right=759;bottom=469)
winform.add(
buttonCls={cls="button";text="清空";left=268;top=415;right=414;bottom=460;z=6};
buttonFy={cls="button";text="百度翻译";left=69;top=416;right=215;bottom=461;z=2};
editFrom={cls="edit";left=40;top=47;right=721;bottom=88;ah=1;aw=1;edge=1;multiline=1;z=1};
editTo={cls="edit";left=39;top=96;right=720;bottom=251;ah=1;aw=1;edge=1;multiline=1;vscroll=1;z=3};
listviewTo={cls="listview";left=39;top=257;right=720;bottom=409;ah=1;aw=1;edge=1;vscroll=1;z=5};
static={cls="static";text="百度翻译";left=47;top=10;right=171;bottom=40;font=LOGFONT(h=-24;name='微软雅黑');transparent=1;z=4}
)
/*}}*/

import web.rest.jsonLiteClient;
var http = web.rest.jsonLiteClient();

winform.editFrom.text = "hello"
winform.listviewTo.setColumns({"中英文","翻译"},{100,800})

winform.buttonFy.oncommand = function(id,event){
        winform.editTo.text = ""
        winform.listviewTo.clear()
       
        var url = "https://fanyi.baidu.com/sug"; //baidu翻译接口
        var api = http.api(url);
        var data = api.post({"kw" = winform.editFrom.text;})
        for k,v in data.data{
                winform.editTo.print(v.k,v.v);
                winform.listviewTo.addItem({v.k,v.v})
        }
       
}

winform.buttonCls.oncommand = function(id,event){
        winform.editFrom.text = ""
        winform.editTo.text = ""
        winform.listviewTo.clear()
}

winform.show();
win.loopMessage();
页: [1]
查看完整版本: 通用代码:baidu翻译接口